Skip to content

gpu: defer CreateCommittedResource for untouched read-only slot 133 textures #2764

Backlog

Description

@triggered02

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) committed D3D12_HEAP_TYPE_DEFAULT 2D textures charges Local +512.00 MiB, Pagefile +514.93 MiB, SysCommit +519.47 MiB.
  • ID3D12Device::Evict() drops Local to +0.00 MiB but leaves Pagefile +514.93 MiB and SysCommit +519.47 MiB unchanged. D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT likewise charges +513.01 MiB Pagefile / +513.68 MiB SysCommit at CreateHeap time.
  • By contrast, the wrap(nullptr) lazy-materialization pattern already used by publish_tiled_texture / sampled_address_texture (src/startup_stubs/d3d12_memory_srv.inl:526-576) keeps VRAM and commit at 0 until first GPU touch (and CreateReservedResource with 0 tiles mapped also keeps Local +0.00 MiB, SysCommit +0.00 MiB, Pagefile +0.12 MiB on TiledResourcesTier >= 1 formats).

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):

  1. In slot 133, for textures without ALLOW_RENDER_TARGET | ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, wrap nullptr with the stored sanitized D3D12_RESOURCE_DESC, format, and title_memory, preserving note_resource and retire_set_class eligibility without charging x2w_budget::committed or calling CreateCommittedResource yet.
  2. In view_slot<18>, record the tracked view (note_view, keeping #2379 design B retire_view_refs accounting intact) and create a null SRV placeholder when real == nullptr.
  3. Materialize lazily via CreateCommittedResource (and refresh any bound SRV descriptor) on first actual GPU use (draw_translated sampling / 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, creating slot 133 read-only textures + slot 18 SRVs leaves x2w-budget texture at 0/0 and 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_translated or list_copy_*.
  • Peak commit savings when all world textures are actively drawn in later gameplay (lazy materialization defers un-drawn textures, not actively sampled ones).

Refs #2379, #1199.

Activity

  1. R0Y00 commented on Nov 26, 2026

    @R0Y00
    Owner

    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.

  2. added a commit that references this issue on Nov 26, 2026
    92db6d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions