AstOperation.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  2. using Ryujinx.Graphics.Shader.Translation;
  3. using System.Numerics;
  4. using static Ryujinx.Graphics.Shader.StructuredIr.AstHelper;
  5. namespace Ryujinx.Graphics.Shader.StructuredIr
  6. {
  7. class AstOperation : AstNode
  8. {
  9. public Instruction Inst { get; }
  10. public StorageKind StorageKind { get; }
  11. public int Index { get; }
  12. private IAstNode[] _sources;
  13. public int SourcesCount => _sources.Length;
  14. public AstOperation(Instruction inst, StorageKind storageKind, IAstNode[] sources, int sourcesCount)
  15. {
  16. Inst = inst;
  17. StorageKind = storageKind;
  18. _sources = sources;
  19. for (int index = 0; index < sources.Length; index++)
  20. {
  21. if (index < sourcesCount)
  22. {
  23. AddUse(sources[index], this);
  24. }
  25. else
  26. {
  27. AddDef(sources[index], this);
  28. }
  29. }
  30. Index = 0;
  31. }
  32. public AstOperation(Instruction inst, StorageKind storageKind, int index, IAstNode[] sources, int sourcesCount) : this(inst, storageKind, sources, sourcesCount)
  33. {
  34. Index = index;
  35. }
  36. public AstOperation(Instruction inst, params IAstNode[] sources) : this(inst, StorageKind.None, sources, sources.Length)
  37. {
  38. }
  39. public IAstNode GetSource(int index)
  40. {
  41. return _sources[index];
  42. }
  43. public void SetSource(int index, IAstNode source)
  44. {
  45. RemoveUse(_sources[index], this);
  46. AddUse(source, this);
  47. _sources[index] = source;
  48. }
  49. public AggregateType GetVectorType(AggregateType scalarType)
  50. {
  51. int componentsCount = BitOperations.PopCount((uint)Index);
  52. AggregateType type = scalarType;
  53. switch (componentsCount)
  54. {
  55. case 2: type |= AggregateType.Vector2; break;
  56. case 3: type |= AggregateType.Vector3; break;
  57. case 4: type |= AggregateType.Vector4; break;
  58. }
  59. return type;
  60. }
  61. }
  62. }