Repository navigation
fix(agc): take depth fast clears from HTILE written by any kernel - #5627
Conversation
|
@AlxcBTW I agree with the composition contract you described: native-owned binds must reach the guarded owner before the generic HTILE read/store-back. If #5627 lands first, I will carry that routing and a regression in our native-depth stack; if our stack lands first, your stated follow-up here handles it. #5554 still depends on #5524/#5111, transitively #5496/#4820; it does not require the generic store-back implementation. Our refreshed dependency composition passes repeated native-depth tests on NVIDIA and AMD, but I have not tested it together with #5627 and make no combined-head compatibility claim. |
adriadam10
left a comment
There was a problem hiding this comment.
This no longer rebases onto current main, and the part that conflicts needs a decision from you:
- #5111 is merged, so its commit drops out. The next commit then conflicts in
DepthSurface.cpp,State.cpp,Dispatch.cppandtests/DepthSurfaceReuse.cpp, plus the debt entry. mainnow has the native multisampled depth owner (#5496).DepthSurfaceViewtakesGuestMemory::GpuMutex()beforesurfacesMutex(), andRequireNoResidentDepthRead_nid_no_patchthrows on a guest write over an owner's range (DepthSurface.cpponmain, around line 917).storeBackClearedHtilewrites expanded words over the HTILE of every depth target, so a bind of a native-owned target would hit that guard. Your description says whichever PR lands second carries the routing: that is this one now. Please route a native-owned bind to the owner's path before the read and store-back, with a test that binds one.- The read and store-back were placed outside the surfaces lock to wait on recorded work. With the new lock order, check that they still run before
GpuMutexis taken, or say why not.
After the rebase, rerun agc_driver_depth_htile_write, agc_driver_depth_fast_clear_submit, agc_driver_graphics and the native-depth tests. Happy to re-review then.
…e surfaces lock The bind-time HTILE read covered one word per 8x8 tile from DB_HTILE_DATA_BASE, but main models the HTILE as the pipe-aligned SW_64KB_Z_X metadata (HtileMetadataBytes, the extent HtileFillCovers takes): at 1920x1080, 1856 of the 32400 tile words lie past the first tiles*4 bytes, so they kept ZMask 0 after a store-back. The read and the store-back now cover the whole metadata and run before the surfaces mutex is taken, since both wait for recorded work over the range. The tests' HTILE arrays hold the whole metadata. PPSA25344 (Unreal Engine 5) decodes its depth through HTILE in its Nanite depth export after the depth prepass and takes ZMask 0 as a tile holding the clear value; the new agc_driver_depth_fast_clear_submit case checks that a draw after a fast clear leaves every word expanded.
…its words are uniform A fill or clear the driver recognizes over an HTILE drops the range's last-read generation, so the next bind reads the words and stores them back even when the write tracker did not see the fill's stores. A depth view of slice 1 or later reads the HTILE at its own address (DB_HTILE_DATA_BASE + slice * HtileMetadataBytes); the HTILE word layout is only modelled for slice 0, so such a slice takes the clear and the store-back only when all its words are equal and keeps its fill-time fast clears otherwise. DepthTarget::slice carries DB_DEPTH_VIEW SLICE_START. agc_driver_depth_fast_clear_submit: an unrecognized kernel clears the HTILE on two frames in a row and both clears are taken; slice 1 with words that are not all equal is refused and stored back untouched; slice 1 with equal words takes the clear. agc_driver_graphics checks the decoded slice.
…ore-back A multisampled depth target is created as, or already is, the native depth owner, and a target whose HTILE overlaps a resident depth guard aliases one. Neither may have its HTILE read or rewritten by the generic store-back: the expanded words would be a guest write over the owner's range. DepthSurfaceView decides this before the store-back, which still runs before GpuMutex() and the surfaces mutex are taken. NativeMultisampleDepth binds the owner and a single-sample alias of its HTILE and checks the words stay untouched.
7f8db66 to
139e3b8
Compare
|
Thanks @adriadam10. The branch is rebased onto current
To rerun: |
|
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.
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.
|
adriadam10
left a comment
There was a problem hiding this comment.
Re-checked against the new head:
- Rebase is clean, #5111 is gone.
RoutesToNativeDepthOwnersends multisampled targets and any target whose HTILE overlaps a resident depth guard past the generic read and store-back.NativeMultisampleDepthfails if that routing is disabled.- The read and store-back still run before
GpuMutex(); the routing check only takes the shared guard mutex.
Ran agc_driver_graphics, agc_driver_depth_fast_clear, agc_driver_depth_fast_clear_submit, agc_driver_depth_htile_write, agc_driver_native_multisample_depth and agc_driver_native_depth_retirement on lavapipe: all pass. The new submit and htile_write cases fail without the change. Merging once the full Build is green.
|
Rebased again onto |
Main brings the pipelined-draw stack (boykopovar#1193/boykopovar#1201/boykopovar#1202), boykopovar#6316 after boykopovar#6060, boykopovar#5893, boykopovar#5910 and depth/HTILE work (boykopovar#454, boykopovar#5496, boykopovar#5554, boykopovar#5524, boykopovar#5627, 626cff7). Our SharedSpirv / cold-SPIR-V storage is replaced by main's mapped cache entries (CreateFileMappingW on Windows), so cached variants' words are views into the cache files instead of heap copies; APS5_COLD_SPIRV, APS5_COLD_SPIRV_FILE and APS5_CACHE_SPIRV_BACKING are gone. Kept local: lane hang fixes, boykopovar#5815, boykopovar#6227, table stores and storage tables, option 1 substitutes (.slots), stencil remap and alias path (a written storage view our alias path serves seeds from the depth surface instead of retiring it), 10_11_11 blending next to main's reversed-order blending, VRAM share/spill/fallbacks, diagnostics. Versions: FormatVersion 43, RuntimeAbi 17, request serializer v31. Notes in work/sync-20261013/*-4.md. AI-assisted: yes
What
Supersedes #2053, as @oneandonlydean asked there. @esatturan's commit is kept with his authorship, rebased onto current
main, with three commits of ours on top: two answer the review on #2053 and one routes native-owned depth binds around the generic path (the review on this PR).#2053 reads a depth target's HTILE at bind when it was written since it was last read. If every word marks the depth (ZMask 0) or the stencil (SMem 0) cleared, the surface takes the pending fast clear and the words are stored back as expanded. That covers clears made by kernels the fill hooks do not recognize (PPSA29141's
InvokeHTileClearComputeShader), and the store-back also matters for titles that read their HTILE after drawing (Sword of the Sea, below).Commits, bottom to top:
fix(agc): take depth fast clears from HTILE written by any kernelis @esatturan's fix(agc): take depth fast clears from HTILE written by any kernel #2053 commit, rebased: the store-back fitsmain'sDepthSurfaceView, the debt entry moved todocs/dev/debt/libSceAgcDriver.md, a duplicateGuestMemory.hppinclude is gone, andagc_driver_depth_htile_writecounts its tiles itself becausemain's harness has noHtileBytes.fix(agc): read and store back the whole pipe-aligned HTILE outside the surfaces lockfix(agc): take a slice of a depth array from its own HTILE only when its words are uniformfix(agc): route native-owned depth binds before the HTILE read and store-backWhat changed against #2053:
Whole metadata. The read covered
tiles * 4bytes fromDB_HTILE_DATA_BASE.mainmodels the HTILE as the pipe-aligned SW_64KB_Z_X metadata (HtileMetadataBytes, the extentHtileFillCoverstakes). With the HTILE equation of Sword of the Sea's Nanite export shader, 1856 of the 32400 tile words of a 1920x1080 surface lie past the firsttiles * 4bytes and would keep ZMask 0 after a store-back. The read and the store-back now cover the whole metadata. Both wait for recorded work over the range, so they run beforeDepthSurfaceViewtakes the surfaces mutex.GPU-written HTILE, two frames in a row (@oneandonlydean's and @adriadam10's request, PPSA01802). A fill or clear the driver recognizes over an HTILE drops the range's last-read generation, so the next bind reads and stores back again even when the write tracker did not see the stores. A bind also reads the words whenever the recorder has a pending write over the HTILE.
agc_driver_depth_fast_clear_submitgets a case where an unrecognized kernel (the fill kernel behind ans_nop, so no matcher takes it) clears the HTILE on two consecutive frames and both clears are taken.Slices of a depth array (@XairRrR's data). Since fix(agc): give each slice of a depth array its own HTILE #5111 a slice's HTILE is at
DB_HTILE_DATA_BASE + slice × HtileMetadataBytes(extent). The HTILE word layout is only modelled for slice 0: XairRrR's fit on PPSA05684 shows slices 1 to 3 need extra Z terms (X8 and Y8 also take Z0 and Z1) that noGFX10_HTILE_SW_PATTERNentry has. So a slice of 1 or more takes the clear and the store-back only when all its HTILE words are equal, which decodes the same under any layout (PPSA05684's boat level binds slices 4 and 5 of arrays whose HTILE is a uniform0xfffffff0). Otherwise it is refused and its words are left alone.DepthTarget::firstSlicecarriesDB_DEPTH_VIEWSLICE_START.Tests. @esatturan's
agc_driver_depth_htile_writeis kept; its HTILE arrays now hold the whole metadata. New inagc_driver_depth_fast_clear_submit:0xfffc000f/0xfffff3ff); this fails onmain, where the words stay 0;agc_driver_graphicschecks the decoded slice.The debt entry "HTILE written by other kernels" records what is still open: the slice layout above, and per-tile clear values of a depth-only HTILE (ZMask 0 everywhere but different Min/Max Z, as in PPSA05684's cascades), which are still taken as a whole-surface clear to
DB_DEPTH_CLEAR.Not in this PR: the store-back is a CPU write after the bind-time read. Recording it as a GPU fill in stream order, as @XairRrR does locally, would also remove the wait on pending HTILE writes.
Composition with #5496, #5524 and #5554. #5496 and #5524 are on
main: the native multisampled depth owner guards its depth and HTILE ranges, andDepthSurfaceViewtakesGuestMemory::GpuMutex()before the surfaces mutex. The expanded store-back is a guest write over an owner's HTILE, which the owner refuses, so commit 4 decides before the store-back whether the bind belongs to the owner (@adriadam10's request, and the routing @Amoenus and I agreed on here):DepthSurfaceViewcallsRoutesToNativeDepthOwnerfirst and skips the HTILE read and store-back when it is true. It is true for every multisampled target (it is the native owner or is about to be created as one, and the owner's import validates the HTILE as the guest left it) and for any target whose HTILE overlaps a resident depth guard (a single-sample alias of an owner's metadata). Those binds go on to the existing owner and creation path with its own refusals. Single-sample targets that do not alias an owner are unchanged. This replaces thesamples != 1early return in the store-back.GpuMutex()is taken, because the read waits for recorded work; the routing check takes only the shared depth guard mutex with no other lock held.NativeMultisampleDepthbinds a native-owned target twice and a single-sample alias of its HTILE, with HTILE words of 0, and checks the words are untouched and the alias is refused by the owner path.#5554 builds on #5524 and does not need the generic store-back.
Evidence: Sword of the Sea (PPSA25344, Unreal Engine 5)
The title needs the store-back for a different reason than the clear detection: it reads its HTILE after drawing.
MatchMemoryValueFill), so the clear itself is already taken onmain. The guest HTILE then keeps ZMask 0 for the whole frame, because our depth draws never update it.Tested
ci/lab/htile2053, based onmain5a81f6085, run 38497597289): Linux (lavapipe, GCC) 1092 of 1092 tests pass, includingagc_driver_graphicsand everyagc_driver_depth_*test; Windows (WinLibs GCC 15.2) builds and 1112 of 1112 pass, theagc_driver_depth_*execution tests skipped for lack of a Vulkan device. Not rerun on this head (rebased ontomainfdea36b83, with the routing commit); a new fork CI run will be linked here.agc_driver_depth_*execution tests passed on the earlier rebase of this stack (fix/htile-store-back-rebase, without the slice commit, on themainof 2026-10-13; driver not recorded). Not rerun on this head.main. The menu gate (no dark pixels, top luma 88 at frame 585) passed on 2026-10-12 on our lab buildsots/menu-boot-m1(21d699737), which has no store-back. That run is not evidence for this PR.main(57f96fd2), the levels rendered correctly (my comment on fix(agc): take depth fast clears from HTILE written by any kernel #2053). Not rerun on this head.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)