Skip to content

fix(agc): keep a read-trapped image trapped when a label stores a large image around it on macOS - #20138

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/agc-label-occasional-store-keeps-traps
Nov 22, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/agc-label-occasional-store-keeps-traps

Conversation

@XIIYAZ

@XIIYAZ XIIYAZ commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What

On macOS, agc_small_tiled_shadow_label fails:

AGC graphics: a label stored a small image inside a pending large tiled one instead of trapping its reads

The test writes a small linear image at +0x20000 inside a large kR64KBX image (256x256, 0x40000 bytes); both have pending GPU results. It then calls StoreReadbackBeforeLabel. On macOS that function read-traps the small image's pages instead of storing them: GuestWriteWatchTrapReads succeeds and readTrapped is set. The same call then occasionally stores large tiled images that were written occasionally:

occasional store 10e1c0000+40000

That FlushPending covers the trapped image. FlushPending deliberately stores every read-trapped pending image its stored images cover, so their newer results land on top. So the trap is lifted and the small image is stored within the same label: exactly what the trap was meant to avoid.

With label traps on (macOS, trap), the occasional store now skips a large image that covers a read-trapped pending image. Its writtenOccasionally flag is left set, so a later label stores it once nothing inside it is trapped. A CPU access to the large image still stores it through the usual hooks: the test's next step stores one block of the large image and checks that this releases the trapped image with its own results. Linux and Windows have no label traps, and their path is unchanged.

Tested

Setup:

  • Apple M4, macOS 26.7.3, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), Apple clang 21.0.0
  • full Release build with -DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under Rosetta
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1
  • on main with the open macOS build fixes applied

Results:

  • agc_small_tiled_shadow_label fails before this change and passes after it, including the later steps: the block store releasing the inner trap, and the reads of both images.
  • I ran ctest -R '^(agc|shader|job)' (1578 tests, -j 1) and compared it with the same run before this change: agc_small_tiled_shadow_label is fixed and nothing that passed before fails because of this change. agc_driver_msaa_dcc_clear_2 failed once in that run; it is intermittent on this machine and failed the same way in earlier runs without this change.

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: none
  • GPUs tested: Apple M4 (MoltenVK 1.4.2, LunarG Vulkan SDK 1.4.363.1, macOS 26.7.3)
  • AI-assisted: yes

@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

Nothing blocks this change; the implementation skips occasional label stores for overlapping images while a read trap is active, preserving the existing later flush path.

What I ran

Reviewed head 23d1a9d34ec7f447c6089a2e5a5ad86be2dcf376 using repo_read.py for targeted source reads. No tests were run during this review; test results in the description are author reported.

Results

Check Result Note
Diff and implementation passed Targeted logic and callers read
Tests not run Author reported test runs only

Findings

Blocking

None.

Non-blocking

None.

Not verified

Read description.md, commits.md, manifest.json, diff.patch, and targeted sections of Texture.cpp, Texture.hpp, and Recorder.cpp. The full changed Texture.cpp was excluded from the review folder because it was too large; only the relevant method, overlap helper, trap handling, and test context were read. No test execution, macOS runtime, or non-Apple build was verified.

To get this to a good state

Nothing is required.

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

github-actions Bot commented Nov 14, 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 1368 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6192 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6209 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6280 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6481 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 10743 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 12746 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13251 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13796 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 18369 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 19130 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 22190 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp

@ghost

ghost commented Nov 15, 2026

Copy link
Copy Markdown

Windows + NVIDIA (Blackwell) run of head 23d1a9d34e, merged with git merge --no-ff onto main 9659ce01e4 (clean merge). A non-macOS check that the changed label path keeps passing on Windows.

Setup: Windows 11 Pro, NVIDIA GeForce RTX 5070 Ti, driver 621.01, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1. Both sides carry the diff of #19899, without which main does not compile on MinGW.

main 9659ce01e4 this PR
build completes completes
agc_small_tiled_shadow_label, agc_driver_msaa_dcc_clear_2 pass 2 of 2 pass in 3 of 3 serial runs
same tests with ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.363), VK_LOADER_DEBUG=layer, ctest -V pass, 0 VUID- lines pass, 0 VUID- lines
ctest -R '^(agc|shader|video_out|guest_video_out)' -j 12 0 failed 1834 tests, 0 failed, 20 skipped (the same skips as main)

AI-assisted: yes

@kurexw kurexw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on macOS 27.2 / Apple M4 with MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1, validation layer 1.4.363), x86-64 build under Rosetta. This is the only GPU I tested.

Head 23d1a9d34e merged alone onto main 3b17977ba6, compared with 3b17977ba6 itself. I ran the 29 AGC tests that fail on main on this Mac, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer, through ctest --test-dir build -R <those 29> -V, three runs per side. Every Vulkan test logged Insert instance layer "VK_LAYER_KHRONOS_validation" and none logged was not found but was requested by env var VK_INSTANCE_LAYERS.

test main (3 runs) this PR (3 runs)
agc_small_tiled_shadow_label Failed, Failed, Failed Passed, Passed, Passed

The other 27 tests gave the same result on both sides.

agc_driver_label_after_import_copy is flaky on main as well: main Failed, Passed, Passed, this PR Passed, Passed, Passed. Every failure on either side is the same timing check ("round N: a CPU read after the label that followed the copy found K of 262144 destination bytes not yet copied"), and it varied the same way across the other PRs I tested in the same session, so I don't attribute it to this change.

VUID- lines: identical per test on both sides (30 on main, 30 with this PR, over the three runs). The VUID- lines on both sides are main's existing VUID-VkDeviceCreateInfo-sType-unique (a duplicated VkPhysicalDevicePortabilitySubsetFeaturesKHR in the device pNext chain) and VUID-VkSamplerCreateInfo-samplerMipLodBias-04467; this PR adds none.

@Jazeupoi

Jazeupoi commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Tested this head (23d1a9d34e) on Apple M4, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.1), x86-64 Release under Rosetta 2. Base: main d3074de315 with #17425 and #11049 (needed for the macOS build) and #20845 merged locally; "this PR" is the same tree with this head merged (clean merge).

  • agc_small_tiled_shadow_label run alone 10 times (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1): 10/10 fail on the base, 0/10 with this PR.
  • ctest -R 'label|shadow|recorder_' (60 tests), twice per build: the base failed 6 and 6, this PR 5 and 5. The difference is agc_small_tiled_shadow_label; the other five (label_after_import_copy, label_ordered_flush, label_ordered_flush_unimported, unregistered_label_behind_write_back, unregistered_label_on_gpu) fail on both.
  • SuperTuxKart (PPSA69421) race, same scripted input: frame p50 147.5 ms on the base, 149.1 ms with this PR; it draws the same.

This head also merges cleanly with #21972, which edits the trap checks in the same function.

Also run under the Khronos validation layer 1.4.363 (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer): the layer is inserted (no was not found messages), and this PR adds no VUID- messages; the base and this PR report the same ones.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 23d1a9d34e, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#17478, #21223, #24030, #24201, #14202, #18889, #19531, #21641, #21773, #22468, #22471, #23239, #23255, #23484, #23869, #23992, #24311, #18425, #21195, #21255, #22989, #23507, #23886, #14582, #17878, #19666, #19899, #21656, #21746). 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
none: no test of its own in this PR - -

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 4 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. The 2125 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 86c3e3a into boykopovar:main Nov 22, 2026
14 checks passed
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.

6 participants