Proposal: upload textures picked by index by what shaders sampled, and let go of the least recently sampled (RX 9070 XT numbers) #1423

Open
opened 2026-11-27 02:19:16 +00:00 by github-bot · 2 comments
Owner

@⁠Granite900 on GitHub · 2026-11-27 01:52 UTC · original

The textures shaders pick by index (draw.rs heap_textures) are uploaded in the queue's order and let go when nothing names them. The layer cannot see which of them a frame samples. When the card cannot hold them all, what is on screen waits behind what is not, and textures still in use are let go and made again. This proposes that the translated shaders report what they sample, so that the queue uploads that first and lets go of what has not been sampled lately. I am asking before writing any of it.

What it looks like on a 16 GB card (RX 9070 XT, driver 32.0.32029.2010, Ryzen 7 9850X3D, 32 GB)

Base 4c60466 with #452's change (the AMD compiler crash), diagnostics build, the test switch set plus VICTORY_TILES_SMALL_WHEN_FULL_MB=512. Café scene of the opening, about 2 minutes a run. Frame shots (VICTORY_SHOT) were taken with the waitress on screen.

Added to the set above Title textures with no host copy at the end Passes that made none for lack of room Let go / made again Faces in the G-buffer's colour target
VICTORY_BAKE_SOURCES=full 20,739 (12.0 GB) 455 – several black (base skin; tattoos drawn)
=full, VICTORY_CARD_WINDOWS_MB=512 28,152 (13.7 GB) 147 33,707 / 8,335 all right, but slower, more stutter, textures lost on screen
=1 (half of #1422), VICTORY_TEXTURE_ROOM_PERCENT=96 22,210 (12.3 GB) 282 25,453 / 6,137 some black, fast
=1 with #1422, 96 % 29,059 (14.0 GB) 220 31,573 / 5,418 one black in the wide shot

The card stayed at 12.4–12.7 GB of a 13.9 GB budget. In a usual frame the card is idle 72–84 ms of about 125 ms (frame log, warm shader cache). So the card has room to spare in time, but not in memory.

The switches only move the line between faces and speed. More room fixes faces, but it costs frame time because the buffer windows leave the card, and it makes textures churn. On 8 GB cards #898 shows the same queue that never drains (15–19 k waiting). There, too, the line resource::room draws while room is kept for targets and copies not made yet holds the queue back with gigabytes unused. #1422 takes the skin bake's sources out of that line. This proposal is about everything else.

What other layers and engines do

  • The application makes resident what the next submissions use, keeps a margin under the budget, and evicts what no recent submission used: least recently used (D3D12 residency, Periodic trim spec, Dawn's residency manager, which keeps to 95 % of the budget).
  • With bindless access, what was sampled is not known on the CPU, so streaming systems have the GPU say what it sampled: sampler feedback, and feedback buffers in virtual texturing. They read it back a frame later and render a lower level until it is resident. This layer already has that fallback (VICTORY_TILES_SMALL_WHEN_FULL_MB).

This layer translates every shader, so it can add that report itself.

Proposal, in steps that each measure on their own

  1. Record only. Every handle a translated shader makes from a view heap index (emit::shader heap_handle; lower calls it) also sets bit index in a buffer of one bit per view slot (2,097,152 slots = 256 KiB), with one atomic OR. The layer reads the buffer back a frame later and clears it, then logs a line: slots sampled this frame, of them with no host copy, and with only small levels. No upload or eviction changes. This says how much of the queue is ever sampled, and how much of what is sampled is missing.
  2. Upload by sampled. Slots sampled while missing go to the front of the queue, ahead of its order and of the frame's budget, within the card's budget.
  3. Let go by least recently sampled. When the card is past its line, the host copies of slots sampled longest ago go first, before anything sampled in the last few frames.

Questions

  • Is something like this already planned or in progress? The README's "next" lists touch the texture queue often.
  • Is an extra UAV in every translated shader's root signature acceptable, or is there a better place for the bits (the layer's own descriptor at the end of the view heap)?
  • Cost: one atomic per by-index handle per lane, or per wave if the index is uniform (most are). It has to be measured. The card is idle half the frame here.
  • lower.rs is over the 512 KiB policy limit, so the hook refuses any commit that touches it. Step 1 may fit in emit/shader.rs and the GPU crate alone. If it does not, is a split of lower.rs planned?

I can build step 1 and measure it on this card if this direction is wanted.

AI-assisted (Claude Code); no game data.

**@⁠Granite900** on GitHub · 2026-11-27 01:52 UTC · [original](https://github.com/fxceless/victory-fork/issues/1423) The textures shaders pick by index (`draw.rs` `heap_textures`) are uploaded in the queue's order and let go when nothing names them. The layer cannot see which of them a frame samples. When the card cannot hold them all, what is on screen waits behind what is not, and textures still in use are let go and made again. This proposes that the translated shaders report what they sample, so that the queue uploads that first and lets go of what has not been sampled lately. I am asking before writing any of it. ## What it looks like on a 16 GB card (RX 9070 XT, driver 32.0.32029.2010, Ryzen 7 9850X3D, 32 GB) Base `4c60466` with #452's change (the AMD compiler crash), diagnostics build, the test switch set plus `VICTORY_TILES_SMALL_WHEN_FULL_MB=512`. Café scene of the opening, about 2 minutes a run. Frame shots (`VICTORY_SHOT`) were taken with the waitress on screen. | Added to the set above | Title textures with no host copy at the end | Passes that made none for lack of room | Let go / made again | Faces in the G-buffer's colour target | |---|---|---|---|---| | `VICTORY_BAKE_SOURCES=full` | 20,739 (12.0 GB) | 455 | – | several black (base skin; tattoos drawn) | | `=full`, `VICTORY_CARD_WINDOWS_MB=512` | 28,152 (13.7 GB) | 147 | 33,707 / 8,335 | **all right**, but slower, more stutter, textures lost on screen | | `=1` (half of #1422), `VICTORY_TEXTURE_ROOM_PERCENT=96` | 22,210 (12.3 GB) | 282 | 25,453 / 6,137 | some black, fast | | `=1` with #1422, 96 % | 29,059 (14.0 GB) | 220 | 31,573 / 5,418 | one black in the wide shot | The card stayed at 12.4–12.7 GB of a 13.9 GB budget. In a usual frame the card is idle 72–84 ms of about 125 ms (frame log, warm shader cache). So the card has room to spare in time, but not in memory. The switches only move the line between faces and speed. More room fixes faces, but it costs frame time because the buffer windows leave the card, and it makes textures churn. On 8 GB cards #898 shows the same queue that never drains (15–19 k waiting). There, too, the line `resource::room` draws while room is kept for targets and copies not made yet holds the queue back with gigabytes unused. #1422 takes the skin bake's sources out of that line. This proposal is about everything else. ## What other layers and engines do - The application makes resident what the next submissions use, keeps a margin under the budget, and evicts what no recent submission used: least recently used ([D3D12 residency](https://learn.microsoft.com/en-ie/Windows/Win32/direct3d12/residency), [Periodic trim spec](https://microsoft.github.io/DirectX-Specs/d3d/D3D12_PeriodicTrimNotifications.html), Dawn's [residency manager](https://dawn.googlesource.com/dawn/+/f56f19059b12dd5dd358937b5af3d6394762c45e/src/dawn_native/d3d12/ResidencyManagerD3D12.cpp), which keeps to 95 % of the budget). - With bindless access, what was sampled is not known on the CPU, so streaming systems have the GPU say what it sampled: [sampler feedback](https://microsoft.github.io/DirectX-Specs/d3d/SamplerFeedback.html), and feedback buffers in virtual texturing. They read it back a frame later and render a lower level until it is resident. This layer already has that fallback (`VICTORY_TILES_SMALL_WHEN_FULL_MB`). This layer translates every shader, so it can add that report itself. ## Proposal, in steps that each measure on their own 1. **Record only.** Every handle a translated shader makes from a view heap index (`emit::shader` `heap_handle`; `lower` calls it) also sets bit *index* in a buffer of one bit per view slot (2,097,152 slots = 256 KiB), with one atomic OR. The layer reads the buffer back a frame later and clears it, then logs a line: slots sampled this frame, of them with no host copy, and with only small levels. No upload or eviction changes. This says how much of the queue is ever sampled, and how much of what is sampled is missing. 2. **Upload by sampled.** Slots sampled while missing go to the front of the queue, ahead of its order and of the frame's budget, within the card's budget. 3. **Let go by least recently sampled.** When the card is past its line, the host copies of slots sampled longest ago go first, before anything sampled in the last few frames. ## Questions - Is something like this already planned or in progress? The README's "next" lists touch the texture queue often. - Is an extra UAV in every translated shader's root signature acceptable, or is there a better place for the bits (the layer's own descriptor at the end of the view heap)? - Cost: one atomic per by-index handle per lane, or per wave if the index is uniform (most are). It has to be measured. The card is idle half the frame here. - `lower.rs` is over the 512 KiB policy limit, so the hook refuses any commit that touches it. Step 1 may fit in `emit/shader.rs` and the GPU crate alone. If it does not, is a split of `lower.rs` planned? I can build step 1 and measure it on this card if this direction is wanted. AI-assisted (Claude Code); no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:19:16 +00:00
Author
Owner

@⁠akimfomin on GitHub · 2026-11-27 02:03 UTC · original

For the record-only stage, I checked the descriptor lifetime at your 4c60466 base. HostHeap::publish already refuses a queued update when its view index/generation no longer matches. A frame-delayed bitset needs the same distinction: if the GPU sampled A at slot 240 and that slot holds B at readback, applying the bit to B would create a false hot texture. Matching a slot alone also aliases two shader-visible heaps.

A first synthetic fixture could contain one true sample, one constructed handle that is never sampled, and one sampled slot recycled before the CPU consumes the feedback. Only the stable sample should be eligible to affect scheduling. If the exact heap/view epoch the commands saw is unknown, count the mark separately rather than using it for eviction. A minimal CPU model passed these four controls (including two heaps with the same slot). No hardware or overhead result yet. PortBridge can help repeat the fixture once the record-only prototype is available. AI-assisted source review with OpenAI Codex.

**@⁠akimfomin** on GitHub · 2026-11-27 02:03 UTC · [original](https://github.com/fxceless/victory-fork/issues/1423#issuecomment-7207798274) For the record-only stage, I checked the descriptor lifetime at your `4c60466` base. [`HostHeap::publish`](https://github.com/fxceless/victory-fork/blob/4c60466140f4bccd2252427b6f2cfbc658c16906/crates/victory-gpu/src/descriptor/host.rs#L2403-L2418) already refuses a queued update when its view index/generation no longer matches. A frame-delayed bitset needs the same distinction: if the GPU sampled A at slot 240 and that slot holds B at readback, applying the bit to B would create a false hot texture. Matching a slot alone also aliases two shader-visible heaps. A first synthetic fixture could contain one true sample, one constructed handle that is never sampled, and one sampled slot recycled before the CPU consumes the feedback. Only the stable sample should be eligible to affect scheduling. If the exact heap/view epoch the commands saw is unknown, count the mark separately rather than using it for eviction. A minimal CPU model passed these four controls (including two heaps with the same slot). No hardware or overhead result yet. [PortBridge](https://github.com/akimfomin/PortBridge) can help repeat the fixture once the record-only prototype is available. AI-assisted source review with OpenAI Codex.
Author
Owner

@⁠Granite900 on GitHub · 2026-11-27 02:14 UTC · original

Agreed — a slot alone isn't enough. Step 1 will keep, per submission, the (heap, index, generation) key each sampled slot held when the commands were recorded, and match the readback against that snapshot rather than the live slot; marks whose key no longer matches (or whose heap is unknown) are counted separately and never feed eviction. The three-case fixture (true sample, constructed-but-unsampled handle, recycled slot) plus the two-heaps-same-slot case will go in as unit tests with the prototype.

**@⁠Granite900** on GitHub · 2026-11-27 02:14 UTC · [original](https://github.com/fxceless/victory-fork/issues/1423#issuecomment-7207955353) Agreed — a slot alone isn't enough. Step 1 will keep, per submission, the `(heap, index, generation)` key each sampled slot held when the commands were recorded, and match the readback against that snapshot rather than the live slot; marks whose key no longer matches (or whose heap is unknown) are counted separately and never feed eviction. The three-case fixture (true sample, constructed-but-unsampled handle, recycled slot) plus the two-heaps-same-slot case will go in as unit tests with the prototype.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/fxceless--victory-fork#1423
No description provided.