startup: refuse a scalar instruction with the wrong operand count (33 handlers) #2097
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2104"
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 ChazY11 on 2026-11-25T00:23:58Z.
What
Thirty-three handlers in
tools/startup/gfx2hlsl.pyindexops[0]/ops[1]/ops[2]without checking how many operands they were given, so amalformed instruction comes back as
IndexErrorinstead ofUnsupported. In this translator that is not a cosmetic difference:Stage.translaterecordsUnsupportedas a refusal and any other exception ashandler_error(...), labelledinternal error— its own markerfor a translator defect, which
#1723's census then counts as a gap nobody can 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.Three guards, each in the one body several handlers share:
s_cmp/s_cmpkfactorylen(ops) != 2op_s_and_saveexec_b64s_and/s_or/s_andn2_saveexec_b32/b64)len(ops) != 2op_s_andn2_wrexec_b64len(ops) != 2scalar_selects_cselect_b32/b64)len(ops) != 3Measured
The sweep feeds every
op_*handler operand shapes no decoder produces (none, one to four VGPRs, a truncated register, an attribute token):Valid forms are unchanged, checked directly rather than by reading the diff:
The check this comes with
tests/startup_gfx2hlsl_handler_arity_check.pyis the fixture that produced those numbers, and it is a ratchet rather than a snapshot:PENDINGholds the handlers that still do not refuse, and this PR takes it from 57 to 24. Registered asstartup_gfx2hlsl_handler_arityinCMakeLists.txt, added to the platform-independent list in.github/workflows/windows.yml, and listed in AGENTS.md.Fail-first, one control per guard
Removing exactly one guard at a time and running the check names exactly the handlers that share that body:
All 28
tests/startup_gfx2hlsl_*_check.pyexit 0.Two notes on scope
with the behaviour; if you would rather have the test alone first, say so and I will split it back and reopen #2063 against
main.PENDINGentries are thebuffer_load_*/image_*/tbuffer_*/v_*handlers, which do not share bodies — each needs itsown line, so that is a separate slice and deliberately not here.
What this does not establish
That any of these shapes comes from a real shader. They cannot: the decoder always produces the operand form of the encoding. This is robustness of
the text entry point the unit fixtures use, not a live decode bug, and the check says so in its docstring so the next reader does not over-read the
number.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:48:58Z.
I retained the 33 scalar dispatch guards. I replaced the generic handler probe because it skipped successful returns and assigned the same operand shapes to unrelated handlers. The revised test uses the real batch Stage path and checks 33 accepted operand lists and 99 distinct arity refusals. A control that silently drops the extra compare operand is detected.