perf(agc): keep the HTILE clear check of untracked memory until its stamp moves #11602
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11602"
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 XatiX on 2026-10-26T22:33:02Z.
What
storeBackClearedHtile, called by everyDepthSurfaceView, avoids rereading a depth target's HTILE while the write watch proves it unchanged since the last read:htileReads()keeps the generationCollectWritesreturned, andUnchangedSincechecks it. For HTILE outside the write watch,CollectWritesreturns 0, so the stored generation is 0, the proof is never tried, and every draw reads the whole HTILE withGuestMemory::Readand scans every word withHtileFillClears.Builder's Journey (PPSA05496) reaches this in a later level. Two HTILE buffers of 512 KiB and 640 KiB are outside the write watch. Counters added locally, not part of this PR, showed this per 10 s:
UnchangedSincepath;Watchedfalse andCollectWrites0.With
APS5_SAMPLE_COMMITTER,DepthSurfaceViewwas 42.5 % of the draw committer: 23 % in the inlined scan loop and 11.6 % in thememcmpunderGuestMemory::Read.Change. Over HTILE outside the write watch (
collected == 0, no pending write), a scan that found no clear is kept under the stampStorageTexture::compareUntrackeduses for untracked memory:NewestStampof the range;ForgetSerial, cached only while even;NewestWriteNoteover the range.The stamp is taken before the read, after
GuestMemory::FlushGpuWritesover the HTILE (asStorageTexture::compareUntrackeddoes), so results still pending on the GPU over it are stored before the stamp is read. The kept scan also recordshtileStencil, becauseHtileFillClearsreads the same words differently with and without stencil in the HTILE. A call with the same address, size,htileStenciland stamp returns 0 without reading. In all other cases the HTILE is read and scanned as before: any stamp change, a differenthtileStencil, a collect epoch of 0, a scan that found a clear, or a pending write.forgetHtileReadsdrops these entries with the generations.This keeps the ordering the collect memo already relies on: a CPU write is seen at the next collect epoch, and a driver store or recorded GPU write moves the stamp.
Tests (
DepthSurfaceReuse.cpp, run byagc_driver_graphics):TestUntrackedHtileScan: an HTILE in memory outside the write watch, holding no clear, is checked twice in one collect epoch.mainthis fails with "an HTILE outside the write watch that held no clear must not be read again before its stamp moves".TestUntrackedHtileStencilScan: unchanged untracked HTILE words0x0000000fon a D32S8 surface, all in one collect epoch.htileStencilcheck this fails with "an HTILE outside the write watch scanned without stencil must be read again for a lookup with stencil in the same collect epoch".TestUntrackedHtileDriverStore: after a kept scan, a cleared HTILE is stored throughGuestMemory::MarkWritten(a driver store) in the same collect epoch. The next lookup must read the HTILE again and clear the surface. WithoutNewestStampin the stamp this fails with "an HTILE outside the write watch must be read again after a driver store in the same collect epoch".In these tests the flush hook counts calls over the HTILE: a lookup that reads it makes two (the stamp's flush and the read's), and a kept scan makes exactly one. Without the flush before the stamp the first check fails ("the first check of an HTILE outside the write watch must read it").
Tested
Windows 11 (build 26300), Ryzen 7 9800X3D, NVIDIA GeForce RTX 5080 with driver 617.42, 3840x2160 output, MinGW GCC Release build.
Performance. Builder's Journey (PPSA05496 03.002.583): title, then Continue into the level the save resumes. Plain
mainagainstmainwith this PR, same machine and session, game relinked once withmain's relinker:82e2d0ed142f):main82e2d0ed1, which includes #11098.b827db337d3d): the samemainwith this PR's first four commits (the flush before the stamp came later and only adds a hook call per lookup).Each build started from an empty shader cache, ran once untimed to fill it, then once measured. Only
APS5_TRACE_SECONDS=60:4and the pad input file were set. Neither trace dropped events. The two traces follow in the next comment.tools/trace_digest.py, threads in ms per frame, with an earlier pair from the same session (60:5window; A's trace dropped 6,836 events in its last 0.1 s):The draw committer's time drops by half or more in both pairs. The frame rate follows it only where the committer limits the frame: about +5 % in the 4 s pair and +30 % in the 5 s pair, whose A window caught a slower stretch of the level. @klosixgaming-arch's plain
maincomparison on a second title, Soul Hackers 2 (PPSA03743 01.002.000, RTX 5090), shows the same:Graphics.Draw46.3/52.6 → 30.4/29.3 ms per frame and 80–90 → 100–129 presents in 5 s.main319621ba2itself crashes in this title before the level: queue worker 0 faults inside the NVIDIA shader compiler (nvgpucomp64.dll+0xa98518) with or without this PR, when the shader cache starts empty. That is unrelated to this change and is why A is the earliermain82e2d0ed1.GPU tests. Rebased onto
main319621ba2. On this PR (d4afbc459) and onmain319621ba2, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:ctest --test-dir build-test -R "^agc_driver_graphics$|^agc_driver_.*depth|htile" -V, 42 tests.was not found but was requested by env var VK_INSTANCE_LAYERS. Validation comes from Vulkan SDK 1.4.363.0.VUID-error.python3 tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.py: these PRs changeDepthSurface.cpporDepthSurfaceReuse.cppnear this change:storeBackClearedHtilefor layered views. This PR leaves its signature and result unchanged.TestUnmappedStalePlaneFlushandRunDepthSurfaceReuseTests.Not tested: Linux, where
UntrackedHintreturns 0 and the stamp falls back to the collect epoch.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-26T23:12:07Z.
Review: CHANGES_REQUESTED
Reviewed head
fe048a368bf30a7b6a1c1fd388878e3c599dcb39. The stamp layout and cacheability checks mirrorStorageTexture::compareUntracked, and the new test covers one no-clear scan per epoch plus a CPU-written clear after the epoch advances. I downloaded both attached traces and ranpython3 tools/trace_digest.pyon them; the tool’s summary lines match the posted values and identify the same Builder’s Journey version, scene window, GPU, driver, OS and resolution. Both traces reporttrace_dropped: true(withtotals_full: falsefor the affected threads), so event-level trace detail is incomplete even though the summary totals are reported complete.[P2] Clarify the required
mainbaseline before treating the perf report as complete. The report says capture A usedmainata120df348plus PR #11098, and #11098 is still open. That is a stacked base, not a capture ofmainas the performance-report requirement specifies. The matched A/B pair is useful evidence for this patch on top of #11098, but it does not establish the required main-to-change comparison. Please either provide maintainer-approved guidance that this dependency-stacked baseline satisfies the protocol (and declare the dependency), or add an applicable baseline/change pair under the approved report format. Because the title needs #11098 to reach the tested scene, please get that policy clarification rather than reporting a title capture that cannot reach the scene.The PR reports a Windows build and focused Vulkan tests (35/36 passing identically on its comparison main); I did not rerun the GPU tests locally. Hosted conventions, intake and labels pass; this PR’s hosted status does not include a product/relinker build run.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T20:09:12Z.
Review: APPROVED
Re-checked — new head, looks good
The stencil keying and its tests hold up, and the baseline concern from my earlier review is covered now that #11098 is merged and an independent plain-
maincomparison exists.What I ran
3faa0e3dc7merged ontomainat319621ba2e(merges cleanly; #11098 is already in thatmain).Results
git diff --checkagc_driver_graphics(runsRunDepthSurfaceReuseTests)Graphics.Draw66.2 ms/frameGraphics.Draw19.9 ms/frameNegative control
I changed the code under test in a scratch copy, kept the tests, and ran them.
stencil == target.htileStencilfrom the cache check (L1840)NewestStamp,ForgetSerialandNewestWriteNotefrom the stampFindings
Blocking
None.
Non-blocking
StorageTexture::compareUntrackedcallsFlushGpuWritesbefore taking its stamp, and the new path (L1833, stamp at L1746) does not. I could not establish whether a deferred storage-image write over HTILE that is not yet stored can be missed here, since HTILE is normally written by recorded dispatches or fills thatpendingandNoteHtileDepthClearcover. If it is not reachable, a sentence saying so would be enough.Depends on: #11098and "A =main+ #11098" in the description are out of date. Please update them. The plain-mainrecapture promised in the description can now be taken on Builder's Journey.Sources
DepthSurface.cppL1735 (scan record), L1746 (stamp), L1833 (use), L1840 (lookup with stencil), L1873 (store)maincomparison: the table posted by klosixgaming-arch on this PR (PPSA03743, RTX 5090,main0cd07dc4abvs92df59deeb).Not verified
UntrackedHintreturns 0 and the stamp falls back to the epoch.trace_droppedfrom the attachments, since no summary file was attached; I rely on the posted JSON.