Lazy Vertex IO

This commit is contained in:
Isaac Marovitz 2023-10-09 11:49:58 -04:00 committed by Isaac Marovitz
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; 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) foreach (AstOperand decl in function.Locals)
{ {
string name = context.OperandManager.DeclareLocal(decl); 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) if (inst == Instruction.Return && operation.SourcesCount != 0)
{ {
return $"{op} {GetSourceExpr(context, operation.GetSource(0), context.CurrentFunction.ReturnType)}"; 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); 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.AppendLine(GetFunctionSignature(context, function, stage, isMainFunc));
context.EnterScope(); context.EnterScope();
Declarations.DeclareLocals(context, function); Declarations.DeclareLocals(context, function, stage);
PrintBlock(context, function.MainBlock, isMainFunc); PrintBlock(context, function.MainBlock, isMainFunc);
@ -77,6 +77,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
string funcKeyword = "inline"; string funcKeyword = "inline";
string funcName = null; string funcName = null;
string returnType = Declarations.GetVarTypeName(context, function.ReturnType);
if (isMainFunc) if (isMainFunc)
{ {
@ -84,6 +85,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
{ {
funcKeyword = "vertex"; funcKeyword = "vertex";
funcName = "vertexMain"; funcName = "vertexMain";
returnType = "VertexOutput";
} }
else if (stage == ShaderStage.Fragment) 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) private static void PrintBlock(CodeGenContext context, AstBlock block, bool isMainFunction)