Skip to content

fix(shader): reuse bound specialization fields for null buffer slots - #13774

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:fix/shader-null-buffer-substitutes
Nov 1, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:fix/shader-null-buffer-substitutes

Conversation

@Celegans12

Copy link
Copy Markdown
Contributor

What

After #9957 moved buffer presence to run time, null V#s still select different shader modules from their unused stride, format and alignment words. This is the buffer-substitutes piece next in the order agreed in #675, after #8160/#8161.

Each program learns a slot's fields after its first valid bound plan. Null slots use those fields; never-bound slots use zeros. Bound slots retain their own fields and the actual descriptors still control presence. Full/masked result memos and plan creation share one immutable substitute snapshot, so null -> bound -> the identical null cannot retain a pre-learning module. Tables stay process-local; APS5_NO_BUFFER_SUBSTITUTES=1 restores main's selection.

Related: #6412 adds descriptor-status validation and key fields; retain them when composing. #6924 changes persistent plan identity; it must key the effective fields too. #7642/#9508/#10193 change the same ordinary/heap keys. #12662/#12980 extend the Prepare signature. #10757 changes memo-result recycling. These are composition points, not prerequisites.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, Release, -DBUILD_TESTING=ON, based on main 18f5949.
  • 20/20 focused tests pass on NVIDIA (--repeat until-fail:3).
  • Same build on Windows lavapipe: 20/20 pass.
  • agc_driver_null_buffer_substitutes and the added agc_shader_disk_cache check fail on main. Direct/captured/prepared calls, null loads/stores, changed formats, masked-memo verification and GPL on/off pass.
  • Validation loaded on candidate and main's 19 neighboring tests: no VUIDs/skips on either Windows driver.
  • Merge with main 8dc9f36: 20/20 on both Windows drivers.
  • Linux GCC 13.3/lavapipe: 18/18 repeated three times; main 17/17.
  • Not tested: Linux validation layer, new title run, AMD, Intel. No FPS claim.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: PPSA26344 Ghost of Yōtei (PPSA26344) #675
  • GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, 610.62, Windows 11; Mesa 26.2.4 llvmpipe, Windows 11; Mesa 25.2.8 llvmpipe, WSL Ubuntu 24.04
  • AI-assisted: yes

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9508 core/shader/recompiler/Recompiler.cpp L986-990, L993-997, L1109, L1689, L1707-1715, L1717-1718, L1800, L1818, L1846

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1896 docs/dev/ENVIRONMENT.md
PR 4472 docs/dev/ENVIRONMENT.md
PR 5021 core/shader/recompiler/Recompiler.cpp
PR 5371 core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
PR 5609 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 5925 core/shader/recompiler/ShaderDiskCache.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6501 docs/dev/ENVIRONMENT.md
PR 6858 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 6924 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/CompiledVariant.hpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 6970 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 7223 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 7449 docs/dev/ENVIRONMENT.md
PR 7457 docs/dev/ENVIRONMENT.md
PR 7514 docs/dev/ENVIRONMENT.md
PR 7604 docs/dev/ENVIRONMENT.md
PR 7622 core/shader/recompiler/ShaderDiskCache.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 7689 core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 7694 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 7922 docs/dev/ENVIRONMENT.md
PR 8004 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 8484 docs/dev/ENVIRONMENT.md
PR 8542 docs/dev/ENVIRONMENT.md
PR 8939 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9012 docs/dev/ENVIRONMENT.md
PR 9020 core/shader/recompiler/Recompiler.cpp
PR 9183 core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9248 docs/dev/ENVIRONMENT.md
PR 9335 core/shader/recompiler/Recompiler.cpp
PR 9345 docs/dev/ENVIRONMENT.md
PR 9356 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9387 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9633 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9712 docs/dev/ENVIRONMENT.md
PR 9749 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9790 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 9852 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 9969 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 10026 docs/dev/ENVIRONMENT.md
PR 10069 docs/dev/ENVIRONMENT.md
PR 10351 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/ShaderDiskCache.cpp
PR 10359 core/shader/recompiler/Recompiler.cpp
PR 10442 docs/dev/ENVIRONMENT.md
PR 10472 docs/dev/ENVIRONMENT.md
PR 10652 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp
core/shader/recompiler/Recompiler.cpp
PR 10720 core/shader/recompiler/ShaderDiskCache.cpp
docs/dev/ENVIRONMENT.md
PR 10757 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 10894 docs/dev/ENVIRONMENT.md
PR 10941 core/shader/recompiler/Recompiler.cpp
PR 11126 core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
PR 11351 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 11435 docs/dev/ENVIRONMENT.md
PR 11436 docs/dev/ENVIRONMENT.md
PR 12120 docs/dev/ENVIRONMENT.md
PR 12323 docs/dev/ENVIRONMENT.md
PR 12324 core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 12536 docs/dev/ENVIRONMENT.md
PR 12544 docs/dev/ENVIRONMENT.md
PR 12662 core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 12746 docs/dev/ENVIRONMENT.md
PR 12828 core/shader/recompiler/Recompiler.cpp
PR 12863 docs/dev/ENVIRONMENT.md
PR 12980 core/shader/recompiler/Optimization/include/Optimization/DescriptorBindingBuilder.hpp
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp
core/shader/recompiler/Recompiler.cpp
docs/dev/ENVIRONMENT.md
PR 13044 docs/dev/ENVIRONMENT.md
PR 13159 docs/dev/ENVIRONMENT.md
PR 13263 docs/dev/ENVIRONMENT.md
PR 14051 docs/dev/ENVIRONMENT.md

