startup: lower s_bitset0_b64 and s_bitset1_b64 in gfx2hlsl #2897
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2897
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2897"
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?
@R0D4X on GitHub · 2026-11-26 16:55 UTC · original
R0D4X:feat/gfx2hlsl-s-bitset64→main· +469 −0 · 4 files · 1 commits · merged 2026-11-27 06:50 UTCWhat this changes
Adds lowering for the 64-bit scalar bit-clear/set SOP1 instructions
s_bitset0_b64ands_bitset1_b64intools/startup/gfx2hlsl.py(already decoded bytools/disasm_rdna2.py, alongside the existing 32-bits_bitset0/1_b32handlers).S0[5:0]in the destination SGPR pairs[D:D+1]in place without modifyingSCC.null, immediate, or constant-tracked SGPR) update only the targeted 32-bit half and fold when that half is constant. For dynamic SGPR indices that alias the low half (s[D:D+1], sD), the high half is updated first so the index is read before being overwritten.masks/mask_highon either half ofDor onS0), descriptor-bearing SGPRs, VGPRs, odd or out-of-range SGPR pairs, floats,m0, andsrc_scc.Tests added
tests/startup_gfx2hlsl_s_bitset64_check.py: SOP1 binary decode viaG.decode(), 416 pair/index cases,s[4:5], s4ands[4:5], s5aliasing checks, constant folding, uniformity tracking, refusal cases, unlowered control, and FXCps_5_1+ DXCps_6_0GPU readback draws (including a negative-control draw).tests/cmake/startup_gfx2hlsl_s_bitset64.cmakeandtests/checks/python-linux/startup_gfx2hlsl_s_bitset64.txt.Verification
b011dbfa(onupstream/mainb505c32b)10.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17, D3D12 debug layer enabled1414:008c, driver10.0.26100.9818) and NVIDIA GeForce RTX 5080 (10de:2c02, driver32.0.16.2124)Results:
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_bitset64|^startup_tools_lint$' -V-> 4/4 passed, 0 skipped (debug_errors=0 debug_warnings=0on all draws)ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_bitset64'-> 3/3 passed, 0 skippeddocs_links_check.py,bidi_controls_check.py,startup_gfx2hlsl_s_bitset_check.py, scalar/arity/null/refusal checks,git diff --check) -> all passedgfx2hlsl.py(breakings[D:D+1], sDalias order, dropping bit-5 selection, swapping clear/set, droppingmask_highand odd-pair guards) -> 5/5 caught (rc=1)Scope: Covers synthetic gfx1013 SOP1 fixtures translated by
gfx2hlsl.pyand run on WARP and RTX 5080; does not establish full-title startup or frame rate.@thepatrickworld on GitHub · 2026-11-26 19:16 UTC · original
Review note on
b011dbfa: the aliasing section's vectors all miss the aliasing classPure-Python path only (
python3 -B tests/startup_gfx2hlsl_s_bitset64_check.py, CPython 3.11.16, Linux); no GPU run is involved in anything below.The ordering branch, and two mutants it does not see
scalar_bitset64(tools/startup/gfx2hlsl.py:5846) emits the two HLSL assignments in a chosen order when the bit index lives in the low word of the destination pair (tools/startup/gfx2hlsl.py:5904), and the docstring says why: "when S0 aliases the low word of D, the high word is updated first so S0 is read intact". Section 3 of the fixture (tests/startup_gfx2hlsl_s_bitset64_check.py:206-216) is labelled "aliasing s[4:5], s4 and s[4:5], s5 preserve original index".Two one-line mutants, both of which leave the whole fixture green (77 checks, exit 0):
Both values come from evaluating the emitted statements through the fixture's own
run_lines(), and all 28 alias comparisons of section 3 agree with the reference under each mutant.Why the 28 vectors miss it
For M-a the separating class is narrow: the low write only happens when index bit 5 is clear, and it can only take bit 5 of the low word from 0 to 1 when
index & 31 == 5, with bit 5 still clear in the high word - so only the set form with the source aliasing the low word separates (s4 = 5, s5 = 0). For M-b the mirror holds: only the clear form with the source aliasing the high word separates (s4 = 0x20, s5 = 0x25). In the current list(5, 0x12345678)has bit 5 set inhi(0x78 & 0x20), and the remaining pairs have index bit 5 set orindex & 31 != 5; none is in either class.Minimal addition
One pair per direction, in the section 3 loop:
(5, 0)for the low-word alias and(0x20, 0x25)for the high-word alias. Measured on a temporary copy of the fixture: with(5, 0)added, M-a fails withaliasing s[4:5], s4 and s[4:5], s5 preserve original index: MISMATCH(exit 1) while the unmutated head still exits 0; with(0x20, 0x25)added, M-b does the same. Asserting the emitted order directly (stage.lines[0].startswith('s5 =')for thes4form) would pin the mechanism rather than two values, if you prefer that.Worth noting: the pixel_aot fixture already pins this pattern for the other lowering -
tests/pixel_aot_check.py:6367-6380buildss_bitset1_b64 s[44:45], s44withlo=5, hi=0x11111111and encodes the read-after-write result(5, 0x11111131)as the expected mismatch. The startup handler added here has no equivalent.Section 9's two lines (
tests/startup_gfx2hlsl_s_bitset64_check.py:314and:316) compareref_bitset64to itself and never callStage, so the "mutation" labels announce a control that does not run; the grid does the real work - of ten mutants I applied toscalar_bitset64, eight are killed (5-bit index masking in both index paths, dropped bit-5 word selection, unmasked fold shift, inverted word selection, 63-bit dynamic mask, clear/set swap, removed pair-alignment guard), and the aliasing order plus the post-write lane-mask discard survive.What this does not say
Not a claim that the lowering is wrong: on
b011dbfathe 416-case grid, the 28 alias comparisons and four further alias probes all match the reference, and the mutants are mine. The draw entries cannot see the ordering either - the synthetic pixel program passess6as the index for both instructions - and I did not run the draw mode here (no DXC, no GPU on this host).AI-assisted.
@thepatrickworld on GitHub · 2026-11-26 19:46 UTC · original
Independent AMD (RDNA 4) result on
b011dbfa— Not a code change; measurements only.Environment
debug_layer=unavailableon this machine.b011dbfa7e640c4b26af80bc1b44a0b2950b016e, as recorded bygit rev-parse HEADin the run's environment block.ctest -N→Total Tests: 2445, including#2420controls,#2421warp,#2422hardware. The test command takes its interpreter from this machine'sx2w-pr641/out/pe-env; the fixture imports the translator from its own tree, so the lowering under test is the one atb011dbfa.Commands
Observed
100% tests passed out of 3— controls 0.57 s, warp 4.34 s, hardware 6.20 s — and noSKIPline anywhere.On the card, 16
startup_flat_param words=readback lines: 7 vectors × 2 compilers (fxcps_5_1, dxcps_6_0) plus 2 negative controls, which re-drawlo_bit0with a deliberately wrong expected list. The 14 positive readbacks equal the list the fixture printed for that vector; the renderer compares bymemcmp(tests/offscreen_check.cpp:1557) and the fixture raises on any non-zero exit, so a mismatch would have printedexpected=… actual=…— the log has none. Both negative controls draw, print their readback, then exit 1 (failmaps to 1,skipto 77 —tests/offscreen_check.cpp:1968), and the readback line is printed before the comparison (tests/startup_flat_param.cpp:126), so the compare is the only step after it.The two vectors above a 63 index, identical from both compilers:
What this draw measures, and what it does not
Every operand of these draws is a literal in the emitted HLSL —
s6 = 0x00000040u; s6 = 0x00000040u ^ 0x00000000u;— and each half is a literal ternary:s4 = ((s6 & 32u) == 0u ? (0x00000001u & ~(1u << (s6 & 31u))) : 0x00000001u);. The translator folds that XOR itself, so clearing its const symbol never produced a runtime operand.Recompiling the same emitted HLSL through the fixture's own
compile_hlsl()(identical flags by construction; a fresh.cso, not the one the draw consumed):dxc folds even at
-Od, which points at constant evaluation rather than the optimising passes. fxc folds only when optimising — the same shader at/Odkeepsnot/and/or/xoron literals. Either way, no runtime operand reaches the adapter. (fxc prints six decimals in a listing, so1.000004is not a bit-exact quote — the words themselves are the readback lines above.)So the draw pins the emitted expression — a wrong half select (
s6 >= 32ufors6 & 32u) folds to a different word forwrap_64, the only one of the seven that separates it, sincewrap_101satisfies both predicates — and that the four words survive transport. It never exercises the ternary at runtime, so_warpvs_hardwaresays nothing about the lowering here; what it can still separate is a broken export or readback.If a runtime measurement is wanted, the renderer side already exists:
run_startup_flat_paramtakes the four entry constants as an optional extra argument (tests/offscreen_check.cpp:1552,entry_constantsintests/startup_flat_param.cpp:22), and the translator already emitscbuffer entry : register(b0)when a pipeline declares them (tools/startup/gfx2hlsl.py:10503). The sibling fixture uses exactly that path for its two operands (tests/startup_gfx2hlsl_bfm_b64_check.py:565-569, checked at:584). The missing half is on the fixture side: the index would have to arrive through a scalar load from that buffer instead of a literalsop1_mov_lit, and a root constant is opaque to both compilers, so the(s6 & 32u)ternary would then really execute on the GPU.Regression
The controls entry prints 77
: oklines, the last being the fixture's own summary — 76 individual checks. Each draw entry prints 79 = 76 + the 2 negative controls + summary; the 76 are the pure-Python controls, re-executed in all three entries. 0 fail, 0 skip.Limits
lo_bit0,wrap_64,wrap_101) and 2 of 7 at/Od, where the two compilers behave differently.s[4:5]indexed bys6, sos[D:D+1], sDaliasing is not exercised; thealiasing … okline in this log is the pure-Python control from my earlier note.wrap_64's readback is byte-identical tolo_bit0's: its value is against the half-select mutant, not as a new word.gfx1013bytes only; nothing about startup throughput.AI-assisted.
@R0Y00 on GitHub · 2026-11-27 06:49 UTC · original · approved these changes
Independent review of
b011dbfaintegrated withmain2917babc(cb5f6a10locally). The six-bit index selects a single half and both operations preserve SCC, consistent with AMD RDNA 2 ISA, Table 14. The dynamic alias order keeps the scalar index live until the opposite half has been processed.I rebuilt
offscreen_checkand ranctest --preset <dev|release> --no-tests=error -R '^startup_gfx2hlsl_s_bitset64_(controls|warp|hardware)$'. Debug and Release/O2each passed 3/3 without skips. The draw suite exercised FXC and DXC, including wrong-expectation controls on both adapters. The neighboringpython -B tests/startup_gfx2hlsl_s_bitset_check.pyalso passed. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656 and WARP 10.0.26100.9818, with the debug layer enabled. Hosted Windows, Linux Python and gfx1013 checks passed. The hosted/O2job skipped and the local/O2retest passed.