Repository navigation
startup: invalidate cached constants when the graphics root changes - #1808
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of 49eea1e7 (head of this PR, base ecc6e6ce, which already contains #1744). Comment only, no approval.
Verdict: no blocking findings on the code. Two process points below, and one verification gap on my side.
Interaction with #1744. Not redundant. #1744 clears pass.root_address when the root signature changes. This PR keeps that, folds the descriptor-table reset into the same if (pass.root != params) block (the old code computed the same comparison twice), and adds the root constants, which #1744 left alone. The block now reads clearly: tables, addresses and constants are invalidated together, and setting the same signature again keeps all three. That matches the public D3D12 rule that root arguments are invalidated by a different root signature. I checked the other writers of pass.constants: the only writer is slot 40 (list_root_constants, bounds-checked to 16 parameters of 8 words), and the only reader is the translated draw (d3d12_draw.inl, guarded by ud.a < 16 && ud.b < 8). memset(pass.constants, 0, sizeof(pass.constants)) covers exactly the 16x8 array.
Process points
- Overlap with #1726 (
SetGraphicsRoot32BitConstant, slot 38): it clearspass.constantsinside the sameif (pass.root != params)block oflist_graphics_root(std::fill_n(&pass.constants[0][0], 16 * 8, 0u)). The two PRs will conflict textually and do the same thing there. Whichever lands second needs a rebase and should drop its copy of the clearing. Worth coordinating in the threads. - #1803 (compute root state) also edits
list_graphics_root, a few lines below.
The test. startup_root_reset now binds a table and a root constant (parameter 1, value 173, read as the blue channel via udsrc 3 rootconst 1 0). The four cases are specific: bound and same-signature keep blue 173, the switched signature expects 0, out-of-range keeps both and logs four lines. The PR text says the switched case read blue 173 before the fix, which is the negative control I would want. The fixture change in startup_stream_setup.cpp only adds the second root parameter when X2W_TEST_ROOT_RESET is set.
Commands run locally (worktree at the exact head SHA above, Linux)
git diff --check origin/main...HEAD,tests/docs_links_check.py(17 files, 368 links),tests/bidi_controls_check.py: clean.python3 -m py_compile tests/startup_root_reset_check.py: compiles.
Not run, honestly stated: I could not build or run the Windows test (startup_root_reset_{warp,hardware}) or mutate the C++ here. The pipeline's Windows step was blocked by a command guard in my session, and this machine cannot compile d3d12_xs_device.cpp. So I did not run the two source mutations I would have wanted (removing the memset, and clearing constants unconditionally so that same-signature also drops them). Both should be caught by the bound/same_root and switch_root cases as written, but that is my reading, not a run.
AI-assisted; commands listed were executed locally.
Follow-up to #1744.
Changing the graphics root invalidates all cached root arguments. The startup shim already cleared the descriptor tables and root addresses but retained constants consumed by translated shaders. Clear those constants in the same invalidation path. Setting the same root still preserves translated arguments.
Extend the root reset fixture to feed a nonzero root constant into the blue channel. The unfixed implementation reads back blue 173 after switching roots, where the expected value is zero. The original root, redundant rebind and out-of-range writes retain the expected texture and constant.
Tested 49eea1e on Windows 11 build 26300.9711:
Two passed with no skips. WARP used Microsoft Basic Render Driver 10.0.26100.9711. Hardware used NVIDIA GeForce RTX 4070 with driver 32.0.16.2114. This fixture runs with the D3D12 debug layer disabled.