fix(agc): release a resident multisample depth before a GPU buffer may write over it #11369
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11369"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-26T09:04:41Z.
What
A GPU buffer a shader may write could land on the memory of a resident native multisampled depth surface without the surface being released first. Guest, DMA, texture, storage-image, index and vertex reads already go through
RequireNoResidentDepthRead_nid_no_patchbefore they touch that memory; a writable storage buffer did not. When the buffer was a host import, the GPU wrote straight into guest memory, the surface's guarded generation moved, and the next access to the surface (for example a read that asked for guest publication) stopped onguest writes over native multisample depth are not implemented.GuestBufferMemory::UploadFinishnow callsRequireNoResidentDepthRead_nid_no_patchfor each range inWrites(), next to the existingFlushDepthPlanescall and before the GPU runs. This is the order a console sees: the buffer's stores land on top of whatever the depth surface left in memory.mainthat is still thesample-preserving guest publicationrefusal, now raised at the buffer upload instead of at a later access; with #9950 it publishes the samples first.Buffers bound read-only are not covered; a new debt entry says so.
Tested
Windows 11 Home 26200, Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (AMD 32.0.31021.1015, Vulkan 1.4.349), WinLibs GCC 15.2.0 r7, Release. The regression test and the validation comparison below were run on this branch as pushed (a65bb53c25, on
mainb27cc8416f); the selected-test run was on the same commit onmainefd368fec6, before a rebase with no conflicts.agc_driver_native_multisample_depthgainsCheckBufferWrites: a fresh D16 and D32 surface at 2, 4 and 8 samples, on a device created withVK_EXT_external_memory_hostand buffer device addresses, so the written range is bound as a host import (the test requiresHostImportCovers; without the extension it prints a skip line). Two cases per format and sample count:main: fails witha buffer the GPU may write left an unwritten native depth surface resident over it. With this PR: passes.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest --test-dir build -R "^agc_driver_native_multisample_depth" -V: neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS;VUID-occurrences are 0 onmainand 0 with this PR. Themainrun stops at the new check, so it covers less of the test than the PR run.tools/select_tests.pyselected 1490 of 2398 tests for this diff,-j4,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: 8 failures, and the same 8 fail onmainon this machine:select_tests,nid_database_cache,agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store,agc_driver_sample_order_grid_reference,agc_driver_frame_capture_eop,agc_driver_frame_replay_shader,agc_driver_frame_replay_shader_host.main29ce6d87ebwith #10935, #10304, #9950 and #11199 applied locally. Same title, inputs and other libraries in every run, frame dumps checked:guest writes over native multisample depth are not implemented(these runs carried temporary diagnostics, removed since). In four of them a temporary write watch showed the last writes to the 4x D32 128x64 surface at 0x20008d0000 wereMarkPossiblyWrittenstamps over 0x20008d0000+0x30000 fromGuestBufferMemory::MarkDirectWritesandGuestBufferMemory::WriteBack, after the surface's draws; the access that then stopped was the guest publication request of a later read.VK_ERROR_OUT_OF_DEVICE_MEMORY. Both are separate from this change and not investigated here. Gameplay was not reached.946de281e1(onmain18ef6be0cd), same machine and validation-layer environment,ctest --test-dir build -R "^agc_driver_native_multisample_depth$" -V: this branch passes; the same tree withGuestBufferMemory.cppfrommainfails witha buffer the GPU may write left an unwritten native depth surface resident over it; this branch merged with #10497 (8a0dcd5af9, which carries #10469 and #10492) passes. 0VUID-occurrences and no missing-layer line in any of the three logs.609f4f1205, after dropping the written-surface refusal case, same machine and validation-layer environment: this branch passes, and the same tree withGuestBufferMemory.cppfrom the basemain18ef6be0cdfails witha buffer the GPU may write left an unwritten native depth surface resident over it. The buffer-write cases ran for formats 124 and 126 at 2, 4 and 8 samples (checked=24 unavailable=0); 0VUID-lines.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch fix/agc-msaa-depth-buffer-write: #10920 edits the same two lines of the test's ownDevicesetup (it adds the portability subset). Not listed by the tool, since the only shared file is the debt file:ShaderResources::requireGuestBuffers(), which callsRequireNoMultisampleTargetfor every guest buffer, read-only or writable, right beforeUploadFinish; in production that also covers this PR's line, but this PR's test drivesGuestBufferMemory::Uploaddirectly, so theUploadFinishguard and its test stay in either landing order. Once #6498 is in, the read-only sentence of this PR's debt entry is dropped.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:09:41Z.
Review: CHANGES_REQUESTED
Reviewed exact head
a65bb53c25c5bad83b638deed03fa0caeca2f7b6.The production change appears to retire or publish a resident native depth surface before the GPU can write into an overlapping guest buffer, and the test covers unrelated, depth-plane, HTILE, and already-written cases. I found one portability issue in the new
Device(importHost=true)fixture that can prevent the added cases from running on otherwise usable Vulkan devices.At
NativeMultisampleDepth.cpp, the fixture enablesVkPhysicalDeviceBufferDeviceAddressFeatures::bufferDeviceAddress = VK_TRUEwhenever both extension names are enumerated. Extension presence does not establish support for this optional feature. The Vulkan feature structure must be queried withvkGetPhysicalDeviceFeatures2, and only a supported feature may be enabled at device creation. If a device exposes both extension names but reportsbufferDeviceAddress == VK_FALSE, this fixture failsvkCreateDevicerather than skipping only the host-import cases. Please query the feature and gate the import-host device/test path on its support (while retaining the existing extension checks), then rerun the focused test on the author GPU and a Vulkan configuration without BDA if available.I did not run the AGC test locally: this environment has no
/dev/driGPU device. Current hosted eligibility, conventions, intake, labels, and report checks pass; product and GPU build jobs are skipped by the repository path policy. The reported Windows/RX 9070 XT test remains author-provided evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:29:01Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
7ab89a42bdceca2d1f33f63282e9708d3d9a0800against currentmain4e43321bd6ceccdc1ae28568bbbc35d9a6446464. The newvkGetPhysicalDeviceFeatures2query now gatesbufferDeviceAddress; unsupported devices create without the optional extensions and the test skips host-import cases. The author reports the focused test passed on the RX 9070 XT and the forced-off path skipped all six combinations. I found no remaining issue with that feature query.Two merge-readiness items remain:
tools/check_main_sync.pyreports this branch is 2 commits ahead and 84 behind current main (merge baseb27cc8416f820e40ce187f165d34138e24373dd7). The merge preview with main is clean and main has not changed the PR's touched paths since that base, but the repository requires branches to stay current. Please rebase/sync to current main and rerun the focused Vulkan test and conventions on the resulting exact head.Devicesetup inNativeMultisampleDepth.cppto enableVK_KHR_portability_subset. A three-way merge preview of the current heads reports a content conflict in that file, in the same setup region this PR now changes for BDA. Please coordinate integration order and preserve both the portability-subset setup and this feature-gated host-import setup; addDepends on: #10920if that PR must land first.On this host,
check_conventions.pyandgit diff --checkpass for the current PR head, and the main merge preview is clean. I could not run the Vulkan test locally because/dev/driis absent. Hosted eligibility, conventions, labels and report pass; product/GPU build jobs are skipped by path policy.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T10:03:28Z.
Review: DISMISSED
The BDA feature gate fix and the reported RX 9070 XT/forced-off test results remain useful; this exact head is still
7ab89a42bdceca2d1f33f63282e9708d3d9a0800. Currentmainis now5b5d24cb22, leaving the branch 87 commits behind. The merge preview is clean, butdocs/dev/debt/libSceAgcDriver.mdchanged on main since the branch base, so the rebase must retain those descriptor notes along with this PR’s debt. Please rebase and rerun the focused Vulkan test and conventions on the resulting head. The open #10920 integration conflict inNativeMultisampleDepth.cppremains: coordinate the portability-subset setup and BDA feature setup, and recordDepends onif order is required. Current conventions and diff checks pass on the existing head; product/GPU jobs are skipped by path policy.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T07:53:38Z.
Review: COMMENTED
Linux NVIDIA and lavapipe run. The runs so far are Windows only (RX 9070 XT, RTX 5070 Ti).
Setup: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), each selected with
VK_DRIVER_FILES. Head946de281emerged with--no-commitontomainb7105f728(clean; it also merges cleanly onto8df2c3ed0). Focused runs useANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos layer 1.4.341).VK_LOADER_DEBUG=layershows the layer inserted, and no log has the missing-layer message.main+ only this PR'sNativeMultisampleDepth.cpp):agc_driver_native_multisample_depthfails on both devices witha buffer the GPU may write left an unwritten native depth surface resident over it, soCheckBufferWritesreaches the host-import path on both.agc_driver_native_multisample_depthpasses 3/3 on both devices.Native multisampled depth cases checked=24 unavailable=0, with the "GPU buffer write over the depth or HTILE released the unwritten surface and refused the written one" line for every sample count.checked=16 unavailable=8.^agc_driver_native_multisample_depth,^agc_driver_multisample,guest_buffer, 16 tests): 16/16 3/3 on the 3070. On lavapipe it is 15/16 3/3; the failure isagc_driver_multisample_retirement, which fails the same way onmainon this host. 0VUID-on either device.^agcsuite (without display/flip/lds_atomics64,-j1 --timeout 30): 3070 1042/1042; lavapipe 1041/1042, with the samemultisample_retirementfailure asmain.sizeofasserts inShaderDiskCache.cppandPipelineJournal.cpphold.public_headerspasses withmain8df2c3ed0.GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.