@JJenkx

JJenkx commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Windows GPU run of head ab67d16cd7, merged onto main 18f5949788 (clean merge, local only).

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, Radeon RX 6700 XT with AMD proprietary driver 26.10.1 (Vulkan 1.4.315), WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. Khronos validation layer 1.4.363 requested for every test (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation).

  • agc_driver_null_buffer_substitutes, agc_shader_disk_cache, agc_shader_disk_cache_host_stderr, agc_shader_disk_cache_large_file, agc_shader_disk_cache_long_paths, agc_shader_disk_cache_pack_ownership, built from the test files this PR changes: pass, 3 of 3 runs each (--repeat until-fail:3), no failures, no skips.
  • They create Vulkan instances on the RX 6700 XT: the validation layer was inserted 3 times across the runs and reported no VUIDs.
  • Negative control: this PR's test files on main sources (one run) fail: agc_driver_null_buffer_substitutes. So the test catches what the change fixes on this GPU.

AI-assisted: yes (Claude Code).

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head ab67d16 merged onto main 828ac0b · tested 2026-10-31 09:21 UTC · 28 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,417 passed · 3 failed (0 new, 2 also fail on main, 1 unstable on main) · 42 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,462 of 3,048 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (912 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_graphics_maps_fallback 35.3 s, ⚠️ agc_driver_graphics 31.0 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_submit_progress_no_timeline: failed in 8 of the last 10 main runs
Failing on main too (2, not counted against this PR)
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (4 IDs in 426 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (426 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, and 418 more
VUID-vkCmdCopyImage-srcImage-01548 (13 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_sampling, and 5 more
VUID-vkCmdCopyImage-srcImage-01551 (13 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_plane_sampling, and 5 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_srgb8_color_target
Skipped (42)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or plat
Reproduce
git fetch origin ab67d16cd728c66e73353e684abd9b99fd65324a 828ac0b2ae74aac181ba128fb59b08a1534f2041
git checkout 828ac0b2ae74aac181ba128fb59b08a1534f2041 && git merge --no-ff ab67d16cd728c66e73353e684abd9b99fd65324a
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

Null buffer descriptors still split modules on unused specialization
fields after buffer presence moved to run time. Learn the first valid
bound fields per slot and use them for absent descriptors, retaining
actual runtime presence and independent bound formats.
Snapshot the learned fields once for result memo keys and materialization
so identical null captures cannot retain a module made before learning.
Cover direct, captured and prepared calls, null stores, and changed formats.
Keep the process-local table and an off switch for main's module selection.

AI-assisted: yes
@adriadam10
adriadam10 force-pushed the fix/shader-null-buffer-substitutes branch from ab67d16 to 068f2b3 Compare October 31, 2026 22:36
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 31, 2026
@adriadam10
adriadam10 merged commit 7c4dcf0 into boykopovar:main Nov 1, 2026
14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the interdiff of the null-slot substitutes (plan key, result memo and masked hash all use the same snapshot, learning happens after the first valid bound plan) and the new test, which pins null→bound and bound→null in direct, captured and prepared modes. main moved the test registrations into tests/cmake/*.cmake, so the conflict was only the agc_driver_null_buffer_substitutes TIMEOUT line, now added to agc_driver_runtime_formatted_store_tests.cmake. Rebased on main, built and ran the tests; merged.

@muhmuhkuh

Copy link
Copy Markdown
Contributor

Data point from Grand Theft Auto VI (PPSA38500), RTX 3080 Ti, Windows.

The substitute table is process-local (the static map in attachSubstitutes, not stored in the shader disk cache). So the field set a null V# slot inherits depends on which bound dispatch of that slot comes first in a run. For large compute modules (500k-800k SPIR-V words, 30-60 s per vkCreateComputePipelines on NVIDIA) the specialized module key then changes from run to run, and the pipeline cache does not warm up:

  • one warm run: 43 of 58 slow compute builds (1568 of 2206 s) were new specializations of programs already built in earlier runs; 28 of them were exactly +54 words against the closest earlier version
  • one diffed pair: 6 loads where one version builds the vec4 with a constant w = 1.0 and the other reads all 4 components with all-zero fields
  • with APS5_NO_BUFFER_SUBSTITUTES=1: the 48 new keys of one run were all served from the cache in the next run, none rebuilt

Storing the learned field sets with the variant in the disk cache, or choosing the substitute deterministically, would keep the variant reduction without the cross-run churn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs shader core/shader unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants