Skip to content

fix(shader): use GPU addresses for oversized scalar buffers - #24025

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
MehmetCambaz:fix/oversized-scalar-buffers
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
MehmetCambaz:fix/oversized-scalar-buffers

Conversation

@MehmetCambaz

Copy link
Copy Markdown
Contributor

What

Scalar buffer descriptors whose stride times record count is provably greater than UINT32_MAX cannot fit a single Vulkan storage-buffer descriptor. Teardown (PPSA15246, 01.070.100) reaches this with stride 16 and 0xffffffff records: the declared extent is 0xffffffff0 bytes, and the current storage-buffer path throws shader buffer exceeds descriptor range limit.

Use the existing GPU descriptor/address path for these scalar accesses. A bounded analysis of known set bits proves a minimum descriptor extent; uncertain sizes and vector accesses keep the existing path. This changes resource selection, not the scalar load's address or bounds-check implementation. No title IDs, host vendors, or platform-specific conditions are added.

Add an IR regression covering oversized, boundary, small, unknown-stride and vector descriptors. Extend the scalar-buffer GPU readback test with a shader that constructs a 64 GiB descriptor and checks actual scalar reads.

Overlap: tools/pr_overlap.py --names knownSetBits TakeGpuDescriptor found no matching additions. The branch check reported stale branches that conflict with its base; their shared resource-tracker changes were inspected manually and no functional prerequisite or duplicate oversized-scalar routing was identified. The initial text conflict with #20248 was removed by placing this scalar-only decision before descriptor materialization; git merge-tree confirms a clean merge with its head dd7df7d730. This does not depend on its opt-in buffer tables. Older shared-file PRs examined: #6280, #6488, #7085, #7395, #7642, #7684, #8939, #9457, #9633, #9749, #9790, #9852, #9969, #10193, #13928, #13929, #14032, #14944, #16472, #16812, #16814, #21745, #21763, #22424, #22583 and #23242.

Scope: this removes one buffer-descriptor stop, not every large-memory failure. With the normal host-import budget, the Teardown experiment instead reached a large staging allocation failure. With the process-local APS5_HOST_IMPORT_MIB=14000 setting it passed the original stop and reached an unsupported PM4 type-0 packet at DWORD 15. The budget is a test setting, not a new default or a requirement suitable for every host. No full-gameplay or performance claim is made.

Tested

Windows 10.0 build 26300, AMD Ryzen 9 7900X, NVIDIA GeForce RTX 4070, NVIDIA 610.88, WinLibs GCC 15.2.0 r7, Release. Khronos validation layer 1.4.368, newer than the pinned Vulkan headers (1.4.335).

Focused tests on upstream 2b718a22fe and this change, on the same GPU, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, and VK_LAYER_PATH pointing to the portable Khronos layer:

ctest --test-dir build-windows-release -R '^(agc_driver_scalar_buffer_runtime_word3|agc_oversized_scalar_buffer)$' -V

The scalar-buffer GPU readback test passes on both versions. The new IR regression fails on the original selection logic and passes with this change. Both GPU logs confirm insertion of VK_LAYER_KHRONOS_validation; neither contains a missing-layer warning or a VUID- error. The small GPU fixture can already be clipped to its registered allocation on main; it validates the new path's readback, rather than reproducing Teardown's large registered allocation.

python tools/check_conventions.py --base origin/main, python tools/debt_fold.py --check, and git diff --check pass.

Title evidence was captured on base e1ab104e0a plus this resource-selection change, before rebasing to current main. Teardown's import audit found 887 unique imports, zero absent imports and zero throwing stubs. Advancing past the Cross prompt reproduced the original descriptor-range refusal with shader caches disabled. The narrowed change plus the host-import setting reached the later PM4 rejection. No copyrighted game files, shaders, or raw title logs are included. AMD, Intel, Linux, and complete gameplay are not tested.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • GPUs tested: NVIDIA GeForce RTX 4070, NVIDIA 610.88, Windows 10.0 build 26300
  • AI-assisted: yes

@tablefrogpillow

Copy link
Copy Markdown
Contributor

AMD / Linux results for this PR, on RADV (Mesa 26.2.6) with Khronos validation layer 1.4.363, for head 02ca7dad10 (merge-base 2b718a22fe). Settings: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer. I built with -DANYPS5_AGC_EXECUTION_TESTS=ScalarBufferRuntimeWord3 and ran the test executables directly in that environment, not through ctest. NAVI31 and RAPHAEL are in one Linux box. The VEGA10 run used the same binaries copied to a second Linux host with the same Mesa and layer versions.

agc_driver_scalar_buffer_runtime_word3 on the unmodified PR head:

