ShaderConfig.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. namespace Ryujinx.Graphics.Shader.Translation
  2. {
  3. class ShaderConfig
  4. {
  5. public ShaderStage Stage { get; }
  6. public OutputTopology OutputTopology { get; }
  7. public int MaxOutputVertices { get; }
  8. public int LocalMemorySize { get; }
  9. public ImapPixelType[] ImapTypes { get; }
  10. public OmapTarget[] OmapTargets { get; }
  11. public bool OmapSampleMask { get; }
  12. public bool OmapDepth { get; }
  13. public IGpuAccessor GpuAccessor { get; }
  14. public TranslationFlags Flags { get; }
  15. public TranslationCounts Counts { get; }
  16. public int Size { get; private set; }
  17. public FeatureFlags UsedFeatures { get; private set; }
  18. public ShaderConfig(IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts)
  19. {
  20. Stage = ShaderStage.Compute;
  21. OutputTopology = OutputTopology.PointList;
  22. MaxOutputVertices = 0;
  23. LocalMemorySize = 0;
  24. ImapTypes = null;
  25. OmapTargets = null;
  26. OmapSampleMask = false;
  27. OmapDepth = false;
  28. GpuAccessor = gpuAccessor;
  29. Flags = flags;
  30. Size = 0;
  31. UsedFeatures = FeatureFlags.None;
  32. Counts = counts;
  33. }
  34. public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts)
  35. {
  36. Stage = header.Stage;
  37. OutputTopology = header.OutputTopology;
  38. MaxOutputVertices = header.MaxOutputVertexCount;
  39. LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
  40. ImapTypes = header.ImapTypes;
  41. OmapTargets = header.OmapTargets;
  42. OmapSampleMask = header.OmapSampleMask;
  43. OmapDepth = header.OmapDepth;
  44. GpuAccessor = gpuAccessor;
  45. Flags = flags;
  46. Size = 0;
  47. UsedFeatures = FeatureFlags.None;
  48. Counts = counts;
  49. }
  50. public int GetDepthRegister()
  51. {
  52. int count = 0;
  53. for (int index = 0; index < OmapTargets.Length; index++)
  54. {
  55. for (int component = 0; component < 4; component++)
  56. {
  57. if (OmapTargets[index].ComponentEnabled(component))
  58. {
  59. count++;
  60. }
  61. }
  62. }
  63. // The depth register is always two registers after the last color output.
  64. return count + 1;
  65. }
  66. public TextureFormat GetTextureFormat(int handle)
  67. {
  68. // When the formatted load extension is supported, we don't need to
  69. // specify a format, we can just declare it without a format and the GPU will handle it.
  70. if (GpuAccessor.QuerySupportsImageLoadFormatted())
  71. {
  72. return TextureFormat.Unknown;
  73. }
  74. var format = GpuAccessor.QueryTextureFormat(handle);
  75. if (format == TextureFormat.Unknown)
  76. {
  77. GpuAccessor.Log($"Unknown format for texture {handle}.");
  78. format = TextureFormat.R8G8B8A8Unorm;
  79. }
  80. return format;
  81. }
  82. public void SizeAdd(int size)
  83. {
  84. Size += size;
  85. }
  86. public void SetUsedFeature(FeatureFlags flags)
  87. {
  88. UsedFeatures |= flags;
  89. }
  90. }
  91. }