Repository navigation
Conversation
… that image, not from stale guest bytes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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. |
|
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
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 No new AI-assisted: yes (Claude Code) |
|
@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:
With that, The Exit 8's corridor goes back to 54-100 % black. A local diagnostic in
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:
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 AI-assisted: yes (Claude Code) |
|
Head No new failures and no new validation messages on either GPU.
Layer runs used AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
|
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.
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.
|
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
… 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>
|
@IvanFogel thanks for the fixture and the clear reproduction. I reworked it as you suggested: the source is now chosen per tile. Main What changed
Why both references: in The Exit 8 the writer's own write-back is empty every frame. Its Your fixture is in as
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 Windows 11, RTX 3060 Laptop, driver 610.91, 10 runs per case:
Before the rework, the same build with your fixture failed Other checks
Not run: Linux, and the validation layer. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
The I can't re-run jobs here. Could a maintainer re-run the failed job? AI-assisted: yes (Claude Code) |
|
Builds and passes on AMD RDNA4 with the Khronos validation layer: 0 What this run adds.
Code.
Negative control.
Mutations. Each was applied to the merge, rebuilt and run on the 5 alias cases.
That fits what the fixture was written for: it caught the earlier revision copying a stale tile, which GPU. Head
Validation.
Host:
AI-assisted: yes |
|
@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 Setup. Windows 11 Pro (26300), i5-14600K, RTX 5070 (NVIDIA 621.24), 3840x2160 output with a 2848x1600 render target, 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).
The patch (75 lines added, 1 removed, applies cleanly to
Same build, same unattended run, near-black share of the lower half:
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.
How should we coordinate?
Patch against 5d622ccdiff --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
left a comment
There was a problem hiding this comment.
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.


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:
materialId / 16383.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:
layerGenerationis 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.StorageTexturewith the same surface.This change takes each changed unit from the image that wrote it last, and only while it is the last writer:
StorageTexture::stampStoredreplaces the threeMarkWrittenloops ofwriteBack), andmarkLayersPendingrecords the tracker generation of each unit's latest results (layerResultsSince).StorageTexture::DepthPlaneWriterslooks 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::SyncFromMemorycopies 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_ALIASrestores the old path; its row indocs/dev/ENVIRONMENT.mddescribes the rule.agc_driver_depth_plane_alias_*(IvanFogel's fixture from the review): a shader write through an R32F view, then a CPU store or a PM4DMA_DATAcopy 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
SyncFromMemoryandTexture.hpptoo, 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,
main07336cc200+ 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:
APS5_NO_DEPTH_FROM_ALIAS=1The 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:
_split(control, CPU, DMA)control_prebindcpu_prebinddma_prebindOn 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
_prebindruns, with or without this PR; those runs skip. Before the rework,cpu_split,dma_split,cpu_prebindanddma_prebindfailed on the draw assertion and passed withAPS5_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 withAPS5_NO_DEPTH_FROM_ALIAS=1.Stray (PPSA02100), regression check, on the previous head
dbb10a3638: 5.68 fps withAPS5_NO_DEPTH_FROM_ALIAS=1, 5.69 fps with it on. Not rerun on this head.tools/check_conventions.py --base origin/mainandtools/check_test_registration.py buildpass.Not run: Linux, the validation layer.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code