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

Merged
JB2WIN merged 3 commits from upstream-pr/2169 into main 2026-11-25 03:29:06 +00:00
JB2WIN commented 2026-11-25 02:36:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:36:12Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6595888744 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2169). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T02:36:12Z. --- 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: ```powershell 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](https://claude.com/claude-code)
tedin7 commented 2026-11-25 03:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:38:44Z.

Review: COMMENTED


Review of head 7019d041d3 (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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050970073 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2169#pullrequestreview-6050970073). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:38:44Z. **Review:** COMMENTED --- Review of head 7019d041d3004221a4651ee0f3383e3c4db7983f (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.
tedin7 commented 2026-11-25 03:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:58:37Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051201067 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2169#pullrequestreview-6051201067). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T02:58:37Z. **Review:** COMMENTED --- 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.
JB2WIN commented 2026-11-25 03:01:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:56:01Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151377989 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2169#issuecomment-7151377989). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T02:56:01Z. --- @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.
upstream-sync closed this pull request 2026-11-25 04:04:03 +00:00
R0Y00 commented 2026-11-25 04:04:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:25:55Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151908055 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2169#issuecomment-7151908055). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:25:55Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2161
No description provided.