Bind TextureBuffers

This commit is contained in:
Isaac Marovitz 2024-07-27 11:32:45 +01:00 committed by Isaac Marovitz
parent 62602e58b7
commit 3214a4cf8e
2 changed files with 65 additions and 83 deletions

View file

@ -54,10 +54,10 @@ namespace Ryujinx.Graphics.Metal
record struct TextureRef record struct TextureRef
{ {
public ShaderStage Stage; public ShaderStage Stage;
public Texture Storage; public TextureBase Storage;
public Sampler Sampler; public Sampler Sampler;
public TextureRef(ShaderStage stage, Texture storage, Sampler sampler) public TextureRef(ShaderStage stage, TextureBase storage, Sampler sampler)
{ {
Stage = stage; Stage = stage;
Storage = storage; Storage = storage;

View file

@ -805,13 +805,9 @@ namespace Ryujinx.Graphics.Metal
public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler) public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler)
{ {
if (texture is TextureBuffer) if (texture != null)
{ {
// TODO: Texture buffers _currentState.TextureRefs[binding] = new(stage, texture, sampler);
}
else if (texture is Texture view)
{
_currentState.TextureRefs[binding] = new(stage, view, sampler);
} }
else else
{ {
@ -1124,59 +1120,52 @@ namespace Ryujinx.Graphics.Metal
case MetalRenderer.TextureSetIndex: case MetalRenderer.TextureSetIndex:
if (!segment.IsArray) if (!segment.IsArray)
{ {
if (segment.Type != ResourceType.BufferTexture) for (int i = 0; i < count; i++)
{ {
for (int i = 0; i < count; i++) int index = binding + i;
ref var texture = ref _currentState.TextureRefs[index];
var storage = texture.Storage;
if (storage == null)
{ {
int index = binding + i; continue;
ref var texture = ref _currentState.TextureRefs[index];
var storage = texture.Storage;
if (storage == null)
{
continue;
}
var mtlTexture = storage.GetHandle();
MTLRenderStages renderStages = 0;
if ((segment.Stages & ResourceStages.Vertex) != 0)
{
vertResourceIds[vertResourceIdIndex] = mtlTexture.GpuResourceID._impl;
vertResourceIdIndex++;
if (texture.Sampler != null)
{
vertResourceIds[vertResourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
vertResourceIdIndex++;
}
renderStages |= MTLRenderStages.RenderStageVertex;
}
if ((segment.Stages & ResourceStages.Fragment) != 0)
{
fragResourceIds[fragResourceIdIndex] = mtlTexture.GpuResourceID._impl;
fragResourceIdIndex++;
if (texture.Sampler != null)
{
fragResourceIds[fragResourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
fragResourceIdIndex++;
}
renderStages |= MTLRenderStages.RenderStageFragment;
}
renderCommandEncoder.UseResource(new MTLResource(mtlTexture.NativePtr), MTLResourceUsage.Read, renderStages);
} }
}
else var mtlTexture = storage.GetHandle();
{
// TODO: Buffer textures MTLRenderStages renderStages = 0;
if ((segment.Stages & ResourceStages.Vertex) != 0)
{
vertResourceIds[vertResourceIdIndex] = mtlTexture.GpuResourceID._impl;
vertResourceIdIndex++;
if (texture.Sampler != null)
{
vertResourceIds[vertResourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
vertResourceIdIndex++;
}
renderStages |= MTLRenderStages.RenderStageVertex;
}
if ((segment.Stages & ResourceStages.Fragment) != 0)
{
fragResourceIds[fragResourceIdIndex] = mtlTexture.GpuResourceID._impl;
fragResourceIdIndex++;
if (texture.Sampler != null)
{
fragResourceIds[fragResourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
fragResourceIdIndex++;
}
renderStages |= MTLRenderStages.RenderStageFragment;
}
renderCommandEncoder.UseResource(new MTLResource(mtlTexture.NativePtr), MTLResourceUsage.Read, renderStages);
} }
} }
else else
@ -1343,41 +1332,34 @@ namespace Ryujinx.Graphics.Metal
case MetalRenderer.TextureSetIndex: case MetalRenderer.TextureSetIndex:
if (!segment.IsArray) if (!segment.IsArray)
{ {
if (segment.Type != ResourceType.BufferTexture) for (int i = 0; i < count; i++)
{ {
for (int i = 0; i < count; i++) int index = binding + i;
ref var texture = ref _currentState.TextureRefs[index];
var storage = texture.Storage;
if (storage == null)
{ {
int index = binding + i; continue;
}
ref var texture = ref _currentState.TextureRefs[index]; var mtlTexture = storage.GetHandle();
var storage = texture.Storage; if (segment.Stages.HasFlag(ResourceStages.Compute))
{
computeCommandEncoder.UseResource(new MTLResource(mtlTexture.NativePtr), MTLResourceUsage.Read);
resourceIds[resourceIdIndex] = mtlTexture.GpuResourceID._impl;
resourceIdIndex++;
if (storage == null) if (texture.Sampler != null)
{ {
continue; resourceIds[resourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
}
var mtlTexture = storage.GetHandle();
if (segment.Stages.HasFlag(ResourceStages.Compute))
{
computeCommandEncoder.UseResource(new MTLResource(mtlTexture.NativePtr), MTLResourceUsage.Read);
resourceIds[resourceIdIndex] = mtlTexture.GpuResourceID._impl;
resourceIdIndex++; resourceIdIndex++;
if (texture.Sampler != null)
{
resourceIds[resourceIdIndex] = texture.Sampler.GetSampler().GpuResourceID._impl;
resourceIdIndex++;
}
} }
} }
} }
else
{
// TODO: Buffer textures
}
} }
else else
{ {