Skip to content

perf(agc): expand an HTILE on the GPU behind a pending mask clear kernel - #8105

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:perf/agc-htile-mask-clear-on-gpu
Oct 31, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
Celegans12:perf/agc-htile-mask-clear-on-gpu

Conversation

@Celegans12

@Celegans12 Celegans12 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Binding a depth target behind an HTILE mask clear waited for GPU readback. Record its mask/value with the newest pending write and unique recorder ID; expand on the GPU when that write determines ZMask/SMem across the HTILE. Other patterns read back. Accept the structured-buffer variant seen in Ghost of Yōtei (PPSA26344).

The recorder-lifetime collision reported by @MarcZX10 and @adriadam10 is fixed by checking owner identity, removing its proofs at recorder teardown, and removing device proofs at depth cleanup. The global 64-record bound and conservative overlap invalidation remain.

The recognized clear carries its HTILE range through preparation, upload and binding. Only its pending native owner admits that range; ordinary writes, depth-plane accesses and color guards retain their checks. The exception ends at arm and cannot enter resource/recipe caches. @jotitadev's reproduction and supplied patch guided this guard fix.

Related: #7002 changes buffer/color checks. #7642/#9508/#6412/#10193 change reuse gates. #9533/#9717/#9742 extend clear fixtures. #9950/#10492/#10469/#10497 publish native depth through the fallback guard. #13021/#13023 add publication arguments and #6804 adds a PrepareDispatch parameter; compose those with this range. #6300/#6808 extend clear-generation proofs. #11602/#6192/#12921 change HTILE proof stamps; #10940 device-scopes texture write-back. None supplies this dispatch allowance or recorder-mask ownership; retain their independent refusal conditions.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 0835ec8, -DBUILD_TESTING=ON: four focused targets build. NVIDIA: 9/9 tests, each repeated three times; lavapipe: 9/9 once. ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V: layer loaded, no VUID errors. Registration and conventions pass.
  • agc_driver_htile_mask_lifetime fails 3/3 on the previous PR rebased onto this main: reused recorder storage, HTILE address and note 1 turn ordinary 0x0000000f words into 0xfffc000f without readback. All eight GPU assertions now run and pass: recreated/live owner isolation, same-owner fast path, recorder cleanup and both owners of a cleared device while preserving another device's proof. Checks compare both ThreadHookWaits and metadata bytes.
  • The previous round's agc_driver_native_depth_buffer_clear regression failed 3/3 before its guard fix; that test and seven neighbors remain in the current passing set. Historical paired main e2df06e controls passed 7/7 on both drivers; those controls were not rebuilt this round. Recorder/DepthSurface production files are unchanged between that main and 0835ec8.
  • Both Windows drivers still lack the imported-HTILE write-coverage assertion: PM4 cases verify controlled refusal, not successful watched-clear sampling. The new lifetime test executes on both; unsupported host-import devices explicitly skip it. Not tested: Linux, AMD, Intel or titles this revision.
Historical performance evidence, 24 October; no new performance claim for the guard or lifetime fixes

main vs the original change on the same machine (RTX 3080 Laptop, driver 610.62, Windows 11), Ghost of Yōtei (PPSA26344 v1.008) title menu from the same save with no input, warm caches, interleaved runs in one session, perf-report protocol (only APS5_TRACE_FRAMES=150:60, no APS5_PROFILE_*): main a5a2c94 against main a5a2c94 + this PR. Frame p50 131.9 ms (3 runs) against 133.6 ms (2 runs), GPU busy 77.7 against 80.5 ms per present. That's inside the run-to-run spread (main's three runs: 128.2-135.1 ms), as expected for a scene that doesn't exercise this path; our open-world numbers, from our own tree, are in the comments. Traces and tools/trace_digest.py output per run: pl-main-1, pl-main-2, pl-main-3, pl-8105-1, pl-8105-2.

