Skip to content

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

Merged
NotRexed merged 1 commit into
NotRexed:mainfrom
duck-paradise:fix/keep-finalized-gpu-textures
Nov 8, 2026
Merged

NotRexed merged 1 commit into
NotRexed:mainfrom
duck-paradise:fix/keep-finalized-gpu-textures

Conversation

@duck-paradise

Copy link
Copy Markdown
Contributor

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

…d streaks after long play, issues 107 and 386)

OoT's terrain draws each chunk's 260 x 260 RG8 normal map once, finalizes the texture when the chunk goes out of
range, and when the chunk comes back makes a texture over the same storage and samples it without drawing it again.
On the console the texels are still in that memory. Here they were only in the Vulkan image: 60 frames after the
finalize the eviction destroyed it (no write-back for finalized ones), and the texture made again over storage the
GPU rendered was not uploaded and sampled empty. The ground went to streaks in square patches (one projection
stretched along X or Z) after tens of minutes, and stayed so until a restart.

Traced with RX_VK_WATCH_DIM=260x260 and RX_VK_VRAM_MB=1500 (to evict sooner), walking away from the save spot in
Hyrule Field and back: e.g. NotRexed#350 at 0x1168973000 drawn at frame 1437, finalized 2259, evicted 2320, made again at
2891 and "NOT uploaded (over storage the GPU rendered)". 6 such tiles in that run, 0 with this change; the same
tiles are now sampled again ~1000 frames after they were drawn, with their texels.

Kept: textures the GPU drew in one frame, 4 MB or less, finalized, whose storage is still the range the GPU drew
them in (gpu_owned) and that no other image was drawn over. Up to RX_VK_KEEP_FINALIZED_MB (512 by default, within
the texture budget; 0: evicted as before), the least recently used beyond that going as before. Not written back
into guest memory instead: the game may have put other things there since, and a write-back over scene data once
crashed it.

Tested on an RX 9070 XT (Windows, driver 26.10.1) on a local branch; the change applies to main as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@madebyjordan

Copy link
Copy Markdown
Contributor

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants