Skip to content

Runtime: suspend conditional rendering around WriteBufferImmediate - #1337

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
emirhan-karaca:fix/write-immediate-predication
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
emirhan-karaca:fix/write-immediate-predication

Conversation

@emirhan-karaca

Copy link
Copy Markdown
Contributor

Fixes silent suppression of WriteBufferImmediate (vkCmdUpdateBuffer) under an active SetPredication on Intel Windows Vulkan drivers (claimed in #1218 (comment); sibling to #1321 / D3D-148, touching non-overlapping lines).

Measured D3D12 vs Vulkan behavior

Synthetic Windows 11 D3D12 probe (SetPredication set to false via EQUAL_ZERO with predicate word 0; no game files):

Backend WriteBufferImmediate (DEFAULT / MARKER_IN / MARKER_OUT) AtomicCopyBufferUINT
Intel(R) UHD Graphics D3D12 (101.7092) writes all three (unconditional) skipped (predicated)
NVIDIA RTX 5050 Laptop D3D12 (621.24) writes all three (unconditional) skipped (predicated)
Microsoft WARP D3D12 skipped skipped (predicated)
Leonida Vulkan on NVIDIA (621.24) writes all three executes (tracked in unpredicated_copies)
Leonida Vulkan on Intel (101.7092) dropped (leaves 0xcdcdcdcd) skipped by driver

On hardware D3D12 (matching Microsoft's SetPredication documentation, which omits WriteBufferImmediate from the predicated-operations list), WriteBufferImmediate is unconditional. On Intel's Windows Vulkan driver, vkCmdUpdateBuffer inside an active vkCmdBeginConditionalRenderingEXT scope following PredicateReducer::capture's compute dispatch is suppressed, causing all three write modes to be silently dropped. AtomicCopyBufferUINT is predicated on all three native D3D12 drivers and is intentionally left untouched here.

Fix

  • Suspend conditional rendering around vk.update_buffer in the WriteImmediate branch of emit() (runtime/src/vulkan_replay.h) whenever predicate.buffer is non-null, and resume it immediately afterward.
  • Extend vk_command_replay_test Part F (when VK_EXT_conditional_rendering is available) to execute all three WriteBufferImmediate modes under a false predicate, followed by a predicated render-target clear verifying conditional rendering resumes properly.
  • Add CPU-only regression test replay_write_immediate_predication_test (registered in runtime/CMakeLists.txt) verifying suspend/resume ordering and balance for predicated and unpredicated writes.

Verification

Built with GCC 16.2 (-std=c++20) + Khronos Vulkan-Headers on Windows 11. Synthetic tests only; no game files.

  • Negative control on main (c0ac5fd):
    • vk_command_replay_test Part F on Intel(R) UHD Graphics (101.7092): FAIL (F buffer a +16: got 0xcdcdcdcd, want 0x66666666; +20 and +24 also 0xcdcdcdcd).
    • replay_write_immediate_predication_test (CPU): FAIL (all three update_buffer calls emitted while conditional rendering active).
  • After fix:
    • CPU tests: replay_write_immediate_predication_test, command_list_test, replay_clear_gate_test, replay_uav_clear_offset_test, predicated_copy_test — all PASS.
    • Intel(R) UHD Graphics (driver 101.7092): vk_command_replay_test, vk_predicate_capture_test, vk_predicated_copy_test — all PASS.
    • NVIDIA GeForce RTX 5050 Laptop GPU (driver 621.24): same 3 GPU tests — all PASS.

AI-assisted.

@evilclanker9000

Copy link
Copy Markdown
Contributor

I checked a GPU consumer of the immediate writes at 8e50a770f8bc8e3a225fd1332bc70912328c2f55 and compared it with native D3D12. With an initial false predicate, I wrote a zero low dword (DEFAULT) and either 0 or 1 to the high dword (MARKER_OUT) of a second predicate. A whole-target blue clear under the original predicate had to stay suppressed. After transitioning and binding the second predicate, a 5×3 green rectangle tested its captured 64-bit value. I checked the written dwords as well as all 64 RGBA texels against the expected mask.

Backend High dword written as 1, read back Green / red pixels High dword control 0, green / red
Native RTX 5080 and native integrated Radeon 1 15 / 49 0 / 64
This PR, Vulkan RTX 5080 and Radeon 1 15 / 49 0 / 64
Microsoft WARP 0 0 / 64 0 / 64

The low dword stayed zero throughout. The Vulkan test used a resource-relative write into a slice of the backing buffer and read the predicate at physical offset 160. No blue pixels or validation errors. WARP reported direct-list immediate-write support but suppressed the writes under this false predicate, consistent with the PR's WARP observation. Windows 11 26200, NVIDIA 616.92, AMD 26.10.1.

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 8e50a77 on an NVIDIA GeForce RTX 3070, driver 610.88, Windows 11 (26300), MSVC 19.44 (VS generator, RelWithDebInfo, /W4), Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1: pass

  • Build has 0 warnings under MSVC (your verification was with GCC, so this covers the other compiler). ctest (validation on): 61/61, including the new replay_write_immediate_predication, predicated_copy and d3d12_predicated_copy.
  • vk_command_replay_test A to G: exit 0, 0 validation messages. Part F's new block ran (the device has conditional rendering): the three immediate writes landed, and the clear after them stayed suppressed under the restored predicate.
  • d3d12_vulkan_device_test, d3d12_com_test: exit 0, 0 validation messages.

NVIDIA never dropped these writes, so this run shows the change is safe there, not the Intel fix itself. Your negative control on UHD Graphics covers that.

Code read: the suspend and resume follow the same pattern emit() already uses around the depth-24 dispatch (run_depth24) and the occlusion resolves in emit_query, and vkCmdUpdateBuffer is outside any render pass, so ending and beginning conditional rendering there is valid. Doing it on every driver rather than only Intel seems right, since Vulkan doesn't predicate vkCmdUpdateBuffer anyway and D3D12 hardware treats the write as unconditional.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, llvm-mc 23.1.6): pass. ctest: all pass on the RTX 4080 SUPER (65–66). The Intel UHD 770 failures are the known ones (vk_binary_occlusion fixed by #1321, d3d12_vulkan_device fixed by merged #1285, d3d12_descriptor min-LOD, d3d12_copy_xfmt).

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 8e50a77 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass (no regression against main).

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest with validation on: 66/66 pass.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and the Khronos validation layer: d3d12_com_test, d3d12_copy_xfmt_test, d3d12_debug_markers_test, d3d12_depth_resolve_test, d3d12_descriptor_test, d3d12_fence_events_test, d3d12_fence_timing_test, d3d12_fence_waiter_test, d3d12_gcl8_test, d3d12_indirect_rt_test, d3d12_method_variants_test, d3d12_multithread_test, d3d12_node_mask_test, d3d12_predicated_copy_test, d3d12_query_rules_test, d3d12_resource_desc_test, d3d12_sampler2_test, d3d12_state_map_test, d3d12_typeless_rtv_test, d3d12_uav_clear_test, d3d12_vulkan_device_test, vk_command_replay_test pass, with 0 validation messages (no VUIDs). vk_overlapping_occlusion and vk_binary_occlusion pass under ctest.
  • d3d12_clear_test fails, the same as on plain main f85582e on this GPU (NVIDIA rounds the 0.5 clear on 8-bit UNORM/SNORM down, Vulkan 7f, WARP 80, plus one depth-format-55 case). This is not caused by this PR.

The vk_* harness tests that need translated SPIR-V weren't run. No game files used. AI-assisted run (Claude Code).

@ianneobot-cyber

Copy link
Copy Markdown

Tested 8e50a77 on Windows 11 (native, MSVC 17.14, Vulkan SDK 1.4.363), NVIDIA RTX 3070 Ti Laptop (621.14): pass

Code read: the suspend/resume is balanced, only when predicate.buffer is set, and vkCmdUpdateBuffer is outside a render pass so ending/restarting conditional rendering there is valid. The CPU test drives the real emit() from vulkan_replay.h with a mocked function table. Looks good to me.

@Rainmaker33

Copy link
Copy Markdown

Tested 8e50a77 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main f85582e. VS 2022, Vulkan SDK 1.4.363.0. Runtime built with scripts\build_runtime.ps1 (CMake, RelWithDebInfo).

  • replay_write_immediate_predication (ctest, LEONIDA_VK_VALIDATION=1): passed, no VUIDs.
  • vk_command_replay_test with validation: exit 0. Part F covers "immediate writes in three modes, UINT and UINT64 atomic copies, buffer and texture discards".
  • ctest: 67/68 pass. process_cmdline fails the same way on main here (code page 1253, RT-84).

@ItsNotRexed
ItsNotRexed merged commit 67c3e40 into ItsNotRexed:main Nov 22, 2026
@bobcatchris

Copy link
Copy Markdown
Contributor

Tested 8e50a770 on AMD Radeon RX 7900 XTX (RDNA3, gfx1100; AMD 26.10.1, Windows 32.0.32015.7029, Vulkan 1.4.359; Windows 11 26200; MSVC 19.39): pass.

Your verification was GCC 16.2 only, so this adds a second toolchain: the branch builds clean with the repo's own scripts/build_runtime.ps1 (BUILD_EXIT=0, no warnings in the touched files).

What I ran:

  • replay_write_immediate_predication_test.exe → exit 0, WriteBufferImmediate suspends and restores conditional rendering.
  • With LEONIDA_VK_VALIDATION=1: vk_command_replay_test (Part F among A–G), vk_predicate_capture_test, vk_predicated_copy_test → all exit 0, 0 VUIDs (the only "validation error" strings in the output are the test's own "no validation errors" lines).
  • Negative control on this toolchain: reverted only the runtime/src/vulkan_replay.h hunk to c0ac5fd6, rebuilt, and the CPU test exits 1 with all three FAIL: predicated writes: … lines (all three modes run outside conditional rendering, conditional rendering balanced, exact suspend/resume event order); restoring the hunk and rebuilding gives exit 0. So the regression test is not vacuous under MSVC either.

On AMD the Intel-driver suppression you describe does not occur (as your table predicts), so Part F here is a no-regression check on a third vendor rather than a reproduction.

CI on this branch shows "not run"; nothing local is blocking it. Synthetic inputs only, no game files.

AI-assisted.

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.

9 participants