ShaderConfig.cs 3.5 KB

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