native_pso: a single-sided stencil PSO keeps its depth/stencil/raster state (RT-STATE-DEPTH-RASTER-BACKFACE-MASK) #2473

Merged
Tyrannys merged 1 commit from upstream-pr/2473 into main 2026-11-28 17:52:27 +00:00
Tyrannys commented 2026-11-27 15:41:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-27T15:41:39Z.


Claimed in the coordination issue as: RT-STATE-DEPTH-RASTER-BACKFACE-MASK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7222238523)

What and why

Item 1 of @kevincommits' RT-STATE-AUDIT-PIPELINE finding in #1608 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7221587976), part of #2464 Part B. Thanks for the audit and the repro values.

np::d3d12_depth_raster (runtime/src/native_pso.h) refused any stencil state whose DB_STENCILREFMASK_BF read/write masks differ from DB_STENCILREFMASK, even when DB_DEPTH_CONTROL.BACKFACE_ENABLE is clear. In that case RDNA2 ignores the _BF register and the back face uses the front one, which the function already did for the back face's ops and function. The empty result made fill_depth_raster_state (d3d12_xs_native_pso.h) fall back to its defaults for the whole PSO: depth ALWAYS with writes, cull NONE, stencil off.

The masks are now compared only when BACKFACE_ENABLE is set. Two-sided stencil with differing masks is still refused, because D3D12_DEPTH_STENCIL_DESC has one pair of masks.

Tested

Windows 11, MSVC (VS 18), RelWithDebInfo, on main ec91d695c.

  • native_pso_depth_test gains two checks: kevincommits' values (STENCIL_ENABLE=1, BACKFACE_ENABLE=0, DB_STENCILREFMASK=0x01ffff00, DB_STENCILREFMASK_BF=0) and a differing back write mask (0x01f0ff00) must build the state with its depth (GEQUAL, no writes), cull (BACK) and front stencil ops on both faces.
  • Negative control: with main's native_pso.h, both new checks fail; with the fix, all 28 checks pass. The two-sided "front and back write masks that differ are not built" check still passes.
  • ctest -R "native_pso|pso_stream|pso_validation": 5/5 pass (pso_stream, native_pso_blend, native_pso_depth, native_pso_fallback, d3d12_pso_validation).
  • scripts/check_no_game_data.py: clean.

GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (the tests here are CPU-only)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5529310516 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2473). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-27T15:41:39Z. --- Claimed in the coordination issue as: RT-STATE-DEPTH-RASTER-BACKFACE-MASK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7222238523) ### What and why Item 1 of @kevincommits' `RT-STATE-AUDIT-PIPELINE` finding in #1608 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7221587976), part of #2464 Part B. Thanks for the audit and the repro values. `np::d3d12_depth_raster` (`runtime/src/native_pso.h`) refused any stencil state whose `DB_STENCILREFMASK_BF` read/write masks differ from `DB_STENCILREFMASK`, even when `DB_DEPTH_CONTROL.BACKFACE_ENABLE` is clear. In that case RDNA2 ignores the `_BF` register and the back face uses the front one, which the function already did for the back face's ops and function. The empty result made `fill_depth_raster_state` (`d3d12_xs_native_pso.h`) fall back to its defaults for the whole PSO: depth `ALWAYS` with writes, cull `NONE`, stencil off. The masks are now compared only when `BACKFACE_ENABLE` is set. Two-sided stencil with differing masks is still refused, because `D3D12_DEPTH_STENCIL_DESC` has one pair of masks. ### Tested Windows 11, MSVC (VS 18), RelWithDebInfo, on `main` `ec91d695c`. - `native_pso_depth_test` gains two checks: kevincommits' values (`STENCIL_ENABLE=1`, `BACKFACE_ENABLE=0`, `DB_STENCILREFMASK=0x01ffff00`, `DB_STENCILREFMASK_BF=0`) and a differing back write mask (`0x01f0ff00`) must build the state with its depth (GEQUAL, no writes), cull (BACK) and front stencil ops on both faces. - Negative control: with `main`'s `native_pso.h`, both new checks fail; with the fix, all 28 checks pass. The two-sided "front and back write masks that differ are not built" check still passes. - `ctest -R "native_pso|pso_stream|pso_validation"`: 5/5 pass (`pso_stream`, `native_pso_blend`, `native_pso_depth`, `native_pso_fallback`, `d3d12_pso_validation`). - `scripts/check_no_game_data.py`: clean. GPUs tested: profile M: NVIDIA GeForce RTX 4070 SUPER, 12 GB, desktop, driver 621.01, Windows 11 (the tests here are CPU-only) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Tauwni commented 2026-11-27 16:17:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-27T16:17:45Z.


Tested on a Mac, natively (Apple clang 17) and under Wine:

Tree native_pso_depth
main pass
this PR's native_pso_depth_test.cpp on main, no fix fail: single-sided stencil: the back-face mask register is ignored, depth and raster state kept and ... a differing back write mask is ignored, natively and under Wine
main + this PR pass, natively and under Wine

