Skip to content

startup: guard and verify 64-bit VOP3 shifts in gfx2hlsl - #1783

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
R0D4X:fix/issue-1723-gfx2hlsl-shift64
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
R0D4X:fix/issue-1723-gfx2hlsl-shift64

Conversation

@R0D4X

@R0D4X R0D4X commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1723

Summary

Scoped follow-up on top of #1818 (shl64, shr64u, shr64i already landed on main), carrying forward the binary round-trip, partial-overlap, exec-masked, WARP/hardware draw, and malformed-operand coverage without duplicating the shift helpers:

  • Targeted production guards (tools/startup/gfx2hlsl.py):
    • i64_words(): enforce architectural pair bounds (v up to v255, even-aligned s up to s105) 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, within v255/s105, not vcc/exec or a float inline constant), and invalidate uniform_v for both overwritten destination VGPRs.
    • Keeps the landed shl64 / shr64u / shr64i helpers and { uint2 t = ...; vX = t.x; vY = t.y; } emission untouched (startup_gfx2hlsl_b64_shift stays green).
  • End-to-end verification (tests/startup_gfx2hlsl_shift64_check.py):
    • Pure-Python verification of all three landed helpers (shl64, shr64u, shr64i) against an independent 64-bit Python reference across 648 (lo, hi, amount) cases per op (1,944 total, covering all shifts 0..63 plus wrapped counts >= 64), static shift-count < 32 checks, partial-overlap corruption controls (v[3:4] <- v[2:3]), inline sign-extension (-1, 1), exec-masked emission, uniform_v invalidation, pointer-SGPR-pair refusal, and 37 malformed-operand/modifier/count refusals.
    • binary <llvm-mc> round-trip verification of all fixture encodings for the Ubuntu pixel-binary CI job.
    • draw <dxc> <offscreen_check> <warp|hardware> [fxc] end-to-end FXC ps_5_1 + DXC ps_6_0 offscreen 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 for shl64/shr64u, logical shift for shr64i).
  • CMake & CI wiring (CMakeLists.txt, .github/workflows/windows.yml): register startup_gfx2hlsl_shift64_{controls,warp,hardware} and add tests/startup_gfx2hlsl_shift64_check.py to pixel-binary (binary llvm-mc-15) and python-linux.

Verification

  • Base commit: df40e4bc (upstream/main, includes startup: lower the 64-bit vector shifts #1818)
  • Host environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + DXC 1.9.2602.17
  • WARP: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.9818, D3D12 debug layer enabled
  • Hardware GPU: NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2124, D3D12 debug layer enabled

Commands and Observed Results

.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_b64_shift_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_shift64_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_operand_count_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_translator_check.py
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
  • Observed: all passed (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_v invalidation, 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).
cmake --preset dev
ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_(b64_shift|shift64_)' -V
  • Observed: 4 passed, 0 skipped, 0 failed (10.25 s):
    • startup_gfx2hlsl_b64_shift: passed (0.09 s)
    • startup_gfx2hlsl_shift64_controls: passed (0.13 s)
    • startup_gfx2hlsl_shift64_warp: passed (2.09 s), FXC ps_5_1 and DXC ps_6_0 matched 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) on NVIDIA GeForce RTX 5080 (driver 32.0.16.2124, D3D12 debug layer enabled), identical readbacks and mutation failures for FXC ps_5_1 and DXC ps_6_0, debug_errors=0 debug_warnings=0.
cmake --preset release
ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_(b64_shift|shift64_)' -V
  • Observed: 4 passed, 0 skipped, 0 failed (9.61 s: b64_shift 0.09 s, controls 0.13 s, warp 1.93 s, hardware 7.43 s).

  • Note: tests/startup_gfx2hlsl_shift64_check.py binary llvm-mc-15 was not run locally (llvm-mc is not installed on this Windows host); fixture words were cross-checked against tools/disasm_rdna2.py / gfx2hlsl.decode() and are exercised by the Ubuntu pixel-binary CI 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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. The sb == 0 carry case is guarded, so there is no >> 32 undefined shift. The >= 32 branch is correct for all three (zero fill for the logical ones, sign fill for the arithmetic one).
  • The r64 temporary is written once and then split into both destination registers. A partial overlap such as v[3:4] <- v[2:3] therefore reads the sources before either destination is written.
  • Operand validation refuses modifiers, odd or unaligned SGPR pairs, vcc/exec pairs, float-inline shift amounts, and 64-bit inline constants outside -16..64. These are rejected as Unsupported, not mis-lowered.
  • The new test is registered in CMake (controls + warp + hardware) and in both windows.yml lists.

Non-blocking note: the PR is CONFLICTING against current main (58de158). git merge-tree reports content conflicts in .github/workflows/windows.yml and CMakeLists.txt (adjacent test registrations). tools/startup/gfx2hlsl.py merges 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) in ashr_i64: startup_gfx2hlsl_shift64_check.py fails with "v_ashrrev_i64: emitted helper matches reference on 648 cases".
  • sh < 32u -> sh <= 32u in lshl_b64: the same check fails with "v_lshlrev_b64: emitted helper matches reference on 648 cases".

Commands run:

  • git diff --check <merge-base>...HEAD: clean
  • tests/bidi_controls_check.py: pass
  • tests/startup_gfx2hlsl_shift64_check.py: pass
  • tests/startup_gfx2hlsl_operand_count_check.py, tests/startup_gfx2hlsl_bit_alu_check.py, tests/startup_translator_check.py: pass
  • docs_links_check: not applicable, no docs touched
  • Windows Server 2025 (build 26100, MSVC 14.44, WARP) at the same commit e899a9bd, targets offscreen_check, regex startup_gfx2hlsl_shift64_controls|_warp|startup_translator, py-check startup_gfx2hlsl_shift64_check.py:
    • Debug (--preset dev): 3/3 tests passed
    • Release /O2 (--preset release): 3/3 tests passed
    • Python check: ok
  • The 298 *_hardware tests were not run (the VM exposes WARP only).

AI-assisted; commands listed were executed locally.

@R0Y00

R0Y00 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

#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.

@R0D4X R0D4X changed the title startup: lower 64-bit VOP3 shifts in gfx2hlsl startup: guard and verify 64-bit VOP3 shifts in gfx2hlsl Nov 24, 2026
@R0D4X
R0D4X force-pushed the fix/issue-1723-gfx2hlsl-shift64 branch from e899a9b to 2857ddc Compare November 24, 2026 20:03

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/main is 18 lines in tools/startup/gfx2hlsl.py (guards), the 389-line tests/startup_gfx2hlsl_shift64_check.py, three CMake registrations and two windows.yml entries. That follows the maintainer's request to carry the checks forward without a second helper implementation.

Earlier findings

  • Previous review (e899a9bd): the only open point was CONFLICTING against main. git merge-tree --write-tree HEAD origin/main now reports 0 conflicts.
  • My review of #1818 (P2): shift64 did not clear uniform_v for the destination pair, so a later v_readfirstlane_b32 could accept a register that now holds a lane-varying shift result. This head adds self.uniform_v.discard(dst[1]) and discard(dst[2]), and the test 64-bit shift invalidates uniform_v for both destination registers checks it. Closed.

What I checked in the guards

  • i64_words: VGPR pairs must end at or below v255; SGPR pairs must start even and end at or below s105; the inline integer regex is now 0|-?[1-9]\d* within -16..64, so spellings like -0, 00 or +1 are refused; everything else (literals, floats, vcc, exec, other ranges) raises Unsupported.
  • shift64: exactly three operands; destination pair a VGPR pair ending at or below v255; the shift amount is a single register in range (not a pair), not vcc/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.
  • The helpers themselves are the ones already on main (checked in my #1818 review), and the test evaluates the emitted text on 648 cases per operation against an independent 64-bit reference, with the three per-operation mutations and a partial-overlap control (v[3:4] <- v[2:3]).
  • Clean-room and title-neutral: source-built fixtures only; no title is named.

Commands run (Linux, exactly 2857ddc4)

python3 -B tests/startup_gfx2hlsl_shift64_check.py      -> rc=0, every check ok (helpers, overlap, accepted forms, 37 refusals, uniform_v)
for t in tests/startup_gfx2hlsl*_check.py               -> all pass
git diff --check origin/main...HEAD                     -> clean
python3 -B tests/docs_links_check.py                    -> Checked 18 Markdown files and 376 links
python3 -B tests/bidi_controls_check.py                 -> no bidirectional controls
git merge-tree --write-tree HEAD origin/main            -> 0 conflicts

Mutations of tools/startup/gfx2hlsl.py (each restored; git status clean)

mutation result
SGPR pair even-alignment check removed test FAILS (refusal list)
both uniform_v.discard calls removed test FAILS (64-bit shift invalidates uniform_v)
VGPR destination upper bound (dst[2] > 255) dropped test FAILS (refusal list)
vcc/exec/float shift-count guard dropped test FAILS (refusal list)
operand-count guard removed test FAILS (IndexError, an error rather than a refusal, so the guard is exercised)
inline constant range widened to 128 test FAILS (refusal list)

P3

  • The startup_gfx2hlsl_shift64_{warp,hardware} draws and the binary mode (llvm-mc-15) were not run here.

Limits

No dxc/fxc, renderer or llvm-mc on 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.

@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Ran the new check, then broke each guard it claims

At the PR head, device-free:

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_shift64_check.py
pointer-holding SGPR pair refused: ok
modifiers, invalid operands and wrong counts refused (37 cases): ok
exit 0

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_b64_shift_check.py
exit 0

Four mutations to the guards this PR adds, each reverted; the new check goes red for every one while the landed b64_shift
check stays green (so the mutations are specific to the new coverage, not to the shared lowering):

mutation shift64_check b64_shift_check
i64_words: drop the even-alignment requirement on an SGPR pair red green
i64_words: widen the inline range -16..64 → -64..128 red green
shift64: destination no longer has to be a pair red green
shift64: uniform_v.discard(dst[2]) → pass (only the low half invalidated) red green

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_readfirstlane much later. The fixture catches it, so the 37 refusal
cases 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_words refuses a decimal token outside -16..64, and the comment does not say where those bounds come from. A reader
reaching 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

  • AI-assisted review.

@R0Y00
R0Y00 merged commit b180e9c into R0Y00:main Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants