Skip to content

kyty: texture cache recreates and re-uploads aliased full-screen images (007 First Light, cutscene 1) #32

Open

Description

@XatiX

Summary

In 007 First Light (PPSA11386), the first in-game cutscene runs at 1 to 3 FPS on the Kyty backend; the menus run at 35 to 45. The scene is GPU-bound on texture uploads: about 330 to 360 MB per frame.

The texture cache keeps deleting and recreating the scene's full-screen images. The game places these images of different formats at overlapping offsets in one memory area. Each recreated image is uploaded in full (32 to 63 MB) from guest memory.

Found while testing past #31: the cutscene's first draw stops on a merged hull shader, and these numbers come from a local build that drops those draws.

Measurements

Three runs in the scene, 15 s each. Counters from Common::DebugCounters, per frame:

per frame
Frames per second 1.6 to 3
TextureUploadBytes 330 to 360 MB
BufferUploadBytes 5 to 14 MB
GpuWaitNs 200 to 600 ms
Draws / Dispatches 260 to 2400 / 310 to 420
GpuFaults 160 to 270
  • kytyGpuExecute spends about half its samples in win32u.dll (the GPU fence wait).
  • No CPU thread is close to full.
  • nvidia-smi shows the GPU 70 to 80 % busy.

What the texture cache does

I logged every InsertImage of 3840x2160 or larger during one run in the scene (temporary print, not in any branch).

  • 4733 images inserted, at only 868 distinct addresses.
  • The same address, size and format was created again many times:
    • k16_16_16_16Float, 63 MB: 1636 times
    • k8_8_8_8UNorm, 32 MB: 1670 times
    • k11_11_10Float, 32 MB: 450 times
  • Almost every insert overlaps an image inserted before it, usually at a different offset rather than the same start (old format -> new format, count):
71 -> 56   offset     1471
56 -> 71   offset     1418
71 -> 71   offset      486
36 -> 71   offset      306
56 -> 36   offset      306
36 -> 56   offset      202
56 -> 56   offset      164
56 -> 71   same start  120

So the game reuses one area (around 0x4267000000 to 0x4277000000) for several render targets and compute outputs at overlapping offsets, and changes which one occupies a range within a frame. That is the usual console pattern for transient resources.

Kyty replaces the overlapping image. The next draw or dispatch that uses the replaced one creates it again. InitializeImage (textureCache.cpp:1633) then uploads it from guest memory, because a new image is buffer-modified and CPU-dirty (textureCache.cpp:1643).

A summary of the uploads per 5 s window showed 1000 to 2000 images, almost all of these 32 and 63 MB images with write_count == 0.

Likely side effect

The picture in the scene is nearly black. Guest memory doesn't contain what the GPU last rendered into that range (that is only in the replaced host image), so a recreated image starts from stale guest data. This is an inference; I have not verified it.

Possible directions

Not tried:

  • No upload when the GPU wrote last: when a new image's range was last written by the GPU into an image that is being replaced, don't upload from guest memory. Either treat the contents as undefined, as a transient alias would be on hardware, or copy or reinterpret from the replaced host image when the layouts are compatible.
  • Extend the discarded-target skip: WasDiscardedTarget already skips the upload for render targets whose contents were discarded. The images thrashing here were, in a partial log, mostly requested as storage images (BindingType::Storage), which that skip doesn't cover. That needs confirming.
  • Keep host images per format for an aliased range: rather than deleting them on every overlap, keep them and track which one is current, to avoid the reallocation as well as the upload.

Happy to prototype one of these and measure it on this scene if you have a preference.

Environment

Windows 11, NVIDIA GeForce RTX 5080 (driver 617.42), WinLibs GCC 15.2.0, LLVM 21.1.8, AnyKyty at fe0d5b42b4 plus the guard page commit from #22 and a local drop of merged-hull tessellation draws (#31). Not checked on Linux; nothing here is Windows-specific.

AI-assisted: yes.

🤖 Generated with Claude Code

