Debian Codegraph @

Source/Core/VideoBackends/OGL/OGLConfig.cpp

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoBackends/OGL/OGLConfig.h"
5
6 #include <cstdio>
7 #include <ranges>
8 #include <string>
9 #include <string_view>
10
11 #include <fmt/ranges.h>
12
13 #include "Common/Assert.h"
14 #include "Common/GL/GLContext.h"
15 #include "Common/GL/GLExtensions/GLExtensions.h"
16 #include "Common/MsgHandler.h"
17
18 #include "VideoBackends/OGL/OGLTexture.h"
19
20 #include "VideoCommon/DriverDetails.h"
21 #include "VideoCommon/FramebufferManager.h"
22 #include "VideoCommon/OnScreenDisplay.h"
23 #include "VideoCommon/VideoConfig.h"
24
25 namespace OGL
26 {
27 void InitDriverInfo()
28 {
29 const std::string_view svendor(g_ogl_config.gl_vendor);
30 const std::string_view srenderer(g_ogl_config.gl_renderer);
31 const std::string_view sversion(g_ogl_config.gl_version);
32 DriverDetails::Vendor vendor = DriverDetails::VENDOR_UNKNOWN;
33 DriverDetails::Driver driver = DriverDetails::DRIVER_UNKNOWN;
34 DriverDetails::Family family = DriverDetails::Family::UNKNOWN;
35 double version = 0.0;
36
37 // Get the vendor first
38 if (svendor == "NVIDIA Corporation")
39 {
40 if (srenderer != "NVIDIA Tegra")
41 {
42 vendor = DriverDetails::VENDOR_NVIDIA;
43 }
44 else
45 {
46 vendor = DriverDetails::VENDOR_TEGRA;
47 }
48 }
49 else if (svendor == "ATI Technologies Inc." || svendor == "Advanced Micro Devices, Inc.")
50 {
51 vendor = DriverDetails::VENDOR_ATI;
52 }
53 else if (sversion.contains("Mesa"))
54 {
55 vendor = DriverDetails::VENDOR_MESA;
56 }
57 else if (svendor.contains("Intel"))
58 {
59 vendor = DriverDetails::VENDOR_INTEL;
60 }
61 else if (svendor == "ARM")
62 {
63 vendor = DriverDetails::VENDOR_ARM;
64 }
65 else if (svendor == "http://limadriver.org/")
66 {
67 vendor = DriverDetails::VENDOR_ARM;
68 driver = DriverDetails::DRIVER_LIMA;
69 }
70 else if (svendor == "Qualcomm")
71 {
72 vendor = DriverDetails::VENDOR_QUALCOMM;
73 }
74 else if (svendor == "Imagination Technologies")
75 {
76 vendor = DriverDetails::VENDOR_IMGTEC;
77 }
78 else if (svendor == "Vivante Corporation")
79 {
80 vendor = DriverDetails::VENDOR_VIVANTE;
81 }
82
83 // Get device family and driver version...if we care about it
84 switch (vendor)
85 {
86 case DriverDetails::VENDOR_QUALCOMM:
87 {
88 driver = DriverDetails::DRIVER_QUALCOMM;
89 double glVersion;
90 sscanf(g_ogl_config.gl_version, "OpenGL ES %lg V@%lg", &glVersion, &version);
91 }
92 break;
93 case DriverDetails::VENDOR_ARM:
94 // Currently the Mali-T line has two families in it.
95 // Mali-T6xx and Mali-T7xx
96 // These two families are similar enough that they share bugs in their drivers.
97 //
98 // Mali drivers provide no way to explicitly find out what video driver is running.
99 // This is similar to how we can't find the Nvidia driver version in Windows.
100 // Good thing is that ARM introduces a new video driver about once every two years so we can
101 // find the driver version by the features it exposes.
102 // r2p0 - No OpenGL ES 3.0 support (We don't support this)
103 // r3p0 - OpenGL ES 3.0 support
104 // r4p0 - Supports 'GL_EXT_shader_pixel_local_storage' extension.
105
106 driver = DriverDetails::DRIVER_ARM;
107 if (GLExtensions::Supports("GL_EXT_shader_pixel_local_storage"))
108 version = 400;
109 else
110 version = 300;
111 break;
112 case DriverDetails::VENDOR_MESA:
113 {
114 if (svendor == "nouveau")
115 {
116 driver = DriverDetails::DRIVER_NOUVEAU;
117 }
118 else if (svendor == "Intel Open Source Technology Center")
119 {
120 driver = DriverDetails::DRIVER_I965;
121 if (srenderer.contains("Sandybridge"))
122 family = DriverDetails::Family::INTEL_SANDY;
123 else if (srenderer.contains("Ivybridge"))
124 family = DriverDetails::Family::INTEL_IVY;
125 }
126 else if (srenderer.contains("AMD") || srenderer.contains("ATI"))
127 {
128 driver = DriverDetails::DRIVER_R600;
129 }
130
131 int major = 0;
132 int minor = 0;
133 int release = 0;
134 sscanf(g_ogl_config.gl_version, "%*s (Core Profile) Mesa %d.%d.%d", &major, &minor, &release);
135 version = 100 * major + 10 * minor + release;
136 }
137 break;
138 case DriverDetails::VENDOR_INTEL: // Happens in OS X/Windows
139 {
140 u32 market_name;
141 sscanf(g_ogl_config.gl_renderer, "Intel HD Graphics %d", &market_name);
142 switch (market_name)
143 {
144 case 2000:
145 case 3000:
146 family = DriverDetails::Family::INTEL_SANDY;
147 break;
148 case 2500:
149 case 4000:
150 family = DriverDetails::Family::INTEL_IVY;
151 break;
152 default:
153 family = DriverDetails::Family::UNKNOWN;
154 break;
155 };
156 #ifdef _WIN32
157 int glmajor = 0;
158 int glminor = 0;
159 int major = 0;
160 int minor = 0;
161 int release = 0;
162 int revision = 0;
163 // Example version string: '4.3.0 - Build 10.18.10.3907'
164 sscanf(g_ogl_config.gl_version, "%d.%d.0 - Build %d.%d.%d.%d", &glmajor, &glminor, &major,
165 &minor, &release, &revision);
166 version = 100000000 * major + 1000000 * minor + 10000 * release + revision;
167 version /= 10000;
168 #endif
169 }
170 break;
171 case DriverDetails::VENDOR_NVIDIA:
172 {
173 int glmajor = 0;
174 int glminor = 0;
175 int glrelease = 0;
176 int major = 0;
177 int minor = 0;
178 // TODO: this is known to be broken on Windows
179 // Nvidia seems to have removed their driver version from this string, so we can't get it.
180 // hopefully we'll never have to workaround Nvidia bugs
181 sscanf(g_ogl_config.gl_version, "%d.%d.%d NVIDIA %d.%d", &glmajor, &glminor, &glrelease, &major,
182 &minor);
183 version = 100 * major + minor;
184 }
185 break;
186 case DriverDetails::VENDOR_IMGTEC:
187 {
188 // Example version string:
189 // "OpenGL ES 3.2 build 1.9@4850625"
190 // Ends up as "109.4850625" - "1.9" being the branch, "4850625" being the build's change ID
191 // The change ID only makes sense to compare within a branch
192 driver = DriverDetails::DRIVER_IMGTEC;
193 double gl_version;
194 int major, minor, change;
195 constexpr double change_scale = 10000000;
196 sscanf(g_ogl_config.gl_version, "OpenGL ES %lg build %d.%d@%d", &gl_version, &major, &minor,
197 &change);
198 version = 100 * major + minor;
199 if (change >= change_scale)
200 {
201 ERROR_LOG_FMT(VIDEO, "Version changeID overflow - change:{} scale:{}", change, change_scale);
202 }
203 else
204 {
205 version += static_cast<double>(change) / change_scale;
206 }
207 }
208 break;
209 // We don't care about these
210 default:
211 break;
212 }
213 DriverDetails::Init(DriverDetails::API_OPENGL, vendor, driver, version, family,
214 std::string(srenderer));
215 }
216
217 bool PopulateConfig(GLContext* m_main_gl_context)
218 {
219 bool bSuccess = true;
220 bool supports_glsl_cache = false;
221
222 g_ogl_config.gl_vendor = (const char*)glGetString(GL_VENDOR);
223 g_ogl_config.gl_renderer = (const char*)glGetString(GL_RENDERER);
224 g_ogl_config.gl_version = (const char*)glGetString(GL_VERSION);
225
226 if (!m_main_gl_context->IsGLES())
227 {
228 if (!GLExtensions::Supports("GL_ARB_framebuffer_object"))
229 {
230 // We want the ogl3 framebuffer instead of the ogl2 one for better blitting support.
231 // It's also compatible with the gles3 one.
232 PanicAlertFmtT("GPU: ERROR: Need GL_ARB_framebuffer_object for multiple render targets.\n"
233 "GPU: Does your video card support OpenGL 3.0?");
234 bSuccess = false;
235 }
236
237 if (!GLExtensions::Supports("GL_ARB_vertex_array_object"))
238 {
239 // This extension is used to replace lots of pointer setting function.
240 // Also gles3 requires to use it.
241 PanicAlertFmtT("GPU: OGL ERROR: Need GL_ARB_vertex_array_object.\n"
242 "GPU: Does your video card support OpenGL 3.0?");
243 bSuccess = false;
244 }
245
246 if (!GLExtensions::Supports("GL_ARB_map_buffer_range"))
247 {
248 // ogl3 buffer mapping for better streaming support.
249 // The ogl2 one also isn't in gles3.
250 PanicAlertFmtT("GPU: OGL ERROR: Need GL_ARB_map_buffer_range.\n"
251 "GPU: Does your video card support OpenGL 3.0?");
252 bSuccess = false;
253 }
254
255 if (!GLExtensions::Supports("GL_ARB_uniform_buffer_object"))
256 {
257 // ubo allow us to keep the current constants on shader switches
258 // we also can stream them much nicer and pack into it whatever we want to
259 PanicAlertFmtT("GPU: OGL ERROR: Need GL_ARB_uniform_buffer_object.\n"
260 "GPU: Does your video card support OpenGL 3.1?");
261 bSuccess = false;
262 }
263 else if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_UBO))
264 {
265 PanicAlertFmtT(
266 "Buggy GPU driver detected.\n"
267 "Please either install the closed-source GPU driver or update your Mesa 3D version.");
268 bSuccess = false;
269 }
270
271 if (!GLExtensions::Supports("GL_ARB_sampler_objects"))
272 {
273 // Our sampler cache uses this extension. It could easily be workaround and it's by far the
274 // highest requirement, but it seems that no driver lacks support for it.
275 PanicAlertFmtT("GPU: OGL ERROR: Need GL_ARB_sampler_objects.\n"
276 "GPU: Does your video card support OpenGL 3.3?");
277 bSuccess = false;
278 }
279 }
280
281 // Copy the GPU name to g_Config, so Analytics can see it.
282 g_backend_info.AdapterName = g_ogl_config.gl_renderer;
283
284 g_backend_info.bSupportsDualSourceBlend = (GLExtensions::Supports("GL_ARB_blend_func_extended") ||
285 GLExtensions::Supports("GL_EXT_blend_func_extended"));
286 g_backend_info.bSupportsPrimitiveRestart =
287 !DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVE_RESTART) &&
288 ((GLExtensions::Version() >= 310) || GLExtensions::Supports("GL_NV_primitive_restart"));
289 g_backend_info.bSupportsGSInstancing = GLExtensions::Supports("GL_ARB_gpu_shader5");
290 g_backend_info.bSupportsSSAA = GLExtensions::Supports("GL_ARB_gpu_shader5") &&
291 GLExtensions::Supports("GL_ARB_sample_shading");
292 g_backend_info.bSupportsGeometryShaders =
293 GLExtensions::Version() >= 320 &&
294 !DriverDetails::HasBug(DriverDetails::BUG_BROKEN_GEOMETRY_SHADERS);
295 g_backend_info.bSupportsPaletteConversion =
296 GLExtensions::Supports("GL_ARB_texture_buffer_object") ||
297 GLExtensions::Supports("GL_OES_texture_buffer") ||
298 GLExtensions::Supports("GL_EXT_texture_buffer");
299 g_backend_info.bSupportsClipControl = GLExtensions::Supports("GL_ARB_clip_control");
300 g_ogl_config.bSupportsCopySubImage =
301 (GLExtensions::Supports("GL_ARB_copy_image") || GLExtensions::Supports("GL_NV_copy_image") ||
302 GLExtensions::Supports("GL_EXT_copy_image") ||
303 GLExtensions::Supports("GL_OES_copy_image")) &&
304 !DriverDetails::HasBug(DriverDetails::BUG_BROKEN_COPYIMAGE);
305 g_ogl_config.bSupportsTextureSubImage = GLExtensions::Supports("ARB_get_texture_sub_image");
306
307 // Desktop OpenGL supports the binding layout if it supports 420pack
308 // OpenGL ES 3.1 supports it implicitly without an extension
309 g_backend_info.bSupportsBindingLayout = GLExtensions::Supports("GL_ARB_shading_language_420pack");
310
311 // Clip distance support is useless without a method to clamp the depth range
312 g_backend_info.bSupportsDepthClamp = GLExtensions::Supports("GL_ARB_depth_clamp");
313
314 // Desktop OpenGL supports bitfield manulipation and dynamic sampler indexing if it supports
315 // shader5. OpenGL ES 3.1 supports it implicitly without an extension
316 g_backend_info.bSupportsBitfield = GLExtensions::Supports("GL_ARB_gpu_shader5");
317 g_backend_info.bSupportsDynamicSamplerIndexing = GLExtensions::Supports("GL_ARB_gpu_shader5");
318
319 g_ogl_config.bIsES = m_main_gl_context->IsGLES();
320 supports_glsl_cache = GLExtensions::Supports("GL_ARB_get_program_binary");
321 g_ogl_config.bSupportsGLPinnedMemory = GLExtensions::Supports("GL_AMD_pinned_memory");
322 g_ogl_config.bSupportsGLSync = GLExtensions::Supports("GL_ARB_sync");
323 g_ogl_config.bSupportsGLBaseVertex = GLExtensions::Supports("GL_ARB_draw_elements_base_vertex") ||
324 GLExtensions::Supports("GL_EXT_draw_elements_base_vertex") ||
325 GLExtensions::Supports("GL_OES_draw_elements_base_vertex");
326 g_ogl_config.bSupportsGLBufferStorage = GLExtensions::Supports("GL_ARB_buffer_storage") ||
327 GLExtensions::Supports("GL_EXT_buffer_storage");
328 g_ogl_config.bSupportsMSAA = GLExtensions::Supports("GL_ARB_texture_multisample");
329 g_ogl_config.bSupportViewportFloat = GLExtensions::Supports("GL_ARB_viewport_array");
330 g_ogl_config.bSupportsDebug =
331 GLExtensions::Supports("GL_KHR_debug") || GLExtensions::Supports("GL_ARB_debug_output");
332 g_ogl_config.bSupportsTextureStorage = GLExtensions::Supports("GL_ARB_texture_storage");
333 g_ogl_config.SupportedMultisampleTexStorage = MultisampleTexStorageType::TexStorageNone;
334 g_ogl_config.bSupportsImageLoadStore = GLExtensions::Supports("GL_ARB_shader_image_load_store");
335 g_ogl_config.bSupportsConservativeDepth = GLExtensions::Supports("GL_ARB_conservative_depth");
336 g_ogl_config.bSupportsAniso = GLExtensions::Supports("GL_EXT_texture_filter_anisotropic");
337 g_backend_info.bSupportsComputeShaders = GLExtensions::Supports("GL_ARB_compute_shader");
338 g_backend_info.bSupportsST3CTextures = GLExtensions::Supports("GL_EXT_texture_compression_s3tc");
339 g_backend_info.bSupportsBPTCTextures = GLExtensions::Supports("GL_ARB_texture_compression_bptc");
340 g_backend_info.bSupportsCoarseDerivatives =
341 GLExtensions::Supports("GL_ARB_derivative_control") || GLExtensions::Version() >= 450;
342 g_backend_info.bSupportsTextureQueryLevels =
343 GLExtensions::Supports("GL_ARB_texture_query_levels") || GLExtensions::Version() >= 430;
344
345 if (GLExtensions::Supports("GL_ARB_shader_storage_buffer_object"))
346 {
347 GLint fs = 0;
348 GLint vs = 0;
349 glGetIntegerv(GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &fs);
350 glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs);
351 g_backend_info.bSupportsFragmentStoresAndAtomics = fs >= 1;
352 g_backend_info.bSupportsVSLinePointExpand = vs >= 1;
353 }
354 else
355 {
356 g_backend_info.bSupportsFragmentStoresAndAtomics = false;
357 g_backend_info.bSupportsVSLinePointExpand = false;
358 }
359
360 if (GLExtensions::Supports("GL_EXT_shader_framebuffer_fetch"))
361 {
362 g_ogl_config.SupportedFramebufferFetch = EsFbFetchType::FbFetchExt;
363 }
364 else if (GLExtensions::Supports("GL_ARM_shader_framebuffer_fetch"))
365 {
366 g_ogl_config.SupportedFramebufferFetch = EsFbFetchType::FbFetchArm;
367 }
368 else
369 {
370 g_ogl_config.SupportedFramebufferFetch = EsFbFetchType::FbFetchNone;
371 }
372 g_backend_info.bSupportsFramebufferFetch =
373 g_ogl_config.SupportedFramebufferFetch != EsFbFetchType::FbFetchNone;
374
375 if (m_main_gl_context->IsGLES())
376 {
377 g_ogl_config.SupportedESPointSize =
378 GLExtensions::Supports("GL_OES_geometry_point_size") ? EsPointSizeType::PointSizeOes :
379 GLExtensions::Supports("GL_EXT_geometry_point_size") ? EsPointSizeType::PointSizeExt :
380 EsPointSizeType::PointSizeNone;
381 g_ogl_config.SupportedESTextureBuffer =
382 GLExtensions::Supports("VERSION_GLES_3_2") ? EsTexbufType::TexbufCore :
383 GLExtensions::Supports("GL_OES_texture_buffer") ? EsTexbufType::TexbufOes :
384 GLExtensions::Supports("GL_EXT_texture_buffer") ? EsTexbufType::TexbufExt :
385 EsTexbufType::TexbufNone;
386
387 supports_glsl_cache = true;
388 g_ogl_config.bSupportsGLSync = true;
389
390 // TODO: Implement support for GL_EXT_clip_cull_distance when there is an extension for
391 // depth clamping.
392 g_backend_info.bSupportsDepthClamp = false;
393
394 // GLES does not support logic op.
395 g_backend_info.bSupportsLogicOp = false;
396
397 // glReadPixels() can't be used with non-color formats. But, if we support
398 // ARB_get_texture_sub_image (unlikely, except maybe on NVIDIA), we can use that instead.
399 g_backend_info.bSupportsDepthReadback = g_ogl_config.bSupportsTextureSubImage;
400
401 // GL_TEXTURE_LOD_BIAS is not supported on GLES.
402 g_backend_info.bSupportsLodBiasInSampler = false;
403
404 if (GLExtensions::Version() == 300)
405 {
406 g_ogl_config.eSupportedGLSLVersion = GlslEs300;
407 g_ogl_config.bSupportsAEP = false;
408 g_ogl_config.bSupportsTextureStorage = true;
409 g_backend_info.bSupportsGeometryShaders = false;
410 }
411 else if (GLExtensions::Version() == 310)
412 {
413 g_ogl_config.eSupportedGLSLVersion = GlslEs310;
414 g_ogl_config.bSupportsAEP = GLExtensions::Supports("GL_ANDROID_extension_pack_es31a");
415 g_backend_info.bSupportsBindingLayout = true;
416 g_ogl_config.bSupportsImageLoadStore = true;
417 g_backend_info.bSupportsGeometryShaders = g_ogl_config.bSupportsAEP;
418 g_backend_info.bSupportsComputeShaders = true;
419 g_backend_info.bSupportsGSInstancing =
420 g_backend_info.bSupportsGeometryShaders &&
421 g_ogl_config.SupportedESPointSize != EsPointSizeType::PointSizeNone;
422 g_backend_info.bSupportsSSAA = g_ogl_config.bSupportsAEP;
423 g_backend_info.bSupportsFragmentStoresAndAtomics = true;
424 g_ogl_config.bSupportsMSAA = true;
425 g_ogl_config.bSupportsTextureStorage = true;
426 if (GLExtensions::Supports("GL_OES_texture_storage_multisample_2d_array"))
427 g_ogl_config.SupportedMultisampleTexStorage = MultisampleTexStorageType::TexStorageOes;
428 g_backend_info.bSupportsBitfield = true;
429 g_backend_info.bSupportsDynamicSamplerIndexing = g_ogl_config.bSupportsAEP;
430 }
431 else
432 {
433 g_ogl_config.eSupportedGLSLVersion = GlslEs320;
434 g_ogl_config.bSupportsAEP = GLExtensions::Supports("GL_ANDROID_extension_pack_es31a");
435 g_backend_info.bSupportsBindingLayout = true;
436 g_ogl_config.bSupportsImageLoadStore = true;
437 g_backend_info.bSupportsGeometryShaders = true;
438 g_backend_info.bSupportsComputeShaders = true;
439 g_backend_info.bSupportsGSInstancing =
440 g_ogl_config.SupportedESPointSize != EsPointSizeType::PointSizeNone;
441 g_backend_info.bSupportsPaletteConversion = true;
442 g_backend_info.bSupportsSSAA = true;
443 g_backend_info.bSupportsFragmentStoresAndAtomics = true;
444 g_ogl_config.bSupportsCopySubImage = true;
445 g_ogl_config.bSupportsGLBaseVertex = true;
446 g_ogl_config.bSupportsDebug = true;
447 g_ogl_config.bSupportsMSAA = true;
448 g_ogl_config.bSupportsTextureStorage = true;
449 g_ogl_config.SupportedMultisampleTexStorage = MultisampleTexStorageType::TexStorageCore;
450 g_backend_info.bSupportsBitfield = true;
451 g_backend_info.bSupportsDynamicSamplerIndexing = true;
452 g_backend_info.bSupportsSettingObjectNames = true;
453 }
454 }
455 else
456 {
457 if (GLExtensions::Supports("GL_ARB_texture_storage_multisample"))
458 g_ogl_config.SupportedMultisampleTexStorage = MultisampleTexStorageType::TexStorageCore;
459
460 if (GLExtensions::Version() < 300)
461 {
462 PanicAlertFmtT("GPU: OGL ERROR: Need at least GLSL 1.30\n"
463 "GPU: Does your video card support OpenGL 3.0?\n"
464 "GPU: Your driver supports GLSL {0}",
465 reinterpret_cast<const char*>(glGetString(GL_SHADING_LANGUAGE_VERSION)));
466 bSuccess = false;
467 }
468 else if (GLExtensions::Version() == 300)
469 {
470 g_ogl_config.eSupportedGLSLVersion = Glsl130;
471 g_ogl_config.bSupportsImageLoadStore = false; // layout keyword is only supported on glsl150+
472 g_ogl_config.bSupportsConservativeDepth =
473 false; // layout keyword is only supported on glsl150+
474 g_backend_info.bSupportsGeometryShaders =
475 false; // geometry shaders are only supported on glsl150+
476 }
477 else if (GLExtensions::Version() == 310)
478 {
479 g_ogl_config.eSupportedGLSLVersion = Glsl140;
480 g_ogl_config.bSupportsImageLoadStore = false; // layout keyword is only supported on glsl150+
481 g_ogl_config.bSupportsConservativeDepth =
482 false; // layout keyword is only supported on glsl150+
483 g_backend_info.bSupportsGeometryShaders =
484 false; // geometry shaders are only supported on glsl150+
485 }
486 else if (GLExtensions::Version() == 320)
487 {
488 g_ogl_config.eSupportedGLSLVersion = Glsl150;
489 }
490 else if (GLExtensions::Version() == 330)
491 {
492 g_ogl_config.eSupportedGLSLVersion = Glsl330;
493 g_ogl_config.bSupportsExplicitLayoutInShader =
494 GLExtensions::Supports("GL_ARB_explicit_attrib_location");
495 }
496 else if (GLExtensions::Version() >= 430)
497 {
498 // TODO: We should really parse the GL_SHADING_LANGUAGE_VERSION token.
499 if (GLExtensions::Version() >= 450)
500 {
501 g_ogl_config.eSupportedGLSLVersion = Glsl450;
502 }
503 else
504 {
505 g_ogl_config.eSupportedGLSLVersion = Glsl430;
506 }
507 g_ogl_config.bSupportsTextureStorage = true;
508 g_ogl_config.SupportedMultisampleTexStorage = MultisampleTexStorageType::TexStorageCore;
509 g_ogl_config.bSupportsImageLoadStore = true;
510 g_ogl_config.bSupportsExplicitLayoutInShader = true;
511 g_backend_info.bSupportsSSAA = true;
512 g_backend_info.bSupportsSettingObjectNames = true;
513
514 // Compute shaders are core in GL4.3.
515 g_backend_info.bSupportsComputeShaders = true;
516 if (GLExtensions::Version() >= 450)
517 g_ogl_config.bSupportsTextureSubImage = true;
518 }
519 else
520 {
521 g_ogl_config.eSupportedGLSLVersion = Glsl400;
522 g_backend_info.bSupportsSSAA = true;
523
524 if (GLExtensions::Version() == 420)
525 {
526 // Texture storage and shader image load/store are core in GL4.2.
527 g_ogl_config.bSupportsTextureStorage = true;
528 g_ogl_config.bSupportsImageLoadStore = true;
529 }
530 }
531
532 // Desktop OpenGL can't have the Android Extension Pack
533 g_ogl_config.bSupportsAEP = false;
534
535 // Desktop GL requires GL_PROGRAM_POINT_SIZE set to use gl_PointSize in shaders.
536 // It is implicitly enabled in GLES.
537 glEnable(GL_PROGRAM_POINT_SIZE);
538 }
539
540 // Supported by all GS-supporting ES and 4.3+
541 g_backend_info.bSupportsGLLayerInFS =
542 g_backend_info.bSupportsGeometryShaders && g_ogl_config.eSupportedGLSLVersion >= Glsl430;
543
544 g_backend_info.bSupportsBBox = g_backend_info.bSupportsFragmentStoresAndAtomics;
545
546 // Either method can do early-z tests. See PixelShaderGen for details.
547 g_backend_info.bSupportsEarlyZ =
548 g_ogl_config.bSupportsImageLoadStore || g_ogl_config.bSupportsConservativeDepth;
549
550 g_backend_info.AAModes.clear();
551 if (g_ogl_config.bSupportsMSAA)
552 {
553 bool supportsGetInternalFormat =
554 GLExtensions::Supports("VERSION_4_2") || GLExtensions::Supports("VERSION_GLES_3");
555 if (supportsGetInternalFormat)
556 {
557 // Note: GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES should technically be used for
558 // GL_OES_texture_storage_multisample_2d_array, but both are 0x9102 so it does not matter.
559
560 std::vector<int> color_aa_modes;
561 {
562 GLenum colorInternalFormat = OGLTexture::GetGLInternalFormatForTextureFormat(
563 FramebufferManager::GetEFBColorFormat(), true);
564 GLint num_color_sample_counts = 0;
565 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, colorInternalFormat,
566 GL_NUM_SAMPLE_COUNTS, 1, &num_color_sample_counts);
567
568 ASSERT_MSG(VIDEO, num_color_sample_counts >= 0,
569 "negative GL_NUM_SAMPLE_COUNTS for colors does not make sense: {}",
570 num_color_sample_counts);
571 color_aa_modes.reserve(num_color_sample_counts + 1);
572 if (num_color_sample_counts > 0)
573 {
574 color_aa_modes.resize(num_color_sample_counts);
575
576 static_assert(sizeof(GLint) == sizeof(u32));
577 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, colorInternalFormat, GL_SAMPLES,
578 num_color_sample_counts,
579 reinterpret_cast<GLint*>(color_aa_modes.data()));
580 ASSERT_MSG(VIDEO, std::ranges::is_sorted(color_aa_modes | std::views::reverse),
581 "GPU driver didn't return sorted color AA modes: [{}]",
582 fmt::join(color_aa_modes, ", "));
583 }
584
585 if (color_aa_modes.empty() || color_aa_modes.back() != 1)
586 color_aa_modes.push_back(1);
587 }
588
589 std::vector<int> depth_aa_modes;
590 {
591 GLenum depthInternalFormat = OGLTexture::GetGLInternalFormatForTextureFormat(
592 FramebufferManager::GetEFBColorFormat(), true);
593 GLint num_depth_sample_counts = 0;
594 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, depthInternalFormat,
595 GL_NUM_SAMPLE_COUNTS, 1, &num_depth_sample_counts);
596
597 ASSERT_MSG(VIDEO, num_depth_sample_counts >= 0,
598 "negative GL_NUM_SAMPLE_COUNTS for depth does not make sense: {}",
599 num_depth_sample_counts);
600 depth_aa_modes.reserve(num_depth_sample_counts + 1);
601 if (num_depth_sample_counts > 0)
602 {
603 depth_aa_modes.resize(num_depth_sample_counts);
604
605 static_assert(sizeof(GLint) == sizeof(u32));
606 glGetInternalformativ(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, depthInternalFormat, GL_SAMPLES,
607 num_depth_sample_counts,
608 reinterpret_cast<GLint*>(depth_aa_modes.data()));
609 ASSERT_MSG(VIDEO, std::ranges::is_sorted(depth_aa_modes | std::views::reverse),
610 "GPU driver didn't return sorted depth AA modes: [{}]",
611 fmt::join(depth_aa_modes, ", "));
612 }
613
614 if (depth_aa_modes.empty() || depth_aa_modes.back() != 1)
615 depth_aa_modes.push_back(1);
616 }
617
618 // The spec says supported sample formats are returned in descending numeric order.
619 // It also says "Only positive values are returned", but does not specify whether 1 is
620 // included or not; it seems like NVIDIA and Intel GPUs do not include it.
621 // We've inserted 1 at the back of both if not present to handle this.
622 g_backend_info.AAModes.clear();
623 g_backend_info.AAModes.reserve(std::min(color_aa_modes.size(), depth_aa_modes.size()));
624 // We only want AA modes that are supported for both the color and depth textures. Probably
625 // the support is the same, though. views::reverse is used to swap the order ahead of time.
626 std::ranges::set_intersection(color_aa_modes | std::views::reverse,
627 depth_aa_modes | std::views::reverse,
628 std::back_inserter(g_backend_info.AAModes));
629 }
630 else
631 {
632 // The documentation for glGetInternalformativ says its value is at least the minimum of
633 // GL_MAX_SAMPLES, GL_MAX_COLOR_TEXTURE_SAMPLES, and GL_MAX_DEPTH_TEXTURE_SAMPLES (and
634 // GL_MAX_INTEGER_SAMPLES for integer textures, assumed not applicable here).
635 GLint max_color_samples = 0;
636 glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &max_color_samples);
637 GLint max_depth_samples = 0;
638 glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &max_depth_samples);
639 // Note: The desktop OpenGL ref pages don't actually say that GL_MAX_SAMPLES is a valid
640 // parameter for glGetIntegerv (though the ES ones do). However, MAX_SAMPLES is
641 // referenced in the GL 3.1 spec and by GL_ARB_texture_multisample (which is written against
642 // the OpenGL 3.1 spec), so presumably it is valid.
643 GLint max_samples = 0;
644 glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
645 u32 supported_max_samples =
646 static_cast<u32>(std::min({max_samples, max_color_samples, max_depth_samples}));
647
648 while (supported_max_samples > 1)
649 {
650 g_backend_info.AAModes.push_back(supported_max_samples);
651 supported_max_samples /= 2;
652 }
653 g_backend_info.AAModes.push_back(1);
654 // The UI wants ascending order
655 std::ranges::reverse(g_backend_info.AAModes);
656 }
657 }
658 else
659 {
660 g_backend_info.AAModes = {1};
661 }
662
663 const bool bSupportsIsHelperInvocation = g_ogl_config.bIsES ?
664 g_ogl_config.eSupportedGLSLVersion >= GlslEs320 :
665 g_ogl_config.eSupportedGLSLVersion >= Glsl450;
666 g_ogl_config.bSupportsKHRShaderSubgroup =
667 GLExtensions::Supports("GL_KHR_shader_subgroup") && bSupportsIsHelperInvocation;
668 if (g_ogl_config.bSupportsKHRShaderSubgroup)
669 {
670 // Check for the features: basic + arithmetic + ballot
671 GLint supported_features = 0;
672 glGetIntegerv(GL_SUBGROUP_SUPPORTED_FEATURES_KHR, &supported_features);
673 if (~supported_features &
674 (GL_SUBGROUP_FEATURE_BASIC_BIT_KHR | GL_SUBGROUP_FEATURE_ARITHMETIC_BIT_KHR |
675 GL_SUBGROUP_FEATURE_BALLOT_BIT_KHR))
676 {
677 g_ogl_config.bSupportsKHRShaderSubgroup = false;
678 }
679 }
680
681 // We require texel buffers, image load store, and compute shaders to enable GPU texture decoding.
682 // If the driver doesn't expose the extensions, but supports GL4.3/GLES3.1, it will still be
683 // enabled in the version check below.
684 g_backend_info.bSupportsGPUTextureDecoding = g_backend_info.bSupportsPaletteConversion &&
685 g_backend_info.bSupportsComputeShaders &&
686 g_ogl_config.bSupportsImageLoadStore;
687
688 // Background compiling is supported only when shared contexts aren't broken.
689 g_backend_info.bSupportsBackgroundCompiling =
690 !DriverDetails::HasBug(DriverDetails::BUG_SHARED_CONTEXT_SHADER_COMPILATION);
691
692 // Program binaries are supported on GL4.1+, ARB_get_program_binary, or ES3.
693 if (supports_glsl_cache)
694 {
695 // We need to check the number of formats supported. If zero, don't bother getting the binaries.
696 GLint num_formats = 0;
697 glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &num_formats);
698 supports_glsl_cache = num_formats > 0;
699 }
700 g_backend_info.bSupportsPipelineCacheData = supports_glsl_cache;
701
702 int samples;
703 glGetIntegerv(GL_SAMPLES, &samples);
704 if (samples > 1)
705 {
706 // MSAA on default framebuffer isn't working because of glBlitFramebuffer.
707 // It also isn't useful as we don't render anything to the default framebuffer.
708 // We also try to get a non-msaa fb, so this only happens when forced by the driver.
709 PanicAlertFmtT(
710 "The graphics driver is forcibly enabling anti-aliasing for Dolphin. You need to "
711 "turn this off in the graphics driver's settings in order for Dolphin to work.\n\n"
712 "(MSAA with {0} samples found on default framebuffer)",
713 samples);
714 bSuccess = false;
715 }
716
717 if (!bSuccess)
718 return false;
719
720 g_Config.VerifyValidity();
721 UpdateActiveConfig();
722
723 OSD::AddMessage(fmt::format("Video Info: {}, {}, {}", g_ogl_config.gl_vendor,
724 g_ogl_config.gl_renderer, g_ogl_config.gl_version),
725 5000);
726
727 if (!g_ogl_config.bSupportsGLBufferStorage && !g_ogl_config.bSupportsGLPinnedMemory)
728 {
729 OSD::AddMessage(fmt::format("Your OpenGL driver does not support {}_buffer_storage.",
730 m_main_gl_context->IsGLES() ? "EXT" : "ARB"),
731 60000);
732 OSD::AddMessage("This device's performance may be poor.", 60000);
733 }
734
735 INFO_LOG_FMT(VIDEO, "Video Info: {}, {}, {}", g_ogl_config.gl_vendor, g_ogl_config.gl_renderer,
736 g_ogl_config.gl_version);
737
738 const std::string missing_extensions = fmt::format(
739 "{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
740 g_backend_info.bSupportsDualSourceBlend ? "" : "DualSourceBlend ",
741 g_backend_info.bSupportsPrimitiveRestart ? "" : "PrimitiveRestart ",
742 g_backend_info.bSupportsEarlyZ ? "" : "EarlyZ ",
743 g_ogl_config.bSupportsGLPinnedMemory ? "" : "PinnedMemory ",
744 supports_glsl_cache ? "" : "ShaderCache ",
745 g_ogl_config.bSupportsGLBaseVertex ? "" : "BaseVertex ",
746 g_ogl_config.bSupportsGLBufferStorage ? "" : "BufferStorage ",
747 g_ogl_config.bSupportsGLSync ? "" : "Sync ", g_ogl_config.bSupportsMSAA ? "" : "MSAA ",
748 g_backend_info.bSupportsSSAA ? "" : "SSAA ",
749 g_backend_info.bSupportsGSInstancing ? "" : "GSInstancing ",
750 g_backend_info.bSupportsClipControl ? "" : "ClipControl ",
751 g_ogl_config.bSupportsCopySubImage ? "" : "CopyImageSubData ",
752 g_backend_info.bSupportsDepthClamp ? "" : "DepthClamp ");
753
754 if (missing_extensions.empty())
755 INFO_LOG_FMT(VIDEO, "All used OGL Extensions are available.");
756 else
757 WARN_LOG_FMT(VIDEO, "Missing OGL Extensions: {}", missing_extensions);
758
759 return true;
760 }
761
762 } // namespace OGL