SwizzleAdd (NOT TESTED)

This commit is contained in:
Isaac Marovitz 2024-07-24 15:43:53 +01:00
parent b4cf2d1cc9
commit 1bb3f28504
No known key found for this signature in database
GPG Key ID: 97250B2B09A132E1
6 changed files with 21 additions and 8 deletions

View File

@ -65,11 +65,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine("using namespace metal;");
context.AppendLine();
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
{
}
DeclareInputAttributes(context, info.IoDefinitions.Where(x => IsUserDefined(x, StorageKind.Input)));
context.AppendLine();
DeclareOutputAttributes(context, info.IoDefinitions.Where(x => x.StorageKind == StorageKind.Output));
@ -93,6 +88,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
{
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Msl/HelperFunctions/FindMSBU32.metal");
}
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
{
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Msl/HelperFunctions/SwizzleAdd.metal");
}
}
static bool IsUserDefined(IoDefinition ioDefinition, StorageKind storageKind)

View File

@ -5,5 +5,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
public static string FindLSB = "findLSB";
public static string FindMSBS32 = "findMSBS32";
public static string FindMSBU32 = "findMSBU32";
public static string SwizzleAdd = "swizzleAdd";
}
}

View File

@ -0,0 +1,7 @@
float swizzleAdd(float x, float y, int mask, uint thread_index_in_simdgroup)
{
float4 xLut = float4(1.0, -1.0, 1.0, 0.0);
float4 yLut = float4(1.0, 1.0, -1.0, 1.0);
int lutIdx = (mask >> (int(thread_index_in_simdgroup & 3u) * 2)) & 3;
return x * xLut[lutIdx] + y * yLut[lutIdx];
}

View File

@ -69,6 +69,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
builder.Append(GetSourceExpr(context, operation.GetSource(argIndex), dstType));
}
if ((operation.Inst & Instruction.Mask) == Instruction.SwizzleAdd)
{
// SwizzleAdd takes one last argument, the thread_index_in_simdgroup
builder.Append(", thread_index_in_simdgroup");
}
}
return $"{info.OpName}({builder})";
@ -142,8 +148,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
return Lod(context, operation);
case Instruction.Store:
return Store(context, operation);
case Instruction.SwizzleAdd:
return "|| SWIZZLE ADD ||";
case Instruction.TextureSample:
return TextureSample(context, operation);
case Instruction.TextureQuerySamples:

View File

@ -116,7 +116,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
Add(Instruction.SquareRoot, InstType.CallUnary, "sqrt");
Add(Instruction.Store, InstType.Special);
Add(Instruction.Subtract, InstType.OpBinary, "-", 2);
Add(Instruction.SwizzleAdd, InstType.Special);
Add(Instruction.SwizzleAdd, InstType.CallTernary, HelperFunctionNames.SwizzleAdd);
Add(Instruction.TextureSample, InstType.Special);
Add(Instruction.TextureQuerySamples, InstType.Special);
Add(Instruction.TextureQuerySize, InstType.Special);

View File

@ -19,5 +19,6 @@
<EmbeddedResource Include="CodeGen\Msl\HelperFunctions\FindLSB.metal" />
<EmbeddedResource Include="CodeGen\Msl\HelperFunctions\FindMSBS32.metal" />
<EmbeddedResource Include="CodeGen\Msl\HelperFunctions\FindMSBU32.metal" />
<EmbeddedResource Include="CodeGen\Msl\HelperFunctions\SwizzleAdd.metal" />
</ItemGroup>
</Project>