Skip to content

fix: import dmabuf as vulkan render target#1114

Open
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/vulkan-dmabuf-render-target
Open

fix: import dmabuf as vulkan render target#1114
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:fix/vulkan-dmabuf-render-target

Conversation

@deepin-wm

Copy link
Copy Markdown
Contributor

Description

Replace wlr_texture-based VkImage creation in WRenderHelper::acquireRenderTarget with a direct dmabuf import using vulkan_import_dmabuf(for_render=true) logic ported from wlroots 0.20.

Problem

wlr_texture_from_buffer creates a VkImage with VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT (no VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT). Using this VkImage as a render target via QRhiTextureRenderTarget violates Vulkan's requirement that color attachment images have COLOR_ATTACHMENT_BIT usage, causing render target creation failure or validation errors.

Solution

Port wlroots 0.20's vulkan_import_dmabuf(for_render=true) to waylib, creating a VkImage with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT directly from the dmabuf. The implementation uses only public Vulkan and wlroots APIs, with no dependency on wlroots' private renderer structs.

Changes

  • New waylib/src/server/qtquick/private/wvulkandmabufimport_p.h — Declares VkDmabufImage struct and import/release functions
  • New waylib/src/server/qtquick/private/wvulkandmabufimport.cpp — Ported from wlroots 0.20: DRM→VkFormat table, modifier query, memory fd import, disjoint/multi-plane handling
  • Modified waylib/src/server/qtquick/wrenderhelper.cpp — Vulkan branch uses direct dmabuf import; pixman/gles2 branches use scoped std::unique_ptr<qw_texture>; fix BufferData memory leak in onBufferDestroy
  • Modified waylib/src/server/CMakeLists.txt — Register new source/header; add optional Vulkan pkg dependency

Testing

  • GL and pixman rendering paths are unaffected
  • Vulkan render target creation should succeed without validation errors

Multica Issue WM-76

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @deepin-wm, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-wm deepin-wm force-pushed the fix/vulkan-dmabuf-render-target branch 5 times, most recently from abc87c5 to ba161b6 Compare July 8, 2026 11:43
@LFRon

LFRon commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

