EmitterContext.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using Ryujinx.Graphics.Shader.Decoders;
  2. using Ryujinx.Graphics.Shader.IntermediateRepresentation;
  3. using System.Collections.Generic;
  4. using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
  5. namespace Ryujinx.Graphics.Shader.Translation
  6. {
  7. class EmitterContext
  8. {
  9. public Block CurrBlock { get; set; }
  10. public OpCode CurrOp { get; set; }
  11. private ShaderConfig _config;
  12. private List<Operation> _operations;
  13. private Dictionary<ulong, Operand> _labels;
  14. public EmitterContext(ShaderConfig config)
  15. {
  16. _config = config;
  17. _operations = new List<Operation>();
  18. _labels = new Dictionary<ulong, Operand>();
  19. }
  20. public Operand Add(Instruction inst, Operand dest = null, params Operand[] sources)
  21. {
  22. Operation operation = new Operation(inst, dest, sources);
  23. Add(operation);
  24. return dest;
  25. }
  26. public void Add(Operation operation)
  27. {
  28. _operations.Add(operation);
  29. }
  30. public void MarkLabel(Operand label)
  31. {
  32. Add(Instruction.MarkLabel, label);
  33. }
  34. public Operand GetLabel(ulong address)
  35. {
  36. if (!_labels.TryGetValue(address, out Operand label))
  37. {
  38. label = Label();
  39. _labels.Add(address, label);
  40. }
  41. return label;
  42. }
  43. public void PrepareForReturn()
  44. {
  45. if (_config.Stage == ShaderStage.Fragment)
  46. {
  47. if (_config.OmapDepth)
  48. {
  49. Operand dest = Attribute(AttributeConsts.FragmentOutputDepth);
  50. Operand src = Register(_config.GetDepthRegister(), RegisterType.Gpr);
  51. this.Copy(dest, src);
  52. }
  53. int regIndex = 0;
  54. for (int attachment = 0; attachment < 8; attachment++)
  55. {
  56. OutputMapTarget target = _config.OmapTargets[attachment];
  57. for (int component = 0; component < 4; component++)
  58. {
  59. if (target.ComponentEnabled(component))
  60. {
  61. Operand dest = Attribute(AttributeConsts.FragmentOutputColorBase + regIndex * 4);
  62. Operand src = Register(regIndex, RegisterType.Gpr);
  63. this.Copy(dest, src);
  64. regIndex++;
  65. }
  66. }
  67. }
  68. }
  69. }
  70. public Operation[] GetOperations()
  71. {
  72. return _operations.ToArray();
  73. }
  74. }
  75. }