Repository navigation
D3D-393: cover input assembly state after a mesh draw - #9221
LukeOsland1 wants to merge 4 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
|
Verified head
AI-assisted. |
|
Tested
So the new test depends on the change. The PR's 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. |
|
Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at 6ac562f. Full No regression. The only failures are the same 5 as on AI-assisted (Claude Code). |
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.