gfx2hlsl: refuse a scalar ALU source list shorter than the table template uses #2515
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!2515
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2515/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-25 19:24 UTC · original
ChazY11:startup/scalar-table-short-arity→main· +120 −0 · 5 files · 1 commits · merged 2026-11-25 19:49 UTCWhat
Stage.scalarbuilds a scalar ALU expression withtext.format(*values), where theSCAentry spells its sourcesas
{0},{1}, … A source list shorter than the template uses leavesvaluestoo short andstr.formatraisesIndexError, which the single-shader path records astranslator crash in <op>: IndexErrorinstead of a refusalnaming the instruction — the class #2463 catalogues.
The arity guards merged in #2469 fire earlier in
lower()for their own subsets; this path reachesscalar()without passing one, so the short form of 36 two-source templates crashed. One guard before
text.formatcoversall of them, and it returns the same instruction-specific
Unsupportedshape the rest of the table uses.Refs #2463
Reproduction
Before the change, on
6d2d3bed:Fuzzing every two-source template with one source fewer gives 35
IndexErrors (s_add_i32 s_add_u32 s_and_b32 s_and_b64 s_andn2_b32 s_andn2_b64 s_ashr_i32 s_bfe_u32 s_lshl[1234]_add_u32 s_lshl_b32 s_lshr_b32 s_max_i32 s_max_u32 s_min_i32 s_min_u32 s_mul_hi_u32 s_mul_i32 s_nand_b32 s_nand_b64 s_nor_b32 s_nor_b64 s_or_b32 s_or_b64 s_orn2_b32 s_orn2_b64 s_pack_hh_b32_b16 s_sub_i32 s_sub_u32 s_xnor_b32 s_xnor_b64 s_xor_b32 s_xor_b64). Thethree-operand form is unaffected: every extra source is already refused with a well-formed message.
Checks
The whole
startup_gfx2hlsl_*family on this branch: 67 checks, 0 red.The two diagnostic paths, as asked
instruction into a refusal.
s_bfm_b32— it carries its ownexpected 3message, so it refuses with or without this guard. The controlexcludes it by name and asserts separately that it still refuses by its own message, rather than counting it as a
survivor and loosening the threshold.
Negative control
Changing
if len(srcs) < needed:toif False:makes the check exit 1; restoring it exits 0. That is the samein-place mutation the review reported, now part of the fixture.
Registration
CMakeLists.txt,AGENTS.mdand the Linux CI list each gain one entry next tostartup_gfx2hlsl_scalar_arity_check.py. No other behaviour changes: accepted instructions translate exactly asbefore, and only the refusing path is new.
Scope
One reviewable behaviour: a short source list is refused instead of crashing. The pointer-join and lane-mask claims
mentioned in #2463 stay with their authors; this branch does not touch them.
AI-assisted. Pure Python; no build or GPU needed. Verified on Windows 11 build 26300.9974.
Stage.scalar builds the expression with text.format(*values), where the SCA entry spells its sources as {0}, {1}, ... A short operand list leaves values too short and str.format raises IndexError, which the single-shader path records as "translator crash in <op>: IndexError" rather than as a refusal naming the instruction (the class #2463 catalogues). The arity guards merged in #2469 fire earlier in lower() for their own subsets; this path reaches scalar() without passing one, so the short form of 36 two-source templates crashed. The guard asserts the count the template needs before formatting, which covers all of them in one place. python -B tests/startup_gfx2hlsl_scalar_table_arity_check.py scalar table arity checks: 0 failed The check covers the short form refused with the operand count it names, the complete form never refused for its operand count, and a negative control that disabling the guard brings the IndexError back for 35 of the 36 (s_bfm_b32 keeps its own arity message, so it refuses either way and is excluded by name rather than counted as a survivor). gfx2hlsl family after the change: 67 checks, 0 red. AI-assisted.