native_pso_blend and native_pso_fallback pass on all three.

GPUs tested: Apple M3 (profile S), macOS 26.5.1, Wine 11.0 (WineHQ macOS build) with its MoltenVK 1.4.1, clang-cl/lld-link 23.1.6 cross build, main ec91d695c. No game files. MEASURED, 1 run each.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7223090275 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2473#issuecomment-7223090275). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-27T16:17:45Z. --- Tested on a Mac, natively (Apple clang 17) and under Wine: | Tree | `native_pso_depth` | |---|---| | `main` | pass | | this PR's `native_pso_depth_test.cpp` on `main`, no fix | **fail**: `single-sided stencil: the back-face mask register is ignored, depth and raster state kept` and `... a differing back write mask is ignored`, natively and under Wine | | `main` + this PR | pass, natively and under Wine | `native_pso_blend` and `native_pso_fallback` pass on all three. GPUs tested: Apple M3 (profile S), macOS 26.5.1, Wine 11.0 (WineHQ macOS build) with its MoltenVK 1.4.1, clang-cl/lld-link 23.1.6 cross build, `main` `ec91d695c`. No game files. MEASURED, 1 run each. AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-27 18:40:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T18:40:44Z.


Tested for #2464 as Aslanek asked: unit tests and a game run on my machine; CI ignored for now as asked.

RUN pr2473-court | 2026-11-27 | MoonEyes | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        main ec91d695c + PR #2473 (head 8aaea30c7), merged locally without conflict, nothing pushed | shaders: main's own translation
MACHINE:     RTX 4060 8 GB, desktop, only GPU, display attached | NVIDIA 610.88 | Windows 11 Pro 26300 | Ryzen 5 3600 | 32 GB | Windows GPU timeout at the default (2 s)
RECIPE:      short recipe: docs/running.md Windows NVIDIA recipe, pipeline cache warm, 330 s cap, scripted button presses from 60 s | build RelWithDebInfo, only the PR's targets built
TESTS:
  - native_pso_depth_test: 1/1 pass on the PR | fails on main: yes (exit 1, when the PR's test file is built on top of main's sources)
GAME:        session=1 at 145 s | world entered at 200 s | last window >= 1 img/s ends at 286 s | 0 frames after world entry + 240 s | end: time limit (cap 330 s, ended at 341 s) | device loss: no (no fault report) | private RAM max 17038 MB
COMPARED TO: w77 (main ec91d695c, same short recipe): session=1 at 145 s, world at 195 s, last window >= 1 img/s at 293 s, private RAM max 16043 MB, ended by the time limit (337 s)
             w79 (main, same short recipe): world at 200 s, last window >= 1 img/s at 286 s, private RAM max 16583 MB, ended by the time limit (350 s)
             one run each (n=1); on main the spread of world entry on this recipe is about 165 to 200 s, so no conclusion on timings
VERDICT:     unit test passes and fails on main; game run clean to the time limit, no device loss; no timing conclusion (n=1)

Reading (marked):

  • MEASURED: the display stops after the world is entered (86 s after world entry for the last window >= 1 img/s here; 98 s on w77, 86 s on w79). Present on main too, not caused by this PR (finding https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7224692645).
  • MEASURED: the run reached the time limit without a device loss; this says the PR does not break the game boot on this machine, not that it changes anything in the game.
  • The game logs of this run were deleted by a disk cleanup before this write-up; the figures above were extracted before that and cannot be re-checked from the logs now.

Limits: one machine, one run for the PR, one run for each main witness.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7225748448 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2473#issuecomment-7225748448). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T18:40:44Z. --- Tested for #2464 as Aslanek asked: unit tests and a game run on my machine; CI ignored for now as asked. ``` RUN pr2473-court | 2026-11-27 | MoonEyes | AI-assisted: Claude Code (Claude Opus 5.5) BASE: main ec91d695c + PR #2473 (head 8aaea30c7), merged locally without conflict, nothing pushed | shaders: main's own translation MACHINE: RTX 4060 8 GB, desktop, only GPU, display attached | NVIDIA 610.88 | Windows 11 Pro 26300 | Ryzen 5 3600 | 32 GB | Windows GPU timeout at the default (2 s) RECIPE: short recipe: docs/running.md Windows NVIDIA recipe, pipeline cache warm, 330 s cap, scripted button presses from 60 s | build RelWithDebInfo, only the PR's targets built TESTS: - native_pso_depth_test: 1/1 pass on the PR | fails on main: yes (exit 1, when the PR's test file is built on top of main's sources) GAME: session=1 at 145 s | world entered at 200 s | last window >= 1 img/s ends at 286 s | 0 frames after world entry + 240 s | end: time limit (cap 330 s, ended at 341 s) | device loss: no (no fault report) | private RAM max 17038 MB COMPARED TO: w77 (main ec91d695c, same short recipe): session=1 at 145 s, world at 195 s, last window >= 1 img/s at 293 s, private RAM max 16043 MB, ended by the time limit (337 s) w79 (main, same short recipe): world at 200 s, last window >= 1 img/s at 286 s, private RAM max 16583 MB, ended by the time limit (350 s) one run each (n=1); on main the spread of world entry on this recipe is about 165 to 200 s, so no conclusion on timings VERDICT: unit test passes and fails on main; game run clean to the time limit, no device loss; no timing conclusion (n=1) ``` Reading (marked): - MEASURED: the display stops after the world is entered (86 s after world entry for the last window >= 1 img/s here; 98 s on w77, 86 s on w79). Present on main too, not caused by this PR (finding https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7224692645). - MEASURED: the run reached the time limit without a device loss; this says the PR does not break the game boot on this machine, not that it changes anything in the game. - The game logs of this run were deleted by a disk cleanup before this write-up; the figures above were extracted before that and cannot be re-checked from the logs now. Limits: one machine, one run for the PR, one run for each main witness. AI-assisted (Claude Code, Claude Opus 5.5)
timbot103 commented 2026-11-28 02:02:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T02:02:23Z.


Reviewed at head 8aaea30c7 on Windows 11 (MSVC 2022 19.44).

Verification

  • Built native_pso_depth_test.
  • native_pso_depth_test: passed.

Notes

  • Checking back-face stencil mask equality only when BACKFACE_ENABLE is set (native_pso.h:358-392) avoids dropping depth/stencil/raster state on single-sided stencil PSOs whose unused back-face register differs, while keeping the unsupported two-sided mismatch fallback intact.

Approve.

AI-assisted review + local MSVC verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232086982 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2473#issuecomment-7232086982). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-28T02:02:23Z. --- Reviewed at head `8aaea30c7` on Windows 11 (MSVC 2022 `19.44`). ### Verification - Built `native_pso_depth_test`. - `native_pso_depth_test`: **passed**. ### Notes - Checking back-face stencil mask equality only when `BACKFACE_ENABLE` is set (`native_pso.h:358-392`) avoids dropping depth/stencil/raster state on single-sided stencil PSOs whose unused back-face register differs, while keeping the unsupported two-sided mismatch fallback intact. Approve. AI-assisted review + local MSVC verification.
lixonik commented 2026-11-28 10:37:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T10:37:45Z.

Review: APPROVED


Reviewed 8aaea30c7 and verified the native PSO depth/stencil tests.

Code audit:

  • runtime/shims/d3d12_xs_native_pso.h: gating the DB_STENCILREFMASK_BF mask equality check on two_sided = ((d >> 7) & 1) != 0 (BACKFACE_ENABLE) matches hardware single-sided stencil semantics so stale/unrelated backface mask bits no longer cause the PSO's depth/stencil/raster state to be rejected.

Verification (Windows 11, MSVC 19.44, Ninja Release):

  • Built native_pso_depth_test.
  • ctest -R '^native_pso_depth$': 1/1 passed.
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6097268996 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2473#pullrequestreview-6097268996). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-28T10:37:45Z. **Review:** APPROVED --- Reviewed `8aaea30c7` and verified the native PSO depth/stencil tests. Code audit: - `runtime/shims/d3d12_xs_native_pso.h`: gating the `DB_STENCILREFMASK_BF` mask equality check on `two_sided = ((d >> 7) & 1) != 0` (`BACKFACE_ENABLE`) matches hardware single-sided stencil semantics so stale/unrelated backface mask bits no longer cause the PSO's depth/stencil/raster state to be rejected. Verification (Windows 11, MSVC 19.44, Ninja Release): - Built `native_pso_depth_test`. - `ctest -R '^native_pso_depth$'`: 1/1 passed. - `python -I scripts/check_no_game_data.py`: passed. AI-assisted (Antigravity, Gemini).
MoonEyes commented 2026-11-28 17:52:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:52:24Z.


Red/green: On main native_pso_depth_test fails 2 checks (a single-sided stencil PSO loses its depth/stencil/raster state over an unused back-face mask), and with the PR ctest -R "^native_pso_depth$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243353272 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2473#issuecomment-7243353272). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T17:52:24Z. --- Red/green: On main native_pso_depth_test fails 2 checks (a single-sided stencil PSO loses its depth/stencil/raster state over an unused back-face mask), and with the PR ctest -R "^native_pso_depth$" passes. Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 22:02:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:02:39Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head 8aaea30c7; green run in a merge package of 11 PRs, no new ctest failure vs main
  • Test: ctest -R "^native_pso_depth$"
  • Red on main: 2 failures (one-sided stencil: the back-face mask is not ignored)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246455413 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2473#issuecomment-7246455413). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:02:39Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `8aaea30c7`; green run in a merge package of 11 PRs, no new ctest failure vs main - Test: `ctest -R "^native_pso_depth$"` - Red on main: 2 failures (one-sided stencil: the back-face mask is not ignored) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
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
ProjectLeonida/mandy!2473
No description provided.