ShaderConfig.cs 3.9 KB

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