Activity

  1. simnJS commented on Nov 18, 2026

    @simnJS
    Owner

    Great find, and the black picture fits: the replaced host image held the only up-to-date contents. Please go ahead. My preference, in order:

    1. Carry the contents across on the GPU instead of uploading from guest memory. When a new image's range overlaps an image that the GPU wrote last, initialize the new one from that host image (buffer copy / reinterpretation of the overlapping bytes) and skip the upload. That fixes the stale picture and removes most of the ~340 MB per frame. I'd rather not treat the contents as undefined: some titles do read across aliases.
    2. Then keep the host images per format for an aliased range and track which one is current, so a format switch stops costing an allocation too. Combined with 1, a switch becomes a GPU copy of only what was written.
    3. The WasDiscardedTarget extension to storage images is fine as a cheap extra, but it won't cover the aliased compute outputs.

    Behind a switch (on by default, 0 restores today's path), with TextureUploadBytes, fps and a screenshot of the 007 cutscene before and after, plus a check that title A and Subnautica are unchanged. Since 007's cutscene needs #31 first, a local drop of those draws is fine for measuring, just keep it out of the PR.

  2. Scramblrrrr commented on Nov 19, 2026

    @Scramblrrrr

    Our Windows/NVIDIA test setup is now ready on bf195d2. #77 adds Windows coverage for the merged-hull fixture: all 15 Kyty shim tests pass, with merged and split each covering 1082/4096 pixels on RTX 5070 Ti / 617.42 and zero Vulkan validation errors against the baseline.

    I am keeping the alias implementation separate from that test-port work. If there is a public WIP branch for the GPU overlap/content-transfer fix, I can cross-test its build and native fixtures on Windows. Actual 007 cutscene/image checks on this setup remain pending visual access; I will not call idle presentation counts gameplay FPS or use skipped tessellation draws as a rendering fix.

    AI-assisted: yes.

  3. simnJS commented on Nov 19, 2026

    @simnJS
    Owner

    Thanks @Scramblrrrr, and nice work on the Windows coverage in #77. There's no WIP branch for the alias fix on our side: nobody here is working on it right now. If you or anyone wants to take it, it's open, and we'll review it. The issue text has the root cause and the numbers to check against: per-frame uploads of 330-360 MB going down, and the cutscene FPS.

  4. SleglJan commented on Nov 19, 2026

    @SleglJan
    Contributor

    I'm working on this one; XatiX handed it over to me. The change carries the contents across on the GPU, as you suggested. The GPU-written images under the new one are written back into a device-local buffer, and the new image is uploaded from it, or copied directly when the layouts match. Anything it can't order safely falls back to today's upload, and KYTY_ALIAS_CARRY=0 turns it off. It covers DCC/CMASK colour images and depth sources and passes its own tests on lavapipe. It hasn't run in the cutscene yet: the title hangs the GPU here soon after (#98), and each hang has taken the desktop down, so the in-scene numbers are pending. I'll open the PR once I have them; a Windows cross-test then would be welcome.

    AI-assisted: yes (Claude Code)

  5. SleglJan commented on Nov 19, 2026

    @SleglJan
    Contributor

    First in-scene numbers for the GPU carry (local branch on f394e91, one binary, KYTY_ALIAS_CARRY=0 vs 1, warm caches, one run each, 007 First Light cutscene 1 over flips 5000–5599, RX 9070 XT / RADV, Mesa 26.2.6): it barely fires in the scene, so no PR yet. What stops it, in case it helps the write-back work on #30:

    • Carry off: 1.26 FPS, texture uploads about 348 MB per frame. Carry on: 1.20 FPS, about 350 MB per frame; it carried 69 images (25 MB) over those 600 flips. It does fire before the cutscene (984 carries in the menus and loads).
    • Over those flips it was refused 47,276 times; 42,039 of them (89 %, and 99 % of those that reached its plan) are buffer_newer: a logged buffer write over the source is newer than the source's last write.
    • In a 15-minute run with a breakdown, the cutscene part had 56,632 such vetoes: 52,189 from writable storage-buffer bindings that overlap the source image, 4,375 from colour-metadata (DCC/CMASK) clears, and 68 where the diagnostic found no logged write.
    • A bind with the write flag makes ObtainBuffer mark the whole binding GPU-dirty (descriptors.cpp:162-164 passes the full range and the shader-level write flag), whether or not the shader writes those bytes. The carry's own log, which only takes writes over pages that hold images, recorded about 480k such binds in that cutscene part.
    • So by today's rule the carry has to yield: those ranges are GPU-dirty in the buffer cache, and today's upload of the new image reads them through ObtainBufferForImage. Finer tracking of what a storage binding really writes is what would let the carry through.

    The carry passes its own tests (30 on lavapipe, each of 31 deliberate breakages caught, validation layer clean). I'll keep it local unless you see a use for it as is.

    AI-assisted: yes (Claude Code)

  6. simnJS commented on Nov 20, 2026

    @simnJS
    Owner

    Status at AnyKyty de0fa04: there is no fix on the head yet, and no branch that moves the numbers.

    The root cause above stands. @SleglJan's GPU carry (local, KYTY_ALIAS_CARRY) passes its tests but carried 69 images (25 MB) over 600 flips of the cutscene, and 89 % of its refusals are buffer_newer: a logged buffer write over the source image is newer than the source's last write. Almost all of them (52,189 of 56,632 in the longer run) come from writable storage-buffer bindings that overlap the image. On the head, a binding with the write flag marks its whole range GPU-dirty in the buffer cache (ObtainBuffer with resource.written, in descriptors.cpp), whether or not the shader writes those bytes, and InvalidateMemoryFromGPU only retires images that start at the written address.

    So the next step is not more carry code: it is tracking what a writable storage binding really writes. It is the same defect as R3 in #108, and until it is fixed the cutscene stays at 1-3 FPS. 65a1b01db4 (compare-and-write) covers readbacks into guest memory and does not change this.

    Open to anyone; comment here first so two people do not do the same work.

  7. SleglJan commented on Nov 20, 2026

    @SleglJan
    Contributor

    On the 1-3 FPS in the status: on RADV, cutscene 1 ran at 28.7 to 29.7 FPS on 82039de925, two commits before de0fa047bb. I haven't run de0fa047bb or later.

    On 82039de925 the title's draws no longer reach the table-resolution path (counters on #99). #109 (5b1fe32f94: sampled-float bindless texture tables through the image heap, on by default) landed between the two builds and would fit. I haven't bisected it or run cutscene 1 with it off. In gameplay from our save on 82039de925, KYTY_IMAGE_TABLE_HEAP=0 ran at about 4 FPS instead of about 28 (one run each, on #98).

    I haven't measured the texture-upload volume on 82039de925, and the carry isn't rebased onto it. So I can't say whether the per-frame re-uploads from this issue are gone, or still there and no longer the limit. The flip window 5000-5599 from my earlier comment doesn't compare on this build either: flip 5000 now comes on the licence screen of the first launch, and cutscene 1 starts near flip 11,600.

    Setup: Linux, RX 9070 XT, RADV (Mesa 26.2.6), kernel 7.3.4, the local title patch from #98.

    AI-assisted: yes (Claude Code)

  8. simnJS commented on Nov 20, 2026

    @simnJS
    Owner

    Thanks @SleglJan, 4.0 → 29.6 fps on cutscene 1 is a big jump (×7), and #109 (texture tables through the image heap, 5b1fe32f94) landing in between fits. That's also why your counters on #99 show no table resolutions any more. When you next run that cutscene on the current head, one look at the texture upload volume would tell us whether this issue's per-frame re-uploads are gone (then we close it) or just no longer the limit (then it stays open, lower priority).

  9. added
    perf
    on Nov 22, 2026
  10. changed the title [-]kyty: texture cache recreates and re-uploads aliased full-screen images every frame (007 cutscene at 1-3 FPS)[/-] [+]kyty: texture cache recreates and re-uploads aliased full-screen images (007 First Light, cutscene 1)[/+] on Nov 22, 2026
  11. added
    area: gpu-memory
    needs: game
    needs: measurement
    on Nov 22, 2026
  12. simnJS commented on Nov 22, 2026

    @simnJS
    Owner

    Status at AnyKyty a4b4360d66: no change aimed at this issue has landed. Since the image heap serves bindless texture tables (5b1fe32f94), cutscene 1 runs at about 29 FPS on RADV instead of 1 to 3, so the title now says what is measured rather than the old frame rate.

    What decides this issue is one number on the current head: the texture upload volume per frame in cutscene 1 (the TextureUploadBytes counter of the first report). If the per-frame re-uploads are gone, we close it; if they are still there but no longer the limit, it stays open at a lower priority.

  13. simnJS commented on Nov 26, 2026

    @simnJS
    Owner

    @SleglJan, when you next run cutscene 1 on the current AnyKyty, one number decides this issue: TextureUploadBytes per frame in the cutscene. Your #290 (64 MiB VMA blocks) landed since, so it is also the first check of memory use on RADV with it. If the per-frame re-uploads are gone, we close this; if they are still there but no longer the limit, it stays open at a lower priority.

  14. added
    medium
    on Nov 26, 2026
  15. SleglJan commented on Nov 26, 2026

    @SleglJan
    Contributor

    Measured on e68fe52755, which includes #290, plus a test-only line that prints the Common::DebugCounters totals at every 30th call of AgcDriverPresentBuffer_nid_postfix, one call per flip of a guest display buffer. The current tip 9ceedb5409 adds one commit on top, which rejects invalid image LOD and compute exports in the shader translator. KYTY_PERF_OVERLAY=1 switches the counters on; the overlay itself is not built.

    Setup: Linux 7.3.4, RX 9070 XT, RADV GFX1201 (Mesa 26.2.6), the local title patch from #98. Two runs by the new-game route, the first with empty caches and the second with the first run's caches. Both stopped at their 660 s cap at cutscene 2's L prompt, without an error exit and without an amdgpu fault, timeout or reset in the kernel log.

    The cutscene-1 window lies between the first and last letterboxed screenshots the screen log kept: one row every 5 to 6 s, and a shot is kept when its OCR text changes. That gives 79 s and 73 s; the counted intervals cover 76 s and 73 s. The window can miss the cutscene's first and last seconds, so its frame rate does not compare directly with the 29.6 FPS I gave on 82039de925 (106 s, from the cutscene's first row to the frame-rate spike at its end).

    Cutscene-1 window, per frame, from 30-frame intervals:

    run 1 (empty caches) run 2 (warm caches)
    Frames per second 38.1 42.1
    TextureUploadBytes, mean 320 MiB 323 MiB
    TextureUploadBytes, median (min to max) 334 MiB (57 to 380) 327 MiB (174 to 377)
    BufferUploadBytes, mean 6.7 MiB 7.9 MiB
    TextureEvictions 1.4 1.3
    GpuWaitNs 20.5 ms 22.7 ms
    GpuFaults 269 350
    Draws / Dispatches 1579 / 493 1482 / 496

    The texture upload means are 335 and 339 MB per frame. The first report gave 330 to 360 MB at 1.6 to 3 FPS, on Windows with an RTX 5080, on fe0d5b42b4 plus #22 and a local drop of the merged-hull draws. In the menus before the campaign (offline dialog, main menu and difficulty selection; 60 s ending at about the start press), the same counter reads 390 and 245 MiB per frame at 59.94 FPS.

    What the counter covers:

    • TextureUploadBytes adds linear.size in TextureCache::UploadImage and the partial layer upload (UploadImageLayers). Some other buffer-to-image copies, such as CopyToImage and the stencil copies, are not counted.
    • For uploads from an image's guest range (InitializeImage and the partial layer upload), the source is what BufferCache::ObtainBufferForImage returns: a buffer-cache buffer, or a staging copy of guest memory when no cached buffer covers the range and the range is not GPU-modified.
    • ApplyPartialBufferCopy also counts a re-upload of an image from a device-local scratch copy.
    • Tiled images go through a compute detile pass.

    So the counter does not say how much of it crosses PCIe. It also does not separate uploads into recreated images from other uploads; I did not log InsertImage as the first report did.

    Memory, same runs (VRAM and GTT from amdgpu mem_info_vram_used and mem_info_gtt_used, 1 Hz, device-wide; 0.6 to 1.0 GiB VRAM before the launch). The harness launches the title twice; the second launch is the measured one.

    • VRAM after launch: jumps from 5.9 and 5.0 GiB to 14.1 and 14.3 GiB between two samples, 14 to 16 s after the second launch and before the first notice screen. It is above 15 GiB 1 to 2 s later.
    • VRAM through the load: falls to 6 to 8 GiB during the load after difficulty selection and is back above 15 GiB as the campaign starts.
    • VRAM in the window: 14.2 to 15.9 and 14.1 to 15.8 GiB of 15.9 GiB (median 14.7 and 15.1).
    • GTT: goes above 1 GiB as the campaign starts, 28 s and 13 s before the cutscene-1 window, and peaks there at 1.7 and 2.6 GiB. In the window it reads 0.7 to 1.4 and 0.7 to 1.2 GiB (median 1.2 and 0.7).
    • System memory: the title's cgroup peaks at 14.5 and 14.9 GiB (memory.peak, page cache included), reached after the cutscene-1 window. In the window memory.current is at most 13.4 and 13.9 GiB. Swap is off for that cgroup.
    • Baseline: both runs include perf(kyty): allocate device memory in 64 MiB VMA blocks #290; I have no run without it to compare these figures with.

    AI-assisted: yes (Claude Code)

  16. simnJS commented on Nov 26, 2026

    @simnJS
    Owner

    Thanks @SleglJan, that answers it. The per-frame re-uploads are still there (about 330 MiB per frame through the cutscene), but they are no longer the limit: 38 to 42 FPS on RADV now, against 29.6 before. As agreed, this stays open at a lower priority.

    Two things from your numbers that we will follow:

    • VRAM sits at 14 to 15.9 GiB of 15.9 during the cutscene. A device memory cap based on the driver's real heap usage is in review on our side; it already holds a 16 GB card steady on another title. It will land on AnyKyty once its review points are fixed, and your setup would be a good check for it (gpu-memory: check the device memory cap on AMD with and without Resizable BAR, on iGPUs and on 8 GB cards #306).
    • To tell recreated images from plain re-uploads, the next useful number is the InsertImage count per frame in the same window, as in the first report. Only if you have time.
  17. SleglJan commented on Nov 26, 2026

    @SleglJan
    Contributor

    InsertImage counts in cutscene 1, by the same window rule, from one more run set up like run 2 (warm caches, same commit e68fe52755). The test-only line now also counts calls of TextureCache::InsertImage. A re-insert is an insert whose (data.address, data.size, guest_format) was already inserted earlier in the same process; in the 1280x720 row, already inserted at 1280x720 or larger. The counter does not tell whether the earlier image was freed in between.

    Per frame in the window Inserts Of which re-inserts
    All images 73.9 49.0
    extent 1280x720 or larger 41.7 28.1
    extent 3840x2160 or larger 3.2 1.8
    • Window: 62 s between the shots; the counted intervals cover 61.5 s, 2,670 frames, 43.4 FPS. In this run the screen log kept no shot of the cutscene's first subtitle lines. Going by the subtitle in its first shot, the window starts about 11 s later in the cutscene than in runs 1 and 2, and it ends at the same point.
    • Distinct keys: they grow from 61,988 to 128,478 over the window for all extents, and from 32,737 to 69,188 at 1280x720 or larger. 24.9 inserts per frame (66,490 in the window) are of keys not inserted before.
    • Upload volume: TextureUploadBytes in the window is 325 MiB per frame (mean; median 328 MiB). Runs 1 and 2 gave 320 and 323 MiB.
    • Menus: 0.02 inserts per frame in the 60 s of menus before the start press, while TextureUploadBytes there reads 126 MiB per frame (runs 1 and 2: 390 and 245).

    For comparison, the first report logged 4,733 inserts of 3840x2160 or larger during one run in the scene, at 868 distinct addresses. Its counter runs were 15 s each, at 1.6 to 3 FPS. The same filter here gives 8,496 inserts in the window. These counts key on address, size and format together, not on the address alone; I have no distinct count for that row.

    AI-assisted: yes (Claude Code)

  18. simnJS commented on Nov 26, 2026

    @simnJS
    Owner

    Thanks, this is very useful. Two thirds of the inserts in the window (49.0 of 73.9 per frame) are re-inserts of a key that already existed earlier in the process, so most of the ~325 MiB per frame is the same images being dropped and created again, not new data.

    One thing would tell us where to look: what dropped those images before they were re-inserted. If the same counter line can also count, per frame, the images removed by the GC (eviction under memory pressure) and the images invalidated because guest memory under them was written, the split will show whether this is a cache-size and eviction problem (#306) or a write-tracking problem (an overlapping write invalidating images that did not actually change).

  19. SleglJan commented on Nov 26, 2026

    @SleglJan
    Contributor

    From one more run set up like runs 2 and 3 (warm caches, e68fe52755). In the cutscene-1 window, 62.7 of the 64.4 FreeImage calls per frame come from overlap resolution and 1.08 from the GC. Neither InvalidateLocked nor InvalidateMemoryFromGPU frees an image in this tree. The counters still do not pair a re-insert with the removal of its key's earlier image. The test-only line now also counts:

    • every FreeImage and ParkImage call site in TextureCache;
    • three outcomes of InvalidateLocked: whole-image CPU-dirty, partially dirty and maybe-dirty (not its first- and last-page untracks);
    • the bytes InitializeImage uploads, split by the image's state.

    The window, by the same rule: 63 s between the shots; the counted intervals cover 62.6 s, 2,730 frames, 43.6 FPS. Going by the subtitles in its first and last shots, it starts and ends within a shot of run 3's window.

    Removals in the window:

    Site Per frame
    FreeImage, all calls 64.4
    ResolveOverlap, its last case (see below) 62.7
    RunGarbageCollector (eviction) 1.08
    FindImageImpl, cached image has fewer resources than requested 0.47
    Other frees: ExpandImage 0.11, stencil associations 0.07, the other two ResolveOverlap cases 0.05, ResolveDepthOverlap 0.01; BcAlias and UnmapMemory none 0.24
    ResolveDepthOverlap, parked instead of freed (not a FreeImage call) 9.4
    DiscardParkedImage (not a FreeImage call) 6.1
    • The last case of ResolveOverlap: a requested image overlaps a cached one. They are not at the same address with the same block extent and block size, and neither is a mip of the other. The requested image starts at or after the cached one, and the cached image is safe_to_delete: not a bound depth target, no table pins or heap references, and not accessed for more than NumFramesBeforeRemoval (16) GC ticks.
    • Cross-checks: the frees by site add up exactly to the FreeImage calls. GC evictions equal TextureEvictions (1.08 per frame).
    • Guest writes: in this tree InvalidateLocked never frees an image. It marks it CPU-dirty, partially dirty or maybe-dirty, or stops tracking its first or last page (not counted). In the whole window there were 5 whole-image CPU-dirty marks, no partial ones, and 5.4 maybe-dirty marks per frame.

    Uploads: TextureUploadBytes is 310 MiB per frame in this window (run 3: 325), all of it uploaded inside InitializeImage:

    • 159.5 MiB into the first fill of an image whose key was inserted before;
    • 116.4 MiB into the first fill of an image with a new key;
    • 34.5 MiB into later fills of existing images.

    Inserts in the window: 70.7 per frame, 46.9 of them re-inserts (run 3: 73.9 and 49.0).

    AI-assisted: yes (Claude Code)

  20. simnJS commented on Nov 26, 2026

    @simnJS
    Owner

    This settles where the churn comes from, thanks: 62.7 of 64.4 frees per frame are the last case of ResolveOverlap, and guest writes free nothing. So the title reuses the same memory for images of different shapes every frame, and each switch frees the cached image and builds the requested one again from guest memory (159.5 MiB per frame of first fills of re-inserted keys).

    Two fixes are possible, and one more split decides between them. For the images created by that case, how many of the bytes uploaded in InitializeImage are for an image whose first GPU use writes it (a render target, a depth target, a storage image or a clear) rather than reads it (sampled, or a copy source)?

    • If most are written first, the upload is wasted: the image should not be filled from guest memory until something reads it before writing it.
    • If most are read first, the freed image should be parked like in ResolveDepthOverlap, and brought back when its key is requested again, as long as nothing (CPU or GPU) wrote its range in between.

    Would you like to take it once the split is known? It fits your counters, and a PR that moves TextureUploadBytes in this window would be easy to judge.

  21. SleglJan commented on Nov 26, 2026

    @SleglJan
    Contributor

    The split, from one more run set up like runs 2 to 4 (warm caches, e68fe52755). The test-only line now records, for every upload in InitializeImage, the innermost tagged use on the call stack. Most first fills happen lazily, through RefreshImage, at the first use that finds the image CPU-dirty, so that use is the image's first use. The exceptions: ClearImage and MaterializeColorClear call InitializeImage directly (see Limit), and ExpandImage fills its new image right after the insert (no use tag, so under Other). An image whose first use uploaded nothing (a full clear, or a target skipped by WasDiscardedTarget) has its first counted fill at a later use. Window by the same rule: 69 s between the shots; the counted intervals cover 68.6 s, 2,970 frames, 43.3 FPS.

    First fills per frame, by the use that triggered them:

    Use Inserts after an overlap free Other first fills
    Storage image (FindTexture, storage binding) 53.8 MiB 136.5 MiB
    Clear (ClearImage, MaterializeColorClear, ClearImageFromBuffer) 13.4 MiB 18.4 MiB
    Render target 12.1 MiB 7.4 MiB
    Depth target 6.0 MiB 4.7 MiB
    Sampled (FindTexture, texture binding) 2.9 MiB 2.0 MiB
    Other (image heap rebind, no tagged use) 0.0 MiB 2.3 MiB
    Total 88.2 MiB 171.3 MiB
    • By use: the uses tagged as writes (storage, clear, render target, depth target, copy destination) take 96.7 % of the bytes in the first column and 97.5 % in the second. Without the clear row they take 81.5 % and 86.8 %. Sampling takes 3.3 % and 1.2 %. No first fill came from a copy, as source or destination.
    • First column: inserts that came after ResolveOverlap's last case freed an image earlier in the same FindImageImpl call. The flag only links an insert to a free in the same request, so it does not cover every image created by that case, and it does not prove that each flagged image replaced the freed one. A stencil plane inserted when a depth target is bound or cleared takes the flag of the thread's last FindImageImpl call.
    • Later fills: fills of images after their first fill are 41.2 MiB per frame, 30.1 MiB of them at storage binds.
    • Cross-checks: the first and later fills add up exactly to TextureUploadBytes, 300.7 MiB per frame (run 4: 310), so no upload in the window came from outside InitializeImage. The frees are 62.2 per frame, 60.2 of them from ResolveOverlap's last case (run 4: 64.4 and 62.7). Inserts are 68.7 per frame, 43.1 of them re-inserts (run 4: 70.7 and 46.9).
    • Limit: this splits by binding type.
      • A clear triggers a fill only when it leaves part of the image to the guest data. ClearImage calls InitializeImage only when the clear does not cover every mip, layer and aspect; a full clear uploads nothing. MaterializeColorClear fills during the lookup, before per-slice clears that the GPU runs only if its metadata check passes.
      • A storage, render-target or depth-target bind can still read the old contents (a shader that reads its storage image, blending, a depth test or a load of the previous contents), or write only part of the image (one mip level, part of the area).
      • The counters show neither, so a use tagged as a write here does not mean the contents are overwritten before any read.

    Yes, I'd like to take the fix. Because of that limit, I'll first check which of these first uses read the old contents before deciding between skipping the fill and parking.

    AI-assisted: yes (Claude Code)

  22. SleglJan commented on Nov 27, 2026

    @SleglJan
    Contributor

    Two more measurements on the storage first fills, which are 205 of the 281 MiB of first fills per frame in the cutscene-1 window. Both runs were made on e68fe52755 with test-only counters, set up like runs 2 to 5 (warm caches).

    1. What the shader does with the image, and what the upload brings (run 6, a window by the same rule; the counted intervals cover 71.1 s and 3,180 frames):

    • Writes without reading: 99.7 % of the storage first-fill bytes come from binds whose shader writes the image and neither reads it nor uses atomics (ImageResource written and not read or atomic, set around FindTexture in the descriptor image loop). The read flag is an upper bound on real reads.
    • The upload source: for 100 % of those bytes, the image is flagged IsBufferModified() when InitializeImage starts, meaning the buffer cache holds GPU-written bytes in its range.
    • Same-range re-inserts: over all uses, re-inserts over a freed or parked image with exactly the same range are 6.0 MiB per frame (3.5 MiB of it storage). First fills after an overlap free are 96.9 MiB per frame. That counts only the newest free or park within 4 GC ticks, in a ring of 1,024. CPU writes after the free and DeleteImage removals without FreeImage are not seen.

    So skipping these fills is only safe if what they bring in is overwritten before anything reads it.

    2. What the first dispatch changes (run 7, a second test-only build, the whole run rather than only the window):

    • Method: for 1 in 16 of these fills, the build downloads the image twice through Kyty's own DownloadImage, each time into its own zeroed buffer:

      • right after the fill;
      • right after the dispatch call whose storage bind triggered the fill.

      It then compares the two, element by element (bytes_per_block bytes each, all levels and layers).

    • Control: for 1 in 32 samples, it took two downloads back to back. All 1,392 pairs matched exactly. This shows only that the downloads are stable; there is no positive control showing that a known full overwrite reads as fully changed.

    • Coverage of the sample:

      • All 731,114 eligible fills were inside compute dispatches.
      • 18,038 (2.5 %) were left out: images over 32 MiB, depth images, or images that can't be downloaded.
      • 88 were skipped while 4 samples were in flight.
      • 44,544 were compared and none dropped.
    • Results:

      • 5.2 % of the sampled bytes were in images where every element changed.
      • Per sample: 6.5 % changed fully, 6.1 % 99 % or more but not all, 35.5 % 90-99 %, 18.3 % 50-90 %, 17.3 % some but under half, 16.3 % none. So 93.5 % of samples had elements unchanged after that dispatch, counting padding and same-value writes.
      • Over all elements: 72.0 % changed, 25.5 % unchanged and zero in both copies, 2.5 % unchanged and nonzero.
      • None of the multi-level images (12.5 % of samples) changed fully.
    • Limits:

      • An element written with the value it already held counts as unchanged.
      • Padding that the retile leaves untouched stays zero in both copies, so it counts as unchanged and zero.
      • Only that one dispatch is compared; a later writer may fill the rest before anything reads it.
      • The sampling slows the run (23,100 flips, against 36,630 in run 6), so it isn't a timing run.

    So this data doesn't support a plain skip for write-only storage first uses. Render-target, depth, clear, sampled and other first fills (76 MiB per frame) aren't covered here.

    AI-assisted: yes (Claude Code)

  23. github-actions commented on Nov 27, 2026

    @github-actions

    Thanks, this rules out using a write-only storage binding as the sole condition for skipping the initial upload. The readbacks measure changed values, not write coverage, so they don’t establish whether the remaining contents are overwritten before a later read.

    For a narrow first prototype, can you measure how many first-fill bytes are triggered by clears that provably overwrite every aspect, mip level, and layer the upload would initialize? That would give us a safe case to test without changing storage-image behavior.

  24. SleglJan commented on Nov 27, 2026

    @SleglJan
    Contributor

    None, in this run. All clear-triggered first fills come from MaterializeColorClear. Each slice's clear of one level runs only if a GPU check finds that slice uniformly fast-cleared, so it is never provably full when the upload is recorded.

    This is from run 8, one more run on e68fe52755 with a test-only counter, set up like runs 6 and 7 (whole run, 36,570 flips).

    • Where clear-tagged first fills can come from:
      • ClearImage: it calls InitializeImage only when the clear is not full_image (all aspects, all levels, all layers), so a full clear already skips the upload. For a stencil clear that doesn't cover all subresources, it also refreshes the stencil plane. That site isn't classed here; it filled nothing in this run.
      • ClearImageFromBuffer: it calls ClearImage with one aspect: all levels and layers for colour or depth, the stencil subresources for stencil.
      • MaterializeColorClear: it calls InitializeImage and records a GPU check, per slice and clear key, of whether the slice's metadata is uniformly fast-cleared. It then clears that level's area of each slice under conditional rendering.
    • The counter: it tags each InitializeImage these paths call directly with its path and coverage and counts first-fill bytes, by the same rule as the earlier splits. The tagged bytes matched the counter's total for clear-use first fills exactly.
    • Results:
      • First fills: 187.9 MiB per frame. Clear use: 28.9 MiB per frame, 15.4 %.
      • All 28.9 MiB came from MaterializeColorClear (4.79 fills per frame).
      • ClearImage, called directly or from ClearImageFromBuffer, triggered no first fill.
    • So the case you asked about, a clear that provably covers every aspect, level and layer the upload would write, is 0 bytes here; that case already skips the upload in ClearImage. The clear-use first fills that remain are MaterializeColorClear's upload before its GPU-predicated clear.
    • Limits:
      • This counts only first fills, so ClearImage calls that found the image clean, or that skipped the upload, are not in it.
      • "The aspect the upload writes" is read from the code: depth for depth images, colour otherwise.
      • Coverage is per subresource; a clear covers a subresource's whole extent.
      • The figure is for the whole run, not only the cutscene-1 window. There, run 6 had 35.1 MiB per frame of clear-use first fills.

    AI-assisted: yes (Claude Code)

  25. github-actions commented on Nov 27, 2026

    @github-actions

    Thanks, that rules out the full-clear prototype: ClearImage already skips the upload for unconditional full clears, and MaterializeColorClear has to preserve contents when its GPU predicate is false. There’s no need to rerun that split just for the cutscene window.

    If you want to keep investigating, the next useful number is how many first-fill bytes could be avoided by reusing a parked image with the same cache key and no intervening CPU or GPU write to its range. A counter-only estimate would tell us whether parking is worth prototyping without changing upload behavior.

  26. SleglJan commented on Nov 27, 2026

    @SleglJan
    Contributor

    At most about zero. For 81 % of the first-fill bytes whose key had an earlier image in the counter's table, a GPU write to an overlapping range was committed after that image left. The other 19 % was already out of date when the image left (IsCpuDirty or IsBufferModified).

    These are from run 9, one more run on e68fe52755 with a test-only counter, set up like runs 6 to 8 (whole run, 35,550 flips).

    • The counter:
      • It remembers the last 2,048 images that left the cache through ParkImage or FreeImage, if they were registered and non-empty. Entries are updated on discard and unpark.
      • For each first fill, it looks for one with the same key: the fields SameParkedLayout compares.
      • It puts the range in the first class that applies, in this order:
        1. the image was already out of date when it left (IsCpuDirty or IsBufferModified);
        2. a CPU write was seen (InvalidateMemory, map and unmap events);
        3. a GPU write was committed for an overlapping image (CommitGpuWrite, which runs at write binds, clears and copies), or came from the copy hand-overs or InvalidateMemoryFromGPU;
        4. the buffer cache holds GPU data in the range at the fill;
        5. none of these.
      • Its totals matched the earlier counter's first-fill totals exactly.
    • Results, MiB per frame:
      • first fills: 261.6;
      • same key, still parked: 0;
      • same key, parked then discarded: 2.9 (all in the GPU-write class);
      • same key, freed: 194.1. Of that, 37.8 was out of date when it left, 0 had a CPU write, 156.2 a GPU write, 0.04 had buffer-cache GPU data, and 0.04 none of these;
      • no same-key entry in the table: 64.6.
    • So: reuse with no CPU or GPU write in between would save at most 0 MiB per frame from parked images and 0.04 from freed ones (0.0 % of first fills). This fits simnJS's reading (09:39:33Z) that the title reuses the same memory for images of different shapes.
    • About parking as it stands: ParkImage and UnparkImage are called only from ResolveDepthOverlap. The other removals, including ResolveOverlap's last case, go through FreeImage. An unparked image is refilled by CopyImage when the sample counts match, so parking today saves creating the image, not the fill.
    • Limits:
      • Only the "none of these" class bounds reuse, and it is an upper bound: CPU writes to pages nobody watches are not seen, and emulator write-backs of GPU results count as CPU writes.
      • The table holds the last 2,048 departures; 1.73 million entries were overwritten. So the bound covers the 197 MiB per frame that had an entry. Most of the GPU-write bytes (143 of 156 MiB per frame) came back 5 to 64 GC ticks after the image left.
      • Shader writes through buffers are seen only as buffer-cache state at the fill.
      • This run counted 261.6 MiB per frame of first fills over the whole run, against 187.9 in run 8 with the same setup (and 259.2 for run 6's whole run). I haven't explained that difference.

    AI-assisted: yes (Claude Code)

  27. github-actions commented on Nov 27, 2026

    @github-actions

    Thanks. For the 197 MiB/frame matched by the counter, at most 0.04 MiB/frame could reuse cached contents unchanged. The bounded history leaves the unmatched fills unresolved, but the measured savings don’t justify a parking prototype to reduce uploads. Reusing allocations would be a separate optimization; it wouldn’t eliminate the refill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: gpu-memorymediumneeds: gameneeds: measurementperf

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions