InstGenPacking.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Ryujinx.Graphics.Shader.StructuredIr;
  2. using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenHelper;
  3. using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo;
  4. namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
  5. {
  6. static class InstGenPacking
  7. {
  8. public static string PackDouble2x32(CodeGenContext context, AstOperation operation)
  9. {
  10. IAstNode src0 = operation.GetSource(0);
  11. IAstNode src1 = operation.GetSource(1);
  12. string src0Expr = GetSoureExpr(context, src0, GetSrcVarType(operation.Inst, 0));
  13. string src1Expr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 1));
  14. return $"packDouble2x32(uvec2({src0Expr}, {src1Expr}))";
  15. }
  16. public static string PackHalf2x16(CodeGenContext context, AstOperation operation)
  17. {
  18. IAstNode src0 = operation.GetSource(0);
  19. IAstNode src1 = operation.GetSource(1);
  20. string src0Expr = GetSoureExpr(context, src0, GetSrcVarType(operation.Inst, 0));
  21. string src1Expr = GetSoureExpr(context, src1, GetSrcVarType(operation.Inst, 1));
  22. return $"packHalf2x16(vec2({src0Expr}, {src1Expr}))";
  23. }
  24. public static string UnpackDouble2x32(CodeGenContext context, AstOperation operation)
  25. {
  26. IAstNode src = operation.GetSource(0);
  27. string srcExpr = GetSoureExpr(context, src, GetSrcVarType(operation.Inst, 0));
  28. return $"unpackDouble2x32({srcExpr}){GetMask(operation.Index)}";
  29. }
  30. public static string UnpackHalf2x16(CodeGenContext context, AstOperation operation)
  31. {
  32. IAstNode src = operation.GetSource(0);
  33. string srcExpr = GetSoureExpr(context, src, GetSrcVarType(operation.Inst, 0));
  34. return $"unpackHalf2x16({srcExpr}){GetMask(operation.Index)}";
  35. }
  36. private static string GetMask(int index)
  37. {
  38. return '.' + "xy".Substring(index, 1);
  39. }
  40. }
  41. }