InstGenVector.cs
1 using Ryujinx.Graphics.Shader.IntermediateRepresentation; 2 using Ryujinx.Graphics.Shader.StructuredIr; 3 4 using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenHelper; 5 using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo; 6 7 namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions 8 { 9 static class InstGenVector 10 { 11 public static string VectorExtract(CodeGenContext context, AstOperation operation) 12 { 13 IAstNode vector = operation.GetSource(0); 14 IAstNode index = operation.GetSource(1); 15 16 string vectorExpr = GetSourceExpr(context, vector, OperandManager.GetNodeDestType(context, vector)); 17 18 if (index is AstOperand indexOperand && indexOperand.Type == OperandType.Constant) 19 { 20 char elem = "xyzw"[indexOperand.Value]; 21 22 return $"{vectorExpr}.{elem}"; 23 } 24 else 25 { 26 string indexExpr = GetSourceExpr(context, index, GetSrcVarType(operation.Inst, 1)); 27 28 return $"{vectorExpr}[{indexExpr}]"; 29 } 30 } 31 } 32 }