GPU: make host textures on first use instead of at resource creation #1525
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1526"
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 0xKaji on 2026-11-24T18:47:55Z.
Why
Buffers (
shadow.rs) and shader-visible descriptor heaps (descriptor.rs) are already created lazily on first use, buthand_out_resource()incrates/victory-gpu/src/resource.rsstill callshost_texture()(CreateCommittedResourceinD3D12_HEAP_TYPE_DEFAULT) eagerly for every texture the title registers.During startup and world streaming, the title registers thousands of placed/address textures before drawing them (in our RTX 3060 8 GB trace,
3,289textures totaling~8,233 MiBof estimated footprint before Stage (e) even begins). On 8 GB GPUs this saturates VRAM (7,851 / 8,192 MiB) within ~44 s and triggersNV_ERR_NO_MEMORY/vkAllocateMemoryOOM faults — the pre-lazy commit cannot reach Stage (e) on an 8 GB GPU with warm caches (OOM atframe=1123), which is itself the motivating case (related to #1226, and orthogonal to mip-drop quality reduction in #1296).What Changed
crates/victory-gpu/src/resource.rs:initial_state: u32andclear_value: Option<[u32; 5]>onResource(copied while the caller's pointer is still live), and changeResource::hostfromOption<Arc<HostTexture>>toOnceLock<Option<Arc<HostTexture>>>.ID3D12Resourceon first use viaResource::host_entry()whenhost_resource(),host_copy(),host_transition(),view_format(), ortexture_at()accesses it.existing_host_resource()to query an already-materialized host texture without creating one, and avoid materializing inDrop for Resource.resource::tests::host_texture_is_made_on_first_useandresource::tests::clear_value_survives_lazy_materialization.crates/victory-gpu/src/list.rs:existing_host_resource()inhost_barrier()so resource barriers on textures never yet touched by a view, copy, clear, or draw do not materialize them into VRAM. (When a texture is later materialized on first use,HostList::transition/prelude()transitions it from itsinitial_state.)Aliasing
The host layer has never shared
ID3D12Heapor usedCreatePlacedResource(host_texture()atcrates/victory-gpu/src/resource.rs:887gives everyResourceits own committed allocation onmain); placed/address backing (resource.rs:1172,resource.rs:1261) is CPU-side only, so lazy materialization does not change aliasing semantics.Verification
Tested on CachyOS Linux (
7.3.5-2), Wine11.22,vkd3d-proton 3.2.0(GE-Proton11-14), NVIDIA RTX 3060 8 GB (driver620.73.04), cross-built withcargo xwin(x86_64-pc-windows-msvc):cargo xwin clippy -p victory-gpu --tests --target x86_64-pc-windows-msvc -- -D warnings: 0 warnings.cargo test -p xtask(asset policy) + Linux-compatible crates: 0 failed.victory-gpuunder Wine (--test-threads=1):resource::tests: 8 passed, 0 failed — includinghost_texture_is_made_on_first_useandclear_value_survives_lazy_materialization(overwrites caller stack storage before lazy materialization, runsClearRenderTargetView+ GPU readback, asserts pixel values match the original clear color).victory-gpusuite stacked with#177 + #190 + #347: 51 passed, 0 failed, 1 ignored (plusclear_value_survives_lazy_materializationverified under Wine).VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains,VICTORY_D3D12_DRED=1, stacked on#177 + #190 + #347):frame=1123:7,851vs5,392 MiB(−2.40 GiB).7,851vs5,639 MiB(−2.16 GiB). VRAM stays flat~5,390 MiBacross frames512–1123with lazy, vs spiking to7,851 MiBbetween frames512–1024onmain.nvidia-smi):run5, warm)run6, warm)frame=1285,333 MiB5,312 MiBframe=5125,379 MiB5,344 MiBframe=10247,851 MiB5,384 MiBframe=1123(last common)7,851 MiB(OOM crash at+66 s:vkAllocateMemory 0xc0000005,NV_ERR_NO_MEMORY)5,392 MiB(0 kernelNVRM/Xiderrors)120 s)5,639 MiBpeak (frame=1366,1,415draws/frame,488pipelines incl.127mesh, 0 crashes, 0 Xids)On GPUs with more VRAM this OOM may not occur; on 8 GB GPUs, eager host texture allocation hits the VRAM ceiling before Stage (e) once compilation stalls are gone, whereas lazy materialization keeps full mip quality with >2 GiB of headroom.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T18:57:02Z.
Review: APPROVED
Verified locally merged onto
origin/main(Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-gpu— 52 passed, 0 failed (1 ignored) on both RTX 5090 hardware andVICTORY_D3D12_WARP=1(includinghost_texture_is_made_on_first_useandclear_value_survives_lazy_materialization)cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— okClean lazy host texture materialization on first use while preserving clear values. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by antikohza on 2026-11-24T19:58:59Z.
@0xKaji — saw your reference to #1296 and your RTX 3060 8 GB
NV_ERR_NO_MEMORY/vkAllocateMemorymeasurements here.Just a heads-up that #1296 (
a6f3ccb) is updated with discrete adapter selection, LUID-matched<= 8.5 GiBauto mip-drop,ResourceMinLODClamprebasing, and subresource-granularHostWrittentracking — and we also verified a clean stack combining #431 (lazy first-use textures) + #967 + #1296 onantikohza:feat/texture-mip-drop-on-1542(0d79788, Windows CI run 45473319819). Stacking mip-drop with lazy materialization gives 8 GB Linux/Proton and Windows setups even more headroom.Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-24T22:01:22Z.
Closing as a duplicate of #431 (@AntoninMichelq), which I missed when checking for overlap. It makes host textures on first use the same way (
OnceLock+ clear value kept), opened earlier, and also defers frees past running submissions. For reference, the same idea on an RTX 3060 8 GB under Linux/Wine + vkd3d-proton 3.2.0 took the world's same-frame host-texture peak from ~7.85 GiB to ~5.39 GiB and turned an OOM at +66 s into a clean 120 s run. Thanks @DenRakEiw for the review.Pull request closed