Skip to content

runtime: flush COMPUTE_SHADER_BIT to HOST on XDXR postbuild readbacks (VK-XDXR-POSTBUILD-READBACK-STAGE) - #615

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
tahffo68hk-hash:fix/vk-xdxr-postbuild-readback-stage
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
tahffo68hk-hash:fix/vk-xdxr-postbuild-readback-stage

Conversation

@tahffo68hk-hash

Copy link
Copy Markdown
Contributor

Summary

In \prepare()\ (
untime/src/vulkan_replay.h), the KHR \AccelerationStructurePostbuild\ path marks \out.wrote_readback = true\ and \out.readback_src_stages |= VK_PIPELINE_STAGE_2_TRANSFER_BIT\ so \VulkanQueue::execute_now()\ emits a host-visibility barrier when \dest_va\ targets a host-readable readback buffer.

However, the XDXR \AccelerationStructurePostbuild\ path — where \XdxrBuilder::record_postbuild()\ dispatches a compute shader writing compacted/current acceleration-structure sizes to \dest_va\ — omitted setting \out.wrote_readback = true\ and \out.readback_src_stages |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT. As a result, a submission ending with XDXR \EmitRaytracingAccelerationStructurePostbuildInfo\ into a \READBACK\ buffer emitted no \COMPUTE_SHADER_BIT -> HOST_BIT\ flush barrier.

Fix

  • In
    untime/src/vulkan_replay.h\ (\prepare()), set \out.wrote_readback = true\ and \out.readback_src_stages |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT\ on the XDXR \AccelerationStructurePostbuild\ path when !info->sources.empty().

Verification

  • Unit test (
    eplay_readback_stages_test):
    • Before fix: \FAIL: XDXR postbuild compacted size reports COMPUTE_SHADER_BIT, \FAIL: XDXR postbuild current size reports COMPUTE_SHADER_BIT\
    • After fix: \PASS\ (
      eplay_readback_stages: depth24, rgb96, copy, UAV-clear and XDXR postbuild readback stages exact)
  • Real Vulkan GPU test (\�k_xdxr_postbuild_readback_test, builds a real 1-triangle XDXR BLAS on the GPU and executes a standalone XDXR postbuild submission into a host-readable buffer):
    • Before fix on NVIDIA GeForce RTX 5060 Ti: \FAIL line 168: barriers >= 1\ (0 \COMPUTE_SHADER_BIT -> HOST_BIT\ barriers emitted)
    • After fix on NVIDIA GeForce RTX 5060 Ti: \PASS (compute_to_host_barriers=1, reported_size=320, expected=320)\
    • After fix on AMD Radeon(TM) Graphics (GFX1036): \PASS (compute_to_host_barriers=1, reported_size=320, expected=320)\

Claimed on #14. (AI-assisted)

中文翻译

摘要

在
untime/src/vulkan_replay.h\ 的 \prepare()\ 中,KHR \AccelerationStructurePostbuild\ 路径会设置 \out.wrote_readback = true\ 和 \out.readback_src_stages |= VK_PIPELINE_STAGE_2_TRANSFER_BIT\,使 \VulkanQueue::execute_now()\ 在 \dest_va\ 指向主机可读回读缓冲区时发出主机可见性屏障。

但 XDXR \AccelerationStructurePostbuild\ 路径(通过计算着色器将压缩/当前加速结构大小写入 \dest_va\)漏掉了 \out.wrote_readback = true\ 和 \out.readback_src_stages |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT\,导致仅含 XDXR postbuild 写入 \READBACK\ 缓冲区的提交缺失 \COMPUTE_SHADER_BIT -> HOST_BIT\ 刷新屏障。

修复

  • 在
    untime/src/vulkan_replay.h\ 的 XDXR \AccelerationStructurePostbuild\ 路径中(!info->sources.empty()\ 时),设置 \out.wrote_readback = true\ 与 \out.readback_src_stages |= VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT\。

验证

  • 单元测试(
    eplay_readback_stages_test\):修复前失败,修复后通过。
  • 真实 Vulkan GPU 测试(\�k_xdxr_postbuild_readback_test\):
    • 修复前(NVIDIA GeForce RTX 5060 Ti):\FAIL line 168: barriers >= 1\
    • 修复后(NVIDIA GeForce RTX 5060 Ti):\PASS (compute_to_host_barriers=1, reported_size=320, expected=320)\
    • 修复后(AMD Radeon(TM) Graphics / GFX1036):\PASS (compute_to_host_barriers=1, reported_size=320, expected=320)\

已在 #14 认领。(AI 辅助)

@kawaii-shakal

Copy link
Copy Markdown
Contributor

Independent run on Windows: passes, with and without validation.

Head dfadf4c built as it is (cmake --build runtime/build --config RelWithDebInfo, MSVC 19.50.35721.0), ctest -R "readback_stages|xdxr":

LEONIDA_VK_VALIDATION Result
unset 8/8 passed
1 (Khronos validation with synchronization validation, Vulkan SDK 1.4.363.0) 8/8 passed; every xdxr_build_check scene reports 0 validation errors and 0/1000 (or 0/300, 0/200) rays differing; d3d12_xdxr_rt 0 errors

I read the diff too: the COMPUTE_SHADER → HOST flush on XDXR postbuild readbacks matches what the KHR path already does for its query results.

One thing for whoever lands second: #626 (mine, RT-XDXR-SERIALIZE) adds XDXR copy mode 19 (SERIALIZE), which also writes the destination from the build compute shader by VA and is typically read back by the title. If both merge, that mode should take the same readback stage path this PR adds. I'll rebase #626 onto this if it merges first.

GPU: NVIDIA GeForce RTX 5070 Ti, driver 617.42, Vulkan 1.4.351, Windows 11 Pro 26300.

AI-assisted.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: VK-XDXR-POSTBUILD-READBACK-STAGE: in vulkan_replay prepare(), an XDXR postbuild that has sources now sets wrote_readback and adds the COMPUTE_SHADER stage to the readback flush, so its results are visible to the CPU read. kawaii-shakal independently ran it 8/8 both plain and under validation.

Why it's good: vk_xdxr_postbuild_readback, replay_readback_stages, xdxr_* and d3d12_xdxr_rt*: 9/9 plain and 9/9 under validation. The new vk_xdxr_postbuild_readback is the extra test in the cumulative count.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 4a50caf, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 540d511: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 316/317 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The full semantic suite has the same single environment-only failure as main. git merge-tree against current main 51a6074: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

@QemmHD
QemmHD merged commit 2a5ff97 into ProjectLeonida:main Nov 24, 2026
7 of 13 checks passed
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.

3 participants