startup: refuse a buffer load with no operands instead of indexing an empty list #2352
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2360"
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-25T13:36:34Z.
What
op_buffer_load_dwordandtbufferreadops[0]beforebuffer_address()can reach its own operand-count check, so an instruction with no operands at all came back as an index error from inside the handler:translator crash in …is the batch translator's marker for a translator defect (Stage.translate records any non-Unsupportedexception that way), not for an instruction it does not lower, and the single-shader path does not catch it at all.Two lines, each in the one body several handlers share:
op_buffer_load_dwordcoversbuffer_load_dword/x2/x3/x4,tbuffercoverstbuffer_load_format_x/xy/xyz/xyzw. Eight handlers.Why the guard is "empty list" and not "not four"
A short operand list that still carries a modifier must keep refusing on the modifier. The
ldsform decodes to three operands, andstartup_buffer_address_check.pyasserts exactly that:Checking
len(ops) != 4at the head of the body shadows that message — I tried it first and this fixture caught it, which is the reason the guard is as narrow as it is. The shared message did gain the expected count (buffer load with %d operands, expected 4), matching the phrasing the scalar handlers use; nothing asserted the old text.Fail-first, one control per guard
Removing each guard alone, with the flag this check exists to catch:
The check
tests/startup_gfx2hlsl_handler_arity_check.pygains arefuse()helper for handlers whose accepted form needs a bound descriptor, and sixteen assertions: the empty and one-operand form of each of the eight loads. It asserts three things per case — exactly one refusal, no emitted block, and that the refusal is nottranslator crash …— so a handler that starts raising something else fails here too.Verification
Both exit 0, and all 57
tests/startup_gfx2hlsl_*_check.pyexit 0 on this branch.What this does not touch
The remaining handlers that index operands without a count check (
image_load,image_sample*,v_cndmask_b32,v_mov_b32,s_bitcmp*, …) are unchanged: they do not share one body with the loads, so each needs its own line and its own accepted-form fixture. That is a separate slice.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:39:45Z.
Review: COMMENTED
Review of head
74d9c46d4d(0 P1 / 0 P2).Scope:
tools/startup/gfx2hlsl.pyandtests/startup_gfx2hlsl_handler_arity_check.pyonly. A MUBUF or MTBUF load with an empty operand list used to hitops[0]and surface as a translator crash (IndexError). It is now a cleanUnsupportedrefusal. The new guard sits only on the empty-list path, so the shared check inbuffer_address()still refuses the other short forms, including the lds form that decodes to three operands.Checks (run locally):
python3 tests/startup_gfx2hlsl_handler_arity_check.py-> PASS (33 accepted, 99 scalar refusals, 16 load refusals)python3 tests/docs_links_check.py-> PASSpython3 tests/bidi_controls_check.py-> PASSgit diff --check origin/main...HEAD-> cleanMutations (each reverted with
git checkout -- .):if not ops:guard inop_buffer_load_dword. The test failed withtranslator crash in buffer_load_dword: IndexError.len(ops) != 4withlen(ops) < 0inbuffer_address(). The 1-operand case failed with the same IndexError.Notes: the change touches Python and test files only. GitHub checks for the fixtures and the Linux Python job pass. The Windows job was still running when this was written.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T13:48:58Z.
Ready behind this one: the image bodies have the same defect
Same shape as the two buffer bodies, seven handlers instead of eight:
image()reads vdata, an address and a descriptor and indexed them without a countcheck, so a short list reached
ops[1]orops[2]:Covered:
image_sample,image_sample_l,image_sample_lz,image_sample_b,image_get_lod,image_load,image_load_mip— one guard,len(ops) < 3,placed before the first index. Fail-first control removes exactly that guard and the check reports
('image_sample', ('v[8:11]',), [('translator crash in image_sample: IndexError', 'ps')]).It is pushed as
startup/image-arityin my fork and I am not opening it as a second PR yet, because both changes add the samerefuse()helper at the sameanchor in
tests/startup_gfx2hlsl_handler_arity_check.py— two PRs adding it would conflict in exactly that hunk, and you would have to resolve a duplicate youdid not write. Once this one lands I will rebase and open it as the one-file change it is; if you would rather see both together, say so and I will fold it in
here instead.
Baseline check for the "did it break anything" question, since a lot of
startup_*checks need a renderer and fail with no arguments: the failing set of all148
tests/startup_*_check.pyrun with no arguments is identical on this branch and onmain(51 each, zero added, zero removed), so the only checks thatmove are the ones this PR touches.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T13:50:06Z.
Thanks — and your second mutation is the one I would keep: disabling
if not ops:only proves the empty case is covered, whilelen(ops) != 4→len(ops) < 0proves the shared check still guards the short-but-nonempty forms. That pair is exactly the split I was worried about whenI first wrote a full
len(ops) != 4guard at the head of the body andstartup_buffer_address_check.pyrejected it on theldscase.Two things to close the loop on what was still pending in your write-up:
so all four jobs are green on this head; nothing is waiting on Windows.
One caution about reverting with
git checkout -- .rather than the single file: in a branch like this one the working tree also holds the intended change, so ablanket checkout drops the patch too, not just the mutation. I lost an earlier iteration of this exact PR that way — the safe order is commit first, then mutate.
Nothing else from my side; the image counterpart is pushed as
startup/image-arityand waits behind this one as described above.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T14:04:45Z.
Update on the image slice I said was waiting behind this PR: I took it out of your conflict path instead of waiting.
#2373now carries it with a new check file (tests/startup_gfx2hlsl_image_arity_check.py) rather than adding arefuse()helper tostartup_gfx2hlsl_handler_arity_check.py, so it touches none of the lines this PR edits and the two can land in either order. The production change is unrelated to this one —image()instead of the two buffer bodies.If you would rather have one arity file with both families, say so and I will fold the image assertions into this PR and close #2373; the refusals are additive and the merge is mechanical. Otherwise both stand on their own.
AI-assisted.