Skip to content

fix(agc): take a depth plane a shader wrote through its own view from that image, not from stale guest bytes - #23739

Open
yinx080 wants to merge 3 commits into
boykopovar:mainfrom
yinx080:fix/agc-depth-from-alias
Open

yinx080 wants to merge 3 commits into
boykopovar:mainfrom
yinx080:fix/agc-depth-from-alias

Conversation

@yinx080

@yinx080 yinx080 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

The Exit 8 (PPSA23276, UE5 with Nanite) renders most walls and floors black on main: the G-buffer stays empty there, so lighting has nothing to shade.

The draws that fail are UE5's classic Nanite material pass:

  • Each material draws at depth materialId / 16383.
  • The draw tests EQUAL against the Nanite material depth, a separate D32 target.

The material depth is written by Nanite's emit pass, a compute shader, through the title's own R32F storage view of the depth memory. That memory is Z64KBX, the same surface as the depth surface's mirror.

Right after the emit, that view holds the correct material ids on every wall and floor pixel. Then this happens:

  1. The view's write-back is empty: its layerGeneration is still the one from its first upload, every unit has been stamped since, so every unit counts as written by someone else and the results are dropped without a store.
  2. At the next bind, the depth surface sees every unit changed and refreshes its own mirror from guest memory. The mirror is a second StorageTexture with the same surface.
  3. The mirror gets the bytes of whatever transient resource used that memory before, in whole 64 KiB units.
  4. The EQUAL test fails on most of the screen.

