Skip to content

D3D-393: cover input assembly state after a mesh draw - #9221

Closed
LukeOsland1 wants to merge 4 commits into
ProjectLeonida:mainfrom
LukeOsland1:codex/mesh-classic-state
Closed

LukeOsland1 wants to merge 4 commits into
ProjectLeonida:mainfrom
LukeOsland1:codex/mesh-classic-state

Conversation

@LukeOsland1

Copy link
Copy Markdown
Contributor

Depends on: #5259

D3D-393. Coordination claim.

The main merge in #5259 brought mesh draws into the draw-state cache. This follow-up adds a replay test for the transition back to input assembly. It records an indexed draw, a mesh draw, and two copies of the original indexed draw. The mesh callback checks that topology and restart have each been set once at that point. The final counts require the first classic draw after the mesh to restore those states and the next identical draw to reuse them.

Only commit 6ac562f is new relative to #5259 at 870b724. Tested the complete replay_draw_state_test on Windows 11 with MSVC C++20 /W4 and Vulkan SDK 1.4.341.1 headers: pass. As a negative control I retained the cached dynamic state after the mesh draw; only the new scenario failed, observing one topology and one restart command where two were required. The dependency already implements the restoration. Synthetic CPU replay callbacks, no GPU execution or game files. Staged diff and game-data check clean. AI-assisted with Codex.

requiemsnkrp and others added 4 commits November 23, 2026 10:54
…w (D3D-393)

emit kept no memory of what it had bound, so every draw bound its pipeline, set 0
and 144 bytes of push constants, set viewport, scissor, topology, primitive restart,
both stencil references and blend constants, and bound its vertex and index buffers:
16-17 Vulkan calls per draw. detail::BoundDrawState remembers what the command buffer
holds and a draw records only what differs. It carries across the per-draw rendering
scopes (Vulkan keeps bound state for the command buffer's life; begin/end rendering,
barriers, transfers and vkCmdClearAttachments leave it alone). It forgets:
- the vertex strides when a pipeline without vertex input is bound (its static stride
  state invalidates them; VUID-vkCmdDraw-pStrides-04913 without the re-bind);
- set 0 and push constants when the push-constant stages differ (layout compatibility);
- everything at a command that binds or runs a helper (dispatch, indirect dispatch,
  predicate capture, predicated or depth24 copy, query resolve, acceleration
  structures, any command kind added later: keeps_draw_state lists the ones that
  keep it), and at the start of every emit.

replay_cpu_bench (no-op entry points, median of 7 runs): 16 -> 7 calls per draw,
17 -> 8 per indexed draw, frame 8.30 -> 4.65 calls per command; emit 136.0 -> 138.2
ns per draw (the skipped calls are no-ops there). On an RTX 3060's driver the eight
dynamic-state and push calls a repeated draw no longer records cost ~101 ns per draw
to record (scratch recorder, not committed).

replay_draw_state_test counts the calls for each rule with mocks. d3d12_draw_state_test
renders 6 scenarios (state changing and kept from draw to draw; clears, a copy, a
barrier, a dispatch, a binary-occlusion resolve, a bundle and a pipeline without
vertex input between draws) on the layer, the default adapter and WARP: same grids,
and every pixel byte-identical to main's output; validation and synchronization
validation clean. ctest 173/173 (171 before plus the two new tests); d3d12_|vk_|replay_
with LEONIDA_VK_VALIDATION=1: 89/89.

AI-assisted.
Conflicts in runtime/CMakeLists.txt (main's d3d12_stores_atomics_test next to this branch's d3d12_draw_state_test:
both kept) and runtime/src/vulkan_replay.h (the draw's push constants: this branch's skip of unchanged pushes kept).
Main now binds the device's current generation of set 0 (ReplayFunctions::bindless_set, D3D-314) rather than the
pipeline's: the draw's set 0 bind compares and records that set, so a flush that replaced it is bound again.

AI-assisted.
One file conflicted, runtime/src/vulkan_replay.h: main's mesh draws (DispatchMesh: no topology or primitive restart dynamic state, draw_mesh_tasks) with this branch's skips of unchanged dynamic state and index buffer. A mesh draw sets the topology and restart nowhere, so the draw after it sets every dynamic state again (BoundDrawState::dynamic false).

AI-assisted.

@Grimkaaah Grimkaaah 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.

Independent Linux CPU review

What changed: draw-state skip/restore after mesh draws (D3D-393); docs + replay_draw_state_test / d3d12_draw_state_test.

Checked: diff. Bound-state rules look consistent with the Vulkan lifetime model described.

No game files. D3D12/GPU tests not run on this Linux host.

@smowlyy

smowlyy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified head 6ac562f90 merged onto main (6312c057f) on native Windows 11 (10.0.26300.9974, MSVC 19.44, RelWithDebInfo, Vulkan SDK 1.4.363.0):

  • python -I scripts/check_no_game_data.py on all 5 changed files: clean (exit 0)
  • cmake --build runtime/build --target d3d12_draw_state_test replay_draw_state_test --parallel: built cleanly
  • ctest --test-dir runtime/build -R replay_draw_state --output-on-failure -V: 1/1 passed (replay draw state: ok)
  • LEONIDA_VK_VALIDATION=1 .\runtime\build\d3d12_draw_state_test.exe on NVIDIA GeForce RTX 5060 Ti (driver 610.88, Vulkan 1.4.341): passed with 0 validation errors (draw state: 6 scenarios on the layer, 12 host comparisons, 0 failures)

AI-assisted.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6ac562f9 on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 6312c057: pass

  • Built only the replay_draw_state test target from the merged tree and ran it through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1, with four failing checks (graphics pipeline binds 3, expected 1, set binds, pushes, viewports).

So the new test depends on the change.

The PR's runtime/test/d3d12_draw_state_test.cpp is a Windows target and was not built; the portable half is what this verifies.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) with the agent's recheck.sh before posting.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at 6ac562f. Full ctest -j 8, out of 240 tests:

No regression. The only failures are the same 5 as on main dde82f2 on this card (vk_queue_query_sync, d3d12_vulkan_device tiles == 1, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; tracked in #8426). Every test this PR adds or touches passes.

AI-assisted (Claude Code).

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.

7 participants