perf(agc): expand an HTILE on the GPU behind a pending mask clear kernel #8105
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8105"
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 Celegans12 on 2026-10-19T21:49:21Z.
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
PrepareDispatchparameter; 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
main0835ec8bdc,-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_lifetimefails 3/3 on the previous PR rebased onto this main: reused recorder storage, HTILE address and note 1 turn ordinary0x0000000fwords into0xfffc000fwithout 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 bothThreadHookWaitsand metadata bytes.agc_driver_native_depth_buffer_clearregression failed 3/3 before its guard fix; that test and seven neighbors remain in the current passing set. Historical paired maine2df06e661controls passed 7/7 on both drivers; those controls were not rebuilt this round. Recorder/DepthSurface production files are unchanged between that main and0835ec8bdc.Historical performance evidence, 24 October; no new performance claim for the guard or lifetime fixes
mainvs 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 (onlyAPS5_TRACE_FRAMES=150:60, noAPS5_PROFILE_*):maina5a2c946a3againstmaina5a2c946a3+ 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 andtools/trace_digest.pyoutput 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)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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T21:49:35Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T22:54:04Z.
The #7233 RTX run exposed an ordering detail that likely affects this buffer-mask path:
NoteHtileDepthClearruns beforePrepareDispatch, and the HTILE host import can first happen while building dispatch resources. A clear baseline captured atNoteHtileDepthClearthen 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
MatchHtileBufferMaskClearpath also callsNoteHtileDepthClearand 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.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T23:00:18Z.
I checked the call flow more closely. A shared path should work without changing your mask-write tracking: when
NoteHtileDepthClearrecognizes the buffer-mask clear, propagate its completion candidate through the existingDispatchargument. ThenrecordDispatchcan arm the baseline after resource imports and register the existing completion check; your laterNoteHtileMaskOnGpustill 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.
Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T23:49:28Z.
@MarcZX10, I checked this against #8105 and you're right. The buffer kernel goes through the same
NoteHtileDepthClearcall as the global-store one, beforePrepareDispatch, and it passesnativeBytesequal tobytes. So for a sampled native multisample target it armsclearGenerationat 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 theStoredAllSincecheck.I'm fine with #7233 going first. The
htileClearCompletionargument you already pass toDispatchlooks like the right shared hook to me. Once #7233 lands I'll rebase #8105 and set it from the buffer branch wheneverNoteHtileDepthClearreturns true, the same way the global-store branch does.NoteHtileMaskOnGpustays as it is, since it only feeds the single-sample store-back. I'll add a test next to yourDriverDispatchcase that sends the buffer kernel through PM4 over a native multisample HTILE.If your rebased version arms the baseline inside
recordDispatchinstead, 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, onmainalone, #8105 behaves for native multisample targets the same way the global-store kernel already does, so I'm leaving it as is.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-19T23:49:29Z.
This one has no
mainnumbers 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
mainvs change pair needs a Yōtei run onmain, 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):
After (long33-s1e5h):
Imported from boykopovar/AnyPS5. Originally posted by TheSovietWaffle on 2026-10-20T07:40:12Z.
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, head3bcacf596:agc_driver_depth_fast_clear_submitpasses 3 of 3 on both GPUs.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T20:33:32Z.
Review: CHANGES_REQUESTED
htileAfterMaskClear(DepthSurface.cpp:1435-1439) returns "cleared" without checking the ZMask bits of the mask: without stencil it never checksclear->mask & 0x3f0, and with stencil and a stencil value of 0 it returns before checkingmask & 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 ofmaskto be 0 andvalueto 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.perflabel needs theaps5-summary.jsonlline ofmainand of the change from the same title, scene and machine, plustools/trace_digest.pyoutput (bot comment above). The description says there is nomainsummary for the Yōtei scene; please capture both.NoteHtileDepthClearcall inDispatch.cpp, and the thread with MarcZX10 agreed to sequence #7233 first; list it under Depends on and rebase once it lands.Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-21T03:41:12Z.
Thanks for the careful read. I went through
htileAfterMaskClearagain, and I don't think a ZMask can survive there, because in this HTILE layout the ZMask is bits 3:0. That's the layoutHtileFillClearsand the expanded words on main use: a word clears the depth exactly whenword & 0xfis 0. The first check in the function returns no clear, for every branch, whenmask & 0xforvalue & 0xfis non-zero. So whenever we report a clear,(word & mask) | valuehas 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 (
MixedClearedSliceClearson 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 inRecordedMaskClearClearsWithoutWait(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
RecordedMaskKeepingZMaskReadsBacktoagc_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 themask & 0xfcheck 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
htileClearCompletionfrom the buffer branch, with a test next to MarcZX10'sDriverDispatchcase), and I'll change the field then. The main-vs-branch summary pair and thetrace_digest.pyoutput are still owed.The branch is also rebased onto current main (dd0cb9849).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T16:03:44Z.
Review: CHANGES_REQUESTED
Re-checked 18e8a7618 against the earlier review:
htileAfterMaskClearreturns no clear whenmask & 0xforvalue & 0xfis non-zero (DepthSurface.cpp:1685), and ZMask is bits 3:0, so the0x3f0bits are not ZMask.RecordedMaskKeepingZMaskReadsBacknow pins the read-back case.htileClearCompletionplus the PM4agc_driver_native_depth_buffer_cleartest look right.perfPR. Please paste theaps5-summary.jsonlline ofmainand of the change from the same title, scene and machine, and thetools/trace_digest.pysummaries of both (attach the traces). The Yōtei numbers from your own tree don't replace amaincapture; if the Yōtei scene can't be run onmain, a synthetic depth-clear scene run on both works.Nothing else to change.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T17:41:11Z.
Review: COMMENTED
On the NVIDIA failure of
agc_driver_native_depth_buffer_clearthat @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 currentmain. 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). Head18e8a7618d,mained1e0ed08f.agc_driver_native_depth_buffer_clear3a2ca40dabmained1e0ed08fcompute 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 (26c20975ac, 28/10). It addedRequireNoResidentDepthRead_nid_no_patchover every writable buffer range inGuestBufferMemory::UploadFinish. #6498 (341cf8beee, 30/10) then addedRequireNoMultisampleTarget(..., "a shader buffer access")inShaderResources::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
NoteHtileDepthClearalready accepted that dispatch as the clear transition (clearPending). The global-store kernel does not go through a descriptor buffer, soDriverDispatchis 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, andCompleteHtileDepthClearstill checks for racing CPU writes.diff on top of the merge
With it, on the merge with
ed1e0ed08f:^agcsuite (without display/flip/lds64) 1129/1129 on lavapipe.mainalone is 1128/1128; the extra test is the new one.a GPU buffer write over the depth or HTILE released the unwritten surface, D16/D32 x 4/8 samples) and #6498'sagc_driver_sample_multisample_targetstill pass.The test also prints
skipped native HTILE write-coverage assertionon 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
htileClearCompletiondown 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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T03:49:04Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new process-wide HTILE-mask registry can mistake an unrelated write for a prior mask clear after a
Recorderis recreated and its local write-note counter restarts.What I ran
Reviewed head
c8051ed3bab05296a22f49141a0553cefa10d837against PR basede824c2919ca65086c6324a1e0388866a7327eea; the no-build merge preview against currentmainwas clean. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++/GPU tests.Results
main.Selected unedited precheck output
Negative control
Findings
Blocking
HtileMaskWritestores only the clear range/pattern andRecorder::PendingWritesOver's numeric note.htileAfterMaskClearaccepts a record when its note equalsRecorder::NewestWriteNoteand the ranges cover. The write-note counter is perRecorderand 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;ClearDepthSurfacesdoes 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.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-31T03:50:42Z.
Review: CHANGES_REQUESTED
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, andhtileAfterMaskClear(DepthSurface.cpp:1886) accepts a record whenwrite.note == newestand the ranges cover. The note isRecorder::writeNoteCount, a per-instance counter that starts at 0 (Recorder.cpp:3000), whilehtileMasks()is process-static andClearDepthSurfaces(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.htileAfterMaskClear, and erase the owner's records inClearDepthSurfacesfor that device.ThreadHookWaitsincreases). 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.