startup: guard and verify 64-bit VOP3 shifts in gfx2hlsl #1776
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1783"
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 R0D4X on 2026-11-24T18:34:47Z.
Refs #1723
Summary
Scoped follow-up on top of #1818 (
shl64,shr64u,shr64ialready landed onmain), carrying forward the binary round-trip, partial-overlap,exec-masked, WARP/hardware draw, and malformed-operand coverage without duplicating the shift helpers:tools/startup/gfx2hlsl.py):i64_words(): enforce architectural pair bounds (vup tov255, even-alignedsup tos105) and refuse malformed decimal tokens.shift64(): enforce exact operand count (len(ops) == 3), architectural destination bound (dst[2] <= 255), valid 32-bit shift amount (ops[1]not a register pair, withinv255/s105, notvcc/execor a float inline constant), and invalidateuniform_vfor both overwritten destination VGPRs.shl64/shr64u/shr64ihelpers and{ uint2 t = ...; vX = t.x; vY = t.y; }emission untouched (startup_gfx2hlsl_b64_shiftstays green).tests/startup_gfx2hlsl_shift64_check.py):shl64,shr64u,shr64i) against an independent 64-bit Python reference across 648(lo, hi, amount)cases per op (1,944 total, covering all shifts0..63plus wrapped counts>= 64), static shift-count< 32checks, partial-overlap corruption controls (v[3:4] <- v[2:3]), inline sign-extension (-1,1),exec-masked emission,uniform_vinvalidation, pointer-SGPR-pair refusal, and 37 malformed-operand/modifier/count refusals.binary <llvm-mc>round-trip verification of all fixture encodings for the Ubuntupixel-binaryCI job.draw <dxc> <offscreen_check> <warp|hardware> [fxc]end-to-end FXCps_5_1+ DXCps_6_0offscreen readbacks covering both disjoint (v[12:13]) and partially overlapping (v[3:4] <- v[2:3]) shifts across boundary shift counts (0, 1, 31, 32, 33, 63, 64, 0xffffffc1), plus per-op GPU mutation controls (dropped cross-word carry forshl64/shr64u, logical shift forshr64i).CMakeLists.txt,.github/workflows/windows.yml): registerstartup_gfx2hlsl_shift64_{controls,warp,hardware}and addtests/startup_gfx2hlsl_shift64_check.pytopixel-binary(binary llvm-mc-15) andpython-linux.Verification
df40e4bc(upstream/main, includes #1818)10.0.26300.9974), MSVC19.44.35230, Windows SDK10.0.26100.0, FXC + DXC1.9.2602.17Microsoft Basic Render Driver(1414:008c), driver10.0.26100.9818, D3D12 debug layer enabledNVIDIA GeForce RTX 5080(10de:2c02), driver32.0.16.2124, D3D12 debug layer enabledCommands and Observed Results
startup_gfx2hlsl_b64_shift_check.py: PASS;startup_gfx2hlsl_shift64_check.py: 1,944 helper evaluations, 3 draw-0 mutations, 3 partial-overlap controls,uniform_vinvalidation, 38 refusals ok;startup_gfx2hlsl_operand_count_check.py:0 failed;docs_links_check.py: 18 files / 376 links ok;bidi_controls_check.py: 1326 files ok).startup_gfx2hlsl_b64_shift: passed (0.09 s)startup_gfx2hlsl_shift64_controls: passed (0.13 s)startup_gfx2hlsl_shift64_warp: passed (2.09 s), FXCps_5_1and DXCps_6_0matched all 12 draws per compiler and rejected all 3 deliberate mutations with exact expected mutated words,debug_errors=0 debug_warnings=0.startup_gfx2hlsl_shift64_hardware: passed (7.91 s) onNVIDIA GeForce RTX 5080(driver32.0.16.2124, D3D12 debug layer enabled), identical readbacks and mutation failures for FXCps_5_1and DXCps_6_0,debug_errors=0 debug_warnings=0.Observed: 4 passed, 0 skipped, 0 failed (9.61 s:
b64_shift0.09 s,controls0.13 s,warp1.93 s,hardware7.43 s).Note:
tests/startup_gfx2hlsl_shift64_check.py binary llvm-mc-15was not run locally (llvm-mcis not installed on this Windows host); fixture words were cross-checked againsttools/disasm_rdna2.py/gfx2hlsl.decode()and are exercised by the Ubuntupixel-binaryCI job.Scope note: these passing fixtures verify 64-bit shift guards, helper semantics, and desktop GPU execution in isolation; they do not establish full-game startup.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:56:40Z.
Review: COMMENTED
Peer review of head
e899a9bd373c591652da3052afdac78df6b73fef(PRODUCTION_REVIEW_ONLY, technical comment only).Result: no P1/P2 defects found in the local verification.
Checked by reading the diff and the surrounding translator code:
lshl_b64,lshr_b64,ashr_i64(tools/startup/gfx2hlsl.py): the shift amount is masked to 6 bits. Thesb == 0carry case is guarded, so there is no>> 32undefined shift. The>= 32branch is correct for all three (zero fill for the logical ones, sign fill for the arithmetic one).r64temporary is written once and then split into both destination registers. A partial overlap such asv[3:4] <- v[2:3]therefore reads the sources before either destination is written.vcc/execpairs, float-inline shift amounts, and 64-bit inline constants outside -16..64. These are rejected asUnsupported, not mis-lowered.Non-blocking note: the PR is
CONFLICTINGagainst currentmain(58de1589).git merge-treereports content conflicts in.github/workflows/windows.ymlandCMakeLists.txt(adjacent test registrations).tools/startup/gfx2hlsl.pymerges cleanly. A rebase is needed before merge. The technical review above is against the PR head.Local mutations (Linux, then restored with
git checkout -- .):uint2(ah, sf)->uint2(ah, 0u)inashr_i64:startup_gfx2hlsl_shift64_check.pyfails with "v_ashrrev_i64: emitted helper matches reference on 648 cases".sh < 32u->sh <= 32uinlshl_b64: the same check fails with "v_lshlrev_b64: emitted helper matches reference on 648 cases".Commands run:
git diff --check <merge-base>...HEAD: cleantests/bidi_controls_check.py: passtests/startup_gfx2hlsl_shift64_check.py: passtests/startup_gfx2hlsl_operand_count_check.py,tests/startup_gfx2hlsl_bit_alu_check.py,tests/startup_translator_check.py: passe899a9bd, targetsoffscreen_check, regexstartup_gfx2hlsl_shift64_controls|_warp|startup_translator, py-checkstartup_gfx2hlsl_shift64_check.py:--preset dev): 3/3 tests passed/O2(--preset release): 3/3 tests passed*_hardwaretests were not run (the VM exposes WARP only).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:56:31Z.
#1818 is now on main with the three shift helpers. This branch still has distinct value in its binary round-trip, partial-overlap and masked-write checks, exact WARP/hardware draws, and malformed operand controls. Please carry those forward on main using the landed helpers. Keep a small production guard where a control finds a real gap, for example a register pair extending beyond the architectural range. Avoid carrying a second helper implementation. The scoped follow-up can keep your commits and evidence here.
[PR #1783] startup: lower 64-bit VOP3 shifts in gfx2hlslto [PR #1783] startup: guard and verify 64-bit VOP3 shifts in gfx2hlslImported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:07:06Z.
Review: COMMENTED
Re-review of head
2857ddc4c40710468c8fd367397be6bdb602bfe5(startup: guard and verify 64-bit VOP3 shifts in gfx2hlsl), checked out at exactly that SHA. Verdict: no P1, no P2. The earlier findings are closed.What the branch is now
After #1818 landed, this branch no longer adds helpers: the diff against current
origin/mainis 18 lines intools/startup/gfx2hlsl.py(guards), the 389-linetests/startup_gfx2hlsl_shift64_check.py, three CMake registrations and twowindows.ymlentries. That follows the maintainer's request to carry the checks forward without a second helper implementation.Earlier findings
e899a9bd): the only open point wasCONFLICTINGagainst main.git merge-tree --write-tree HEAD origin/mainnow reports 0 conflicts.shift64did not clearuniform_vfor the destination pair, so a laterv_readfirstlane_b32could accept a register that now holds a lane-varying shift result. This head addsself.uniform_v.discard(dst[1])anddiscard(dst[2]), and the test64-bit shift invalidates uniform_v for both destination registerschecks it. Closed.What I checked in the guards
i64_words: VGPR pairs must end at or belowv255; SGPR pairs must start even and end at or belows105; the inline integer regex is now0|-?[1-9]\d*within -16..64, so spellings like-0,00or+1are refused; everything else (literals, floats,vcc,exec, other ranges) raisesUnsupported.shift64: exactly three operands; destination pair a VGPR pair ending at or belowv255; the shift amount is a single register in range (not a pair), notvcc/exec, not a float inline constant. A float inline constant as a count is refused although the hardware would use its raw bits; that is conservative, not wrong.v[3:4] <- v[2:3]).Commands run (Linux, exactly
2857ddc4)Mutations of tools/startup/gfx2hlsl.py (each restored;
git statusclean)uniform_v.discardcalls removed64-bit shift invalidates uniform_v)dst[2] > 255) droppedvcc/exec/float shift-count guard droppedIndexError, an error rather than a refusal, so the guard is exercised)P3
startup_gfx2hlsl_shift64_{warp,hardware}draws and thebinarymode (llvm-mc-15) were not run here.Limits
No
dxc/fxc, renderer orllvm-mcon this host, so the draw and binary-round-trip parts of the test were not run, and the generated HLSL was not compiled. Those need the Windows CI job. The PR changes no C++.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T20:16:21Z.
Ran the new check, then broke each guard it claims
At the PR head, device-free:
Four mutations to the guards this PR adds, each reverted; the new check goes red for every one while the landed
b64_shiftcheck stays green (so the mutations are specific to the new coverage, not to the shared lowering):
shift64_checkb64_shift_checki64_words: drop the even-alignment requirement on an SGPR pairi64_words: widen the inline range-16..64→-64..128shift64: destination no longer has to be a pairshift64:uniform_v.discard(dst[2])→pass(only the low half invalidated)The last one is the one I would have expected to slip through: forgetting to invalidate the high half of a written pair is a
classic uniform-tracking bug that produces a wrong
v_readfirstlanemuch later. The fixture catches it, so the 37 refusalcases plus the targeted checks are doing real work rather than restating the emission.
Scope of what I checked
I mutated the four guards; I did not re-derive the 389-line fixture's binary round-trip or its WARP/hardware draw modes —
those need LLVM and a GPU and are described in the PR as unchanged from #1818. My run covers the device-free controls only,
which is why the table above is about guards and not about emitted HLSL text.
Small thing
i64_wordsrefuses a decimal token outside-16..64, and the comment does not say where those bounds come from. A readerreaching line 1016 will want one clause — the reasoning is presumably "the disassembler prints inline constants in this
range for a 64-bit source", which is worth stating next to the numbers.
Verdict
Reviewed. Every guard the description lists is pinned by the new check, and the shared lowering is untouched (the second
column is the control for that). No objections.
Notes