aps5-summary.jsonl, pl-main-3 and pl-8105-1 (the run closest to each side's mean; `title` written as `ō`, since the summary writer double-encodes it and GitHub mangles that escape)
{"commit":"a5a2c946a3a9","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":11388.409},"presents":60,"frame_ms":{"p50":132.237,"p90":378.788,"p99":2488.458,"max":2488.458},"gpu_busy_ms_per_present":76.739,"worker_busy_pct":{"queue worker 0x0":61.336,"queue worker 0x20":12.709,"queue worker 0x52":10.897,"queue worker 0x53":12.001,"queue worker 0x30":43.438,"queue worker 0x38":50.980,"queue worker 0x48":3.931},"top_phases_ms_per_frame":{"Driver.Packet":363.867,"Shader.PrepareArtifact":329.176,"Driver.Packet.dispatch":163.759,"Driver.Packet.memory_wait":130.658,"Driver.Dispatch":116.659,"Driver.Packet.prepare_memory":46.855,"GpuMutex.wait.dispatch":32.057,"Shader.Register":29.105},"trace_dropped":false,"trace":"aps5-trace-a5a2c946a3a9-16452.json.gz"}
{"commit":"b2bea6d90d06","dirty":false,"env":{"APS5_NO_CLEAR_HAND_OVER":"1","APS5_NO_DEFERRED_SETTLES":"1","APS5_NO_PAD_INPUT":"1","APS5_NO_PIPELINE_JOURNAL":"1","APS5_NO_RESIDENT_LINEAR":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_RESOURCE_CACHE_ENTRIES":"1024","APS5_TRACE_FRAMES":"150:60"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","cpu":"11th Gen Intel(R) Core(TM) i9-11900H @ 2.50GHz","cpu_threads":16,"memory_mib":32469,"title_id":"PPSA26344","title":"Ghost of Yōtei","content_version":"01.008.000","resolution":"3840x2160","window":{"spec":"frames 150:60","first_present":150,"ms":12317.426},"presents":60,"frame_ms":{"p50":128.450,"p90":361.446,"p99":3476.353,"max":3476.353},"gpu_busy_ms_per_present":75.766,"worker_busy_pct":{"queue worker 0x0":56.658,"queue worker 0x52":9.090,"queue worker 0x20":10.824,"queue worker 0x53":10.181,"queue worker 0x30":39.973,"queue worker 0x38":46.768,"queue worker 0x48":4.182},"top_phases_ms_per_frame":{"Shader.PrepareArtifact":452.689,"Driver.Packet":359.164,"Driver.Packet.dispatch":157.312,"Driver.Packet.memory_wait":130.349,"Driver.Dispatch":113.443,"Driver.Packet.prepare_memory":45.684,"Shader.Register":33.281,"GpuMutex.wait.flush":29.871},"trace_dropped":false,"trace":"aps5-trace-b2bea6d90d06-17424.json.gz"}

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
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3080 Laptop GPU, driver 610.62; lavapipe (Mesa 26.2.4, LLVM 22.1.8); both Windows 11
  • AI-assisted: yes

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions

github-actions Bot commented Oct 19, 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 7002 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2450-2451
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2655
PR 8874 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp L6
PR 8963 core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp L6
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2655
PR 9533 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3140, L3143
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L851, L1022-1025, L1027-1038, L1046-1059, L1572
PR 9717 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3140, L3143
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L851, L1022-1025, L1027-1038, L1046-1059, L1572
PR 9742 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3140, L3143
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L851, L1022-1025, L1027-1038, L1046-1059, L1572
PR 9950 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2101
PR 10469 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2098-2099, L2101
PR 10492 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3139-3140, L3142-3143
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2101
PR 10497 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3139-3140, L3142-3143
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2098-2099, L2101
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L2450-2451
PR 10893 core/libs/prx/libSceAgcDriver/tests/execution/DepthFastClearSubmit.cpp L1-2, L24, L288-289
PR 13021 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3140, L3143
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp L41-42
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2098, L2101
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L851, L1022-1025, L1027-1038, L1046-1059, L1572
PR 13023 core/libs/prx/libSceAgcDriver/CMakeLists.txt L3140, L3143
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp L41-42
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2098, L2101
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp L851, L1022-1025, L1027-1038, L1046-1059, L1572

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 1368 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 1395 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 1896 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 2434 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4472 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5021 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 5371 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 5609 core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 5925 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6182 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6185 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6186 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 6187 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6188 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6192 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6194 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6197 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6209 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6223 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6300 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp
PR 6412 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 6481 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6548 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6804 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6808 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp
PR 6905 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 6918 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 6960 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6970 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7048 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7275 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7369 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7449 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7457 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7464 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7514 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 7604 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 7622 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 7689 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 7844 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7922 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8004 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8014 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8246 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8484 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8542 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 8592 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9012 core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9489 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9592 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9712 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9852 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9884 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 9891 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9892 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 9915 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 10025 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10026 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 10233 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10249 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
PR 10442 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10652 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 10757 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 10894 core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 10920 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cpp
PR 11442 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 11444 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/Recorder.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
PR 11554 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12120 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 12157 core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
PR 12324 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 12536 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12828 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 12862 core/libs/prx/libSceAgcDriver/CMakeLists.txt
PR 13148 core/libs/prx/libSceAgcDriver/CMakeLists.txt
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp

@MarcZX10

Copy link
Copy Markdown
Contributor

The #7233 RTX run exposed an ordering detail that likely affects this buffer-mask path: NoteHtileDepthClear runs before PrepareDispatch, and the HTILE host import can first happen while building dispatch resources. A clear baseline captured at NoteHtileDepthClear then treats that import-window stamp as a CPU race.

I am prototyping #7233 so recognition leaves the clear pending and the baseline is armed after resource imports, immediately before GPU writes are recorded. Your MatchHtileBufferMaskClear path also calls NoteHtileDepthClear and records the mask after dispatch, so it will need the same baseline transition at the right post-build point. My prototype is still local and only compile-validated here; the Xeon host stops before the GPU test. Let’s coordinate the two paths before either is merged; I can share/rebase the implementation once we agree on the hook for the mask dispatch.

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked the call flow more closely. A shared path should work without changing your mask-write tracking: when NoteHtileDepthClear recognizes the buffer-mask clear, propagate its completion candidate through the existing Dispatch argument. Then recordDispatch can arm the baseline after resource imports and register the existing completion check; your later NoteHtileMaskOnGpu still associates the pending write note with the mask for store-back expansion. The global-store clear follows the same path.

Would you be comfortable sequencing #7233 first and rebasing #8105 on that API, or do you prefer another shared hook? The rebased #7233 prototype is local and not pushed yet; I want to avoid landing incompatible lifecycle changes.

@github-actions github-actions Bot added the agc libSceAgc* label Oct 19, 2026
@Celegans12

Copy link
Copy Markdown
Contributor Author

@MarcZX10, I checked this against #8105 and you're right. The buffer kernel goes through the same NoteHtileDepthClear call as the global-store one, before PrepareDispatch, and it passes nativeBytes equal to bytes. So for a sampled native multisample target it arms clearGeneration at the same early point, before the HTILE is imported for the dispatch. And if I read #7233 right, the buffer kernel's store is a descriptor-bound range there, so it only counts as a possible write. Without the completion hook, that path would then also fail the StoredAllSince check.

I'm fine with #7233 going first. The htileClearCompletion argument you already pass to Dispatch looks like the right shared hook to me. Once #7233 lands I'll rebase #8105 and set it from the buffer branch whenever NoteHtileDepthClear returns true, the same way the global-store branch does. NoteHtileMaskOnGpu stays as it is, since it only feeds the single-sample store-back. I'll add a test next to your DriverDispatch case that sends the buffer kernel through PM4 over a native multisample HTILE.

If your rebased version arms the baseline inside recordDispatch instead, that works for us too, as long as the buffer branch can pass the same address and byte count. Could you ping me here when it's pushed? Then I'll rebase onto it. Until then, on main alone, #8105 behaves for native multisample targets the same way the global-store kernel already does, so I'm leaving it as is.

@Celegans12

Copy link
Copy Markdown
Contributor Author

This one has no main numbers yet either. What I have comes from our Yōtei tree, where the same kernel recognition sits on top of a different local implementation of the GPU expansion. In the world, the depth store-back used to wait on the GPU 12-14 times per 10 s, 1.3-1.7 s in total. In the run just before this change those waits had moved into a pre-sync (about 1.1 s per 10 s). With the buffer kernel recognized there were none.

The traced frames of the closest pair don't show a frame-time difference beyond our run-to-run noise. That pair is the same scene, machine and environment, presents 880-891, before and after only this recognition: frame p50 went from 2,763 to 2,704 ms, but GPU busy went from 1,069 to 1,192 ms per present, and p90/p99 got worse in that window. Two runs of one build here have differed by 18% in p50. Where the saved time did show up is the queue-0 committer: it was 61% busy before and 46% after, in the untraced windows.

A main vs change pair needs a Yōtei run on main, and the machine is busy with other game work right now. I'll do it when it's free and post both lines here. If a different scene or a synthetic depth-clear benchmark would suit you better, tell me and I'll use that instead.

Summary lines (our tree, not main)

Before (long31-s1e5):

{"commit":"1cb08e3c4c5d","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":35992.963},"presents":12,"frame_ms":{"p50":2763.181,"p90":2911.173,"p99":5630.251,"max":5630.251},"gpu_busy_ms_per_present":1069.385,"worker_busy_pct":{"queue worker 0x0":94.692,"queue worker 0x52":49.055,"queue worker 0x20":56.191,"queue worker 0x53":47.992,"queue worker 0x30":82.793,"queue worker 0x48":3.548,"queue worker 0x38":83.449,"queue worker 0x51":4.364,"queue worker 0x50":45.901},"top_phases_ms_per_frame":{"Driver.Packet":14023.139,"Driver.Packet.memory_wait":8917.156,"Driver.Packet.dispatch":2607.674,"Driver.Dispatch":2162.854,"DrawPipeline.commit":1765.433,"Driver.Packet.draw":1505.629,"Driver.Draw":1500.810,"Graphics.Draw":1253.805},"trace_dropped":false,"trace":"aps5-trace-1cb08e3c4c5d-10200.json.gz"}

