Claimed in #1548: https://github.com/ItsNotRexed/Leonida/issues/1548#issuecomment-7079018062
What and why
VulkanQueue::execute ( untime/src/vulkan_backend.h) uses PreparedList::wrote_readback and PreparedList::readback_src_stages to emit the GPU→HOST memory barrier after a batch writes to a host_readable buffer (D3D12_HEAP_TYPE_READBACK or D3D12_HEAP_TYPE_CUSTOM with D3D12_CPU_PAGE_PROPERTY_WRITE_BACK). Two write paths in prepare() ( untime/src/vulkan_replay.h) did not match their actual Vulkan producer:
- Compute-converted CopyTexture readbacks (depth24_as_float depth plane and gb96): prepare() set out.readback_src_stages |= VK_PIPELINE_STAGE_2_COPY_BIT before prepare_texture_copy and the p.has_depth24 checks ran. During emit(), kCmdCopyImageToBuffer writes to the device-local scratch buffer and ** un_depth24 (a compute shader)** writes directly into p.binding.buffer (host_readable), so VulkanQueue::execute saw copy_only = true and emitted srcStageMask = COPY_BIT, srcAccessMask = TRANSFER_WRITE_BIT instead of COMPUTE_SHADER_BIT / MEMORY_WRITE_BIT. Evaluating p.binding.host_readable after copy preparation succeeds records VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT for compute-converted readbacks (p.has_depth24 && !p.binding.image, matching predicated CopyBuffer) while keeping COPY_BIT for stencil/ordinary texture/buffer copies and avoiding stale wrote_readback flags on failed preparations.
- ClearUnorderedAccess on host_readable buffers (CUSTOM write-back heaps): buffer UAV clears (kCmdFillBuffer / kCmdUpdateBuffer / kCmdCopyBuffer) never set out.wrote_readback or out.readback_src_stages, so VulkanQueue::execute emitted no GPU→HOST barrier at all. Non-empty, non-skipped buffer UAV clears on host_readable buffers now record out.wrote_readback = true and out.readback_src_stages |= VK_PIPELINE_STAGE_2_TRANSFER_BIT.
Added CPU regression test eplay_readback_stages_test (registered in untime/CMakeLists.txt) and extended depth24_convert_test with a kCmdPipelineBarrier2 host-barrier observer verifying depth24_as_float, gb96, and buffer UAV clear readback barriers and data across QueueKind::direct, QueueKind::compute, and QueueKind::copy.
AI-assisted implementation and testing.
Tested
Compiler: w64devkit GCC 16.2.0 (-std=c++20 -O2 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers), Khronos Vulkan-Headers 1.4.363.0, Windows 11 x64.
-
Negative control (unmodified 99f99890 ulkan_replay.h with new tests):
eplay_readback_stages_test: failed 5 assertions (depth24 depth readback, gb96 readback, mixed depth24 + RGBA8 readback, failed copy preparation, host_readable buffer UAV clear).
- depth24_convert_test on both Intel(R) UHD Graphics (101.7092) and NVIDIA GeForce RTX 5050 Laptop GPU (621.24): failed at host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT.
- With fix ($sha):
- CPU tests (9/9 pass): eplay_readback_stages_test, eplay_copy_offset_test, predicated_copy_test, eplay_uav_clear_offset_test, eplay_clear_gate_test, eplay_query_predication_test, eplay_write_immediate_predication_test, command_list_test, eplay_cpu_bench --self-test.
- GPU tests on Intel(R) UHD Graphics (
Tested
eeb87335on AMD Radeon RX 9070 (RDNA4, driver 26.10.1 / Vulkan 1.4.359), Windows 11 Pro 24H2, MSVC 14.44 (VS 2022 Community), Vulkan SDK 1.4.363.0: pass.replay_readback_stages_test.exe: exit 0 (replay_readback_stages: depth24, rgb96, copy and UAV-clear readback stages exact).depth24_convert_test.exe(standard andLEONIDA_VK_VALIDATION=1): exit 0, all 9 assertions pass includinghost-readback visibility barriers (depth24, rgb96, buffer UAV clear) ok.ctest -R "depth24_convert|replay_readback_stages": 2/2 passed (100%).AI-assisted. No game files.