HwCapabilities.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.OpenGL
  4. {
  5. static class HwCapabilities
  6. {
  7. private static readonly Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
  8. private static readonly Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
  9. private static readonly Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
  10. public enum GpuVendor
  11. {
  12. Unknown,
  13. Amd,
  14. Intel,
  15. Nvidia
  16. }
  17. private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor);
  18. public static GpuVendor Vendor => _gpuVendor.Value;
  19. private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
  20. public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
  21. public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
  22. public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
  23. public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
  24. public static float MaxSupportedAnisotropy => _maxSupportedAnisotropy.Value;
  25. private static bool HasExtension(string name)
  26. {
  27. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  28. for (int extension = 0; extension < numExtensions; extension++)
  29. {
  30. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  31. {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. private static int GetLimit(All name)
  38. {
  39. return GL.GetInteger((GetPName)name);
  40. }
  41. private static GpuVendor GetGpuVendor()
  42. {
  43. string vendor = GL.GetString(StringName.Vendor).ToLower();
  44. if (vendor == "nvidia corporation")
  45. {
  46. return GpuVendor.Nvidia;
  47. }
  48. else if (vendor == "intel")
  49. {
  50. return GpuVendor.Intel;
  51. }
  52. else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.")
  53. {
  54. return GpuVendor.Amd;
  55. }
  56. else
  57. {
  58. return GpuVendor.Unknown;
  59. }
  60. }
  61. }
  62. }