After (long33-s1e5h):

{"commit":"a6ea328656e3","dirty":false,"env":{"APS5_BINDLESS_IMAGES":"1","APS5_BINDLESS_LAZY":"1","APS5_BINDLESS_STATS":"1","APS5_CACHE_SPIRV_BACKING":"1","APS5_COLD_SPIRV":"1","APS5_COLD_SPIRV_FILE":"1","APS5_DUMP_FRAMES":"300","APS5_DUMP_FRAMES_EVERY":"10","APS5_INLINE_SHADER_PREPARE":"1","APS5_MEM_STATS":"10","APS5_NO_ADDRESS_DRAW_REUSE":"1","APS5_NO_RESULT_MEMO":"1","APS5_PAD_SCRIPT":"100:cross,106:cross,112:cross,118:cross,124:cross,130:cross,136:cross,142:cross,148:cross,154:cross,160:cross,166:cross,172:cross,178:cross,184:cross,190:cross,196:cross,202:cross,208:cross,214:cross,220:cross,226:cross,232:cross,238:cross,244:cross,250:cross,256:cross,262:cross,268:cross,274:cross,280:cross,286:cross,292:cross,298:cross,304:cross,310:cross,316:cross,322:cross,328:cross,334:cross,340:cross,346:cross,352:cross,358:cross,364:cross,370:cross,376:cross,382:cross,388:cross,394:cross,400:cross,406:cross,412:cross,418:cross,424:cross,430:cross,436:cross,442:cross,448:cross,454:cross,460:cross,466:cross,472:cross,478:cross,484:cross,490:cross,496:cross,502:cross,508:cross,514:cross,520:cross,526:cross,532:cross,538:cross,544:cross,550:cross,556:cross,562:cross,568:cross,574:cross,580:cross","APS5_PAD_SCRIPT_REPEAT":"","APS5_PIPELINE_INDIRECT":"1","APS5_PROFILE_DRAW":"1","APS5_PROFILE_GPU":"1","APS5_SPANNED_WAVE":"1","APS5_STAGING_DIFF":"1","APS5_TEXTURE_OVERFLOW_MIB":"1024","APS5_TRACE_DIR":"<path>","APS5_TRACE_EVENTS":"1048576","APS5_TRACE_FRAMES":"880:12","APS5_UNNORM_WRAP_GUARD":"1"},"gpu":"NVIDIA GeForce RTX 3080 Laptop GPU","driver":"NVIDIA 610.62","os":"Windows 10.0.26200","resolution":"3840x2160","window":{"spec":"frames 880:12","first_present":880,"ms":36701.776},"presents":12,"frame_ms":{"p50":2703.958,"p90":3608.411,"p99":7357.782,"max":7357.782},"gpu_busy_ms_per_present":1191.815,"worker_busy_pct":{"queue worker 0x0":95.016,"queue worker 0x52":51.918,"queue worker 0x53":50.897,"queue worker 0x20":58.559,"queue worker 0x38":83.559,"queue worker 0x48":3.025,"queue worker 0x30":82.988,"queue worker 0x51":4.696,"queue worker 0x50":43.446},"top_phases_ms_per_frame":{"Driver.Packet":14472.703,"Driver.Packet.memory_wait":9587.032,"Driver.Packet.dispatch":2261.263,"Driver.Packet.draw":1797.523,"Driver.Draw":1793.000,"Driver.Dispatch":1762.886,"DrawPipeline.commit":1728.961,"Graphics.Draw":1583.262},"trace_dropped":false,"trace":"aps5-trace-a6ea328656e3-18376.json.gz"}

