fix(shader): read a buffer V#'s presence at run time instead of specializing it #9957

Merged
mrfelek merged 1 commit from upstream-pr/9957 into main 2026-10-26 03:54:35 +00:00
mrfelek commented 2026-10-23 00:05:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-23T00:05:14Z.


What

A buffer V#'s presence (dwords[2] != 0 && (dwords[0] != 0 || (dwords[1] & 0xffff) != 0)) was supplied as specialization constant BufferBase + i*BufferWords + 2 from the dispatch's V# snapshot, and buildSpecializedModule turns supplied specializations into literal constants. The same guest program therefore compiled to two SPIR-V modules, one where the buffer was bound and one where it was still null, with different RecompileResult::Identity() and no VkPipelineCache hit between them; which one a dispatch got depended on timing.

PPSA26344 has eight compute programs of 1.2–1.45M SPIR-V words reached in both states; every new state cost a 54–320 s NVIDIA pipeline compile, and pipeline journal replay of the other state did not help.

descriptor() in SpirvRuntimeBuffer.cpp now computes presence from the V#'s words at run time, as the registration-module path already does; the formatted-buffer helper takes it from its existing valid parameter, and DescriptorBindingBuilder no longer supplies BufferBase + 2. The GuardedMemoryLoads fixture now encodes validity in the V# words instead of the specialization. ShaderDiskCache FormatVersion is bumped because generated SPIR-V changes.

Tested

Ubuntu 26.10, Ryzen 9 5950X, RTX 3080 Ti 12 GB, NVIDIA 615.71.09. PPSA26344 02.002.000 title-scene load (with a separate blend change applied locally to get past its earlier stop).

  • Before: captures of the 1,231,429-word program from two runs differed in exactly one specialization literal (BufferBase+2: 1 vs 0) and 20 OpLogicalAnd folding it. Warm run: pipelines over 100k words took 1,221 s in the first 15 min because 5 journal-replayed giants were rebuilt at 54–70 s each.
  • After, cold run: one capture per giant across 8 programs (+~2% SPIR-V each).
  • After, warm run: identical capture hashes, no giant rebuilt (journal replay 48 ms–1.26 s, live 18–74 ms); pipelines over 100k words took 21.8 s in the first 15 min.
  • Focused tests (tools/select_tests.py, 1143 selected): 1140 pass; the same 3 failures (agc_driver_sample_order, agc_driver_sample_order_grid_reference, agc_driver_sample_order_recipe_depth_locations) occur on main 895f47f4ee on this machine.
  • Same tests with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on main and on this change: the same 3 failures and identical VUID sets (four pre-existing kinds), no new validation errors.

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 #675
  • GPUs tested: NVIDIA RTX 3080 Ti, driver 615.71.09, Ubuntu 26.10
  • AI-assisted: yes

Related: #639 added registration-time modules, which already read presence from the V# at run time; this brings the dispatch-time specialization path in line.
Conflicts with #7484 only in the GuardedMemoryLoads test fixture (emitLoad/AccessTrace signatures); whichever lands second needs a small fixture rebase.

AI-assisted. Tested by me on my own machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4975807406 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9957). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-10-23T00:05:14Z. --- ### What A buffer V#'s presence (`dwords[2] != 0 && (dwords[0] != 0 || (dwords[1] & 0xffff) != 0)`) was supplied as specialization constant `BufferBase + i*BufferWords + 2` from the dispatch's V# snapshot, and `buildSpecializedModule` turns supplied specializations into literal constants. The same guest program therefore compiled to two SPIR-V modules, one where the buffer was bound and one where it was still null, with different `RecompileResult::Identity()` and no VkPipelineCache hit between them; which one a dispatch got depended on timing. PPSA26344 has eight compute programs of 1.2–1.45M SPIR-V words reached in both states; every new state cost a 54–320 s NVIDIA pipeline compile, and pipeline journal replay of the other state did not help. `descriptor()` in SpirvRuntimeBuffer.cpp now computes presence from the V#'s words at run time, as the registration-module path already does; the formatted-buffer helper takes it from its existing `valid` parameter, and `DescriptorBindingBuilder` no longer supplies `BufferBase + 2`. The GuardedMemoryLoads fixture now encodes validity in the V# words instead of the specialization. ShaderDiskCache FormatVersion is bumped because generated SPIR-V changes. ### Tested Ubuntu 26.10, Ryzen 9 5950X, RTX 3080 Ti 12 GB, NVIDIA 615.71.09. PPSA26344 02.002.000 title-scene load (with a separate blend change applied locally to get past its earlier stop). - Before: captures of the 1,231,429-word program from two runs differed in exactly one specialization literal (`BufferBase+2`: 1 vs 0) and 20 `OpLogicalAnd` folding it. Warm run: pipelines over 100k words took 1,221 s in the first 15 min because 5 journal-replayed giants were rebuilt at 54–70 s each. - After, cold run: one capture per giant across 8 programs (+~2% SPIR-V each). - After, warm run: identical capture hashes, no giant rebuilt (journal replay 48 ms–1.26 s, live 18–74 ms); pipelines over 100k words took 21.8 s in the first 15 min. - Focused tests (`tools/select_tests.py`, 1143 selected): 1140 pass; the same 3 failures (`agc_driver_sample_order`, `agc_driver_sample_order_grid_reference`, `agc_driver_sample_order_recipe_depth_locations`) occur on main 895f47f4ee on this machine. - Same tests with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` on main and on this change: the same 3 failures and identical VUID sets (four pre-existing kinds), no new validation errors. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA26344 #675 - [x] GPUs tested: NVIDIA RTX 3080 Ti, driver 615.71.09, Ubuntu 26.10 - [x] AI-assisted: yes Related: #639 added registration-time modules, which already read presence from the V# at run time; this brings the dispatch-time specialization path in line. Conflicts with #7484 only in the GuardedMemoryLoads test fixture (`emitLoad`/`AccessTrace` signatures); whichever lands second needs a small fixture rebase. AI-assisted. Tested by me on my own machine.
MarcZX10 commented 2026-10-23 00:06:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T00:06:43Z.

Review: APPROVED


I reviewed the exact head 5106dae4ce37c9217addcf6d63bf744953d236d3. The change removes dispatch-time buffer-presence specialization from the cache identity and derives it from the descriptor words at runtime. The specialized GCN path masks the high-base word before testing its low 16 bits, and the formatted-buffer helper now receives validity from its existing runtime parameter. The GuardedMemoryLoads fixture encodes descriptor validity in the V# words, and the shader disk-cache format is bumped. I found no correctness issue in those paths.\n\nLocal checks run: and All conventions checks passed. both pass. I did not run the local GPU test suite because no usable build tree is available and the root filesystem is full. I inspected the reported same-machine NVIDIA baseline/change results: the author reports 1,140/1,143 selected tests passing on both, the same three existing sample-order failures and identical pre-existing VUID sets, plus matching warm capture hashes across eight large programs. Hosted relinker/product build jobs are policy-skipped for this PR, so I am relying on the author-provided runtime report for GPU validation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5622407173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9957#pullrequestreview-5622407173). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T00:06:43Z. **Review:** APPROVED --- I reviewed the exact head 5106dae4ce37c9217addcf6d63bf744953d236d3. The change removes dispatch-time buffer-presence specialization from the cache identity and derives it from the descriptor words at runtime. The specialized GCN path masks the high-base word before testing its low 16 bits, and the formatted-buffer helper now receives validity from its existing runtime parameter. The GuardedMemoryLoads fixture encodes descriptor validity in the V# words, and the shader disk-cache format is bumped. I found no correctness issue in those paths.\n\nLocal checks run: and All conventions checks passed. both pass. I did not run the local GPU test suite because no usable build tree is available and the root filesystem is full. I inspected the reported same-machine NVIDIA baseline/change results: the author reports 1,140/1,143 selected tests passing on both, the same three existing sample-order failures and identical pre-existing VUID sets, plus matching warm capture hashes across eight large programs. Hosted relinker/product build jobs are policy-skipped for this PR, so I am relying on the author-provided runtime report for GPU validation.
MarcZX10 commented 2026-10-23 00:27:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T00:27:39Z.

Review: APPROVED


Reviewed the four-file change and the reported same-machine main/change Vulkan validation runs. The dispatch-time path now derives buffer presence from V# words at run time; the formatted-buffer path uses the existing runtime parameter, and the disk-cache version is bumped for the SPIR-V change. The fixture now encodes validity in descriptor words rather than specialization, matching the production behavior. The author reports the same three known test failures and VUID set on main and the change, with no new validation errors; required intake/conventions checks pass. Approved at head 5106dae4ce37c9217addcf6d63bf744953d236d3.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5622539414 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9957#pullrequestreview-5622539414). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T00:27:39Z. **Review:** APPROVED --- Reviewed the four-file change and the reported same-machine main/change Vulkan validation runs. The dispatch-time path now derives buffer presence from V# words at run time; the formatted-buffer path uses the existing runtime parameter, and the disk-cache version is bumped for the SPIR-V change. The fixture now encodes validity in descriptor words rather than specialization, matching the production behavior. The author reports the same three known test failures and VUID set on main and the change, with no new validation errors; required intake/conventions checks pass. Approved at head 5106dae4ce37c9217addcf6d63bf744953d236d3.
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!9957
No description provided.