fix(shader): fall back when SPIR-V optimization invalidates a module #4241

Closed
MarcZX10 wants to merge 1 commit from upstream-pr/4241 into main
MarcZX10 commented 2026-10-12 02:02:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T02:02:25Z.


What

ValidateAndOptimizeSpirv already validates the input before optimization, but it threw when SPIRV-Tools produced output that failed validation. For valid input, it now reports that validation failure to stderr and returns the validated pre-optimization module, so an optimizer regression does not abort shader preparation. Valid optimized modules are still selected as before.

The new optimizer regression check verifies that invalid optimized output selects the valid input and that valid output remains selected. The exact specialized module from #4205 was not provided, so this tests the fallback decision rather than reproducing that game's shader. The output remains subject to Vulkan/SPIR-V validation by the existing caller path.

Tested

Linux x86_64, CMake/Ninja Release build with SPIRV-Tools enabled:

  • Built agc_spirv_optimizer_tests after rebasing on current main.
  • ctest --test-dir /tmp/AnyPS5-4205-build -R '^agc_spirv_optimizer$' --output-on-failure: passed (1/1).
  • tools/check_conventions.py --base upstream/main --head HEAD: passed.
  • git diff --check upstream/main...HEAD: passed.
  • No title run; the issue's exact shader dump was unavailable.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (n/a)
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824059338 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4241). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-12T02:02:25Z. --- ### What `ValidateAndOptimizeSpirv` already validates the input before optimization, but it threw when SPIRV-Tools produced output that failed validation. For valid input, it now reports that validation failure to stderr and returns the validated pre-optimization module, so an optimizer regression does not abort shader preparation. Valid optimized modules are still selected as before. The new optimizer regression check verifies that invalid optimized output selects the valid input and that valid output remains selected. The exact specialized module from #4205 was not provided, so this tests the fallback decision rather than reproducing that game's shader. The output remains subject to Vulkan/SPIR-V validation by the existing caller path. ### Tested Linux x86_64, CMake/Ninja Release build with SPIRV-Tools enabled: - Built `agc_spirv_optimizer_tests` after rebasing on current `main`. - `ctest --test-dir /tmp/AnyPS5-4205-build -R '^agc_spirv_optimizer$' --output-on-failure`: passed (1/1). - `tools/check_conventions.py --base upstream/main --head HEAD`: passed. - `git diff --check upstream/main...HEAD`: passed. - No title run; the issue's exact shader dump was unavailable. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (n/a) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-12 07:37:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T07:37:25Z.


Closing: using the unoptimized module when the optimized one fails validation is a fallback, and those aren't allowed (#182). #4018 fixed this validation error at its cause in the structurizer; if #4205 still fails on main, it needs that kind of fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119861957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4241#issuecomment-6119861957). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T07:37:25Z. --- Closing: using the unoptimized module when the optimized one fails validation is a fallback, and those aren't allowed (#182). #4018 fixed this validation error at its cause in the structurizer; if #4205 still fails on main, it needs that kind of fix.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4241
No description provided.