GPU PR head
RX 7900 GRE (NAVI31, RDNA3) 3/3 pass
Ryzen 7800X3D iGPU (RAPHAEL, gfx1036, RDNA2) 3/3 pass
RX Vega 56 (VEGA10, GCN5, Wave64) 3/3 pass

In all nine logs the loader inserts VK_LAYER_KHRONOS_validation. None contains was not found, and there are 0 VUID- messages.

  • agc_oversized_scalar_buffer passes on the PR. With ResourceTracker.cpp reverted to the merge-base it fails with oversized scalar buffer selected the wrong access path. This is a host-side pure-logic result, not a GPU one.
  • The GPU fixture also passes with ResourceTracker.cpp reverted: 3/3 on NAVI31 and on RAPHAEL, 0 VUID-. I did not run that control on VEGA10. So the fixture does not separate the two arms.
  • To confirm the oversized cases take the new path on each GPU, I added a temporary local fprintf in the gpuDescriptor = true branch. It is not part of this PR, and I ran it once per GPU without the layer. It fired 6 times on each of NAVI31, RAPHAEL and VEGA10, and the fixture passed each time. With that branch taken, the fixture's reads come back with the expected values on RDNA3, RDNA2 and GCN5 under RADV, including the 0xa0000005 word. This covers only the small fixture allocation. It does not show anything about reads at Teardown's sizes.

Not tested: Teardown, AMD on Windows, lavapipe.

AI-assisted: yes (runs scripted with an AI assistant, on the hardware above)

@github-actions github-actions Bot added build shader core/shader docs agc libSceAgc* labels Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

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 6280 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 6488 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7642 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 7684 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9457 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9633 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9749 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9790 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9852 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9897 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 9969 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 10193 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 13928 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 13929 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14032 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14853 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 14944 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 15555 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 16472 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 16631 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 16812 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 16814 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 18106 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 18107 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 20248 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 20519 core/shader/recompiler/Optimization/src/ResourceTracker.cpp
PR 22424 core/shader/recompiler/Optimization/src/ResourceTracker.cpp

@throny

throny commented Nov 22, 2026

Copy link
Copy Markdown

GPU test run: ✅ no new failures or validation errors on Windows / NVIDIA

Basis: built and ran · this PR's head 02ca7dad10 merged onto main 851212fb98 · Windows 11 Pro 26300, RTX 4080 (10de:2704, driver 610.88, subgroup 32), WinLibs GCC 15.2.0 r7, Release

Checked

  • The agc_* tests tools/select_tests.py selects for this change: 2049 of 2050 passed, run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (Khronos validation layer, nightly 1.4.369, newer than the 1.4.335 minimum).
  • The loader logged Insert instance layer "VK_LAYER_KHRONOS_validation" 1890 times and never was not found but was requested by env var VK_INSTANCE_LAYERS.
  • 0 VUID- messages, the same as a full agc_* run of main 851212fb98 on this machine with the same settings.
  • The failure is agc_driver_store_over_untracked, which also fails intermittently on main here (agc_driver_store_over_untracked is flaky on Windows: the second-store case sometimes finds no saved guest bytes #22670), not this change.
  • New in this PR, passing on NVIDIA: agc_oversized_scalar_buffer.

Findings: none from this run; this is a GPU run, not a code review.

AI-assisted test run (Claude Code) · head 02ca7dad10 · base main 851212fb98

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The scalar descriptor selection change and its included tests were reviewed at head 02ca7dad10471cec0628b4cb7a7d34c9e41784c3; I found no verified blocking defect, but did not run checks independently.

What I ran

No commands or tests were run. The prepared diff and included source files were inspected using the review reader.

Results

Check Result Note
Diff and changed source review passed All five changed files were read
Tests and prechecks not run Only author-reported results were available

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run tests, prechecks, builds, or GPU checks. The author reports those checks passed, but I did not independently verify them. The review bundle listed five changed files under reviewed, and I read all five: core/libs/prx/libSceAgcDriver/tests/OversizedScalarBuffer.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_oversized_scalar_buffer_tests.cmake, core/libs/prx/libSceAgcDriver/tests/execution/ScalarBufferRuntimeWord3.cpp, core/shader/recompiler/Optimization/src/ResourceTracker.cpp, and docs/dev/debt/changes/oversized-scalar-buffer.md. No changed files were excluded.

To get this to a good state

Nothing is required.

@Helldiverr

Copy link
Copy Markdown
Contributor

GPU test run: passes on AMD RDNA4 with no VUID- errors; the new IR test fails on main and catches two mutations, but the GPU readback case also passes on main

Base: main 16d82b47e7. This PR's head 02ca7dad10 merged onto it cleanly as 20a5d5bd08. Line numbers below are from head 02ca7dad10.

Code:

  • knownSetBits (core/shader/recompiler/Optimization/src/ResourceTracker.cpp:33) returns the bits a value is known to have set. It looks through immediates, or, and and constant shifts, and anything else counts as 0 (:36). It can therefore only underestimate stride and records, so the new branch below fires only when the size is proven too large.
  • A scalar buffer whose known stride (dword 1 bits 16 to 29) times its known record count exceeds UINT32_MAX now takes the GPU-address path (:2260 to :2265). That is the same result the existing fallback gives when the descriptor cannot be rebuilt.
  • Vector buffers and sizes that are not known keep the storage-buffer path.
  • tools/check_conventions.py --base 16d82b47e7 --head 20a5d5bd08 reports All conventions checks passed.

Negative control:

  • I added the PR's core/libs/prx/libSceAgcDriver/tests/OversizedScalarBuffer.cpp, its CMake fragment and its ScalarBufferRuntimeWord3.cpp unchanged to main 16d82b47e7, then rebuilt and ran them.
  • agc_oversized_scalar_buffer failed with stride=16 records=4294967295 scalar=1 dynamic=0 expected=1 actual=0 dma=0.
  • agc_driver_scalar_buffer_runtime_word3 passed on main, its new oversized case included (core/libs/prx/libSceAgcDriver/tests/execution/ScalarBufferRuntimeWord3.cpp:143 to :146). The PR description says the same.
  • So on the GPU this case checks the readback through the new path, but it does not tell the two paths apart. Only the IR test does.

Mutation:

  • A. I changed > to >= (core/shader/recompiler/Optimization/src/ResourceTracker.cpp:2262).
    • agc_oversized_scalar_buffer failed on the boundary case (core/libs/prx/libSceAgcDriver/tests/OversizedScalarBuffer.cpp:61): stride=1 records=4294967295 scalar=1 dynamic=0 expected=0 actual=1 dma=1.
  • B. I made knownSetBits return all ones for a value it cannot see through (:36).
    • It failed on the runtime-stride case (core/libs/prx/libSceAgcDriver/tests/OversizedScalarBuffer.cpp:64): stride=16 records=4294967295 scalar=1 dynamic=1 expected=0 actual=1 dma=1.
    • So the test checks that a stride which is not known keeps the storage-buffer path.
  • agc_driver_scalar_buffer_runtime_word3 passed under both mutations. I reverted both.

GPU:

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R '^(agc_driver_scalar_buffer_runtime_word3|agc_oversized_scalar_buffer|agc_driver_gcn_scalar_buffer_base|agc_driver_buffer_descriptor_runtime|agc_driver_runtime_buffer_spans|agc_driver_oversized_descriptor_sets)$' -V

This is the PR's two tests plus four buffer-descriptor tests nearby.

Test main head run 1 head run 2 head run 3
agc_driver_buffer_descriptor_runtime Passed 0.32 s Passed 0.33 s Passed 0.31 s Passed 0.32 s
agc_driver_gcn_scalar_buffer_base Passed 0.97 s Passed 0.23 s Passed 0.22 s Passed 0.23 s
agc_driver_oversized_descriptor_sets Passed 0.18 s Passed 0.12 s Passed 0.12 s Passed 0.12 s
agc_driver_runtime_buffer_spans Passed 0.43 s Passed 0.40 s Passed 0.37 s Passed 0.40 s
agc_driver_scalar_buffer_runtime_word3 Passed 0.29 s Passed 0.27 s Passed 0.23 s Passed 0.27 s
agc_oversized_scalar_buffer not on main (negative control above) Passed 0.05 s Passed 0.01 s Passed 0.01 s
  • Every test that opens an AgcDriver::VulkanDevice selected the R9700 (subgroup=64).
  • agc_driver_oversized_descriptor_sets loads the layer but logs no device selection.
  • agc_oversized_scalar_buffer is a CPU-side IR test.
  • The main run was the first run after its rebuild, so its times include a cold start. This is not a speed claim.

Validation:

  • Insert instance layer "VK_LAYER_KHRONOS_validation" appears 5 times in the main log and in each head log, once per test that loads Vulkan.
  • was not found but was requested by env var VK_INSTANCE_LAYERS appears in no log.
  • VUID- lines: 0 on main, and 0, 0 and 0 on the three head runs. The negative-control and mutation logs also have none.

Host:

  • GPU: AMD Radeon AI PRO R9700 (gfx1201, 1002:7551), driver 32.0.31044.16, Vulkan 1.4.349
  • Validation layer: Khronos 1.4.363 (LunarG SDK)
  • CPU and OS: Ryzen 9 9950X3D, Windows 11 Pro 26300
  • Build: WinLibs GCC 15.2, Release
  • Commits: main 16d82b47e7, head 02ca7dad10, merged onto main as 20a5d5bd08

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit e6d5c71 into boykopovar:main Nov 27, 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* build docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants