Skip to content

[WPE] Memory-mapped GPU buffers fail under DRM platform #47208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nikolaszimmermann
Copy link
Contributor

@nikolaszimmermann nikolaszimmermann commented Jun 25, 2025

2fee37e

[WPE] Memory-mapped GPU buffers fail under DRM platform
https://bugs.webkit.org/show_bug.cgi?id=294995

Reviewed by NOBODY (OOPS!).

When using the DRM platform on i.MX systems with separate GPU and IPU, memory-
mapped GPU buffers failed to initialize properly. The DRM implementation
correctly chooses the first KMS-capable device (e.g. /dev/dri/card1) for
display buffer allocation. However, it incorrectly propagates the same node
to DRMDeviceManager as 'drmRenderNode' -- which is meant to be associated with
the "main device". For an overview about the terminology (main device vs. target
device), see: https://wayland.app/protocols/linux-dmabuf-v1#zwp_linux_dmabuf_feedback_v1.

Memory-mapped GPU buffers are still able to allocate gbm_bos from card1,
and export them as dma-bufs -- but trying to mmap() will fail, with
EACCESS permission denied error. That operation is only possible for
buffers allocated using the "main device".

The Wayland platform handles this correctly by listening to `main_device` and
`tranche_target_device' linux-dmabuf-v1 events. The GPU is correctly used as
'main device', whereas the display-controller is used as 'target device' --
fix DRM to behave the same.

Covered by existing tests, under DRM backend + linear tile textures
activated.

* Source/WebCore/platform/graphics/gbm/DRMDeviceManager.cpp:
(WebCore::DRMDeviceManager::initializeMainDevice):
(WebCore::DRMDeviceManager::mainGBMDevice const):
(WebCore::DRMDeviceManager::deviceNode):
(WebCore::DRMDeviceManager::mainDeviceNode const): Deleted.
(WebCore::DRMDeviceManager::mainGBMDeviceNode const): Deleted.
* Source/WebCore/platform/graphics/gbm/DRMDeviceManager.h:
* Source/WebCore/platform/graphics/gbm/GraphicsContextGLTextureMapperGBM.cpp:
(WebCore::GraphicsContextGLTextureMapperGBM::createDrawingBuffer const):
* Source/WebCore/platform/graphics/gbm/MemoryMappedGPUBuffer.cpp:
(WebCore::MemoryMappedGPUBuffer::create):
* Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
(initializeDMABufAvailability):
* Source/WebKit/GPUProcess/glib/GPUProcessGLib.cpp:
(WebKit::GPUProcess::platformInitializeGPUProcess):
* Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreDMABuf.cpp:
(WebKit::AcceleratedBackingStoreDMABuf::BufferGBM::create):
* Source/WebKit/WPEPlatform/wpe/drm/WPEDisplayDRM.cpp:
(findTargetDevice):
(findMainDeviceName):
(wpeDisplayDRMSetup):
(findDevice): Deleted.
* Source/WebKit/WebProcess/WebPage/dmabuf/AcceleratedSurfaceDMABuf.cpp:
(WebKit::AcceleratedSurfaceDMABuf::RenderTargetEGLImage::create):
* Source/WebKit/WebProcess/glib/WebProcessGLib.cpp:
(WebKit::WebProcess::initializePlatformDisplayIfNeeded const):

2fee37e

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ❌ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ❌ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

https://bugs.webkit.org/show_bug.cgi?id=294995

Reviewed by NOBODY (OOPS!).

When using the DRM platform on i.MX systems with separate GPU and IPU, memory-
mapped GPU buffers failed to initialize properly. The DRM implementation
correctly chooses the first KMS-capable device (e.g. /dev/dri/card1) for
display buffer allocation. However, it incorrectly propagates the same node
to DRMDeviceManager as 'drmRenderNode' -- which is meant to be associated with
the "main device". For an overview about the terminology (main device vs. target
device), see: https://wayland.app/protocols/linux-dmabuf-v1#zwp_linux_dmabuf_feedback_v1.

Memory-mapped GPU buffers are still able to allocate gbm_bos from card1,
and export them as dma-bufs -- but trying to mmap() will fail, with
EACCESS permission denied error. That operation is only possible for
buffers allocated using the "main device".

The Wayland platform handles this correctly by listening to `main_device` and
`tranche_target_device' linux-dmabuf-v1 events. The GPU is correctly used as
'main device', whereas the display-controller is used as 'target device' --
fix DRM to behave the same.

Covered by existing tests, under DRM backend + linear tile textures
activated.

* Source/WebCore/platform/graphics/gbm/DRMDeviceManager.cpp:
(WebCore::DRMDeviceManager::initializeMainDevice):
(WebCore::DRMDeviceManager::mainGBMDevice const):
(WebCore::DRMDeviceManager::deviceNode):
(WebCore::DRMDeviceManager::mainDeviceNode const): Deleted.
(WebCore::DRMDeviceManager::mainGBMDeviceNode const): Deleted.
* Source/WebCore/platform/graphics/gbm/DRMDeviceManager.h:
* Source/WebCore/platform/graphics/gbm/GraphicsContextGLTextureMapperGBM.cpp:
(WebCore::GraphicsContextGLTextureMapperGBM::createDrawingBuffer const):
* Source/WebCore/platform/graphics/gbm/MemoryMappedGPUBuffer.cpp:
(WebCore::MemoryMappedGPUBuffer::create):
* Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
(initializeDMABufAvailability):
* Source/WebKit/GPUProcess/glib/GPUProcessGLib.cpp:
(WebKit::GPUProcess::platformInitializeGPUProcess):
* Source/WebKit/UIProcess/gtk/AcceleratedBackingStoreDMABuf.cpp:
(WebKit::AcceleratedBackingStoreDMABuf::BufferGBM::create):
* Source/WebKit/WPEPlatform/wpe/drm/WPEDisplayDRM.cpp:
(findTargetDevice):
(findMainDeviceName):
(wpeDisplayDRMSetup):
(findDevice): Deleted.
* Source/WebKit/WebProcess/WebPage/dmabuf/AcceleratedSurfaceDMABuf.cpp:
(WebKit::AcceleratedSurfaceDMABuf::RenderTargetEGLImage::create):
* Source/WebKit/WebProcess/glib/WebProcessGLib.cpp:
(WebKit::WebProcess::initializePlatformDisplayIfNeeded const):
@nikolaszimmermann nikolaszimmermann requested review from a team, philn and cdumez as code owners June 25, 2025 21:49
@nikolaszimmermann nikolaszimmermann self-assigned this Jun 25, 2025
@nikolaszimmermann nikolaszimmermann added the WPE WebKit WebKit WPE component label Jun 25, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merging-blocked Applied to prevent a change from being merged WPE WebKit WebKit WPE component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants