d3d12_xs: depth, stencil and raster state for slot 57 native pipelines from state blob A (RT-SLOT57-DEPTH-RASTER) #1691

Manually merged
github merged 10 commits from gh-pr/1691/head into gh-pr/1691/base 2026-11-26 10:01:00 +00:00
Owner

@⁠OreoFR on GitHub · 2026-11-25 08:20 UTC · original
OreoFR:rt-slot57-depth-raster → main · +814 −11 · 8 files · 10 commits · merged 2026-11-25 13:55 UTC

Claimed in the coordination issue as: RT-SLOT57-DEPTH-RASTER (#1608)

Depends on: #1671, #1592

This builds on #1671: same functions in runtime/shims/d3d12_xs_native_pso.h and runtime/src/native_pso.h. Its commits are the first five here and drop out once it merges. #1592 has the same one-line #include conflict as #1671. The real-boot test also used #1558 and #1547 to get past the landing screen on NVIDIA; this change doesn't need them.

What and why

The slot 57 native factory built every PSO with depth ALWAYS plus writes (wherever there was a DSV), no stencil, no culling and depth clip on. State blob A carries the real state in RDNA2 registers beside the blend registers #1671 decodes (vertex-pipeline offsets, +84 in mesh pipelines). Measured over all 25,471 graphics records of 1.0.2.1:

  • +0xb8 DB_DEPTH_CONTROL:
    • with no DSV in blob B, Z_ENABLE is clear in 7,040 of 7,079 records;
    • STENCIL_ENABLE is set only with stencil formats;
    • depth bounds is never used;
    • the test is off in 9,062 records, otherwise mostly GEQUAL (reversed depth).
  • +0xbc DB_STENCIL_CONTROL: only KEEP, REPLACE_TEST, ADD_WRAP (operand 1), ZERO and INVERT are used. +0xc0/+0xc4 DB_STENCILREFMASK(_BF): the two faces have equal masks in every stencil record.
  • +0xa0 PA_SU_SC_MODE_CNTL: no culling in 13,534 records, back faces in 11,873, front faces in 62.
  • +0x9c PA_CL_CLIP_CNTL: D3D clip space in every record, and both z clips off (depth clamp) in 960.

The layouts and counts are in docs/fspx.md. Aggregate counts only; no blob bytes are quoted.

  • runtime/src/native_pso.h:

    • decode_state_a_depth_raster reads the registers. It shares the shape and tag check with the blend decode.
    • d3d12_depth_raster maps them to D3D12. The compare functions are shifted by one. The stencil ops map as follows, with the adding ones only for an operand of 1:
      • REPLACE_TEST → REPLACE;
      • ADD_WRAP → INCR, ADD_CLAMP → INCR_SAT, and the subtracting ones likewise;
      • ZERO, INVERT and KEEP map to themselves.
    • The back face takes the _BF fields under BACKFACE_ENABLE. Cull comes from CULL_FRONT/CULL_BACK, FrontCounterClockwise = !FACE, and DepthClipEnable is off when both z clips are off.
  • runtime/shims/d3d12_xs_native_pso.h: fill_depth_raster_state applies the mapping to both the VS and the mesh paths. A pipeline without a DSV keeps depth and stencil off.

  • Not built, falling back to today's defaults (logged):

    • another clip space, or only one z clip off;
    • a polygon mode, or culling both faces;
    • depth bounds, or the colour-write-on-depth flags;
    • a stencil op with no D3D12 equivalent, or front and back masks that differ.

    None of these occurs in 1.0.2.1: a Python mirror of these rules maps all 25,471 records.

  • Out of scope: depth bias (PA_SU_POLY_OFFSET_*), because its D3D12 units depend on the depth format.

  • runtime/test/native_pso_depth_test.cpp (portable, standard library only): register reads for both families, every mapping above, and each refused form.

What a real boot can and can't show. The first-run pages and the loading slideshow are drawn without a DSV, so this change must not alter them, and it doesn't. The 3D pipelines it changes only draw once a world frame is reached, which no build has yet. The one field whose effect isn't visible before then is the winding: FACE maps to FrontCounterClockwise = !FACE, as RADV and PAL program it.

Tested

  • Real boot, retail 1.0.2.1, native Windows: main + #1558 + #1547 + #1671 + this branch, fresh first-run profile, factory on.
    • The first-run pages, the legal screens and the loading slideshow draw as with #1671 alone.
    • No slot 57 pipeline is refused, none falls back to the default depth state, and there was no device loss in that run (one earlier run lost the device at 138 s right after the first press, before #1671's stand-in fix; it didn't recur).
  • ctest on Windows: native_pso_depth, native_pso_blend, xs_proxy_mock and xbox_native_base_draw pass.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 591.59 (32.0.15.9159), Windows 11

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase). It's stacked on #1671, as stated above.
  • 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. (Not a translator change; the measurement is in docs/fspx.md.)

🤖 Generated with Claude Code

**@⁠OreoFR** on GitHub · 2026-11-25 08:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691) `OreoFR:rt-slot57-depth-raster` → `main` · +814 −11 · 8 files · 10 commits · merged 2026-11-25 13:55 UTC Claimed in the coordination issue as: RT-SLOT57-DEPTH-RASTER (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) Depends on: #1671, #1592 This builds on #1671: same functions in `runtime/shims/d3d12_xs_native_pso.h` and `runtime/src/native_pso.h`. Its commits are the first five here and drop out once it merges. #1592 has the same one-line `#include` conflict as #1671. The real-boot test also used #1558 and #1547 to get past the landing screen on NVIDIA; this change doesn't need them. ### What and why The slot 57 native factory built every PSO with depth `ALWAYS` plus writes (wherever there was a DSV), no stencil, no culling and depth clip on. State blob A carries the real state in RDNA2 registers beside the blend registers #1671 decodes (vertex-pipeline offsets, +84 in mesh pipelines). Measured over all 25,471 graphics records of 1.0.2.1: - **`+0xb8` `DB_DEPTH_CONTROL`:** - with no DSV in blob B, `Z_ENABLE` is clear in 7,040 of 7,079 records; - `STENCIL_ENABLE` is set only with stencil formats; - depth bounds is never used; - the test is off in 9,062 records, otherwise mostly `GEQUAL` (reversed depth). - **`+0xbc` `DB_STENCIL_CONTROL`:** only `KEEP`, `REPLACE_TEST`, `ADD_WRAP` (operand 1), `ZERO` and `INVERT` are used. **`+0xc0`/`+0xc4` `DB_STENCILREFMASK(_BF)`:** the two faces have equal masks in every stencil record. - **`+0xa0` `PA_SU_SC_MODE_CNTL`:** no culling in 13,534 records, back faces in 11,873, front faces in 62. - **`+0x9c` `PA_CL_CLIP_CNTL`:** D3D clip space in every record, and both z clips off (depth clamp) in 960. The layouts and counts are in `docs/fspx.md`. Aggregate counts only; no blob bytes are quoted. - `runtime/src/native_pso.h`: - `decode_state_a_depth_raster` reads the registers. It shares the shape and tag check with the blend decode. - `d3d12_depth_raster` maps them to D3D12. The compare functions are shifted by one. The stencil ops map as follows, with the adding ones only for an operand of 1: - `REPLACE_TEST` → `REPLACE`; - `ADD_WRAP` → `INCR`, `ADD_CLAMP` → `INCR_SAT`, and the subtracting ones likewise; - `ZERO`, `INVERT` and `KEEP` map to themselves. - The back face takes the `_BF` fields under `BACKFACE_ENABLE`. Cull comes from `CULL_FRONT`/`CULL_BACK`, `FrontCounterClockwise = !FACE`, and `DepthClipEnable` is off when both z clips are off. - `runtime/shims/d3d12_xs_native_pso.h`: `fill_depth_raster_state` applies the mapping to both the VS and the mesh paths. A pipeline without a DSV keeps depth and stencil off. - **Not built, falling back to today's defaults (logged):** - another clip space, or only one z clip off; - a polygon mode, or culling both faces; - depth bounds, or the colour-write-on-depth flags; - a stencil op with no D3D12 equivalent, or front and back masks that differ. None of these occurs in 1.0.2.1: a Python mirror of these rules maps all 25,471 records. - **Out of scope:** depth bias (`PA_SU_POLY_OFFSET_*`), because its D3D12 units depend on the depth format. - `runtime/test/native_pso_depth_test.cpp` (portable, standard library only): register reads for both families, every mapping above, and each refused form. **What a real boot can and can't show.** The first-run pages and the loading slideshow are drawn without a DSV, so this change must not alter them, and it doesn't. The 3D pipelines it changes only draw once a world frame is reached, which no build has yet. The one field whose effect isn't visible before then is the winding: `FACE` maps to `FrontCounterClockwise = !FACE`, as RADV and PAL program it. ### Tested - **Real boot, retail 1.0.2.1, native Windows:** `main` + #1558 + #1547 + #1671 + this branch, fresh first-run profile, factory on. - The first-run pages, the legal screens and the loading slideshow draw as with #1671 alone. - No slot 57 pipeline is refused, none falls back to the default depth state, and there was no device loss in that run (one earlier run lost the device at 138 s right after the first press, before #1671's stand-in fix; it didn't recur). - **ctest on Windows:** `native_pso_depth`, `native_pso_blend`, `xs_proxy_mock` and `xbox_native_base_draw` pass. GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 591.59 (32.0.15.9159), Windows 11 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). It's stacked on #1671, as stated above. - [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. (Not a translator change; the measurement is in `docs/fspx.md`.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A library pipeline enables MAX on an R8_UINT target; the colour block bypasses
blending there, and D3D12 refuses the PSO.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On devices without renderable B4G4R4A4, the Vulkan layer refuses blending on the
RGBA8 stand-in (E_NOTIMPL). Turn blending off on those targets, then on every
target, before leaving the pipeline to the PC description path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
adrianmjim's review: the blend fallback ran on any E_NOTIMPL, which also stands for
refusals unrelated to blending (stream_unsupported, mesh limits, FullyCovered, and
#1703's dual-source refusal). Such a pipeline was retried with blending off, logged as
a blend refusal, and, if the retry succeeded, drew without the blend the title asked for.

Now only a pipeline with a blended B4G4R4A4 target is retried, with blending off on
those targets alone (without_stand_in_blend, its own header), and the line is printed
only when that retry succeeds. The "every target" step is gone: no real boot used it
(RTX 4070 Laptop and kawaii-shakal's RTX 5070 Ti only ever logged the B4G4R4A4 step).
native_pso_fallback_test covers the decision.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	runtime/CMakeLists.txt
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:58 +00:00
github manually merged commit 7a769396d9 into gh-pr/1691/base 2026-11-26 10:01:00 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 09:45 UTC · original · reviewed

Review (read-only, not run). I checked the decode against the RDNA2 register layout, and it matches:

  • ZFUNC and STENCILFUNC are 0..7 → D3D12 1..8, with the + 1;
  • FACE = 1 means clockwise is front, so FrontCounterClockwise = !FACE;
  • a polygon mode, culling both faces, depth bounds, the colour-write flags, a single disabled z clip, and unequal face masks are refused;
  • no DSV turns depth and stencil off.

Two questions:

  1. The stencil reference value. DB_STENCILREFMASK bits 7:0 are STENCILTESTVAL, the reference. The decode reads the masks and STENCILOPVAL but not the test value, so the pipeline relies on the title calling OMSetStencilRef. On the console the ref can come in with the pipeline's register set. If the title never sets it for these PSOs, stencil tests would compare against 0. Could you count how many stencil-enabled records have a nonzero STENCILTESTVAL (bits 7:0 of +0xc0)? If any do, the native PSO path may need to supply it as the default ref.
  2. Depth bias is out of scope here. A count of records with POLY_OFFSET_*_ENABLE set in PA_SU_SC_MODE_CNTL (bits 11 and 12) would show how many shadow or decal pipelines will draw without it once a world frame is reached. It would also be a good marker for the follow-up.

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

**@⁠kawaii-shakal** on GitHub · 2026-11-25 09:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691#pullrequestreview-6055209294) · **reviewed** Review (read-only, not run). I checked the decode against the RDNA2 register layout, and it matches: - `ZFUNC` and `STENCILFUNC` are 0..7 → D3D12 1..8, with the `+ 1`; - `FACE` = 1 means clockwise is front, so `FrontCounterClockwise = !FACE`; - a polygon mode, culling both faces, depth bounds, the colour-write flags, a single disabled z clip, and unequal face masks are refused; - no DSV turns depth and stencil off. Two questions: 1. **The stencil reference value.** `DB_STENCILREFMASK` bits 7:0 are `STENCILTESTVAL`, the reference. The decode reads the masks and `STENCILOPVAL` but not the test value, so the pipeline relies on the title calling `OMSetStencilRef`. On the console the ref can come in with the pipeline's register set. If the title never sets it for these PSOs, stencil tests would compare against 0. Could you count how many stencil-enabled records have a nonzero `STENCILTESTVAL` (bits 7:0 of `+0xc0`)? If any do, the native PSO path may need to supply it as the default ref. 2. **Depth bias** is out of scope here. A count of records with `POLY_OFFSET_*_ENABLE` set in `PA_SU_SC_MODE_CNTL` (bits 11 and 12) would show how many shadow or decal pipelines will draw without it once a world frame is reached. It would also be a good marker for the follow-up. AI-assisted review (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠OreoFR on GitHub · 2026-11-25 10:09 UTC · original

@⁠kawaii-shakal thanks for checking the decode. The counts, over all 25,471 graphics records of 1.0.2.1:

  1. STENCILTESTVAL (+0xc0 and +0xc4 bits 7:0) is 0 in all 6,213 stencil-enabled records, front and back. So the reference always comes from the title (OMSetStencilRef), and leaving it out of the PSO loses nothing here. I'll note it in docs/fspx.md.
  2. Depth bias: POLY_OFFSET_FRONT_ENABLE and POLY_OFFSET_BACK_ENABLE (bits 11 and 12) are set in all 25,471 records, so they don't tell which pipelines use a bias. The values look like the floats at +0xac / +0xb0, which fit the offset scale and offset: both 0 in 23,987 records, and nonzero in about 1,480 (for example 0.003 / 29.0 in 746, 0 / 16.0 in 631). That's the count a depth-bias follow-up should start from, together with the unit conversion for each depth format.

AI-assisted.

**@⁠OreoFR** on GitHub · 2026-11-25 10:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691#issuecomment-7159299256) @⁠kawaii-shakal thanks for checking the decode. The counts, over all 25,471 graphics records of 1.0.2.1: 1. **`STENCILTESTVAL`** (`+0xc0` and `+0xc4` bits 7:0) is **0 in all 6,213 stencil-enabled records**, front and back. So the reference always comes from the title (`OMSetStencilRef`), and leaving it out of the PSO loses nothing here. I'll note it in `docs/fspx.md`. 2. **Depth bias:** `POLY_OFFSET_FRONT_ENABLE` and `POLY_OFFSET_BACK_ENABLE` (bits 11 and 12) are set in **all 25,471 records**, so they don't tell which pipelines use a bias. The values look like the floats at `+0xac` / `+0xb0`, which fit the offset scale and offset: both 0 in 23,987 records, and nonzero in about 1,480 (for example 0.003 / 29.0 in 746, 0 / 16.0 in 631). That's the count a depth-bias follow-up should start from, together with the unit conversion for each depth format. AI-assisted.
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-25 11:33 UTC · original · reviewed

Built and tested on Windows 11 with MSVC 19.44 (scripts\build_runtime.ps1, incremental on main 3f81d46ac's build tree), NVIDIA GeForce RTX 4060, driver 610.88. Head f0e776adf (it carries #1671's commits).

ctest -R "native_pso|dual_source|translated_draw|xs_proxy_mock|xbox_native_base_draw": 13/13 passed, including native_pso_blend, native_pso_depth, d3d12_translated_draw and xbox_native_base_draw, and the nine xs_proxy_mock* variants.

Not checked: the in-game effect (blend, depth/stencil/raster state on the slot 57 pipelines). That needs a world frame, which my setup does not reach yet.

AI-assisted: yes (Claude Code ran the build and the tests; I read the results).

**@⁠MoonEyes** on GitHub · 2026-11-25 11:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691#pullrequestreview-6056846388) · **reviewed** Built and tested on Windows 11 with MSVC 19.44 (`scripts\build_runtime.ps1`, incremental on main 3f81d46ac's build tree), NVIDIA GeForce RTX 4060, driver 610.88. Head f0e776adf (it carries #1671's commits). `ctest -R "native_pso|dual_source|translated_draw|xs_proxy_mock|xbox_native_base_draw"`: 13/13 passed, including `native_pso_blend`, `native_pso_depth`, `d3d12_translated_draw` and `xbox_native_base_draw`, and the nine `xs_proxy_mock*` variants. Not checked: the in-game effect (blend, depth/stencil/raster state on the slot 57 pipelines). That needs a world frame, which my setup does not reach yet. AI-assisted: yes (Claude Code ran the build and the tests; I read the results).
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-25 11:57 UTC · original

Tested as part of the #1671 + #1691 + #1703 stack (188207a9d) on main bcaa13dad, in a real boot on an RTX 5070 Ti (NVIDIA 617.42, Windows 11). Menu text renders as glyphs instead of solid blocks, and no pipeline is refused. Details: #1671. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠kawaii-shakal** on GitHub · 2026-11-25 11:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691#issuecomment-7161724342) Tested as part of the #1671 + #1691 + #1703 stack (188207a9d) on `main` bcaa13dad, in a real boot on an RTX 5070 Ti (NVIDIA 617.42, Windows 11). Menu text renders as glyphs instead of solid blocks, and no pipeline is refused. Details: https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1671. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 13:55 UTC · original

Merged, after #1703. Thank you, @⁠OreoFR, and thanks to @⁠kawaii-shakal for the stencil-reference and depth-bias questions and the real boot, and to @⁠MoonEyes for the independent pass.

  • Checked the bit positions against the RDNA2 layout: compare functions (+1), stencil ops and their order in D3D12_DEPTH_STENCILOP_DESC, ref/mask fields, BACKFACE_ENABLE, cull, and both z clips off → DepthClipEnable = FALSE. All correct, on both the vertex and the mesh paths.
  • FrontCounterClockwise = !FACE is the one field a frame hasn't confirmed yet, and the PR says so. Worth checking first once a world frame draws.
  • Small follow-up idea: also refuse CLIP_DISABLE (bit 16) and DX_RASTERIZATION_KILL (bit 22) in PA_CL_CLIP_CNTL, or note that they are clear in all records.
  • Windows suite under Wine (llvmpipe and an RDNA2 iGPU) on main with #1703 + this branch: nothing goes from pass to fail; native_pso_depth passes on both.
  • Next time, please name the model in the AI-assistance line.
  • Checked on main 77baf9062 + 7a769396d: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass; check_no_game_data.py is clean on the 5 changed files.

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

**@⁠aslan2142** on GitHub · 2026-11-25 13:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1691#issuecomment-7164499775) Merged, after #1703. Thank you, @⁠OreoFR, and thanks to @⁠kawaii-shakal for the stencil-reference and depth-bias questions and the real boot, and to @⁠MoonEyes for the independent pass. - Checked the bit positions against the RDNA2 layout: compare functions (+1), stencil ops and their order in `D3D12_DEPTH_STENCILOP_DESC`, ref/mask fields, `BACKFACE_ENABLE`, cull, and both z clips off → `DepthClipEnable = FALSE`. All correct, on both the vertex and the mesh paths. - `FrontCounterClockwise = !FACE` is the one field a frame hasn't confirmed yet, and the PR says so. Worth checking first once a world frame draws. - Small follow-up idea: also refuse `CLIP_DISABLE` (bit 16) and `DX_RASTERIZATION_KILL` (bit 22) in `PA_CL_CLIP_CNTL`, or note that they are clear in all records. - Windows suite under Wine (llvmpipe and an RDNA2 iGPU) on `main` with #1703 + this branch: nothing goes from pass to fail; `native_pso_depth` passes on both. - Next time, please name the model in the AI-assistance line. - **Checked on `main` `77baf9062` + `7a769396d`:** it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass; `check_no_game_data.py` is clean on the 5 changed files. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.