Operand.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Ryujinx.Graphics.Shader.Decoders;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Graphics.Shader.IntermediateRepresentation
  5. {
  6. class Operand
  7. {
  8. private const int CbufSlotBits = 5;
  9. private const int CbufSlotLsb = 32 - CbufSlotBits;
  10. private const int CbufSlotMask = (1 << CbufSlotBits) - 1;
  11. public OperandType Type { get; }
  12. public int Value { get; }
  13. public InterpolationQualifier Interpolation { get; }
  14. public INode AsgOp { get; set; }
  15. public HashSet<INode> UseOps { get; }
  16. private Operand()
  17. {
  18. UseOps = new HashSet<INode>();
  19. }
  20. public Operand(OperandType type) : this()
  21. {
  22. Type = type;
  23. }
  24. public Operand(OperandType type, int value, InterpolationQualifier iq = InterpolationQualifier.None) : this()
  25. {
  26. Type = type;
  27. Value = value;
  28. Interpolation = iq;
  29. }
  30. public Operand(Register reg) : this()
  31. {
  32. Type = OperandType.Register;
  33. Value = PackRegInfo(reg.Index, reg.Type);
  34. }
  35. public Operand(int slot, int offset) : this()
  36. {
  37. Type = OperandType.ConstantBuffer;
  38. Value = PackCbufInfo(slot, offset);
  39. }
  40. private static int PackCbufInfo(int slot, int offset)
  41. {
  42. return (slot << CbufSlotLsb) | offset;
  43. }
  44. private static int PackRegInfo(int index, RegisterType type)
  45. {
  46. return ((int)type << 24) | index;
  47. }
  48. public int GetCbufSlot()
  49. {
  50. return (Value >> CbufSlotLsb) & CbufSlotMask;
  51. }
  52. public int GetCbufOffset()
  53. {
  54. return Value & ~(CbufSlotMask << CbufSlotLsb);
  55. }
  56. public Register GetRegister()
  57. {
  58. return new Register(Value & 0xffffff, (RegisterType)(Value >> 24));
  59. }
  60. public float AsFloat()
  61. {
  62. return BitConverter.Int32BitsToSingle(Value);
  63. }
  64. }
  65. }