startup: decode a PA_SU_SC_MODE_CNTL value to D3D12 cull, winding and fill #2472
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2480"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T18:01:38Z.
What
src/startup_stubs/rasterizer_state_decode.h(new) turns aPA_SU_SC_MODE_CNTLregister value into theCullMode,FrontCounterClockwiseandFillModeof aD3D12_RASTERIZER_DESC(#1999, item B). Field positions follow the amdgpugc_10_3_0_sh_mask.hheader and Mesa'ssrc/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_FRONT[0] andCULL_BACK[1] map to FRONT, BACK or NONE.FACE[2] 0 means counter-clockwise front faces, the same as radeonsi'sS_028814_FACE(!front_ccw). Whether the guest's window coordinates and the D3D12 viewport agree on the winding is not established, so the caller'sflip_windinginverts it.POLY_MODE[4:3] dual mode with the same type on both faces. Lines map to WIREFRAME, triangles to SOLID. WithPOLY_MODE0 the type fields are ignored.POLY_MODE;PROVOKING_VTX_LAST[19];PERSP_CORR_DIS[20].The function is pure and not used by the draw path yet. The other
D3D12_RASTERIZER_DESCfields 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 asstartup_rasterizer_decode. It decodes synthetic register values:FACEvalues and bothflip_windingsettings;POLY_MODE;MULTI_PRIM_IB_ENA,KEEP_TOGETHER_ENABLE) that leave the result alone;The
_face_control,_cull_controland_fill_controlruns each read one field wrongly. They are WILL_FAIL controls and must fail.Other checks:
docs/startup-runtime.mddescribes the decoder;docs_links_check.pyandbidi_controls_check.pypass.Environment
allbuilds (Ninja Release, MSVC Build Tools 18).The D3D12 cull and winding behaviour itself is covered by the desktop reference in #2260 and the stream fixture in #2387.
Refs #1999
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:41:31Z.
Review: COMMENTED
Review of head
94db0040(comment only).What I checked:
rasterizer_state_decode.hmatches 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.flip_windingsettings, dual polygon mode, the ignored type fields, unread fields, and the 10 refused forms. The three--mutatecontrols 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).flip_winding) is also not established against the D3D12 viewport. Both are left to @R0Y00.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.git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.pyandpython3 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.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T19:18:07Z.
Built and run here: all four cases pass, 10 of 11 mutations are caught, and the survivor is provably inert
The three
--mutate face|cull|fillcontrols declaredWILL_FAIL TRUEare the right shape: each one reads a singlefield 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.hBeyond the three fields your controls already cover, I mutated the refusal conditions and the mapping:
poly_mode > 1→> 0(accept the reserved encoding)front != back || (front != 1 && front != 2)→ drop the mismatch halfcull_front && cull_back→||field(mode, 11, 13)test disabledfield(mode, 19, 19)test disabledfield(mode, 20, 20)test disabledfield()mask off by one:(1u << (hi - lo + 1)) - 1→(1u << (hi - lo)) - 1FrontCounterClockwise:!= flip_winding→== flip_windingfield(mode, 2, 2) == 0→== 1r.DepthClipEnable = TRUE→FALSEcull_front ? FRONT : cull_back ? BACK : NONE→ the two arms swappedThat 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
By the time the ternary runs,
cull_front && cull_backhas already returned, so at most one arm is ever true and thenesting 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:
— 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_ENABLEamong them) are not read. Since disabling each of the threerefusal 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_ENABLEin 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_checkbuilt withcmake --build --preset dev --target …(thefull 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.