@TheSovietWaffle

Copy link
Copy Markdown
Contributor

Tested on RTX 3080 (NVIDIA 617.42) and AMD Radeon RDNA 2 iGPU (1002:164e, 32.0.21045.5002), Windows 10 Pro 22H2, WinLibs GCC 15.2.0, Release, head 3bcacf596: agc_driver_depth_fast_clear_submit passes 3 of 3 on both GPUs.

AI-assisted: yes (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from 3bcacf5 to 446a4fc Compare October 20, 2026 14:32
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@adriadam10 adriadam10 self-assigned this Oct 20, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • htileAfterMaskClear (DepthSurface.cpp:1435-1439) returns "cleared" without checking the ZMask bits of the mask: without stencil it never checks clear->mask & 0x3f0, and with stencil and a stencil value of 0 it returns before checking mask & 0xf0. The kernel computes (word & mask) | value, so a set mask bit keeps the earlier word's ZMask, which the description says must not happen ("the ZMask bits don't depend on the earlier words"). RecordedMaskClearClearsWithoutWait (DepthFastClearSubmit.cpp:284-286) fills words with a non-zero ZMask (0x010 & mask, ...) and still expects a cleared depth, so it pins this behaviour instead of catching it. Please require the ZMask bits of mask to be 0 and value to give a cleared ZMask in every branch, and add a case where the mask keeps a non-zero ZMask and the read-back path is expected.
  • The perf label needs the aps5-summary.jsonl line of main and of the change from the same title, scene and machine, plus tools/trace_digest.py output (bot comment above). The description says there is no main summary for the Yōtei scene; please capture both.
  • #7233 and #7371 change the same NoteHtileDepthClear call in Dispatch.cpp, and the thread with MarcZX10 agreed to sequence #7233 first; list it under Depends on and rebase once it lands.

@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from 446a4fc to dd0cb98 Compare October 21, 2026 03:41
@Celegans12

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read. I went through htileAfterMaskClear again, and I don't think a ZMask can survive there, because in this HTILE layout the ZMask is bits 3:0. That's the layout HtileFillClears and the expanded words on main use: a word clears the depth exactly when word & 0xf is 0. The first check in the function returns no clear, for every branch, when mask & 0xf or value & 0xf is non-zero. So whenever we report a clear, (word & mask) | value has ZMask 0.

The 0x3f0 bits aren't ZMask. With stencil in HTILE they hold the stencil state (SMem is 9:8). Without stencil they're part of Min/Max Z, which a cleared tile doesn't use (MixedClearedSliceClears on main already relies on that). In the stencil-0 branch the stencil is cleared as well, so the old stencil bits don't matter, and the store-back sets 0x3f0 anyway. That's also why the words in RecordedMaskClearClearsWithoutWait (0x010, 0x0a0, ...) only vary bits 4-9 and keep ZMask 0, so I left that test as it is.

You're right that the read-back case wasn't covered, though, so I added RecordedMaskKeepingZMaskReadsBack to agc_driver_depth_fast_clear_submit. It records a mask clear whose mask keeps the ZMask (0x3ff, or 0x0ff with stencil) over words with a non-zero ZMask. It expects the depth to stay as it was, and the bind to read the HTILE back. It passes on the branch. With the mask & 0xf check removed, it fails 3 of 3 times with "an HTILE mask clear that keeps non-zero ZMask bits cleared the depth". If I've got the layout wrong somewhere, point me at it and I'll change the check.

On Depends on: the current head doesn't use anything from #7233. It builds and passes on main alone, so I've left the field at none for now. Once #7233 lands, the plan is still to rebase onto its API (setting htileClearCompletion from the buffer branch, with a test next to MarcZX10's DriverDispatch case), and I'll change the field then. The main-vs-branch summary pair and the trace_digest.py output are still owed.

The branch is also rebased onto current main (dd0cb98).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from dd0cb98 to 72e3eab Compare October 21, 2026 21:19
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 21, 2026
@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from 72e3eab to 18e8a76 Compare October 22, 2026 23:43
@Celegans12

Copy link
Copy Markdown
Contributor Author

@MarcZX10, the rebase onto #7233's API is done (18e8a76). The buffer branch in Dispatch now sets htileClearCompletion whenever NoteHtileDepthClear returns true, the same way the global-store branch does. NoteHtileMaskOnGpu is unchanged.

The test I promised sits next to your DriverDispatch case. It's that case again with the buffer kernel, sent through PM4 over a native 4-sample HTILE. It had to be its own ctest entry, agc_driver_native_depth_buffer_clear, because the driver can't start again in the same process after the first case shuts it down. On my RTX 3080 that import isn't write-watched, so like your case it ends on the refusal check. If the buffer branch ignores the completion candidate, it fails 3 of 3 with "native multisample depth clear has not been recorded". The watched path only runs where the kernel has asynchronous userfaultfd write protection. WSL doesn't, so that part is up to GitHub's Linux job. The targeted depth tests pass 30/30 here, and the validation-layer run shows no VUID- on main or the branch. Depends on stays at none, since #7233 is merged now.

@github-actions github-actions Bot added build and removed needs rebase Conflicts with main, rebase needed labels Oct 22, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked 18e8a76 against the earlier review:

  • ZMask: you are right, I withdraw that point. htileAfterMaskClear returns no clear when mask & 0xf or value & 0xf is non-zero (DepthSurface.cpp:1685), and ZMask is bits 3:0, so the 0x3f0 bits are not ZMask. RecordedMaskKeepingZMaskReadsBack now pins the read-back case.
  • #7233 and #7371 are merged and the rebase onto htileClearCompletion plus the PM4 agc_driver_native_depth_buffer_clear test look right.
  • Still open: this is a perf PR. Please paste the aps5-summary.jsonl line of main and of the change from the same title, scene and machine, and the tools/trace_digest.py summaries of both (attach the traces). The Yōtei numbers from your own tree don't replace a main capture; if the Yōtei scene can't be run on main, a synthetic depth-clear scene run on both works.

Nothing else to change.

@TechLevelZero

Copy link
Copy Markdown
Contributor

❌ NVIDIA GPU test: failed

PR head 18e8a76 merged onto main 52c09d5 · tested 2026-10-29 10:44 UTC · 23 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ❌ 2,275 passed · 6 failed (1 new: 1 not compared, 5 also fail on main) · 39 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,320 of 2,873 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (894 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) none

Failing tests

This PR changes test files, so each failing test was also built and run on main with only the PR's test changes applied. ✅ there means the failure comes from the PR's other changes; ❌ means the test fails on main too, so this run does not show the PR caused it.

Test With this PR Same test on main 52c09d5 (main + this PR's test changes only)
agc_driver_native_depth_buffer_clear ❌ failed not compared: the PR's tests do not build without its other changes
agc_driver_native_depth_buffer_clear: Failed (also failed when re-run alone), assertion and diagnostics
ctest: Failed

Selected GPU name=NVIDIA RTX 2000 Ada Generation vendor=0x10de device=0x28b0 driver=2497233024
[write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 4 after the import); imported ranges stay watched
Native depth feedback refused through the draw resource path; a written surface refused and a depth-tested one retired on guest read
[write-watch] host imports resolve write protection: no (0 of 4 scratch pages written after a GPU read, 0 after a GPU write, 4 after the import); imported ranges stay watched
[Shaders/ShaderRegistry.cpp:906 ReportPreparedAtUse] Compute shader 0x62e243c9cd00 was not registered; preparing its artifact at dispatch
compute shader 0x62e243c9cd00: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)
agc_driver_depth_clear_hle: VUID-vkCmdCopyBuffer-commonparent (6x)
Failing on main too (5, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)
agc_driver_depth_clear_hle: SEGFAULT in the parallel run; also passed only on retry in 22 other runs in the last 7 days
Validated but not compared (1, not in the main baseline's validation pass)
agc_driver_native_depth_buffer_clear
Validation IDs already present on main (4 IDs in 436 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (436 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alpha_to_coverage, agc_driver_array_layer_target_cpu, agc_driver_bc_block_copy, and 428 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (39)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SD
Reproduce
git fetch origin 18e8a7618d3d307729fb8e3058ce33ec78f38cad 52c09d567d2fa453494dd720fcf53a98149468e4
git checkout 52c09d567d2fa453494dd720fcf53a98149468e4 && git merge --no-ff 18e8a7618d3d307729fb8e3058ce33ec78f38cad
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1
# the failing tests, on this merge and on main:
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc_driver_native_depth_buffer_clear)$' --parallel 1 -V

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@MarcZX10

Copy link
Copy Markdown
Contributor

The new NVIDIA run from 10:44 reports agc_driver_native_depth_buffer_clear failing on the RTX 2000 Ada host. Its log says host imports did not acquire write protection (0/4 scratch pages observed written after either GPU access or import) and then refused native depth feedback. The report couldn't compare this test on main because the test changes do not build without the production changes.

Your earlier Windows report says the same test exercises the refusal path when the import is not write-watched, so please reconcile the two outcomes: does this Linux failure reflect an expected unsupported-host path, or does it expose a regression in the buffer-clear completion/refusal handling? If expected, please make the test/report distinguish that limitation and provide a meaningful baseline/control; if not, fix it and rerun the focused test. I have not reproduced the GPU failure locally.

@blawesom

Copy link
Copy Markdown
Contributor

Static review plus an independent Linux/AMD run on both trees per the repo AGENTS AGC protocol (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja 1.13.2, Release, BUILD_TESTING=ON, Ryzen 7 9800X3D). No findings.

What I checked (static)

  • The change extends perf(agc): take the HTILE words pending fills leave instead of reading them #6505's "skip the HTILE read back when the pending writer is a uniform GPU fill" to the mask-clear kernel variant (each HTILE word becomes word & mask | value). MatchHtileBufferMaskClear recognizes that kernel by exact opcode sequence plus strict layout checks: unknown opcodes, a truncated kernel, a float descriptor, an 8-byte stride, non-uniform per-word masks, a 32-thread group, an indirect dispatch and a partial-group dispatch all reject, as pinned by htileBufferMaskClearTests. Record count is min(threads, userData[2]) for both the group-count and thread-count dispatch forms, matching the two tests' bytes == 0x40000/0x20000 cases.
  • htileAfterMaskClear takes the fast path only when it can express the full post-clear HTILE word shape as depth-only (0xfffc000f) or depth+stencil (0xfffff3ff) marks; anything outside that narrow known-good surface falls back to the read-back path, so a mis-recognized clear cannot produce wrong depth state.
  • The dispatch integration threads the recorded HtileMaskClear (mask/value from userData[5]/userData[4] for the depth-clear form, matcher result for the buffer form) through Dispatch.cpp to NoteHtileMask/NoteHtileMaskOnGpu, which records it against the newest covering write note — stale notes (not newest, or not covering the range) discard the record, so a later non-mask write invalidates the shortcut. The mask list is bounded (64 entries) and pruned on overlap, consistent with the neighbouring recorder caches.
  • Tests cover both polarities: RecordedMaskClearClearsWithoutWait asserts the bind after a recognized mask clear does not wait on the GPU (ThreadHookWaits unchanged), stores the expanded HTILE (0xfffc000f/0xfffff3ff), and that the cleared depth/stencil behave as cleared; RecordedMaskKeepingZMaskReadsBack asserts the inverse — a clear that keeps ZMask bits deliberately does read the HTILE back (waits change). The fault catalogue grew DriverBufferDispatch and the new PM4 buffer-clear path feeds CheckDepthTarget through it, wired to --buffer-clear (registered as agc_driver_native_depth_buffer_clear).

Focused paired run (AGENTS AGC protocol, VVL env)

tree result other fixtures
this head 18e8a7618d 8/8 Passed includes new agc_driver_native_depth_buffer_clear (Passed)
main bb04a4f1ea 7/7 Passed new fixture not present at base; shared 7 identical

Both logs: 0 was not found but was requested by env var VK_INSTANCE_LAYERS, 0 VUID-. Comparing logs, no new validation errors from this change.

Not covered

The htileAfterMaskClear shape classification (depth-only vs depth+stencil vs "keep reading") is only exercised through the two stencil flag cases in RecordedMaskClearClearsWithoutWait; the intermediate mask shapes (e.g. mask with a non-zero 0x3f0 low nibble) take the read-back path and are pinned only as "not-fast-path" behavior in the throw-away matcher test. That is the safe direction (read back over skip wrong), just noting the safety net is the matcher's narrowness rather than exhaustive shape coverage.

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

On the NVIDIA failure of agc_driver_native_depth_buffer_clear that @MarcZX10 asked about: it is not specific to that host. The test passes on the PR's own base and fails once the PR is merged with current main. Two merges from 28-30/10 now refuse the buffer kernel's HTILE write.

Setup: Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, lavapipe (Mesa 26.0.3; write-watch reports host imports keep write protection: yes). Head 18e8a7618d, main ed1e0ed08f.

tree agc_driver_native_depth_buffer_clear
PR merged onto its merge-base 3a2ca40dab passes
PR merged onto main ed1e0ed08f fails 3/3: compute shader ...: AGC graphics: sample-preserving guest publication of native multisample depth is not implemented (same message as the NVIDIA run)

Cause: a first-parent git bisect (PR merged at each step) lands on #11369 (26c2097, 28/10). It added RequireNoResidentDepthRead_nid_no_patch over every writable buffer range in GuestBufferMemory::UploadFinish. #6498 (341cf8b, 30/10) then added RequireNoMultisampleTarget(..., "a shader buffer access") in ShaderResources::requireGuestBuffers.

The buffer variant of the mask clear binds the HTILE through a writable V#. Both checks see a buffer over the HTILE guard of a resident, host-written native 4x depth and throw, even though NoteHtileDepthClear already accepted that dispatch as the clear transition (clearPending). The global-store kernel does not go through a descriptor buffer, so DriverDispatch is unaffected. With both checks removed (diagnostic only), the focal passes 3/3. Removing only #11369's line still fails, because #6498's check catches it.

A fix that works here (22 lines, attached below): exempt a buffer range at those two call sites only when every resident depth guard it overlaps is the HTILE of a surface whose recognized clear is in flight (clearPending || clearGeneration != 0, no refusal). Anything else still goes through the existing checks, and CompleteHtileDepthClear still checks for racing CPU writes.

diff on top of the merge
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
index b29d2d0e3b..dfe967888a 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/include/DepthSurface.hpp
@@ -40,6 +40,8 @@ std::uint64_t DirectDepthCopyCount();
 std::uint64_t MultisampledDepthBytes_nid_no_patch(VkExtent2D extent, std::uint32_t bytesPerTexel, std::uint32_t samples);
 void RequireNoResidentDepthRead_nid_no_patch(std::uint64_t address, std::size_t bytes);
 void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std::vector<std::pair<std::uint64_t, std::uint64_t>>& ranges);
+// True when every resident native depth guard over the range is the HTILE of a surface whose recognized clear is in flight.
+bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes);
 bool HasResidentDepthGuards_nid_no_patch();
 void RetireUnmappedDepth_nid_no_patch(std::uintptr_t address, std::size_t bytes);
 void RequireNoNativeDepthFeedback_nid_no_patch(const Context& context, const DepthTarget& target, std::span<const std::shared_ptr<Texture>> sampled);
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
index ef143dde32..219c52c891 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
@@ -2161,6 +2161,22 @@ void AppendHostWrittenDepthRanges(std::uint64_t address, std::size_t bytes, std:
     }
 }
 
