startup: refuse a short operand list in the scalar ALU handlers #2461

Merged
ChazY11 merged 3 commits from upstream-pr/2469 into main 2026-11-25 18:51:41 +00:00
ChazY11 commented 2026-11-25 17:36:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:36:53Z.


Eleven of the 44 SCA entries read ops[1] without checking the count, so a short list came back as
translator crash in <op>: IndexError — the batch translator's marker for a translator defect, not for text
it does not lower. s_add_u32 with no operands was the shortest repro.

What changed

Stage.scalar is the single entry for the whole SCA table, so the guard is one check rather than eleven:

if base != 's_movk_i32' and len(ops) < 2:
    raise Unsupported('%s with %d operands, expected 2' % (base, len(ops)))

op_s_bfm_b32 keeps its own body (it folds constant masks and inspects ops[0] for the m0 destination), so
it gets the same check in place. s_movk_i32 keeps its existing exact check for the immediate it folds.

before: s_add_u32              -> translator crash in s_add_u32: IndexError
after:  s_add_u32              -> s_add_u32 with 0 operands, expected 2
before: s_add_u32 s0           -> translator crash in s_add_u32: IndexError
after:  s_add_u32 s0           -> s_add_u32 with 1 operands, expected 2

s_cselect_b32, s_abs_i32, s_bcnt1_i32_b32, s_addk_i32 and the s_cmp* forms already refused these
correctly and are unaffected.

The check

tests/startup_gfx2hlsl_scalar_arity_check.py covers, for all 44 SCA entries, one accepted shape and both
short forms, plus the refusal text for three of them and a negative control that loads the translator with
the guard removed:

python out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_arity_check.py
scalar ALU operand count checks: 0 failed
PASS

Guard removal proof, one at a time:

scalar guard removed  -> exit 1
bfm guard removed     -> exit 1
restored              -> exit 0

Registered in CMakeLists.txt (visible as startup_gfx2hlsl_scalar_arity in ctest -N), in the Linux
Run Python checks list, and in AGENTS.md.

Verification

  • all 63 tests/startup_gfx2hlsl_*_check.py exit 0 on this branch;
  • ctest --preset dev -R startup_gfx2hlsl passes 131/131 (658 s), so no accepted form changed;
  • this is a refusal path: no shader output changes and no GPU readback is involved.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6610156412 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2469). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T17:36:53Z. --- Eleven of the 44 `SCA` entries read `ops[1]` without checking the count, so a short list came back as `translator crash in <op>: IndexError` — the batch translator's marker for a translator defect, not for text it does not lower. `s_add_u32` with no operands was the shortest repro. ## What changed `Stage.scalar` is the single entry for the whole `SCA` table, so the guard is one check rather than eleven: ```python if base != 's_movk_i32' and len(ops) < 2: raise Unsupported('%s with %d operands, expected 2' % (base, len(ops))) ``` `op_s_bfm_b32` keeps its own body (it folds constant masks and inspects `ops[0]` for the `m0` destination), so it gets the same check in place. `s_movk_i32` keeps its existing exact check for the immediate it folds. before: s_add_u32 -> translator crash in s_add_u32: IndexError after: s_add_u32 -> s_add_u32 with 0 operands, expected 2 before: s_add_u32 s0 -> translator crash in s_add_u32: IndexError after: s_add_u32 s0 -> s_add_u32 with 1 operands, expected 2 `s_cselect_b32`, `s_abs_i32`, `s_bcnt1_i32_b32`, `s_addk_i32` and the `s_cmp*` forms already refused these correctly and are unaffected. ## The check `tests/startup_gfx2hlsl_scalar_arity_check.py` covers, for all 44 `SCA` entries, one accepted shape and both short forms, plus the refusal text for three of them and a negative control that loads the translator with the guard removed: ```text python out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_arity_check.py scalar ALU operand count checks: 0 failed PASS ``` Guard removal proof, one at a time: ```text scalar guard removed -> exit 1 bfm guard removed -> exit 1 restored -> exit 0 ``` Registered in `CMakeLists.txt` (visible as `startup_gfx2hlsl_scalar_arity` in `ctest -N`), in the Linux `Run Python checks` list, and in `AGENTS.md`. ## Verification - all 63 `tests/startup_gfx2hlsl_*_check.py` exit 0 on this branch; - `ctest --preset dev -R startup_gfx2hlsl` passes 131/131 (658 s), so no accepted form changed; - this is a refusal path: no shader output changes and no GPU readback is involved. AI-assisted.
ChazY11 commented 2026-11-25 18:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:42:39Z.


