vk: keep finalized textures the GPU drew once (ground streaks after long play, #107, #386) #593

Merged
duck-paradise merged 1 commit from fix/keep-finalized-gpu-textures into main 2026-11-08 19:22:24 +00:00
duck-paradise commented 2026-11-08 13:38:01 +00:00 (Migrated from github.com)

Summary

After tens of minutes of play, the ground in Hyrule Field turns into streaks in square patches (one projection stretched along X or Z) and stays that way until a restart. This is the symptom in #107 (and the "tiled pattern over Hyrule Field's path" in #386).

Cause

OoT's terrain draws each chunk's 260 x 260 RG8 normal map (NVN 0xd, 9 levels) once. It finalizes the texture when the chunk goes out of range. When the chunk comes back, it makes a texture over the same storage and samples it without drawing it again. On the console the texels are still in that memory.

In Hookshot they only exist in the Vulkan image:

  1. About 60 frames after the finalize, the eviction destroys the image. Finalized textures get no write-back.
  2. The texture made again over that storage takes the "storage the GPU rendered, not written since" path.
  3. It is not uploaded, so it is sampled empty, and the terrain shading goes to streaks.

Trace with RX_VK_WATCH_DIM=260x260 and RX_VK_VRAM_MB=1500 (to evict sooner), walking away from a spot in Hyrule Field and back:

1437 made #350 0x1168973000 260x260 NVN 0xd
1437 written #350
2259 finalized #350
2320 evicted #350
2891 made #2667 0x1168973000
2891 sampled, over rendered storage #2667
2891 NOT uploaded (over storage the GPU rendered) #2667

That run had 6 such tiles.

Change (gpu/vk/vk_texture.cpp, eviction only)

A texture is kept instead of evicted when all of these hold:

  • the GPU drew it in one frame (first_written == last_written)

  • it is 4 MB or less

  • the game finalized it

  • its storage is still the range the GPU drew it in (gpu_owned)

  • no other image was drawn over it

  • Cap: up to RX_VK_KEEP_FINALIZED_MB, 512 by default. This counts within the texture budget, so it does not add VRAM. Beyond the cap, the least recently used go as before. 0 restores the old behaviour.

  • No write-back to guest memory: the game may have put other things there since, and a write-back over scene data crashed it before (the SceneLowPriority case).

  • Logs:

    • finalized textures the GPU drew once, kept for being made again every 600 frames, by size and format
    • kept finalized textures over N MB when the cap evicts one
    • ... finalized by the game, sampled again at frame N once per texture sampled more than 60 frames after it was drawn
  • Refactor: the existing "drawn over" check became a lambda so it can be shared. Its behaviour is unchanged.

Testing

  • Hardware: RX 9070 XT, Windows, AMD driver 26.10.1, on a local branch. The patch applies to main as is, but I could not build main here.
  • Repro run: same walk-away-and-back at RX_VK_VRAM_MB=1500. "NOT uploaded" went from 6 to 0. The same tile addresses (e.g. 0x1168973000, 0x11689a8000, 0x11699d5000) are now sampled again about 1000 frames after they were drawn, with their texels.
  • What gets kept: other finalized one-frame textures are kept too, for example small UI-sized targets and 640x360 targets. In a few minutes that was about 50-80 MB, of which the terrain tiles were about 1.4 MB. That is why there is a cap.
  • Not yet done: a long session at the default budget.

🤖 Generated with Claude Code

## Summary After tens of minutes of play, the ground in Hyrule Field turns into streaks in square patches (one projection stretched along X or Z) and stays that way until a restart. This is the symptom in #107 (and the "tiled pattern over Hyrule Field's path" in #386). ## Cause OoT's terrain draws each chunk's **260 x 260 RG8 normal map** (NVN 0xd, 9 levels) once. It finalizes the texture when the chunk goes out of range. When the chunk comes back, it makes a texture over the same storage and **samples it without drawing it again**. On the console the texels are still in that memory. In Hookshot they only exist in the Vulkan image: 1. About 60 frames after the finalize, the eviction destroys the image. Finalized textures get no write-back. 2. The texture made again over that storage takes the "storage the GPU rendered, not written since" path. 3. It is **not uploaded**, so it is sampled empty, and the terrain shading goes to streaks. Trace with `RX_VK_WATCH_DIM=260x260` and `RX_VK_VRAM_MB=1500` (to evict sooner), walking away from a spot in Hyrule Field and back: ``` 1437 made #350 0x1168973000 260x260 NVN 0xd 1437 written #350 2259 finalized #350 2320 evicted #350 2891 made #2667 0x1168973000 2891 sampled, over rendered storage #2667 2891 NOT uploaded (over storage the GPU rendered) #2667 ``` That run had 6 such tiles. ## Change (`gpu/vk/vk_texture.cpp`, eviction only) A texture is kept instead of evicted when all of these hold: - the GPU drew it in one frame (`first_written == last_written`) - it is 4 MB or less - the game finalized it - its storage is still the range the GPU drew it in (`gpu_owned`) - no other image was drawn over it - **Cap:** up to `RX_VK_KEEP_FINALIZED_MB`, 512 by default. This counts within the texture budget, so it does not add VRAM. Beyond the cap, the least recently used go as before. `0` restores the old behaviour. - **No write-back to guest memory:** the game may have put other things there since, and a write-back over scene data crashed it before (the SceneLowPriority case). - **Logs:** - `finalized textures the GPU drew once, kept for being made again` every 600 frames, by size and format - `kept finalized textures over N MB` when the cap evicts one - `... finalized by the game, sampled again at frame N` once per texture sampled more than 60 frames after it was drawn - **Refactor:** the existing "drawn over" check became a lambda so it can be shared. Its behaviour is unchanged. ## Testing - **Hardware:** RX 9070 XT, Windows, AMD driver 26.10.1, on a local branch. The patch applies to `main` as is, but I could not build `main` here. - **Repro run:** same walk-away-and-back at `RX_VK_VRAM_MB=1500`. "NOT uploaded" went from 6 to 0. The same tile addresses (e.g. 0x1168973000, 0x11689a8000, 0x11699d5000) are now sampled again about 1000 frames after they were drawn, with their texels. - **What gets kept:** other finalized one-frame textures are kept too, for example small UI-sized targets and 640x360 targets. In a few minutes that was about 50-80 MB, of which the terrain tiles were about 1.4 MB. That is why there is a cap. - **Not yet done:** a long session at the default budget. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
madebyjordan commented 2026-11-08 16:27:51 +00:00 (Migrated from github.com)

Tested on AMD: RX 6700 XT (Adrenalin driver 32.0.21045.16010), Windows 11, release v2.0.0 with this PR applied.

Without it, after ~13 minutes in Hyrule Field the ground stopped drawing (flat fog-coloured terrain with only grass and rocks on it, plus vertical streaks); the log showed ~64,000 textures retired, with the texture budget squeezed to ~3.2 GB. With it, two 15+ minute sessions riding across Hyrule Field and back: the ground stayed intact.

Tested on AMD: RX 6700 XT (Adrenalin driver 32.0.21045.16010), Windows 11, release v2.0.0 with this PR applied. Without it, after ~13 minutes in Hyrule Field the ground stopped drawing (flat fog-coloured terrain with only grass and rocks on it, plus vertical streaks); the log showed ~64,000 textures retired, with the texture budget squeezed to ~3.2 GB. With it, two 15+ minute sessions riding across Hyrule Field and back: the ground stayed intact.
Commenting is not possible because the repository is archived.
No description provided.