大佬那DTK应用/DDE组件花屏的问题咋办(
难倒是在DTK上游修嘛

@deepin-wm deepin-wm force-pushed the fix/vulkan-dmabuf-render-target branch from ba161b6 to 55b704c Compare July 8, 2026 12:32
Comment thread waylib/src/server/qtquick/private/wvulkandmabufimport.cpp Outdated
Comment thread waylib/src/server/qtquick/private/wvulkandmabufimport.cpp
Comment thread waylib/src/server/qtquick/private/wvulkandmabufimport.cpp Outdated
Comment thread waylib/src/server/qtquick/private/wvulkandmabufimport.cpp Outdated
Comment thread waylib/src/server/qtquick/wrenderhelper.cpp
@zccrs zccrs marked this pull request as ready for review July 9, 2026 02:25

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @zccrs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@zccrs

zccrs commented Jul 9, 2026

Copy link
Copy Markdown
Member

大佬那DTK应用/DDE组件花屏的问题咋办( 难倒是在DTK上游修嘛

那些组件呀?什么样的画屏,可以搞个图看看

deepin-wm pushed a commit to deepin-wm/treeland that referenced this pull request Jul 9, 2026
- Replace WLR_LITTLE_ENDIAN with Qt's Q_BYTE_ORDER == Q_LITTLE_ENDIAN
- Remove per-format #ifdef DRM_FORMAT guards; define missing macros in CMake
- Fix DRM_FORMAT_XYUV -> DRM_FORMAT_XYUV8888 (correct macro name)
- Make isYCbCr constexpr
- Replace #pragma GCC diagnostic with QT_WARNING_PUSH/POP
- Add else { return {}; } when get_dmabuf fails in acquireRenderTarget
@LFRon

LFRon commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

大佬那DTK应用/DDE组件花屏的问题咋办( 难倒是在DTK上游修嘛

那些组件呀?什么样的画屏,可以搞个图看看

就是大佬说的DTK/DDE组件只能显示个轮廓, 具体原因我TG上放过,我这边是动了wlroots才解决的

@LFRon

LFRon commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

还有大佬, wlroots 0.19版本的也顺便做一下呗

@deepin-wm deepin-wm force-pushed the fix/vulkan-dmabuf-render-target branch 2 times, most recently from d6f8c3d to 50a2562 Compare July 9, 2026 07:11
Groveer added a commit to deepin-wm/treeland that referenced this pull request Jul 9, 2026
Per maintainer zccrs review on PR linuxdeepin#1114: replace the #ifndef fallback
fourcc definitions with #if defined(DRM_FORMAT_xxx) per-entry guards.
The 8 formats added in libdrm >= 2.4.129 (R16F, R32F, GR1616F, GR3232F,
BGR161616, BGR161616F, BGR323232F, ABGR32323232F) are now each wrapped in
#if defined(...)/#endif inside the verbatim wlroots 0.20 format table, so
it compiles on older libdrm (CI uses 2.4.123) without locally redefining
fourcc macros. isYCbCr is left untouched (all macros it references are
defined); CMakeLists.txt is unchanged.

Log: Switched DRM_FORMAT_* compatibility from #ifndef fallbacks to per-entry #if defined() guards

Influence:
1. Vulkan render-target dmabuf import still compiles on CI's libdrm 2.4.123
2. On libdrm >= 2.4.129 the full wlroots 0.20 format table is used as-is
3. No runtime behavior change
1. Port wlroots 0.20 vulkan_import_dmabuf(for_render=true) to waylib
2. Replace wlr_texture-based VkImage in acquireRenderTarget with
   direct dmabuf import so the buffer is a valid render target
3. New VkImage gets VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT for valid
   render target usage instead of reusing a wlr_texture
4. Add VkDmabufImage lifecycle management in BufferData destructor
5. Fix BufferData memory leak in onBufferDestroy
6. Keep the verbatim wlroots 0.20 formats[] table; guard the 8
   DRM_FORMAT_* entries added in libdrm >= 2.4.129 with
   #if defined() so it compiles on CI's older libdrm (2.4.123)
7. Use Q_BYTE_ORDER == Q_LITTLE_ENDIAN instead of a custom endian macro
8. Make isYCbCr, kVkFormats and vkFormatFromDrm constexpr
9. Use QT_WARNING_PUSH/POP instead of pragma GCC diagnostic
10. Return an empty target when get_dmabuf fails (else branch)

Log: Fixed Vulkan render target to use a proper color-attachment VkImage

Influence:
1. Test Vulkan rendering with various dmabuf formats
2. Verify render target creation without validation errors
3. Test buffer creation and destruction for memory leaks
4. Verify GL and pixman rendering paths are unaffected
5. Confirm the build passes on libdrm 2.4.123 and >= 2.4.129

fix: 使用 dmabuf 导入创建 vulkan 渲染目标

1. 将 wlroots 0.20 的 vulkan_import_dmabuf(for_render=true) 移植到 waylib
2. 在 acquireRenderTarget 中用直接 dmabuf 导入替代 wlr_texture 创建
   VkImage,使缓冲可作为有效渲染目标
3. 新建 VkImage 带 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,替代复用
   wlr_texture 的做法,获得合法的渲染目标用途
4. 在 BufferData 析构中添加 VkDmabufImage 生命周期管理
5. 修复 onBufferDestroy 中 BufferData 的内存泄漏
6. 保留 wlroots 0.20 原始 formats[] 表;对 libdrm >= 2.4.129 新增的
   8 个 DRM_FORMAT_* 条目用 #if defined() 守卫,使其在 CI 较旧的
   libdrm (2.4.123) 上也能编译
7. 用 Q_BYTE_ORDER == Q_LITTLE_ENDIAN 替代自定义大小端宏
8. 将 isYCbCr、kVkFormats、vkFormatFromDrm 改为 constexpr
9. 用 QT_WARNING_PUSH/POP 替代 pragma GCC diagnostic
10. get_dmabuf 失败时返回空目标(else 分支)

Log: 修复 Vulkan 渲染目标,使用合法的颜色附件 VkImage

Influence:
1. 测试 Vulkan 渲染路径下各种 dmabuf 格式
2. 验证渲染目标创建成功,无 validation 错误
3. 测试 buffer 创建和销毁,确认无内存泄漏
4. 验证 GL 和 pixman 渲染路径不受影响
5. 确认在 libdrm 2.4.123 与 >= 2.4.129 上均能编译通过
@Groveer Groveer force-pushed the fix/vulkan-dmabuf-render-target branch from 24abc32 to bae7a8a Compare July 9, 2026 14:09
@Groveer Groveer requested a review from zccrs July 9, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants