Skip to content

spirv_gs_to_compute: a missing or failing spirv-dis/spirv-as is one ERROR line and exit 2 - #6235

Open
evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-gsc-tools-error
Open

evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/8-gsc-tools-error

Conversation

@evilclanker9000

@evilclanker9000 evilclanker9000 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

tools/spirv_gs_to_compute.py now reports a SPIRV-Tools binary it cannot run as one ERROR: line and exit 2, the way the other tools in tools/ report a missing or failing external program. Before, main() let the exception out:

  • spirv-dis/spirv-as not on PATH (the docstring only says they are needed): FileNotFoundError: [WinError 2] The system cannot find the file specified, exit 1.
  • a module spirv-dis refuses to disassemble, or the rewritten module spirv-as rejects: subprocess.CalledProcessError, and the assembler's own message was nowhere in the output.

Both lines name SPIRV_DIS / SPIRV_AS, the override the docstring already documents, and keep the tool's own last line of stderr so the reason is visible. spirv-as output is captured for that; it is only read on failure.

Test

python -m pytest tests/test_spirv_gs_to_compute.py -q (SPIRV-Tools on PATH, no GPU):

  • before: RAISED FileNotFoundError [WinError 2] The system cannot find the file specified (same call, loaded from upstream/main's copy of the tool), and the two new tests fail.
  • after: 29 passed in 3.38s.

Reproduced from the shell too, on upstream/main's base of this branch:

$ python -I tools/spirv_gs_to_compute.py empty.bin o.spv   # no SPIRV-Tools on PATH
Traceback (most recent call last): ... FileNotFoundError: [WinError 2] ...
$ SPIRV_DIS=no-such-spirv-dis python -I tools/spirv_gs_to_compute.py empty.bin o.spv
ERROR: no-such-spirv-dis not found: install SPIRV-Tools, put it on PATH, or set SPIRV_DIS to it
$ SPIRV_DIS=<python> python -I tools/spirv_gs_to_compute.py empty.bin o.spv
ERROR: empty.bin is not a SPIR-V module <python> can read: Try `python -h' for more information.

The new tests need neither SPIRV-Tools nor a GPU: SPIRV_DIS is set to a name that does not exist, then to sys.executable, whose --raw-id exits 2.

Notes

  • Item: EGEN-GSC-TOOLS-ERROR. Reported first as a finding: in the coordination issue.
  • Scope kept to the two subprocess calls. A successful spirv-dis whose output has no OpCapability is still rewrite()'s problem, not an I/O error.
  • capture_output=True on spirv-as is the only behaviour change on the success path: nothing reads them there, so the assembled module is unchanged (the full test file, which assembles and validates real modules, passes).
  • No docs row: the docstring already states the SPIRV_DIS / SPIRV_AS override, and this only makes the failure follow it.

AI-assisted.

…RROR line and exit 2

subprocess raised FileNotFoundError (SPIRV-Tools not on PATH) and CalledProcessError (a module spirv-dis or spirv-as refuses) straight out of main(), so the tool ended in a traceback where every other tool prints one ERROR line and exits 2. The docs already tell the user SPIRV_DIS / SPIRV_AS override the binary name, so the line names the variable to set. spirv-as's output is captured now so its own last line can be reported instead of being lost in a traceback.
…nonzero exit

Both tests fail on the previous commit: the missing binary raised FileNotFoundError out of main(), and a disassembler that exits nonzero raised CalledProcessError. They need neither SPIRV-Tools nor a GPU: SPIRV_DIS is set to a name that does not exist, then to sys.executable, whose --raw-id exits 2.
@AsgerCode

Copy link
Copy Markdown

Tested 89c9440 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files, no SPIRV-Tools on PATH): fail, a SPIRV_DIS/SPIRV_AS that exists but cannot be started (a folder, a non-.exe file) still gives a traceback and exit 1

What I ran:

  • python -I -m pytest tests/test_spirv_gs_to_compute.py -q: 4 passed, 25 skipped (the skipped tests need SPIRV-Tools or llvm-mc). Both new tests run here. tests/test_spirv_gs_to_compute_bounds.py: 6 passed.
  • Negative control (merge-base tools/spirv_gs_to_compute.py, PR tests): both new tests fail (FileNotFoundError [WinError 2], and CalledProcessError ... exit status 2). The tests catch the spirv-dis change.
  • Merge with current main (8575d36e): clean (main added spirv_gs_to_compute: reject OpEmitVertex in a loop header before OpLoopMerge (SHADER-617) #3319 to the tool). On the merged tree: 11 passed, 25 skipped, and the table below is the same.
  • Not run: a real spirv-dis/spirv-as (no Vulkan SDK here). I reached the spirv-as call with .bat fakes: SPIRV_DIS prints the test file's PHI_GS text, and SPIRV_AS exits 1 with a message on stderr.
SPIRV_DIS / SPIRV_AS PR head merge base
SPIRV_DIS = name not on PATH exit 2, one ERROR: ... not found line FileNotFoundError traceback
SPIRV_DIS = a folder exit 1, PermissionError: [WinError 5] Access is denied traceback same
SPIRV_DIS = a text file exit 1, OSError: [WinError 193] %1 is not a valid Win32 application traceback same
SPIRV_DIS = empty exit 1, OSError: [WinError 87] traceback same
SPIRV_AS = name not on PATH exit 2, one ERROR line traceback
SPIRV_AS = a folder exit 1, PermissionError traceback same
SPIRV_AS exits 1 exit 2, one line with the assembler's last stderr line CalledProcessError traceback
SPIRV_AS exits 1, byte 0x81 on stderr exit 2, but Exception in thread ... UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 is printed first, and the ERROR line has no detail CalledProcessError traceback

The bug: only FileNotFoundError is caught. If you point SPIRV_DIS at the SDK Bin folder instead of spirv-dis.exe, the tool still prints a traceback. That is an easy mistake, and the new error line tells the user to set that variable. Suggested fix: after each except FileNotFoundError, add except OSError as e: that prints ERROR: cannot run {dis}: {e.strerror or e} and returns 2. Also pass errors="replace" on the spirv-as call, because its output is now captured and decoded. I applied both changes locally: every row above became one ERROR line and exit 2, and the test file still passed.

Nits, none blocking:

  1. Neither new test reaches the spirv-as half. A test that monkeypatches gsc.subprocess.run to succeed once and then raise CalledProcessError would cover it without SPIRV-Tools.

Overlap with open PRs (all change the same two subprocess.run calls):

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 89c9440 merged with main 1ce6eb5 on Linux/Python 3.12.16: pass

Merge was clean (tools/spirv_gs_to_compute.py, tests/test_spirv_gs_to_compute.py).

  • python -I -m pytest -q tests/test_spirv_gs_to_compute.py (pytest-style file): 4 passed, 25 skipped (the skips need spirv-as and spirv-val, which are not installed here).
  • Negative control (tools/spirv_gs_to_compute.py restored from upstream/main, tests from the PR): 2 failed, 2 passed, 25 skipped: test_missing_spirv_dis_is_one_error_line and test_spirv_dis_that_refuses_the_input_is_one_error_line. PR version restored afterwards.

Diff read: a missing spirv-dis or spirv-as (FileNotFoundError) and a nonzero exit from either (CalledProcessError) now print one ERROR: line and return 2, naming the SPIRV_DIS/SPIRV_AS variable for the missing case, instead of a traceback; the assembler call now captures its output so its last line can be quoted. The two new tests need no SPIRV-Tools (they use a nonexistent binary and the Python executable as a stand-in). The 25 skipped tests, which run the tool end to end with the real SPIRV-Tools, were not run here.

@yuruiwang233

Copy link
Copy Markdown

Code read (CPU only) - I did not run the suite; checks here are still 0/2 pending, so this is a read of the diff, not a test report.

What I checked:

  • Both call sites now catch FileNotFoundError and CalledProcessError and return 2 with a single stderr line, which matches the error style the rest of tools/ uses. The two new tests pin the exact wording for the missing binary and the shape for the refusing one, and the body documents the negative control (2 failed with the tool reverted), which is what makes the tests meaningful.

Three notes, all non-blocking:

  1. Only FileNotFoundError is caught. A SPIRV_DIS/SPIRV_AS that exists but is not executable raises PermissionError, and an unusable format raises a plain OSError (EXEC format), so those still traceback. Catching OSError would cover both and lets the same one-line message serve.
  2. Test 2 uses sys.executable as the failing tool, so its expected text is whatever CPython prints for an unknown option, and the count of colons in that line is now part of the assertion. A short script written to tmp_path under a POSIX-only skip would pin the message; if the Windows run must keep sys.executable, one line of comment saying why would save the next reader.
  3. On the assembler path, if spirv-as creates out.spv and then fails, the partial file stays behind. The new test only checks the dis-failure path, so consider unlinking args[1] in the CalledProcessError branch before returning 2, to keep the promise that a nonzero exit leaves no output.

Otherwise LGTM.

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.

4 participants