GPU: make host textures on first use instead of at resource creation #1526
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!1526
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1526/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?
@0xKaji on GitHub · 2026-11-24 18:47 UTC · original
0xKaji:feat/lazy-host-textures→main· +310 −28 · 2 files · 1 commits · closed without mergingWhy
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.
@antikohza on GitHub · 2026-11-24 19:58 UTC · original
@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.@0xKaji on GitHub · 2026-11-24 22:01 UTC · original
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