Skip to content

fix(agc): count owned texture copies in the sampled cache budget - #23726

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
lgqdaxia:codex/agc-sampled-copy-budget
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
lgqdaxia:codex/agc-sampled-copy-budget

Conversation

@lgqdaxia

Copy link
Copy Markdown
Contributor

What

When a sampled texture needs its own image copied from a storage image, the sampled cache only charges for the source if the storage cache no longer holds it. The copy's GPU allocation is omitted, so the sampled cache can retain more bytes than its budget accounts for.

Charge the sampled entry for its own allocation while preserving the existing charge for a source held outside the storage cache. A view that shares the source image has no separate allocation. Check the resulting byte count in the existing sRGB and format-repack allocation recovery tests.

Tested

Windows 11 Pro (build 26300), NVIDIA GeForce RTX 3080 Laptop GPU, NVIDIA 621.14. Four focused CTests ran on a0f6ff94e917 with the new assertions and on 21fbc23a4ddf with the same patch as this PR. The sRGB and format-repack cases allocated separate 4 MiB and 1 MiB images on the baseline. Both reported only the 256 KiB already in the sampled cache after reclaiming the idle texture. All four tests passed with the fix, including ordinary sampled allocation recovery and the sampled cache budget test.

Both runs inserted Vulkan validation layer 1.4.368 and reported zero VUID- errors. Both used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and VK_LOADER_DEBUG=error,warn,layer. The measurements cover cache accounting and allocation recovery.

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 3080 Laptop GPU, driver 621.14, Windows 11 Pro build 26300
  • AI-assisted: yes

@github-actions github-actions Bot added the agc libSceAgc* label Nov 19, 2026
@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Ran the focused tests with the Khronos validation layer on Linux and an NVIDIA GPU, since CI runs the GPU tests only on lavapipe and the NVIDIA run in the Tested section is on Windows.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head bca0d038e2 merged onto main e1ab104e0a with --no-ff (clean, as 68b0ea0227). Main baseline is a Release build of e1ab104e0a on the same machine.

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_(sampled_cache_budget|recover_(sampled|storage|srgb|repack)_allocation)$' -V
main e1ab104e0a this PR
Result 5 of 5 passed 5 of 5 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 5 5
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

The four agc_driver_recover_*_allocation tests run the recoveryTests cases that carry the new assertions; they pass on both sides, as does agc_driver_sampled_cache_budget. Every fixture device was the RTX 4090.

Negative control: with main's ShaderResources.cpp and the rest of this PR, agc_driver_recover_srgb_allocation fails with AGC graphics: sampled copy allocation is missing from the cache budget: 4194304 copy bytes, 262144 accounted bytes and agc_driver_recover_repack_allocation with ... 1048576 copy bytes, 262144 accounted bytes, the same 4 MiB and 1 MiB as in the Tested section; recover_sampled and recover_storage still pass. With the change restored all five pass.

No new VUID- errors; all focused tests pass on Ada.

AI-assisted: yes (Claude Code)

@Colewiz7

Copy link
Copy Markdown
Contributor

Head bca0d038e2 merged onto main 23786c4e4f as 9f05846a3b, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6299 on the 7900 XT, the 2028 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1960 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@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 6192 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6340 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6412 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 9318 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 9712 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9852 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9897 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 10442 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10743 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 12575 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 12944 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 13796 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 13809 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampledCacheBudget.cpp
PR 14032 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 14262 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 14944 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 15529 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 15570 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 16831 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 16879 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 16953 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 18390 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 20248 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 20519 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 22424 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 22439 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 24346 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 24661 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 25534 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 26197 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 26436 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 26913 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 27171 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 27343 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp

@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 sampled cache now accounts for owned storage-copy allocations, with focused assertions covering the sRGB and repack recovery cases; the review found no verified blocking defects.

What I ran

Reviewed head bca0d038e2b57645f253147a89fb3d7a15df4ab1 using the prepared diff and repo_read.py for targeted source context. No tests were run by me; the description reports four focused CTests run by the author.

Results

Check Result Note
Diff and targeted code review passed Accounting and recovery paths inspected
Tests run by reviewer not run Author reports four focused CTests passed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full text of ShaderResources.cpp was excluded from the review folder and inspected only through targeted repo_read.py ranges. No other changed files were excluded. The reported CTest runs and hardware behavior were not independently verified.

To get this to a good state

Nothing is required.

@Jirka135

Copy link
Copy Markdown
Contributor

Windows run on RTX 50 and the AMD Windows driver (RDNA2 iGPU), with a red check. Head bca0d038e2 merged onto main 35e39b5c5b with git merge --no-ff --no-commit (clean).

Setup: Windows 11 Enterprise 10.0.26300, Ryzen 7 9800X3D, WinLibs GCC 15.2.0, Release. NVIDIA GeForce RTX 5090 (10de:2b85), driver 617.42, and the AMD Radeon(TM) Graphics iGPU (1002:13c0), selected with ANYPS5_GPU. Khronos validation layer 1.4.369. 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_sampled_cache_budget|agc_driver_recover_(sampled|storage|srgb|repack)_allocation)$' -V, 3 runs with the layer and 3 without per arm and GPU.

RTX 5090 AMD iGPU
main 5/5 (6/6 runs) 5/5 (6/6)
main code + this PR's SampledCacheBudget.cpp recover_srgb and recover_repack fail 6/6: sampled copy allocation is missing from the cache budget: 4194304 copy bytes, 262144 accounted bytes (1048576 for repack) same, 6/6
this PR 5/5 (6/6 runs) 5/5 (6/6)

Every layer log shows Insert instance layer "VK_LAYER_KHRONOS_validation", none shows was not found but was requested by env var VK_INSTANCE_LAYERS, and no log has a VUID- line.

GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11; AMD Radeon(TM) Graphics (Ryzen 7 9800X3D iGPU), driver 32.0.21045.29003, Windows 11

AI-assisted: yes

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head bca0d038e2, applied with git apply on main fd4aeed483 together with the other 28 PRs of one batch (#22683, #23796, #23923, #24367, #24370, #24409, #24486, #24587, #10623, #18903, #18941, #19461, #21018, #21303, #21451, #21965, #23477, #23478, #24463, #12827, #14127, #14991, #20063, #24103, #24331, #24508, #24565, #15838). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
agc_driver_sampled_cache_budget, agc_driver_sampled_cache_budget_memory, agc_driver_sampled_cache_budget_memory_demand and 3 more (6 tests, matched by name to the test file this PR changes) all pass all pass

Whole batch: the full ctest -j 12 (6523 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #24409 (guest_usbd); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): guest_net_dns_info, test_script_registration. The 2126 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit 35a1895 into boykopovar:main Nov 27, 2026
14 checks passed
@lgqdaxia
lgqdaxia deleted the codex/agc-sampled-copy-budget branch November 28, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants