GPU: host textures are made on a title texture's first use, not with the resource #2221
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2221
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2221/head"
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?
@0xkn0wh3r3 on GitHub · 2026-11-25 08:12 UTC · original
0xkn0wh3r3:gpu/host-textures-made-on-first-use→main· +360 −40 · 3 files · 1 commits · closed without mergingProblem
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
@Marvisak on GitHub · 2026-11-25 13:30 UTC · original · edited 2026-11-25 16:04 UTC
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
@0xkn0wh3r3 on GitHub · 2026-11-25 18:51 UTC · original
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