Skip to content

vulkan_replay: a dropped indirect dispatch prepares and emits no clamp pass (RT-REPLAY-DROPPED-DISPATCH-CLAMP) - #2523

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-replay-dropped-dispatch-clamp
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-replay-dropped-dispatch-clamp

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-REPLAY-DROPPED-DISPATCH-CLAMP (#1608 (comment))

What and why

Item 3 of @kevincommits' finding in #1608 (#1608 (comment)). Thanks for the repro.

In prepare() (runtime/src/vulkan_replay.h), an ExecuteIndirect(DISPATCH) had its clamp pass (vulkan_indirect_clamp.h) prepared and linked into the list's shared work budget (share_list_budget) before its compute pipeline was resolved. When the pipeline was dropped (skipped on request, or async_build and still building), the command continued with p.indirect_clamp still set. emit() then recorded the clamp pass and only afterwards skipped the dispatch. So a dispatch that never runs:

  • claimed clamp scratch and a counter slot;
  • had its records counted against the list's work budget, which every later clamped draw and dispatch of the same list shares, so later commands could find less budget left.

Change. The dispatch's pipeline is resolved before the clamp is prepared, so a dropped dispatch leaves prepare() before any clamp exists. The pipeline block moved unchanged (same checks, same skipped/async_build/strict handling), with a comment saying why it comes first. Indirect draws keep their order: they have no pipeline at this point.

A pipeline left to PipelineCompiles is not dropped later (first_use defers only pipelines that are neither skipped nor async_build, and a failed deferred build fails the list in check_compiled_pipelines), so emit() needs no change.

Overlap: none found among open PRs touching vulkan_replay.h (#2491, #2486, #2485, #2469 and others change other functions). Items 1 and 2 of the same finding come as separate PRs.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main 431ceba. CPU only.

  • New replay_dropped_indirect_clamp_test (fake pipelines, buffers and clamp pass; counts clamps prepared and emitted, dispatches emitted, and which budget word each emitted clamp reads):
    • kevincommits' repro, a dropped dispatch alone: 0 clamps prepared, 0 emitted, 0 dispatches (main: 1 prepared, 1 emitted, 0 dispatches), for skipped and for async_build;
    • a dropped dispatch before a built one, and between two built ones: one clamp per dispatch that runs;
    • every emitted clamp reads the budget word of the list's first emitted clamp;
    • control: two built dispatches, 2 clamps, 2 dispatches.
  • With main's vulkan_replay.h, 10 checks fail (the extra clamp prepared and emitted in each dropped case); all pass with the change.
  • ctest -R "^(replay_dropped_indirect_clamp|replay_pipeline_compiles|replay_pipeline_compiles_strict|indirect_topology_and_stats)$": 4/4 pass.
  • scripts/check_no_game_data.py: clean.

Not tested: a game boot. Whether this changes what a boot draws depends on how often a list has a dropped indirect dispatch ahead of clamped work.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (CPU tests only)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

…p pass

From kevincommits' finding (item 3) in ProjectLeonida#1608.

prepare() set up the clamp pass (vulkan_indirect_clamp.h) of an
ExecuteIndirect(DISPATCH) before it resolved the dispatch's compute pipeline.
When that pipeline was dropped (skipped on request, or async_build and still
building), the command was left out after its clamp was prepared and linked
into the list's shared work budget, and emit() then recorded the clamp pass
before skipping the dispatch. The pass claimed scratch and counter slots and
counted the dropped call's records against the list budget that every later
clamped draw and dispatch of the list shares.

The pipeline is now resolved first, so a dropped dispatch leaves prepare()
before any clamp exists. A pipeline left to PipelineCompiles is not dropped
later: a failed deferred build fails the list.

New CPU test replay_dropped_indirect_clamp follows the repro: a dropped
dispatch alone, before and between built ones, for skipped and async_build
pipelines. 10 checks fail on main; all pass with the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timbot103

Copy link
Copy Markdown
Contributor

Reviewed at head 4d3badfa4 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built replay_dropped_indirect_clamp_test and gta6rt.
  • replay_dropped_indirect_clamp_test: ok.

Notes

  • Resolving the DISPATCH compute pipeline before prepare_indirect_clamp() cleanly keeps skipped and still-building async indirect dispatches from allocating clamp scratch or claiming indirect_list_budget, while preserving command indices for all remaining commands. The 6 ordering checks cover both skipped and async_build cases well.
  • Minor comment accuracy (vulkan_replay.h:4114-4116): The inline comment says "so the budget word every later clamp of the list reads would be set up by a pass that never runs." In emit() (vulkan_replay.h:5318-5360), emit_indirect_clamp() actually ran before the dispatch skip at line 5360, so the pass did run (wasting scratch and charging the dropped dispatch against the shared list budget, exactly as the commit message describes). Tweaking that comment line keeps it aligned with the commit message.

Approve.

AI-assisted review + local MSVC verification.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2523 | head 4d3badf (merged cleanly with main 09c1539) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(replay_dropped_indirect_clamp|indirect_clamp|indirect_clamp_safety|d3d12_indirect_dispatch_count|d3d12_indirect_group_budget)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: replay_dropped_indirect_clamp_test fails (10 failure(s): skipped and async-building ExecuteIndirect(DISPATCH) commands prepared and emitted orphan clamp passes and took ownership of the list's shared list_budget) | green on PR+main: 5/5 CTests pass (replay_dropped_indirect_clamp in 0.06s, indirect_clamp in 0.46s, indirect_clamp_safety in 0.06s, d3d12_indirect_dispatch_count in 0.62s, and d3d12_indirect_group_budget in 0.52s) on RTX 3090 with LEONIDA_VK_VALIDATION=1 (0 Khronos validation errors); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

Resolving the compute pipeline for ExecuteIndirect(DISPATCH) before preparing the indirect clamp pass ensures skipped/async-building dispatches never allocate clamp scratch or own the list's shared work budget word.

Tests run

  • ctest --output-on-failure -R "^(replay_dropped_indirect_clamp|replay_pipeline_compiles|replay_pipeline_compiles_strict|indirect_topology_and_stats)$": 4/4 passed (replay_pipeline_compiles 0.49 s, replay_pipeline_compiles_strict 0.38 s, replay_dropped_indirect_clamp 0.02 s, indirect_topology_and_stats 0.03 s).

AI-assisted (Antigravity, Gemini).

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.

4 participants