Skip to content

【Vulkan后端增强】Enhance Vulkan Renderer backend - #1171

Open
LFRon wants to merge 14 commits into
linuxdeepin:masterfrom
LFRon:feat-and-refactor/enable-vulkan-renderer
Open

【Vulkan后端增强】Enhance Vulkan Renderer backend#1171
LFRon wants to merge 14 commits into
linuxdeepin:masterfrom
LFRon:feat-and-refactor/enable-vulkan-renderer

Conversation

@LFRon

@LFRon LFRon commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

该PR是 #1032 的更新版, 改动的wlroots由外侧转为treeland内侧的wlroots

Summary by Sourcery

Enhance the compositor’s Vulkan backend with synchronized Qt/wlroots rendering, robust resource lifetimes, Vulkan effects and cursor handling, capture support, and related Wayland protocol integration.

New Features:

  • Add a Vulkan rendering path that shares wlroots and Qt Vulkan resources with explicit image ownership, synchronization, render-target preservation, and texture sampling support.
  • Support Vulkan backdrop rendering for effects, including blur, rotation, content compositing, and direct hardware-cursor rendering.
  • Expose renderer-backed linux-dmabuf and presentation-time Wayland globals for Vulkan sessions.
  • Add Vulkan-specific frame tracing, presentation feedback, failure handling, and cleanup diagnostics.
  • Provide Vulkan capture support by dumping rendered buffers to normalized images before copying them to clients.

Bug Fixes:

  • Fix Vulkan texture format/view handling, queue-family transitions, DMA-BUF synchronization, staging uploads, and render-buffer lifetime management.
  • Prevent stale or mismatched surface textures, cursor resources, swapchains, and deferred QRhi resources from being reused or destroyed prematurely.
  • Improve capture validation and copying for invalid images, crop regions, formats, strides, and buffer-access failures.
  • Preserve existing non-Vulkan rendering behavior while making texture-provider and scene-graph paths resilient to missing textures.

Enhancements:

  • Integrate the vendored wlroots Vulkan extensions directly into Waylib and coordinate Qt Quick frame submission with wlroots queue operations.
  • Add Vulkan-specific render-pass dependencies, shared depth-stencil attachments, asynchronous staging support, and batched texture barriers.
  • Refine Vulkan cursor placement, scaling, fallback behavior, and output scheduling.
  • Add presentation feedback tracking for textured surfaces and output commits.

Build:

  • Detect wlroots Vulkan support and conditionally locate and link Vulkan.
  • Build the vendored wlroots before Waylib and include new protocol and tracing sources.

Documentation:

  • Update Waylib build instructions to use the default CMake configuration.

Chores:

  • Update Vulkan and wlroots integration APIs and compatibility wrappers across the embedded renderer.

@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 @LFRon, your pull request is larger than the review limit of 150000 diff characters

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LFRon

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-ci-robot

Copy link
Copy Markdown

Hi @LFRon. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 3 times, most recently from 3d74e19 to 49ea9e2 Compare July 21, 2026 03:34
@LFRon

