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

Closed
opened 2026-11-26 06:46:37 +00:00 by triggered02 · 1 comment
triggered02 commented 2026-11-26 06:46:37 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T06:46:37Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6621155304 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2764). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-26T06:46:37Z. --- ### 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.
R0Y00 commented 2026-11-26 08:01:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:04:31Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185069064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2764#issuecomment-7185069064). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T07:04:31Z. --- 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2756
No description provided.