GPU: streamed textures take video memory only for the levels the title holds (opt-in; 0.4-1.4 GB less on current main) #2389
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!2389
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2389"
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?
@desplmfao on GitHub · 2026-11-25 12:31 UTC · original
desplmfao:perf/texture-levels-on-demand→main· +1248 −23 · 6 files · 8 commits · openProblem
Every host texture takes video memory for all its mip levels, including the levels the title hasn't streamed in yet. In Grand Theft Auto VI's world that is gigabytes of memory nothing reads: the title's streaming holds most textures at their small levels, and the large ones arrive later or never. It's a large part of why the world doesn't fit a 12 GB card.
Change
Opt-in, with
VICTORY_LEVELS_ON_DEMAND=1. It needs tiled resources tier 2 or higher.VICTORY_LEVELS_MIN_KB), that is not a render target, depth or unordered-access texture, gets a reserved host texture (CreateReservedResource, orCreateReservedResource2when it needs castable formats).UpdateTileMappings). Small levels that share the packed tail go together. The tiles come from a pool of 64 MiB heaps (tiles.rs).main's upload of unmapped title memory already gives, so the picture doesn't change.host_writtengives it every level first.host texturesline shows the textures alive, the MB given, the MB not allocated, and theUpdateTileMappingscalls.Measured
Grand Theft Auto VI Series X 1.0.2.1, the first mission's prison yard. RTX 5080 on Linux, Proton with vkd3d-proton 3.2.0, on our stack (this PR plus other open PRs). Same exe, with the switch off and on:
UpdateTileMappings) costs about 1 ms per frame. There were 140UpdateTileMappingscalls in all, about 0.25 ms in total, and none after streaming settled. The rest of the frame-time spread is the scene's own streaming, which looks the same with the switch off.UpdateTileMappingsbecomes sparse binding, and that path is what I measured.How it was found
507KAZ (who doesn't use GitHub; shared with permission) tuned fxceless/victory-fork on an RTX 4070 12 GB with 16 GB of RAM to get the world running. Of the fork's memory switches, this one made the difference: about 2.2–3.0 GB freed on his card. The mechanism is fxceless's (
tiles.rsin fxceless/victory-fork at9376fd6), ported ontomain's texture design.Differences from the fork:
mainhas no registry for them. #2149 would add the first-viewed one.The measurement above is ours.
Related
VICTORY_TEXTURE_MIP_DROP) drop top levels everywhere, which lowers quality. This keeps every level the title holds.Tested
cargo test -p victory-gpu --lib --features diagnostics tiles::(Windows build under Proton, RTX 5080): 4 passed. This includes the GPU testlevels_take_tiles_when_given_and_give_them_back, which gives tiles to levels of a real reserved texture.texture::: 3 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without--features diagnostics: clean.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@DrDarkDK on GitHub · 2026-11-25 13:16 UTC · original
I ran
levels_take_tiles_when_given_and_give_them_backat0db32bdon native Windows with an RTX 4070 Ti (621.01, tiled resources tier 4) and WARP (tier 3).Both adapters passed with the debug layer off. With
VICTORY_D3D12_DEBUG=1, both reached the final mapping step, then the test process exited with code 2173 before reporting a result. I added a test-only queue wait by submitting an empty list throughhost.executebefore dropping the tiled texture. With that wait, the test passed on both adapters with the debug layer enabled.Could the fixture wait for the mapping work before teardown? This checks synthetic tile mappings and their cleanup. It doesn’t measure streaming or VRAM savings in the title.
AI-assisted with Codex.
@desplmfao on GitHub · 2026-11-25 13:22 UTC · original
@DrDarkDK thanks, that was a real gap in the fixture. Fixed in
8c896eb, the way you suggested: an empty submission throughhost.execute, which submits and waits, now runs before the tiled texture is dropped. That way the queuedUpdateTileMappingsare done before the heaps go back to the pool.I also checked whether the title can hit the same thing, and it can't.
Tiledlives inside the host texture, andTiled::giveonly runs while uploading for a list (texture.rs). That list keeps the texture alive, and its mappings are queued on the same queue ahead of it, so in the game the heaps never go back while a mapping is pending. Only the test dropped the texture right after mapping.On the RTX 5080 under Wine with vkd3d-proton,
tiles::gives 4 passed, and clippy is clean. I couldn't reproduce the debug-layer exit here, since there's no D3D12 debug layer under vkd3d. A rerun on your 4070 Ti withVICTORY_D3D12_DEBUG=1would confirm it.@pickles976 on GitHub · 2026-11-25 15:07 UTC · original
Independent RTX 4060 Laptop / Wine check of
8c896ebb1650d1575fee2a1689a03804e4e04a83, including the mapping-wait fixture fix. The initial test runs used an isolated, unmodified copy of this exact head, not our title integration tree.Tested
2576c0b4adfae4a). Rust 1.98.1, debug, Windows MSVC cross-build with Wine as the Cargo runner;VICTORY_ADAPTER=nvidia.levels_take_tiles_when_given_and_give_them_back. 1 passed; reported tiled-resource tier 4. The real reserved-texture mapping, packed-tail, repeated-give and teardown assertions were reached. No runtime code was changed for that probe.Not tested
Full workspace suite, native Windows, the D3D12 debug layer, AMD/Intel, or title streaming on this exact head. No claim of measured VRAM savings, playable world rendering, or fitting the game into 8 GiB follows from these synthetic tests.
AI use
omp with
openai-codex/gpt-6-astraprepared the isolated checkouts, ran the checks and temporary no-skip probe, and drafted this report from the output.@Marvisak on GitHub · 2026-11-25 16:02 UTC · original · edited 2026-11-26 08:25 UTC
Automated triage for the maintainers.
Merge candidate.
bb9ab45addresses both points from the last triage. Incrates/victory-gpu/src/resource.rs,HostTexture::held_bytes()returns the allocation for an ordinary texture andTiled::given_bytes()(the tiles its levels hold) for a tiled one.evict_among/chooseandgive_upnow use it, so giving up a tiled texture is credited with what it frees.evict_unusedsubtractstiles::free_bytes()next toplacement::free_bytes(). The default path is unchanged whenVICTORY_LEVELS_ON_DEMANDis unset:reserved_texturereturnsNone, andtiles::status()returns early when no tiled texture was made. CIcheckpasses and the PR merges cleanly.On your latest reply: thanks. The title now gives the current figure ("0.4-1.4 GB less on current main"). That matches your Linux A/B (about 1.4 GB less peak video memory) and the native Windows RTX 5070 Ti run in the thread (about 0.4-0.6 GB, tier 4, clean exit). Nothing is left open from triage.
Generated by Claude Code
@desplmfao on GitHub · 2026-11-25 16:19 UTC · original
Merged
maininef1dcd6and29f572a(merge commits, no rebase).mainhad reworked texture creation in the meantime: textures fed from title memory are placed in heaps made ahead, made on first use and several at a time, uploads come from large staging buffers, and only subresources whose bytes changed are uploaded. The hooks moved:VICTORY_LEVELS_ON_DEMAND=1, an eligible streamed texture is made reserved beforemain's heap placement, so it never goes into a heap made ahead. If the reserved texture can't be made, it falls through tomain's placement or committed path unchanged. With the switch off,reserved_texturereturnsNoneimmediately and creation is exactlymain's.mainnow uploads only changed subresources, but a level that just got tiles has to be uploaded whether it changed or not (its tiles may hold a previous owner's data). Apendinglevel mask onStagingcovers those levels. They're detiled and uploaded at the next refresh, and they go back into the mask if a detile fails.host_writtenbecamemain'shost_writes: a reserved texture a host copy writes gets every level its tiles before that submission's upload list, which runs ahead of the copy.main.Tiled::withoutis no longer test-only, and the module note describes the new flow.tiles::,texture::andresource::give 24 passed under Wine on an RTX 5080, and clippy is clean with and without--features diagnostics. The in-title check on this merged head (picture and video memory) is still to come. I'll post it here.@desplmfao on GitHub · 2026-11-26 01:31 UTC · original
Both points are fixed in
bb9ab45, on top of a fresh merge ofmain(67a6614):HostTexture::held_bytes()returns the allocation for an ordinary texture. For a tiled one, it returns the bytes of the tiles its levels have (Tiled::given_bytes, which was test-only and isn't any more).evict_among/chooseandgive_upuse it, so giving up a tiled texture is credited with what it really frees.tiles::free_bytes()is subtracted inevict_unused, next toplacement::free_bytes().The tile test now also checks the pool's free bytes as a level takes its tiles.
tiles::,texture::andresource::give 25 passed under Wine (RTX 5080), and clippy is clean with and without diagnostics.From an in-title A/B on this branch (fork build, before this fix; ~3 min in the world each, medians):
VICTORY_LEVELS_ON_DEMANDSo no frame-time cost, and about 1.4 GB less.
@desplmfao on GitHub · 2026-11-26 01:54 UTC · original
A note on the size of the saving, since the title still says about 5 GB. That figure was measured on the older base, before
main's texture rework: heaps made ahead, uploads from staging buffers, and only changed subresources uploaded. On currentmain, the in-title A/B above gives about 1.4 GB less peak video memory (11,047 against 12,434 MiB) with no frame-time cost. Somainitself now spends much less on streamed textures, and the switch saves correspondingly less on top of it.GPU: streamed textures take video memory only for the levels the title holds (opt-in, ~5 GB less)to GPU: streamed textures take video memory only for the levels the title holds (opt-in; 0.4-1.4 GB less on current main)@catminou4 on GitHub · 2026-11-25 12:36 UTC · original · reviewed
Streamed textures take video memory only for the levels the title maps (tiles module, +868). 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. Large feature: tiled resource wiring with queue-ordered tile mappings. Needs hardware validation.
@pickles976 on GitHub · 2026-11-26 04:35 UTC · original
@/tmp/v2389c.md
@kawaii-shakal on GitHub · 2026-11-26 07:13 UTC · original
Measured on native Windows, which the description lists as not tried: Windows 11 26300, RTX 5070 Ti 16 GB (tiled resources tier 4), title 1.0.2.1 with the default console (Series X). Two diagnostics builds, one of
main63bcca4and one ofmain+ this PR (bb9ab45) withVICTORY_LEVELS_ON_DEMAND=1. Same save, standing still in the world. The numbers come from the process's own report lines (video memory:viaQueryVideoMemoryInfoandGetProcessMemoryInfo,host textures:, this PR's line), read 120 s after the first report where textures used by lists pass 1 GB.mainThe switch line reports
tier=4 on=true. The PR's own line said213 alive (267 made so far), 159 MB given to 506 levels alive; 210 MB not allocated (369 MB if every level had memory), with 577UpdateTileMappingscalls in all. There were no refreshes without memory, and the run exited cleanly.So it works on Windows/NVIDIA, but the saving at this spot is about 0.4–0.6 GB, not ~5 GB. Here all host textures take 5.8 GB, and only 213 of them pass the filter (2D, one layer, ≥1 MiB, not a target). I did not compare the picture side by side.
🤖 Generated with Claude Code (Claude Opus 5.5)
@desplmfao on GitHub · 2026-11-26 08:02 UTC · original
@kawaii-shakal thanks, the first Windows run of this, and it's clean: tier 4, no refreshes without memory, a clean exit. Your 0.4–0.6 GB at that spot agrees with my 1.4 GB on Linux in a busier scene. Since
main's texture rework,mainitself spends much less on streamed textures, and only the textures that pass the filter can save anything (213 of yours). The "~5 GB" in the title came from the older base, so I've changed the title to "0.4–1.4 GB less on current main".@fuzeofficlal on GitHub · 2026-11-26 11:39 UTC · original · requested changes
The on-demand reserved texture path and eviction accounting (
held_bytes,tiles::free_bytes) are well structured, and the existing tests pass on Windows 11 with RTX 5090 (tier 4) and WARP (tier 3) underVICTORY_D3D12_DEBUG=1andVICTORY_LEVELS_ON_DEMAND=1(tiles::4/4,texture::3/3,resource::18/18,draw::tests20/20).However, two lifetime/synchronization bugs in tile reclamation and
host_writesreproduce reliably on RTX 5090 and WARP and need to be fixed before merge:Blocking —
Tiled::droprecycles tiles and destroysID3D12HeapwhileID3D12Resourcestill has live COM holders (crates/victory-gpu/src/tiles.rs:473-491,236-247):HostHeap::kept(descriptor/host.rs),host::retire(RETIRED, released only at the end ofHost::execute), andHostList::keephold COM clones ofID3D12Resource(copy.texture), notArc<HostTexture>. That is whyplacement.rsdefers freeing heap ranges and empty heaps inHostTexture::dropviaplacement::free(self.texture.clone(), p)untillast_holder(&resource)confirms no other COM reference remains.Tiled::dropinstead callsgive_backimmediately whenArc<HostTexture>drops. In normal execution this happens both when the title releases a texture whose descriptor-heap slot still views it, and duringevict_unused()->give_up()(which movesID3D12ResourceintoRETIREDviadescriptor::evict, then dropsArc<HostTexture>immediately at the start ofHost::execute, ahead ofbindless::uploadsandrelease_retired()).Awith0xAA, keeping a liveID3D12Resourceclone (asHostHeap::kept/RETIREDdoes), droppingTiled, then allocating textureBand filling it with0x55handsA's exact physical tile run(0, 32)toBand silently overwritesA(before=[aa, aa, aa, aa, aa, aa, aa, aa]->after_B_wrote_0x55=[55, 55, 55, 55, 55, 55, 55, 55]).ID3D12Heapdestruction / GPU fault (RTX 5090, both with and withoutVICTORY_D3D12_DEBUG=1): with two 64 MiB heaps inPOOL, dropping theTiledowners on heap 0 while oneID3D12Resourceclone remains live immediately drops heap 0 (pool[index] = None,heaps_mb=128->64, given_back=0->1); a subsequentCopyTextureRegionfrom that liveID3D12Resourcecrashes the process on RTX 5090 with0xc0000409 (STATUS_STACK_BUFFER_OVERRUN)even without the debug layer.placement.rsby passing(self.texture.clone(), runs)fromHostTexture::dropinto a pending list intiles.rs, and only returning tile runs / releasing empty heaps oncelast_holder(&resource)is true (and after any queuedUpdateTileMappingshave completed).Blocking —
host_writescallstiled.give(UpdateTileMappings) at command-list record time (crates/victory-gpu/src/texture.rs:243-264):tiled.give(©.texture, every)directly fromhost_writes(texture.rs:254) queuesUpdateTileMappingsontohost.queue()from recording threads beforeHost::execute.Tiled::dropdestroys the backing heap whileUpdateTileMappingsis still in flight onhost.queue()— reproduced live with exit code2173on both RTX 5090 and WARP underVICTORY_D3D12_DEBUG=1.list's upload runs.host_writes(and settingpending) until submission preparation insideHost::execute(ahead oflist's upload list, matchingStaging::give_heldandlist.defer_host).One smaller non-blocking note: in
Staging::refresh_now, the untracked!committed(self.memory, size)branch (crates/victory-gpu/src/texture.rs:678-699) returns early with zeros without callinggive_held, so an untracked partially-committed reserved texture would never receive tiles for its committed small mips.@desplmfao on GitHub · 2026-11-26 12:46 UTC · original
@fuzeofficlal thanks, both were real. Fixed in
6b91df4:HostTexture::dropnow hands its resource and itsTiledtotiles::free, as it already does withplacement::freefor placed textures.tiles::reapgives the tiles back, and frees an empty heap, only whenplacement::last_holder(&resource)is true and everyUpdateTileMappingsqueued before the texture was let go has run.Host::executereads the mapping counter before signalling its fence and records it as run only after its waits succeed.reapruns afterrelease_retired(), at the start oftake(), and infree_bytes(). It releases the resource first and gives the tiles back outside the lock.host_writesnow only notes the texture in the list (HostList::defer_tiles, cleared by a reset).Host::executegives the tiles aftersync_heapsand ahead ofbindless::uploads(texture::give_for_host_writes). One difference from your suggestion:pendingis set there too, not inhost_writes. Otherwise a list dropped unrun would leavependingset, and a later refresh would give tiles for a write that never happened. Every mapping is now queued while a submission is prepared, and that submission waits for it.refresh_now, untracked and partly committed: for levels-on-demand textures it now reads throughcopy_mapped(zeros where unmapped), then hashes, callsgive_held, detiles and uploads like the committed path. So the mapped small levels get their tiles and their bytes. Committed textures keep the old zero upload.Two new tests, both failing with the old behaviour:
tiles::tests::tiles_go_back_only_once_nothing_holds_the_texture_and_its_mappings_ran(your repro: a clone of the resource held, then a new texture given level 0 gets no overlapping tiles)resource::tests::a_host_write_gives_tiles_at_submission_not_when_recordedClippy is clean with and without diagnostics. Under Wine (RTX 5080), the full
victory-gpurun has the same 30 failures asmainthere. In the title withVICTORY_LEVELS_ON_DEMAND=1it runs into the world with no crash and no tile warnings, and video memory is in the same range as before (~10.3 GB). I couldn't confirm thatVICTORY_D3D12_DEBUG=1reaches the debug layer under vkd3d-proton, so a rerun of your RTX 5090/WARP repro would be the real check.@fuzeofficlal on GitHub · 2026-11-26 13:09 UTC · original · approved these changes
Re-reviewed and re-verified
6b91df4a(based onorigin/main63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 tier 4 and WARP tier 3, Rust1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll; synthetic tests only, no game files).All three issues from the previous review are cleanly fixed and verified:
crates/victory-gpu/src/resource.rs:994-996,tiles.rs:213-275,host.rs:1290,1340,1459):HostTexture::dropnow routes throughtiles::free(self.texture.clone(), tiled), andtiles::reap()releasestexturebefore droppingtiledoutside the lock only oncefreed[i].queued <= ranandplacement::last_holder(&freed[i].texture)is true.0xAAvs0x55):before=[aa, aa, aa, aa, aa, aa, aa, aa],after_B_wrote_0x55=[aa, aa, aa, aa, aa, aa, aa, aa], 0 D3D12 Debug Layer messages on both RTX 5090 and WARP (was silent0x55overwrite onbb9ab450).heaps_mb=128->128,given_back=0->0, andCopyTextureRegionsucceeds cleanly with 0 errors on pure RTX 5090 (no debug layer), RTX 5090 (VICTORY_D3D12_DEBUG=1), and WARP (VICTORY_D3D12_DEBUG=1) (was a0xc0000409crash on RTX 5090 onbb9ab450). Dropping the last COM clone and callingreap()cleanly returns heap 0 (heaps_mb=128->64, given_back=0->1).host_writestile mapping (crates/victory-gpu/src/texture.rs:247-285,host.rs:1219-1223,2321-2330):host_writesnow records onlyHostList::defer_tiles(cleared byHostList::reset), andgive_for_host_writesruns insideHost::executeahead ofbindless::uploads, also settingstaging.pendingthere so unrun lists never dirtypending.VICTORY_D3D12_DEBUG=1):tiles::queued()stays unchanged at record time, reset and earlier out-of-order submissions see 0 tiles, unrun dropped lists tear down cleanly (exit 0; previously exit code2173), and actual submission maps all levels with 0 debug messages.crates/victory-gpu/src/texture.rs:703-708): now read viacopy_mappedintoScratchso committed small mips flow throughgive_heldand upload properly.Verification
cargo xtask policy:192 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features): 0 warnings.VICTORY_D3D12_DEBUG=1,VICTORY_LEVELS_ON_DEMAND=1,--features diagnostics,--test-threads=1):tiles::tests,texture::tests,resource::tests,draw::tests— 47 passed, 0 failed.VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1,VICTORY_LEVELS_ON_DEMAND=1,--features diagnostics): 47 passed, 0 failed.Non-blocking Test Note
tiles::testsin parallel underVICTORY_D3D12_DEBUG=1on RTX 5090 hit a test-only race on the globalPOOLbetweenlevels_take_tiles_when_given_and_give_them_back(crates/victory-gpu/src/tiles.rs:689-697) and the newtiles_go_back_only_once_nothing_holds_the_texture_and_its_mappings_ran: both grab 32 tiles from the first 64 MiB heap concurrently, causing line 697 to panic (65011712 0) and unwinding to drop the test's bareTiledwithouttiles::free(exit code 2173under the debug layer). Serializing thePOOL-measuring tests intiles::testswith a test-onlyMutex<()>would avoid parallel test flakiness.#2101,#2101's test callmake_texture(&d, 0, std::ptr::null())will need the 4thfalse(on_demand) argument added here.Production lifetime and synchronization issues are fully resolved. Approved.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.