This change takes each changed unit from the image that wrote it last, and only while it is the last writer:

  • A write-back records the stamp it makes over each tracked unit (StorageTexture::stampStored replaces the three MarkWritten loops of writeBack), and markLayersPending records the tracker generation of each unit's latest results (layerResultsSince).
  • StorageTexture::DepthPlaneWriters looks at the live images with exactly the mirror's surface at the same address. A changed unit goes to the image whose latest results or own write-back is newer than every stamp on the unit's block; when several qualify, the newest wins.
  • DepthSurface::SyncFromMemory copies those units on the device from their images, and every other changed unit from the mirror, as before. A CPU store, a DMA copy or another image's write-back made after the shader write stamps the block newer, so the guest bytes win there.
  • APS5_NO_DEPTH_FROM_ALIAS restores the old path; its row in docs/dev/ENVIRONMENT.md describes the rule.
  • New tests agc_driver_depth_plane_alias_* (IvanFogel's fixture from the review): a shader write through an R32F view, then a CPU store or a PM4 DMA_DATA copy into one unit, with no draw first, a draw in between (_split) or a bind before the write (_prebind). They skip when the plane is not write-watched or its block generations are unavailable.

Both references are needed. The emit view in The Exit 8 never stores (step 1), so only its results time shows it wrote last; with the write-back stamp alone the corridor stays 54-100 % black. The write-back stamp covers an image whose results did reach memory, since its own stamp is newer than its results.

Overlap with #15621. #15621 changes SyncFromMemory and Texture.hpp too, so one of the two will need a rebase after the other. It doesn't fix this case on its own: main + #15621 rendered 31-100 % of the corridor near-black.

Root cause. The empty write-back in step 1 is why guest memory never receives the results. This change works around it for depth planes; if the write-back's generation check is the place to fix it, I can look at that in a separate PR.

Tested

Windows 11 Pro (26200), Ryzen 7 5800H, RTX 3060 Laptop (NVIDIA 610.91), WinLibs GCC 15.2.0 r7, Release, main 07336cc200 + this branch (5d622cc26c).

  • The Exit 8, 1080p, opening corridor. A 200 s scripted walk with a window shot every 30 s; the share of near-black pixels (max channel < 12) in the lower part of the screen, where the walls and floor are:

    30 s 60 s 90 s 120 s 150 s
    APS5_NO_DEPTH_FROM_ALIAS=1 54.1 % 70.3 % 100 % 100 % 100 %
    this PR 0.6 % 0.5 % 0.0 % 0.0 % 0.0 %

    The 180 s shot of the last run failed to capture; the run went the full 200 s. Walls, floor, tiles, posters and the guide line render with correct occlusion, and the frame rate matches the path-off run: about 58-74 presents per 10 s after warm-up in both, with an occasional dip in each.

  • The new cases, 10 runs each:

    Case pass / skip / fail
    _split (control, CPU, DMA) 10 / 0 / 0 each
    control_prebind 4 / 6 / 0
    cpu_prebind 5 / 5 / 0
    dma_prebind 4 / 6 / 0
    no draw first (control, CPU, DMA) 0 / 10 / 0 each

    On Windows the write watch stops covering the plane after the storage write-back in every run without a draw first and in about half the _prebind runs, with or without this PR; those runs skip. Before the rework, cpu_split, dma_split, cpu_prebind and dma_prebind failed on the draw assertion and passed with APS5_NO_DEPTH_FROM_ALIAS=1, matching IvanFogel's Linux run.

  • Unit tests. ctest -R "^agc_driver_depth": 54 of 54 pass (45 existing + 9 new), and the same with APS5_NO_DEPTH_FROM_ALIAS=1.

  • Stray (PPSA02100), regression check, on the previous head dbb10a3638: 5.68 fps with APS5_NO_DEPTH_FROM_ALIAS=1, 5.69 fps with it on. Not rerun on this head.

  • tools/check_conventions.py --base origin/main and tools/check_test_registration.py build pass.

  • Not run: Linux, the validation layer.

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 (overlaps fix(agc): order driver stores over a depth plane by record order #15621, see above)
  • Fixes: none
  • Unblocks: PPSA23276 The Exit 8 (PPSA23276) #8587
  • GPUs tested: NVIDIA GeForce RTX 3060 Laptop, driver 610.91, Windows 11
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

… that image, not from stale guest bytes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Nov 19, 2026
@yinx080

yinx080 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author
30s image-1795101077005

@oneandonlydean

Copy link
Copy Markdown
Collaborator

The new SyncFromMemory path takes changed units from the alias without proving the alias wrote them last. A CPU or DMA write, or another image's write-back, that lands after the shader write would be replaced by the alias's older texels.

Could you gate it per unit the way the refresh borrow in Texture.cpp does (GuestMemory::ChangedBlocks against alias->layerGeneration, plus Cached and CopyRefusal), and keep the alias itself (weak_ptr plus its version) instead of a bare aliasVersion? Versions are per image, so the highest version across several images does not say which one moved.

I would also like an agc_driver_depth case: shader write through an R32F view, then a CPU write to one unit, then a bind, expecting the CPU bytes in that unit. The write-back visibility issue you raised still looks like the root cause; once gated, this is a fine stopgap.

@github-actions github-actions Bot added docs agc libSceAgc* labels Nov 19, 2026
@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

NVIDIA Linux run with the Khronos validation layer; Tested is on Windows (RTX 3060 Laptop).

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 dbb10a3638 merged onto main e1ab104e0a with --no-ff (clean, as 40e9759b16). 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_depth' -V
main e1ab104e0a this PR
Result 45 of 45 passed 45 of 45 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 50 50
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

The PR adds no test, so this shows the existing depth tests do not regress with the alias path on (the default); it does not show that any of them reach the new FindLiveNewest path.

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

AI-assisted: yes (Claude Code)

@yinx080

yinx080 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@oneandonlydean thanks, agreed on the hazard. Before pushing, a question, because the gate as described rejects the writer in this title every time.

I implemented it as you described:

  • the alias is kept as std::weak_ptr plus its version;
  • candidates are live images with the mirror's exact surface;
  • each candidate is checked with Cached and CopyRefusal;
  • each unit is taken only when ChangedBlocks against alias->layerGeneration reports BlockUnchanged and the generation is not 0.

With that, The Exit 8's corridor goes back to 54-100 % black. A local diagnostic in FindDepthPlaneWriter shows why. Opening corridor, about 130 syncs over 90 s, two candidate images per sync:

check result
Cached() one of the two candidates is uncached: the transient storage view of the dispatch
CopyRefusal(context, &mirror, source, address) "released" for the other one, because the mirror itself is uncached; with the source alone it passes
ChangedBlocks(..., layerGeneration, stamped, cpu) all 84 units stamped after layerGeneration in every sync once the image is no longer pending; cpu is 0 for all of them
units gated 84 only in the 4 syncs where the image's results were still pending; 0 in all the others

So by the time the plane syncs, the writer has written back. Its own write-back stamps every unit above the generation the image recorded when the shader wrote, and the gate can't tell that stamp from another image's write-back or a DMA write. The refresh borrow doesn't hit this, since it only takes pending units.

Two ways I can see:

  1. Gate on CPU stores only. Take a unit when ChangedBlocks' cpu output says no collect stamped it since layerGeneration. Choose the writer per unit as the live image with the newest layerGeneration there, so a later write-back by another image wins over it. This covers the test you asked for (CPU write after the shader write → CPU bytes win) and keeps Exit 8 rendering. It still lets a DMA write that lands after the shader write be overwritten.
  2. Record the write-back's own stamp. The store records the generation it stamped per unit, and the gate allows only that stamp. That closes the DMA case too, but changes the write-back path, which feels closer to the root cause than this PR should go.

Which would you prefer? Or, if you'd rather the write-back visibility issue be fixed directly, I can look at that instead and close this PR as a stopgap that wasn't needed.

The agc_driver_depth case (shader write through an R32F view, CPU write to one unit, bind, CPU bytes expected) will come with whichever version you pick.

AI-assisted: yes (Claude Code)

@Colewiz7

Copy link
Copy Markdown
Contributor

Head dbb10a3638 merged onto main 23786c4e4f as caf5016176, 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 added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 19, 2026

@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 based on the source inspected; the reported runtime and test results were not independently run.

What I ran

Reviewed head dbb10a363881dc91d6b4aaa2326233881534fdf7. No commands or tests were run. Read description.md, commits.md, manifest.json, diff.patch, and the complete changed files Texture.hpp, DepthSurface.cpp, and docs/dev/ENVIRONMENT.md; read the changed function and surrounding context in Texture.cpp through the pinned reader. No changed files were excluded by the prepared manifest.

Results

Check Result Note
Diff and changed code review passed Four changed files inspected
Tests and build not run Results in the PR description are author-reported
Runtime behavior not run No console run performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full text of Texture.cpp was not read because it was excluded from the review folder for size; only the changed implementation and relevant context were read through repo_read.py. Tests, build, and reported console behavior were not independently verified. No code-level test coverage for this changed behavior was confirmed.

To get this to a good state

Nothing is required.

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

I reproduced the later-writer regression discussed above. With an R32F storage write followed by an ordinary CPU store or a PM4 DMA_DATA copy into one depth tile, guest memory contains the new value but the next depth draw uses the older image. This happens when the depth surface was already bound. The cold first-bind cases pass.

Same nine cases on an RTX 3070 Ti Result
Main e825fa1492 9/9 passed
PR dbb10a3638 merged into that main 5/9 passed
Same PR build with APS5_NO_DEPTH_FROM_ALIAS=1 9/9 passed

In each failing case, 16,399 pixels should pass the depth test. The PR draws 15, losing exactly the 16,384 pixels in the overwritten tile. CPU and DMA stores both advance the tile’s guest generation. Only the CPU store sets the CPU-write flag. A CPU-only gate would still accept stale texels after the DMA copy. I traced all four failures to the new alias-copy branch. Each time it copied one rectangle for tile 2 from alias version 2.

Four existing depth tests passed on both trees. All runs required real Vulkan with the shader cache disabled, logged the Khronos validation layer, and produced no VUID or synchronization diagnostics. Tested on CachyOS Linux, NVIDIA GeForce RTX 3070 Ti, driver 620.70.06. This was a synthetic draw and did not run The Exit 8.

Regression fixture and run instructions

The patch below applies to main e825fa1492 and its merge with this PR. After applying it, configure the usual test build, build agc_driver_depth_plane_partial_store_tests, and run:

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_LOADER_DEBUG=layer VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R '^peer_23739_' -V
--- a/core/libs/prx/libSceAgcDriver/tests/execution/DepthPlanePartialStore.cpp
+++ b/core/libs/prx/libSceAgcDriver/tests/execution/DepthPlanePartialStore.cpp
@@ -1,3 +1,4 @@
+#include "prx/libSceAgcDriver/Execution/include/Pm4.hpp"
 #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
 #include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp"
 #include "prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp"
@@ -126,6 +127,62 @@
 
 }
 
+constexpr std::uint32_t Threads = 32;
+constexpr std::uint32_t Format8Uint = 5;
+constexpr std::uint32_t Format16Unorm = 7;
+constexpr std::uint32_t Format32Float = 22;
+constexpr std::uint32_t TileDepth64KB = 0x18;
+constexpr std::uint32_t Type2D = 9;
+constexpr std::uint32_t Type2DArray = 13;
+
+
+constexpr std::uint32_t RowPasses = 15;
+
+alignas(256) constexpr std::array<std::uint32_t, 9> StoreRowCode{
+    0x7e280d00, 0x102828ff, 0x3cf80000, 0x7e3c0300, 0x7e3e0280, 0xf0201108, 0x0001141e, 0xbf810000, 0xbf810000,
+};
+
+alignas(256) constexpr std::array<std::uint32_t, 7> StoreStencilRowCode{
+    0x7e280281, 0x7e3c0300, 0x7e3e0280, 0xf0201108, 0x0001141e, 0xbf810000, 0xbf810000,
+};
+
+alignas(256) constexpr std::array<std::uint32_t, 10> StoreRowLayerCode{
+    0x7e280d00, 0x102828ff, 0x3cf80000, 0x7e3c0300, 0x7e3e0280, 0x7e400280, 0xf0201128, 0x0001141e, 0xbf810000, 0xbf810000,
+};
+
+std::array<std::uint32_t, 8> StorageView(std::uint64_t address, std::uint32_t format, std::uint32_t layers, std::uint32_t baseLevel = 0, std::uint32_t lastLevel = 0) {
+    return {
+        static_cast<std::uint32_t>(address >> 8u),
+        static_cast<std::uint32_t>((address >> 40u) & 0xffu) | (format << 20u) | (((PlaneWidth - 1u) & 3u) << 30u),
+        ((PlaneWidth - 1u) >> 2u) | ((PlaneHeight - 1u) << 14u),
+        0xfacu | (baseLevel << 12u) | (lastLevel << 16u) | (TileDepth64KB << 20u) | ((layers > 1u ? Type2DArray : Type2D) << 28u),
+        layers - 1u, lastLevel << 4u, 0u, 0u,
+    };
+}
+
+void Store(AgcDriver::VulkanDevice& device, const std::array<std::uint32_t, 8>& view, std::span<const std::uint32_t> code) {
+    std::vector<std::uint32_t> userData(16, 0u);
+    std::copy(view.begin(), view.end(), userData.begin() + 4);
+    const std::array<ShaderRecompiler::MemoryRegion, 1> memory{{{reinterpret_cast<std::uintptr_t>(code.data()), std::as_bytes(code)}}};
+    const ShaderRecompiler::ShaderComputeStageInfo compute{{Threads, 1, 1}, 0u, {false, false, false}, false, 1};
+    ShaderRecompiler::RecompileRequest request{
+        {ShaderRecompiler::ShaderStage::Compute, reinterpret_cast<std::uintptr_t>(code.data()), code, 0, {}},
+        {32, 0, userData, compute, std::nullopt, std::nullopt, memory},
+        device.Target(),
+        {0, 0, 0, 128}
+    };
+    request.useCache = false;
+    const auto program = ShaderRecompiler::Recompile(request);
+    device.Dispatch(program, 1, 1, 1, {}, reinterpret_cast<std::uintptr_t>(code.data()));
+    device.WaitIdle();
+}
+
+void StoreRow(AgcDriver::VulkanDevice& device, std::uint8_t* plane, VkFormat format, std::uint32_t layers, std::uint32_t level = 0) {
+    const std::span<const std::uint32_t> code = layers > 1u ? std::span<const std::uint32_t>(StoreRowLayerCode) : std::span<const std::uint32_t>(StoreRowCode);
+    Store(device, StorageView(reinterpret_cast<std::uintptr_t>(plane), format == VK_FORMAT_D16_UNORM ? Format16Unorm : Format32Float, layers, level, level), code);
+}
+
+
 int main(int argc, char** argv) {
     try {
         const bool uploadImage = argc > 1 && std::string(argv[1]) == "--upload-image";
@@ -148,6 +205,54 @@
         const auto draw = [&](const Surface& surface, const DrawOptions& options) { return Draw(*device, shaders, surface, options, PlaneExtent, Colors); };
         const DrawOptions writeHalf{.depthWrite = true, .depthCompare = VK_COMPARE_OP_ALWAYS};
 
+        if (argc==2 && std::string_view(argv[1]).starts_with("--peer-")) {
+            const std::string mode(argv[1]);
+            const auto watched=AgcDriver::GuestMemory::Watched(base, PlaneBytes);
+            Require(watched, "six-unit depth plane requires write watch");
+            Fill(plane, 0.25f);
+            if (mode.ends_with("-prebind")) std::printf("first bind covered %u pixels\n",draw(depth,writeHalf));
+            StoreRow(*device, reinterpret_cast<std::uint8_t*>(plane), VK_FORMAT_D32_SFLOAT, 1);
+            AgcDriver::Graphics::StorageTexture::FlushPending(base, PlaneBytes, nullptr, "test");
+            device->WaitIdle();
+            std::printf("published row guest > half %zu, registered cached writer %d\n",
+                static_cast<std::size_t>(std::count_if(plane,plane+PlaneBytes/4,[](float x){return x>0.5f;})),
+                AgcDriver::Graphics::StorageTexture::FindLive(base,PlaneBytes)!=nullptr);
+            if (mode.ends_with("-split")) {
+                const auto first=draw(depth,{});
+                std::printf("before unit replacement draw passed %u texels\n",first);
+                Require(first==RowPasses,"guest shader row was not readable through depth");
+            }
+            AgcDriver::GuestMemory::CollectWritesUncached(base,PlaneBytes);
+            const auto before=AgcDriver::GuestMemory::TrackerGeneration();
+            auto expected=RowPasses;
+            if (mode.find("-cpu")!=std::string::npos) {
+                FillUnit(plane,2,0.75f);
+                expected+=UnitTexels;
+            } else if (mode.find("-dma")!=std::string::npos) {
+                const auto source=reinterpret_cast<std::uintptr_t>(blocks);
+                const auto destination=base+2*Block;
+                std::fill_n(reinterpret_cast<float*>(blocks),UnitTexels,0.75f);
+                const std::array<std::uint32_t,7> packet{0xc0055000,0x60000000,
+                    static_cast<std::uint32_t>(source),static_cast<std::uint32_t>(source>>32),
+                    static_cast<std::uint32_t>(destination),static_cast<std::uint32_t>(destination>>32),Block};
+                AgcDriver::QueueState queue;
+                AgcDriver::Pm4::Validate(packet,0);
+                AgcDriver::Pm4::Execute(packet,queue);
+                expected+=UnitTexels;
+            }
+            const auto inMemory=static_cast<std::size_t>(std::count_if(plane,plane+PlaneBytes/4,[](float x){return x>0.5f;}));
+            AgcDriver::GuestMemory::CollectWritesUncached(base,PlaneBytes);
+            std::array<std::uint64_t,Units> generation{};
+            generation.fill(before);
+            std::array<std::uint8_t,Units> changed{},cpu{};
+            Require(AgcDriver::GuestMemory::ChangedBlocks(base,PlaneBytes,generation,changed,cpu),"watched block generations must be available");
+            std::printf("unit 2 guest stamp %u CPU stamp %u\n",changed[2],cpu[2]);
+            const auto got=draw(depth,{});
+            std::printf("mode %s guest %zu GPU %u expected %u\n",mode.c_str(),inMemory,got,expected);
+            Require(inMemory==expected,"guest bytes before draw must contain both ordered writes");
+            Require(got==expected,"depth test must observe both ordered writes");
+            return 0;
+        }
         const bool pageWatch = argc == 2 && std::string_view(argv[1]) == "--cpu-write-after-page-unwatch";
         const bool partialWatch = pageWatch || (argc == 2 && std::string_view(argv[1]) == "--cpu-write-after-partial-unwatch");
         if (partialWatch || (argc == 2 && std::string_view(argv[1]) == "--cpu-write-after-memo")) {
--- a/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_depth_plane_partial_store_tests.cmake
+++ b/core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_depth_plane_partial_store_tests.cmake
@@ -60,3 +60,30 @@
     add_test(NAME agc_driver_depth_plane_partial_store_buffer_copy COMMAND agc_driver_depth_plane_partial_store_tests --buffer-copy)
     add_test(NAME agc_driver_depth_plane_partial_store_upload_image COMMAND agc_driver_depth_plane_partial_store_tests --upload-image)
 endif()
+
+add_test(NAME peer_23739_control COMMAND agc_driver_depth_plane_partial_store_tests --peer-control)
+set_tests_properties(peer_23739_control PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_cpu COMMAND agc_driver_depth_plane_partial_store_tests --peer-cpu)
+set_tests_properties(peer_23739_cpu PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_dma COMMAND agc_driver_depth_plane_partial_store_tests --peer-dma)
+set_tests_properties(peer_23739_dma PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_control_split COMMAND agc_driver_depth_plane_partial_store_tests --peer-control-split)
+set_tests_properties(peer_23739_control_split PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_cpu_split COMMAND agc_driver_depth_plane_partial_store_tests --peer-cpu-split)
+set_tests_properties(peer_23739_cpu_split PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_dma_split COMMAND agc_driver_depth_plane_partial_store_tests --peer-dma-split)
+set_tests_properties(peer_23739_dma_split PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_control_prebind COMMAND agc_driver_depth_plane_partial_store_tests --peer-control-prebind)
+set_tests_properties(peer_23739_control_prebind PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_cpu_prebind COMMAND agc_driver_depth_plane_partial_store_tests --peer-cpu-prebind)
+set_tests_properties(peer_23739_cpu_prebind PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
+
+add_test(NAME peer_23739_dma_prebind COMMAND agc_driver_depth_plane_partial_store_tests --peer-dma-prebind)
+set_tests_properties(peer_23739_dma_prebind PROPERTIES ENVIRONMENT "ANYPS5_NO_SHADER_CACHE=1" TIMEOUT 30 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")

AI-assisted review.

aliasVersion = alias->Version();
if (StoresUnits(*alias)) {
const auto rects = alias->UnitRects(changed);
copyPlane(mirrorPlane, alias, false, false, true, &rects);

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.

Please select the source per changed tile. An alias can provide the data when it is still the last writer, including its own write-back. A later CPU store or DMA copy must win for that tile. Of the two options discussed above, tracking the generation from the alias’s own write-back can distinguish the DMA case, provided the stamp belongs to that same alias and tile. The attached fixture covers both orderings and preserves the shader-only result as a control.

@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 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 24327 docs/dev/ENVIRONMENT.md L348
PR 29074 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L605
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L8170
PR 29082 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L605
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L8170
PR 29083 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp L605
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp L8170

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 1395 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 1896 docs/dev/ENVIRONMENT.md
PR 4448 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 4472 docs/dev/ENVIRONMENT.md
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 6186 docs/dev/ENVIRONMENT.md
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 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6924 docs/dev/ENVIRONMENT.md
PR 7085 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7275 docs/dev/ENVIRONMENT.md
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 7643 docs/dev/ENVIRONMENT.md
PR 8246 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 9289 docs/dev/ENVIRONMENT.md
PR 9345 docs/dev/ENVIRONMENT.md
PR 9356 docs/dev/ENVIRONMENT.md
PR 9387 docs/dev/ENVIRONMENT.md
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_depth_plane_partial_store_tests.cmake
core/libs/prx/libSceAgcDriver/tests/execution/DepthPlanePartialStore.cpp
docs/dev/ENVIRONMENT.md
PR 9712 docs/dev/ENVIRONMENT.md
PR 9852 docs/dev/ENVIRONMENT.md
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 10469 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10743 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 11435 docs/dev/ENVIRONMENT.md
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 12324 docs/dev/ENVIRONMENT.md
PR 12746 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 12792 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 12849 docs/dev/ENVIRONMENT.md
PR 13251 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 13809 docs/dev/ENVIRONMENT.md
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 15136 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 15456 docs/dev/ENVIRONMENT.md
PR 15548 docs/dev/ENVIRONMENT.md
PR 15570 docs/dev/ENVIRONMENT.md
PR 16217 docs/dev/ENVIRONMENT.md
PR 16372 docs/dev/ENVIRONMENT.md
PR 16793 docs/dev/ENVIRONMENT.md
PR 16953 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 17259 docs/dev/ENVIRONMENT.md
PR 17611 docs/dev/ENVIRONMENT.md
PR 17719 docs/dev/ENVIRONMENT.md
PR 17729 docs/dev/ENVIRONMENT.md
PR 17943 docs/dev/ENVIRONMENT.md
PR 18029 docs/dev/ENVIRONMENT.md
PR 18082 docs/dev/ENVIRONMENT.md
PR 18173 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 18226 docs/dev/ENVIRONMENT.md
PR 18829 docs/dev/ENVIRONMENT.md
PR 19557 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 20041 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 20063 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 20172 docs/dev/ENVIRONMENT.md
PR 20183 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 20518 docs/dev/ENVIRONMENT.md
PR 20728 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 21211 docs/dev/ENVIRONMENT.md
PR 22062 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22071 docs/dev/ENVIRONMENT.md
PR 22424 docs/dev/ENVIRONMENT.md
PR 22434 docs/dev/ENVIRONMENT.md
PR 22531 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 22546 docs/dev/ENVIRONMENT.md
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 22697 docs/dev/ENVIRONMENT.md
PR 23242 docs/dev/ENVIRONMENT.md
PR 23596 docs/dev/ENVIRONMENT.md
PR 23674 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
PR 23811 docs/dev/ENVIRONMENT.md
PR 23975 docs/dev/ENVIRONMENT.md
PR 24083 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 24661 docs/dev/ENVIRONMENT.md
PR 24714 docs/dev/ENVIRONMENT.md
PR 25561 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 25574 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 25716 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 26686 docs/dev/ENVIRONMENT.md
PR 27133 docs/dev/ENVIRONMENT.md
PR 27864 docs/dev/ENVIRONMENT.md
PR 28119 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28140 docs/dev/ENVIRONMENT.md
PR 28142 docs/dev/ENVIRONMENT.md
PR 28150 docs/dev/ENVIRONMENT.md
PR 28176 core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28193 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
PR 28229 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 28299 docs/dev/ENVIRONMENT.md
PR 28372 docs/dev/ENVIRONMENT.md
PR 28384 docs/dev/ENVIRONMENT.md
PR 28387 docs/dev/ENVIRONMENT.md
PR 28391 docs/dev/ENVIRONMENT.md
PR 28470 core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
docs/dev/ENVIRONMENT.md
PR 28487 docs/dev/ENVIRONMENT.md
PR 28488 docs/dev/ENVIRONMENT.md
PR 28590 docs/dev/ENVIRONMENT.md
PR 28673 docs/dev/ENVIRONMENT.md
PR 28738 docs/dev/ENVIRONMENT.md
PR 28786 docs/dev/ENVIRONMENT.md
PR 28787 docs/dev/ENVIRONMENT.md
PR 28808 docs/dev/ENVIRONMENT.md
PR 28960 docs/dev/ENVIRONMENT.md
PR 28962 docs/dev/ENVIRONMENT.md
PR 28964 docs/dev/ENVIRONMENT.md

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head dbb10a3638, applied with git apply on main fd4aeed483 together with the other 25 PRs of one batch (#24107, #24132, #24238, #15143, #22088, #22685, #24032, #16054, #20001, #20344, #24170, #24396, #16856, #17298, #20497, #23347, #24426, #24554, #24598, #21376, #21556, #22047, #22082, #14124, #18476). 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 (6524 tests) on the RTX 3080 has 8 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: #21556 (guest_json_allocator), #16856 (guest_kernel_sys_module_internal), #15143 (guest_math_exact); 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): public_headers. The 2127 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)

yinx080 and others added 2 commits November 22, 2026 20:19
… wrote it last

A depth plane sync took every changed unit from the newest live image with the
mirror's surface, so a CPU store or DMA copy made after the image's shader write
was replaced by the image's older texels. A unit now comes from an image only
when no stamp landed on its block after the image's latest results or after its
own write-back (the newest such image wins); other changed units come from the
mirror as before. Write-backs record the stamp they make per unit for this.

Adds the agc_driver_depth_plane_alias_* cases (shader write, then a CPU store or
a DMA copy into one unit, with and without an earlier bind or draw).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yinx080

yinx080 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@IvanFogel thanks for the fixture and the clear reproduction. I reworked it as you suggested: the source is now chosen per tile. Main 07336cc200 is merged in first (3734906fcb, no conflicts); the change is 5d622cc26c.

What changed

  • A storage image's write-back records the stamp it made on each tile (layerStoredStamp). Each time the image's results are marked pending, it also records the tracker generation of those results for each tile (layerResultsSince).
  • At a depth plane sync, a changed tile comes from a live image with exactly the mirror's surface only when nothing has stamped that tile since that image's own write-back or its latest results. If several images qualify, the newest one wins. The other changed tiles come from the mirror, as on main. A later CPU store, DMA copy or another image's write-back stamps the tile newer, so the guest bytes win there.
  • The bare aliasVersion is gone, so nothing is copied just because a version moved.

Why both references: in The Exit 8 the writer's own write-back is empty every frame. Its layerGeneration stays at its first upload, so every tile looks written since then, and its results are dropped without a store. That is the visibility problem from earlier in this thread. So the writer never makes a stamp of its own, and its results time is what shows it was the last writer. The write-back stamp covers the case where it did store, since that stamp is newer than its results. With only the write-back stamp, the corridor was 54-100 % black again, as on main.

Your fixture is in as agc_driver_depth_plane_alias_{control,cpu,dma}{,_split,_prebind}, with three changes:

  • the tests are renamed to match the file;
  • they are registered like their neighbours (SKIP_RETURN_CODE 77, PATH on Windows);
  • the two preconditions (plane watched, block generations available) now skip instead of failing.

On Windows the tracker stops covering the plane after the storage write-back: always in the three cases without a draw first, and in about half the _prebind runs. This happens with and without this PR, and in those runs the path-off build also draws the old tile. So the non-split cases rely on your Linux run.

Windows 11, RTX 3060 Laptop, driver 610.91, 10 runs per case:

Case this PR: pass / skip / fail
control_split, cpu_split, dma_split 10 / 0 / 0 each
control_prebind 4 / 6 / 0
cpu_prebind 5 / 5 / 0
dma_prebind 4 / 6 / 0
control, cpu, dma 0 / 10 / 0 each (tracker unavailable)

Before the rework, the same build with your fixture failed cpu_split, dma_split, cpu_prebind and dma_prebind on the draw assertion, and passed them with APS5_NO_DEPTH_FROM_ALIAS=1, matching your table.

Other checks

  • ctest -R '^agc_driver_depth': 54 of 54 pass (45 existing + 9 new), both with the path on and with APS5_NO_DEPTH_FROM_ALIAS=1.
  • The Exit 8, scripted corridor walk, a window shot every 30 s, near-black share of the walls and floor:
30 s 60 s 90 s 120 s 150 s 180 s
APS5_NO_DEPTH_FROM_ALIAS=1 (main's behaviour) 54 % 70 % 100 % 100 % 100 % 100 %
this PR 0.6 % 0.5 % 0.0 % 0.0 % 0.0 % (window capture failed; the run went the full 200 s)
  • tools/check_test_registration.py build: passes.

Not run: Linux, and the validation layer.

AI-assisted: yes (Claude Code)

@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 — comments

The alias refresh path and its test changes were reviewed at head 5d622cc26c81a33c184e70d1a905b807c688f9c5; Texture.cpp was excluded from the review bundle, so the complete changed implementation was not verified.

What I ran

No build or tests were run. I used repo_read.py to inspect the prepared description, commits, manifest, diff, changed-file ranges, and tracker declarations/behavior at the pinned head.

Results

Check Result Note
Prepared diff review passed Core changed paths and test logic inspected
Full changed-file review not run Texture.cpp full text was excluded
Build and tests not run No commands run

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

The full text of core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp was excluded as too large; only its changed regions were read. The manifest lists six changed files, and all six were reviewed; this excluded file was only partially read. No build, tests, Linux run, validation-layer run, or physical-console behavior was verified. The author-reported Windows test results were not run by this review.

To get this to a good state

Nothing is required. The implementation in the excluded portion of Texture.cpp remains unverified, so this review does not make a formal approval decision.

@yinx080

yinx080 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The windows job failed on one test, guest_jxr_bitio (abort, exit code 0xc0000409, in libSceJxr). This PR doesn't touch libSceJxr. The same test aborted the same way on an unrelated PR in run 45068616380, so it looks flaky. The other 5,598 tests passed.

I can't re-run jobs here. Could a maintainer re-run the failed job?

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot added the build label Nov 23, 2026
@Helldiverr

Copy link
Copy Markdown
Contributor

Builds and passes on AMD RDNA4 with the Khronos validation layer: 0 VUID- and 0 synchronization hazards, and every head run gives the same results. However, none of the new alias tests fails on main, and they still pass when the new per-writer copy is removed. On this machine they guard the later-writer rule but do not show the fix itself. The two prebind cases skip here.

What this run adds.

  • Earlier runs: Colewiz7 on RADV (7900 XT), on the earlier head dbb10a3638 only. The author ran the current head on an RTX 3060 Laptop without the validation layer.
  • This run adds:
    • the first AMD run, with and without the layer, of head 5d622cc26c, on Windows with a discrete RDNA4 GPU;
    • synchronization validation;
    • a negative control and two mutations.

Code.

  • DepthSurface.cpp:1948-1966 on the head: when the mirror stores units and APS5_NO_DEPTH_FROM_ALIAS is unset, DepthPlaneWriters picks live aliases that share the mirror's base, shape and tracked layers. Units without a writer are copied from the mirror, and each writer's units are then copied from that writer.
  • Texture.cpp:7254-7255: a writer's stamp counts only if ChangedBlocks still reports BlockUnchanged since that store or result. This is the later-writer rule from IvanFogel's reproduction.
  • Texture.cpp:7217 stampStored replaces the three MarkWritten loops in writeBackLayers (:8106, :8124, :8280).
  • Conventions.
    • No comments are added.
    • The new switch has an ENVIRONMENT.md row.
    • There is no debt fragment.
    • tools/check_conventions.py --base aa11bb9111 and tools/debt_fold.py --check pass on the merge.

Negative control.

  • I copied the PR's DepthPlanePartialStore.cpp and its cmake file onto main aa11bb9111 and ran the alias cases twice.
  • control_split, cpu_split and dma_split pass on main, with the same values as on the head: guest 15 GPU 15 expected 15 and guest 16399 GPU 16399 expected 16399.
  • cpu_prebind and dma_prebind skip on main, as they do on the head.

Mutations. Each was applied to the merge, rebuilt and run on the 5 alias cases.

  1. In DepthPlaneWriters, I dropped the BlockUnchanged condition (Texture.cpp:7254-7255), so the latest stamp wins even after a later guest write.
    • cpu_split and dma_split fail with guest 16399 GPU 15 expected 16399.
    • control_split passes.
    • So the tests do guard the later-writer rule.
  2. I removed the per-writer copyPlane loop (DepthSurface.cpp:1961-1964), so the writers' units are never copied in.
    • All three split cases still pass with the same values.
    • So on this machine, no test depends on the writer copy that the PR adds.

That fits what the fixture was written for: it caught the earlier revision copying a stale tile, which main never does. A case in which a draw reads a tile that only the storage image holds would also cover the new writer copy. Mutation 2 is a ready-made check for such a case. The non-split cases, which yinx080 reports skip on Windows, may be where this coverage was meant to come from.

GPU. Head 5d622cc26c, merged cleanly onto main aa11bb9111 as 73517e6002:

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_depth_plane_(alias_control_split|alias_cpu_split|alias_dma_split|alias_cpu_prebind|alias_dma_prebind|partial_store_image_copy)$" -V
run image_copy control_split cpu_split dma_split cpu_prebind dma_prebind
main Passed absent absent absent absent absent
main + PR tests (2 runs) not run Passed Passed Passed Skipped Skipped
head 1, 2, 3 Passed Passed Passed Passed Skipped Skipped
head, APS5_NO_DEPTH_FROM_ALIAS=1 (2 runs) not run Passed Passed Passed Skipped Skipped
mutation 1 (no BlockUnchanged) not run Passed Failed Failed Skipped Skipped
mutation 2 (no writer copy) not run Passed Passed Passed Skipped Skipped
main, sync validation Passed absent absent absent absent absent
head, sync validation Passed Passed Passed Passed Skipped Skipped
  • Every prebind run printed published row guest > half 15, registered cached writer 0 and exited 77. The split cases printed registered cached writer 1.
  • I did not run the no-draw-first cases. The PR says they skip on Windows.

Validation.

  • Insert instance layer "VK_LAYER_KHRONOS_validation" appears once on main, 6 times on each head run, and 5 times on each control, no-alias and mutation run: once in each test that ran.
  • No log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
  • VUID- lines: 0 on main, and 0 on every head, control, no-alias and mutation run.
  • With VK_KHRONOS_VALIDATION_VALIDATE_SYNC=true added, both main and the head have 0 SYNC-HAZARD- lines and 0 VUID- lines.

Host:

  • GPU: AMD Radeon AI PRO R9700 (gfx1201, 1002:7551), driver 32.0.31044.16, Vulkan 1.4.349
  • Validation layer: Khronos validation layer 1.4.363 (LunarG SDK)
  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: main aa11bb9111, head 5d622cc26c, merged as 73517e6002

AI-assisted: yes

@ashwin280802

Copy link
Copy Markdown
Contributor

@yinx080 I tested this PR on The Exit 8 and it fixes most of the corridor for me. I also found why some of it still goes black here. The data and a small patch on top of your head 5d622cc26c are below. How would you like to coordinate?

Setup. Windows 11 Pro (26300), i5-14600K, RTX 5070 (NVIDIA 621.24), 3840x2160 output with a 2848x1600 render target, main 102cad67dae merged with 5d622cc26c. PPSA23276, content version 01.004.000.

What I still saw with the PR. The opening corridor stays black for about the first 25 s, and while walking it switches back to black in some places. With unattended runs (no input) and a frame dump every 8 presents, the share of near-black pixels in the lower half was 69-88% for dumps 1-8 and about 1% afterwards. That matches the 54-100% you measured with the path off, but here it happens with the path on.

Why (measured with temporary local logging, not part of the patch).

  • In the black stretch, the material depth plane is checked about 50-130 times per second and always reports no change. Meanwhile the R32F view over it marks new results 3-4 times per second. Its write-back stores nothing, as you found, so no unit is stamped and SyncFromMemory never reaches DepthPlaneWriters.
  • At each bind I compared the newest results of the live R32F views at the plane's address with the results last copied into the plane. During the black dumps there were 54-108 stale binds per second and no current ones. From the first correct dump on, there were no stale binds.
  • A plane created during this stretch has no mirror yet. Only a refresh creates the mirror, and only a stamp starts a refresh, so the plane stays stale until something unrelated stamps that memory (about 38 s in here).
  • The tracker generation cannot tell "results newer than the last refresh" either. It only moves on a stamp or a collect, so layerResultsSince and the plane's unitGeneration stay equal in exactly this case.
  • A readback of the plane and its views at a flip matched what the counters say: when the plane was current, it held the newest view's material ids (for example 0.000488311 = 8/16383) on the floor rows.

The patch (75 lines added, 1 removed, applies cleanly to 5d622cc26c).

  • markLayersPending gives the marked units the next value of a global results serial (layerResultsSerial). Unlike the tracker generation, it moves with no stamp.
  • SyncFromMemory, plane with a mirror: units where a live same-surface image (your DepthPlaneWriters candidate test) has a newer serial than the plane last refreshed from count as changed.
  • SyncFromMemory, plane without a mirror: if a live single-mip R32F image at the plane's address with the plane's width and height has a newer serial than the last one copied, every unit counts as changed. The refresh creates the mirror and your writer selection then takes the units.
  • APS5_NO_DEPTH_ALIAS_RESULTS turns both parts off and has a row in docs/dev/ENVIRONMENT.md.

Same build, same unattended run, near-black share of the lower half:

dumps 1-8 later dumps
APS5_NO_DEPTH_ALIAS_RESULTS=1 (this PR alone) 69-88% 1%
patch on 0-2% 1%

The dumped frames show the full corridor (tiled walls, floor with the guide line, posters) from the first dump on. In a manual run that walked the loop past the corners where it used to flicker, I saw no black surfaces. Dumped frames per 100 s run were 30-43 across arms and runs, with no consistent difference between patch on and off.

Not covered.

  • No new test yet. A case for this would need a view whose write-back stores nothing, followed by a bind of a fresh plane.
  • Not run with the validation layer, on Linux or on AMD, and only on this title.
  • The no-mirror case matches by address, size, mip count and R32F format, because there is no mirror for SameSurfaceShape. In my runs it also refreshed a second 2848x1600 plane at another address; no visible change and no measurable slowdown, but it is broader than your test.
  • The real fix is probably still the empty write-back you mentioned. The patch only makes the plane notice results it would otherwise miss.

How should we coordinate?

  1. You fold this into this PR, if it fits your design. I can rerun these checks on any new head.
  2. I open a follow-up PR on top of yours, with a test, which waits for this PR to merge.
  3. You'd rather solve it differently, for example at the empty write-back. Then I'm happy to test that instead.
Patch against 5d622cc
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
index 145165fd570..151de8c923b 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/include/Texture.hpp
@@ -580,6 +580,9 @@ public:
     // of several: see ClassifyFill).
     static std::shared_ptr<StorageTexture> FindLive(std::uint64_t address, std::uint64_t bytes);
     static std::vector<std::pair<std::shared_ptr<StorageTexture>, std::vector<bool>>> DepthPlaneWriters(const StorageTexture& mirror, const std::vector<bool>& units);
+    static std::vector<bool> DepthPlaneAliasResults(const StorageTexture& mirror, std::vector<std::uint64_t>& seen);
+    static std::uint64_t NewestAliasResults(std::uint64_t address, std::uint32_t width, std::uint32_t height);
+    std::uint64_t ResultsSerial() const;
     // Whether the two surfaces differ in nothing but their address (and DCC metadata).
     bool SameSurfaceShape(const StorageTexture& other) const;
     bool ImageCoversGuestBytes() const;
@@ -954,6 +957,7 @@ private:
     std::vector<std::uint64_t> layerGeneration;
     std::vector<std::uint64_t> layerStoredStamp;
     std::vector<std::uint64_t> layerResultsSince;
+    std::vector<std::uint64_t> layerResultsSerial;
     void stampStored(std::uint64_t from, std::uint64_t to);
     std::vector<std::uint64_t> layerPendingSince;
     std::vector<std::uint64_t> completionKept;
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
index 77252571c98..2366961b4b6 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
@@ -1944,7 +1944,22 @@ public:
 
     void SyncFromMemory(const GuestTextureResource& resource, bool storing = false) {
         std::uint64_t generation = 0;
-        const auto changed = WrittenUnits(resource, generation);
+        auto changed = WrittenUnits(resource, generation);
+        static const bool aliasResults = std::getenv("APS5_NO_DEPTH_ALIAS_RESULTS") == nullptr && std::getenv("APS5_NO_DEPTH_FROM_ALIAS") == nullptr;
+        std::vector<std::uint64_t> seen;
+        if (aliasResults && !unitGeneration.empty() && (changed.empty() || changed.size() == unitGeneration.size())) {
+            if (mirrorPlane.storage != nullptr) {
+                if (aliasResultsSeen.size() != unitGeneration.size()) aliasResultsSeen.assign(unitGeneration.size(), 0);
+                seen = aliasResultsSeen;
+                const auto fresh = StorageTexture::DepthPlaneAliasResults(*mirrorPlane.storage, seen);
+                if (anyUnit(fresh)) {
+                    if (changed.empty()) changed.assign(unitGeneration.size(), false);
+                    for (std::size_t unit = 0; unit < fresh.size(); ++unit) changed[unit] = changed[unit] || fresh[unit];
+                }
+            } else if (StorageTexture::NewestAliasResults(resource.baseAddress, target.extent.width, target.extent.height) > aliasCopiedSerial) {
+                changed.assign(unitGeneration.size(), true);
+            }
+        }
         // The registry generation moves on every mapping mutation, so an unchanged value means every recorded backing is still current. Read it before the lookups: a mutation racing them leaves the stored value old and the next sync refreshes again.
         if (const auto registryGeneration = GuestAllocations::GuestAllocationsGeneration_nid_postfix(); registryGeneration != backingGeneration) {
             for (std::size_t unit = 0; unit < unitBacking.size(); ++unit) unitBacking[unit] = RegisteredBacking(target.address + unit * unitBytes);
@@ -1955,6 +1970,7 @@ public:
             unitGeneration.assign(unitGeneration.size(), generation);
             return;
         }
+        if (!seen.empty()) aliasResultsSeen = std::move(seen);
         StorageTexture::NoteRefreshWork();
         if (clearing) {
             ClearStale();
@@ -1993,6 +2009,7 @@ public:
                 for (const auto& [writer, units] : writers) {
                     const auto rects = writer->UnitRects(units);
                     copyPlane(mirrorPlane, writer, false, false, true, &rects);
+                    aliasCopiedSerial = std::max(aliasCopiedSerial, writer->ResultsSerial());
                 }
                 written = ++depthWrites;
                 return;
@@ -2063,6 +2080,8 @@ public:
     std::vector<std::uint64_t> unitBacking;
     std::uint64_t backingGeneration = 0;
     std::vector<std::uint64_t> unitGeneration;
+    std::vector<std::uint64_t> aliasResultsSeen;
+    std::uint64_t aliasCopiedSerial = 0;
     std::uint64_t unitBytes = 0;
     bool syncing = false;
     std::uint64_t scannedEpoch = 0;
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
index 71b1fbd4cb9..3ffbca477a1 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
@@ -4952,6 +4952,11 @@ void StorageTexture::markLayersPending(std::uint32_t first, std::uint32_t count)
     StampUnkeptUnits(keptAtUnwatch, {descriptor.baseAddress, trackedLayerBytes, guestBytes}, layerGeneration, layerPendingSince, first, count, pendingSince);
     if (layerResultsSince.size() != trackedLayers) layerResultsSince.assign(trackedLayers, 0);
     std::fill_n(layerResultsSince.begin() + first, count, pendingSince);
+    if (count != 0) {
+        static std::atomic<std::uint64_t> resultsSerial{0};
+        if (layerResultsSerial.size() != trackedLayers) layerResultsSerial.assign(trackedLayers, 0);
+        std::fill_n(layerResultsSerial.begin() + first, count, resultsSerial.fetch_add(1, std::memory_order_relaxed) + 1);
+    }
     // Results of this image now cover the alias's results borrowed into these units: this image
     // stores them, the alias no longer has to (its results, unchanged since the borrow, are in
     // this image's content). An alias written since keeps its own newer results pending.
@@ -7586,6 +7591,51 @@ std::vector<std::pair<std::shared_ptr<StorageTexture>, std::vector<bool>>> Stora
     return writers;
 }
 
+std::uint64_t StorageTexture::ResultsSerial() const {
+    return layerResultsSerial.empty() ? 0 : *std::max_element(layerResultsSerial.begin(), layerResultsSerial.end());
+}
+
+std::vector<bool> StorageTexture::DepthPlaneAliasResults(const StorageTexture& mirror, std::vector<std::uint64_t>& seen) {
+    std::vector<bool> fresh(seen.size(), false);
+    if (!mirror.blockUnits || seen.size() != mirror.trackedLayers) return fresh;
+    std::vector<std::shared_ptr<StorageTexture>> candidates;
+    {
+        auto& live = Live();
+        std::lock_guard lock(live.mutex);
+        for (auto* texture : live.textures) {
+            if (texture == &mirror || texture->released || !texture->blockUnits || texture->trackedLayers != mirror.trackedLayers || texture->descriptor.baseAddress != mirror.descriptor.baseAddress || !texture->SameSurfaceShape(mirror)) continue;
+            if (auto alive = texture->weak_from_this().lock()) candidates.push_back(std::move(alive));
+        }
+    }
+    const auto previous = seen;
+    for (const auto& candidate : candidates) {
+        const auto& serials = candidate->layerResultsSerial;
+        if (serials.size() != seen.size()) continue;
+        for (std::size_t unit = 0; unit < seen.size(); ++unit) {
+            if (serials[unit] <= previous[unit]) continue;
+            fresh[unit] = true;
+            seen[unit] = std::max(seen[unit], serials[unit]);
+        }
+    }
+    return fresh;
+}
+
+std::uint64_t StorageTexture::NewestAliasResults(std::uint64_t address, std::uint32_t width, std::uint32_t height) {
+    std::vector<std::shared_ptr<StorageTexture>> candidates;
+    {
+        auto& live = Live();
+        std::lock_guard lock(live.mutex);
+        for (auto* texture : live.textures) {
+            const auto& descriptor = texture->descriptor;
+            if (texture->released || descriptor.baseAddress != address || descriptor.width != width || descriptor.height != height || descriptor.mipCount != 1 || texture->imageFormat != VK_FORMAT_R32_SFLOAT) continue;
+            if (auto alive = texture->weak_from_this().lock()) candidates.push_back(std::move(alive));
+        }
+    }
+    std::uint64_t newest = 0;
+    for (const auto& candidate : candidates) newest = std::max(newest, candidate->ResultsSerial());
+    return newest;
+}
+
 bool StorageTexture::SameSurfaceShape(const StorageTexture& other) const {
     const auto& mine = descriptor;
     const auto& theirs = other.descriptor;
diff --git a/docs/dev/ENVIRONMENT.md b/docs/dev/ENVIRONMENT.md
index bfbde329635..d28a56145a8 100644
--- a/docs/dev/ENVIRONMENT.md
+++ b/docs/dev/ENVIRONMENT.md
@@ -315,6 +315,7 @@ The code reads environment names through `getenv`, `IsEnvironmentSet`, `kibSetti
 | `APS5_NO_DECODE_WATCH_COUNTS` | presence | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cpp` |  | makes a vertex stage decode's write watch copy every queued write range and compare them afterwards, instead of counting the retired items and looking up the ones that retired during the decode |
 | `APS5_NO_DEFERRED_EVICTION` | presence | `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` |  | destroys displaced resource-cache entries under the mutex instead of deferring them to the open batch |
 | `APS5_NO_DEFERRED_SETTLES` | presence | `core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp` |  | settles watched private host imports as they open instead of through the deferred block-settling path (Windows only) |
+| `APS5_NO_DEPTH_ALIAS_RESULTS` | presence | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |  | refreshes a depth plane only for units whose guest memory was stamped, not also for units where a live image over the plane marked results the plane has not refreshed from (a same-surface image when the plane has a mirror, a same-size single-mip R32F image when it has none) |
 | `APS5_NO_DEPTH_FROM_ALIAS` | presence | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |  | refreshes a depth plane's changed units from its own mirror of guest memory, not from another live image with exactly the mirror's surface that holds a unit's newest texels (its results there are pending with no store over the unit since, or its last write-back made the unit's newest stamp) |
 | `APS5_NO_DEPTH_PLANE_REUSE` | presence | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |  | rebuilds the shader resources of every draw that samples a copy of several depth planes instead of reusing a cached set and repeating the copy's lookup |
 | `APS5_NO_DEPTH_TRANSFER_PASS` | presence | `core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp` |  | copies a D32 depth plane into a 32-bit color storage image (one `vkCmdCopyImage` where `APS5_NO_DIRECT_DEPTH_COPY` allows it, else through the staging buffer) instead of reading it into the image in a compute pass (used when `VK_KHR_push_descriptor` is enabled); copies back into the depth plane never use the pass |

AI-assisted: yes (Claude Code)

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

The current head checks store ownership per depth-plane unit before taking it from the alias image. The CPU and DMA prebind cases verify that a later writer stays visible even when the image still contains an earlier row. Please keep the guest-byte and final depth-test assertions together in the paired run. The ordinary depth-plane tests and new alias cases are queued on lavapipe.

AI-assisted: yes.

This branch has not been deployed

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants