HwCapabilities.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.OpenGL
  4. {
  5. static class HwCapabilities
  6. {
  7. private static Lazy<bool> _astcCompression = new Lazy<bool>(SupportsAstcCompressionImpl);
  8. public static bool SupportsAstcCompression => _astcCompression.Value;
  9. private static bool SupportsAstcCompressionImpl()
  10. {
  11. // The NVIDIA driver has software decompression support for ASTC textures,
  12. // but the extension is not exposed, so we check the list of compressed
  13. // formats too, since the support is indicated there.
  14. return SupportsAnyAstcFormat() || HasExtension("GL_KHR_texture_compression_astc_ldr");
  15. }
  16. private static bool SupportsAnyAstcFormat()
  17. {
  18. int formatsCount = GL.GetInteger(GetPName.NumCompressedTextureFormats);
  19. int[] formats = new int[formatsCount];
  20. GL.GetInteger(GetPName.CompressedTextureFormats, formats);
  21. foreach (int format in formats)
  22. {
  23. if (IsAstcFormat(format))
  24. {
  25. return true;
  26. }
  27. }
  28. return false;
  29. }
  30. private static bool IsAstcFormat(int format)
  31. {
  32. switch ((All)format)
  33. {
  34. case All.CompressedRgbaAstc4X4Khr:
  35. case All.CompressedRgbaAstc5X4Khr:
  36. case All.CompressedRgbaAstc5X5Khr:
  37. case All.CompressedRgbaAstc6X5Khr:
  38. case All.CompressedRgbaAstc6X6Khr:
  39. case All.CompressedRgbaAstc8X5Khr:
  40. case All.CompressedRgbaAstc8X6Khr:
  41. case All.CompressedRgbaAstc8X8Khr:
  42. case All.CompressedRgbaAstc10X5Khr:
  43. case All.CompressedRgbaAstc10X6Khr:
  44. case All.CompressedRgbaAstc10X8Khr:
  45. case All.CompressedRgbaAstc10X10Khr:
  46. case All.CompressedRgbaAstc12X10Khr:
  47. case All.CompressedRgbaAstc12X12Khr:
  48. case All.CompressedSrgb8Alpha8Astc4X4Khr:
  49. case All.CompressedSrgb8Alpha8Astc5X4Khr:
  50. case All.CompressedSrgb8Alpha8Astc5X5Khr:
  51. case All.CompressedSrgb8Alpha8Astc6X5Khr:
  52. case All.CompressedSrgb8Alpha8Astc6X6Khr:
  53. case All.CompressedSrgb8Alpha8Astc8X5Khr:
  54. case All.CompressedSrgb8Alpha8Astc8X6Khr:
  55. case All.CompressedSrgb8Alpha8Astc8X8Khr:
  56. case All.CompressedSrgb8Alpha8Astc10X5Khr:
  57. case All.CompressedSrgb8Alpha8Astc10X6Khr:
  58. case All.CompressedSrgb8Alpha8Astc10X8Khr:
  59. case All.CompressedSrgb8Alpha8Astc10X10Khr:
  60. case All.CompressedSrgb8Alpha8Astc12X10Khr:
  61. case All.CompressedSrgb8Alpha8Astc12X12Khr:
  62. return true;
  63. }
  64. return false;
  65. }
  66. private static bool HasExtension(string name)
  67. {
  68. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  69. for (int extension = 0; extension < numExtensions; extension++)
  70. {
  71. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  72. {
  73. return true;
  74. }
  75. }
  76. return false;
  77. }
  78. }
  79. }