startup: lower s_bfm_b64 in gfx2hlsl #2000
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2007"
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 JB2WIN on 2026-11-24T22:58:27Z.
Refs #1723
Change
tools/startup/gfx2hlsl.pynow lowerss_bfm_b64. It is one of the refusals in the #1723 census (1 pair).D.u64 = ((1ULL << S0.u[5:0]) - 1) << S1.u[5:0]. The entry lists no SCC write; the bit operations next to it do list one. The existings_bfm_b32entry and thepixel_aotreference also leave SCC unchanged, so the handler emits noscc.s_and_b64and the others) keep only a lane bit and a zero high word.s_bfm_b64produces a real 64-bit value, so the newStage.op_s_bfm_b64writes both wordss[d]ands[d+1]. It uses the preamble'sshl64helper, asv_lshlrev_b64does.shl64masks the offset and cuts at bit 63. A width of 32 or more gives the low word0xffffffffand the high word(1u << (w & 31u)) - 1u. A width of 0 gives 0. No emitted shift count is 32 or more.exec/vccor descriptor sources.Test
New device-free check
tests/startup_gfx2hlsl_bfm_b64_check.py, registered asstartup_gfx2hlsl_bfm_b64and listed in the pure-Python job andAGENTS.md.shl64from the preamble and compares the result with an independent bit-loop reference.[5:0]that must be ignored, inline and literal sources, constant folding and destination equal to source. The check also asserts that no shift count reaches 32.& 31instead of& 63, a 5-bit offset, and width 0 giving all ones.main: withmain'sgfx2hlsl.pythe check fails withUnsupported: s_bfm_b64.Results on
1ebfe511plus this commit:ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl'passed 41/41.tests/startup_translator_check.pyandtests/docs_links_check.pypass.The check evaluates the emitted HLSL in Python. It does not compile it or draw with it.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:08:44Z.
Ran it, broke it five ways — all caught — and checked the emitted formula against the ISA expression
Windows 11 build 26300.9974, device-free:
bw >= 32u→bw > 32u(the exactly-32 boundary)(1u << (bw & 31u))→(bw & 63u)(a shift count of 32 or more)s[d] = t.x; s[d+1] = t.ywritten the other way rounduint bw = width & 63u→ no mask (a width above 63)shl64pre-masked in a different wayYour two controls and the first two of my mutations fail in the same place — the width boundary at 32 and the six-bit masking — which is a good sign that the check knows what can go wrong rather than merely comparing text.
The arithmetic, checked exhaustively
I reimplemented the emitted expression (mask split into two words,
shl64masking the offset to six bits) and compared it with((1ULL << S0.u[5:0]) - 1) << S1.u[5:0]over every(width, offset)pair:and that a width outside the six-bit field behaves exactly like its masked value, as the ISA says it must:
So the two-word split at
bw >= 32u, the(1u << (bw & 31u)) - 1uhigh word, and the0high word below 32 all hold together.Two details worth keeping in the description
dst[1] % 2anddst[2] > 105are the right refusals, not merely "is it an SGPR pair": a 64-bit scalar destination must be even-aligned in the file, and 105 is the last usable high word. A reviewer who had not read your diff would expect alignment to be enforced byreg_rangeand would be wrong.self.sym.pop(d)before emitting, with the comment that a source may be the destination, is the subtle half.s_bfm_b64 s0, s0, s1readss0and writess0/s1through locals, so the emitted block is correct only because both words are computed before either store. That sentence is doing real work.What I could not check
SCC being unchanged is argued from the ISA PDF entry, the neighbouring
s_bfm_b32entry andpixel_aot. I do not have the PDF, so I can only say the reasoning is consistent with the code — the handler emits nosccwrite, and my mutations did not disturb that.Scope
Text and arithmetic; no shader was compiled or run. Constant folding is covered by your fixture, not by my probes.
Verdict
Reviewed. Five independent breakages, five failures, and the formula agrees with the ISA expression on all 4,096 inputs.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:12:43Z.
Two open PRs lower
s_bfm_b64— #2003 and #2007 — and they conflict on three filesNot a problem with your patch; a coordination note so the effort is not spent twice. Checked against
main7f149ac9:Both add a fixture with the same filename, so whichever lands second has to be rewritten rather than rebased.
Where the two implementations differ
The semantics agree (
D.u64 = ((1ULL << S0[5:0]) - 1) << S1[5:0], SCC untouched, both words written). The differences are in what is refused:dst[2] != dst[1] + 1anddst[2] > 105dst[1] % 2reg_rangemaps tosexec/vccand any ranger[1] != r[2]Two of those matter:
dst[1] % 2— a 64-bit scalar destination must be even-aligned in the register file. #2007 enforces it; #2003 does not, sos_bfm_b64 s[3:4], …would be accepted. That is the one substantive difference I would not want to lose.exec/vccas sources — #2007 refuses them by name, #2003 accepts them through the genericspath. Whether that is right depends on whether the ISA allows a 64-bit pair spelling here; worth agreeing on rather than leaving to merge order.What I would suggest
Keep #2007's
dst[1] % 2and its explicit source refusal, and take #2003's split modifier/operand messages if you prefer them — then close the other, since neither check can be reused as is.I have already reviewed #2007 at the behaviour level (five mutations, all caught, plus an exhaustive check of the emitted expression against the ISA formula over all 4,096
(width, offset)pairs). I have not reviewed #2003.The same duplication exists for
v_swap_b32(#1995 and #2012), so this looks like a pattern worth a one-line note inCONTRIBUTING.md— "check open PRs for the mnemonic before starting" — rather than something either author did wrong.Notes
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:31:15Z.
Please prefer this single implementation and coordinate the overlap with #2003. Before overwriting either destination word, reject a source SGPR tracked in Stage.masks. The current code drops the destination’s mask flag before reading its numeric sources, so aliases can bypass even a later check. Add a compare-derived scalar mask, with and without destination aliasing, as a refusal control. After rebasing on #1931, also prove or invalidate the uniformity of both written words and check that readfirstlane cannot consume a stale proof.
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T00:11:40Z.
Rebased on
b12df353, which includes #1931, and pushed as9d0eb2c4:op_s_bfm_b64now reads both sources and checks them againstStage.masksbefore it touches the destination. A mask source raisesUnsupportedbefore any mask flag,sym,varying_s,used_sor HLSL changes. Theself.u()expressions are also computed before any write.uniform_source()before the write, so aliasing sees the old value. Both written words are proven uniform together (theirvarying_sentries cleared) when both sources are uniform; otherwise both are marked varying. Before, the runtime path left a stale proof in place. Constant folding still goes throughset_s.v_cmp-derived mask as width, offset or both, with and without destination aliasing. Each one also asserts that HLSL,sym,masks,varying_sandused_sare unchanged.v_readfirstlane_b32case for both words.exec), andv_readfirstlane_b32must refuse. A later uniform write restores the proof.s[d+1]fails the three stale-proof cases.tests/startup_gfx2hlsl_*_check.py,startup_translator_check.pyanddocs_links_check.pypass, andctest --preset dev --no-tests=error -R '^startup_gfx2hlsl'passes 46/46.The overlap with #2003 is in the thread there.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:01:44Z.
Review: COMMENTED
Review of head
9d0eb2c41bafb99201e0a7bc9d824126b7fea5f3(comment only, no approval).Verdict: no blockers found. One P2 and one nit.
Checked
D.u64 = ((1<<S0[5:0]) - 1) << S1[5:0], no SCC write. This matches thes_bfm_b32handler next to it. Width >= 32 gives low word0xffffffffand high word(1u << (w & 31)) - 1. No emitted shift count is 32 or more. Width 63 gives0x7fffffffin the high word, which is correct. Width 64 masks to 0, which gives 0.op_s_bfm_b64matches the run-time path.startup_gfx2hlsl_bfm_b64),windows.ymlandAGENTS.md. Title is neutral and the diff is clean-room.Commands run locally on the PR head
python3 tests/startup_gfx2hlsl_bfm_b64_check.py: PASSpython3 tests/docs_links_check.py: 18 files, 393 links OKpython3 tests/bidi_controls_check.py: OKgit diff --check origin/main...HEAD: cleanMutations of the new logic (each reverted with
git checkout -- .)0xffffffffuchanged to0xfffffffeu: the test fails (killed).bw = width & 63uchanged to& 31u: the test fails (killed).self.masks.discard(d + 1): the test still passes (survived).Findings
shl64,bw >= 32u ? ... : ...anduint2is only covered indirectly. Please add a WARP readback on a Win2025 host (for example widths 0, 1, 31, 32, 33, 63 and offsets 0, 1, 31, 32, 63) and put the result in the PR body. I did not run Windows here. The Windows CI job only builds and runs the existing tests.self.masks.discard(d + 1). Add a case wheres[d+1]was a lane mask before the write and is read as a number after it.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:53:46Z.
Review: COMMENTED
Review of head
283f03ead8d7862aaaa76980ef14f082b2f8166d(s_bfm_b64 lowering in gfx2hlsl).Summary: No P1 or P2 findings. The lowering matches the ISA definition
D.u64 = ((1ULL << S0.u[5:0]) - 1) << S1.u[5:0], SCC unchanged.Checked
(1<<(w&31))-1. Width 32 gives high 0 and width 0 gives 0, so both edges are right. The offset goes throughshl64, which drops bits past bit 63. Every HLSL shift count stays below 32.windows.ymlandAGENTS.mdare all updated. The optional--startup-flat-paramconstants argument is bounds-checked (6..7 args, 4 hex words).Commands run locally on the worktree
python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py-> PASS (all controls and 3 built-in mutations caught)python3 -B tests/startup_gfx2hlsl_sopk_accum_check.py(sibling) -> PASSpython3 tests/docs_links_check.py-> OK (18 files, 401 links)python3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> cleanbw >= 32uchanged tobw > 32uin the emitted HLSL -> the test fails (rc=1, mismatch at width 32). Killed.& 63uchanged to& 31uon the width -> caught ("width masked with 31").git checkout -- ..Nits (non-blocking)
foreachblock says "review of #2007", which refers to the PR itself. Prefer describing the behaviour.s_bf*ops follow.Windows proof: I did not run a separate Win2025 job. The PR's own Windows CI is green and the draw test runs on WARP and hardware adapters. A fresh Win2025 WARP readback is still advisable before merge, if not already done for this exact head.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T02:48:57Z.
@tedin7, both points are addressed in
283f03ea(rebased on498c23cc).WARP and hardware readback. New
startup_gfx2hlsl_bfm_b64_warpand_hardwaretests run a draw mode. Width and offset arrive as run-time root constants, so the translator cannot fold them. Each draw evaluates the pair and the swapped pair, and all four words are read back through the uint target and compared with the bit-loop reference.debug_errors=0)ps_5_1, DXCps_6_0d3d10warp.dll10.0.26100.9818ps_5_1, DXCps_6_0Windows 11 build 26200, Windows SDK 10.0.26100.0 compilers.
[5:0](64/0, 0x41/0xc1, 0xffffffa1/3, 5/0xffffff9f).ffffffff,0,ffffffff,0andffffffe0,1f,1f,0.gfx2hlsl.pyis unchanged.offscreen_check --startup-flat-paramnow optionally takes the four entry constants. Without the argument they stay 0, so existing callers are unchanged.Nit. New case:
s21is a lane mask fromv_cmp, thens_bfm_b64 s[20:21]overwrites it, thens21is read as a number. This is accepted and gives the reference high word. Readings21while it is still a mask is refused. A mutation that dropsself.masks.discard(d + 1)makes the check fail.ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl'passed 66/66 with no skips, and all 43 pure checks pass.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:15Z.
@JB2WIN could you rebase this branch onto current
mainand force-push?GitHub reports head
283f03eaas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):AGENTS.mdCMakeLists.txttests/desktop_gpu.htests/offscreen_check.cpptests/startup_flat_param.cppCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T18:32:09Z.
Independent verification requested after the rebase. In the saved-profile comparison at
a6c8d80d, one previously translated graphics pipeline reached thes_bfm_b64refusal with the current startup translator. This gives the existing patch a concrete follow-up under #870.The author's next step is the rebase already requested above. An independent reviewer can claim the WARP/hardware rerun here now. Once the new head is posted, record its commit and run
ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_bfm_b64($|_(warp|hardware)$)' -Vfrom a Release build with the relevant fixtures built. Report the readback for both words, the negative-control result, adapter and driver, and any skips. Main development will recheck the affected translation once the patch lands.Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-25T19:15:26Z.
I’ll take the independent Release rerun requested above once the rebased head is up. I’ll use Windows 11 x64 build 26300.10075 with WARP and an RTX 4070 and report both destination words, the readback controls, and any skips.
Pre-rebase baseline at
283f03ead8d7862aaaa76980ef14f082b2f8166d: 3/3 CTests passed with no skips on in-box WARP 10.0.26100.10068 and RTX 4070 driver 32.0.16.2124. Both FXC and DXC matched the reference, including width 33 and offset 31 (80000000,fffffffffor the first pair and00000000,fffffffefor the swapped pair). Both negative controls rejected the intentionally wrong results. A direct DXC replay of that pair reported the debug layer enabled, with zero warnings or errors, on both adapters.I’ll repeat this on the new head.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T20:03:11Z.
The branch now includes the mainline conflict repair at
db5f84fe. Both mask words use the current scalar-uniformity bookkeeping. The renderer keeps the optional four entry constants and the newer culling/winding operation. My Windows Release run passed 8/8 for BFM, flat parameter and nearby translator cases, plus 2/2 raster winding cases. The BFM draws checked both mask pairs with FXC and DXC on WARP and RTX 4060 Laptop, including the uncapped-reference and width-zero mutation controls. @RonLogic, this is the candidate for your independent rerun. The #870 executable retry is separate.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:07:35Z.
Review: COMMENTED
Review of head
db5f84fe(comment only, Linux checks; no Windows run by me).Code (
tools/startup/gfx2hlsl.py,op_s_bfm_b64): matches the ISA expression. Width masked to 6 bits, offset handled inshl64, no emitted shift count of 32 or more. Both sources are read and checked againstStage.masksbefore either destination word changes, which covers the earlier request. Modifiers, operand count, odd or out-of-range destination pair, exec/vcc and descriptor sources are refused. Uniformity is recorded for both words from the old source state.Checked locally on the exact head:
python3 -B tests/startup_gfx2hlsl_bfm_b64_check.py: PASSpython3 tests/docs_links_check.py: passpython3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: clean& 63uon the width -> check exits 1 (caught)bw >= 32uchanged tobw >= 33u-> check exits 1 (caught)Care items: the
.github/workflows/windows.ymlchange is one line and must be exercised by this PR's own CI run. Theoffscreen_check/startup_flat_paramedits are small and sit next to the new WARP/hardware cases.Not covered by me: WARP/hardware readback (an independent Release rerun is already claimed above by @RonLogic) and anything about the startup path under #870. Because the PR is tied to the #870 saved-profile follow-up, the merge stays with @R0Y00 / MasterDomino, who can verify on the real executable. I am not merging it.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T01:43:41Z.
Measurement, on a local capture (counts and instruction shape only), at main
7287979: 195 requests stop ats_bfm_b64, the largest refusal aftersrc_sccoperands, the slot 57 execz block, a livevccin an execz block,v_readfirstlane_b32and register-offsets_loadthrough the resource heap. Another 25 stop ats_bfm_b64right after the 64-bit literal of #2039. I measured that with main's translator plus an in-memory wrap that accepts that literal; I did not run either branch.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-26T03:39:58Z.
@JB2WIN, @R0Y00: this conflicts with
mainagain, and with 195 requests stopping ats_bfm_b64(Leyukaka above) it is worth landing. I merged currentmaininto the PR head, as a merge commit on top ofdb5f84fe, so the branch can fast-forward to it without a force-push:https://github.com/Ybucaille/Xbox2Windows/tree/startup/gfx2hlsl-bfm-b64-merge (
a73b60f8)AGENTS.md(thebfm_b64andmask_datalines),CMakeLists.txt(thebfm_b64warp/hardware draw block now has its ownforeach/endforeach, next tomain's int_alu, cndmask_abs and cube blocks),tests/desktop_gpu.handtests/offscreen_check.cpp(the PR's optionalconstantsargument of--startup-flat-paramalongsidemain's--startup-entry-words).gfx2hlsl.py,startup_flat_param.cppandwindows.ymlmerged cleanly.uniform_source,record_scalar_uniformity,set_s,maskskeep their signatures onmain; the handler still refuses mask sources before any write, somain's newreject_lane_mask_dataadds nothing here.startup_gfx2hlsl_bfm_b64_check.pyexit 0; dropping& 63uon the width makes it exit 1. The other 117startup_gfx2hlsl_*/ flat-param / translator / docs checks give the same results as onmain(two draw checks fail on both without Windows tools).AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:48:25Z.
Review: APPROVED
I verified the contributor merge is a fast-forward from the previous PR head. On its combination with main, the Release offscreen suite passed 11/11 on WARP and RTX 4060 Laptop, including the all-width/all-offset static grid, both DWORD outputs in FXC and DXC, the width and offset mutations, and the adjacent integer/negative-zero/culling checks. The newer main diff is the independent gather diagnostic. This verifies the source-built instruction lowering; the local refusal census is separate.
Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-26T04:43:48Z.
Thanks @Ybucaille. I checked
a73b60f8and fast-forwarded the branch to it (db5f84fe..a73b60f8, no force-push).Windows run at
a73b60f8, which still merges cleanly into current main (418f9245, checked withgit merge-tree):ctest --preset release --no-tests=error -R "bfm|flat_param|startup_stubs$" -V: 11/11 passed, 0 skippedstartup_gfx2hlsl_bfm_b64,startup_gfx2hlsl_bfm_b64_warp,startup_gfx2hlsl_bfm_b64_hardwarestartup_flat_param_controls,startup_flat_param_warp,startup_flat_param_hardwarecompute_store_aot_alu_bfm_warp/_hardware,pixel_aot_bfm_warp/_hardware,startup_stubsThis covers the compile of the merged C++ and the WARP and hardware draws that were not run before. Refs #2618.
AI-assisted (Claude Code); the commands above were executed locally.