Skip to content

spirv_gs_to_compute: one ERROR line and exit 2 for a missing input, a missing spirv-dis/spirv-as, or an unwritable --layout - #6428

Open
evilclanker9000 wants to merge 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/7-spirvgs-tool-errors
Open

evilclanker9000 wants to merge 4 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/7-spirvgs-tool-errors

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

tools/spirv_gs_to_compute.py runs spirv-dis and spirv-as with check=True and no guard, and writes --layout unguarded. So the three ordinary failures — a nonexistent input, a SPIRV-Tools binary that is not on PATH (or a wrong SPIRV_DIS/SPIRV_AS), and a --layout under a folder that does not exist — each ended in a Python traceback, and the missing input exited 1 instead of the exit 2 BUILD-1046 asks of a missing input. This makes each one a single ERROR: line and exit 2, and keeps the refusing tool's own first stderr line so the reason is still visible.

The happy path is unchanged: a valid geometry module still lowers, writes the layout and validates (below).

Test

Both directions, tests/test_spirv_gs_to_compute.py (needs no SPIRV-Tools on PATH for the three new tests: the input check runs before spirv-dis, and the other two fake the subprocess):

python -m pytest tests/test_spirv_gs_to_compute.py -q
  • before this branch: test_cli_names_a_missing_input_in_one_line fails — assert 1 == 2, stderr is FileNotFoundError ... traceback; test_cli_names_a_disassembler_that_cannot_start fails the same way; test_cli_names_an_assembler_that_cannot_start_or_refuses lets FileNotFoundError: [Errno 2] ... 'spirv-as' escape main().
  • after: 6 passed, 25 skipped (the skips need spirv-as/spirv-val on PATH).

Command line, before and after (main f6c6d11ee vs this branch):

python -I tools/spirv_gs_to_compute.py no-such.spv out.spv
before: Traceback (most recent call last): ... FileNotFoundError: [WinError 2] (exit 1)
after:  ERROR: input not found: no-such.spv (exit 2)

SPIRV_DIS=no-such-dis python -I tools/spirv_gs_to_compute.py make_game.py out.spv
after:  ERROR: cannot run no-such-dis: The system cannot find the file specified (install SPIRV-Tools or set SPIRV_DIS) (exit 2)

Happy path on this machine, with SPIRV_DIS/SPIRV_AS pointed at the local SPIRV-Tools build and a hand-assembled PHI_GS module (the one already in the test file, written to a scratch file outside the branch):

spirv-as --target-env vulkan1.2 gs.spvasm -o gs.spv
SPIRV_DIS=.../spirv-dis.exe SPIRV_AS=.../spirv-as.exe python -I tools/spirv_gs_to_compute.py gs.spv gs_cs.spv --layout gs_lay.json
exit 0; gs_lay.json = {"verts_in": 3, "max_verts": 3, "topology": "triangle_strip", "inputs": ["position"], "outputs": ["position"], "local_size": 64}
spirv-val --target-env vulkan1.2 gs_cs.spv -> exit 0

tools/spirv_gs_to_compute.py with a real spirv-dis that refuses a non-module now also prints one line: ERROR: ...spirv-dis.exe refused gs_spvasm.txt: error: file size should be a multiple of 4; file 'gs_spvasm.txt' corrupt (exit 2).

  • python -m compileall -q tools/spirv_gs_to_compute.py tests/test_spirv_gs_to_compute.py -> 0
  • python -m pytest tests/test_spirv_gs_to_compute_bounds.py -q -> 6 passed

No GPU needed: no translation or dispatch is involved.

Notes

  • Exit 2 (not 1) for all three, because each is a usage error — the rule tests/test_missing_input_exit_codes.py encodes. An input that parses but holds an unsupported op still exits 1 from Unsupported, unchanged.
  • The --layout guard comes with the same commit series: without it the module is already written when the layout write fails, so it was the same class of half-done run.
  • _why() returns the tool's first stderr line (or exit N when it printed nothing), so a refusal says why instead of just naming the path.
  • I did not document exit codes in the module docstring: its last two lines are what --help prints and a test pins those two lines.

AI-assisted.

spirv-dis runs with check=True, so a nonexistent input died in a FileNotFoundError traceback (exit 1) before any message; check the input path first, as BUILD-1046 asks of every tool.
A spirv-dis that is not on PATH (or a wrong SPIRV_DIS) raised FileNotFoundError out of subprocess.run; print one ERROR line that names the tool and the variable, and exit 2 like the path guards already do, and keep a refusal's own first stderr line.
The assembler ran with check=True unguarded: a spirv-as that is not on PATH raised FileNotFoundError, and a refusal raised CalledProcessError, both as a traceback. One ERROR line naming SPIRV_AS, with the tool's own first stderr line when it refused the module.
The layout JSON was written unguarded after the module, so a --layout under a folder that does not exist left a traceback behind a module that had already been written.
@memorypressure

Copy link
Copy Markdown

Verified merged with main 1cc6e3c: the tool's suite runs 31 tests (pytest, re-run) and passes, the four new ERROR-line tests fail on clean main, and the bounds suite stays green; the stubbed spirv-dis/spirv-as paths mean no SPIRV-Tools install is needed (and under python -I the file hard-fails on import pytest rather than silently running nothing). Heads-up for ordering: I merge-tested it against the current head of the long-running #4149 — both edit tools/spirv_gs_to_compute.py and conflict, so whichever merges second needs a rebase. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@skorex

skorex commented Nov 23, 2026

Copy link
Copy Markdown

Duplicate of #6235

#6235 makes the same change and was opened earlier. Topic: spirv_gs_to_compute: missing spirv-dis/as = one error line.

Suggest closing this PR in favour of #6235, and porting anything this one adds that #6235 lacks there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants