agc_driver_dcc_keys_first_write fails where host imports stay write-watched (NVIDIA, Linux): cause and patch #2767

Closed
opened 2026-10-10 13:32:55 +00:00 by fma-rc · 3 comments
fma-rc commented 2026-10-10 13:32:55 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T13:32:55Z.


agc_driver_dcc_keys_first_write fails on main on Linux with the NVIDIA proprietary driver and passes on RADV on the same machine. It was reported in #2188, which was closed as device-specific; it still fails on current main, and the cause is in the texture refresh path, not in the driver.

Setup: main 78aedb40, Arch Linux 7.2.9, GCC 16.2.1, Release. NVIDIA RTX 5080 (615.78.08); AMD Radeon 610M (RADV, Mesa 26.1.4).

Reproduce: ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R '^agc_driver_dcc_keys_first_write$'

AGC graphics: an unchanged pending image was uploaded again

Measured (full ctest -j12, 698 tests):

NVIDIA RTX 5080 RADV, Radeon 610M
main 697 pass; this test fails in 5 of 5 runs 698 pass
main + patch below 698 pass in 4 of 5 runs, see note 698 pass

Cause. The two devices differ in one line of the test's own log:

NVIDIA: [write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched
RADV:   [write-watch] host imports resolve write protection: yes (4 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges are compared

When imported ranges stay watched, GuestMemory::ChangedBlocks reports the image's blocks as BlockMaybeWritten after the import, although no byte changed. In StorageTexture::Refresh, scanBlocks takes that as a change, so the unchanged pending image is written back and uploaded again, which is what the test forbids. On RADV the range is compared instead and the blocks come back unchanged.

Patch that makes the test pass here. In scanBlocks (Graphics/src/Texture.cpp), a block reported as maybe-written is compared before it counts as changed:

             if (compared) cpuBlocks = stampedBlocks;
+            for (std::uint32_t unit = 0; tracked && blockUnits && unit < trackedLayers; ++unit) {
+                if (stampedBlocks[unit] != GuestMemory::BlockMaybeWritten) continue;
+                std::array<std::uint8_t, 1> block{};
+                if (!compareUntracked(layerBegin(unit), static_cast<std::size_t>(layerBytes(unit)), block) || block[0] != GuestMemory::BlockUnchanged) continue;
+                stampedBlocks[unit] = GuestMemory::BlockUnchanged;
+                cpuBlocks[unit] = 0;
+            }
         };

tools/check_conventions.py --base origin/main passes with it. I can't open a pull request (intake), so it is here for whoever wants it.

Note on the fifth run. In one of five parallel runs with the patch, agc_driver_exec_host_lanes and agc_driver_pixel_interlock ended with SIGSEGV. The core dump of agc_driver_exec_host_lanes shows the crash inside libnvidia-glvkspirv.so on the thread running LinkPipelineFromLibraries, while the main thread waited in ClearPipelineLibraries. It did not recur in 4 further parallel runs or in 10 serial runs of those two tests, and I have not seen it in 5 parallel runs without the patch. I could not reproduce it on demand, so I can't say whether it is related.

Not established: the cost of the extra compare on a title (no title run was measured), and whether other callers of ChangedBlocks treat maybe-written blocks the same way.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5791691353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2767). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T13:32:55Z. --- `agc_driver_dcc_keys_first_write` fails on `main` on Linux with the NVIDIA proprietary driver and passes on RADV on the same machine. It was reported in #2188, which was closed as device-specific; it still fails on current `main`, and the cause is in the texture refresh path, not in the driver. **Setup:** `main` 78aedb40, Arch Linux 7.2.9, GCC 16.2.1, Release. NVIDIA RTX 5080 (615.78.08); AMD Radeon 610M (RADV, Mesa 26.1.4). **Reproduce:** `ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R '^agc_driver_dcc_keys_first_write$'` ``` AGC graphics: an unchanged pending image was uploaded again ``` **Measured** (full `ctest -j12`, 698 tests): | | NVIDIA RTX 5080 | RADV, Radeon 610M | |---|---|---| | `main` | 697 pass; this test fails in 5 of 5 runs | 698 pass | | `main` + patch below | 698 pass in 4 of 5 runs, see note | 698 pass | **Cause.** The two devices differ in one line of the test's own log: ``` NVIDIA: [write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched RADV: [write-watch] host imports resolve write protection: yes (4 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges are compared ``` When imported ranges stay watched, `GuestMemory::ChangedBlocks` reports the image's blocks as `BlockMaybeWritten` after the import, although no byte changed. In `StorageTexture::Refresh`, `scanBlocks` takes that as a change, so the unchanged pending image is written back and uploaded again, which is what the test forbids. On RADV the range is compared instead and the blocks come back unchanged. **Patch that makes the test pass here.** In `scanBlocks` (`Graphics/src/Texture.cpp`), a block reported as maybe-written is compared before it counts as changed: ```diff if (compared) cpuBlocks = stampedBlocks; + for (std::uint32_t unit = 0; tracked && blockUnits && unit < trackedLayers; ++unit) { + if (stampedBlocks[unit] != GuestMemory::BlockMaybeWritten) continue; + std::array<std::uint8_t, 1> block{}; + if (!compareUntracked(layerBegin(unit), static_cast<std::size_t>(layerBytes(unit)), block) || block[0] != GuestMemory::BlockUnchanged) continue; + stampedBlocks[unit] = GuestMemory::BlockUnchanged; + cpuBlocks[unit] = 0; + } }; ``` `tools/check_conventions.py --base origin/main` passes with it. I can't open a pull request (intake), so it is here for whoever wants it. **Note on the fifth run.** In one of five parallel runs with the patch, `agc_driver_exec_host_lanes` and `agc_driver_pixel_interlock` ended with SIGSEGV. The core dump of `agc_driver_exec_host_lanes` shows the crash inside `libnvidia-glvkspirv.so` on the thread running `LinkPipelineFromLibraries`, while the main thread waited in `ClearPipelineLibraries`. It did not recur in 4 further parallel runs or in 10 serial runs of those two tests, and I have not seen it in 5 parallel runs without the patch. I could not reproduce it on demand, so I can't say whether it is related. **Not established:** the cost of the extra compare on a title (no title run was measured), and whether other callers of `ChangedBlocks` treat maybe-written blocks the same way.
simonbbby commented 2026-10-10 14:16:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-10T14:16:14Z.


I tested the patch on a second NVIDIA setup: RTX 3090 with driver 595.99.02, Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, main db343a93. The probe prints the same line here:

[write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched
agc_driver_dcc_keys_first_write alone Full ctest --parallel 12 (698 tests)
main fails 5 of 5 (an unchanged pending image was uploaded again) 3 runs; this test fails in all 3
main + patch passes 5 of 5 5 runs, 698/698 each

With the patch, RADV (Ryzen 9 9950X iGPU, Mesa 25.2.8) and llvmpipe also pass 698/698.

About the SIGSEGV in your fifth run: I got agc_driver_exec_host_lanes to segfault once without the patch, in the first of the three unpatched full runs, so it doesn't come from this change. It didn't recur in 6 more parallel runs of the agc_driver tests alone. Its core was rotated out before I could read it, so I can't confirm the stack matches yours (libnvidia-glvkspirv.so under LinkPipelineFromLibraries).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6098405175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2767#issuecomment-6098405175). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-10T14:16:14Z. --- I tested the patch on a second NVIDIA setup: RTX 3090 with driver 595.99.02, Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, `main` db343a93. The probe prints the same line here: ``` [write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched ``` | | `agc_driver_dcc_keys_first_write` alone | Full `ctest --parallel 12` (698 tests) | |---|---|---| | `main` | fails 5 of 5 (`an unchanged pending image was uploaded again`) | 3 runs; this test fails in all 3 | | `main` + patch | passes 5 of 5 | 5 runs, 698/698 each | With the patch, RADV (Ryzen 9 9950X iGPU, Mesa 25.2.8) and llvmpipe also pass 698/698. About the SIGSEGV in your fifth run: I got `agc_driver_exec_host_lanes` to segfault once *without* the patch, in the first of the three unpatched full runs, so it doesn't come from this change. It didn't recur in 6 more parallel runs of the `agc_driver` tests alone. Its core was rotated out before I could read it, so I can't confirm the stack matches yours (`libnvidia-glvkspirv.so` under `LinkPipelineFromLibraries`).
fma-rc commented 2026-10-10 17:26:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T17:26:45Z.


Status on current main 57f96fd2: the failure is still there on the NVIDIA device, and the patch above still applies cleanly and fixes it.

Arch Linux, GCC 16.2.1, Release, ANYPS5_REQUIRE_VULKAN=1, ctest -j12. RTX 5080 (615.78.08) and Radeon 610M (RADV, Mesa 26.1.4).

RTX 5080 RADV, Radeon 610M
main, agc_driver_dcc_keys_first_write fails passes
main + patch, full suite 698 of 698 pass 698 of 698 pass

ctest lists 4 video_out_flip_* tests as skipped in the RTX 5080 run, and those plus 3 guest_video_out_* tests in the RADV run; they are counted in the 698.

python3 tools/check_conventions.py --base origin/main passes with the patch applied.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100237377 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2767#issuecomment-6100237377). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-10T17:26:45Z. --- Status on current `main` 57f96fd2: the failure is still there on the NVIDIA device, and the patch above still applies cleanly and fixes it. Arch Linux, GCC 16.2.1, Release, `ANYPS5_REQUIRE_VULKAN=1`, `ctest -j12`. RTX 5080 (615.78.08) and Radeon 610M (RADV, Mesa 26.1.4). | | RTX 5080 | RADV, Radeon 610M | |---|---|---| | `main`, `agc_driver_dcc_keys_first_write` | fails | passes | | `main` + patch, full suite | 698 of 698 pass | 698 of 698 pass | ctest lists 4 `video_out_flip_*` tests as skipped in the RTX 5080 run, and those plus 3 `guest_video_out_*` tests in the RADV run; they are counted in the 698. `python3 tools/check_conventions.py --base origin/main` passes with the patch applied. AI-assisted: yes
milescoviello commented 2026-10-10 17:50:51 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-10T17:50:51Z.


Confirming on a third NVIDIA setup, a Blackwell laptop: RTX 5090 Laptop GPU (0x2c58), driver 610.57.04, Gentoo, Linux 7.2.8, GCC 15.3.0, Release with CI's configure flags (-DANYPS5_ENABLE_SPIRV_TOOLS=ON), main 57f96fd2. The probe prints the same line:

[write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched
agc_driver_dcc_keys_first_write alone Full ctest --parallel 4 (701 tests)
main fails 10 of 10 (an unchanged pending image was uploaded again) 700/701, only this test fails
main + patch passes 5 of 5 701/701

On main, APS5_WRITE_WATCH_IMPORTS=unwatch passes 3 of 3 and watch fails 3 of 3.

It is not specific to NVIDIA. On the same laptop's Intel iGPU (Arrow Lake 0x7d67, Mesa 26.1.8 ANV) the probe reports yes (4 of 4 scratch pages written after a GPU read, 4 after the import), so imports are compared there and the test passes on main. Forced to APS5_WRITE_WATCH_IMPORTS=watch, the same assertion fails on main (the import resolves the write protection on ANV too) and passes with the patch, 3 of 3. Full ctest with the patch on the iGPU: 692/700, the same 8 failures as on main, none in this path (agc_driver_lds_beyond_device_limit excluded, #2805).

On the SIGSEGV question: agc_driver_exec_host_lanes and agc_driver_pixel_interlock passed in both of my full NVIDIA runs (one on main, one with the patch).

I also have a regression test that reproduces the import window without depending on the driver (a store of the byte already there inside ImportWatched, over a pending image), if that would help this land.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6100451369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2767#issuecomment-6100451369). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-10T17:50:51Z. --- Confirming on a third NVIDIA setup, a Blackwell laptop: RTX 5090 Laptop GPU (0x2c58), driver 610.57.04, Gentoo, Linux 7.2.8, GCC 15.3.0, Release with CI's configure flags (`-DANYPS5_ENABLE_SPIRV_TOOLS=ON`), `main` 57f96fd2. The probe prints the same line: ``` [write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 4 after the import); imported ranges stay watched ``` | | `agc_driver_dcc_keys_first_write` alone | Full `ctest --parallel 4` (701 tests) | |---|---|---| | `main` | fails 10 of 10 (`an unchanged pending image was uploaded again`) | 700/701, only this test fails | | `main` + patch | passes 5 of 5 | 701/701 | On `main`, `APS5_WRITE_WATCH_IMPORTS=unwatch` passes 3 of 3 and `watch` fails 3 of 3. It is not specific to NVIDIA. On the same laptop's Intel iGPU (Arrow Lake 0x7d67, Mesa 26.1.8 ANV) the probe reports `yes (4 of 4 scratch pages written after a GPU read, 4 after the import)`, so imports are compared there and the test passes on `main`. Forced to `APS5_WRITE_WATCH_IMPORTS=watch`, the same assertion fails on `main` (the import resolves the write protection on ANV too) and passes with the patch, 3 of 3. Full `ctest` with the patch on the iGPU: 692/700, the same 8 failures as on `main`, none in this path (`agc_driver_lds_beyond_device_limit` excluded, #2805). On the SIGSEGV question: `agc_driver_exec_host_lanes` and `agc_driver_pixel_interlock` passed in both of my full NVIDIA runs (one on `main`, one with the patch). I also have a regression test that reproduces the import window without depending on the driver (a store of the byte already there inside `ImportWatched`, over a pending image), if that would help this land. AI-assisted: yes
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#2767
No description provided.