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

Merged
Tyrannys merged 1 commit from upstream-pr/2523 into main 2026-11-29 08:19:54 +00:00
Tyrannys commented 2026-11-28 00:39:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-28T00:39:43Z.


Claimed in the coordination issue as: RT-REPLAY-DROPPED-DISPATCH-CLAMP (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231080379)

What and why

Item 3 of @kevincommits' finding in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285). 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 431ceba4f. 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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5535012110 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-28T00:39:43Z. --- Claimed in the coordination issue as: RT-REPLAY-DROPPED-DISPATCH-CLAMP (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231080379) ### What and why Item 3 of @kevincommits' finding in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285). 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 `continue`d 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` 431ceba4f. 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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](https://claude.com/claude-code)
timbot103 commented 2026-11-28 01:34:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T01:34:00Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7231757536 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#issuecomment-7231757536). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T01:34:00Z. --- 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 commented 2026-11-28 07:36:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:36:20Z.


#2523 | head 4d3badfa4e (merged cleanly with main 09c1539483) | 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236047037 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#issuecomment-7236047037). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T07:36:20Z. --- #2523 | head 4d3badfa4e8cf7d299015595109e150ed3351fa1 (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `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 commented 2026-11-28 09:28:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T09:28:04Z.

Review: APPROVED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6096961395 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#pullrequestreview-6096961395). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T09:28:04Z. **Review:** APPROVED --- 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).
timbot103 commented 2026-11-29 01:07:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T01:07:33Z.

Review: COMMENTED


Reviewed head 4d3badfa4 by static inspection only. I ran no builds, tests, or GPU workloads.

The early drop in runtime/src/vulkan_replay.h keeps both helper slots empty and preserves command indices. The first surviving clamp owns the shared budget. Surviving commands retain count-buffer validation, predicate handling, and their existing barriers and pipeline bindings. The CPU test checks both clamp preparation and emission, dispatch counts, and budget ownership. The CMake target follows the existing Windows and Linux Vulkan-header test setup.

  • At runtime/src/vulkan_replay.h:4121, a deferred compute pipeline can be queued before its own required clamp rejects an oversized scratch allocation. The submission still compiles it, and a compile failure can mask the clamp failure. Could first_use() run early only for skipped or async pipelines, with other pipeline first uses following successful helper preparation?
  • At runtime/CMakeLists.txt:4668, please pin LEONIDA_STRICT_REPLAY=0 and LEONIDA_INDIRECT_CLAMP=1 so inherited settings do not fail the async cases or the built controls.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6100843949 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#pullrequestreview-6100843949). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T01:07:33Z. **Review:** COMMENTED --- Reviewed head `4d3badfa4` by static inspection only. I ran no builds, tests, or GPU workloads. The early drop in `runtime/src/vulkan_replay.h` keeps both helper slots empty and preserves command indices. The first surviving clamp owns the shared budget. Surviving commands retain count-buffer validation, predicate handling, and their existing barriers and pipeline bindings. The CPU test checks both clamp preparation and emission, dispatch counts, and budget ownership. The CMake target follows the existing Windows and Linux Vulkan-header test setup. - At `runtime/src/vulkan_replay.h:4121`, a deferred compute pipeline can be queued before its own required clamp rejects an oversized scratch allocation. The submission still compiles it, and a compile failure can mask the clamp failure. Could `first_use()` run early only for skipped or async pipelines, with other pipeline first uses following successful helper preparation? - At `runtime/CMakeLists.txt:4668`, please pin `LEONIDA_STRICT_REPLAY=0` and `LEONIDA_INDIRECT_CLAMP=1` so inherited settings do not fail the async cases or the built controls. AI-assisted.
TheGeogeo commented 2026-11-29 04:57:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T04:57:59Z.


