ShaderConfig.cs 3.9 KB

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