GPU: host textures are made on a title texture's first use, not with the resource #2219
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2221"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T08:12:14Z.
Problem
Every title texture got its host texture (
CreateCommittedResource(3)) when the title created the resource:create_committed,create_committed3,create_placedandcreate_at_addressall went throughhand_out_resource→shared_texture→make_texture. Console titles create many textures up front (streaming pools, placed resources in big heaps) that nothing draws for a long time, or ever, so video memory fills with host textures nothing uses.texture_counts()already showed it on the frame-rate line (host texture bytes against the bytes some list used).Measured with 64 committed title textures of the kinds titles stream: BC1 2048², BC7 1024² and RGBA8 1024² with every mip, and an RGBA16F 1920×1080 render target. All of them were created and never used. The test is
resource::tests::unused_textures_take_no_host_memory(ignored); the same check was run onmainfor the first row.main, after creating themFix
Resource::hostis aOnceLock<Option<Arc<HostTexture>>>, filled by one function,host_texture, on first use. The resource keeps what is needed to make it later: the state and the clear value. The clear value is copied, because the title's pointer is only valid for the call.Every reader goes through it:
host_resource,host_copy,host_transition,view_format,texture_atandalias_source. So these all make the host texture on demand:descriptor/host.rs)list::ensure_statelist.rsdraw.rsqueue.rstexture.rsRecording runs on several threads:
OnceLockmakes the texture once, and threads that race for it wait for the first.Things that only look do not make one:
list::host_barrier) use the newhost_resource_made. A texture nothing used has no state to leave. Its first use in a list moves it where that use needs, through the list's prelude, as for any first use in a list.current: a texture not made yet will share the memory's live host texture.alias_source: it looks for the title texture the GPU wrote. One never used was never written.Nothing needs a host texture when the resource is created, so nothing is made eagerly:
texture::staging/upload, once per list per host texture). A texture made later still gets them.texture_at) are made when a draw reads them, as before.Kept the same
MEMORY,memory_key,takes)REPLACEDcountTEXTURES_AT,alias_sourceandalias_copylead).leaddisabled,draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_viewfails ("round 0: one host texture"). That shows this is needed.TEXTURES,TEXTURE_BYTES,USED,SHARED,SAVEDandREPLACEDcount what is made, when it is made. A newWAITINGcount (title textures alive with no host texture yet) is shown on the frame-rate line.Tests
resource::tests::host_textures_are_made_on_first_use. It makes three title textures at one memory: an R32_UINT unordered-access texture and two RGBA8 views. It checks that:Arc::ptr_eq, counted inSHARED);resource::tests::unused_textures_take_no_host_memory: the measurement above, with exact counter checks. It reads process-wide counters, so run it alone:cargo test -p victory-gpu --lib unused_textures -- --ignored --nocapture --test-threads=1.cargo test --workspace --exclude victory-shader --no-fail-fast: everything passes exceptdescriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views. These fail the same way on unmodifiedmainon this machine (the GPU's shader-visible heap is smaller thanHEAP_VIEWS).cargo test -p victory-shader --no-fail-fast -- --test-threads=1: 244 passed, 3 failed. The failures are hardware checks: twoemit::stride_testsandgathers_at_a_level_match_the_hardware.victory-shaderis not changed and does not depend onvictory-gpu.cargo clippy --workspace --all-targetsandcargo clippy --workspace --all-targets --features victory-gpu/diagnostics: no warnings.Not covered
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T08:22:50Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib host_textures_are_made_on_first_use— passed on RTX 5090cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean lazy creation of host textures on first use rather than at resource creation. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:24Z.
Review: COMMENTED
Host textures are made on a title texture's first use; barriers no longer force creation (
host_resource_made). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Nice lazy-allocation fix; the newwaitingtexture metric helps visibility.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:30:02Z.
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/host.rs,crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T18:51:13Z.
Closing: upstream
a7381ed(host textures made on first use) covers this, and52d14b1,cea278candab2e2b2build on it. The one difference is that upstream counts a list's barrier as a use, where this PR didn't make a host texture for a barrier alone. That's a deliberate upstream choice, so I'm not carrying it on.Pull request closed