Skip to content

rdna2spirv: a missing spirv-as/spirv-val is one setup error, not a traceback - #3768

Open
216598762 wants to merge 2 commits into
ItsNotRexed:mainfrom
216598762:build-rdna2spirv-missing-tool
Open

216598762 wants to merge 2 commits into
ItsNotRexed:mainfrom
216598762:build-rdna2spirv-missing-tool

Conversation

@216598762

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #3574 (comment)

What and why

assemble_spirv starts spirv-as and spirv-val directly. When SPIRV-Tools is not on PATH, the first shader raises FileNotFoundError out of main(): python -I tools/image_fuzz.py --programs 1 reproduces it at rdna2spirv.py:13604. A missing external tool is a setup error for the whole run, not a bad shader, so main() now catches only an OSError naming spirv-as or spirv-val, prints one ERROR: line and returns 2. Other OSErrors are re-raised.

The catch is at the main() call site, so it does not conflict with #3423, which rewrites assemble_spirv itself; no other tool calls assemble_spirv directly.

Tested

  • python -I tests/test_rdna2spirv_cli.py: 27 tests, OK (1 skipped). New tests cover a missing assembler and a missing validator: each returns 2 with one ERROR: line, no Traceback, no .spv, and no .tmp.
  • python -m compileall -q tools tests: clean. git diff --check: clean.
  • CLI with a valid ps_fixture and a PATH without SPIRV-Tools: exit 2, ERROR: spirv-as not found; install SPIRV-Tools ..., 0 tracebacks, only .spvasm written (no .spv/index).
  • image_fuzz.py --programs 1 with llvm-mc present and no spirv-as: exits 1 with translator failed: plus the one ERROR line, 0 tracebacks. Before: FileNotFoundError traceback.
  • Python 3.14.10, Linux. No GPU and no game files.

AI-assisted.

Depends on: none. (Same file as #3423 but different lines: it rewrites assemble_spirv; this changes the main() call site.)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • Not a new translator rule, so no contract-table change is needed.

assemble_spirv raises FileNotFoundError when spirv-as or spirv-val is not on
PATH. Report that once from main (exit 2) instead of failing the first shader
with a traceback; image_fuzz reproduces it when SPIRV-Tools is absent.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 277a567d: python -I tests/test_rdna2spirv_cli.py -> 27 tests, OK (1 skip); compileall clean; git diff --check clean.

The two mocked cases match the real failure mode: subprocess.run raises FileNotFoundError with filename set to spirv-as/spirv-val, and the new handler returns 2 with one line and leaves no .tmp, module or index. Catching only those two filenames (re-raising any other OSError) is the right scope.

One nit: with --assembler python the message still says "install SPIRV-Tools (spirv-as, spirv-val)", which is fine for spirv-val, but if a user gives a renamed --assembler there is no way to pass one; no action needed.

No blocker from me.

@ray3242

ray3242 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, a missing spirv-as still ends in a traceback at this PR's head. I reproduced it:

run output exit
Windows CPython 3.12.10 (embeddable amd64) under Wine 6.0.3, spirv-as not on PATH: python -I tools\rdna2spirv.py <disasm> --out <spirv> with the same ps_fixture.s / .dxbc as the tests Traceback ... rdna2spirv.py, line 13604, in assemble_spirv ... FileNotFoundError: [WinError 2] File not found 1
Same fixture on Linux CPython 3.12.16, PATH=/nonexistent the new ERROR: spirv-as not found; ... line 2

Cause: on Windows, subprocess gets the error from _winapi.CreateProcess and never sets a filename. A bare subprocess.run(["spirv-as", ...]) in the same Windows CPython raises FileNotFoundError with filename=None, winerror=2. The new if e.filename not in ("spirv-as", "spirv-val"): raise then re-raises it. The new tests mock FileNotFoundError(2, ..., "spirv-as"), the POSIX form, so they pass either way.

A fix that works on both: catch FileNotFoundError around each tool call inside assemble_spirv, where the code knows which tool it started, and report that tool by name without reading e.filename. A test that raises FileNotFoundError(2, "The system cannot find the file specified") with no filename would cover the Windows case.

Tested at 277a567. AI-assisted (Devin).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on Windows at 277a567 using the normal CLI. With only spirv-as missing and with only spirv-val missing, both exited 1 with a traceback; CreateProcess left e.filename unset. Both-tools-present control translated and validated. All 27 tests pass because their synthetic exceptions supply a filename. Catch the missing executable at its known launch site and preserve #3423's stdin and relative-path behavior. AI-assisted synthetic CPU review.

@tupacfan04

Copy link
Copy Markdown
Contributor

The intent is right, but the fix does not work on Windows.

With PATH stripped of SPIRV-Tools and a valid ps_fixture:

  • main: exit 1 with FileNotFoundError: [WinError 2] ... 'spirv-val' and a traceback.
  • this head: identical - exit 1 with the same traceback, no ERROR: line.

Cause: tools/rdna2spirv.py:13793 tests e.filename, but on Windows a CreateProcess failure raises FileNotFoundError(WinError 2) with filename=None (I confirmed filename=None errno=2 winerror=2), so the raise path is taken. The new test misses it because tests/test_rdna2spirv_cli.py:289-292 injects a POSIX-style filename.

Suggestion: recognise it by e.errno == errno.ENOENT / e.winerror == 2 / the command string rather than e.filename, or set filename-independent matching; then the same test can cover the Windows shape.

Everything else is fine: tests/test_rdna2spirv_cli.py 27 OK (1 skipped), decode/merge 23 OK each, compileall and git diff --check clean, merge clean, and the negative control errors with FileNotFoundError on main.

AI-assisted review, no game files, no GPU.

…ception

A Windows CreateProcess failure raises FileNotFoundError(2, ..., None, 2), so
OSError.filename is None and the setup-error check re-raised it as a traceback.
assemble_spirv now raises SpirvToolMissing naming cmd[0], built at the call
site, and the tests model the Windows exception shape.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@216598762

Copy link
Copy Markdown
Contributor Author

Fixed at 9129abc5 — both reproductions were right, thanks.

Cause is exactly what @kacper-serewis described: a Windows CreateProcess failure is FileNotFoundError(2, "The system cannot find the file specified", None, 2), so OSError.filename is None and the setup-error check re-raised it as a traceback. Reading the tool name back off the exception cannot work there.

The fix names the tool where the command is built: assemble_spirv runs spirv-as and spirv-val through _run_spirv_tool, which turns a FileNotFoundError into SpirvToolMissing(cmd[0]); main catches that and prints the same one-line error with exit 2, before anything is published.

Tests (python -I tests/test_rdna2spirv_cli.py): 28 tests, OK (1 skip). The two setup-error tests now raise the Windows shape (FileNotFoundError(2, ..., None, 2) instead of an exception carrying a filename), so they fail on the previous head (I measured 3 errors there) and pass now; a third test pins SpirvToolMissing.tool == "spirv-as" and that the .spv is not published.

I could not run this on Windows myself (Linux box, no Win32 CLI here), so the Windows failure is modelled in the tests rather than executed on it. A re-run of the two cases on Windows would settle it. No GPU used; no game files. AI-assisted (Codebuff).

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.

5 participants