Repository navigation
Conversation
… image When a lookup finds a cached image with fewer subresources than the request, FindImageImpl frees it and creates the requested image from guest memory. A GPU-written image whose writes were not written back loses them there: the new image holds the older guest bytes. Expand a GPU-written image with as many levels as the request instead, as ResolveOverlap already does for a same-format request with more subresources: the new image is loaded from guest memory and the cached image is copied into its first layers. With equal level counts a layer starts at the same guest offset in both images, so the copy by index keeps each layer in place. Other images are freed as before.
|
The regression checks the byte pattern in the four old layers and the guest contents in the two new ones. There is still a new failure path for images that have both GPU writes and a subsequent CPU invalidation. |
A GPU-written image that a guest write invalidated keeps its GPU-modified flag, so the fewer-resources branch of FindImageImpl also expands it. ExpandImage refreshes the source first, and RefreshCopySource stops the process when the refresh cannot clear the CPU-dirty state: InitializeImage returns early for a multisampled image, and RefreshImage stops for a compressed one. Expand only single-sample uncompressed images, for which the refresh clears the CPU-dirty state; free the others as before, including clean multisampled and compressed ones. The new check covers a GPU-written image invalidated before the larger request: with one sample the expanded image holds the newer guest bytes in the old layers; with four samples the lookup returns an image with the requested layers instead of stopping in RefreshCopySource. The test device now enables shaderStorageImageMultisample when supported and otherwise limits storageImageSampleCounts to one sample, as VulkanCreateDevice does, so the multisampled images the check creates are valid under the validation layer.
|
Confirmed on
The shim test device now enables Tests (AMD Radeon RX 9070 XT, RADV GFX1201, Mesa 26.2.6, Linux): the 110 tests that 007 water smoke (one run, the #98 setup, a build of this commit plus a test-only counter line that is not part of the PR): the water is drawn, with the same detector value as this PR's earlier smoke runs, 28.62 FPS (28.61 and 28.93 there), no error exits. After 9,000 GC ticks the counter shows 2 images expanded by the new condition in AI-assisted: yes (Claude Code) |
What
TextureCache::FindImageImplfrees the cached image it found when that image's subresources compare below the request's (resources <) and creates the requested image from guest memory.FreeImagedoes not write a GPU-written image back, so what the GPU wrote to it since its last write-back is lost: the new image holds the older guest bytes.IsGpuModified()) found there with as many levels as the request, that is with fewer layers, is now expanded withExpandImage, asResolveOverlapalready does for a same-format request with more subresources: the new image is loaded from guest memory, the old image is copied into its first layers and then freed. Other images are freed as before.IsGpuModified()stays set after a write-back byDownloadImageMemory, so an image already written back is expanded too.kyty_shim_image_write_back_aliasgets a check: a GPU-written image of 1 level and 4 layers, then a request at the same address for 6 layers in another format, once R32Uint → R8G8B8A8Unorm and once B8G8R8A8Unorm → R8G8B8A8Unorm with one guest format,k8_8_8_8UNorm(B8G8R8A8Unorm is the host formatResolveHostFormatpicks for a render target of it withChannelOrder::kAlt). The first 4 layers must keep the written bytes, the other 2 must hold the guest memory, and the image must stay GPU-written. A third case requests 2 levels and 6 layers; that image must be loaded from guest memory alone. Without the fix the check fails with "a request for more layers dropped the GPU-written layers".A request reaches this branch with a format other than the cached image's when
ResolveOverlapreturns the cached image at the same address because the two formats are view-compatible (ImageViewOps::FormatsCompatible: the same compatibility class, for uncompressed color formats the texel block size). In series R and the run on the stack below, every expansion had a pixel format different from the request's. For such pairsTextureCache::CopyImagecopies withvkCmdCopyImage(the backing formats have the same block size), so the bits stay as they are, as in a view of the old image in the new format.Image::CopyImagecopies level by level and layer by layer by index; with equal level counts (this PR's condition) and the same pitch, height, block size, tile mode and type (that path ofResolveOverlap), a layer starts at the same guest offset in both images.In 007 this is one way the water goes missing (#98). With diagnostic switches that make the missing water likely, the water was missing in 2 of 2 runs without the change and present in 4 of 4 with it (series W2 in Tested; one-sided Fisher p = 1/210 = 0.005 against the 6 runs without it under the same forcing: the 2 of series W2 and the 4 of series W). In those runs without the change, the branch freed 4 GPU-written 129×129 R32Uint layered images in the logged window, 3 of them in the frame before the area opens; with the change it expanded them.
Known limits:
ResolveOverlap's expansions, the old image is refreshed first (RefreshCopySource). A CPU-dirty old image that is multisampled or uses video-out compression stops withEXITthere, where the base freed it. Not seen in 007.ResolveOverlapfrees an idle image at the requested address with the same block extent and block size when the tile mode differs, or the mip layout at equal subresources, and an idle overlapping image that starts at or below the requested address, is not a level or layer of the request and holds the request as none of its levels or layers; the texture GC frees GPU-written images it cannot download (SafeToDownload()false).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 and the setup described in #98.This PR is based on
7de61e3451. Its condition was narrowed in review: an earlier version expanded every GPU-written image found in the branch, whatever its level count, and with different level counts its copy by index put the old image in the wrong place (levels are stored smallest first). Series R and W below ran that earlier version; the other runs use this PR's condition. Builds and settings:7de61e3451+ fix(kyty): keep in-use device-address pinned buffers in the memory GC #278 + fix(kyty): apply a metadata clear issued before its depth target exists #289 + perf(kyty): allocate device memory in 64 MiB VMA blocks #290 (the stack of the kyty: 007 First Light hangs the GPU on RADV at 40398cf776 (gfx ring timeout, mode1 reset, ErrorDeviceLost) #98 runs), with the change behind an environment switch (not part of this PR) and a counter line every 10 s for this branch. NoKYTY_*set other than the switch. Series R, and one run with this PR's condition.7de61e3451+ fix(kyty): keep in-use device-address pinned buffers in the memory GC #278 + the code of fix(kyty): apply a metadata clear issued before its depth target exists #289 and perf(kyty): allocate device memory in 64 MiB VMA blocks #290 + diagnostic logging and switches, not part of this PR). Set in every run: the diagnostic logging (KYTY_DIAG_P1_LOGwith its draw-group lookups,KYTY_DIAG_VRAM_LOG), the texture GC's pressure threshold at 12,500 MiB (KYTY_DIAG_GC_PRESSURE_MIB) and a switch that lets the texture GC free up to 40 idle images per tick instead of 10 without memory pressure, from early in the area load until the area opens (KYTY_DIAG_GC_EARLY_FLUSH=1). In the runs with the change alsoKYTY_DIAG_EXPAND_FEWER_V2=1, this PR's condition (series W2), orKYTY_DIAG_EXPAND_FEWER=1, the earlier version (series W). The build's other diagnostic switches are unset.7de61e3451alone, noKYTY_*set.This PR changes no file that #278 or #290 change. #289 changes the same two files in other places;
git merge-treemerges the two without conflict.Water is judged from 60 s of video recorded from 150 s after the title starts: the mean luma of the water region over the gameplay frames, missing below 22 (here 3.4-15.3 when missing, 23.8-30.0 when present). On the diagnostic build a run also needs the per-frame rate of the water's draw group in the diagnostic log below 0.35 to count as missing. The rules of every series were fixed before its runs.
Series W2, this PR's condition on the diagnostic build, in the order without / with / with / without / with / with, 300 s per run. Rule: the forcing is reproduced if at least 1 of the 2 runs without the change is dry; the change prevents it if none of the 4 with it is dry. Planned test: Fisher's exact test, one-sided, of the runs with the change against all runs without it under this forcing on this build line today (these 2 and the 4 of series W).
Series W, the earlier version on the diagnostic build, in the order without / with / with / without / with / with / without / with / with / without, 300 s per run. Rule: the forcing is reproduced if at least 2 of the 4 runs without the change are dry; the change prevents it if none of the 6 with it is dry.
Series R, the earlier version on the stack, in the order without / with / with / without / with / without / without / with, 340 s per run, no forcing. FPS is the median of the window-title FPS over 200-300 s. Character band (the one-frame black band of #289) and one-frame black squares are counted per 10 s of gameplay by the frame-difference detector used in #98, over the 30-34 s of gameplay after the area has loaded. VRAM and GTT are the card's (sysfs, every process), peak over the span of the counter lines. Rule: no regression if the median FPS with the change is at least 0.97 × the median without and its minimum at least 0.95 × the minimum without, and the medians of both counts with the change are at most the maximum without.
KYTY_ABcomparison; this PR makes no speed claim.This PR's condition on the stack, one run, 340 s, switch on; the counter line also counts the GPU-written images the condition declines. Rule fixed before the run: if the condition declines no image, series R applies to this PR as it is. It declined 8,546 GPU-written images (another level count) and expanded 2 (61,440,000 bytes by guest size, a different format from the request), so series R does not carry over as measured; this PR changes far less than the earlier version did. In that run the water was present and the FPS was 42.41 (series R without the change: 41.66-44.64).
This PR's commit on
7de61e3451alone, two runs of 300 s: water present in both (29.5, 30.0), 28.41 and 29.72 FPS. The earlier version on7de61e3451alone, two runs: water present in both, 28.61 and 28.93 FPS.The regression rule of series R was not run for this PR's condition; the readings for it above are single runs.
Tests (RADV GFX1201):
agc_kyty_shaders,guest_gpu_fault,guest_host_write_filter) gives the same result per test on7de61e3451and on this PR: 107 passed,kyty_shim_rt_corpusskipped,kyty_shim_wave64_cross_laneandkyty_shim_wave_split_written_readsfail here on both. On this PRkyty_shim_image_write_back_aliaspasses with the new check.7de61e3451fails with "a request for more layers dropped the GPU-written layers"; every other test gives the same result as on7de61e3451. With the earlier version of the change it fails with "an image with fewer levels was copied into the request's layers".kyty_shim_image_write_back_aliasalso passes on7de61e3451and on this PR withVK_LAYER_KHRONOS_validation1.4.363,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_LOADER_DEBUG=layer(the layer loaded, per the loader log; no validation messages on either).tools/check_conventions.py --base 7de61e3451andtools/check_kyty_settings.pypass.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