Browse Source

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
rdb 4 years ago
parent
commit
c36fa1ef17

+ 25 - 2
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

+ 6 - 0
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, "

+ 1 - 0
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<CoordinateSystem> gl_coordinate_system;