Skip to content

startup: apply the decoded slot 57 depth-stencil state behind X2W_DEPTH_STATE - #2169

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
JB2WIN:startup/depth-stencil-apply
Nov 25, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
JB2WIN:startup/depth-stencil-apply

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Refs #1999 (item A, second half)

Change

This applies the slot 57 depth-stencil decoder from #2124 to translated draws behind a new switch X2W_DEPTH_STATE=1. The switch is off by default.

  • Where: translation_for in d3d12_draw.inl. When info->path == 57, the pipeline has no depth-stencil state yet and the switch is on, block A is passed to read_depth_stencil_words/decode_depth_stencil. Slot 57 pipelines carry no desktop DEPTH_STENCIL subobject, so this block is the only thing that can set has_depth_stencil there; the check stays in place as a guard.
  • Fallback: if the decoder refuses, or the block is too short, the original desktop state stays (depth and stencil off), and one log line gives the reason.
  • DSV: pipeline_for uses the decoded state only when a DSV is bound. The binding already exists (slot 50, used by startup_stream_depth), so item D is not needed for this part.
  • Stencil reference: draw_translated sets it with OMSetStencilRef right after SetPipelineState. That overrides any earlier title OMSetStencilRef for the draw. Whether the console expects this order is not measured, and the docs say so.
  • Code: the selection logic is in a new device-free header src/startup_stubs/depth_state_apply.h. The decoder itself is unchanged.
  • Default behaviour: with the switch off, nothing reads the registers, and the desc, the PSO key, the list state and the log are unchanged. This is checked by
    • the device-free test startup_depth_state and its control startup_depth_state_switch_control, which fails under --mutate switch;
    • the fixture's switch-off runs, which check the pixel result and that no depth log line appears;
    • startup_stream_depth_* and startup_slot57_blend_draw_*, which still pass.

Test

New fixture tests/startup_slot57_depth.cpp + tests/startup_slot57_depth_check.py. The same renderer runs on WARP and on hardware (skip 77 where none is available), with synthetic shaders and two overlapping triangles at z = 0.25 and z = 0.75:

Case Switch on Switch off
Reversed-Z: GREATER, clear 0 near triangle wins (red) desktop default (green)
LESS with clear 0 (wrong direction) blue green
LESS, clear 1, reversed draw order green red
Stencil EQUAL, ref 0x5A against stored 0x5A green green
Stencil EQUAL, ref 0x5B against stored 0x5A blue green
Stencil REPLACE 7, then EQUAL 7 green green
Stencil REPLACE 7, then EQUAL 8 red green
Refused by the decoder (colour-write coupling, stencil op ONES) desktop fallback (green) green
No DSV bound green green
All registers zero green green

Mutations: each fails the fixtures.

  • Switch ignored: rz_greater draws green instead of red.
  • ZFUNC mapping swapped: blue instead of red; startup_pipeline_state also fails.
  • Stencil reference not set: st_equal_hit draws blue instead of green.

Run on 7019d041, rebased on 5d02dd37, with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200:

ctest --preset dev --no-tests=error -R '^startup_(depth_state|slot57_|stream_depth|pipeline_state)'   # 10/10 passed
ctest --preset dev --no-tests=error -R '^startup_'   # before the rebase: 362/362 passed, 2 skips (startup_view_heap_warp, startup_logical_view_warp; not touched here)

