Disable DMABuf renderer for NVIDIA proprietary drivers
authorCarlos Garcia Campos <cgarcia@igalia.com>
Tue, 5 Dec 2023 13:28:29 +0000 (14:28 +0100)
committerAlberto Garcia <berto@igalia.com>
Tue, 5 Dec 2023 13:28:29 +0000 (14:28 +0100)
Bug: https://bugs.webkit.org/show_bug.cgi?id=262607
Bug-Debian: https://bugs.debian.org/1039720
Origin: https://github.com/WebKit/WebKit/pull/18614

===================================================================

Gbp-Pq: Name disable-dmabuf-nvidia.patch

Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreDMABuf.cpp

index 64d04332a598df4693432421528a8daae515b4d2..ecf1ac6ca7607143d72e3957055ad4d57b485dc5 100644 (file)
 #include <WebCore/GLContext.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/PlatformDisplay.h>
+#include <WebCore/PlatformDisplaySurfaceless.h>
 #include <epoxy/egl.h>
 #include <wtf/glib/GUniquePtr.h>
 
 #if USE(GBM)
 #include <WebCore/DMABufFormat.h>
+#include <WebCore/PlatformDisplayGBM.h>
 #include <gbm.h>
 static constexpr uint64_t s_dmabufInvalidModifier = uint64_t(WebCore::DMABufFormat::Modifier::Invalid);
 #else
@@ -55,6 +57,29 @@ static constexpr uint64_t s_dmabufInvalidModifier = ((1ULL << 56) - 1);
 
 namespace WebKit {
 
+static bool isNVIDIA()
+{
+    const char* forceDMABuf = getenv("WEBKIT_FORCE_DMABUF_RENDERER");
+    if (forceDMABuf && strcmp(forceDMABuf, "0"))
+        return false;
+
+    std::unique_ptr<WebCore::PlatformDisplay> platformDisplay;
+#if USE(GBM)
+    const char* disableGBM = getenv("WEBKIT_DMABUF_RENDERER_DISABLE_GBM");
+    if (!disableGBM || !strcmp(disableGBM, "0")) {
+        if (auto* device = WebCore::PlatformDisplay::sharedDisplay().gbmDevice())
+            platformDisplay = WebCore::PlatformDisplayGBM::create(device);
+    }
+#endif
+    if (!platformDisplay)
+        platformDisplay = WebCore::PlatformDisplaySurfaceless::create();
+
+    WebCore::GLContext::ScopedGLContext glContext(WebCore::GLContext::createOffscreen(platformDisplay ? *platformDisplay : WebCore::PlatformDisplay::sharedDisplay()));
+    if (strstr(reinterpret_cast<const char*>(glGetString(GL_VENDOR)), "NVIDIA"))
+        return true;
+    return false;
+}
+
 OptionSet<DMABufRendererBufferMode> AcceleratedBackingStoreDMABuf::rendererBufferMode()
 {
     static OptionSet<DMABufRendererBufferMode> mode;
@@ -70,6 +95,9 @@ OptionSet<DMABufRendererBufferMode> AcceleratedBackingStoreDMABuf::rendererBuffe
             return;
         }
 
+        if (isNVIDIA())
+            return;
+
         mode.add(DMABufRendererBufferMode::SharedMemory);
 
         const auto& eglExtensions = WebCore::PlatformDisplay::sharedDisplay().eglExtensions();