Tested 4d3badfa4 merged (no commit) with main c8bf0e7b6. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. check_no_game_data.py is clean. Run with LEONIDA_STRICT_REPLAY and LEONIDA_INDIRECT_CLAMP unset.

  • Green: replay_dropped_indirect_clamp passes.
  • Red: with runtime/src/vulkan_replay.h back to main, it fails 10 checks (10 failure(s)), for example a skipped pipeline: 1 clamps prepared, want 0, a pipeline still building (async_build): 1 clamps emitted, want 0 and built, skipped, built: 3 clamps prepared, want 2.
  • No regression: the merge rebuilds 180 executables. Of their 287 other tests, only xbox_present fails, as on plain main here.
  • LINK: gta6rt.exe linked without ws2_32.lib gives main's 26 unresolved Rust-std symbols, nothing new. Its imports are identical to main's.

Points for the merge, not blockers here:

  • It conflicts with #767 in vulkan_replay.h. #767 changes the bindless_set check to (bindless_set || tail_set) inside the pipeline block this PR moves up. Whichever lands second should carry || pipeline->tail_set into the moved block. No conflict with #2530.
  • Review points still open, with no author reply:
    • The comment at vulkan_replay.h:4114-4116 says "a pass that never runs", but the clamp pass did run.
    • Line 4121: a deferred compute pipeline is queued before its own clamp rejects an oversized scratch, so a compile failure can hide the clamp failure. The review asked for first_use() early only for skipped or async pipelines.
    • Pin LEONIDA_STRICT_REPLAY=0 and LEONIDA_INDIRECT_CLAMP=1 on the test (CMakeLists.txt:4668): an inherited strict value fails its async cases.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7250967261 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#issuecomment-7250967261). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T04:57:59Z. --- Tested `4d3badfa4` merged (no commit) with `main` `c8bf0e7b6`. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. `check_no_game_data.py` is clean. Run with `LEONIDA_STRICT_REPLAY` and `LEONIDA_INDIRECT_CLAMP` unset. - Green: `replay_dropped_indirect_clamp` passes. - Red: with `runtime/src/vulkan_replay.h` back to `main`, it fails 10 checks (`10 failure(s)`), for example `a skipped pipeline: 1 clamps prepared, want 0`, `a pipeline still building (async_build): 1 clamps emitted, want 0` and `built, skipped, built: 3 clamps prepared, want 2`. - No regression: the merge rebuilds 180 executables. Of their 287 other tests, only `xbox_present` fails, as on plain `main` here. - LINK: `gta6rt.exe` linked without `ws2_32.lib` gives `main`'s 26 unresolved Rust-std symbols, nothing new. Its imports are identical to `main`'s. Points for the merge, not blockers here: - It conflicts with #767 in `vulkan_replay.h`. #767 changes the `bindless_set` check to `(bindless_set || tail_set)` inside the pipeline block this PR moves up. Whichever lands second should carry `|| pipeline->tail_set` into the moved block. No conflict with #2530. - Review points still open, with no author reply: - The comment at `vulkan_replay.h:4114-4116` says "a pass that never runs", but the clamp pass did run. - Line 4121: a deferred compute pipeline is queued before its own clamp rejects an oversized scratch, so a compile failure can hide the clamp failure. The review asked for `first_use()` early only for skipped or async pipelines. - Pin `LEONIDA_STRICT_REPLAY=0` and `LEONIDA_INDIRECT_CLAMP=1` on the test (`CMakeLists.txt:4668`): an inherited strict value fails its async cases. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 08:19:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T08:19:57Z.


Merged after TheGeogeo's red/green check (check: green with this PR merged onto main, red without it; gta6rt.exe still links) and a re-check here: no conflict with main 26036832c, same head as checked, not frozen, no-game-data green.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253035612 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2523#issuecomment-7253035612). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T08:19:57Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2523#issuecomment-7250967261): green with this PR merged onto `main`, red without it; `gta6rt.exe` still links) and a re-check here: no conflict with `main` 26036832c, same head as checked, not frozen, `no-game-data` green. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2523
No description provided.