ShaderConfig.cs 3.4 KB

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