1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-18 18:42:03 +00:00

IaIndexing

Fixes shader problems in Donkey Kong Country Tropical Freeze, and Fire Emblem: Three Houses
This commit is contained in:
Isaac Marovitz 2024-08-11 20:29:08 +01:00 committed by Isaac Marovitz
parent bdb00f3981
commit fc581cf707
3 changed files with 175 additions and 144 deletions

View file

@ -76,7 +76,7 @@ namespace Ryujinx.Graphics.Metal
return;
}
switch (_shaders[index].Stage)
switch (shader.Stage)
{
case ShaderStage.Compute:
ComputeFunction = library.NewFunction(StringHelper.NSString("kernelMain"));
@ -88,7 +88,7 @@ namespace Ryujinx.Graphics.Metal
FragmentFunction = library.NewFunction(StringHelper.NSString("fragmentMain"));
break;
default:
Logger.Warning?.Print(LogClass.Gpu, $"Cannot handle stage {_shaders[index].Stage}!");
Logger.Warning?.Print(LogClass.Gpu, $"Cannot handle stage {shader.Stage}!");
break;
}

View file

@ -60,9 +60,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
return _sb.ToString();
}
public void EnterScope()
public void EnterScope(string prefix = "")
{
AppendLine("{");
AppendLine(prefix + "{");
_level++;

View file

@ -139,6 +139,19 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
{
if (isMainFunc)
{
// TODO: Support OaIndexing
if (context.Definitions.IaIndexing)
{
context.EnterScope($"array<float4, {Constants.MaxAttributes}> {Defaults.IAttributePrefix} = ");
for (int i = 0; i < Constants.MaxAttributes; i++)
{
context.AppendLine($"in.{Defaults.IAttributePrefix}{i},");
}
context.LeaveScope(";");
}
DeclareMemories(context, context.Properties.LocalMemories.Values, isShared: false);
DeclareMemories(context, context.Properties.SharedMemories.Values, isShared: true);
@ -356,23 +369,18 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
private static void DeclareInputAttributes(CodeGenContext context, IEnumerable<IoDefinition> inputs)
{
if (context.Definitions.IaIndexing)
if (context.Definitions.Stage == ShaderStage.Compute)
{
Logger.Warning?.PrintMsg(LogClass.Gpu, "Unhandled IA Indexing!");
return;
}
else
{
if (inputs.Any() || context.Definitions.Stage != ShaderStage.Compute)
{
string prefix = "";
switch (context.Definitions.Stage)
{
case ShaderStage.Vertex:
context.AppendLine($"struct VertexIn");
context.AppendLine("struct VertexIn");
break;
case ShaderStage.Fragment:
context.AppendLine($"struct FragmentIn");
context.AppendLine("struct FragmentIn");
break;
}
@ -386,8 +394,26 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine("float2 point_coord [[point_coord]];");
}
if (context.Definitions.IaIndexing)
{
// MSL does not support arrays in stage I/O
// We need to use the SPIRV-Cross workaround
for (int i = 0; i < Constants.MaxAttributes; i++)
{
var suffix = context.Definitions.Stage == ShaderStage.Fragment ? $"[[user(loc{i})]]" : $"[[attribute({i})]]";
context.AppendLine($"float4 {Defaults.IAttributePrefix}{i} {suffix};");
}
}
if (inputs.Any())
{
foreach (var ioDefinition in inputs.OrderBy(x => x.Location))
{
if (context.Definitions.IaIndexing && ioDefinition.IoVariable == IoVariable.UserDefined)
{
continue;
}
string iq = string.Empty;
if (context.Definitions.Stage == ShaderStage.Fragment)
@ -432,39 +458,40 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine($"{type} {name} {iq}{suffix};");
}
}
context.LeaveScope(";");
}
}
}
private static void DeclareOutputAttributes(CodeGenContext context, IEnumerable<IoDefinition> outputs)
{
if (context.Definitions.OaIndexing)
{
Logger.Warning?.PrintMsg(LogClass.Gpu, "Unhandled OA Indexing!");
}
else
{
if (outputs.Any() || context.Definitions.Stage == ShaderStage.Fragment)
{
string prefix = "";
switch (context.Definitions.Stage)
{
case ShaderStage.Vertex:
context.AppendLine($"struct VertexOut");
context.AppendLine("struct VertexOut");
break;
case ShaderStage.Fragment:
context.AppendLine($"struct FragmentOut");
context.AppendLine("struct FragmentOut");
break;
case ShaderStage.Compute:
context.AppendLine($"struct KernelOut");
context.AppendLine("struct KernelOut");
break;
}
context.EnterScope();
if (context.Definitions.OaIndexing)
{
// MSL does not support arrays in stage I/O
// We need to use the SPIRV-Cross workaround
for (int i = 0; i < Constants.MaxAttributes; i++)
{
context.AppendLine($"float4 {Defaults.OAttributePrefix}{i} [[user(loc{i})]];");
}
}
if (outputs.Any())
{
outputs = outputs.OrderBy(x => x.Location);
if (context.Definitions.Stage == ShaderStage.Fragment && context.Definitions.DualSourceBlend)
@ -486,6 +513,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
foreach (var ioDefinition in outputs)
{
if (context.Definitions.OaIndexing && ioDefinition.IoVariable == IoVariable.UserDefined)
{
continue;
}
string type = ioDefinition.IoVariable switch
{
IoVariable.Position => "float4",
@ -517,11 +549,10 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine($"{type} {name} {suffix};");
}
}
context.LeaveScope(";");
}
}
}
private static void AppendHelperFunction(CodeGenContext context, string filename)
{