FSI (with raster order groups)

This commit is contained in:
Isaac Marovitz 2024-07-24 16:25:03 +01:00
parent 1bb3f28504
commit 6be0890f34
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
3 changed files with 15 additions and 11 deletions

View File

@ -65,14 +65,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine("using namespace metal;");
context.AppendLine();
var fsi = (info.HelperFunctionsMask & HelperFunctionsMask.FSI) != 0;
DeclareInputAttributes(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.Input)));
context.AppendLine();
DeclareOutputAttributes(context, info.IoDefinitions.Where(x => x.StorageKind == StorageKind.Output));
context.AppendLine();
DeclareBufferStructures(context, context.Properties.ConstantBuffers.Values, true);
DeclareBufferStructures(context, context.Properties.StorageBuffers.Values, false);
DeclareBufferStructures(context, context.Properties.ConstantBuffers.Values, true, fsi);
DeclareBufferStructures(context, context.Properties.StorageBuffers.Values, false, fsi);
DeclareTextures(context, context.Properties.Textures.Values);
DeclareImages(context, context.Properties.Images.Values);
DeclareImages(context, context.Properties.Images.Values, fsi);
if ((info.HelperFunctionsMask & HelperFunctionsMask.FindLSB) != 0)
{
@ -180,7 +182,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
}
}
private static void DeclareBufferStructures(CodeGenContext context, IEnumerable<BufferDefinition> buffers, bool constant)
private static void DeclareBufferStructures(CodeGenContext context, IEnumerable<BufferDefinition> buffers, bool constant, bool fsi)
{
var name = constant ? "ConstantBuffers" : "StorageBuffers";
var addressSpace = constant ? "constant" : "device";
@ -193,8 +195,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
foreach (BufferDefinition buffer in sortedBuffers)
{
var needsPadding = buffer.Layout == BufferLayout.Std140;
string fsiSuffix = constant && fsi ? " [[raster_order_group(0)]]" : "";
argBufferPointers.Add($"{addressSpace} {Defaults.StructPrefix}_{buffer.Name}* {buffer.Name};");
argBufferPointers.Add($"{addressSpace} {Defaults.StructPrefix}_{buffer.Name}* {buffer.Name}{fsiSuffix};");
context.AppendLine($"struct {Defaults.StructPrefix}_{buffer.Name}");
context.EnterScope();
@ -271,7 +274,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine();
}
private static void DeclareImages(CodeGenContext context, IEnumerable<TextureDefinition> images)
private static void DeclareImages(CodeGenContext context, IEnumerable<TextureDefinition> images, bool fsi)
{
context.AppendLine("struct Images");
context.EnterScope();
@ -284,7 +287,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
foreach (TextureDefinition image in sortedImages)
{
var imageTypeName = image.Type.ToMslTextureType(true);
argBufferPointers.Add($"{imageTypeName} {image.Name};");
string fsiSuffix = fsi ? " [[raster_order_group(0)]]" : "";
argBufferPointers.Add($"{imageTypeName} {image.Name}{fsiSuffix};");
}
foreach (var pointer in argBufferPointers)

View File

@ -131,9 +131,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
case Instruction.Call:
return Call(context, operation);
case Instruction.FSIBegin:
return "|| FSI BEGIN ||";
case Instruction.FSIEnd:
return "|| FSI END ||";
return "// FSI implemented with raster order groups in MSL";
case Instruction.GroupMemoryBarrier:
case Instruction.MemoryBarrier:
case Instruction.Barrier:

View File

@ -164,8 +164,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
public static bool NeedsParenthesis(IAstNode node, Instruction pInst, InstInfo pInfo, bool isLhs)
{
// If the node isn't a operation, then it can only be a operand,
// and those never needs to be surrounded in parenthesis.
// If the node isn't an operation, then it can only be an operand,
// and those never needs to be surrounded in parentheses.
if (node is not AstOperation operation)
{
// This is sort of a special case, if this is a negative constant,