ShaderConfig.cs 4.1 KB

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