startup: refuse an image instruction with fewer than three operands #2373

Manually merged
github merged 1 commit from gh-pr/2373/head into gh-pr/2373/base 2026-11-27 00:45:57 +00:00
Owner

@⁠ChazY11 on GitHub · 2026-11-25 14:04 UTC · original
ChazY11:startup/image-arity → main · +58 −0 · 5 files · 1 commits · merged 2026-11-25 14:17 UTC

What

image() reads vdata, an address and a descriptor, but indexed them without checking how many operands it was given, so a shorter list reached ops[1] or ops[2] and came back as translator crash in <op>: IndexError — the batch translator's marker for a translator defect, not for an instruction it does not lower — and the single-shader path does not catch it at all. Seven handlers share that body: image_sample, image_sample_l, image_sample_lz, image_sample_b, image_get_lod, image_load, image_load_mip.

One guard, before the first index:

if len(ops) < 3:
    raise Unsupported('image instruction with %d operands, expected at least 3' % len(ops))

Measured through the real Stage entry point

image_sample v[8:11], v0   before: translator crash in image_sample: IndexError
                           after:  image instruction with 2 operands, expected at least 3
image_load v[8:11]         before: translator crash in image_load: IndexError
                           after:  image instruction with 1 operands, expected at least 3

The three-operand forms are unchanged: image_load v[8:11], v0, s[16:19] still reports descriptor operand s[16:19] holds None, so the guard replaces the crash and nothing else.

Fail-first

Removing exactly the guard:

AssertionError: ('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')])

restoring it returns startup gfx2hlsl image arity: 7 forms refused at 1 and 2 operands, exit 0.

The check is a new file, deliberately

tests/startup_gfx2hlsl_image_arity_check.py is separate from tests/startup_gfx2hlsl_handler_arity_check.py, which an in-flight PR is editing — two PRs adding a helper at the same anchor would conflict in that hunk for no benefit. The new file asserts the refusal at one and two operands for all seven forms, and that the refusal is not translator crash …, so a handler that starts raising something else fails here too. It is registered in CMakeLists.txt, listed in the Linux CI check list (.github/workflows/windows.yml) and in AGENTS.md.

Verification

out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_image_arity_check.py
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py
out/pe-env/Scripts/python.exe -B tests/run_checks_parallel_check.py

exit 0, and all 58 tests/startup_gfx2hlsl_*_check.py exit 0 on this branch. The failing set of all tests/startup_*_check.py run with no arguments is identical on this branch and on main (51 each, none added or removed), so the only checks that move are the ones this PR touches — most of those need a renderer and fail the same way on both.

What this does not touch

The handlers that still index operands without a count check (v_cndmask_b32, v_mov_b32, v_cvt_i32_f32, s_bitcmp*, …) are unchanged: they do not share a body, so each needs its own line and its own accepted-form fixture. Same for the buffer bodies, which #2360 covers.

AI-assisted.

**@⁠ChazY11** on GitHub · 2026-11-25 14:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2373) `ChazY11:startup/image-arity` → `main` · +58 −0 · 5 files · 1 commits · merged 2026-11-25 14:17 UTC ## What `image()` reads vdata, an address and a descriptor, but indexed them without checking how many operands it was given, so a shorter list reached `ops[1]` or `ops[2]` and came back as `translator crash in <op>: IndexError` — the batch translator's marker for a translator defect, not for an instruction it does not lower — and the single-shader path does not catch it at all. Seven handlers share that body: `image_sample`, `image_sample_l`, `image_sample_lz`, `image_sample_b`, `image_get_lod`, `image_load`, `image_load_mip`. One guard, before the first index: ```python if len(ops) < 3: raise Unsupported('image instruction with %d operands, expected at least 3' % len(ops)) ``` ## Measured through the real `Stage` entry point ```text image_sample v[8:11], v0 before: translator crash in image_sample: IndexError after: image instruction with 2 operands, expected at least 3 image_load v[8:11] before: translator crash in image_load: IndexError after: image instruction with 1 operands, expected at least 3 ``` The three-operand forms are unchanged: `image_load v[8:11], v0, s[16:19]` still reports `descriptor operand s[16:19] holds None`, so the guard replaces the crash and nothing else. ## Fail-first Removing exactly the guard: ```text AssertionError: ('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')]) ``` restoring it returns `startup gfx2hlsl image arity: 7 forms refused at 1 and 2 operands`, exit 0. ## The check is a new file, deliberately `tests/startup_gfx2hlsl_image_arity_check.py` is separate from `tests/startup_gfx2hlsl_handler_arity_check.py`, which an in-flight PR is editing — two PRs adding a helper at the same anchor would conflict in that hunk for no benefit. The new file asserts the refusal at one and two operands for all seven forms, and that the refusal is not `translator crash …`, so a handler that starts raising something else fails here too. It is registered in `CMakeLists.txt`, listed in the Linux CI check list (`.github/workflows/windows.yml`) and in `AGENTS.md`. ## Verification ```powershell out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_image_arity_check.py out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py out/pe-env/Scripts/python.exe -B tests/run_checks_parallel_check.py ``` exit 0, and all 58 `tests/startup_gfx2hlsl_*_check.py` exit 0 on this branch. The failing set of all `tests/startup_*_check.py` run with no arguments is identical on this branch and on `main` (51 each, none added or removed), so the only checks that move are the ones this PR touches — most of those need a renderer and fail the same way on both. ## What this does not touch The handlers that still index operands without a count check (`v_cndmask_b32`, `v_mov_b32`, `v_cvt_i32_f32`, `s_bitcmp*`, …) are unchanged: they do not share a body, so each needs its own line and its own accepted-form fixture. Same for the buffer bodies, which #2360 covers. AI-assisted.
`image()` reads vdata, an address and a descriptor, but it indexed them without checking how many operands it
was given, so a shorter list reached `ops[1]` or `ops[2]` and came back as `translator crash in <op>:
IndexError` instead of a refusal. Seven handlers share that body: `image_sample`, `image_sample_l`,
`image_sample_lz`, `image_sample_b`, `image_get_lod`, `image_load` and `image_load_mip`.

One guard, before the first index:

    if len(ops) < 3:
        raise Unsupported('image instruction with %d operands, expected at least 3' % len(ops))

Measured through the real `Stage` entry point:

    image_sample v[8:11], v0    before: translator crash in image_sample: IndexError
                                after:  image instruction with 2 operands, expected at least 3
    image_load v[8:11]          before: translator crash in image_load: IndexError
                                after:  image instruction with 1 operands, expected at least 3

The three-operand forms are untouched: `image_load v[8:11], v0, s[16:19]` still reports the descriptor operand,
so the guard only replaces the crash.

`tests/startup_gfx2hlsl_image_arity_check.py` is a new, focused check rather than an addition to
`startup_gfx2hlsl_handler_arity_check.py`, which an in-flight PR is editing; it asserts the refusal at one and
two operands for all seven forms and that the refusal is not `translator crash`. Registered in `CMakeLists.txt`,
listed in the Linux CI check list and in AGENTS.md.

Fail-first: removing exactly the guard fails the check with
`('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')])`, and restoring it
returns exit 0. All 58 `tests/startup_gfx2hlsl_*_check.py` exit 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:45:55 +00:00
github manually merged commit 56c1379f44 into gh-pr/2373/base 2026-11-27 00:45:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.