Skip to content

rdna2spirv: an unreadable shader input is one error line, not a traceback - #8253

Open
ne1i wants to merge 2 commits into
ItsNotRexed:mainfrom
ne1i:rdna2spirv-unreadable-input
Open

ne1i wants to merge 2 commits into
ItsNotRexed:mainfrom
ne1i:rdna2spirv-unreadable-input

Conversation

@ne1i

@ne1i ne1i commented Nov 23, 2026

Copy link
Copy Markdown

translate() reads a shader's listing, its container (<name>.dxbc) and its sidecars (fssm/<name>.fssm, fspx/<name>.json), but main() caught only FileNotFoundError. An input that exists and cannot be read (a directory where a file belongs, or a file without read permission) raised IsADirectoryError / PermissionError and ended the whole run in a traceback, so every shader after it went untranslated.

It is now handled the way a missing required input already is (#6292): one ERROR: <shader>: cannot read translation input <path>: <reason> line, the shader's previous module and index entry are retired, the run continues, a summary line counts the unreadable inputs, a --shard run publishes no part, and the exit code is 1. A missing input keeps its existing message, and a readable run is unchanged. Only main()'s file handling changes; no translation rule.

Two points for review:

The existing test_missing_dispatch_invalidates_completed_shard (interrupted case) put a directory at the .dxbc path and passed only because the traceback text contained that path; it now asserts the tool's own error line and no traceback.

Tested on Linux, CPython 3.14, CPU only, synthetic listings and stubs: python -I tests/test_rdna2spirv_cli.py 39 OK (1 skipped); with only the tool reverted, 8 failures. tests/test_rdna2spirv_merge.py, compileall, check_no_game_data.py and git diff --check are clean. Not run: the full tests/semantic suite. Independent of #8066, which touches the resume-index read.

Claim: #8047.

AI-assisted (DeepSeek V4.1 Flash wrote it; reviewed and re-verified with Claude Code).

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified via Tier 2 Free Cloud (Groq gpt-oss-120b): Reporting individual unreadable inputs as actionable error lines while continuing batch translation ensures that an unreadable sidecar or container directory does not abort the entire batch with an unhandled traceback.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested on Windows 11 (26100), CPython 3.14.7, CPU only, without spirv-as/spirv-val on PATH, no game files.

Tool Verification: Pass

The tool change in tools/rdna2spirv.py works as intended:

  • except OSError as e: correctly catches unreadable translation inputs (on Windows, opening a directory as a file raises PermissionError, which inherits from OSError).
  • The diagnostic ERROR: <name>: cannot read translation input <path>: <reason> is printed without a traceback, unreadable_inputs is incremented, and drop_stale(name) correctly purges the stale module and index entry.

Test Issue on Environments Without SPIRV-Tools: 3 Failures

In tests/test_rdna2spirv_cli.py:
UnreadableInput.run_tool() runs a subprocess that translates both the unreadable shader and ps_ok. Because ps_ok translates successfully, rdna2spirv.main() proceeds to invoke spirv-as. On environments without spirv-as on PATH:
rdna2spirv prints ERROR: spirv-as not found; install SPIRV-Tools (spirv-as, spirv-val) and put it on PATH and returns exit code 2 (rdna2spirv.py:18218), causing:

AssertionError: 2 != 1 : ERROR: ps_bad: cannot read translation input ...\ps_bad.dxbc: Permission denied
ERROR: spirv-as not found; install SPIRV-Tools (spirv-as, spirv-val) and put it on PATH

This causes test_an_unreadable_shader_retires_its_previous_module_and_index_entry and both directory subcases of test_each_unreadable_input_kind_is_one_error_line_and_the_run_continues to fail with AssertionError: 2 != 1.

Suggestion

Either:

  1. Add @unittest.skipUnless(shutil.which("spirv-as") and shutil.which("spirv-val"), "requires SPIRV-Tools") to the tests that compile ps_ok via subprocess (matching line 416 of test_rdna2spirv_cli.py); OR
  2. In test_each_unreadable_input_kind_is_one_error_line_and_the_run_continues, accept p.returncode in (1, 2) (or check p.returncode == (1 if shutil.which("spirv-as") else 2)).

test_a_missing_input_keeps_the_message_it_had and test_a_readable_run_is_unchanged pass (the latter mocks spirv-as), and self.deny() properly skips on Windows where chmod 0 does not deny read.
compileall, check_no_game_data.py, and git diff --check are all clean.

AI-assisted.

@jacob-rowlands

Copy link
Copy Markdown

Tested baa652c11 merged onto main dde82f27e on Linux (CachyOS, Python 3.14.10, as a non-root user, SPIRV-Tools on PATH), no game files: pass.

  • python3 -I tests/test_rdna2spirv_cli.py -v: 39 OK. The 1 skip is the Windows-only unmapped-drive case. All four UnreadableInput tests pass, including test_each_unreadable_input_kind_is_one_error_line_and_the_run_continues. On POSIX a file without read permission really can't be opened, so that kind is exercised here.
  • With spirv-as/spirv-val available, the three tests that failed for @LAKSHYA-cmd-tech pass. That's consistent with their reading that run_tool() needs SPIRV-Tools for the ps_ok shader, so it's an environment dependency in the test, not a tool problem.
  • The semantic suite has the same 2 files failing as main. run_gpu_tests.py gives the same results as main on a Ryzen 5 7600X iGPU (RADV) and an RTX 3080, with and without LEONIDA_W64_EMULATE=1.

AI-assisted (Claude Code).

@tupacfan04 tupacfan04 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.

The unreadable-input handler itself works when SPIRV-Tools is present; the no-SPIRV-Tools test failure is already covered by LAKSHYA-cmd-tech's review, so I won't repeat it. Two other gaps remain:

  1. A truncated/short input can still traceback. The new handler is only except OSError around translate(p) (tools/rdna2spirv.py:18144-18151). A truncated .dxbc or FSSM sidecar is readable, so it does not raise OSError; a short struct.unpack can raise struct.error, which is caught neither by the new handler nor by the existing except (IndexError, KeyError, ValueError) at :18156. Add a zero-byte/short .dxbc and FSSM test, and catch struct.error (or validate lengths and raise Unsupported) beside the translator-error handling.

  2. Output writes and stale cleanup are outside the handler. translate(path) only reads, but open(sa, "w") at :18165, drop_stale() at :18126-18131 (a directory at the old .spv path raises IsADirectoryError), and write_index() at :18217 can still traceback. The PR body's statement that an output-write OSError is reported as “cannot read translation input” is not accurate for these paths. Either narrow the read handler and add explicit write/cleanup handling, or add an unwritable-output test and document the behavior.

Checked: with tools present, a directory or permission-denied listing/container/sidecar produces one ERROR: ... cannot read translation input line, increments unreadable_inputs, calls drop_stale, continues to ps_ok, writes the index/part rule and returns 1; a missing input keeps its existing message; a shard with an unreadable input publishes no part/index; a valid run is unchanged. Synthetic only; no game files. AI-assisted (OpenCode).

…y run without SPIRV-Tools

UnreadableInput.run_tool() translated a second, readable shader (ps_ok) through the real CLI, so the run reached
spirv-as; with SPIRV-Tools absent that is the tool's 'spirv-as not found' setup error and exit 2, and three tests
failed with 'AssertionError: 2 != 1'. Drive main() with subprocess.run stubbed for spirv-as/spirv-val, as the file's
other in-process tests already do, so the whole class runs anywhere and still asserts exit 1, the single ERROR line,
the good shader translated and the stale module retired. One new real-CLI test covers the unreadable path alone (no
shader translates, so no assembler is needed).
@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks, reproduced and fixed in b2b5ab45a (tests only; the tool is unchanged).

With SPIRV-Tools off PATH the good shader in the same run still translates, the run reaches spirv-as, and the tool exits 2 with its setup error, which is your 2 != 1. UnreadableInput.run_tool() now drives rdna2spirv.main() in-process with subprocess.run stubbed for spirv-as/spirv-val, the mechanism the file's other in-process tests already use, so the tests still assert exit 1, the single error line, the good shader's module and the retirement, without accepting either exit code. A new real-CLI test covers one unreadable input alone, where nothing translates and no assembler is called.

Re-run on Linux, CPython 3.14, CPU only, synthetic inputs:

  • SPIRV-Tools on PATH: python -I tests/test_rdna2spirv_cli.py Ran 40 tests, OK (skipped=1).
  • PATH with only python and git: Ran 40 tests, OK (skipped=2); the extra skip is the existing skipUnless(shutil.which("spirv-as")) test.
  • Same stripped PATH with only tools/rdna2spirv.py reverted to main: FAILED (failures=2, errors=7).

Not run on Windows here, so a re-check there would be welcome.

AI-assisted (DeepSeek V4.1 Flash; re-run with Claude Code).

@justrealyme

Copy link
Copy Markdown

Tested b2b5ab4 on Windows 11 build 26300, CPython 3.12.9: pass.

python -I tests/test_rdna2spirv_cli.py: OK (6 skipped). (Under CPython 3.10 the file errors on enterContext, which unittest only has from 3.11; CI uses 3.12, so that is not a problem for this PR.)

Synthetic inputs only, no game files. AI-assisted (Claude Code).

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.

6 participants