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

Closed
opened 2026-11-26 20:22:10 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1691
Author: @OreoFR
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: rt-slot57-depth-raster


📝 Commits (10+)

  • 70d3517 d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE)
  • 2f44380 docs: state blob A's colour-target registers, measured over the library (RT-SLOT57-BLEND-STATE)
  • 4e7b764 d3d12_xs: integer render targets keep blending off in slot 57 native PSOs (RT-SLOT57-BLEND-STATE)
  • f557637 d3d12_xs: a native PSO whose blend state the device refuses is built with blending off on its stand-in targets (RT-SLOT57-BLEND-STATE)
  • 81f33de docs: the stand-in-target fallback of RT-SLOT57-BLEND-STATE
  • ebe4512 d3d12_xs: depth, stencil and raster state for slot 57 native pipelines from state blob A (RT-SLOT57-DEPTH-RASTER)
  • 69ddea6 docs: state blob A's depth, stencil and raster registers (RT-SLOT57-DEPTH-RASTER)
  • f0e776a docs: STENCILTESTVAL and depth-bias counts for RT-SLOT57-DEPTH-RASTER (review)
  • 668d65b d3d12_xs: slot 57 retries only a pipeline that blends a B4G4R4A4 stand-in (RT-SLOT57-BLEND-STATE review)
  • 7a76939 Merge branch 'rt-slot57-blend-state' into rt-slot57-depth-raster

📊 Changes

8 files changed (+814 additions, -11 deletions)

View changed files

📝 docs/fspx.md (+80 -2)
📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/shims/d3d12_xs_native_pso.h (+106 -8)
➕ runtime/shims/d3d12_xs_native_pso_fallback.h (+25 -0)
📝 runtime/src/native_pso.h (+237 -1)
➕ runtime/test/native_pso_blend_test.cpp (+143 -0)
➕ runtime/test/native_pso_depth_test.cpp (+141 -0)
➕ runtime/test/native_pso_fallback_test.cpp (+73 -0)

📄 Description

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

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1691 **Author:** [@OreoFR](https://github.com/OreoFR) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `rt-slot57-depth-raster` --- ### 📝 Commits (10+) - [`70d3517`](https://github.com/ubiquitarianism/leonida/commit/70d351788924726089efac6344da8a49f8e45d39) d3d12_xs: blend state for slot 57 native pipelines from state blob A (RT-SLOT57-BLEND-STATE) - [`2f44380`](https://github.com/ubiquitarianism/leonida/commit/2f44380590e9471cb44b15818ad2c2c422a2af21) docs: state blob A's colour-target registers, measured over the library (RT-SLOT57-BLEND-STATE) - [`4e7b764`](https://github.com/ubiquitarianism/leonida/commit/4e7b764dbc04fbd5343fb6c99224a8b0bec9ae9c) d3d12_xs: integer render targets keep blending off in slot 57 native PSOs (RT-SLOT57-BLEND-STATE) - [`f557637`](https://github.com/ubiquitarianism/leonida/commit/f5576377d1b2052277b406d2299c3a2692137173) d3d12_xs: a native PSO whose blend state the device refuses is built with blending off on its stand-in targets (RT-SLOT57-BLEND-STATE) - [`81f33de`](https://github.com/ubiquitarianism/leonida/commit/81f33de1cd307ac7cd7365724c55d27999888629) docs: the stand-in-target fallback of RT-SLOT57-BLEND-STATE - [`ebe4512`](https://github.com/ubiquitarianism/leonida/commit/ebe45122538e90bee0ae82caa04ee8288dac918e) d3d12_xs: depth, stencil and raster state for slot 57 native pipelines from state blob A (RT-SLOT57-DEPTH-RASTER) - [`69ddea6`](https://github.com/ubiquitarianism/leonida/commit/69ddea68031fa0eed64cd3e967c055d21726bec1) docs: state blob A's depth, stencil and raster registers (RT-SLOT57-DEPTH-RASTER) - [`f0e776a`](https://github.com/ubiquitarianism/leonida/commit/f0e776adfb68977088f12576764ed93e4bcb0c02) docs: STENCILTESTVAL and depth-bias counts for RT-SLOT57-DEPTH-RASTER (review) - [`668d65b`](https://github.com/ubiquitarianism/leonida/commit/668d65b4b9cb74586176edb97a9379231153e4ff) d3d12_xs: slot 57 retries only a pipeline that blends a B4G4R4A4 stand-in (RT-SLOT57-BLEND-STATE review) - [`7a76939`](https://github.com/ubiquitarianism/leonida/commit/7a769396d99d93474e980e2d1426854a6c2b3e6c) Merge branch 'rt-slot57-blend-state' into rt-slot57-depth-raster ### 📊 Changes **8 files changed** (+814 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `docs/fspx.md` (+80 -2) 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/shims/d3d12_xs_native_pso.h` (+106 -8) ➕ `runtime/shims/d3d12_xs_native_pso_fallback.h` (+25 -0) 📝 `runtime/src/native_pso.h` (+237 -1) ➕ `runtime/test/native_pso_blend_test.cpp` (+143 -0) ➕ `runtime/test/native_pso_depth_test.cpp` (+141 -0) ➕ `runtime/test/native_pso_fallback_test.cpp` (+73 -0) </details> ### 📄 Description Claimed in the coordination issue as: RT-SLOT57-DEPTH-RASTER (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156345815) 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:22:10 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1706
No description provided.