Not covered: raster state and depth bias (item B), depth bounds, back-face-only stencil state, interaction with a title OMSetStencilRef, clears (#1806), and derived path 55 pipelines that inherit the state. The offsets 0xB8–0xC4 are #2124's and were not measured again.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…TH_STATE

With X2W_DEPTH_STATE=1 (off by default), translated draws of device slot 57
pipelines take the depth-stencil state decoded from state block A
(pipeline_state_decode.h) instead of the desktop default, and set the decoded
stencil reference on the command list after SetPipelineState. A block the
decoder refuses, or one that is too short, keeps the desktop state and logs
the reason. The state is only used when a depth view is bound. With the switch
off nothing reads the words, so the description, pipeline key and list state
are unchanged.

Checks: startup_depth_state (device-free selector, switch-off control),
startup_slot57_depth_{warp,hardware} (two overlapping triangles of unequal
depth, reversed-Z winner, switch off, wrong direction, separate stencil cases
with a known reference, refusal fallbacks). Raster bias, depth bounds,
clears and DSV binding stay out of scope.

Refs R0Y00#1999

AI-assisted (Claude Code).

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

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 7019d04 (comment only, no approval).

Read: depth_state_apply.h, the d3d12_draw.inl hunks, CMake wiring, git diff --stat origin/main...HEAD (8 files, +654/-3).

Commands executed locally (Linux):

  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 402 links OK.
  • python3 tests/bidi_controls_check.py: self-test passed, 1456 files, no bidi controls.
  • git diff --check origin/main...HEAD: clean.
  • g++ -std=c++17 -Isrc tests/startup_depth_state_check.cpp: cannot build here, d3d12.h is missing on Linux. So the C++ tests and the --mutate switch control were NOT run by me. I did not run a mutation of the new logic.
  • gh pr checks 2169: Linux Python job passes. Windows build/test and gfx1013 jobs were still pending when I looked. I did not run a separate Win2025 job.

Findings:

  • P1: none.
  • P2: none.
  • Nit 1 (d3d12_draw.inl ~1191): the decoded stencil reference is applied with OMSetStencilRef on every draw of that pipeline. It overwrites any OMSetStencilRef the title issued before. That matches the doc comment, but it is worth a line in docs/startup-runtime.md that the switch makes register state win over list state.
  • Nit 2 (d3d12_draw.inl ~1191): the guard pass.dsv_format != UNKNOWN || bound->dsv_format != UNKNOWN repeats the dsv_format choice made in pipeline_for (line 492). Both give the same result today. A shared helper would stop them drifting apart.
  • Nit 3: static LONG logged is shared by the applied and refused log paths, so 24 lines of one kind can hide the other. Only affects diagnostics.

What looks right:

  • With the switch off, select_depth_stencil returns nothing and the desktop state is unchanged.
  • The new pipeline-cache key only includes the depth-stencil bytes when they are actually used, so the key and the DepthStencilState assignment agree.
  • Slot 57 pipelines keep any desktop state found first.
  • The title is neutral, and I saw nothing that breaks clean-room.

Not verified: the Windows/WARP result of startup_slot57_depth_* and startup_depth_state*. Please rely on the Windows CI job finishing green before Ready.

AI-assisted; commands listed were executed locally.

…unters

Review nits on R0Y00#2169: one helper chooses the depth view format for both the
pipeline key and the stencil-reference guard, the applied and refused log
paths count separately, and the docs say that with the switch on the
register state wins over list state.

AI-assisted (Claude Code).

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

JB2WIN commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@tedin7, the three nits are in 3b184b31:

  1. docs/startup-runtime.md now says that with the switch on, the register state wins over list state for the stencil reference.
  2. A shared pass_dsv_format(bound, pass) helper now picks the depth format for both the pipeline key in pipeline_for and the stencil-reference guard in draw_translated.
  3. The applied and refused log paths each have their own counter.

ctest --preset dev --no-tests=error -R '^startup_(depth_state|slot57_|stream_depth|pipeline_state)' passes 10/10 on WARP 10.0.26100.9818 and an RTX 3080 (32.0.16.2124), Windows 11 build 26200, including startup_slot57_depth_{warp,hardware}.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 3b184b31f6daf7b44c74c0d308382e0c156ffa46 (2 commits on top of main).

Verdict: no blockers found. Two small notes (P2) and one nit.

Checked locally (Linux)

  • git diff --stat origin/main...HEAD: 8 files, +662/-4.
  • python3 tests/docs_links_check.py: pass (18 files, 402 links).
  • python3 tests/bidi_controls_check.py: pass.
  • git diff --check origin/main...HEAD: clean.
  • python3 -I -m py_compile tests/startup_slot57_depth_check.py: ok.
  • x86_64-w64-mingw32-g++ -std=c++17 -Isrc tests/startup_depth_state_check.cpp: compiles. I could not run the binary: wine here exits with code 53 for any binary, so no pass/fail result and no mutation result from me for the device-free test. The author's mutation table in the PR body (switch ignored, ZFUNC swapped, stencil ref not set) was not re-run by me.
  • CI at review time: Linux Python checks pass; Windows build and gfx1013 jobs still pending. The WARP/hardware fixture (startup_slot57_depth_*) needs the Windows job to count.

Read-through

  • depth_state_apply.h is small and pure. Switch off returns the empty default before anything reads the block. Short block and decoder refusal both set a reason and apply nothing. Stencil ref is carried only when StencilEnable is true. Matches the unit test cases.
  • translation_for: guard info->path == 57 && !bound->has_depth_stencil is right. The desktop state is kept when the decoder refuses.
  • pipeline_for: the PSO key hashes the depth desc only when it is actually used, so a no-DSV pass shares the default PSO. Good.
  • The new startup_slot57_depth target and the tests are wired in CMake like the neighbouring startup_stream_depth. The --mutate switch control uses WILL_FAIL, like startup_pipeline_state_offset_control.

Findings

  • P2 src/startup_stubs/d3d12_draw.inl (draw_translated, the OMSetStencilRef call): the reference is list state and stays set after this draw. A later draw of a different pipeline that relies on an earlier title OMSetStencilRef will now see this value instead. The PR body and docs already say the order is unmeasured. Suggest a one-line note in the docs that the value is not restored, or restore it, so the next reader does not assume it is scoped.
  • P2 The log counters are static LONG and capped at 24. Fine for a switch that is off by default. If the cap is hit, a later refusal reason is silent. Optional: log the reason once per distinct string.
  • nit depth_bounds is reported in the log ("depth bounds not applied"). Consider an OMSetDepthBounds follow-up item in the docs, if not already listed.

No clean-room or title concerns: the title is neutral, and the decoder cites register layout sources only.

AI-assisted; commands listed were executed locally.

@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Resolved the CMake overlap with the depth-target tests and scoped the decoded stencil reference to the slot 57 draw. The next draw sees the saved guest reference, and a successful Reset starts at zero. The mixed-pipeline fixture observes both in pixel readback. The Windows Release selection passed 8/8 with WARP and RTX 4060 Laptop, zero skips. Rebuilding with just the restore removed made st_ref_restore draw blue instead of green on both backends.

@R0Y00
R0Y00 merged commit 009153b into R0Y00:main Nov 25, 2026
5 checks passed
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.

3 participants