HwCapabilities.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
  20. public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
  21. public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
  22. public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
  23. private static bool HasExtension(string name)
  24. {
  25. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  26. for (int extension = 0; extension < numExtensions; extension++)
  27. {
  28. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  29. {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. private static int GetLimit(All name)
  36. {
  37. return GL.GetInteger((GetPName)name);
  38. }
  39. private static GpuVendor GetGpuVendor()
  40. {
  41. string vendor = GL.GetString(StringName.Vendor).ToLower();
  42. if (vendor == "nvidia corporation")
  43. {
  44. return GpuVendor.Nvidia;
  45. }
  46. else if (vendor == "intel")
  47. {
  48. return GpuVendor.Intel;
  49. }
  50. else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.")
  51. {
  52. return GpuVendor.Amd;
  53. }
  54. else
  55. {
  56. return GpuVendor.Unknown;
  57. }
  58. }
  59. }
  60. }