StructuredProgramInfo.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections.Generic;
  2. namespace Ryujinx.Graphics.Shader.StructuredIr
  3. {
  4. readonly struct TransformFeedbackOutput
  5. {
  6. public readonly bool Valid;
  7. public readonly int Buffer;
  8. public readonly int Offset;
  9. public readonly int Stride;
  10. public TransformFeedbackOutput(int buffer, int offset, int stride)
  11. {
  12. Valid = true;
  13. Buffer = buffer;
  14. Offset = offset;
  15. Stride = stride;
  16. }
  17. }
  18. class StructuredProgramInfo
  19. {
  20. public List<StructuredFunction> Functions { get; }
  21. public HashSet<int> Inputs { get; }
  22. public HashSet<int> Outputs { get; }
  23. public HashSet<int> InputsPerPatch { get; }
  24. public HashSet<int> OutputsPerPatch { get; }
  25. public HelperFunctionsMask HelperFunctionsMask { get; set; }
  26. public TransformFeedbackOutput[] TransformFeedbackOutputs { get; }
  27. public StructuredProgramInfo()
  28. {
  29. Functions = new List<StructuredFunction>();
  30. Inputs = new HashSet<int>();
  31. Outputs = new HashSet<int>();
  32. InputsPerPatch = new HashSet<int>();
  33. OutputsPerPatch = new HashSet<int>();
  34. TransformFeedbackOutputs = new TransformFeedbackOutput[0xc0];
  35. }
  36. public TransformFeedbackOutput GetTransformFeedbackOutput(int attr)
  37. {
  38. int index = attr / 4;
  39. return TransformFeedbackOutputs[index];
  40. }
  41. public int GetTransformFeedbackOutputComponents(int attr)
  42. {
  43. int index = attr / 4;
  44. int baseIndex = index & ~3;
  45. int count = 1;
  46. for (; count < 4; count++)
  47. {
  48. ref var prev = ref TransformFeedbackOutputs[baseIndex + count - 1];
  49. ref var curr = ref TransformFeedbackOutputs[baseIndex + count];
  50. int prevOffset = prev.Offset;
  51. int currOffset = curr.Offset;
  52. if (!prev.Valid || !curr.Valid || prevOffset + 4 != currOffset)
  53. {
  54. break;
  55. }
  56. }
  57. if (baseIndex + count <= index)
  58. {
  59. return 1;
  60. }
  61. return count;
  62. }
  63. }
  64. }