ShaderConfig.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. namespace Ryujinx.Graphics.Shader.Translation
  3. {
  4. struct 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 FeatureFlags UsedFeatures { get; 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. UsedFeatures = FeatureFlags.None;
  30. }
  31. public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationFlags flags)
  32. {
  33. Stage = header.Stage;
  34. OutputTopology = header.OutputTopology;
  35. MaxOutputVertices = header.MaxOutputVertexCount;
  36. LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
  37. ImapTypes = header.ImapTypes;
  38. OmapTargets = header.OmapTargets;
  39. OmapSampleMask = header.OmapSampleMask;
  40. OmapDepth = header.OmapDepth;
  41. GpuAccessor = gpuAccessor;
  42. Flags = flags;
  43. UsedFeatures = FeatureFlags.None;
  44. }
  45. public int GetDepthRegister()
  46. {
  47. int count = 0;
  48. for (int index = 0; index < OmapTargets.Length; index++)
  49. {
  50. for (int component = 0; component < 4; component++)
  51. {
  52. if (OmapTargets[index].ComponentEnabled(component))
  53. {
  54. count++;
  55. }
  56. }
  57. }
  58. // The depth register is always two registers after the last color output.
  59. return count + 1;
  60. }
  61. public TextureFormat GetTextureFormat(int handle)
  62. {
  63. // When the formatted load extension is supported, we don't need to
  64. // specify a format, we can just declare it without a format and the GPU will handle it.
  65. if (GpuAccessor.QuerySupportsImageLoadFormatted())
  66. {
  67. return TextureFormat.Unknown;
  68. }
  69. var format = GpuAccessor.QueryTextureFormat(handle);
  70. if (format == TextureFormat.Unknown)
  71. {
  72. GpuAccessor.Log($"Unknown format for texture {handle}.");
  73. format = TextureFormat.R8G8B8A8Unorm;
  74. }
  75. return format;
  76. }
  77. }
  78. }