Skip to content

Preserve the verified fallback shader disassembly - #8334

Open
CristoDeveloper wants to merge 4 commits into
ItsNotRexed:mainfrom
CristoDeveloper:fix/shader-disasm-scan-result
Open

CristoDeveloper wants to merge 4 commits into
ItsNotRexed:mainfrom
CristoDeveloper:fix/shader-disasm-scan-result

Conversation

@CristoDeveloper

@CristoDeveloper CristoDeveloper commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: #8186 — shader_disasm fallback scan

Depends on: #7980 (overlapping fallback loop; this patch builds on main)

What and why

When the FSSM header does not identify the code range, publish the listing produced by the fallback scan. This removes a redundant decoder invocation and prevents a successful scan from publishing a listing with invalid instructions.

Root cause

The scan saved only the start offset of the longest candidate with zero invalid-instruction diagnostics. An invocation that failed without those diagnostics was also assigned that offset. The next invocation supplied the output for publication, even when its diagnostics differed from the scan's.

Impact

In synthetic tests, the old code failed after already decoding a clean candidate and separately exited 0 after publishing a candidate with one invalid instruction. With this change the first case writes the verified listing, and the second exits 1 without publishing a file.

Implementation

Retain the decoder result and its offset together. If the widest candidate without invalid-instruction diagnostics returned empty output, pass that result to the existing error path. A narrower successful decode is insufficient to establish where the program starts. If a per-shader decode produces no listing, remove that shader’s previous output so --skip-existing retries it. The global toolchain probe runs before any shader is processed.

Tested

Windows 11 (build 26200), Python 3.12.10, CPU only. Relevant upstream files were verified by blob hash and tested with synthetic inputs.

  • python -I tests/test_shader_disasm.py — 32 passed, one skipped. Two regressions fail with the original production file and pass with the patch. Separate cases check total decoder failure and a retry after a failed decode with an older listing present. Before the review fix, the older listing survived and the retry exited 0 with reused: 1.
  • python -I tests/test_mc_command.py SplitCommandTest MissingLlvmMcTest.test_run_names_the_command_and_how_to_set_it MissingLlvmMcTest.test_run_names_the_tools_own_option MissingLlvmMcTest.test_run_passes_a_command_that_starts_through — 19 passed.
  • python -I tests/test_report_paths.py SamePathTests MacVolumeTests FoldingVolumeTests — 17 passed, two platform-dependent skips.
  • python -m compileall -q tools tests scripts on the fetched files, git diff --check, and python -I scripts/check_no_game_data.py tools/shader_disasm.py tests/test_shader_disasm.py — passed.

Compatibility

The header-based path runs one decoder invocation. Both backends use the existing listing writer and error reporting.

Coordination

The claim is linked above. #7980 addresses timeouts and repeated failures across files. It edits the same loop and may need a rebase.

Limitations

Verification used a partial checkout. Repository-wide suites that require the full tree were unavailable. AMDGPU-enabled llvm-mc was unavailable locally, so the regression used a subprocess stand-in. CMake, GPU, and full-corpus validation were outside these tests. If the filesystem prevents removing the stale listing, the command reports the path and asks for removal before resuming.

AI assistance

AI-assisted: yes (OpenAI Codex).

Checklist

  • No game data, keys or decryption, including in logs or fixtures.
  • Translator rule documented in docs/design.md (this patch changes the disassembler's result selection).

@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 fallback selection is correct — it retains the widest candidate with zero invalid-instruction diagnostics, publishes the already-checked result when a second invocation fails, refuses an unconfirmed wider candidate, and still reports a total decoder failure. One real defect remains:

A previous output survives the new failure, and --skip-existing reuses it. When the unconfirmed fallback is rejected, tools/shader_disasm.py:167-190 makes one() return "failed" without touching out/<stem>.s. main() records FAILED and calls fail() before the stale-listing pruning (:256-258), so a previous out/one.s from an earlier run remains — including the bad listing the old code published for the same candidate. A rerun with --skip-existing treats any nonempty out/one.s as reusable (:241-249), skips the shader, and the build succeeds with the stale/bad listing. The new test uses a fresh out and asserts os.listdir(out) == [] (tests/test_shader_disasm.py:170-183), so it never seeds a previous one.s.

Fix: on a per-shader failure, remove the planned output for that shader (or write a failure marker and make --skip-existing refuse it), while keeping old listings for global toolchain failures as the pruning comment intends. Add a test that pre-creates out/one.s (the old bad/invalid listing) and runs both without and with --skip-existing; the unconfirmed-fallback run must not leave a successful-looking/reusable listing. The fallback-selection tests are otherwise meaningful. Synthetic only; no game files. AI-assisted (OpenCode).

@RAINighty

Copy link
Copy Markdown

Tested 5dd3c50f5 merged with main 6dda0630b (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1; venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/test_shader_disasm.py with this PR: passes (Ran 32 tests in 4.899s, OK). On main: passes (Ran 29 tests in 4.748s, OK).
  • Negative control: this PR's test with main's version of tools/shader_disasm.py fails (Ran 32 tests in 5.803s, FAILED (failures=2)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 15549afe on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main 46492b02: pass

  • python -I tests/test_shader_disasm.py: Ran 33 tests, OK. With only the non-test files reverted to main: FAILED (failures=4), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

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