Repository navigation
Conversation
|
A write-only compute output at address A can leave a pending clear even when the dispatch wrote ordinary data. A later CPU, DMA or compute write at A leaves that record intact. If a depth target then binds with HTile at A within the next GC tick, |
|
Pushed Confirmed on An intermediate version recorded a clear only in
Further cases apply records through
This covers your last point only from Limits that remain:
Tests (AMD Radeon RX 9070 XT, RADV GFX1201, Mesa 26.2.6, Linux):
007, in the setup of series B in this PR's Tested section (on
The description above still describes AI-assisted: yes (Claude Code) |
|
Thanks for narrowing this to uniform fills and checking coverage per slice. One case from the earlier review is still open. When DispatchDirect records a GPU fill over a registered range, ApplyPendingMetaClears trusts that record without checking the backing. A later host store that bypasses the write hooks can leave the record live and cause the bind to discard valid depth. Could you make that path detect an intervening overwrite or conservatively decline the clear when freshness cannot be established? Please include the replay test you proposed in this PR. Dispatch a handwritten uniform fill over a registered range, bind a two-layer depth target, and check which layers clear. Repeat with a host overwrite before the bind and verify that the affected layer keeps its depth. Please rebase onto current AnyKyty and rerun the focused tests. The alias test passed on lavapipe but was skipped in the Windows job, so a Windows Vulkan result would also help. |
|
Windows Vulkan result for
Against the requested changes, as I read the diff:
The rest of the shim set on the same build
AI-assisted: yes |
A compute dispatch that clears HTile metadata is taken as a clear only when the metadata entry already exists. When the guest clears the HTile of a depth target that is created afterwards, for example a depth replacement of a color image at the same memory, which gets no initial clear, the clear is lost and the first bind keeps the copied color content. Remember such writes for the current and the next GC tick, and start the entry cleared when a depth target inserts it at that address with a size the clear would have covered.
The pending metadata clear recorded every write-only output of a compute dispatch that found no metadata entry, so an ordinary output at a later HTile address marked every slice of the new entry cleared. Later writes to the range did not cancel the record, and a record of one layer's size cleared every layer. Record a clear only for a uniform buffer fill whose value has ZMask (bits 3:0) 0, the cleared depth state in both HTile layouts, and that overlaps no live metadata entry. A stencil-compressed target also needs SMem (bits 9:8) at 0, since its bind clears stencil too. BufferCache::FillBuffer records the fills it performs: uniform compute buffer fills that TryConsumeComputeFill consumes, and CP DMA fills. A uniform buffer fill that TryConsumeComputeFill resolves but does not consume because an image is registered over its range runs on the GPU; DispatchDirect records it once the dispatch is recorded, after the dispatch's own buffer bindings. TextureCache::InvalidateMemory, InvalidateMemoryFromGPU, NoteMetadataWrite, CommitGpuWrite, CopyToImage and UnmapMemory drop the records that overlap their range: CPU-side and GPU-side buffer writes, emulator writes, written buffer bindings, readbacks through ForgetColorMetadataChecks, image writes (render targets, depth targets, storage images, clears and copies) and unmaps. At the insertion the entry starts cleared only in the slices a record covers fully, and for a fill done in memory only where the slice's backing still holds the fill value. The records have their own annotated mutex, and an address range and a 64 KiB granule bitmap, rebuilt at each GC tick, that the hooks test before taking it. The check now goes from FillBuffer to FindDepthTarget on a two-layer D16 target: whole and one-slice clears, a fill that does not clear, a fill on the GPU path, overwrites by a DMA fill, a DMA copy, a written buffer binding and a host store, the GC age and an unmap. Further cases apply records through TextureCacheTestAccess: a record noted without a fill in memory, one cancelled by an image write, fills that overlap a live entry (starting before it and inside it), and stencil-compressed metadata with SMem 0 and SMem 1.
A pending metadata clear for a fill that runs on the GPU (a fill that TryConsumeComputeFill refuses because an image is registered over its range, or a FillBuffer fill on its GPU path) has no backing to check at the bind, so only the write hooks cancel it, and a guest store reaches them only through a write fault. That fault came from the buffer cache's state. It makes the pages such a fill wrote inaccessible while they are GPU-dirty, and a depth target's HTile is 32 KiB-aligned with slices of whole 32 KiB units, so a store into a slice that the record would clear faults and drops the record. But the buffer cache keeps in-place memory (KYTY_COMMAND_MEMORY_IN_PLACE=1) out of its dirty state, a hot page (KYTY_HOT_PAGE_WRITE_WATCH=1) stays writable once it is no longer GPU-dirty, and the record relied on that state lasting until the bind. A store the hooks miss leaves the record live, and the bind then discards the depth the store wrote. The texture cache now holds one page write watcher on every 4 KiB page that such a record covers, from the fill until the last record on the page is applied, dropped, replaced, aged out by the GC or unmapped. Records do not overlap, so only a record's first and last pages are counted. A guest store to the range through the mapping the record was made for then faults whatever the buffer cache's state, unless the page is hot, into TextureCache::InvalidateMemory, which drops the records of fills on the GPU on every page it touches: the fault reports one byte, and the faulting store, like a host write that TryPrepareHostWrite prepares, has to get through. Records of fills done in memory are still dropped only over the written range. FindDepthTarget collects hot-page writes over the metadata range before the insertion. A fill on that path outside the guest address ranges is not recorded. CheckFilledMetaClearReachesBind checks that such a record holds a page watcher until it is applied, also after it is replaced, and none for a fill done in memory; that two records, and 300 records, more than the page manager's 8-bit watcher count, hold one page until they are gone; that a record over three pages protects all three and keeps its last page protected while another record on it is live; that a write fault elsewhere on its page through RenderContext::HandleFault, an invalidation elsewhere on the page, the GC age, an unmap and a written binding drop it and release the page; and that two fills in memory of the two layers on one page still clear both layers. kyty_shim_depth_meta_fill replays handwritten agc_frame_replay captures: a compute image store registers an image over the HTile range of a two-layer depth target, a handwritten uniform buffer fill (buffer_store_format_x) then fills that range on the GPU path, and the depth target, recreated over a one-layer target without HTile, is drawn per layer with a LESS depth test against stored depth below the clear value. A fill with ZMask 0 over both layers clears both, over the first layer only the first, and a fill with ZMask 15 none. A host store into the second layer's HTile between the fill and the bind, applied by the replay as a memory delta, drops the record, so both layers keep their depth. No fill over a registered range is consumed in memory, and a fill over an unregistered range is, which shows that check can fail. tools/lavapipe_skip.txt leaves the test out of the lavapipe job, with the device requirement it gives for kyty_shim_depth_target_alias.
dcc33e7 to
ecb8aa6
Compare
|
Pushed Detect or decline. The third commit detects an intervening overwrite through the mapping the record was made for. The record holds its own page watcher, so such a store faults into the write hooks whatever the buffer cache's state. On a hot page the store does not fault, but Records of fills on the GPU. At the bind such a record has no backing to check, so only a write hook cancels it, and a guest store reaches the hooks only through a write fault or, on a hot page, a collect.
The third commit makes the protection the record's own, independent of the buffer cache's state. In 007 it keeps the band-event reduction, with FPS and CPU within the run-to-run spread (below). If you'd rather rely on the buffer cache's state, I'll drop the third commit.
Limits:
Tests that tell the two commits apart. On the first two commits rebased onto
These cases test the third commit's mechanism. They do not show a store that the previous head misses in 007. These new cases pass on both commits:
Replay test.
The results:
The replay test passes on both commits. It shows the path end to end: in these captures the fill leaves the pages GPU-dirty, so the store faults without the watcher. The unit cases above are what tell the two commits apart. The commit adds the test to Tests (AMD Radeon RX 9070 XT, RADV GFX1201, Mesa 26.2.6, Linux):
007 (the one-frame black band on the player character, Refs #98): band events per 10 s of gameplay, counted by the frame-difference detector of #98, in the setup of series B in the PR's Tested section (24-34 s of gameplay per run). Three builds on
Windows: @Celegans12, thanks for the Windows Vulkan run (RTX 3080 Laptop, NVIDIA 621.14, validation layer on), where the alias test passed 3 of 3 with no VUID lines. It was on the previous head @simnJS, ready for another look. AI-assisted: yes (Claude Code) |
|
I re-ran the Windows check on
Here's how I read the new head against the open points:
AI-assisted: yes |
What
RenderExecutor::TryConsumeComputeMetaCleartakes a compute dispatch as a metadata clear only when every buffer it writes covers an entry ofm_surface_metas(TextureCache::CoversMeta). Entries are created inTextureCache::FindDepthTarget, at a bind that finds none at the target's metadata address. When the guest clears a depth target's HTile before that bind, no entry exists yet, the clear is executed as an ordinary write and nothing marks the entry cleared. At the bind, a new entry starts cleared only when the image hashtile_initial_clear.ResolveDepthOverlapclears that flag for the image it creates in place of an overlapping one, and copies the old image's contents into it where the copy is supported. A depth target created that way therefore keeps the copied contents although the guest cleared it.This PR remembers uniform fills whose value has ZMask 0 (bits 3:0, the cleared state of an HTile word) and that overlap no metadata entry, and applies them, per slice, when
FindDepthTargetinserts the entry:HTILE_Z_CLEAR_REGandHTILE_ZS_CLEAR_REGinsrc/amd/common/ac_descriptors.hwrite these fields the same way. A dispatch that is not a uniform fill records nothing.BufferCache::FillBufferrecords the fills it performs (uniform compute buffer fills thatTryConsumeComputeFillconsumes, and CP DMA fills). A uniform buffer fill thatTryConsumeComputeFillresolves but does not consume because an image is registered over its range runs on the GPU;DispatchDirectrecords it once the dispatch is recorded, after the dispatch's own bindings, since the dispatch's written binding of that range drops the records under it.KYTY_COMMAND_MEMORY_IN_PLACE=1, is kept out of it; a hot page,KYTY_HOT_PAGE_WRITE_WATCH=1, is writable once it is no longer GPU-dirty), so the texture cache holds one page write watcher on every 4 KiB page the record covers, from the fill until the last record on the page is applied, dropped, replaced, aged out or unmapped (records do not overlap, so only a record's first and last pages are counted). A guest store to the range then faults intoTextureCache::InvalidateMemorywhatever the buffer cache's state, unless the page is hot, and that call drops the records of fills on the GPU on every 4 KiB page it touches (the fault reports one byte, and the faulting store has to get through, as does a host write thatTryPrepareHostWriteprepares through the same call).FindDepthTargetcollects hot-page writes over the metadata range before the insertion. A fill on that path outside the guest address ranges is not recorded.TextureCache::InvalidateMemory,InvalidateMemoryFromGPU,NoteMetadataWrite,CommitGpuWrite,CopyToImageandUnmapMemorydrop every record that overlaps their range, whole (InvalidateMemorydrops the records of fills on the GPU on every 4 KiB page it touches): CPU-side and GPU-side buffer writes, emulator writes, written buffer bindings, readbacks throughForgetColorMetadataChecks, image writes throughCommitGpuWrite(render targets, depth targets, storage images, clears and copies, over the image's whole data range), DMA copies into an image throughCopyToImage(over the copied range) and unmaps.RunGarbageCollectordrops records older than one GC tick. The records have their own annotated mutex, and the hooks test an address range and a 64 KiB granule bitmap (rebuilt at each GC tick) before taking it.TryReadBacking) still holds the fill value, which also catches stores the caches do not see.kyty_shim_image_write_back_aliasgetsCheckFilledMetaClearReachesBind:FillBufferfollowed byFindDepthTargeton a two-layer D16 target, for a clear of both layers and of each layer alone, a fill that does not clear, a fill on the GPU path, overwrites before the bind by a DMA fill, a DMA copy, a written buffer binding and a host store, the GC age and an unmap; and, throughTextureCacheTestAccess, a record noted without a fill in memory, a GPU write to an image over the range before the bind, fills that overlap a metadata entry (starting before it and inside it), and stencil-compressed metadata with SMem 0 and SMem 1; and the page watcher of a record of a fill on the GPU: held until the apply, also after a replacement, by two records and by 300 (more than the page manager's 8-bit watcher count) on one page until they are gone, on all three pages of a record over three pages and on its last page while another record there is live, none for a fill done in memory; released and the record dropped by a write fault elsewhere on its page throughRenderContext::HandleFault, an invalidation elsewhere on the page, the GC age, an unmap and a written binding; and two fills in memory of the two layers on one page still clearing both.kyty_shim_depth_meta_fillreplays handwrittenagc_frame_replaycaptures: a compute image store registers an R8 image over the HTile range of a two-layer Z32 depth target, a uniform buffer fill (buffer_store_format_xattid + 64 * group, value from user data) fills that range, whichTryConsumeComputeFillrefuses as registered so that it runs on the GPU andDispatchDirectrecords it, and the target, recreated over a one-layer target without HTile, is drawn per layer with a LESS test against stored depth below the clear value. A fill with ZMask 0 over both layers clears both, over the first layer only the first, with ZMask 15 none, and a host store into the second layer's HTile between the fill and the bind (a memory delta of the replay) drops the record, so both layers keep their depth. The test passes on the previous commit too: the fill leaves the pages GPU-dirty, so the store faults without the record's watcher.tools/lavapipe_skip.txtleaves the test out of the lavapipe job, like the other replay tests. The replay child logs consumed fills (KYTY_PRINTF_DIRECTION=Console): none of the fills over a registered range is consumed, and a fill over an unregistered range is, which shows that this check can fail.In 007, the one-frame black band on the player character (Refs #98), events per 10 s of gameplay (see Tested): on the AnyKyty tip
dcdde0a389, 3 runs each, 11.86 without this PR (9.82-13.42), 0.30 with its first two commits (0.00-0.91) and 0.21 with all three (0.00-0.62). The first version's series on7de61e3451gave 10.0-15.2 without it and 2.7-4.9 with it; on top of #278, 10.6-13.1 against 0.3-1.9, 4 runs each. The title clears the HTile of its 1024×1024 D16 depth targets (shadow maps) with a compute fill before binding them. 2.8-2.9 of the 5.1-5.2 entries inserted per frame for those targets belong to a D16 image created as a replacement of a 1024×1024 R16Unorm image at the same memory, and started from the copied R16 contents. 512×512 D16 targets of the same kind (1.6-1.7 per frame) start cleared with the first version as well. In one run of an intermediate version that recorded only inFillBuffer, with diagnostic counters, 42,728 of the 42,817 records that the first version's rule would have applied at an insertion came from uniform buffer fills with ZMask 0 thatTryConsumeComputeFillrefused only because an image is registered over the range (the other 89 from fills it consumed), which is why this version also records those fills inDispatchDirect.Known limits that can start an entry cleared wrongly:
ResolveDepthOverlap.FillBufferfill that takes its GPU path) has no word check at the bind, since that fill need not have reached guest memory by then; only the hooks above cancel it. Its page watcher makes a guest store to the range fault into them, but a store through another mapping of the same memory does not fault, as for images: the record then still applies, and the bind discards the depth that store wrote. Such a store is neither detected nor declined. A hot page stays writable, and its writes reach the hooks only at a collect;FindDepthTargetcollects over the metadata range before the insertion.Known limits that can lose a clear:
DispatchDirecttriesTryConsumeComputeFill. Fills fromDispatchIndirectandDispatchIndirectThreadsare not recorded, and neither is a direct dispatch that has specialization reads (it skips both consume attempts), a fill thatTryConsumeComputeFillturns into an image clear (ClearImageFromBuffer: an image with exactly the fill's range), or one it refuses for any reason other than a registered range. Fills done byReplicateBufferare not recorded either. They run as before.TextureCache::InvalidateMemoryanywhere on a 4 KiB page that a record of a fill on the GPU covers (a guest store's fault, a host write, a completion write) drops that record. A readback of the range before the bind drops the record too.FindDepthTargetinserts the entry. A fill that overlaps an existing entry records nothing and is handled as before this PR: one that reachesClearMetaat the entry's address marks every slice of that entry cleared, any other (for example one that starts inside the entry, or oneTryConsumeComputeFillrefuses because an image is registered over it) marks nothing, and a later bind at that address finds the entry present and applies no record.Tested
007 First Light (PPSA11386), Linux (CachyOS, kernel 7.3.4), Ryzen 9 7950X3D, AMD Radeon RX 9070 XT (RADV GFX1201, Mesa 26.2.6). Release builds,
SDL_VIDEODRIVER=x11, scripted pad input, one save and route, shader caches warmed from one earlier run, the local 5-byte title patch described in #98.This PR on
dcdde0a389, the AnyKyty tip when the runs were planned, in the setup of series B below, events per 10 s of gameplay (the full rules are in the reply):dcdde0a389: 12.33, 13.42 and 9.82 (mean 11.86). B is the first two commits on it: 0.91, 0.00 and 0.00 (mean 0.30). S is all three, built from an earlier version of the third commit with the same runtime code (the pushed commit differs only in test files andtools/lavapipe_skip.txt): 0.62, 0.00 and 0.00 (mean 0.21). The rules were fixed before the runs: B's mean at most 0.7 × T's for the comparison to count (met), and S's mean at most B's plus 1.0 and at most 0.7 × T's, with no run at 9.0 or above (met).7de61e3451: the second version (dcc33e7251, the first two commits) against the first version, six runs on one day, 6.08, 4.03 and 2.81 (mean 4.31) against 3.82, 4.92 and 4.95 (mean 4.56), its rule met (reply).Tests (RADV GFX1201):
ctest -R '^(kyty_shim_.*|guest_gpu_fault|guest_host_write_filter|agc_kyty_shaders)$'selects 115 tests on the AnyKyty tip688dbf145dand 116 on this PR (the new replay test). They give the same result per test, the alias test included: all pass, exceptkyty_shim_rt_corpusandkyty_shim_wave_split_written_reads, which are skipped on both. The same holds for the third commit ondcdde0a389.kyty_shim_image_write_back_aliasandkyty_shim_depth_meta_fillpass withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1; the loader inserts the layer for each of the six test processes and noVUID-lines appear. They also pass on lavapipe here (Mesa 26.2.6, LLVM 23.1.4) in 2.8 s and 3.2 s; on RADV the replay test takes 0.4 s. This lavapipe also passes three tests thattools/lavapipe_skip.txtlists (kyty_shim_depth_target_alias,kyty_shim_buffer_null_range,kyty_shim_empty_buffer_replay); CI's lavapipe was not run here, and the new entry gives the same reason as theirs.ecb8aa6185(RTX 3080 Laptop, NVIDIA 621.14, validation layer on), comment:kyty_shim_image_write_back_aliasandkyty_shim_depth_meta_fill3 of 3 each, thekyty_shim_set 105 of 105 withkyty_shim_rt_corpusskipped, noVUID-lines.dcdde0a389with only the new test files added, every failing check printed, six cases fail (eight checks; the three-page case fails three): the page watcher held until the apply (also after a replacement), the drop by an invalidation and by a write fault elsewhere on the page, two and 300 records on one page, and the record over three pages.kyty_shim_depth_meta_fillpasses there too: the fill leaves the pages GPU-dirty, so the store faults without the record's own watcher.f19d97375a, with only the check's twelveFillBuffer/FindDepthTargetcases (the others call functions this PR adds), the check fails at its first case: "a fill that clears the HTile of both layers before the bind did not clear them".CommitGpuWriteandCopyToImagehooks and with the overlap test reduced to an entry at the fill's address, with every failing case printed, exactly three cases fail: the image write, the fill that overlaps a live entry and the fill inside one.TryConsumeComputeFill's call toFillBuffermakes (the replay's consumed case checks only that the fill is consumed), theCopyToImagehook (the DMA copy case copies into a buffer), the hot-page collect inFindDepthTarget, in-place memory (KYTY_COMMAND_MEMORY_IN_PLACE=1) and the release of the page watchers in the texture cache's destructor.tools/check_conventions.py --base 688dbf145dandtools/check_kyty_settings.pypass.git merge-treemerges the branch into the AnyKyty tip688dbf145dwithout conflicts.First version (
f19d97375a), measured before the change request; "the change" below is the first versionDiagnosis (done for the first version), with diagnostic logging (not part of this PR) on
7de61e3451plus #278 (2f755a3c46, the only other change on that line), 850 logged frames per run, of which 776-806 in gameplay:ResolveDepthOverlap(nohtile_initial_clear), each replacing a 1024×1024 R16Unorm image at the same memory when the D16 image was bound as a depth target. 1,267 and 1,401 insertions for 512×512 D16 targets started without a clear the same way.f19d97375a's change plus one log line, no switch; one run, 791 gameplay frames): all 2,323 such insertions for 1024×1024 targets (of 4,113) and all 1,337 for 512×512 targets started cleared; 3 band events, all in the head region, none on the body.The first version against the same build without it, in two series of 4 runs each, run in the order without / with / with / without, with / without / without / with, 300 s per run, Kyty's defaults with no
KYTY_*set. Series P: #278 (2f755a3c46, on7de61e3451), with the first version on top. Series B: the first version on7de61e3451. Band events per 10 s of gameplay, counted by the frame-difference detector used in #98 on 60 s of video recorded from 150 s after the game window opens, over the 30-34 s of gameplay after the area has loaded. The rule for each series was fixed before its runs: confirmed if every run with the change is below 2.0 and every run without at least 4.0; not confirmed if any run with the change is at 4.0 or above.7de61e3451Cost of the first version, means without / with on the same runs of series P and B, exact two-sided permutation test, 4 against 4 (p in parentheses). "Whole run" is the title's systemd scope or process from start to exit; "gameplay" starts when
GPUActivestays above 1.5 GB.GPUActive(/proc/meminfo), gameplay, GBamd-requested-vram(title's DRM fdinfo), gameplay, GBGameplay CPU is higher with the first version in both series: user by 0.130 CPU-s/s (3.4 %) and 0.093 (2.5 %), system by 0.075 (23 %) and 0.030 (9 %). In both measures and both series at least one run without the change is above a run with it; pooled over the two series (computed after the runs), p 0.082 for user and 0.131 for system.
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