InstGenVector.cs 1.1 KB

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