ShaderConfig.cs 4.3 KB

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