BindlessElimination.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using System.Collections.Generic;
  3. namespace Ryujinx.Graphics.Shader.Translation.Optimizations
  4. {
  5. class BindlessElimination
  6. {
  7. public static void RunPass(BasicBlock block)
  8. {
  9. // We can turn a bindless into regular access by recognizing the pattern
  10. // produced by the compiler for separate texture and sampler.
  11. // We check for the following conditions:
  12. // - The handle is the result of a bitwise OR logical operation.
  13. // - Both sources of the OR operation comes from CB2 (used by NVN to hold texture handles).
  14. for (LinkedListNode<INode> node = block.Operations.First; node != null; node = node.Next)
  15. {
  16. if (!(node.Value is TextureOperation texOp))
  17. {
  18. continue;
  19. }
  20. if ((texOp.Flags & TextureFlags.Bindless) == 0)
  21. {
  22. continue;
  23. }
  24. if (!(texOp.GetSource(0).AsgOp is Operation handleCombineOp))
  25. {
  26. continue;
  27. }
  28. if (handleCombineOp.Inst != Instruction.BitwiseOr)
  29. {
  30. continue;
  31. }
  32. Operand src0 = handleCombineOp.GetSource(0);
  33. Operand src1 = handleCombineOp.GetSource(1);
  34. if (src0.Type != OperandType.ConstantBuffer || src0.GetCbufSlot() != 2 ||
  35. src1.Type != OperandType.ConstantBuffer || src1.GetCbufSlot() != 2)
  36. {
  37. continue;
  38. }
  39. texOp.SetHandle(src0.GetCbufOffset() | (src1.GetCbufOffset() << 16));
  40. }
  41. }
  42. }
  43. }