HwCapabilities.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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<bool> _supportsImageLoadFormatted = new Lazy<bool>(() => HasExtension("GL_EXT_shader_image_load_formatted"));
  9. private static readonly Lazy<bool> _supportsViewportSwizzle = new Lazy<bool>(() => HasExtension("GL_NV_viewport_swizzle"));
  10. private static readonly Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
  11. private static readonly Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
  12. public enum GpuVendor
  13. {
  14. Unknown,
  15. Amd,
  16. Intel,
  17. Nvidia
  18. }
  19. private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor);
  20. public static GpuVendor Vendor => _gpuVendor.Value;
  21. private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
  22. public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
  23. public static bool SupportsImageLoadFormatted => _supportsImageLoadFormatted.Value;
  24. public static bool SupportsViewportSwizzle => _supportsViewportSwizzle.Value;
  25. public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
  26. public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
  27. public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
  28. public static float MaximumSupportedAnisotropy => _maxSupportedAnisotropy.Value;
  29. private static bool HasExtension(string name)
  30. {
  31. int numExtensions = GL.GetInteger(GetPName.NumExtensions);
  32. for (int extension = 0; extension < numExtensions; extension++)
  33. {
  34. if (GL.GetString(StringNameIndexed.Extensions, extension) == name)
  35. {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. private static int GetLimit(All name)
  42. {
  43. return GL.GetInteger((GetPName)name);
  44. }
  45. private static GpuVendor GetGpuVendor()
  46. {
  47. string vendor = GL.GetString(StringName.Vendor).ToLower();
  48. if (vendor == "nvidia corporation")
  49. {
  50. return GpuVendor.Nvidia;
  51. }
  52. else if (vendor == "intel")
  53. {
  54. return GpuVendor.Intel;
  55. }
  56. else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.")
  57. {
  58. return GpuVendor.Amd;
  59. }
  60. else
  61. {
  62. return GpuVendor.Unknown;
  63. }
  64. }
  65. }
  66. }