HwCapabilities.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.OpenGL
  4. {
  5. static class HwCapabilities
  6. {
  7. private static Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
  8. private static Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
  9. private static Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
  10. private static Lazy<bool> _isNvidiaDriver = new Lazy<bool>(() => IsNvidiaDriver());
  11. public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
  12. public static bool SupportsNonConstantTextureOffset => _isNvidiaDriver.Value;
  13. public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
  14. public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
  15. private static bool HasExtension(string name)
  16. {
  17. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  18. for (int extension = 0; extension < numExtensions; extension++)
  19. {
  20. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  21. {
  22. return true;
  23. }
  24. }
  25. return false;
  26. }
  27. private static int GetLimit(All name)
  28. {
  29. return GL.GetInteger((GetPName)name);
  30. }
  31. private static bool IsNvidiaDriver()
  32. {
  33. return GL.GetString(StringName.Vendor).Equals("NVIDIA Corporation");
  34. }
  35. }
  36. }