Repository navigation
Description
Problem
In src/startup_stubs/d3d12_xs_device.cpp (device_place_resource_x, slot 133), every placed texture call immediately calls CreateCommittedResource on D3D12_HEAP_TYPE_DEFAULT. In heavy startup workloads that create thousands of read-only textures (!(Flags & (ALLOW_RENDER_TARGET | ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS))) ahead of first sampling (textures uploaded 0), those un-sampled textures consume ~4+ GiB of both Local VRAM and Windows process/system commit (PagefileUsage / CommitTotal), pushing 16 GiB hosts into commit exhaustion (#1199).
Empirical evidence (GTX 1660 SUPER, Windows 11, D3D12 micro-probe)
- Creating 64 × 8 MiB (
512 MiB) committedD3D12_HEAP_TYPE_DEFAULT2D textures chargesLocal +512.00 MiB,Pagefile +514.93 MiB,SysCommit +519.47 MiB. ID3D12Device::Evict()dropsLocalto+0.00 MiBbut leavesPagefile +514.93 MiBandSysCommit +519.47 MiBunchanged.D3D12_HEAP_FLAG_CREATE_NOT_RESIDENTlikewise charges+513.01 MiBPagefile/+513.68 MiBSysCommitatCreateHeaptime.- By contrast, the
wrap(nullptr)lazy-materialization pattern already used bypublish_tiled_texture/sampled_address_texture(src/startup_stubs/d3d12_memory_srv.inl:526-576) keeps VRAM and commit at0until first GPU touch (andCreateReservedResourcewith 0 tiles mapped also keepsLocal +0.00 MiB,SysCommit +0.00 MiB,Pagefile +0.12 MiBonTiledResourcesTier >= 1formats).
Proposed solution (opt-in X2W_D3D12_LAZY_TEXTURES=1)
Add an opt-in X2W_D3D12_LAZY_TEXTURES=1 switch (leaving default behavior and existing startup_resource_budget / startup_resource_retire* contracts untouched):
- In
slot 133, for textures withoutALLOW_RENDER_TARGET | ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, wrapnullptrwith the stored sanitizedD3D12_RESOURCE_DESC, format, andtitle_memory, preservingnote_resourceandretire_set_classeligibility without chargingx2w_budget::committedor callingCreateCommittedResourceyet. - In
view_slot<18>, record the tracked view (note_view, keeping#2379design Bretire_view_refsaccounting intact) and create a null SRV placeholder whenreal == nullptr. - Materialize lazily via
CreateCommittedResource(and refresh any bound SRV descriptor) on first actual GPU use (draw_translatedsampling /upload_texture,list_copy_*,WriteToSubresource,Map,view_slot<19..21>).
Acceptance
New source-built WARP + hardware CTest startup_slot133_lazy_textures_{warp,hardware} verifying:
- With
X2W_D3D12_LAZY_TEXTURES=1, creatingslot 133read-only textures +slot 18SRVs leavesx2w-budgettextureat0/0and avoids commit growth; - Drawing or copying one texture materializes only that texture and matches expected pixel/texel readback, while untouched textures remain unmaterialized and retire cleanly at guest
Release(); - With
X2W_D3D12_LAZY_TEXTURES=0, creation remains eager.
Command:ctest --preset dev --no-tests=error -R '^(startup_slot133_lazy_textures|startup_resource_retire(_title|_views)?_|startup_resource_budget)'
NOT established
- Whether any native (non-translated) draw path reads an un-materialized SRV slot without going through
draw_translatedorlist_copy_*. - Peak commit savings when all world textures are actively drawn in later gameplay (lazy materialization defers un-drawn textures, not actively sampled ones).
Activity
R0Y00 commentedon Nov 26, 2026
The measurements justify a focused lazy-materialization fixture. Please include the descriptor lifetime case from #2379 and #2468 in that first slice: publish an SRV, copy the descriptor, release the guest resource, then bind the copied slot on a fresh list. Its first GPU use must produce a nonzero reference readback and materialize exactly one backing. Use a new list after explicit overwrite as the retirement control. Test one native or non-translated consumer as well, or scope the opt-in to proven consumers and keep the remaining path eager. Report the fixture separately from the #1199 startup memory numbers.
d3d12_xs: defer slot-133 read-only texture commits under X2W_D3D12_LA…