startup: decode a PA_SU_SC_MODE_CNTL value to D3D12 cull, winding and fill #2480

Manually merged
github merged 1 commit from gh-pr/2480/head into gh-pr/2480/base 2026-11-27 00:55:40 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-25 18:01 UTC · original
denn0x:startup/raster-mode-decode → main · +220 −0 · 4 files · 1 commits · merged 2026-11-25 20:12 UTC

What

src/startup_stubs/rasterizer_state_decode.h (new) turns a PA_SU_SC_MODE_CNTL register value into the CullMode, FrontCounterClockwise and FillMode of a D3D12_RASTERIZER_DESC (#1999, item B). Field positions follow the amdgpu gc_10_3_0_sh_mask.h header and Mesa's src/amd/registers/gfx10.json.

It decodes the value only. Where a slot 57 pipeline keeps this word in its state block is deliberately not part of the change. The location stays open until it is independently established, as discussed on #1999. The function takes the register value from its caller.

  • Cull: CULL_FRONT [0] and CULL_BACK [1] map to FRONT, BACK or NONE.
  • Winding: FACE [2] 0 means counter-clockwise front faces, the same as radeonsi's S_028814_FACE(!front_ccw). Whether the guest's window coordinates and the D3D12 viewport agree on the winding is not established, so the caller's flip_winding inverts it.
  • Fill: POLY_MODE [4:3] dual mode with the same type on both faces. Lines map to WIREFRAME, triangles to SOLID. With POLY_MODE 0 the type fields are ignored.
  • Refused, with a reason:
    • both faces culled;
    • points, unknown types, or different front and back types;
    • a reserved POLY_MODE;
    • any polygon offset enable [13:11]; the offset words are a separate slice;
    • PROVOKING_VTX_LAST [19];
    • PERSP_CORR_DIS [20].
  • Not read: the remaining fields.

The function is pure and not used by the draw path yet. The other D3D12_RASTERIZER_DESC fields are the defaults: depth clip on, no bias, no MSAA lines, conservative rasterization off.

Test

tests/startup_rasterizer_decode_check.cpp (new, device-free) is registered as startup_rasterizer_decode. It decodes synthetic register values:

  • each cull mode with both FACE values and both flip_winding settings;
  • wireframe and solid dual polygon mode;
  • type fields ignored without POLY_MODE;
  • unread fields (MULTI_PRIM_IB_ENA, KEEP_TOGETHER_ENABLE) that leave the result alone;
  • the 10 refused forms.

The _face_control, _cull_control and _fill_control runs each read one field wrongly. They are WILL_FAIL controls and must fail.

startup_rasterizer_decode_check
startup_rasterizer_decode: PASS (cull none/front/back x FACE x flip, wireframe and solid dual polygon mode, unread fields ignored, 10 refused forms)
startup_rasterizer_decode_check --mutate face   -> 16 failures, exit 1
startup_rasterizer_decode_check --mutate cull   -> 10 failures, exit 1
startup_rasterizer_decode_check --mutate fill   -> 2 failures, exit 1
ctest --preset dev --no-tests=error -R "^startup_rasterizer_decode" -V

Other checks: docs/startup-runtime.md describes the decoder; docs_links_check.py and bidi_controls_check.py pass.

Environment

  • Build: all builds (Ninja Release, MSVC Build Tools 18).
  • Software: Windows 10.0.26300.
  • GPU: device-free, so no GPU runs and no capability skips.

The D3D12 cull and winding behaviour itself is covered by the desktop reference in #2260 and the stream fixture in #2387.

Refs #1999

**@⁠denn0x** on GitHub · 2026-11-25 18:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2480) `denn0x:startup/raster-mode-decode` → `main` · +220 −0 · 4 files · 1 commits · merged 2026-11-25 20:12 UTC ## What `src/startup_stubs/rasterizer_state_decode.h` (new) turns a `PA_SU_SC_MODE_CNTL` register value into the `CullMode`, `FrontCounterClockwise` and `FillMode` of a `D3D12_RASTERIZER_DESC` (#1999, item B). Field positions follow the amdgpu `gc_10_3_0_sh_mask.h` header and Mesa's `src/amd/registers/gfx10.json`. **It decodes the value only.** Where a slot 57 pipeline keeps this word in its state block is deliberately not part of the change. The location stays open until it is independently established, as discussed on #1999. The function takes the register value from its caller. - **Cull:** `CULL_FRONT` [0] and `CULL_BACK` [1] map to FRONT, BACK or NONE. - **Winding:** `FACE` [2] 0 means counter-clockwise front faces, the same as radeonsi's `S_028814_FACE(!front_ccw)`. Whether the guest's window coordinates and the D3D12 viewport agree on the winding is not established, so the caller's `flip_winding` inverts it. - **Fill:** `POLY_MODE` [4:3] dual mode with the same type on both faces. Lines map to WIREFRAME, triangles to SOLID. With `POLY_MODE` 0 the type fields are ignored. - **Refused, with a reason:** - both faces culled; - points, unknown types, or different front and back types; - a reserved `POLY_MODE`; - any polygon offset enable [13:11]; the offset words are a separate slice; - `PROVOKING_VTX_LAST` [19]; - `PERSP_CORR_DIS` [20]. - **Not read:** the remaining fields. The function is pure and not used by the draw path yet. The other `D3D12_RASTERIZER_DESC` fields are the defaults: depth clip on, no bias, no MSAA lines, conservative rasterization off. ## Test `tests/startup_rasterizer_decode_check.cpp` (new, device-free) is registered as `startup_rasterizer_decode`. It decodes synthetic register values: - each cull mode with both `FACE` values and both `flip_winding` settings; - wireframe and solid dual polygon mode; - type fields ignored without `POLY_MODE`; - unread fields (`MULTI_PRIM_IB_ENA`, `KEEP_TOGETHER_ENABLE`) that leave the result alone; - the 10 refused forms. The `_face_control`, `_cull_control` and `_fill_control` runs each read one field wrongly. They are WILL_FAIL controls and must fail. ``` startup_rasterizer_decode_check startup_rasterizer_decode: PASS (cull none/front/back x FACE x flip, wireframe and solid dual polygon mode, unread fields ignored, 10 refused forms) startup_rasterizer_decode_check --mutate face -> 16 failures, exit 1 startup_rasterizer_decode_check --mutate cull -> 10 failures, exit 1 startup_rasterizer_decode_check --mutate fill -> 2 failures, exit 1 ctest --preset dev --no-tests=error -R "^startup_rasterizer_decode" -V ``` **Other checks:** `docs/startup-runtime.md` describes the decoder; `docs_links_check.py` and `bidi_controls_check.py` pass. **Environment** - **Build:** `all` builds (Ninja Release, MSVC Build Tools 18). - **Software:** Windows 10.0.26300. - **GPU:** device-free, so no GPU runs and no capability skips. The D3D12 cull and winding behaviour itself is covered by the desktop reference in #2260 and the stream fixture in #2387. Refs #1999
src/startup_stubs/rasterizer_state_decode.h turns a PA_SU_SC_MODE_CNTL
register value into the CullMode, FrontCounterClockwise and FillMode of
a D3D12_RASTERIZER_DESC (#1999, item B). Field positions follow the
amdgpu gc_10_3_0_sh_mask.h header and Mesa's gfx10.json.

It decodes the value only. Where a slot 57 pipeline keeps the word is
not part of this change and stays open until independently
established. FACE 0 is counter-clockwise front (radeonsi writes
S_028814_FACE(!front_ccw)); the caller's flip_winding inverts it, since
the convention is not established against the D3D12 viewport.

Refused with a reason: both faces culled, point, unknown or mixed
polygon types, a reserved POLY_MODE, any polygon offset enable,
last-vertex provoking and disabled perspective correction. Pure and
unused by draws.

Test: tests/startup_rasterizer_decode_check.cpp (device-free) covers
each cull mode with both FACE values and both flip settings, wireframe
and solid dual polygon mode, unread fields, and the 10 refused forms.
Its face, cull and fill controls each read one field wrongly and must
fail (WILL_FAIL).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:55:38 +00:00
github manually merged commit 94db00408a into gh-pr/2480/base 2026-11-27 00:55:40 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 18:41 UTC · original · reviewed

Review of head 94db0040 (comment only).

What I checked:

  • Scope: one new header, one new device-free check, a CTest registration and a docs paragraph. No .github, launcher, hooks or OS stubs. The header is a pure function and is not used by any draw path.
  • Field layout in rasterizer_state_decode.h matches the public gfx10 PA_SU_SC_MODE_CNTL layout cited in the header: CULL_FRONT [0], CULL_BACK [1], FACE [2], POLY_MODE [4:3], front type [7:5], back type [10:8], offset enables [13:11], PROVOKING_VTX_LAST [19], PERSP_CORR_DIS [20]. The refusals are explicit and each has a reason string. I found no logic bug.
  • Test: the check covers each cull mode with both FACE values and both flip_winding settings, dual polygon mode, the ignored type fields, unread fields, and the 10 refused forms. The three --mutate controls are registered as WILL_FAIL tests in CMakeLists.txt. The mutations change test expectations, not the header, so I also mutated the header (see below).
  • No duplicate: searches for PA_SU_SC_MODE_CNTL and rasterizer cull/winding find only this PR. #2387 (merged) checks winding through slot 86 streams and does not decode this register.
  • Open design question: where a slot 57 pipeline stores this word is left open on #1999. The winding convention (flip_winding) is also not established against the D3D12 viewport. Both are left to @⁠R0Y00.
  • This PR advances no game result. The author posted no game run, and I did not check startup progress. Whether it counts as startup work under #1999 is for @⁠R0Y00 or MasterDomino to say. If they treat it that way, the merge stays with them.
  • The author's Windows build and ctest output in the body is for head 94db0040. I did not re-run it. PR CI on this head: 3 success, 2 skipped, none failed.

Commands run locally (Linux, worktree of this head, mingw-w64 build run under wine):

  • x86_64-w64-mingw32-g++ -std=c++17 -Isrc tests/startup_rasterizer_decode_check.cpp: builds. Plain run: PASS. --mutate face: 16 failures, --mutate cull: 10 failures, --mutate fill: 2 failures, all exit 1.
  • Real mutation of the header (offset enable mask [13:11] narrowed to [12:11]): the check fails on "para offset" (exit 1). Restored afterwards.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py and python3 tests/bidi_controls_check.py: pass.

No issues found. I did not run Win2025, did not update the branch, and did not merge.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 18:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2480#pullrequestreview-6063068377) · **reviewed** Review of head 94db0040 (comment only). What I checked: - Scope: one new header, one new device-free check, a CTest registration and a docs paragraph. No .github, launcher, hooks or OS stubs. The header is a pure function and is not used by any draw path. - Field layout in `rasterizer_state_decode.h` matches the public gfx10 PA_SU_SC_MODE_CNTL layout cited in the header: CULL_FRONT [0], CULL_BACK [1], FACE [2], POLY_MODE [4:3], front type [7:5], back type [10:8], offset enables [13:11], PROVOKING_VTX_LAST [19], PERSP_CORR_DIS [20]. The refusals are explicit and each has a reason string. I found no logic bug. - Test: the check covers each cull mode with both FACE values and both `flip_winding` settings, dual polygon mode, the ignored type fields, unread fields, and the 10 refused forms. The three `--mutate` controls are registered as WILL_FAIL tests in CMakeLists.txt. The mutations change test expectations, not the header, so I also mutated the header (see below). - No duplicate: searches for PA_SU_SC_MODE_CNTL and rasterizer cull/winding find only this PR. #2387 (merged) checks winding through slot 86 streams and does not decode this register. - Open design question: where a slot 57 pipeline stores this word is left open on #1999. The winding convention (`flip_winding`) is also not established against the D3D12 viewport. Both are left to @⁠R0Y00. - This PR advances no game result. The author posted no game run, and I did not check startup progress. Whether it counts as startup work under #1999 is for @⁠R0Y00 or MasterDomino to say. If they treat it that way, the merge stays with them. - The author's Windows build and ctest output in the body is for head 94db0040. I did not re-run it. PR CI on this head: 3 success, 2 skipped, none failed. Commands run locally (Linux, worktree of this head, mingw-w64 build run under wine): - `x86_64-w64-mingw32-g++ -std=c++17 -Isrc tests/startup_rasterizer_decode_check.cpp`: builds. Plain run: PASS. `--mutate face`: 16 failures, `--mutate cull`: 10 failures, `--mutate fill`: 2 failures, all exit 1. - Real mutation of the header (offset enable mask [13:11] narrowed to [12:11]): the check fails on "para offset" (exit 1). Restored afterwards. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py` and `python3 tests/bidi_controls_check.py`: pass. No issues found. I did not run Win2025, did not update the branch, and did not merge. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠ChazY11 on GitHub · 2026-11-25 19:18 UTC · original

Built and run here: all four cases pass, 10 of 11 mutations are caught, and the survivor is provably inert

ctest --preset dev -R 'startup_rasterizer_decode'
    1/4 startup_rasterizer_decode .................  Passed
    2/4 startup_rasterizer_decode_face_control ....  Passed
    3/4 startup_rasterizer_decode_cull_control ....  Passed
    4/4 startup_rasterizer_decode_fill_control ....  Passed
    100% tests passed, 0 tests failed out of 4

The three --mutate face|cull|fill controls declared WILL_FAIL TRUE are the right shape: each one reads a single
field wrongly and the test is expected to fail, so a control that starts passing is itself the alarm.

Eleven mutations of src/startup_stubs/rasterizer_state_decode.h

Beyond the three fields your controls already cover, I mutated the refusal conditions and the mapping:

mutation caught
poly_mode > 1 → > 0 (accept the reserved encoding) caught
front != back || (front != 1 && front != 2) → drop the mismatch half caught
cull_front && cull_back → || caught
field(mode, 11, 13) test disabled caught
field(mode, 19, 19) test disabled caught
field(mode, 20, 20) test disabled caught
field() mask off by one: (1u << (hi - lo + 1)) - 1 → (1u << (hi - lo)) - 1 caught
FrontCounterClockwise: != flip_winding → == flip_winding caught
field(mode, 2, 2) == 0 → == 1 caught
r.DepthClipEnable = TRUE → FALSE caught
cull_front ? FRONT : cull_back ? BACK : NONE → the two arms swapped survived

That is a well-covered decoder: the reserved-encoding refusals, the field helper's own arithmetic and the winding bit
are all pinned, not just the three headline fields.

The survivor is inert by construction, not uncovered

if (cull_front && cull_back) {
    ...                                 // both set: refused before the mapping
}
...
r.CullMode = cull_front ? D3D12_CULL_MODE_FRONT : cull_back ? D3D12_CULL_MODE_BACK : D3D12_CULL_MODE_NONE;

By the time the ternary runs, cull_front && cull_back has already returned, so at most one arm is ever true and the
nesting order cannot change any output. No fixture can catch that mutation because no input distinguishes it.

Worth saying out loud because the code reads as if the order carries priority. Two flat branches would express the
same thing without inviting the question:

r.CullMode = cull_front ? D3D12_CULL_MODE_FRONT
           : cull_back  ? D3D12_CULL_MODE_BACK
                        : D3D12_CULL_MODE_NONE;

— which is what it already is, minus the misleading precedence. Purely cosmetic; I am not asking for a change.

One question on the comment at line 22

The header says the unread bits (KEEP_TOGETHER_ENABLE among them) are not read. Since disabling each of the three
refusal bits is caught, a program that sets one of those unread bits decodes fine and the bit is dropped. Is dropping
them safe for every one of them, or are some of them ones where the correct behaviour would be a refusal rather than a
silently ignored bit? KEEP_TOGETHER_ENABLE in particular sounds like it changes what the rasteriser is allowed to do.
If the answer is "ignoring is correct for this stub", a half-sentence in the comment would settle it.

Environment

Windows 11 build 26300.9974; startup_rasterizer_decode_check built with cmake --build --preset dev --target … (the
full target set stops in DXC on this host, individual targets do not). Each mutation was built, run, reverted and
rebuilt; the final state is 4/4 green.

AI-assisted.

**@⁠ChazY11** on GitHub · 2026-11-25 19:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2480#issuecomment-7172108040) ## Built and run here: all four cases pass, 10 of 11 mutations are caught, and the survivor is provably inert ```text ctest --preset dev -R 'startup_rasterizer_decode' 1/4 startup_rasterizer_decode ................. Passed 2/4 startup_rasterizer_decode_face_control .... Passed 3/4 startup_rasterizer_decode_cull_control .... Passed 4/4 startup_rasterizer_decode_fill_control .... Passed 100% tests passed, 0 tests failed out of 4 ``` The three `--mutate face|cull|fill` controls declared `WILL_FAIL TRUE` are the right shape: each one reads a single field wrongly and the test is expected to fail, so a control that starts passing is itself the alarm. ## Eleven mutations of `src/startup_stubs/rasterizer_state_decode.h` Beyond the three fields your controls already cover, I mutated the refusal conditions and the mapping: | mutation | caught | |---|---| | `poly_mode > 1` → `> 0` (accept the reserved encoding) | **caught** | | `front != back \|\| (front != 1 && front != 2)` → drop the mismatch half | **caught** | | `cull_front && cull_back` → `\|\|` | **caught** | | `field(mode, 11, 13)` test disabled | **caught** | | `field(mode, 19, 19)` test disabled | **caught** | | `field(mode, 20, 20)` test disabled | **caught** | | `field()` mask off by one: `(1u << (hi - lo + 1)) - 1` → `(1u << (hi - lo)) - 1` | **caught** | | `FrontCounterClockwise`: `!= flip_winding` → `== flip_winding` | **caught** | | `field(mode, 2, 2) == 0` → `== 1` | **caught** | | `r.DepthClipEnable = TRUE` → `FALSE` | **caught** | | `cull_front ? FRONT : cull_back ? BACK : NONE` → the two arms swapped | survived | That is a well-covered decoder: the reserved-encoding refusals, the field helper's own arithmetic and the winding bit are all pinned, not just the three headline fields. ## The survivor is inert by construction, not uncovered ```cpp if (cull_front && cull_back) { ... // both set: refused before the mapping } ... r.CullMode = cull_front ? D3D12_CULL_MODE_FRONT : cull_back ? D3D12_CULL_MODE_BACK : D3D12_CULL_MODE_NONE; ``` By the time the ternary runs, `cull_front && cull_back` has already returned, so at most one arm is ever true and the nesting order cannot change any output. No fixture can catch that mutation because no input distinguishes it. Worth saying out loud because the code *reads* as if the order carries priority. Two flat branches would express the same thing without inviting the question: ```cpp r.CullMode = cull_front ? D3D12_CULL_MODE_FRONT : cull_back ? D3D12_CULL_MODE_BACK : D3D12_CULL_MODE_NONE; ``` — which is what it already is, minus the misleading precedence. Purely cosmetic; I am not asking for a change. ## One question on the comment at line 22 The header says the unread bits (`KEEP_TOGETHER_ENABLE` among them) are not read. Since disabling each of the three refusal bits *is* caught, a program that sets one of those unread bits decodes fine and the bit is dropped. Is dropping them safe for every one of them, or are some of them ones where the correct behaviour would be a refusal rather than a silently ignored bit? `KEEP_TOGETHER_ENABLE` in particular sounds like it changes what the rasteriser is allowed to do. If the answer is "ignoring is correct for this stub", a half-sentence in the comment would settle it. ## Environment Windows 11 build 26300.9974; `startup_rasterizer_decode_check` built with `cmake --build --preset dev --target …` (the full target set stops in DXC on this host, individual targets do not). Each mutation was built, run, reverted and rebuilt; the final state is 4/4 green. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.