vulkan_replay: a clamped mesh draw's statistics segment is a mesh segment; a batch reads only its own lists (RT-REPLAY-STATISTICS-MESH-SEGMENTS) #2530

Merged
leonida/mandy
Tyrannys merged 1 commit from rt-replay-statistics-mesh-segments into main 2026-11-29 08:19:44 +00:00

Pull request successfully merged and closed

Tyrannys commented 2026-11-28 00:48:44 +00:00

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

What and why

Item 2 of @kevincommits' finding in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285). Thanks for the analysis.

Overlapping statistics queries and a clamped indirect mesh draw (plan_overlapping_statistics_segments, runtime/src/vulkan_replay.h). A clamped indirect call opens a segment of its own, because the clamp is a helper dispatch. The planner then hardcoded if (draw_command(commands[i]).state) kind = 0; and continued, so the new segment was always a vertex segment, even for an indirect mesh draw (every IndirectMeshDraw is clamped). That draw then ran vkCmdDrawMeshTasksIndirect[Count]EXT inside the full 11-counter pool (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076) with no mesh-primitives query. A mesh draw after it also split the segment again, since the kinds differed. The one-query-at-a-time planner (plan_statistics_segments) already marked the same draw mesh.

Change: the clamped call falls through to the draw-kind rule every draw uses, as has_helper_dispatch already does. The segment it opened has no kind yet, so a draw sets it (vertex or mesh) and a dispatch leaves it unset.

A smaller batch read the stale tail of a larger one (VulkanQueue::execute, runtime/src/vulkan_backend.h). prepared_ keeps the PreparedLists of the largest batch so their storage is reused, and the comment there says only the first lists.size() entries are read. But the segment kinds for the statistics pool were gathered with for (const auto& list : prepared). After a batch whose later lists had a mesh segment, a smaller batch with statistics queries could find that stale 1. It then created mesh_pool and primitives_pool it did not need, or failed as queue_unsupported on a device without them.

Change: the gather is batch_statistics_mesh in vulkan_replay.h, and execute passes it only std::span(prepared).first(lists.size()).

Overlap: none found among open PRs touching vulkan_replay.h or vulkan_backend.h (#2491, #2489, #2486, #2485, #2469, #2402, #2365 change other functions). Items 1 and 3 of the same finding are #2526 and #2523.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main 431ceba4f. CPU tests, plus the existing d3d12_mesh GPU test.

  • replay_query_predication_test gains case 16b, following the repro:
    • two overlapping statistics queries around a clamped mesh draw, a mesh draw and a vertex draw: the clamped draw's segment is a mesh segment, the mesh draw after it stays in that segment, and the vertex draw splits into a vertex segment;
    • one query around the same clamped mesh draw (plan_statistics_segments): mesh too;
    • batch_statistics_mesh over the first list of two leaves the second list's mesh segment out; over both it keeps list order.
  • With the old planner lines put back, the two clamped-mesh checks fail; all pass with the change.
  • ctest -R "^(replay_query_predication|replay_query_edges|indirect_topology_and_stats|d3d12_mesh)$": 4/4 pass. gta6rt_d3d12_com (which includes vulkan_backend.h) builds.
  • scripts/check_no_game_data.py: clean.

Not tested: the execute path itself on a device with a multi-list batch followed by a smaller one. The helper it now calls is tested, but not the queue around it. Also no game boot.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11

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

Claimed in the coordination issue as: RT-REPLAY-STATISTICS-MESH-SEGMENTS (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231080379) ### What and why Item 2 of @kevincommits' finding in #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230685285). Thanks for the analysis. **Overlapping statistics queries and a clamped indirect mesh draw** (`plan_overlapping_statistics_segments`, `runtime/src/vulkan_replay.h`). A clamped indirect call opens a segment of its own, because the clamp is a helper dispatch. The planner then hardcoded `if (draw_command(commands[i]).state) kind = 0;` and `continue`d, so the new segment was always a vertex segment, even for an indirect mesh draw (every `IndirectMeshDraw` is clamped). That draw then ran `vkCmdDrawMeshTasksIndirect[Count]EXT` inside the full 11-counter pool (`VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076`) with no mesh-primitives query. A mesh draw after it also split the segment again, since the kinds differed. The one-query-at-a-time planner (`plan_statistics_segments`) already marked the same draw mesh. Change: the clamped call falls through to the draw-kind rule every draw uses, as `has_helper_dispatch` already does. The segment it opened has no kind yet, so a draw sets it (vertex or mesh) and a dispatch leaves it unset. **A smaller batch read the stale tail of a larger one** (`VulkanQueue::execute`, `runtime/src/vulkan_backend.h`). `prepared_` keeps the PreparedLists of the largest batch so their storage is reused, and the comment there says only the first `lists.size()` entries are read. But the segment kinds for the statistics pool were gathered with `for (const auto& list : prepared)`. After a batch whose later lists had a mesh segment, a smaller batch with statistics queries could find that stale `1`. It then created `mesh_pool` and `primitives_pool` it did not need, or failed as `queue_unsupported` on a device without them. Change: the gather is `batch_statistics_mesh` in `vulkan_replay.h`, and `execute` passes it only `std::span(prepared).first(lists.size())`. Overlap: none found among open PRs touching `vulkan_replay.h` or `vulkan_backend.h` (#2491, #2489, #2486, #2485, #2469, #2402, #2365 change other functions). Items 1 and 3 of the same finding are #2526 and #2523. ### Tested Windows 11, MSVC (VS 18), RelWithDebInfo, on `main` 431ceba4f. CPU tests, plus the existing `d3d12_mesh` GPU test. - `replay_query_predication_test` gains case 16b, following the repro: - two overlapping statistics queries around a clamped mesh draw, a mesh draw and a vertex draw: the clamped draw's segment is a mesh segment, the mesh draw after it stays in that segment, and the vertex draw splits into a vertex segment; - one query around the same clamped mesh draw (`plan_statistics_segments`): mesh too; - `batch_statistics_mesh` over the first list of two leaves the second list's mesh segment out; over both it keeps list order. - With the old planner lines put back, the two clamped-mesh checks fail; all pass with the change. - `ctest -R "^(replay_query_predication|replay_query_edges|indirect_topology_and_stats|d3d12_mesh)$"`: 4/4 pass. `gta6rt_d3d12_com` (which includes `vulkan_backend.h`) builds. - `scripts/check_no_game_data.py`: clean. Not tested: the `execute` path itself on a device with a multi-list batch followed by a smaller one. The helper it now calls is tested, but not the queue around it. Also no game boot. GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 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:03 +00:00

Reviewed at head 202786b51 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built replay_query_predication_test and gta6rt.
  • replay_query_predication_test: passed (query resolves suspend conditional rendering around fills, copies and dispatches).

Notes

  • Opening a fresh statistics segment resets its kind, so clamped mesh draws properly mark the new segment as mesh, consecutive mesh draws stay in it, and a vertex draw splits cleanly (vulkan_replay.h:3313-3354).
  • Batch counting, pool selection, and list-base assignment in vulkan_backend.h (3456-3466, 3533-3547, 3568-3575) all consistently restrict to the active list prefix.
  • Optional test note: replay_query_predication_test.cpp:783-835 slices the input before calling the helper directly; adding a queue-level test running a 2-list batch followed by a 1-list batch would also guard the production slice at vulkan_backend.h.

Approve.

AI-assisted review + local MSVC verification.

Reviewed at head `202786b51` on Windows 11 (MSVC 2022 `19.44`). ### Verification - Built `replay_query_predication_test` and `gta6rt`. - `replay_query_predication_test`: **passed** (`query resolves suspend conditional rendering around fills, copies and dispatches`). ### Notes - Opening a fresh statistics segment resets its kind, so clamped mesh draws properly mark the new segment as mesh, consecutive mesh draws stay in it, and a vertex draw splits cleanly (`vulkan_replay.h:3313-3354`). - Batch counting, pool selection, and list-base assignment in `vulkan_backend.h` (`3456-3466`, `3533-3547`, `3568-3575`) all consistently restrict to the active list prefix. - Optional test note: `replay_query_predication_test.cpp:783-835` slices the input before calling the helper directly; adding a queue-level test running a 2-list batch followed by a 1-list batch would also guard the production slice at `vulkan_backend.h`. Approve. AI-assisted review + local MSVC verification.
zmasi commented 2026-11-28 07:05:26 +00:00

#2530 | head 202786b51e3ae4d90c5ea14e78998d7cefa7900c (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(replay_query_predication|replay_query_edges|vk_overlapping_occlusion|vk_overlapping_occlusion_no_statistics|vulkan_mesh_limits)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: replay_query_predication_test.cpp fails to compile (C3861: batch_statistics_mesh missing; on main, plan_overlapping_statistics_segments forced kind = 0 on clamped indirect mesh draws and VulkanQueue::execute read prepared past lists.size()) | green on PR+main: 5/5 CTests pass (replay_query_predication in 0.07s, replay_query_edges in 0.10s, vk_overlapping_occlusion in 0.40s, vk_overlapping_occlusion_no_statistics in 0.33s, and vulkan_mesh_limits in 0.03s) 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

#2530 | head 202786b51e3ae4d90c5ea14e78998d7cefa7900c (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(replay_query_predication|replay_query_edges|vk_overlapping_occlusion|vk_overlapping_occlusion_no_statistics|vulkan_mesh_limits)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: `replay_query_predication_test.cpp` fails to compile (`C3861`: `batch_statistics_mesh` missing; on `main`, `plan_overlapping_statistics_segments` forced `kind = 0` on clamped indirect mesh draws and `VulkanQueue::execute` read `prepared` past `lists.size()`) | green on PR+main: `5/5` CTests pass (`replay_query_predication` in `0.07s`, `replay_query_edges` in `0.10s`, `vk_overlapping_occlusion` in `0.40s`, `vk_overlapping_occlusion_no_statistics` in `0.33s`, and `vulkan_mesh_limits` in `0.03s`) 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 approved these changes 2026-11-28 08:51:52 +00:00
lixonik left a comment

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

Clamping the indirect mesh draw segment in vulkan_replay.h and wiring batch_statistics_mesh in vulkan_backend.h look clean, and the new cases in replay_query_predication_test.cpp directly cover the changed paths.

Tests run

  • ctest --output-on-failure -R "^replay_query_predication$": 1/1 passed (replay_query_predication 0.03 s).

AI-assisted (Antigravity, Gemini).

Reviewed the diff and tested merged onto `main` (`493867366`) with Ninja Release (MSVC). Clamping the indirect mesh draw segment in `vulkan_replay.h` and wiring `batch_statistics_mesh` in `vulkan_backend.h` look clean, and the new cases in `replay_query_predication_test.cpp` directly cover the changed paths. ### Tests run - `ctest --output-on-failure -R "^replay_query_predication$"`: **1/1 passed** (`replay_query_predication` 0.03 s). AI-assisted (Antigravity, Gemini).
timbot103 reviewed 2026-11-29 01:07:26 +00:00
timbot103 left a comment
No description provided.
Static audit of `202786b51` against `48bae6cad`. The clamp split now selects the mesh pool, and pool selection uses the active list range. One issue already on the base at `runtime/src/vulkan_replay.h:5359` (head line 5367). With the general clamp disabled, a counted dispatch whose pipeline is skipped can still schedule a statistics split during preparation. Emission jumps past both endpoints, so the next query boundary ends an inactive slot and can begin a second statistics query while the old one is active. Checking the pipeline before preparing the counted helper would avoid the split. A mock replay test can catch this with two overlapping queries around a dropped counted dispatch. AI-assisted.
TheGeogeo commented 2026-11-29 04:33:11 +00:00

Tested 202786b51 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.

  • Green: replay_query_predication passes.
  • Red: with runtime/src/vulkan_replay.h and vulkan_backend.h back to main, the test does not compile: batch_statistics_mesh does not exist on main (replay_query_predication_test.cpp(832), C3861). I did not run a separate runtime mutation (putting the old clamp line back behind the new helper); another tester's red/green covers it.
  • No regression: the merge rebuilds 179 executables. Of their 286 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.
  • Note: the test calls only the planner helper, so the vulkan_backend.h part of the change is not covered by it. A queue-level case (a 2-list batch, then 1 list) was suggested in review.
  • No conflict with #2523, which also touches vulkan_replay.h.

No blocker from my side. AI-assisted (Claude Code).

Tested `202786b51` 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. - Green: `replay_query_predication` passes. - Red: with `runtime/src/vulkan_replay.h` and `vulkan_backend.h` back to `main`, the test does not compile: `batch_statistics_mesh` does not exist on `main` (`replay_query_predication_test.cpp(832)`, `C3861`). I did not run a separate runtime mutation (putting the old clamp line back behind the new helper); another tester's red/green covers it. - No regression: the merge rebuilds 179 executables. Of their 286 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. - Note: the test calls only the planner helper, so the `vulkan_backend.h` part of the change is not covered by it. A queue-level case (a 2-list batch, then 1 list) was suggested in review. - No conflict with #2523, which also touches `vulkan_replay.h`. No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 08:19:47 +00:00

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 eb4773b34, same head as checked, not frozen, no-game-data green.

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

Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/2530#issuecomment-7250720821): green with this PR merged onto `main`, red without it; `gta6rt.exe` still links) and a re-check here: no conflict with `main` eb4773b34, 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 description provided.