Skip to content

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

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-replay-statistics-mesh-segments
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-replay-statistics-mesh-segments

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-REPLAY-STATISTICS-MESH-SEGMENTS (#1608 (comment))

What and why

Item 2 of @kevincommits' finding in #1608 (#1608 (comment)). 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 431ceba. 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

…ment; a batch reads only its own lists

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

- plan_overlapping_statistics_segments: a clamped indirect draw opens a
  segment of its own (the clamp is a helper dispatch), but the planner then
  set the segment's kind to vertex and skipped the draw-kind rule. A clamped
  indirect mesh draw under overlapping statistics queries therefore ran in
  the full 11-counter pool (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076)
  and had no mesh-primitives query. The clamped call now falls through to
  the same rule as every draw; a dispatch leaves the kind unset. The
  one-query-at-a-time planner already marked it mesh.
- VulkanQueue::execute keeps the PreparedLists of its largest batch, but
  gathered the segment kinds from all of them, so a smaller batch could pick
  up a stale mesh segment and create the mesh pools (or fail as unsupported
  where the device has none). It now gathers from this batch's lists only,
  through batch_statistics_mesh in vulkan_replay.h.

replay_query_predication_test gains case 16b: the clamped mesh draw's segment
is mesh, a mesh draw after it stays in it, a vertex draw splits; the
non-overlapping planner agrees; and batch_statistics_mesh over the first n
lists leaves the stale tail out. 2 checks fail with the old planner.

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

Copy link
Copy Markdown
Contributor

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

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2530 | head 202786b (merged cleanly with main 09c1539) | 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 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).

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

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