Lazy Vertex IO

This commit is contained in:
Isaac Marovitz 2023-10-09 11:49:58 -04:00 committed by Isaac Marovitz
parent 8a058ba9ad
commit 8aea158ca2
3 changed files with 13 additions and 3 deletions

View file

@ -32,8 +32,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
return ioDefinition.StorageKind == storageKind && ioDefinition.IoVariable == IoVariable.UserDefined;
}
public static void DeclareLocals(CodeGenContext context, StructuredFunction function)
public static void DeclareLocals(CodeGenContext context, StructuredFunction function, ShaderStage stage)
{
if (stage == ShaderStage.Vertex)
{
context.AppendLine("VertexOutput out;");
}
foreach (AstOperand decl in function.Locals)
{
string name = context.OperandManager.DeclareLocal(decl);

View file

@ -69,6 +69,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions
if (inst == Instruction.Return && operation.SourcesCount != 0)
{
return $"{op} {GetSourceExpr(context, operation.GetSource(0), context.CurrentFunction.ReturnType)}";
} else if (inst == Instruction.Return && context.Definitions.Stage == ShaderStage.Vertex)
{
return $"{op} out";
}
int arity = (int)(info.Type & InstType.ArityMask);

View file

@ -51,7 +51,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
context.AppendLine(GetFunctionSignature(context, function, stage, isMainFunc));
context.EnterScope();
Declarations.DeclareLocals(context, function);
Declarations.DeclareLocals(context, function, stage);
PrintBlock(context, function.MainBlock, isMainFunc);
@ -77,6 +77,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
string funcKeyword = "inline";
string funcName = null;
string returnType = Declarations.GetVarTypeName(context, function.ReturnType);
if (isMainFunc)
{
@ -84,6 +85,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
{
funcKeyword = "vertex";
funcName = "vertexMain";
returnType = "VertexOutput";
}
else if (stage == ShaderStage.Fragment)
{
@ -112,7 +114,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
}
}
return $"{funcKeyword} {Declarations.GetVarTypeName(context, function.ReturnType)} {funcName ?? function.Name}({string.Join(", ", args)})";
return $"{funcKeyword} {returnType} {funcName ?? function.Name}({string.Join(", ", args)})";
}
private static void PrintBlock(CodeGenContext context, AstBlock block, bool isMainFunction)