LFRon commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@zccrs 对了大佬, 这个实现里我顺便把CPU-GPU的等待模型改成了GPU内异步等待模型降低了画面延迟且减少了开销, 目前测试下来没啥问题, 大佬是否能参考一下(

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 3 times, most recently from c0942c0 to ec9999c Compare July 22, 2026 13:41
@LFRon LFRon changed the title 【Beta】Enable Vulkan Renderer 【重大更改】Add Vulkan Renderer backend Jul 22, 2026
@LFRon

LFRon commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@zccrs 大佬, 我做了Blur效果支持, 目前我这边测试没问题:

treeland侧的提交: c3e99a7

wlroots侧的提交:
ec9999c

希望对大佬有参考(

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch from ec9999c to 32acd40 Compare July 22, 2026 13:43
@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 3 times, most recently from 9e19f70 to ac5f77d Compare July 24, 2026 03:26
@deepin-bot

deepin-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.16
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1203

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 9 times, most recently from a973cd3 to 9990d35 Compare July 30, 2026 07:50
@deepin-bot

deepin-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.17
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1229

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch from 9990d35 to f47d018 Compare July 31, 2026 06:00
@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 4 times, most recently from e5fc4d0 to cb59c5f Compare August 13, 2026 12:57
@LFRon LFRon changed the title 【重大更改】Add Vulkan Renderer backend 【增强的Vulkan后端】Enhance Vulkan Renderer backend Aug 14, 2026
@LFRon LFRon changed the title 【增强的Vulkan后端】Enhance Vulkan Renderer backend 【Vulkan后端增强】Enhance Vulkan Renderer backend Aug 14, 2026
@deepin-bot

deepin-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.8.18
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1286

@deepin-bot

deepin-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.9.0
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1312

@deepin-bot

deepin-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.9.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1348

@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch 6 times, most recently from 781fd43 to cf0e723 Compare September 6, 2026 11:32
LFRon added 14 commits September 7, 2026 21:21
Expose the Vulkan texture and render-buffer primitives Waylib needs to
share wlroots-owned images with the Qt Quick QRhi bridge.

- Add an image_usage out-parameter to vulkan_import_dmabuf() so callers can
  learn the actual usage flags a render image was created with.
- Store it on struct wlr_vk_render_buffer and return it through
  waylib_vk_renderer_get_render_buffer_attribs() via a new usage field on
  struct wlr_vk_image_attribs.
- Add waylib_vk_renderer_get_queue() to expose the VkQueue so Qt and
  wlroots can be verified to share the same queue.

No GLES2 behavior is affected; these are additive waylib bridge helpers.
Enable the device capabilities Qt Quick needs to implement the Vulkan
blur/backdrop effect (RenderBufferBlitter) with split render passes.

- Probe and enable VK_KHR_separate_depth_stencil_layouts on the device and
  expose it via waylib_vk_renderer_has_separate_depth_stencil_layouts() so
  Qt can safely split and resume render passes around a depth-stencil pass.
- Advertise transfer-source usage for render modifiers and record the max
  transfer-source extent, so render buffers can be created with
  VK_IMAGE_USAGE_TRANSFER_SRC_BIT when supported (used to sample the output
  buffer as the blur source).
- Include color-attachment reads in both compatible render-pass external
  dependencies so preserved color attachments (effect split passes) observe
  the load operation as well as attachment writes. This fixes color issues
  in apps such as Youdao Cloud Notes that rely on preserved contents.

No GLES2 behavior is affected; these are additive waylib bridge helpers.
Bridge the Qt/QRhi render path to wlroots' Vulkan textures when both
share the same VkQueue, so client DMA-BUF/shm textures can be sampled by
Qt Quick without per-frame CPU stalls.

- waylib_vk_renderer_prepare_texture_for_sampling() /
  finish_texture_sampling(): record the queue-family-ownership and layout
  transition for one imported texture on Qt's command buffer.
- Texture sync batch (begin/flush/abort_texture_sync_batch): collect the
  foreign-texture DMA-BUF sync_files for a frame, import them into reusable
  binary semaphores, and submit a single wait-only bridge command buffer
  that also records an all-commands memory barrier, so the later Qt
  submission observes the producer's writes.
- Texture barrier batch (begin/flush/abort_texture_barrier_batch): defer the
  per-texture acquire/release barriers and record a single vkCmdPipelineBarrier
  per phase instead of one per texture.
- Same-frame producer dependency barrier: a render buffer written by the
  current frame's command buffer (output/layer/cursor buffers) can be
  re-imported as a sampled texture within that same command buffer
  (layer-buffer compositing, cross-output canvases, cached render
  targets). An ownership-transfer acquire barrier cannot order those
  writes - the source access mask of an acquire operation is ignored and
  produces no availability - so remember such buffers
  (frame_render_buffers) and record one extra plain barrier with equal
  queue families and equal layouts before the sampling. With
  synchronization2 the equal layout values preserve the image contents,
  and the barrier's submission-order scopes extend the producer's
  color-attachment writes to the sampling reads.
- waylib_vk_renderer_set_stage_async_enabled() + vulkan_submit_stage_async():
  submit SHM staging uploads without blocking the CPU; the texture-sync
  bridge orders the upload before the consumer samples it. WLR_VK_FORCE_STAGE_BLOCK
  and WLR_VK_FORCE_SYNC_POLL force the legacy blocking paths.
- wlr_vk_texture_get_image_attribs(): report the layout of DMA-BUF textures
  from the owned state instead of the stale "transitioned" flag, so the
  reported layout matches the acquire/release
  GENERAL <-> SHADER_READ_ONLY_OPTIMAL ping-pong; pixel textures keep the
  permanent post-upload layout.
- Add new renderer state (timeline semaphore, semaphore pool, barrier arrays,
  stage-async flags) with matching create/destroy handling.

No GLES2 behavior is affected.
Make Qt Quick (QRhi) render the compositor canvas, layer buffers, and
cursor buffers directly into renderer-allocated DMA-BUFs, so every frame
is produced in one offscreen QRhi pass and handed to wlroots as a plain
wlr_buffer - no intermediate copies, and GLES2/Pixman paths keep their
existing behavior.

- WRenderHelper: wrap renderer render buffers and wlroots textures into
  QRhiTexture/QQuickRenderTarget objects with exact-format Vulkan image
  views (including the opaque alpha swizzle), record acquire/release
  ownership-transfer barriers around Qt's use of a render buffer, and
  defer retired render-buffer/swapchain destruction until the frame's GPU
  work has completed.
- WOutputRenderWindow/WBufferRenderer: run outputs and layers inside one
  synchronous offscreen frame (beginFrameChecked/endFrameChecked); release
  every render buffer before the frame is submitted and retire replaced
  swapchains afterwards; expose the last buffer per output viewport for
  cache sampling.
- WOutput::configurePrimarySwapchain()/configureCursorSwapchain(): hand
  the replaced swapchain out to the caller instead of destroying it
  immediately, so its buffers can outlive GPU work still referencing them.
- WSGTextureProvider/WSurfaceItem: keep a client buffer and its wlroots
  texture as one ownership tuple, rebuild Qt wrappers when the buffer
  changes, and defer texture cleanup to render jobs so GPU sampling has
  finished before destruction.
- Harden WOutputHelperPrivate::acquireBuffer(): this legacy path has no
  Vulkan callers and destroys a replaced swapchain immediately, which can
  race with GPU work still referencing its buffers; refuse it on the
  Vulkan renderer instead of introducing an untested retire mechanism.
- Add the renderer-backed linux-dmabuf v4 protocol wrapper and the VKTRACE
  logging helper (WAYLIB_VULKAN_TRACE) covering frames, passes, texture
  wrapping, sampling dispositions, cleanups, and output present/commit
  results.
Render the cursor QML item into a cursor-plane scanout buffer and hand it
to the KMS cursor plane, instead of always compositing it through the
canvas. This keeps the cursor cheap on the Vulkan path, where a canvas
repaint per pointer move would cost a full synchronous frame.

- SourceOutput.qml detaches the cursor item geometry from the live pointer
  position (pinned at (0,0)) when an output layer carries the cursor, so
  moving the pointer no longer dirties the main scene. The on-screen
  placement is computed from wlroots cursor/output coordinates during
  layer rendering, and moves go through move_cursor; woutputitem
  schedules an explicit output frame for the placement update, since the
  detached geometry no longer dirties the scene itself.
- OutputHelper::tryToHardwareCursor(): on Vulkan, re-render the cursor QML
  item directly into a cursor-format scanout buffer (sampling the already
  FOREIGN-released layer buffer would yield undefined contents), falling
  back to software compositing when no suitable cursor size exists or the
  plane rejects the buffer.
- Defer set_cursor() until the frame's command buffer has been submitted
  and completed (endFrameChecked waits on a fence): the buffer handed to
  the cursor plane is produced by that command buffer, so committing it
  earlier could let the plane scan out content the GPU has not rendered
  yet. move_cursor stays in-frame for pointer latency; the deferred commit
  is cancelled whenever the frame does not complete or the fallback to the
  software cursor is taken, and a failed deferred set_cursor keeps the
  cursor on the software canvas path until its content is re-rendered.
Advertise the legacy wl_drm global for Vulkan only when the renderer
exposes an implicit-modifier DMA-BUF texture format. This prevents
legacy-buffer clients such as Youdao Note from selecting DRM formats
the Vulkan renderer cannot import, which showed up as wrong colors and
flicker, while leaving the non-Vulkan wl_drm path unchanged.
Clients select buffer formats that the compositor must import, wrap into
Qt, and sample. Two gaps let them end up with formats that render as a
blank white screen:

- Restrict the advertised dmabuf/shm texture format sets to the subset
  the Qt wrapper displays exactly:
  waylib_vk_renderer_restrict_texture_formats() rebuilds
  dev->dmabuf_texture_formats and dev->shm_texture_formats from a DRM
  format whitelist, and Helper::init applies it before wl_shm and
  linux-dmabuf hand the sets to clients. Verified against RADV: 17/40
  dmabuf and 17/31 shm formats kept - the dropped ones are the 16-bit
  packed, 3-channel, and YCbCr families QRhi cannot map.
- Wrap packed 10-bit A2R10G10B10 buffers (XWayland depth-30 windows,
  e.g. Command & Conquer: Mental Omega under Wine) exactly instead of
  rejecting them: Qt maps both 10-bit channel orders to RGB10A2 and its
  Vulkan backend derives an A2B10G10R10 initial view, which cannot be
  created on a non-MUTABLE A2R10 image. Construct the QVkTexture
  manually (mirroring the attachment-only depth path) with the exact
  wlroots format and the alpha swizzle instead of createFrom().

XWayland selects buffer formats from the X visual depth and does not
consult the advertised sets, so the exact wrapping is required even with
the restriction in place; both mechanisms share the same goal - no
client-visible format may fall outside what the compositor can display.

Verified with Mental Omega: 817 XR30/AR30 wraps with zero discards, the
format sets restricted, and no other rendering behavior changed. GLES2
is not touched.
@LFRon
LFRon force-pushed the feat-and-refactor/enable-vulkan-renderer branch from 444b196 to ddee3fb Compare September 7, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants