Compare commits

..

1 commit

Author SHA1 Message Date
Isaac Marovitz
a285136c1b
Merge 66d4257740 into 6ce49a2dc7 2024-07-26 16:12:40 +00:00
3 changed files with 130 additions and 54 deletions

View file

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

View file

@ -805,9 +805,13 @@ namespace Ryujinx.Graphics.Metal
public readonly void UpdateTextureAndSampler(ShaderStage stage, ulong binding, TextureBase texture, Sampler sampler)
{
if (texture != null)
if (texture is TextureBuffer)
{
_currentState.TextureRefs[binding] = new(stage, texture, sampler);
// TODO: Texture buffers
}
else if (texture is Texture view)
{
_currentState.TextureRefs[binding] = new(stage, view, sampler);
}
else
{
@ -1119,6 +1123,8 @@ namespace Ryujinx.Graphics.Metal
break;
case MetalRenderer.TextureSetIndex:
if (!segment.IsArray)
{
if (segment.Type != ResourceType.BufferTexture)
{
for (int i = 0; i < count; i++)
{
@ -1169,6 +1175,11 @@ namespace Ryujinx.Graphics.Metal
}
}
else
{
// TODO: Buffer textures
}
}
else
{
// TODO: Texture arrays
}
@ -1331,6 +1342,8 @@ namespace Ryujinx.Graphics.Metal
break;
case MetalRenderer.TextureSetIndex:
if (!segment.IsArray)
{
if (segment.Type != ResourceType.BufferTexture)
{
for (int i = 0; i < count; i++)
{
@ -1362,6 +1375,11 @@ namespace Ryujinx.Graphics.Metal
}
}
else
{
// TODO: Buffer textures
}
}
else
{
// TODO: Texture arrays
}

View file

@ -28,6 +28,7 @@ namespace Ryujinx.Graphics.Metal
private MTLComputePipelineState? _computePipelineCache;
private bool _firstBackgroundUse;
public ResourceBindingSegment[][] ClearSegments { get; }
public ResourceBindingSegment[][] BindingSegments { get; }
// Argument buffer sizes for Vertex or Compute stages
public int[] ArgumentBufferSizes { get; }
@ -52,6 +53,7 @@ namespace Ryujinx.Graphics.Metal
_handles[i] = device.NewLibrary(StringHelper.NSString(shader.Code), compileOptions, (library, error) => CompilationResultHandler(library, error, index));
}
ClearSegments = BuildClearSegments(resourceLayout.Sets);
(BindingSegments, ArgumentBufferSizes, FragArgumentBufferSizes) = BuildBindingSegments(resourceLayout.SetUsages);
}
@ -96,6 +98,62 @@ namespace Ryujinx.Graphics.Metal
}
}
private static ResourceBindingSegment[][] BuildClearSegments(ReadOnlyCollection<ResourceDescriptorCollection> sets)
{
ResourceBindingSegment[][] segments = new ResourceBindingSegment[sets.Count][];
for (int setIndex = 0; setIndex < sets.Count; setIndex++)
{
List<ResourceBindingSegment> currentSegments = new();
ResourceDescriptor currentDescriptor = default;
int currentCount = 0;
for (int index = 0; index < sets[setIndex].Descriptors.Count; index++)
{
ResourceDescriptor descriptor = sets[setIndex].Descriptors[index];
if (currentDescriptor.Binding + currentCount != descriptor.Binding ||
currentDescriptor.Type != descriptor.Type ||
currentDescriptor.Stages != descriptor.Stages ||
currentDescriptor.Count > 1 ||
descriptor.Count > 1)
{
if (currentCount != 0)
{
currentSegments.Add(new ResourceBindingSegment(
currentDescriptor.Binding,
currentCount,
currentDescriptor.Type,
currentDescriptor.Stages,
currentDescriptor.Count > 1));
}
currentDescriptor = descriptor;
currentCount = descriptor.Count;
}
else
{
currentCount += descriptor.Count;
}
}
if (currentCount != 0)
{
currentSegments.Add(new ResourceBindingSegment(
currentDescriptor.Binding,
currentCount,
currentDescriptor.Type,
currentDescriptor.Stages,
currentDescriptor.Count > 1));
}
segments[setIndex] = currentSegments.ToArray();
}
return segments;
}
private static (ResourceBindingSegment[][], int[], int[]) BuildBindingSegments(ReadOnlyCollection<ResourceUsageCollection> setUsages)
{
ResourceBindingSegment[][] segments = new ResourceBindingSegment[setUsages.Count][];