HwCapabilities.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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> _maximumViewportDimensions = new Lazy<int>(() => GetLimit(All.MaxViewportDims));
  9. private static Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
  10. private static Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
  11. private static Lazy<bool> _isNvidiaDriver = new Lazy<bool>(() => IsNvidiaDriver());
  12. public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
  13. public static bool SupportsNonConstantTextureOffset => _isNvidiaDriver.Value;
  14. public static int MaximumViewportDimensions => _maximumViewportDimensions.Value;
  15. public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
  16. public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
  17. private static bool HasExtension(string name)
  18. {
  19. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  20. for (int extension = 0; extension < numExtensions; extension++)
  21. {
  22. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  23. {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }
  29. private static int GetLimit(All name)
  30. {
  31. return GL.GetInteger((GetPName)name);
  32. }
  33. private static bool IsNvidiaDriver()
  34. {
  35. return GL.GetString(StringName.Vendor).Equals("NVIDIA Corporation");
  36. }
  37. }
  38. }