From 49f970d5bd9163e2b4e26a33ef8f84529174d5de Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 25 Oct 2020 17:00:44 -0300 Subject: Implement CAL and RET shader instructions (#1618) * Add support for CAL and RET shader instructions * Remove unused stuff * Fix a bug that could cause the wrong values to be passed to a function * Avoid repopulating function id dictionary every time * PR feedback * Fix vertex shader A/B merge --- .../CodeGen/Glsl/OperandManager.cs | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs') diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs index 459b60c4..14ea7032 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs @@ -3,6 +3,7 @@ using Ryujinx.Graphics.Shader.StructuredIr; using Ryujinx.Graphics.Shader.Translation; using System; using System.Collections.Generic; +using System.Diagnostics; using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo; @@ -96,6 +97,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { switch (operand.Type) { + case OperandType.Argument: + return GetArgumentName(operand.Value); + case OperandType.Attribute: return GetAttributeName(operand, config); @@ -287,7 +291,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl return "xyzw"[value]; } - public static VariableType GetNodeDestType(IAstNode node) + public static string GetArgumentName(int argIndex) + { + return $"{DefaultNames.ArgumentNamePrefix}{argIndex}"; + } + + public static VariableType GetNodeDestType(CodeGenContext context, IAstNode node) { if (node is AstOperation operation) { @@ -298,6 +307,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl { return GetOperandVarType((AstOperand)operation.GetSource(0)); } + else if (operation.Inst == Instruction.Call) + { + AstOperand funcId = (AstOperand)operation.GetSource(0); + + Debug.Assert(funcId.Type == OperandType.Constant); + + return context.GetFunction(funcId.Value).ReturnType; + } else if (operation is AstTextureOperation texOp && (texOp.Inst == Instruction.ImageLoad || texOp.Inst == Instruction.ImageStore)) @@ -309,6 +326,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl } else if (node is AstOperand operand) { + if (operand.Type == OperandType.Argument) + { + int argIndex = operand.Value; + + return context.CurrentFunction.GetArgumentType(argIndex); + } + return GetOperandVarType(operand); } else -- cgit v1.2.3