Blender V5.3
gl_backend.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cctype>
10#include <cstdint>
11#include <cstdlib>
12#include <string>
13
14#include "BKE_global.hh"
15#if defined(WIN32)
16# include "BLI_winstuff.hh"
17#endif
18#include "BLI_array.hh"
19#include "BLI_span.hh"
20#include "BLI_string_ref.hh"
21#include "BLI_subprocess.hh"
22#include "BLI_threads.hh"
23#include "BLI_vector.hh"
24
25#include "CLG_log.h"
26
27#include "DNA_userdef_types.h"
28
31
32#include "gl_debug.hh"
33
34#include "gl_backend.hh"
35
36namespace blender {
37
38static CLG_LogRef LOG = {"gpu.opengl"};
39
40namespace gpu {
41
42/* -------------------------------------------------------------------- */
45
46static bool match_renderer(StringRef renderer, const Vector<std::string> &items)
47{
48 for (const std::string &item : items) {
49 const std::string wrapped = " " + item + " ";
50 if (renderer.endswith(item) || renderer.find(wrapped) != StringRef::not_found) {
51 return true;
52 }
53 }
54 return false;
55}
56
57static bool parse_version(const std::string &version,
58 const std::string &format,
59 Vector<int> &r_version)
60{
61 int f = 0;
62 std::string subversion;
63 for (int v : IndexRange(version.size())) {
64 bool match = false;
65 if (format[f] == '0') {
66 if (std::isdigit(version[v])) {
67 match = true;
68 subversion.push_back(version[v]);
69 }
70 }
71 else {
72 match = version[v] == format[f];
73 if (!subversion.empty()) {
74 r_version.append(std::stoi(subversion));
75 subversion.clear();
76 }
77 }
78
79 if (!match) {
80 f = 0;
81 subversion.clear();
82 r_version.clear();
83 continue;
84 }
85
86 f++;
87
88 if (f == format.size()) {
89 return true;
90 }
91 }
92
93 return false;
94}
95
97static bool is_bad_AMD_driver(const char *version_cstr)
98{
99 std::string version_str = version_cstr;
100 /* Allow matches when the version number is at the string end. */
101 version_str.push_back(' ');
102
103 Vector<int> version;
104
105 if (parse_version(version_str, " 00.00.00.00 ", version) ||
106 parse_version(version_str, " 00.00.0.000000 ", version) ||
107 parse_version(version_str, " 00.00.00.000000 ", version) ||
108 parse_version(version_str, " 00.00.000000 ", version) ||
109 parse_version(version_str, " 00.00.00 ", version) ||
110 parse_version(version_str, " 00.00.0 ", version) ||
111 parse_version(version_str, " 00.0.00 ", version) ||
112 parse_version(version_str, " 00.Q0.", version))
113 {
114 return version[0] < 23;
115 }
116 /* Some drivers only expose the Windows version https://gpuopen.com/version-table/ */
117 if (parse_version(version_str, " 00.00.00000.00000 ", version) ||
118 parse_version(version_str, " 00.00.00000.0000 ", version) ||
119 parse_version(version_str, " 00.00.0000.00000 ", version))
120 {
121 return version[0] < 31 || (version[0] == 31 && version[2] < 21001);
122 }
123
124 /* Unknown version, assume it's a bad one. */
125 return true;
126}
127
128void GLBackend::platform_init()
129{
131
132 const char *vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
133 const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
134 const char *version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
139
140#ifdef _WIN32
141 os = GPU_OS_WIN;
142#else
143 os = GPU_OS_UNIX;
144#endif
145
146 if (!vendor) {
147 printf("Warning: No OpenGL vendor detected.\n");
148 device = GPU_DEVICE_UNKNOWN;
149 driver = GPU_DRIVER_ANY;
150 }
151 else if (strstr(renderer, "Mesa DRI R") ||
152 (strstr(renderer, "Radeon") && (strstr(vendor, "X.Org") || strstr(version, "Mesa"))) ||
153 (strstr(renderer, "AMD") && (strstr(vendor, "X.Org") || strstr(version, "Mesa"))) ||
154 (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI ")) ||
155 (strstr(renderer, "Gallium ") && strstr(renderer, " on AMD ")))
156 {
157 device = GPU_DEVICE_ATI;
158 driver = GPU_DRIVER_OPENSOURCE;
159 }
160 else if (strstr(vendor, "ATI") || strstr(vendor, "AMD")) {
161 device = GPU_DEVICE_ATI;
162 driver = GPU_DRIVER_OFFICIAL;
163 }
164 else if (strstr(vendor, "NVIDIA")) {
165 device = GPU_DEVICE_NVIDIA;
166 driver = GPU_DRIVER_OFFICIAL;
167 }
168 else if (strstr(vendor, "Intel") ||
169 /* src/mesa/drivers/dri/intel/intel_context.c */
170 strstr(renderer, "Mesa DRI Intel") || strstr(renderer, "Mesa DRI Mobile Intel"))
171 {
172 device = GPU_DEVICE_INTEL;
173 driver = GPU_DRIVER_OFFICIAL;
174
175 if (strstr(renderer, "UHD Graphics") ||
176 /* Not UHD but affected by the same bugs. */
177 strstr(renderer, "HD Graphics 530") || strstr(renderer, "Kaby Lake GT2") ||
178 strstr(renderer, "Whiskey Lake"))
179 {
180 device |= GPU_DEVICE_INTEL_UHD;
181 }
182 }
183 else if (strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) {
184 device = GPU_DEVICE_NVIDIA;
185 driver = GPU_DRIVER_OPENSOURCE;
186 }
187 else if (strstr(vendor, "Mesa")) {
188 device = GPU_DEVICE_SOFTWARE;
189 driver = GPU_DRIVER_SOFTWARE;
190 }
191 else if (strstr(vendor, "Microsoft")) {
192 /* Qualcomm devices use Mesa's GLOn12, which claims to be vended by Microsoft */
193 if (strstr(renderer, "Qualcomm")) {
194 device = GPU_DEVICE_QUALCOMM;
195 driver = GPU_DRIVER_OFFICIAL;
196 }
197 else {
198 device = GPU_DEVICE_SOFTWARE;
199 driver = GPU_DRIVER_SOFTWARE;
200 }
201 }
202 else if (strstr(vendor, "Apple")) {
203 /* Apple Silicon. */
204 device = GPU_DEVICE_APPLE;
205 driver = GPU_DRIVER_OFFICIAL;
206 }
207 else if (strstr(renderer, "Apple Software Renderer")) {
208 device = GPU_DEVICE_SOFTWARE;
209 driver = GPU_DRIVER_SOFTWARE;
210 }
211 else if (strstr(renderer, "llvmpipe") || strstr(renderer, "softpipe")) {
212 device = GPU_DEVICE_SOFTWARE;
213 driver = GPU_DRIVER_SOFTWARE;
214 }
215 else {
216 printf("Warning: Could not find a matching GPU name. Things may not behave as expected.\n");
217 printf("Detected OpenGL configuration:\n");
218 printf("Vendor: %s\n", vendor);
219 printf("Renderer: %s\n", renderer);
220 }
221
222 /* Detect support level */
223 if (!(epoxy_gl_version() >= 43)) {
224 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
225 }
226 else {
227#if defined(WIN32)
228 long long driverVersion = 0;
229 if (device & GPU_DEVICE_QUALCOMM) {
230 if (BLI_windows_get_directx_driver_version(L"Qualcomm(R) Adreno(TM)", &driverVersion)) {
231 /* Parse out the driver version in format x.x.x.x */
232 WORD ver0 = (driverVersion >> 48) & 0xffff;
233 WORD ver1 = (driverVersion >> 32) & 0xffff;
234 WORD ver2 = (driverVersion >> 16) & 0xffff;
235
236 /* Any Qualcomm driver older than 30.x.x.x will never capable of running blender >= 4.0
237 * As due to an issue in D3D typed UAV load capabilities, Compute Shaders are not available
238 * 30.0.3820.x and above are capable of running blender >=4.0, but these drivers
239 * are only available on 8cx gen3 devices or newer */
240 if (ver0 < 30 || (ver0 == 30 && ver1 == 0 && ver2 < 3820)) {
241 std::cout
242 << "=====================================\n"
243 << "Qualcomm drivers older than 30.0.3820.x cannot run Blender 4.0 or later.\n"
244 << "If your device is older than an 8cx Gen3, you must use a 3.x LTS release.\n"
245 << "If you have an 8cx Gen3 or newer device, a driver update may be available.\n"
246 << "=====================================\n";
247 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
248 }
249 }
250 }
251 if (device & GPU_DEVICE_NVIDIA) {
252 if (BLI_windows_get_directx_driver_version(L"NVIDIA", &driverVersion)) {
253 /* The driver version is packed as four 16bit values, most significant first, matching the
254 * `x.x.x.x` versioning scheme used by Windows. */
255 constexpr long long last_unsupported_version = (23LL << 48) | (21LL << 32) | (13LL << 16) |
256 9135LL;
257 /* Drivers 23.21.13.9135 (391.35) and older are the last of the 391 branch. They are known
258 * to be broken and are no longer updated, so they cannot run Blender. */
259 if (driverVersion <= last_unsupported_version) {
260 std::cout << "=====================================\n"
261 << "NVIDIA drivers 23.21.13.9135 (391.35) and older are not supported.\n"
262 << "Please update to a newer driver.\n"
263 << "=====================================\n";
264 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
265 }
266 }
267 }
268#endif
269 if ((device & GPU_DEVICE_INTEL) && (os & GPU_OS_WIN)) {
270 /* Old Intel drivers with known bugs that cause material properties to crash.
271 * Version Build 10.18.14.5067 is the latest available and appears to be working
272 * ok with our workarounds, so excluded from this list. */
273 if (strstr(version, "Build 7.14") || strstr(version, "Build 7.15") ||
274 strstr(version, "Build 8.15") || strstr(version, "Build 9.17") ||
275 strstr(version, "Build 9.18") || strstr(version, "Build 10.18.10.3") ||
276 strstr(version, "Build 10.18.10.4") || strstr(version, "Build 10.18.10.5") ||
277 strstr(version, "Build 10.18.14.4"))
278 {
279 support_level = GPU_SUPPORT_LEVEL_LIMITED;
280 }
281 /* A rare GPU that has z-fighting issues in edit mode. (see #128179) */
282 if (strstr(renderer, "HD Graphics 405")) {
283 support_level = GPU_SUPPORT_LEVEL_LIMITED;
284 }
285 /* Latest Intel driver have bugs that won't allow Blender to start.
286 * Users must install different version of the driver.
287 * See #113124 for more information. */
288 if (strstr(version, "Build 20.19.15.51")) {
289 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
290 }
291 }
292 if ((device & GPU_DEVICE_ATI) && (os & GPU_OS_UNIX)) {
293 /* Platform seems to work when SB backend is disabled. This can be done
294 * by adding the environment variable `R600_DEBUG=nosb`. */
295 if (strstr(renderer, "AMD CEDAR")) {
296 support_level = GPU_SUPPORT_LEVEL_LIMITED;
297 }
298 }
299 if ((device & GPU_DEVICE_QUALCOMM) && (os & GPU_OS_WIN)) {
300 if (strstr(version, "Mesa 20.") || strstr(version, "Mesa 21.") ||
301 strstr(version, "Mesa 22.") || strstr(version, "Mesa 23."))
302 {
303 std::cerr << "Unsupported driver. Requires at least Mesa 24.0.0." << std::endl;
304 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
305 }
306 }
307
308 /* Check SSBO bindings requirement. */
309 GLint max_ssbo_binds_vertex;
310 GLint max_ssbo_binds_fragment;
311 GLint max_ssbo_binds_compute;
312 glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &max_ssbo_binds_vertex);
313 glGetIntegerv(GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &max_ssbo_binds_fragment);
314 glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &max_ssbo_binds_compute);
315 GLint max_ssbo_binds = std::min(
316 {max_ssbo_binds_vertex, max_ssbo_binds_fragment, max_ssbo_binds_compute});
317 if (max_ssbo_binds < 12) {
318 std::cout << "Warning: Unsupported platform as it supports max " << max_ssbo_binds
319 << " SSBO binding locations\n";
320 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
321 }
322
323 if (!epoxy_has_gl_extension("GL_ARB_shader_draw_parameters")) {
324 std::cout << "Error: The OpenGL implementation doesn't support ARB_shader_draw_parameters\n";
325 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
326 }
327
328 if (!epoxy_has_gl_extension("GL_ARB_clip_control")) {
329 std::cout << "Error: The OpenGL implementation doesn't support ARB_clip_control\n";
330 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
331 }
332
333 if (!epoxy_has_gl_extension("GL_ARB_get_texture_sub_image")) {
334 std::cout << "Error: The OpenGL implementation doesn't support ARB_get_texture_sub_image\n";
335 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
336 }
337 }
338
339 /* Compute shaders have some issues with those versions (see #94936). */
340 if ((device & GPU_DEVICE_ATI) && (driver & GPU_DRIVER_OFFICIAL) &&
341 (strstr(version, "4.5.14831") || strstr(version, "4.5.14760")))
342 {
343 support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED;
344 }
345
346 GPG.init(device,
347 os,
348 driver,
349 support_level,
351 vendor,
352 renderer,
353 version,
355
356 GPG.devices.append(
357 {.identifier = "OPENGL", .index = 0, .vendor_id = 0, .device_id = 0, .name = renderer});
358
362
363 if (epoxy_has_gl_extension("GL_EXT_memory_object")) {
364 GLint number_of_devices = 0;
365 glGetIntegerv(GL_NUM_DEVICE_UUIDS_EXT, &number_of_devices);
366 /* Multiple devices could be used by the context if certain extensions like multi-cast is used.
367 * But this is not used by Blender, so this should always be 1. */
368 BLI_assert(number_of_devices == 1);
369
370 GLubyte device_uuid[GL_UUID_SIZE_EXT] = {0};
371 glGetUnsignedBytei_vEXT(GL_DEVICE_UUID_EXT, 0, device_uuid);
372 GPG.device_uuid = Array<uint8_t, 16>(Span<uint8_t>(device_uuid, GL_UUID_SIZE_EXT));
373
374 /* LUID is only supported on Windows. */
375 if (epoxy_has_gl_extension("GL_EXT_memory_object_win32") && (os & GPU_OS_WIN)) {
376 GLubyte device_luid[GL_LUID_SIZE_EXT] = {0};
377 glGetUnsignedBytevEXT(GL_DEVICE_LUID_EXT, device_luid);
378 GPG.device_luid = Array<uint8_t, 8>(Span<uint8_t>(device_luid, GL_LUID_SIZE_EXT));
379
380 GLint node_mask = 0;
381 glGetIntegerv(GL_DEVICE_NODE_MASK_EXT, &node_mask);
383 }
384 }
385}
386
387void GLBackend::platform_exit()
388{
390 GPG.clear();
391}
392
394{
396 CLOG_TRACE(&LOG, "Using texture pool \"TexturePoolImpl\".");
397 return new TexturePoolImpl();
398 }
399
400 CLOG_TRACE(&LOG, "Using texture pool \"GLTexturePool\".");
401 return new GLTexturePool();
402}
403
405
406/* -------------------------------------------------------------------- */
409
410static const char *gl_extension_get(int i)
411{
412 return reinterpret_cast<char *>(const_cast<GLubyte *>(glGetStringi(GL_EXTENSIONS, i)));
413}
414
416{
417 const char *vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
418 const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
419 const char *version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
420
421 if (G.debug & G_DEBUG_GPU_FORCE_WORKAROUNDS) {
422 printf("\n");
423 printf("GL: Forcing workaround usage and disabling extensions.\n");
424 printf(" OpenGL identification strings\n");
425 printf(" vendor: %s\n", vendor);
426 printf(" renderer: %s\n", renderer);
427 printf(" version: %s\n\n", version);
433 /* Turn off Blender features. */
435 /* Turn off OpenGL 4.4 features. */
438 /* Turn off OpenGL 4.5 features. */
441 /* Turn off OpenGL 4.6 features. */
443 /* Turn off extensions. */
447 /* Turn off vendor specific extensions. */
452
453#if 0
454 /* Do not alter OpenGL 4.3 features.
455 * These code paths should be removed. */
457#endif
458
459 return;
460 }
461
463 (strstr(version, "4.5.13399") || strstr(version, "4.5.13417") ||
464 strstr(version, "4.5.13422") || strstr(version, "4.5.13467")))
465 {
466 /* The renderers include:
467 * Radeon HD 5000;
468 * Radeon HD 7500M;
469 * Radeon HD 7570M;
470 * Radeon HD 7600M;
471 * Radeon R5 Graphics;
472 * And others... */
474 }
475 /* We have issues with this specific renderer. (see #74024) */
477 (strstr(renderer, "AMD VERDE") || strstr(renderer, "AMD KAVERI") ||
478 strstr(renderer, "AMD TAHITI")))
479 {
481 }
482 /* See #82856: AMD drivers since 20.11 running on a polaris architecture doesn't support the
483 * `GL_INT_2_10_10_10_REV` data type correctly. This data type is used to pack normals and flags.
484 * The work around uses `TextureFormat::SINT_16_16_16_16`. In 22.?.? drivers this
485 * has been fixed for polaris platform. Keeping legacy platforms around just in case.
486 */
488 /* Check for AMD legacy driver. Assuming that when these drivers are used this bug is present.
489 */
490 if (is_bad_AMD_driver(version)) {
492 }
493 const Vector<std::string> matches = {
494 "RX550/550", "(TM) 520", "(TM) 530", "(TM) 535", "R5", "R7", "R9", "HD"};
495
496 if (match_renderer(renderer, matches)) {
498 }
499 }
500
501 /* Maybe not all of these drivers have problems with `GL_ARB_base_instance`.
502 * But it's hard to test each case.
503 * We get crashes from some crappy Intel drivers don't work well with shaders created in
504 * different rendering contexts. */
506 (strstr(version, "Build 10.18.10.3") || strstr(version, "Build 10.18.10.4") ||
507 strstr(version, "Build 10.18.10.5") || strstr(version, "Build 10.18.14.4") ||
508 strstr(version, "Build 10.18.14.5")))
509 {
511 }
512 /* Somehow fixes armature display issues (see #69743). */
514 strstr(version, "Build 20.19.15.4285"))
515 {
517 }
518 /* Reading the front-buffer may not return the most recently drawn contents. */
521 }
522 /* Needed to avoid driver hangs on legacy AMD drivers (see #139939). */
524 is_bad_AMD_driver(version))
525 {
527 }
528 /* See #70187: merging vertices fail. This has been tested from `18.2.2` till `19.3.0~dev`
529 * of the Mesa driver */
531 (strstr(version, "Mesa 18.") || strstr(version, "Mesa 19.0") ||
532 strstr(version, "Mesa 19.1") || strstr(version, "Mesa 19.2")))
533 {
535 }
536
537/* Snapdragon X Elite devices currently have a driver bug that results in
538 * eevee rendering a black cube with anything except an emission shader
539 * if shader draw parameters are enabled (#122837) */
540#if defined(WIN32)
541 long long driverVersion = 0;
543 if (BLI_windows_get_directx_driver_version(L"Qualcomm(R) Adreno(TM)", &driverVersion)) {
544 /* Parse out the driver version */
545 WORD ver0 = (driverVersion >> 48) & 0xffff;
546
547 /* X Elite devices have GPU driver version 31, and currently no known release version of the
548 * GPU driver renders the cube correctly. This will be changed when a working driver version
549 * is released to commercial devices to only enable this flags on older drivers. */
550 if (ver0 == 31) {
552 }
553
554 /* Disable OpenGL texture pool on Snapdragon 8cx Gen 3 devices. See #142229. We assume that
555 * these devices use driver 30.x.x.x */
556 if (ver0 == 30) {
558 /* sRGB texture writes through non-sRGB texture view fails on these devices. */
560 }
561 }
562 }
563#endif
564
565 /* Enable our own incomplete debug layer if no other is available. */
566 if (GLContext::debug_layer_support == false) {
568 }
569
570 /* There is an issue in AMD official driver where we cannot use multi bind when using images. AMD
571 * is aware of the issue, but hasn't released a fix. */
574 }
575
576 if (G.debug & G_DEBUG_GPU_NO_TEXTURE_POOL) {
578 }
579
580#ifdef _WIN32
583 {
584 int driver_version_minor = 0, driver_version_major = 0;
586 if (epoxy_has_gl_extension("GL_EXT_memory_object_win32")) {
587 uint64_t device_luid = 0;
588 glGetUnsignedBytevEXT(GL_DEVICE_LUID_EXT, reinterpret_cast<GLubyte *>(&device_luid));
589 uint32_t device_id = 0;
591 device_luid, &driver_version_minor, &driver_version_major, &device_id))
592 {
593 gpu_arch = GPU_platform_get_intel_arch(device_id);
594 }
595 }
596
597 /* #107642, #120273 The legacy Intel 7-10th Gen Processor iGPU driver incorrectly reports that
598 * image binding is supported. But when used it results in `GL_INVALID_OPERATION` with
599 * `internal format of texture N is not supported`. 101.5972 is the oldest checked driver where
600 * it was manually confirmed that this issue is no longer present on newer driver versions. */
601 if (driver_version_major < 101 || (driver_version_major == 101 && driver_version_minor < 5972))
602 {
604 }
605
606 /* glTextureView was fixed for Intel Xe2+ with driver version 101.8801. */
607 if (gpu_arch <= GPUIntelGpuArch::Gen12 || driver_version_major < 101 ||
608 (driver_version_major == 101 && driver_version_minor < 8801))
609 {
611 }
612 }
613#endif
614
615 /* Disable texture pool on closed source AMD driver; glTextureView
616 * breaks frame-buffers for several formats. This is not an issue on Mesa. */
619 }
620
621 /* Metal-related Workarounds. */
622
623 /* Minimum Per-Vertex stride is 1 byte for OpenGL. */
625}
626
628
632
634
648
650
653
654void GLBackend::capabilities_init()
655{
656 BLI_assert(epoxy_gl_version() >= 33);
657 /* Common Capabilities. */
658 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GCaps.max_texture_size);
659 glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &GCaps.max_texture_layers);
660 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &GCaps.max_textures);
661 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &GCaps.max_uniforms_vert);
662 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &GCaps.max_uniforms_frag);
663 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &GCaps.max_batch_indices);
664 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &GCaps.max_batch_vertices);
665 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &GCaps.max_vertex_attribs);
666 glGetIntegerv(GL_MAX_VARYING_FLOATS, &GCaps.max_varying_floats);
667 glGetIntegerv(GL_MAX_IMAGE_UNITS, &GCaps.max_images);
668
669 glGetIntegerv(GL_NUM_EXTENSIONS, &GCaps.extensions_len);
671
672 GCaps.mem_stats_support = epoxy_has_gl_extension("GL_NVX_gpu_memory_info") ||
673 epoxy_has_gl_extension("GL_ATI_meminfo");
678
680
681 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, &GCaps.max_work_group_count[0]);
682 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, &GCaps.max_work_group_count[1]);
683 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, &GCaps.max_work_group_count[2]);
684 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &GCaps.max_work_group_size[0]);
685 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, &GCaps.max_work_group_size[1]);
686 glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, &GCaps.max_work_group_size[2]);
687 glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &GCaps.max_shader_storage_buffer_bindings);
688 glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &GCaps.max_compute_shader_storage_blocks);
689 int64_t max_ssbo_size, max_ubo_size;
690 glGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &max_ubo_size);
691 GCaps.max_uniform_buffer_size = size_t(max_ubo_size);
692 glGetInteger64v(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_ssbo_size);
693 GCaps.max_storage_buffer_size = size_t(max_ssbo_size);
694 GLint ssbo_alignment;
695 glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &ssbo_alignment);
696 GCaps.storage_buffer_alignment = size_t(ssbo_alignment);
697
698 GCaps.stencil_export_support = epoxy_has_gl_extension("GL_ARB_shader_stencil_export");
699
700 /* GL specific capabilities. */
701 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &GCaps.max_texture_3d_size);
702 glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE,
703 reinterpret_cast<int *>(&GCaps.max_buffer_texture_size));
704 glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &GLContext::max_cubemap_size);
705 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GLContext::max_ubo_binds);
706 GLint max_ssbo_binds;
708 glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &max_ssbo_binds);
710 glGetIntegerv(GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &max_ssbo_binds);
712 glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &max_ssbo_binds);
714 GLContext::debug_layer_support = epoxy_gl_version() >= 43 ||
715 epoxy_has_gl_extension("GL_KHR_debug") ||
716 epoxy_has_gl_extension("GL_ARB_debug_output");
717 GLContext::direct_state_access_support = epoxy_has_gl_extension("GL_ARB_direct_state_access");
718 GLContext::framebuffer_fetch_support = epoxy_has_gl_extension("GL_EXT_shader_framebuffer_fetch");
719 GLContext::texture_barrier_support = epoxy_has_gl_extension("GL_ARB_texture_barrier");
720 GLContext::layered_rendering_support = epoxy_has_gl_extension(
721 "GL_ARB_shader_viewport_layer_array");
723 "GL_AMD_vertex_shader_viewport_index");
724 GLContext::vertex_shader_layer_support = epoxy_has_gl_extension("GL_AMD_vertex_shader_layer");
725 GLContext::native_barycentric_support = epoxy_has_gl_extension(
726 "GL_AMD_shader_explicit_vertex_parameter");
728 "GL_ARB_multi_bind");
729 GLContext::stencil_texturing_support = epoxy_gl_version() >= 43;
730 GLContext::derivative_control_support = epoxy_gl_version() >= 45 ||
731 epoxy_has_gl_extension("GL_ARB_derivative_control");
732 GLContext::texture_filter_anisotropic_support = epoxy_has_gl_extension(
733 "GL_EXT_texture_filter_anisotropic");
734
735 /* Disabled until it is proven to work. */
737
739
740#if BLI_SUBPROCESS_SUPPORT
741 GCaps.use_subprocess_shader_compilations = U.shader_compilation_method ==
743#else
745#endif
746 if (G.debug & G_DEBUG_GPU_RENDERDOC) {
747 /* Avoid crashes on RenderDoc sessions. */
749 }
750
751 int thread_count = U.gpu_shader_workers;
752
753 if (thread_count == 0) {
754 /* Good default based on measurements. */
755
756 /* Always have at least 1 worker. */
757 thread_count = 1;
758
760 /* Use reasonable number of worker by default when there are known gains. */
764 {
765 /* Subprocess is too costly in memory (>150MB per worker) to have better defaults. */
766 thread_count = std::max(1, std::min(4, BLI_system_thread_count() / 2));
767 }
768 }
770 /* Best middle ground between memory usage and speedup as Nvidia context memory footprint
771 * is quite heavy (~25MB). Moreover we have diminishing return after this because of PSO
772 * compilation blocking the main thread.
773 * Can be revisited if we find a way to delete the worker thread context after finishing
774 * compilation, and fix the scheduling bubbles (#139775). */
775 thread_count = 4;
776 }
779 {
780 /* Mesa has very good compilation time and doesn't block the main thread.
781 * The memory footprint of the worker context is rather small (<10MB).
782 * Shader compilation gets much slower as the number of threads increases. */
783 thread_count = 8;
784 }
786 /* AMD proprietary driver's context have huge memory footprint (~45MB).
787 * There is also not much gain from parallelization. */
788 thread_count = 1;
789 }
791 /* Intel windows driver offer almost no speedup with parallel compilation. */
792 thread_count = 1;
793 }
794 }
795
796 /* Allow thread count override option to limit the number of workers and avoid allocating more
797 * workers than needed. Also ensures that there is always 1 thread available for the UI. */
798 int max_thread_count = std::max(1, BLI_system_thread_count() - 1);
799
800 GCaps.max_parallel_compilations = std::min(thread_count, max_thread_count);
801
802 /* Disable this feature entirely when not debugging. */
803 if ((G.debug & G_DEBUG_GPU) == 0) {
806 }
807}
808
810
811/* -------------------------------------------------------------------- */
814
815void GLBackend::log_extensions()
816{
818 "OpenGL Extensions\n"
819 " - [%c] Multi-bind\n"
820 " - [%c] Direct state access\n"
821 " - [%c] Anisotropic Texture Filtering\n"
822 " - [%c] Layered rendering\n"
823 " - [%c] Vertex shader viewport index\n"
824 " - [%c] Vertex shader layer array\n"
825 " - [%c] Native barycentric coordinates\n"
826 " - [%c] Framebuffer fetch\n"
827 " - [%c] Texture barrier\n"
828 " - [%c] Shader stencil export\n"
829 " - [%c] Derivative control\n",
839 GCaps.stencil_export_support ? 'X' : ' ',
841}
842
844
845/* -------------------------------------------------------------------- */
848
849void GLBackend::log_workarounds()
850{
852 "OpenGL Workarounds\n"
853 " - [%c] Debug layer workaround\n"
854 " - [%c] Unused framebuffer slot workaround\n"
855 " - [%c] Depth blitting workaround\n"
856 " - [%c] Stencil classify buffer workaround\n"
857 " - [%c] High-quality normals\n"
858 " - [%c] Use main context\n",
865}
866
868
869} // namespace gpu
870} // namespace blender
Compatibility-like things for windows.
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_TRACE(clg_ref,...)
Definition CLG_log.h:192
#define U
#define BLI_assert(a)
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
constexpr IndexRange()=default
static constexpr int64_t not_found
constexpr int64_t find(char c, int64_t pos=0) const
constexpr bool endswith(StringRef suffix) const
TexturePool * texturepool_alloc() override
static bool stencil_texturing_support
Definition gl_context.hh:72
static bool layered_rendering_support
Definition gl_context.hh:66
static bool debug_layer_support
Definition gl_context.hh:59
static bool framebuffer_fetch_support
Definition gl_context.hh:61
static GLint max_ssbo_binds
Definition gl_context.hh:55
static bool debug_layer_workaround
Definition gl_context.hh:79
static bool vertex_shader_layer_support
Definition gl_context.hh:68
static GLint max_ubo_binds
Definition gl_context.hh:54
static bool direct_state_access_support
Definition gl_context.hh:60
static bool texture_filter_anisotropic_support
Definition gl_context.hh:74
static bool unused_fb_slot_workaround
Definition gl_context.hh:80
static bool multi_bind_support
Definition gl_context.hh:70
static GLint max_cubemap_size
Definition gl_context.hh:53
static bool texture_barrier_support
Definition gl_context.hh:73
static bool native_barycentric_support
Definition gl_context.hh:69
static bool multi_bind_image_support
Definition gl_context.hh:71
static bool vertex_shader_viewport_index_support
Definition gl_context.hh:67
static bool derivative_control_support
Definition gl_context.hh:75
void init(GPUDeviceType gpu_device, GPUOSType os_type, GPUDriverType driver_type, GPUSupportLevel gpu_support_level, GPUBackendType backend, const char *vendor_str, const char *renderer_str, const char *version_str, GPUArchitectureType arch_type)
#define L
GPUPlatformGlobal GPG
static bool parse_version(const std::string &version, const std::string &format, Vector< int > &r_version)
Definition gl_backend.cc:57
static void detect_workarounds()
static bool is_bad_AMD_driver(const char *version_cstr)
Definition gl_backend.cc:97
GPUCapabilities GCaps
static const char * gl_extension_get(int i)
static bool match_renderer(StringRef renderer, const Vector< std::string > &items)
Definition gl_backend.cc:46
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
ATTR_WARN_UNUSED_RESULT const BMVert * v
@ GPU_DRIVER_OFFICIAL
@ GPU_DRIVER_SOFTWARE
@ GPU_DRIVER_OPENSOURCE
bool BLI_windows_get_directx_driver_version(const wchar_t *deviceSubString, long long *r_driverVersion)
@ G_DEBUG_GPU_NO_TEXTURE_POOL
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
@ G_DEBUG_GPU_RENDERDOC
@ GPU_SUPPORT_LEVEL_UNSUPPORTED
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
Global G
Definition blender.cc:57
int BLI_system_thread_count()
Definition threads.cc:258
unsigned int uint32_t
Definition BKE_text.h:81
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
@ GPU_ARCHITECTURE_IMR
GPUIntelGpuArch GPU_platform_get_intel_arch(uint32_t device_id)
bool BLI_windows_get_directx_intel_driver_info(uint64_t device_luid, int *driver_version_minor, int *driver_version_major, uint32_t *device_id)
static CLG_LogRef LOG
Definition logging.cpp:12
@ USER_SHADER_COMPILE_SUBPROCESS
MINLINE int min_ii(int a, int b)
@ GPU_DEVICE_QUALCOMM
@ GPU_DEVICE_SOFTWARE
@ GPU_DEVICE_INTEL_UHD
@ GPU_DEVICE_UNKNOWN
@ GPU_DEVICE_INTEL
@ GPU_DEVICE_NVIDIA
@ GPU_DEVICE_APPLE