tests: ratchet the set of gfx2hlsl handlers that do not refuse malformed operands #2063
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!2063
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2063/head"
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?
@ChazY11 on GitHub · 2026-11-24 23:50 UTC · original
ChazY11:tests/pin-handler-arity→main· +137 −0 · 4 files · 1 commits · closed without mergingWhat
A ratchet check for an invariant that was untested: every
Stage.op_*handler must answer malformed operand shapes withUnsupported, never anything else.Why it matters, in this repository's own terms:
Stage.translaterecordsUnsupportedas a refusal and any other exception ashandler_error(...), labelledinternal error— the marker for a translator defect.#1723's census reads those as gaps it cannot act on.refusals is None(single-shader translation) nothing is caught at all, so the same input exits with a traceback instead of a refusal line.Measured on
main76 handlers × 7 shapes (none, one to four VGPRs, a truncated register, an attribute token):
Reachability, stated plainly: these shapes cannot come from
decode_instruction, which always produces the operand form of the encoding. So this is not a live decode bug — it is robustness for the text entry point the unit fixtures use. Fixing all 57 handlers is not one reviewable change, so this PR pins the current state instead.The ratchet
Two controls, run by hand against
tools/startup/gfx2hlsl.py:Verification
Neighbours still green:
startup_gfx2hlsl_swap_check.py,startup_gfx2hlsl_mad_check.py,startup_gfx2hlsl_operand_count_check.py.Registered as
startup_gfx2hlsl_handler_arityinCMakeLists.txt, added to the platform-independent list in.github/workflows/windows.yml, and listed in the AGENTS.md section so the documented list stays in step — the twelve older omissions there are #2053's subject and are not repeated in this PR.Scope
Test only; no handler is changed. The 57 entries are the honest current state, and the list is meant to shrink.
Notes
Rebased after #2024, and the ratchet already earned its keep
mainadded two handlers while this PR was open (s_bitcmp0_b32,s_bitcmp1_b32from #2024). The rebase intoCMakeLists.txtwas a two-sidedaddition and both registrations are kept. Re-run after the rebase:
Both new handlers are already compliant, so the check passes without touching them — and if either had indexed an operand before checking its count,
it would have failed here rather than silently adding a 58th entry later. That is the behaviour this PR exists for.
Neighbours after the rebase:
startup_gfx2hlsl_s_bitcmp_check.py,startup_gfx2hlsl_swap_check.py,startup_triage_run_check.py— all exit 0.Every `Stage.op_*` handler is fed operand shapes the decoder cannot produce: none, one to four plain VGPRs, a truncated register and an attribute token. A handler must answer each one with `Unsupported`, because that is the only exception the translator treats as a refusal: * `Stage.translate` records `Unsupported` as a refusal and any other exception as `handler_error(...)`, which labels the entry `internal error` -- the project's marker for a translator defect, not a missing lowering, so #1723's census counts it as a gap it cannot act on; * with `refusals is None` (single-shader translation) nothing is caught at all, so the same input exits with a traceback instead of a refusal line. On main the sweep finds 260 escapes across 57 of 76 handlers: IndexError: 236 TypeError: 24 IndexError buffer_load_dword (no operands) IndexError image_load v0 / v0 v1 / v0 v1 v2 TypeError s_bfm_b32 v[0 v1 'NoneType' object is not subscriptable TypeError v_fma_mixhi_f16 not enough arguments for format string These shapes cannot come from `decode_instruction`, so this is not a live decode bug; it is a robustness invariant that was untested. Fixing all 57 handlers is not one reviewable change, so this pins the current state instead: `PENDING` lists the handlers that do not hold the invariant today. * a handler outside `PENDING` that starts escaping fails the check; * an entry in `PENDING` that stops escaping also fails, with "remove it from PENDING"; * a `PENDING` entry that is not a handler fails, so a rename shows up here. Verified with two controls against `tools/startup/gfx2hlsl.py`: # a compliant handler starts indexing an operand without a length check handler s_load_dword answers () with IndexError; it must raise Unsupported -> 1 failed # a pending handler gains a length check handler v_mov_b32 now refuses every shape; remove it from PENDING -> 1 failed Command and result: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py startup gfx2hlsl handler arity checks: 76 handlers, 57 pending exit 0 Registered as `startup_gfx2hlsl_handler_arity` in CMakeLists.txt, added to the platform-independent run list in `.github/workflows/windows.yml`, and listed in the AGENTS.md Pure-Python section so the documented list stays in step (the twelve older omissions are #2053's subject, not repeated here).@ChazY11 on GitHub · 2026-11-25 00:14 UTC · original
Ready behind this PR: one guard that empties twenty-four of the entries
Since the list in this check only shrinks when a handler actually stops escaping, the natural follow-up is to fix a slice. The cheapest slice is the
twenty-four
s_cmp_*/s_cmpk_*handlers: they are generated by one factory, and that factory indexesops[0]/ops[1]without checking thecount, so a single guard covers all of them.
Measured on a branch stacked on this one (
startup/scalar-compare-arity, pushed to my fork):with the fail-first control being "remove exactly that guard":
and two-operand lowers unchanged:
All 28
tests/startup_gfx2hlsl_*_check.pyexit 0 there, so the guard does not disturb the shared scalar path.Why I am not opening it as a second PR yet
gh pr create --basecannot target a branch that exists only in a fork, and opening it againstmainwould duplicate this PR's test file. So thebranch is pushed and waiting rather than racing this one:
gfx2hlsl.pyplus the list edit, and I will open it immediately;one, which is why I did not do it by default.
If the slice is not the one you would choose, the sweep is 40 lines and reruns in a second, so any group of the remaining 33 is a candidate — the
s_cmpfamily is simply the one where a shared factory makes the fix a single line.AI-assisted.
@ChazY11 on GitHub · 2026-11-25 00:16 UTC · original
Update: the slice is now thirty-three handlers, in three guards
Both PRs are green here, so I extended the branch that is waiting behind this one. Instead of only
s_cmp*, it now covers every handler thatindexes an operand without checking the count and shares a body with its siblings:
Measured on
startup/scalar-compare-arity(rebased on this PR):One control per guard, removing exactly that guard:
Valid forms unchanged, checked directly:
All 28
tests/startup_gfx2hlsl_*_check.pyexit 0 there. The remaining 24 entries inPENDINGare thebuffer_load_*/image_*/tbuffer_*/v_*handlers, which do not share bodies, so each needs its own line — a separate slice, not this one.Still waiting on this PR rather than racing it:
gh pr create --basecannot target a branch that exists only in a fork. Say the word and I willeither open it against
mainas a two-commit PR or fold these three guards in here.AI-assisted.
@ChazY11 on GitHub · 2026-11-25 00:24 UTC · original
Superseded by #2104
I opened #2104, which is this check together with the guards that empty 33 of its
PENDINGentries (57 → 24). I combined them because everyother change in this tree ships its check with the behaviour, and because a test-only PR has to wait for a reviewer twice — once for the fixture, once
for the fix.
Nothing about this PR's content changes:
tests/startup_gfx2hlsl_handler_arity_check.pyis identical to the first commit of #2104. If you would ratherreview the fixture alone first, close #2104 and merge this one, then I will reopen the guards as a one-file change against
main.Sorry for the duplicate in the queue — my fault for splitting it this way to begin with.
AI-assisted.
@ChazY11 on GitHub · 2026-11-25 00:33 UTC · original
Closing this one myself: #2104 carries the same check verbatim except that its
PENDINGlist is 33 entries shorter, because the guards in that PR make those handlers refuse.Verified rather than assumed:
So nothing in this PR is lost. Keeping both in the queue asked a reviewer to compare two versions of the same file for no benefit, and the decision I offered
("close one or the other") costs someone else time that I can spend instead.
What changed my mind about which to keep: #2092 has just merged, and it is the same shape as #2104 — a production change that ships its check. That is the
shape this tree actually merges, so #2104 is the right vehicle and this one is the redundant half.
If you would rather review the fixture alone first, closing this does not block that: the fixture is the first commit of #2104 and its behaviour is identical
to the version here, apart from the list. Say so there and I will open it as a one-file PR against
main.AI-assisted.
Pull request closed