Repository navigation
d3d12: forward ClearDepthStencilView on console command lists - #2451
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of head b312f9da (comment only, no Windows run on my side).
Issue 1 (scope): this branch carries other work.
git log origin/main..HEAD shows 4 commits, and only the last one is the ClearDepthStencilView change:
d97f04abd3d12: support unplaced buffer memory SRVs in device slot 700bc0b2b8Merge branch 'gpu/slot70-unplaced-buffer-backing'87a23b30d3d12: reject unplaced buffer memory SRVs overlapping live resourcesb312f9dad3d12: forward ClearDepthStencilView on console command lists
The first three are the content of open PR #2395. In the diff that is about 180 lines in src/startup_stubs/d3d12_memory_srv.inl, the helpers in memory_srv_buffer.h, the clear_unplaced_buffers hook in release(), two mutation controls in CMakeLists.txt, and a docs section. None of it is in the title or body. Same shape as #2473 from the same author.
Fix: rebase after #2395 merges, or drop those three commits so the diff is only slot 51 (d3d12_xs_device.cpp, tests/startup_clear_depth_stencil.cpp, its CMake entry).
Issue 2 (possible duplicate): list slot 51 was already proposed in #1806 ("startup: clear depth and stencil views (command-list slot 51)", closed, not merged). Main has no slot 51 handler today, so this is not a conflict with merged code. A maintainer should decide whether #1806 and this PR cover the same slice before either goes on.
Issue 3 (Windows results): the body has no head SHA and no build commit. The dev and release numbers in the body cannot be tied to b312f9da. Please state the commit those runs used.
What looks fine
list_clear_depth_stencilfollows the siblinglist_clear_target(slot 52): shadow-record view lookup viaresolve_view(desktop, 21), transition to DEPTH_WRITE,render_clearsandrender_target_unresolvedcounters.- Refusals are covered by the test: zero flags, read-only depth view, RTV passed as DSV, empty handle.
- Stencil flag is masked off for formats without a stencil plane, and the call returns if nothing is left.
tables[list_kind][51]is also set directly, which the sibling slots 52 to 55 do not do. Harmless, but worth a one-line reason in the code if it is needed.docs/startup-runtime.mdchanges in this diff belong to the slot 70 commits only.
Commands run locally (Linux)
python3 tests/docs_links_check.py-> passed (19 files, 464 links)python3 tests/bidi_controls_check.py-> passedgit diff --check origin/main...HEAD-> clean- The D3D12 tests need Windows headers, so I did not build them or run mutations on Linux.
AI-assisted; commands listed were executed locally.
Built and run here: 2/2 pass on WARP and a physical GPU; five mutations, two caught, three survivors — and one of my earlier runs was void, so here is the corrected setFirst, a correction about my own method, because it produced three bogus results before I noticed: I tried Five mutations of
|
| mutation | result |
|---|---|
zero clear flags accepted (!(flags & (DEPTH | STENCIL)) → false) |
caught |
depth clear on a READ_ONLY_DEPTH view accepted |
caught |
stencil clear on a READ_ONLY_STENCIL view accepted |
not caught |
the STENCIL bit is no longer dropped when the format has no stencil |
not caught |
the early return after that drop is removed (if (!flags) return; → if (false) return;) |
not caught |
The two catches are the important pair: both are cases where passing the call through would make the driver raise a
debug-layer error rather than return something wrong, and the fixture pins them.
The third one is the asymmetric survivor, and it is worth a look: depth-on-read-only is caught, stencil-on-read-only is
not. The two guards are written identically twenty lines apart
if ((flags & D3D12_CLEAR_FLAG_DEPTH) && (view.dsv_flags & D3D12_DSV_FLAG_READ_ONLY_DEPTH)) { … return; }
if ((flags & D3D12_CLEAR_FLAG_STENCIL) && (view.dsv_flags & D3D12_DSV_FLAG_READ_ONLY_STENCIL)) { … return; }so a fixture that creates one read-only-depth view and one read-only-stencil view would cover both — or, if the intent
is that a read-only stencil view cannot exist without a read-only depth view, say so in a comment and the asymmetry is
explained rather than accidental.
The fourth and fifth are the "format has no stencil" normalisation: clearing stencil on an R32_FLOAT DSV drops the bit
and then returns if nothing is left. Neither the drop nor the subsequent return is asserted, so the fixture never clears
stencil on a stencil-less format. One case each would pin them, and the pair matters together — dropping the bit without
the early return would issue a depth-only clear when the caller asked for both.
What I did not do
I did not read tests/startup_clear_depth_stencil.cpp (331 lines) closely enough to say which rect-count and
dsv_flags combinations it builds; the survivors above are states the file demonstrably does not reach, not states I
read it to exclude. If a stencil-less-format case is already there and my mutation is inert for another reason, tell me
and I will re-check rather than leave the claim standing.
Environment
Windows 11 build 26300.9974; WARP and the installed physical GPU; startup_clear_depth_stencil built with
cmake --build --preset dev --target …. Each mutation was built (build verified separately from the test result),
run, reverted and rebuilt; final state 2/2 green.
AI-assisted.
248f915 to
e8eb303
Compare
Implement list slot 51 (ClearDepthStencilView) in d3d12_xs.dll. Resolves the descriptor through the DSV shadow records with creation map fallback, validates readable rect bounds and non-zero flags, checks against read-only DSV plane flags, and transitions the depth target to D3D12_RESOURCE_STATE_DEPTH_WRITE before forwarding to the desktop graphics command list. Adds synthetic fixture tests/startup_clear_depth_stencil.cpp checking WARP and hardware backends, verifying valid depth clears with and without rects, read-only DSV refusal, non-DSV (RTV) handle rejection, and empty descriptor handling. # Conflicts: # CMakeLists.txt
Add a one-line reason for setting tables[list_kind][51] directly while siblings 52-55 only write list_typed: the ClearDepthStencilView fixture calls list vtable[51] directly via invoke(), so the slot must be reachable through both the typed dispatch and the generic table path. Co-Authored-By: Claude Code <noreply@anthropic.com>
e8eb303 to
282bdaa
Compare
|
Rebased onto current main ( The branch now carries only the two topic commits ( Commit Windows Verification
Dev ( cmake --build --preset dev --target startup_clear_depth_stencil
ctest --preset dev --no-tests=error -R '^startup_clear_depth_stencil' -VRelease ( cmake --build --preset release --target startup_clear_depth_stencil
ctest --preset release --no-tests=error -R '^startup_clear_depth_stencil' -V |
|
Hardware run at head Environment: NVIDIA GeForce RTX 3070 Ti, driver 32.0.16.2101 (NVIDIA 621.01) and Windows 11 Pro build 26300.9974 as reported by the system, Command: Result: 2/2 passed, 0 failed (
The WARP run (test 301, For information: in both tests the debug layer prints 2 messages with This run covers NVIDIA and WARP only. Not covered: any test outside the filter above. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 282bdaa against current main (comment review, no approval).
What I checked
list_clear_depth_stencil(slot 51) insrc/startup_stubs/d3d12_xs_device.cpp: it follows the siblinglist_clear_target(slot 52). The view is resolved from the shadow record, with the creation map fallback now enabled for slot 21 inresolve_view. Zero flags, read-only depth, read-only stencil and unreadable rect arrays are all refused before the call. The target is moved to DEPTH_WRITE before the clear.- Table wiring:
list_typed[51]andtables[list_kind][51]are both set, and the comment explains why. Thedepthfloat is a typed parameter, so x64 delivery stays correct. - CMake: the new test uses the same warp/hardware loop and properties as its neighbours.
- Existing evidence on this head: the Windows CI job passes, and the contributor runs on WARP and on physical GPUs (see the thread) pass 2/2.
Non-blocking coverage gaps (also raised in the thread by ChazY11)
tests/startup_clear_depth_stencil.cppbuilds only a read-only-depth view (line 254). The read-only-stencil guard is never exercised, so removing it is not caught.- No case clears stencil on a stencil-less format, so the stencil bit drop and the
if (!flags) return;that follows it are not pinned. A follow-up with one case each would close this.
Linux commands run in a worktree of the head:
python3 tests/docs_links_check.pypasses.python3 tests/bidi_controls_check.pypasses.git diff --check origin/main...HEADis clean.
Not run: Linux cannot build or run the D3D12 fixture, so I did not mutate the code myself. I rely on the Windows CI run and the contributor receipts in the thread.
AI-assisted; commands listed were executed locally.
Description
Implements
CommandListslot 51 (ClearDepthStencilView) on console command lists ind3d12_xs.dll.Details
tables[list_kind][51]andlist_typed[51], preserving x64 float parameter delivery (XMM3forDepth).view_target(handle, 21)).D3D12_DSV_FLAG_READ_ONLY_DEPTH, and stencil clears onD3D12_DSV_FLAG_READ_ONLY_STENCIL.D3D12_CLEAR_FLAG_STENCILif target format lacks a stencil plane.rect_countand bounds readability.D3D12_RESOURCE_STATE_DEPTH_WRITEon the desktop command list.render_clearsandrender_target_unresolveddiagnostic counters.Test Coverage
Added synthetic test
tests/startup_clear_depth_stencil.cpp:ClearDepthStencilViewon 1x1 depth surface with depth 0.25f.ClearDepthStencilViewon 2x2 depth surface with depth 0.75f and explicit rect.GetDeviceRemovedReason() == S_OKand 0 debug layer errors on both WARP and physical hardware.Evidence
Observed:
Release build:
Observed:
Environment:
Build commit
Head commit:
248f9151(d3d12: document why slot 51 is set in both table paths), based onb312f9da(d3d12: forward ClearDepthStencilView on console command lists). All test runs above were executed againstb312f9da; the comment-only commit does not change behavior.Reviewer notes
origin/main..248f9151contains only the ClearDepthStencilView change (d3d12_xs_device.cpp,tests/startup_clear_depth_stencil.cpp, its CMake entry). The slot 70 unplaced-buffer commits are onmainnow and are not part of this PR.tables[list_kind][51]is set directly unlike siblings 52-55; explained with a one-line comment inbuild_tables()(the fixture calls list vtable[51] directly viainvoke(), so the slot must be reachable through both paths).