From c36fa1ef174aab08a2e9a2beb4ba029756a6b469 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 25 Mar 2021 22:59:35 +0100 Subject: [PATCH] glgsg: Workaround driver bug causing flickering in AMD RDNA cards Apparently, the use of glColorPointer with GL_BGRA causes these cards to display garbled vertex colors (tested with RX 5700 XT). This bug doesn't seem to affect glVertexAttribPointer. The "fix" is to just disable packed-dabc colors if these cards are detected. This may cause a minor performance regression since the vertex data now needs to be munged--possibly even unnecessarily, if shaders are used, but this effect is likely very minor (and can be addressed in other ways). Fixes #981 --- .../glstuff/glGraphicsStateGuardian_src.cxx | 27 +++++++++++++++++-- panda/src/glstuff/glmisc_src.cxx | 6 +++++ panda/src/glstuff/glmisc_src.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 2e997a8587..1f6fed0ba0 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1341,11 +1341,34 @@ reset() { _supports_packed_dabc = false; _supports_packed_ufloat = false; #else - _supports_packed_dabc = is_at_least_gl_version(3, 2) || + _supports_packed_dabc = (is_at_least_gl_version(3, 2) || has_extension("GL_ARB_vertex_array_bgra") || - has_extension("GL_EXT_vertex_array_bgra"); + has_extension("GL_EXT_vertex_array_bgra")) && gl_support_vertex_array_bgra; + _supports_packed_ufloat = is_at_least_gl_version(4, 4) || has_extension("GL_ARB_vertex_type_10f_11f_11f_rev"); + + if (_supports_packed_dabc) { + int number = 0; + if (_gl_renderer.compare(0, 14, "AMD Radeon RX ") == 0) { + number = atoi(_gl_renderer.c_str() + 14); + } + else if (_gl_renderer.compare(0, 10, "Radeon RX ") == 0) { + number = atoi(_gl_renderer.c_str() + 10); + } + + // This is buggy for RDNA cards. Verified on 5700 XT, reportedly also + // occurs on the entire 5*00 and 6*00 line. + if (number >= 5000 && number < 8000) { + _supports_packed_dabc = false; + + if (GLCAT.is_debug()) { + GLCAT.debug() + << "Detected AMD Radeon RX " << number + << ", disabling use of GL_BGRA vertex attributes\n"; + } + } + } #endif #ifdef OPENGLES diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 49eaf78a69..2c388985f6 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/panda/src/glstuff/glmisc_src.cxx @@ -304,6 +304,12 @@ ConfigVariableBool gl_support_shadow_filter "cards suffered from a broken implementation of the " "shadow map filtering features.")); +ConfigVariableBool gl_support_vertex_array_bgra + ("gl-support-vertex-array-bgra", true, + PRC_DESC("Disable this if you suspect a bug in the driver implementation " + "of GL_BGRA vertex arrays. The Radeon RX 5700 XT is an example " + "of a card known to suffer from bugs with this feature.")); + ConfigVariableBool gl_force_image_bindings_writeonly ("gl-force-image-bindings-writeonly", false, PRC_DESC("Forces all image inputs (not textures!) to be bound as writeonly, " diff --git a/panda/src/glstuff/glmisc_src.h b/panda/src/glstuff/glmisc_src.h index 415286c674..b815e76ae8 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/panda/src/glstuff/glmisc_src.h @@ -81,6 +81,7 @@ extern ConfigVariableBool gl_fixed_vertex_attrib_locations; extern ConfigVariableBool gl_support_primitive_restart_index; extern ConfigVariableBool gl_support_sampler_objects; extern ConfigVariableBool gl_support_shadow_filter; +extern ConfigVariableBool gl_support_vertex_array_bgra; extern ConfigVariableBool gl_force_image_bindings_writeonly; extern ConfigVariableEnum gl_coordinate_system;