+bool AcceptedHtileClearCovers_nid_no_patch(std::uint64_t address, std::size_t bytes) {
+    if (bytes == 0u || !anyDepthGuard().load(std::memory_order_acquire)) return false;
+    std::lock_guard lock(surfacesMutex());
+    std::shared_lock guardLock(depthGuardMutex());
+    bool any = false;
+    for (const auto& range : depthGuards()) {
+        if (!(address < range.address + range.bytes && range.address < address + bytes)) continue;
+        const bool clearing = std::ranges::any_of(surfaces(), [&](const auto& surface) {
+            return surface->active == range.active && surface->samplingActive && surface->sampling.refusal.empty() && (surface->clearPending || surface->clearGeneration != 0u) && surface->sampling.initial[1].address == range.address && surface->sampling.initial[1].bytes == range.bytes;
+        });
+        if (!clearing) return false;
+        any = true;
+    }
+    return any;
+}
+
 void NoteDepthSurfaceWrite(const Context& context, const DepthTarget& target) {
     if (target.samples == 1u || !anyDepthGuard().load(std::memory_order_acquire)) return;
     std::lock_guard lock(surfacesMutex());
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
index 4658630beb..c25abf26cf 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp
@@ -5450,7 +5450,9 @@ void GuestBufferMemory::UploadFinish(bool addressable) {
     if (space != nullptr) completeSpaceWrites();
     uploaded = true;
     for (const auto& region : regions) static_cast<void>(FlushDepthPlanes(region.begin, static_cast<std::size_t>(region.end - region.begin)));
-    for (const auto& [begin, end] : writes) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin));
+    for (const auto& [begin, end] : writes) {
+        if (!AcceptedHtileClearCovers_nid_no_patch(begin, static_cast<std::size_t>(end - begin))) RequireNoResidentDepthRead_nid_no_patch(begin, static_cast<std::size_t>(end - begin));
+    }
     for (const auto& [begin, end] : writes) StorageTexture::FlushPending(begin, static_cast<std::size_t>(end - begin), nullptr, "written buffer range");
     if (context.hostImportAlignment != 0) {
         auto& state = Imports();
diff --git a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
index e67f52d882..89e384febb 100644
--- a/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
+++ b/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
@@ -5910,7 +5910,7 @@ void ShaderResources::requireGuestBuffers(std::span<const MovedBuffer> moved) co
         const auto override = std::find_if(moved.begin(), moved.end(), [&](const MovedBuffer& entry) { return entry.allocation == index; });
         const auto address = override != moved.end() ? override->address : item.address;
         const auto bytes = override != moved.end() ? override->size : item.size;
-        RequireNoMultisampleTarget(address, bytes, "a shader buffer access");
+        if (!AcceptedHtileClearCovers_nid_no_patch(address, bytes)) RequireNoMultisampleTarget(address, bytes, "a shader buffer access");
     }
 }
 