One addition that every other open PR here has and mine did not: a docs/experiments.md entry. I checked before
writing it — my two earlier merged refusal PRs (#2360, #2373) carried no docs change, so this is not a gate,
but four of the five refusal/lowering PRs open right now document their rule, and the rule behind these count
checks was only in the code comments.

bbd4b69e adds one section to docs/experiments.md: why translator crash in <op>: <ExcType> is the wrong
outcome for a short operand list (Stage.translate records it as a translator defect and refusals_report
groups by that text), which four entry points now refuse instead, and which check pins each. No behaviour
change; tests/docs_links_check.py passes (19 files, 466 links) and the scalar check still exits 0 on the head.

family                     entry point     short form before                  refusal now
buffer loads and stores    buffer_address  translator crash: IndexError      <op> with N operands, expected 4
image instructions         image()         translator crash: IndexError      … expected at least 3 / without dim:
single-body VOP handlers   handler body    translator crash: IndexError      … expected 2 / 3 or 4
scalar ALU (SCA)           Stage.scalar    translator crash: IndexError      … expected 2

If you would rather keep the docs out of this PR, say so and I will drop the commit; it is separable.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7169889629 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2469#issuecomment-7169889629). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T17:42:39Z. --- One addition that every other open PR here has and mine did not: a `docs/experiments.md` entry. I checked before writing it — my two earlier merged refusal PRs (#2360, #2373) carried no docs change, so this is not a gate, but four of the five refusal/lowering PRs open right now document their rule, and the rule behind these count checks was only in the code comments. `bbd4b69e` adds one section to `docs/experiments.md`: why `translator crash in <op>: <ExcType>` is the wrong outcome for a short operand list (`Stage.translate` records it as a translator defect and `refusals_report` groups by that text), which four entry points now refuse instead, and which check pins each. No behaviour change; `tests/docs_links_check.py` passes (19 files, 466 links) and the scalar check still exits 0 on the head. family entry point short form before refusal now buffer loads and stores buffer_address translator crash: IndexError <op> with N operands, expected 4 image instructions image() translator crash: IndexError … expected at least 3 / without dim: single-body VOP handlers handler body translator crash: IndexError … expected 2 / 3 or 4 scalar ALU (SCA) Stage.scalar translator crash: IndexError … expected 2 If you would rather keep the docs out of this PR, say so and I will drop the commit; it is separable. AI-assisted.
ChazY11 commented 2026-11-25 18:01:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T17:59:03Z.


Review-cost note, not a request: #2396 (5 handlers), #2408 (7 image forms) and this one (44 SCA entries) are all
green and independent, and all three are refusal-only. If the size of this one is the reason it is waiting, it
splits cleanly into the 18 entries that actually crashed (s_add_u32, s_sub_u32, s_mul_i32, s_and_b32,
s_or_b32, s_xor_b32, s_lshl_b32, s_lshr_b32, s_ashr_i32, s_min_i32, s_max_u32, s_mov_b32,
s_not_b32, s_brev_b32, s_mul_hi_u32, plus s_bfm_b32 in its own body) and the rest, which the
single Stage.scalar guard covers for free but which never produced the marker. I can reduce the fixture to the
18 and drop the docs commit to make a smaller first merge, and follow with the remainder.

The measurements behind it, in one place, so nothing needs re-running to decide:

short form                 before                                after
s_add_u32                  translator crash in s_add_u32: IndexError    s_add_u32 with 0 operands, expected 2
s_bfm_b32                  translator crash in s_bfm_b32: IndexError    s_bfm_b32 with 0 operands, expected 3

scalar guard removed -> exit 1, bfm guard removed -> exit 1, restored -> exit 0
63/63 tests/startup_gfx2hlsl_*_check.py exit 0
ctest --preset dev -R startup_gfx2hlsl: 131/131 (658 s)
Linux CI check list run locally: 137 entries, 135 ok, 2 capability skips, 0 failures

One limitation I should state rather than leave implied: this machine cannot complete the full C++ build
(archive_reader.exe and friends fail in DXC with unable to create compilation: AccessDenied, unrelated to
any branch here), so my local evidence is limited to the pure-Python and gfx2hlsl side. The PRs are
Python-only and CI builds them on the runners.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170273662 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2469#issuecomment-7170273662). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T17:59:03Z. --- Review-cost note, not a request: #2396 (5 handlers), #2408 (7 image forms) and this one (44 `SCA` entries) are all green and independent, and all three are refusal-only. If the size of this one is the reason it is waiting, it splits cleanly into the 18 entries that actually crashed (`s_add_u32`, `s_sub_u32`, `s_mul_i32`, `s_and_b32`, `s_or_b32`, `s_xor_b32`, `s_lshl_b32`, `s_lshr_b32`, `s_ashr_i32`, `s_min_i32`, `s_max_u32`, `s_mov_b32`, `s_not_b32`, `s_brev_b32`, `s_mul_hi_u32`, plus `s_bfm_b32` in its own body) and the rest, which the single `Stage.scalar` guard covers for free but which never produced the marker. I can reduce the fixture to the 18 and drop the docs commit to make a smaller first merge, and follow with the remainder. The measurements behind it, in one place, so nothing needs re-running to decide: short form before after s_add_u32 translator crash in s_add_u32: IndexError s_add_u32 with 0 operands, expected 2 s_bfm_b32 translator crash in s_bfm_b32: IndexError s_bfm_b32 with 0 operands, expected 3 scalar guard removed -> exit 1, bfm guard removed -> exit 1, restored -> exit 0 63/63 tests/startup_gfx2hlsl_*_check.py exit 0 ctest --preset dev -R startup_gfx2hlsl: 131/131 (658 s) Linux CI check list run locally: 137 entries, 135 ok, 2 capability skips, 0 failures One limitation I should state rather than leave implied: this machine cannot complete the full C++ build (`archive_reader.exe` and friends fail in DXC with `unable to create compilation: AccessDenied`, unrelated to any branch here), so my local evidence is limited to the pure-Python and `gfx2hlsl` side. The PRs are Python-only and CI builds them on the runners. AI-assisted.
upstream-sync closed this pull request 2026-11-25 19:03:54 +00:00
ChazY11 commented 2026-11-25 19:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:27:58Z.


Self-review of the table this PR adds to docs/experiments.md, since a table that looks exhaustive is the easiest
place to mislead. I checked it against every operand-count refusal in the tree on c887a65a:

2147/2155/2177  VEC generic (arity + 1)          -> row "single-body VOP handlers"
2360/2362       SCA table + s_movk_i32           -> row "scalar ALU (SCA)"
2545/2576       saveexec / wrexec                -> not named in the table
2686            scalar select                    -> not named in the table
2784            s_bfm_b32                        -> row "scalar ALU (SCA)"
2966/3013/3188  buffer load                      -> row "buffer loads and stores"

So the classification holds, but three refusal sites (saveexec, wrexec, scalar select) are reachable and
unnamed. Nothing is wrong with the behaviour they describe — all three already refuse — the question is only whether
the table should enumerate them.

Two readings, and I would rather you pick than guess:

  1. The table is about the four entry points that produced translator crash in <op>: <ExcType> — then it is
    correct as written, and I should add one sentence saying so explicitly, because "four rows" reads like "four
    sites" to someone comparing against the source.
  2. The table is meant to be the census of operand-count refusals — then saveexec, wrexec and scalar select
    belong in it, and I will extend it.

My own preference is (1) plus the sentence, since the crash is what the section is about and a longer table invites
the reader to think the list is the whole of the refusal surface. Say which and I will adjust; the docs commit is
separable from the guard commit either way.

While here, one measurement that supports the section's claim that a short operand list is the failure mode and not
a hypothetical: with the Stage.scalar guard removed, s_add_u32 with 0 operands raises IndexError from
%s with %d operands, expected 2 → ops indexing, i.e. exactly the translator crash in s_add_u32: IndexError
line the table's third column records.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170945047 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2469#issuecomment-7170945047). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T18:27:58Z. --- Self-review of the table this PR adds to `docs/experiments.md`, since a table that looks exhaustive is the easiest place to mislead. I checked it against every operand-count refusal in the tree on `c887a65a`: ```text 2147/2155/2177 VEC generic (arity + 1) -> row "single-body VOP handlers" 2360/2362 SCA table + s_movk_i32 -> row "scalar ALU (SCA)" 2545/2576 saveexec / wrexec -> not named in the table 2686 scalar select -> not named in the table 2784 s_bfm_b32 -> row "scalar ALU (SCA)" 2966/3013/3188 buffer load -> row "buffer loads and stores" ``` So the classification holds, but three refusal sites (`saveexec`, `wrexec`, `scalar select`) are reachable and unnamed. Nothing is wrong with the behaviour they describe — all three already refuse — the question is only whether the table should enumerate them. Two readings, and I would rather you pick than guess: 1. **The table is about the four entry points that produced `translator crash in <op>: <ExcType>`** — then it is correct as written, and I should add one sentence saying so explicitly, because "four rows" reads like "four sites" to someone comparing against the source. 2. **The table is meant to be the census of operand-count refusals** — then `saveexec`, `wrexec` and `scalar select` belong in it, and I will extend it. My own preference is (1) plus the sentence, since the crash is what the section is about and a longer table invites the reader to think the list is the whole of the refusal surface. Say which and I will adjust; the docs commit is separable from the guard commit either way. While here, one measurement that supports the section's claim that a short operand list is the failure mode and not a hypothetical: with the `Stage.scalar` guard removed, `s_add_u32` with 0 operands raises `IndexError` from `%s with %d operands, expected 2` → `ops` indexing, i.e. exactly the `translator crash in s_add_u32: IndexError` line the table's third column records. AI-assisted.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2461
No description provided.