HwCapabilities.cs 3.7 KB

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