ShaderConfig.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. namespace Ryujinx.Graphics.Shader.Translation
  3. {
  4. struct ShaderConfig
  5. {
  6. public ShaderStage Stage { get; }
  7. public OutputTopology OutputTopology { get; }
  8. public int MaxOutputVertices { get; }
  9. public int LocalMemorySize { get; }
  10. public OutputMapTarget[] OmapTargets { get; }
  11. public bool OmapSampleMask { get; }
  12. public bool OmapDepth { get; }
  13. public TranslationFlags Flags { get; }
  14. private TranslatorCallbacks _callbacks;
  15. public ShaderConfig(TranslationFlags flags, TranslatorCallbacks callbacks)
  16. {
  17. Stage = ShaderStage.Compute;
  18. OutputTopology = OutputTopology.PointList;
  19. MaxOutputVertices = 0;
  20. LocalMemorySize = 0;
  21. OmapTargets = null;
  22. OmapSampleMask = false;
  23. OmapDepth = false;
  24. Flags = flags;
  25. _callbacks = callbacks;
  26. }
  27. public ShaderConfig(ShaderHeader header, TranslationFlags flags, TranslatorCallbacks callbacks)
  28. {
  29. Stage = header.Stage;
  30. OutputTopology = header.OutputTopology;
  31. MaxOutputVertices = header.MaxOutputVertexCount;
  32. LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
  33. OmapTargets = header.OmapTargets;
  34. OmapSampleMask = header.OmapSampleMask;
  35. OmapDepth = header.OmapDepth;
  36. Flags = flags;
  37. _callbacks = callbacks;
  38. }
  39. public int GetDepthRegister()
  40. {
  41. int count = 0;
  42. for (int index = 0; index < OmapTargets.Length; index++)
  43. {
  44. for (int component = 0; component < 4; component++)
  45. {
  46. if (OmapTargets[index].ComponentEnabled(component))
  47. {
  48. count++;
  49. }
  50. }
  51. }
  52. // The depth register is always two registers after the last color output.
  53. return count + 1;
  54. }
  55. public bool QueryInfoBool(QueryInfoName info, int index = 0)
  56. {
  57. return Convert.ToBoolean(QueryInfo(info, index));
  58. }
  59. public int QueryInfo(QueryInfoName info, int index = 0)
  60. {
  61. if (_callbacks.QueryInfo != null)
  62. {
  63. return _callbacks.QueryInfo(info, index);
  64. }
  65. else
  66. {
  67. switch (info)
  68. {
  69. case QueryInfoName.ComputeLocalSizeX:
  70. case QueryInfoName.ComputeLocalSizeY:
  71. case QueryInfoName.ComputeLocalSizeZ:
  72. return 1;
  73. case QueryInfoName.ComputeLocalMemorySize:
  74. return 0x1000;
  75. case QueryInfoName.ComputeSharedMemorySize:
  76. return 0xc000;
  77. case QueryInfoName.IsTextureBuffer:
  78. return Convert.ToInt32(false);
  79. case QueryInfoName.IsTextureRectangle:
  80. return Convert.ToInt32(false);
  81. case QueryInfoName.PrimitiveTopology:
  82. return (int)InputTopology.Points;
  83. case QueryInfoName.StorageBufferOffsetAlignment:
  84. return 16;
  85. case QueryInfoName.SupportsNonConstantTextureOffset:
  86. return Convert.ToInt32(true);
  87. }
  88. }
  89. return 0;
  90. }
  91. public void PrintLog(string message)
  92. {
  93. _callbacks.PrintLog?.Invoke(message);
  94. }
  95. }
  96. }