Metal: Better Bindings (#29)
* Tell GAL to use Vk model (and break everything) * ResourceBindingSegments * Set information on backend caps * Get ready to break everything * Refactor EncoderStateManager * Remove padding from helper shaders * Fix ref array sizes * Seperate vert & frag buffers * Shader-side changes * Fixes * Fix some helper shader resource layouts * Sort by binding id * Fix helper shader layouts * Don’t do inline vertex buffer updates * Check for null storage
This commit is contained in:
parent
971c270bcf
commit
daee63c451
12 changed files with 709 additions and 453 deletions
|
@ -164,16 +164,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
|||
private static void DeclareBufferStructures(CodeGenContext context, IEnumerable<BufferDefinition> buffers, bool constant)
|
||||
{
|
||||
var name = constant ? "ConstantBuffers" : "StorageBuffers";
|
||||
var count = constant ? Defaults.MaxUniformBuffersPerStage : Defaults.MaxStorageBuffersPerStage;
|
||||
var addressSpace = constant ? "constant" : "device";
|
||||
|
||||
var argBufferPointers = new string[count];
|
||||
List<string> argBufferPointers = [];
|
||||
|
||||
foreach (BufferDefinition buffer in buffers)
|
||||
// TODO: Avoid Linq if we can
|
||||
var sortedBuffers = buffers.OrderBy(x => x.Binding).ToArray();
|
||||
|
||||
foreach (BufferDefinition buffer in sortedBuffers)
|
||||
{
|
||||
var needsPadding = buffer.Layout == BufferLayout.Std140;
|
||||
|
||||
argBufferPointers[buffer.Binding] = $"{addressSpace} {Defaults.StructPrefix}_{buffer.Name}* {buffer.Name};";
|
||||
argBufferPointers.Add($"{addressSpace} {Defaults.StructPrefix}_{buffer.Name}* {buffer.Name};");
|
||||
|
||||
context.AppendLine($"struct {Defaults.StructPrefix}_{buffer.Name}");
|
||||
context.EnterScope();
|
||||
|
@ -211,18 +213,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
|||
context.AppendLine($"struct {name}");
|
||||
context.EnterScope();
|
||||
|
||||
for (int i = 0; i < argBufferPointers.Length; i++)
|
||||
foreach (var pointer in argBufferPointers)
|
||||
{
|
||||
if (argBufferPointers[i] == null)
|
||||
{
|
||||
// We need to pad the struct definition in order to read
|
||||
// non-contiguous resources correctly.
|
||||
context.AppendLine($"ulong padding_{i};");
|
||||
}
|
||||
else
|
||||
{
|
||||
context.AppendLine(argBufferPointers[i]);
|
||||
}
|
||||
context.AppendLine(pointer);
|
||||
}
|
||||
|
||||
context.LeaveScope(";");
|
||||
|
@ -234,31 +227,25 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
|||
context.AppendLine("struct Textures");
|
||||
context.EnterScope();
|
||||
|
||||
var argBufferPointers = new string[Defaults.MaxTexturesPerStage * 2];
|
||||
List<string> argBufferPointers = [];
|
||||
|
||||
foreach (TextureDefinition texture in textures)
|
||||
// TODO: Avoid Linq if we can
|
||||
var sortedTextures = textures.OrderBy(x => x.Binding).ToArray();
|
||||
|
||||
foreach (TextureDefinition texture in sortedTextures)
|
||||
{
|
||||
var textureTypeName = texture.Type.ToMslTextureType();
|
||||
argBufferPointers[texture.Binding] = $"{textureTypeName} tex_{texture.Name};";
|
||||
argBufferPointers.Add($"{textureTypeName} tex_{texture.Name};");
|
||||
|
||||
if (!texture.Separate && texture.Type != SamplerType.TextureBuffer)
|
||||
{
|
||||
argBufferPointers[Defaults.MaxTexturesPerStage + texture.Binding] = $"sampler samp_{texture.Name};";
|
||||
argBufferPointers.Add($"sampler samp_{texture.Name};");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < argBufferPointers.Length; i++)
|
||||
foreach (var pointer in argBufferPointers)
|
||||
{
|
||||
if (argBufferPointers[i] == null)
|
||||
{
|
||||
// We need to pad the struct definition in order to read
|
||||
// non-contiguous resources correctly.
|
||||
context.AppendLine($"ulong padding_{i};");
|
||||
}
|
||||
else
|
||||
{
|
||||
context.AppendLine(argBufferPointers[i]);
|
||||
}
|
||||
context.AppendLine(pointer);
|
||||
}
|
||||
|
||||
context.LeaveScope(";");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue