startup: lower 32-bit scalar writes to m0 and track symbolic m0 state #1888
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1895"
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 consolelogkyo on 2026-11-24T20:27:44Z.
Problem
In
tools/startup/gfx2hlsl.py,Stage.declarations()declaresuint m0 = 0;, and bothStage.u('m0')andStage.op_s_buffer_load_dword()readm0as a runtimeuintregister (for examples_buffer_load_dword s0, s[4:7], m0). However, scalar operations writingm0(sdst == 124) were either silently dropped or crashed:Stage.scalar()writes tom0(and theirSCCupdates).Stage.scalar()returnedNonewheneverdname == 'm0', discardings_mov_b32 m0, ...,s_movk_i32 m0, ...,s_lshl_b32 m0, ...,s_add_u32 m0, ..., etc., som0stayed0at run time and anySCC-producing write tom0leftsccstale.TypeErrorons_cselect_b32,s_bfm_b32,saveexecandwrexectargetingm0. Those handlers subscriptedreg_range(ops[0])[1]directly, which isNonefor'm0'.m0. For 64-bit scalar opcodes (*_b64),decode_s_reg64(124)formats operand124as'm0'. Becausem0is a 32-bit register on RDNA 2, 64-bit scalar instructions namingm0as destination or source either vanished (dname == 'm0') or raisedTypeError.What Changed
tools/startup/gfx2hlsl.py:Stage.scalar()to emitm0 = <expr>;(andscc = ...;when defined bySCA) for 32-bit scalar ALU writes tom0.s_mov_b32 m0, sNbeforev_interp_*) whensNhappens to hold a symbolic pointer/descriptor fromsetup_entry(): non-SCCpointer/descriptor moves intom0record the symbolic tag inself.sym['m0']without failing unlessm0is later read numerically inStage.u('m0')(or used in anSCC-producing operation on descriptor data), and numeric writes tom0clearself.sym['m0'].Stage.scalar_select()andStage.op_s_bfm_b32()to emit 32-bitm0writes and clearself.sym['m0'], allowedm0as a 32-bit source inop_s_andn2_wrexec_b32, and refusedm0withUnsupportedon 64-bit scalar operations (*_b64) andsaveexec/wrexecdestinations.tests/startup_gfx2hlsl_scalar_m0_check.py,CMakeLists.txt,.github/workflows/windows.yml,AGENTS.md,docs/experiments.md:binary llvm-mc-15parity verification, pure-Python controls (including symbolic pointer propagation/clearing, 64-bit andsaveexec/wrexecrefusals, and an in-process monkeypatch control), and two 16-vertex D3D12 buffer-load readback fixtures:s_lshl_b32 m0, s8, 4(writing bothm0andscc) ->s_cselect_b32 m0, m0, 48->s_add_u32 m0, m0, 8->s_buffer_load_dwordx4ats8 = 0ands8 = 2;s_movk_i32 m0, 0x20->s_buffer_load_dwordx2and runtimes_bfm_b32 m0, s8, 2->s_buffer_load_dwordx2ats8 = 3(plus FXCvs_5_1/ps_5_1compilation).Verification
Tested on Windows 11 26H2 (build
26300.9974), MSVC19.44.35230.0, Windows SDK10.0.26100.0(dxc.exe+fxc.exe), D3D12 debug layer enabled (debug_errors=0 debug_warnings=0):10.0.26100.9818— 0 mismatches across all 320-dword buffer readbacks; all wrong-reference controls and translation mutations (m0writes dropped,sccupdate dropped) failed as expected.32.0.32029.2010) — 0 mismatches across all 320-dword buffer readbacks; all wrong-reference controls and translation mutations failed as expected.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T20:55:24Z.
Local review found that s_bfm_b32 targeting m0 cleared the symbolic tag before reading either source. A self-read could therefore use an old numeric value even when m0 held a descriptor pointer. The fast-forward checks both operands while the tag is still live and adds a source-built refusal control for either position. The updated scalar controls passed. Please keep the shared SMEM m0 read through Stage.u once #1881 lands; that ensures it observes this same symbolic guard.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:13:01Z.
Review: COMMENTED
Review of #1895 at exact head
498dcf585285d0a8f689a3d895fb5207ffa6bbbe(fetched frompull/1895/head, HEAD equals currentheadRefOid;git merge-treeagainst currentmainshows no conflicts).Verdict: no P1/P2 found from what is runnable on Linux. Comment only, not an approval. The GPU readback part is not verified by me (see limits).
What I checked
tools/startup/gfx2hlsl.py(+48/-8), newtests/startup_gfx2hlsl_scalar_m0_check.py(+467), ctest entries (controls,warp,hardware,SKIP_RETURN_CODE 77),windows.yml(+2),AGENTS.md(+1),docs/experiments.mdsection.tools/disasm_rdna2.py; data is synthetic. Title is neutral.Stage.scalar()m0 destination now emitsm0 = expr;(+sccwith$->m0, same template asset_s), pointer/descriptor sources are recorded inself.sym['m0']and any later numeric read refuses (u('m0'),smem_soffset). A numeric write pops the stale symbol. 64-bit ops namingm0andsaveexec/wrexecwith a non-sdestination now raiseUnsupportedinstead ofTypeError. The pixel-shader entry register (('const', 0),setup_entry) still moves intom0without failing, so the usuals_mov_b32 m0, sNinterpolation prologue is not turned into a refusal.Commands run locally
git diff --check origin/main...HEAD-> exit 0python -B tests/startup_gfx2hlsl_scalar_m0_check.py controls->startup scalar m0 controls passedpython -B tests/startup_gfx2hlsl_scalar_m0_check.py binary llvm-mc-19->scalar m0 encodings match llvm-mc(llvm-mc-19, the only one on this host; CI usesllvm-mc-15)startup_gfx2hlsl_{b64_shift,bit_alu,capture,cndmask_neg,cvt_alu,mad,op_refusals,operand_count,sdwa,sdwa_cvt,shift64,smem_offset,tbuffer_16f,vcvt_omod}_check.py,startup_translator_check.py,startup_flat_param_check.py,startup_buffer_address_check.pybidi_controls_check.py->no bidirectional controls;docs_links_check.py->Checked 18 Markdown files and 384 linksMutations (applied to
tools/startup/gfx2hlsl.py, controls re-run, thengit checkout -- .)u('m0')stops refusing a symbolic m0scalar()m0 destination branch disabled (writes dropped again)sccupdate after an m0 write removedscc = m0 != 0;missing)syms[0]scalar()removedsmem_soffsetback to the literal'm0'scalar_selectkeeps a stale m0 symbols_bfm_b32constant mask shift off by one0x3cvs0x78)saveexecdestination check removedTypeError)wrexecsource fallback revertedTypeError)10/10 killed. A few kills are crashes rather than precise assertion failures (the two noted above); they still fail the suite.
Not run (honest limits)
startup_gfx2hlsl_scalar_m0_warp|hardware) need DXC,offscreen_checkand a D3D12 adapter, none on this Linux host. The "zero mismatches on WARP and RX 9070 XT" claim in the docs is therefore not independently reproduced by me.binarymode was run withllvm-mc-19, not the pinnedllvm-mc-15.Unsupportedpaths (e.g. a numeric read of an m0 that holds a pointer). The tests argue the intent is right; a Windows run on the local corpus would confirm.Non-blocking notes (P3)
docs/experiments.md(new section): the paragraph is long and mixes the old defect description, the new behavior and the measured results in four dense sentences; splitting "what changed" from "what was measured" would match the neighbouring sections.TypeError/unhandledUnsupportedinstead of an assertion, so a future regression there would fail the suite with a less readable message.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:08:08Z.
Integrated current
mainand routed the new SMEMm0offset path through the same guarded read as other scalar uses. The scalarm0fixture now passes the SMEM pointer rejection and both BFM operand-position controls together, and the startup translator suite reports zero failures.Imported from R0Y00/Xbox2Windows. Originally posted by consolelogkyo on 2026-11-24T21:10:20Z.
Thank you for catching the
s_bfm_b32self-read ordering (6a41a3e9) and mergingsmem_soffsetthroughself.u(tok)(498dcf58)!Pulled
498dcf58locally and verifiedstartup_gfx2hlsl_scalar_m0_(controls|warp|hardware)andstartup_smem_address_(controls|warp|hardware)— 6/6 passed with 0 mismatches on WARP10.0.26100.9818and AMD Radeon RX 9070 XT32.0.32029.2010(debug_errors=0 debug_warnings=0).AI-assisted.