Skip to content

perf(shader): memoize SPIR-V emission failures - #1023

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:perf/shader-memoize-emission-failures
Oct 7, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:perf/shader-memoize-emission-failures

Conversation

@Celegans12

Copy link
Copy Markdown
Contributor

What

A variant whose SPIR-V emission throws is never remembered: findOrCompileVariant keeps only successful variants and the first attempt uses up the prepared program, so every later request reruns PrepareResourceProgram and the emitter to hit the same error. Plan failures already have a memo; this adds one for emission.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main ee391a5: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 368/368 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 367/367 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New verifyEmissionFailureMemo in agc_shader_disk_cache (CPU only): a pixel shader's clock read without VK_KHR_shader_clock emits once per layout, stride and address (on four threads too), twice with APS5_NO_FAILURE_MEMO=1. Fails on main.
  • PPSA26344 v1.008 with fix(shader): throw for constant lane reads outside the host subgroup #997, before: skipped draws took up to 5.2 s per 10 s.
  • Not tested: Linux (CI), console behaviour.

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
  • 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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

The source entry remembers a resource plan that failed to build, but
not a failed emission: findOrCompileVariant kept only successful
variants, and the first attempt used up the prepared program, so every
request for a program whose emission throws ran PrepareResourceProgram
and the emitter again before the draw was skipped.

compileVariant now reports an exception from SpirvEmitter::Emit (and
from SPIRV-Tools validation when enabled), and the source entry keeps
it per code address, binding layout and resource specialization; the
next request for that variant rethrows it before the disk-cache lookup.
Descriptor population depends on the snapshot and an out-of-memory
error is transient, so neither is kept. Nothing reaches the disk cache,
and APS5_NO_FAILURE_MEMO=1 turns the memo off as for plan failures.
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 7, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on RADV (build + full ctest on current main, 395/395; agc_shader_disk_cache fails without the change). The memo key matches what the variant cache already reuses (layout + specialization) plus the address, population and OOM failures stay out, and nothing reaches the disk cache. Merging.

@adriadam10
adriadam10 merged commit 501f1fe into boykopovar:main Oct 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants