ShaderConfig.cs 3.6 KB

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