agc_hook_clear_access fails on Linux when host imports are compared: a pending image's results are dropped #21627

Closed
opened 2026-11-16 13:41:11 +00:00 by edubox · 0 comments
edubox commented 2026-11-16 13:41:11 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-16T13:41:11Z.


agc_hook_clear_access fails on Linux when host imports are compared: a pending image's results are dropped

What happens

ctest -R agc_hook_clear_access fails on the main Linux job with AGC graphics: (e) the flush hook did not store the pending image's results it read. agc_hook_clear_access_off fails the same way; both are agc_driver_recorder_tests --hook-clear-access-only.

Title, test or build step

ctest agc_hook_clear_access and agc_hook_clear_access_off (core/libs/prx/libSceAgcDriver/tests/Recorder.cpp, hookClearAccessTests), on Linux with llvmpipe and without a usable /dev/udmabuf, that is with [write-watch] host imports resolve write protection: yes ...; imported ranges are compared.

AnyPS5 commit

origin/main e4caa07950f (dcf3d15978c fails the same), Release build, ctest from build/. The Windows job passes this test. main's Linux job has no green run in the last 300 workflow runs to compare against, so I cannot say whether this is new.

System

Linux, AMD Ryzen 9 9900X; the failure reproduces with Mesa lavapipe (llvmpipe, Mesa 26.2.6), which is what the CI Linux runner selects. On this machine's NVIDIA RTX 4080 SUPER and RADV the test skips itself with skipped, the device reports watched host memory written when it imports or reads it, so llvmpipe is the only way to reach the failing path.

Steps to reproduce

lavapipe does not have to be installed to be used:

url=$(pacman -Sp vulkan-swrast | head -1)
mkdir -p /tmp/lvp && cd /tmp/lvp && curl -sSfLO "$url" && mkdir root && bsdtar -xf "$(basename "$url")" -C root
printf '{"ICD":{"api_version":"1.4.354","library_path":"/tmp/lvp/root/usr/lib/libvulkan_lvp.so"},"file_format_version":"1.0.1"}\n' > lvp.json
VK_ICD_FILENAMES=/tmp/lvp/lvp.json ./tests/agc_driver_recorder_tests --hook-clear-access-only

It exits 1 with the message above and exits 77 (skipped) without VK_ICD_FILENAMES.

What the trace says

With APS5_TRACE_FLUSH=1:

[flush] image 0x7fe010790000+0x200000 for storage refresh 0x7fe010790000+0x200000
[flush] image 0x7fe010790000+0x200000 for memory access 0x7fe010890000+0x4
[flush] image 0x7fe010790000+0x200000 keeps 1 CPU-written 64 KiB blocks (first stored byte at +0x200000, 0 ranges stored, generation 9)
AGC graphics: (e) the flush hook did not store the pending image's results it read

So the step (e) access does reach the write-back (StorageTexture::FlushPending → writeBackLayers) and the write-back itself decides the one 64 KiB block it needs is CPU-written since the image's generation 9, storing nothing. It is not the AccessKeptByCpu/C4 skip: forcing that off still fails here, through the same writeBackLayers decision.

Instrumenting WriteTracker::stamp for every non-driver stamp, the stamp that makes the block CPU-written is [stampdbg] block 0x7fe010890000 gen 11 kind 0 tag observe: kind Cpu, from an observe() walk (CollectWrites/CollectWritesUncached), generation 11 against the image's generation 9. The same block was already stamped gen 4 kind 0 tag observe earlier in the run, and the only CPU writes the test makes are the std::memset(block, 0x55, allocated) before the image exists. Everything else in the block comes from GPU clears and from the driver's own write-backs, which storeOwn stamps StampKind::Driver and records as driver pieces.

Since blocksKept/ChangedBlocks decide "the CPU wrote this block since the image's generation" from cpuStampOf(block) > generation, a collect that re-attributes bytes to the CPU after a later generation exists makes a pending image's results vanish. The same hold for StampKind::ImportWindow, which stamp() also counts in cpuBlocks.

What I could not settle

Where the fix belongs:

  • in the collect that re-stamps already-attributed bytes as Cpu (the Cpu walk storeOwn makes before its store, or the import windows, both of which can land after a newer image's generation), or
  • in the two decisions that trust cpuStampOf (StorageTexture::blocksKept for the hook skip and the cpu[] of GuestMemory::ChangedBlocks for the write-back), by requiring that the newest stamp of the block is a store that really came from the CPU.

I did not change either: cpuBlocks is what keeps the CPU's bytes over an image's during a write-back, so narrowing it can make stale GPU results overwrite CPU data in titles, and that trade-off needs the owner's call.

Instrumentation I used

git diff of the two debug prints (the stampdbg line in WriteTracker::stamp, and writetrap in WrittenSince), plus the walkTag thread-local that labels each walkWrites call site. They are not part of any branch.

@@ struct WriteTracker
+static thread_local const char* walkTag = "-";
@@ void WriteTracker::stamp(std::uint64_t block, std::uint64_t stampGeneration, StampKind kind) {
+        if (kind != StampKind::Driver && std::getenv("APS5_DBG_STAMP") != nullptr) std::fprintf(stderr, "[stampdbg] block 0x%llx gen %llu kind %d tag %s\n", static_cast<unsigned long long>(blockBegin(block)), static_cast<unsigned long long>(stampGeneration), static_cast<int>(kind), walkTag);
@@ bool WrittenSince(std::uint64_t address, std::size_t bytes, std::uint64_t generation) {
-        if (tracker.stampOf(block) > generation) return true;
+        if (tracker.stampOf(block) > generation) {
+            std::fprintf(stderr, "[writetrap] block 0x%llx stamp %llu cpu %llu gen %llu\n", static_cast<unsigned long long>(tracker.blockBegin(block)), static_cast<unsigned long long>(tracker.stampOf(block)), static_cast<unsigned long long>(tracker.cpuStampOf(block)), static_cast<unsigned long long>(generation));
+            return true;
+        }

The full patch with the walkTag assignments is in my worktree; I can attach it here if it helps.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6422513233 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/21627). Originally posted by [edubox](https://github.com/edubox) on 2026-11-16T13:41:11Z. --- # agc_hook_clear_access fails on Linux when host imports are compared: a pending image's results are dropped ## What happens `ctest -R agc_hook_clear_access` fails on the `main` Linux job with `AGC graphics: (e) the flush hook did not store the pending image's results it read`. `agc_hook_clear_access_off` fails the same way; both are `agc_driver_recorder_tests --hook-clear-access-only`. ## Title, test or build step ctest `agc_hook_clear_access` and `agc_hook_clear_access_off` (`core/libs/prx/libSceAgcDriver/tests/Recorder.cpp`, `hookClearAccessTests`), on Linux with llvmpipe and without a usable `/dev/udmabuf`, that is with `[write-watch] host imports resolve write protection: yes ...; imported ranges are compared`. ## AnyPS5 commit `origin/main` `e4caa07950f` (`dcf3d15978c` fails the same), Release build, `ctest` from `build/`. The Windows job passes this test. `main`'s Linux job has no green run in the last 300 workflow runs to compare against, so I cannot say whether this is new. ## System Linux, AMD Ryzen 9 9900X; the failure reproduces with Mesa lavapipe (`llvmpipe`, Mesa 26.2.6), which is what the CI Linux runner selects. On this machine's NVIDIA RTX 4080 SUPER and RADV the test skips itself with `skipped, the device reports watched host memory written when it imports or reads it`, so llvmpipe is the only way to reach the failing path. ## Steps to reproduce lavapipe does not have to be installed to be used: ```sh url=$(pacman -Sp vulkan-swrast | head -1) mkdir -p /tmp/lvp && cd /tmp/lvp && curl -sSfLO "$url" && mkdir root && bsdtar -xf "$(basename "$url")" -C root printf '{"ICD":{"api_version":"1.4.354","library_path":"/tmp/lvp/root/usr/lib/libvulkan_lvp.so"},"file_format_version":"1.0.1"}\n' > lvp.json VK_ICD_FILENAMES=/tmp/lvp/lvp.json ./tests/agc_driver_recorder_tests --hook-clear-access-only ``` It exits 1 with the message above and exits 77 (skipped) without `VK_ICD_FILENAMES`. ## What the trace says With `APS5_TRACE_FLUSH=1`: ``` [flush] image 0x7fe010790000+0x200000 for storage refresh 0x7fe010790000+0x200000 [flush] image 0x7fe010790000+0x200000 for memory access 0x7fe010890000+0x4 [flush] image 0x7fe010790000+0x200000 keeps 1 CPU-written 64 KiB blocks (first stored byte at +0x200000, 0 ranges stored, generation 9) AGC graphics: (e) the flush hook did not store the pending image's results it read ``` So the step (e) access does reach the write-back (`StorageTexture::FlushPending` → `writeBackLayers`) and the write-back itself decides the one 64 KiB block it needs is CPU-written since the image's generation 9, storing nothing. It is not the `AccessKeptByCpu`/C4 skip: forcing that off still fails here, through the same `writeBackLayers` decision. Instrumenting `WriteTracker::stamp` for every non-driver stamp, the stamp that makes the block CPU-written is `[stampdbg] block 0x7fe010890000 gen 11 kind 0 tag observe`: kind `Cpu`, from an `observe()` walk (`CollectWrites`/`CollectWritesUncached`), generation 11 against the image's generation 9. The same block was already stamped `gen 4 kind 0 tag observe` earlier in the run, and the only CPU writes the test makes are the `std::memset(block, 0x55, allocated)` before the image exists. Everything else in the block comes from GPU clears and from the driver's own write-backs, which `storeOwn` stamps `StampKind::Driver` and records as driver pieces. Since `blocksKept`/`ChangedBlocks` decide "the CPU wrote this block since the image's generation" from `cpuStampOf(block) > generation`, a collect that re-attributes bytes to the CPU after a later generation exists makes a pending image's results vanish. The same hold for `StampKind::ImportWindow`, which `stamp()` also counts in `cpuBlocks`. ## What I could not settle Where the fix belongs: - in the collect that re-stamps already-attributed bytes as `Cpu` (the `Cpu` walk `storeOwn` makes before its store, or the import windows, both of which can land after a newer image's generation), or - in the two decisions that trust `cpuStampOf` (`StorageTexture::blocksKept` for the hook skip and the `cpu[]` of `GuestMemory::ChangedBlocks` for the write-back), by requiring that the newest stamp of the block is a store that really came from the CPU. I did not change either: `cpuBlocks` is what keeps the CPU's bytes over an image's during a write-back, so narrowing it can make stale GPU results overwrite CPU data in titles, and that trade-off needs the owner's call. ## Instrumentation I used `git diff` of the two debug prints (the `stampdbg` line in `WriteTracker::stamp`, and `writetrap` in `WrittenSince`), plus the `walkTag` thread-local that labels each `walkWrites` call site. They are not part of any branch. ```diff @@ struct WriteTracker +static thread_local const char* walkTag = "-"; @@ void WriteTracker::stamp(std::uint64_t block, std::uint64_t stampGeneration, StampKind kind) { + if (kind != StampKind::Driver && std::getenv("APS5_DBG_STAMP") != nullptr) std::fprintf(stderr, "[stampdbg] block 0x%llx gen %llu kind %d tag %s\n", static_cast<unsigned long long>(blockBegin(block)), static_cast<unsigned long long>(stampGeneration), static_cast<int>(kind), walkTag); @@ bool WrittenSince(std::uint64_t address, std::size_t bytes, std::uint64_t generation) { - if (tracker.stampOf(block) > generation) return true; + if (tracker.stampOf(block) > generation) { + std::fprintf(stderr, "[writetrap] block 0x%llx stamp %llu cpu %llu gen %llu\n", static_cast<unsigned long long>(tracker.blockBegin(block)), static_cast<unsigned long long>(tracker.stampOf(block)), static_cast<unsigned long long>(tracker.cpuStampOf(block)), static_cast<unsigned long long>(generation)); + return true; + } ``` The full patch with the `walkTag` assignments is in my worktree; I can attach it here if it helps.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#21627
No description provided.