Repository navigation
startup: lower v_sad_u8, v_sad_u16, and v_sad_u32 in gfx2hlsl - #2450
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Five mutations: four caught, and the survivor is a real gap in the abs/neg guard rather than an equivalentBaseline on this branch:
Why the last one is a gap
The check does refuse "abs" today (that line passes on the branch), so it is exercising one of the three bits. With three sources and one mask, one case cannot cover all three, and nothing notices when two of the three stop being tested. Three ways to close it, cheapest first:
I would take (2) plus (3): it turns the single "abs and neg refused" line into six, and each one names which slot it is. What is well pinned hereThe three helpers are each caught, which is more than I expected for a diff whose helpers are generated as HLSL text: The AI-assisted; the five mutations were run locally on Windows 11 build 26300.9974. |
The v_sad_u8/u16/u32 check listed the ABS (VOP3A w0[10:8]) and NEG (w1[31:29]) rows but aggregated them into one boolean, so a mask narrowed to a single bit (w0[8] or w1[29]) still made G.Pipeline() raise: the printed |v1| or -1 was caught later by Stage.one(), not by the encoding guard. Mutation of either mask survived. Read the refusal back from G.decode()'s refusals list, one row per source and modifier, for VGPR and inline-integer sources alike, and assert the exact 'v_sad_* with neg/abs' reason, so narrowing either mask fails. Register tests/startup_gfx2hlsl_sad_check.py in the windows.yml pure-Python job and the AGENTS.md pure-Python list. Refs R0Y00#2450 AI-assisted.
9377558 to
323c0b8
Compare
The v_sad_u8/u16/u32 check listed the ABS (VOP3A w0[10:8]) and NEG (w1[31:29]) rows but aggregated them into one boolean, so a mask narrowed to a single bit (w0[8] or w1[29]) still made G.Pipeline() raise: the printed |v1| or -1 was caught later by Stage.one(), not by the encoding guard. Mutation of either mask survived. Read the refusal back from G.decode()'s refusals list, one row per source and modifier, for VGPR and inline-integer sources alike, and assert the exact 'v_sad_* with neg/abs' reason, so narrowing either mask fails. Register tests/startup_gfx2hlsl_sad_check.py in the windows.yml pure-Python job and the AGENTS.md pure-Python list. Refs R0Y00#2450 AI-assisted.
323c0b8 to
d2cf113
Compare
|
Thanks — I took (2) plus (3), with one addition that (2)+(3) alone would not have covered. Why the six rows alone were not enough. With What the check does now (
Mutation results on head
Rebased and re-verified on
I did not take (1) (asserting the guard's source text): the reason-pinned rows fail on behaviour, so renaming or reformatting the guard does not churn the fixture. |
MasterDomino
left a comment
There was a problem hiding this comment.
Review of head d2cf1136. I found no P1 or P2 issues. It needs a rebase, and there's one docs nit; I'll merge once it's rebased and CI is green.
What I checked
-
Semantics against RDNA 2
V_SAD_U8/U16/U32:- unsigned byte and halfword absolute differences plus
S2, with 32-bit wrap; sad_u32as an unsigned|S0 − S1| + S2, the same as LLVM's umax−umin+c selection andpixel_aot'smax − min + c.
Everything is integer, so the FXC/DXC float relaxations don't apply.
- unsigned byte and halfword absolute differences plus
-
Modifiers:
- ABS and NEG bits are refused on the raw word for every source slot.
clamp, omod and op_sel are refused:v_sad_u32 … clamp, assembled with llvm-mc 15.0.7, is refused asv_sad_u32 with ['clamp'].- Inline float constants lower as their bit patterns (
1.0becomes0x3f800000u). v_sad_hi_u8andv_msad_u8stay refused.
-
Cache revision:
x2w-startup-shader-14and14csare unchanged. I replayed the 863 distinctPipeline/ComputePipelineinputs built by 69 passing gfx2hlsl checks through the merge base and this head:- previously accepted shaders whose text changed: 0 of 315;
- accepted shaders now refused: none;
- previously refused shaders now accepted: 4, all
v_sad_*.
So no bump is needed.
Commands executed (Windows 11 build 26300; AMD Radeon RX 9070 XT 1002:7550, driver 32.0.32029.2010, debug layer enabled; WARP 10.0.26100.9818; DXC/FXC from SDK 10.0.26100)
python -B tests/startup_gfx2hlsl_sad_check.py
ctest --preset dev --no-tests=error -j1 -R '^startup_gfx2hlsl_sad_(controls|warp|hardware)$' -V
python -B tests/startup_gfx2hlsl_{handler_arity,operand_count,bit_alu}_check.py| Test | Result |
|---|---|
startup_gfx2hlsl_sad_controls |
pass |
startup_gfx2hlsl_sad_warp |
pass: 18 good draws (9 FXC ps_5_1, 9 DXC ps_6_0); the 6 mutated draws read their mutated words; debug_errors=0 |
startup_gfx2hlsl_sad_hardware (RX 9070 XT) |
pass: the same 18 + 6, with 0 debug errors or warnings |
| neighbouring checks | pass |
There were no capability skips. This adds the AMD hardware run the description didn't have.
Negative control
Each mutation is one line of tools/startup/gfx2hlsl.py, applied alone and reverted. The draws ran on WARP and the RX 9070 XT:
| Mutation | Controls | Draw |
|---|---|---|
sad_u8 drops + S2 |
600-triple MISMATCH | expected 000000ff,00000109,fffffc0a,000000df, actual 00000000,… |
sad_u32 compares as signed |
605-triple MISMATCH | expected ffffffff,ffffffff,80000006,ffffffff, actual 00000001,00000001,80000004,00000005 |
sad_u16 high half sign-extended |
600-triple MISMATCH | expected 0000ffff,00010009,fffe0004,00000fff, actual 00000001,0000000b,ffff0002,00000fff |
encoding guard without v_sad_u32 |
accepted binary VOP3A with neg src0 inline 1 |
(the draw has no modifier rows) |
All were caught.
To resolve before merge
- Rebase:
docs/experiments.mdconflicts with currentmain, because both append a section at the end. Keep both. With that resolved locally, the checks above pass 3/3 on a rebuiltoffscreen_check. Note also that #2452 adds acheck_encodingblock at the same spot ingfx2hlsl.py; keeping both blocks works, and both checks pass onmain+ #2450 + #2452. - Nit,
docs/experiments.md:14779: the text says that on the GTX 1660 SUPER "the_debug1variants skip with exit 77", but this PR registers only_controls,_warpand_hardware. Please drop or correct that clause.
AI-assisted; commands listed were executed locally.
The v_sad_u8/u16/u32 check listed the ABS (VOP3A w0[10:8]) and NEG (w1[31:29]) rows but aggregated them into one boolean, so a mask narrowed to a single bit (w0[8] or w1[29]) still made G.Pipeline() raise: the printed |v1| or -1 was caught later by Stage.one(), not by the encoding guard. Mutation of either mask survived. Read the refusal back from G.decode()'s refusals list, one row per source and modifier, for VGPR and inline-integer sources alike, and assert the exact 'v_sad_* with neg/abs' reason, so narrowing either mask fails. Register tests/startup_gfx2hlsl_sad_check.py in the windows.yml pure-Python job and the AGENTS.md pure-Python list. Refs R0Y00#2450 AI-assisted.
d2cf113 to
a991d93
Compare
|
Rebased onto current main (�fba03c9) as @thevoid asked. Head is now �991d931 (was d2cf113); the two commits replayed, and the only conflict was the docs/experiments.md append-tail: I kept main's newest section and re-appended this PR's ## Startup translator: v_sad_u8 ... record. No conflict markers anywhere. Verified on �991d931: ests/startup_gfx2hlsl_sad_check.py control mode exit 0; the test file is blob-identical to the pre-rebase head; both encoding guards are present (�_cmpx*16 at gfx2hlsl.py:368, �_sad* at :374); the windows.yml and AGENTS.md registrations survived; docs_links_check.py 19 files/473 links; git diff --check clean. Diff vs main is the PR's 6 files (+601). PR is MERGEABLE and CI is running on the new head. |
MasterDomino
left a comment
There was a problem hiding this comment.
Approved at head a991d931, triggered02's rebase of d2cf1136 onto main. Thanks for the rebase.
Re-verified at a991d931
- Same change: the PR's changed lines in
tools/startup/gfx2hlsl.py, the check,CMakeLists.txt,AGENTS.mdand the workflow are identical tod2cf1136's, compared as the set of +/- lines. So my review and mutation results above still apply: the semantics match the ISA, there is no cache bump, and all mutants are caught on the RX 9070 XT and WARP. - Rebuilt and re-ran on the rebased tree: Windows 11 build 26300,
offscreen_checkbuilt ata991d931.3/3 pass on the AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010) and WARP 10.0.26100.9818, and the neighbouring checks pass. There were no skips.ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sad_(controls|warp|hardware)$' -V python -B tests/startup_gfx2hlsl_{handler_arity,operand_count,bit_alu}_check.py
Follow-up (not blocking)
docs/experiments.md still says the _debug1 variants skip with exit 77 on the GTX 1660 SUPER (now at line 14900), but this PR registers only _controls, _warp and _hardware. It's a one-line wording fix that can go in a later docs touch-up.
Note for #2452
#2452 adds a check_encoding block at the same spot in gfx2hlsl.py, so it will need one more rebase after this lands; keep both blocks.
Merge checks: required CI passed at this head. The /O2 and coverage skips come from explicit workflow conditions. There are no unresolved review threads. I read @ChazY11's mutation report and triggered02's responses in full.
AI-assisted; commands listed were executed locally.
Post-merge audit of the
|
mutation of tools/startup/gfx2hlsl.py |
caught |
|---|---|
sad_u8 template → sad_u16 |
caught |
sad_u32({0}, {1}, {2}) → third source reused ({0}) so the accumulator is ignored |
caught |
sad_u16 sources swapped ({1}, {0}) |
caught |
pipe.uses_sad.add(base) removed |
caught |
uses_sad recorded only when a set already exists (add → union) |
caught |
the uses_sad block guarded by if False: |
caught |
VEC_U arity 3 → 4 |
caught |
| the sad neg/abs refusal deleted entirely | caught |
the refusal restricted to word0 & 0x700 (word1 bits ignored) |
caught |
the refusal restricted to word1 & 0xe0000000 (word0 bits ignored) |
caught |
The last three are the ones I most wanted to see caught, because they are three different ways to get the same guard
wrong: line 374 tests word0 & 0x700 or word1 & 0xe0000000 for one reason — a NEG on an inline integer would otherwise
print as -N and be accepted as a negative constant. Dropping either half, or the whole guard, is invisible unless the
fixture actually assembles the offending encoding, and it does.
Likewise the two uses_sad mutations: recording the name only into an existing set, or not at all, would change the
emitted HLSL's declarations without changing the instruction text, which is exactly the sort of thing a text-only
assertion misses. It does not.
No survivors, so nothing to ask for. Recording the list here so the next person who touches these three sites knows
which mistakes are already covered.
AI-assisted; pure Python, no build or GPU, Windows 11 build 26300.9974.
Lowers unmodified gfx1013 VOP3A
v_sad_u8(0x15a),v_sad_u16(0x15c), andv_sad_u32(0x15d) intools/startup/gfx2hlsl.py.What changed
tools/startup/gfx2hlsl.py:'v_sad_u8','v_sad_u16'and'v_sad_u32'inVEC_U, emitted as on-demand preamble helperssad_u8,sad_u16,sad_u32inPipeline.common()(tracked viaself.pipe.uses_sadon bothPipelineandComputePipeline).sad_u8(a, b, c)sumsuint(abs(int((a >> shift) & 0xffu) - int((b >> shift) & 0xffu)))across the 4 byte lanes and addscwith 32-bit unsigned wraparound.sad_u16(a, b, c)sumsuint(abs(int(a & 0xffffu) - int(b & 0xffffu))) + uint(abs(int(a >> 16) - int(b >> 16))) + c.sad_u32(a, b, c)computes(a > b ? a - b : b - a) + cwith an unsigned comparison (no signedintoverflow).check_encodingrefuses the per-source VOP3Aabsbits (w0[10:8]) andnegbits (w1[31:29]) on the raw word, sonegon an inline1is refused rather than printed as-1and read as a negative constant;VEC_U/Stage.urefuse the printed|vN|/-vNforms,clamp/omod/op_sel, and wrong operand counts.tests/startup_gfx2hlsl_sad_check.py,CMakeLists.txt,docs/experiments.md, and the CI registrations (.github/workflows/windows.ymlpure-Python job,AGENTS.mdpure-Python list) — the latter added ind2cf1136.Measured checks (
d2cf1136, rebased ontoorigin/main1a0e506d)tests/startup_gfx2hlsl_sad_check.py(pure Python): PASS — on-demand emission (5/5), CPU HLSL evaluation against the reference over 600 triples (v_sad_u8), 600 (v_sad_u16) and 605 (v_sad_u32), mutated-HLSL mismatch controls, 54 synthetic VOP3A binary refusals (18 per instruction: 6 modifier forms + 12abs/negrows), 36 encoding-guard rows whose refusal reason is read back fromG.decode()(12 per instruction:absandnegon sources 0/1/2 as a VGPR and as an inline1), 39Stage.urefusal forms, and 3 unlowered controls.tests/startup_gfx2hlsl_sad_check.py draw <dxc> <offscreen_check> warp <fxc>(Microsoft Basic Render Driver1414:008c, driver10.0.26100.9818): PASS — 18/18 good draws (9 FXCps_5_1+ 9 DXCps_6_0) matched the reference words, and 6/6 mutated draws failed with the exact wrong readback words.tests/startup_gfx2hlsl_sad_check.py draw <dxc> <offscreen_check> hardware <fxc>(NVIDIA GeForce GTX 1660 SUPER, driver32.0.16.1074, Windows build 26200): PASS — the same 18/18 good and 6/6 mutated draws. The debug layer is not installed on that host, so the_debug1variants skip with exit 77.startup_translator_check.py,docs_links_check.py(468 links),bidi_controls_check.py,startup_tools_lint_check.py,git diff --check: all PASS.tools/startup/gfx2hlsl.py: the 4 helper/uses_sadmutations are caught, theabsmask narrowed tow0 & 0x100is caught (v_sad_u8: encoding guard refuses abs src1 VGPR), and thenegmask narrowed tow1 & 0x20000000is caught (v_sad_u8: accepted binary VOP3A with neg src1 inline 1, i.e. the silent-1acceptance this guard exists to prevent). The last two survived the pipeline-level refusal control becauseStage.ustill rejects the printed|v1|.Not established