With it, on the merge with ed1e0ed08f:

  • focal 3/3;
  • ^agc suite (without display/flip/lds64) 1129/1129 on lavapipe. main alone is 1128/1128; the extra test is the new one.
  • #11369's buffer-write cases (a GPU buffer write over the depth or HTILE released the unwritten surface, D16/D32 x 4/8 samples) and #6498's agc_driver_sample_multisample_target still pass.

The test also prints skipped native HTILE write-coverage assertion on lavapipe, both on the base and with the fix, so that assertion isn't exercised on this host.

The authors may prefer to put the exemption somewhere else (for example, passing htileClearCompletion down to the bind). I'm only showing that the guard interaction is the cause.

GPUs tested: lavapipe (Mesa 26.0.3) only.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from 18e8a76 to c8051ed Compare October 31, 2026 03:46
@Celegans12

Copy link
Copy Markdown
Contributor Author

I reproduced the failure 3/3 on the RTX 3080 Laptop with this PR applied to main e2df06e, so @MarcZX10, this was a real guard regression. Thanks @jotitadev for the bisect and supplied fix.

The update passes the recognized clear's HTILE range through preparation, upload and binding, allowing it only while the matching native owner has clearPending. Ordinary buffer writes and the color guards retain their checks; the permission ends at arm, and these resources cannot enter the dispatch/recipe caches. The extended clear test also rejects ordinary writes, oversized ranges, depth-plane accesses and permission reuse after arm.

The focal now passes 3/3 on NVIDIA; all eight focused tests pass there with three repetitions, and 8/8 pass on Windows lavapipe. The seven common tests pass on main on both drivers, with validation loaded and no VUID errors in any of those passes. Both Windows drivers still lack imported-HTILE write coverage, so the PM4 clear tests now reach the expected tracked-generation refusal again; successful watched-clear sampling remains unverified here. I haven't rerun Linux or any title for this update, and the body keeps the earlier performance measurements separate from this guard fix.

@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 — changes requested

The new process-wide HTILE-mask registry can mistake an unrelated write for a prior mask clear after a Recorder is recreated and its local write-note counter restarts.

What I ran

Reviewed head c8051ed3bab05296a22f49141a0553cefa10d837 against PR base de824c2919ca65086c6324a1e0388866a7327eea; the no-build merge preview against current main was clean. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++/GPU tests.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 8105

Results

Check Result
Diff check and conventions Passed.
Dependency/mergeability preview Passed; clean against current main.
Hosted CI on this head Windows, conventions, library-portability, and labels were queued at the final check; Linux, relinker, ASAN, register-context, and write-watch were skipped. Eligibility and report passed.
Author-reported focused testing The author reports the guard regression reproduced 3/3 before the fix and passed 3/3 after it on an RTX 3080 Laptop; the eight focused tests passed with three repetitions on NVIDIA and once on Windows lavapipe. Linux, AMD, Intel, and title testing are reported as not run for this update.
Precheck helper execution The isolated checkout lacked the ABI and test-quality helper scripts; this is a precheck harness issue, not a PR failure.
Selected unedited precheck output
All conventions checks passed.
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-8105-c8051ed3bab0/head-c8051ed3bab0-acd88d27/tools/pr_test_quality.py': [Errno 2] No such file or directory
Conclusion: checks failed

Negative control

Assertion Mutation/change Result
A stale mask record cannot authorize a later recorder's unrelated write Recreate the recorder, reuse the guest HTILE address and local write-note value, then call the readback path Not run; the current tests do not cover recorder identity reuse.

Findings

Blocking

HtileMaskWrite stores only the clear range/pattern and Recorder::PendingWritesOver's numeric note. htileAfterMaskClear accepts a record when its note equals Recorder::NewestWriteNote and the ranges cover. The write-note counter is per Recorder and starts at zero for each instance. The registry is process-static, capped at 64 entries, and otherwise entries survive until the 64-entry cap evicts them; ClearDepthSurfaces does not clear this registry. Thus a later recorder can produce the same note for an unrelated write to a reused guest address, causing the stale mask record to be accepted and the HTILE data to be expanded as if the old mask clear were still authoritative. This can produce incorrect depth/stencil contents.

Key each record and lookup to a unique recorder identity/generation (or make write-note IDs globally unique), and retire that recorder's records when its state is cleared. Add a regression test that recreates a recorder, reuses the address/note, and proves the unrelated write takes the ordinary readback path.

Non-blocking

The newly reported GPU regression fix and its focused tests are useful evidence, but they do not exercise this recorder-lifetime collision.

Sources

Not verified

I did not run builds, C++ tests, GPU tests, Linux/macOS validation, or console/title behavior. The author-provided GPU results were not independently reproduced.

To get this to a good state

Please bind mask records to a unique recorder generation, clean them up with that owner, and add the recorder-reuse regression test. I will rerun the same checks on the new head.

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the guard fix. Agreeing with @MarcZX10's blocking point, checked against the code:

  • HtileMaskWrite (DepthSurface.cpp:1864) stores only the clear and a write-note number, and htileAfterMaskClear (DepthSurface.cpp:1886) accepts a record when write.note == newest and the ranges cover. The note is Recorder::writeNoteCount, a per-instance counter that starts at 0 (Recorder.cpp:3000), while htileMasks() is process-static and ClearDepthSurfaces (DepthSurface.cpp:2689) does not touch it. After a device/recorder is recreated, an unrelated write to a reused HTILE address can get the same note and be expanded as if the old mask clear were still pending.
  • Fix: key each record to its owner (the recorder, or a generation that is unique per recorder), compare it in htileAfterMaskClear, and erase the owner's records in ClearDepthSurfaces for that device.
  • Test: recreate the recorder, reuse the HTILE address and the same note value for an ordinary write, and assert the bind takes the readback path (words read back, ThreadHookWaits increases). It must fail without the owner check.

The guard change itself (recognized clear's range passed through preparation, upload and binding, only for the pending native owner, no resource/recipe cache) looks right to me.

Record an HTILE clear's mask/value with its pending note and recorder ID.
When that write covers the HTILE and determines its ZMask/SMem bits,
expand the metadata on the GPU without a readback. Retire mask proofs
with their recorder or depth device, preserving other owners and the
bounded cache's conservative overlap invalidation.
Recognize the structured-buffer variant and carry its completion range
through preparation, upload and binding. Admit only that range while
its native owner has a pending clear, retaining color guards and
excluding these resources from dispatch and recipe caches.
Cover store-back, PM4 buffer clears, guard refusals, recorder recreation,
live owner isolation and scoped cleanup with GPU byte/wait assertions.

AI-assisted: yes
@Celegans12
Celegans12 force-pushed the perf/agc-htile-mask-clear-on-gpu branch from c8051ed to 448aa81 Compare October 31, 2026 04:53
@Celegans12

Copy link
Copy Markdown
Contributor Author

@MarcZX10 @adriadam10 I reproduced the recorder-lifetime collision from MarcZX10's review and adriadam10's review, and fixed it in 448aa81.

The new regression recreates a recorder in the same storage, reuses the HTILE address and note 1, then records an ordinary GPU write. Before the fix it failed all three runs: no readback wait, and the ordinary words were overwritten with expanded clear metadata. The lookup now checks the existing monotonic recorder ID as well as the note; teardown removes that recorder's proofs, and depth cleanup removes proofs for that device. The global 64-entry bound and conservative overlap invalidation remain.

agc_driver_htile_mask_lifetime now checks both waits and bytes across eight cases, including two live recorders, the same-owner no-wait path, and cleanup of two owners on one device while preserving another device's proof. All nine focused tests passed three times on NVIDIA and once on lavapipe, with validation loaded and no VUID errors; the new assertions executed on both. This is Windows 11 evidence on main 0835ec8. The previous pending-native-clear guard fix is retained; the imported-HTILE write-coverage limitation remains, and I haven't run Linux or a title for this revision.

@adriadam10
adriadam10 merged commit 8dc9f36 into boykopovar:main Oct 31, 2026
12 of 13 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Re-checked 448aa81 against the recorder-lifetime blocker and the earlier points. htileAfterMaskClear now requires write.recorderId == recorder.Id() as well as the note, Recorder::id comes from the monotonic nextRecorderId, ~Recorder drops that recorder's proofs, and ClearDepthSurfaces drops the device's. agc_driver_htile_mask_lifetime covers a recreated recorder in the same storage with the same address and note, two live recorders, recorder cleanup and device cleanup with another device's proof kept, comparing both ThreadHookWaits and the metadata bytes. The pending-native-clear guard fix from the previous round is unchanged, the ZMask point stays withdrawn, and the main vs change captures satisfy the perf request. Merged.

Celegans12 pushed a commit to Celegans12/AnyPS5-Ghost-of-Yotei that referenced this pull request Nov 1, 2026
Conflicts, each resolved by keeping both sides:
- docs/dev/ENVIRONMENT.md: rows APS5_GPU_HEAP, APS5_GPU_HEAP_EXCLUDE, APS5_GPU_PATH, in name order.
- core/libs/prx/libSceAgcDriver/CMakeLists.txt: the WIN32 PATH set_tests_properties line carries both sides' test names in one list: agc_shader_table_trailer and agc_shader_device_image_tables from this branch, agc_driver_image_table_cache_bounds_heap_small and agc_driver_image_table_store_gpu_heap from boykopovar#9508.
- VulkanDevice::Target(): both assignments, deviceImageTables first, then heapDataUniformDwords.

ShaderResources.cpp merged without a conflict and keeps boykopovar#9508's own resolution of boykopovar#8105 from dd7120c, so a build with an HTILE mask clear is never reusable, address-space reuse included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build perf Performance change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants