Skip to content

memory: inventory of application-memory paths and next steps for the #1914 hybrid model #3676

Backlog

Description

@Leyukaka

Context

  • On the console, CPU and GPU share one memory: the application writes GPU data and GPU addresses into its own memory and reads GPU results back from it.
  • On a PC with a discrete GPU, video memory is separate, so every path either shares the application's pages with the GPU or copies them.
  • design: runtime model for the console's unified CPU/GPU memory (copies vs direct use of title memory) #1914 decided a hybrid model: share when the allocation, the adapter and the synchronization contract allow it, copy only when the copy keeps the same visibility and lifetime (it captures bytes at submission), otherwise a diagnosable refusal.

This issue does not reopen that decision. It lists the paths that exist on main today, what a start-up run shows about them, and small work items that can be claimed separately.

Inventory

Read from main at d5970858. Bare :N is src/startup_stubs/d3d12_xs_device.cpp; draw is d3d12_draw.inl, cdisp is d3d12_compute_dispatch.inl, both in src/startup_stubs/. "Desktop copy" means a separate D3D12 resource.

# Mechanism GPU reads Synchronized Where Known limit
1 Slot 133 buffer on an existing heap application memory no copy, both directions :6688-6720 private allocation, committed from its base, offset a multiple of 64 KiB; the heap wraps and pins the whole allocation (#1942); no D3D12_FEATURE_EXISTING_HEAPS query on this path
2 Slot 133 buffer, fallback desktop copy (committed, zeros) never :6724-6732 correct only for consumers that resolve the address themselves; at least 64 KiB each, kept for the process (#3474)
3 Slot 133 texture desktop copy uploaded on bind, re-hashed up to 32 MiB (R8/A8 each frame, others every 15 frames) :6564-6608, draw:2002-2005 never shared: console layouts need detiling
4 Per-draw copy frame_copy upload ring at draw record draw:1940, call draw:4003 misses later writes; cut at 16 MiB (draw:3919-3921); 256 MiB ring
5 Root SRV upload_from_title upload ring at bind, 64 KiB window :3216-3221, :5238-5239 same; #1942 showed bind and record copies read the old bytes
6 Translated compute input snapshot (X2W_TRANSLATED_TITLE_INPUT_SNAPSHOT) snapshot pool at Dispatch record, once draw:2890-2902, cdisp:1514-1519 stale if the application writes before execution; 128 MiB pool
7 Copy-source snapshot (X2W_D3D12_TITLE_COPY_SNAPSHOT) snapshot pool at record, up to 64 KiB list_copy.inl:214-226 GPU writes into the source are not seen
8 Linear buffers (X2W_D3D12_LINEAR_BUFFERS, #2218) application memory if shared, else desktop copy at ExecuteCommandLists linear_buffer_backing.h:3-30, linear_buffer_backing.h:473; hooks :5462, :5553 COMMON state only; no copy for GPU-written buffers (linear_buffer_backing.h:106-107); a write after submission is not seen (#1914)
9 XMem section lease (X2W_MESH86_XMEM_SRV, X2W_MESH_INDIRECT_XMEM; #2280, #2303) XMem pages GPU copy, ordered by fence mesh_xmem_handoff.inl:6-12, mesh_xmem_handoff.inl:204 one writer, one reader, a known range
10 Memory SRV, slot 70, unplaced application memory if private, else a committed UPLOAD buffer at view creation, recopied on reuse d3d12_memory_srv.inl:358-372, d3d12_memory_srv.inl:399-449, d3d12_memory_srv.inl:336-343 entries are erased only when the device is cleared (d3d12_memory_srv.inl:279-297)
11 List upload memory, slot 148 D3D12 upload memory handed to the application no copy list_upload_pages.h:24-37 only for memory D3D12 allocates
12 Page alias on demand (X2W_TRANSLATED_INDIRECT_ADDRESS_ALIAS) application memory no copy :6465-6500 private page outside any placement, heap already open, 64 entries

Two rules sit above the table. Map and GetGPUVirtualAddress return the application's own memory and address when the resource has them (:5710-5725, :5737-5746). The desktop objects stay alive for the process unless X2W_D3D12_RELEASE_RETIRED=1 (:1239-1241, #2379), and buffers are outside that class (:1068).

Not wired into the stand-in: src/era_gpu_alias.h (one buffer over a whole allocation), src/era_title_va.h, src/era_title_gpu.h, src/title_va_lookup.hlsli.

Observed gaps

One start-up run of 900 s on one adapter, aggregate counts only.

Measured

Read from the code

Inferred, not confirmed

  • The removal comes from input bytes that changed between record and execution. The two byte states were not logged.
  • The 7,600 unaligned buffers are in private, fully committed memory and miss sharing only because of the 64 KiB rule: the region-information proof counter (:6618) matches their number, but the default log line prints neither the memory type nor the reason. design: runtime model for the console's unified CPU/GPU memory (copies vs direct use of title memory) #1914 says "mostly mapped sections" and its field report says "the rest fail the 64 KiB offset rule"; both classes exist, the second by count and the first by bytes.
  • The 135 large buffers are XMem views.
  • Row 10's UPLOAD fallback is a candidate for the UPLOAD count: about 85 KiB per object on average. The budget line has one upload category (resource_budget.h:9, resource_budget.h:156), so it cannot say.

Proposed work items

Each is one small PR with a source-built test. Comment here to claim one.

Already taken, do not duplicate

a. Snapshot at submission (row 6). A PR is in preparation. Reserve at record, copy in queue_execute before ExecuteCommandLists (:5486-5493), under the draw_lock already held there.

// record (cdisp:1514): reserve only
auto* mapped = reserve_upload_ring(self, bytes, &view.offset, &view.resource, true);
pass_of(self).pending_snapshots.push_back({view.snapshot_address, mapped, bytes});
// queue_execute, each submitted list, each submission
for (const auto& s : pass_of(w).pending_snapshots)
    if (!x2w_local::guarded_memcpy(s.mapped, reinterpret_cast<const void*>(s.address), s.bytes, false))
        skip_list(w);  // a closed list resubmitted later copies again
  • Test: write A, record, write B, submit; the GPU reads B. A mutant that copies at record fails.
  • Success: no device removal in the run above with the program included.

b. Placement and read-path census. Add range.type and the refusal reason to the default slot 133 line (:6733-6735), as the linear line already does (:6646-6650). Add a five-second line next to :8679:

x2w-d3d12 placed buffers by backing: shared N/bytes, unaligned N/bytes, mapped N/bytes, uncovered N/bytes, create-failed N/bytes (gpu-written N/bytes of each)

c. Split the upload budget category by creator (follow-up to #3491). Creators on main: ring and snapshot pool (:3153), slot 27/127 committed (:1161, :8167), slot 70 fallback (d3d12_memory_srv.inl:449), slot 148 pages (list_upload_pages.h:37), linear staging (linear_buffer_backing.h:1158), Mesh86 cache (mesh86_cache.inl:490).

  • Test: the budget fixture creates one of each and checks its column.
  • Success: the 16,000 objects are attributed.

d. One adapter-facts line at start-up. src/, tools/ and tests/ have no D3D12_FEATURE_ARCHITECTURE query.

D3D12_FEATURE_DATA_ARCHITECTURE1 arch{};
D3D12_FEATURE_DATA_EXISTING_HEAPS heaps{};
device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE1, &arch, sizeof(arch));
device->CheckFeatureSupport(D3D12_FEATURE_EXISTING_HEAPS, &heaps, sizeof(heaps));
log("x2w-d3d12 adapter facts: uma=%d cache_coherent_uma=%d existing_heaps=%d local=%llu nonlocal=%llu", ...);
  • GPU upload heap support can be added where the SDK headers expose it.
  • Test: the line appears once on WARP with existing_heaps=1.
  • Success: reports state per adapter whether sharing is possible, and row 1 can refuse before any open.

e. Design proposal, for the maintainer to accept or reject: one desktop buffer per existing heap. For a buffer below 64 KiB at an unaligned offset in an allocation whose heap is open, stop creating a fallback. Keep one buffer over the heap, as era_gpu_alias does, and give the placement an offset.

struct HeapBuffer { ID3D12Heap* heap; ComPtr<ID3D12Resource> whole; };  // one per existing_heaps entry
// slot 133: (offset & 0xFFFF) != 0, range covered, MEM_PRIVATE, Width < 64 KiB
w->own().real = heap_buffer.whole.Get();
w->own().real_offset = offset;  // every user of `real` adds it
  • Open points: each wrapper is one desktop resource today (states, views, GetDesc); state tracking becomes per heap; GPU reads go to system memory.
  • First PR is the fixture only: two placements in one heap buffer, CPU write and GPU write visible both ways, overlapping ranges, on WARP and hardware.
  • Success: rows 4 to 6 no longer copy these ranges, and the fallback count in (b) drops.

f. Measure before coding.

Hardware

Recommendations, not measured.

Refs #1914, #3640, #3474, #2379, #3639

Activity

  1. Not-Saii commented on Dec 1, 2026

    @Not-Saii
    Contributor

    Claiming (b) placement and read-path census.

    Environment: Windows 11 build 26300, NVIDIA GeForce RTX 4090 (driver 32.0.16.1088), Windows SDK 10.0.26100, plus WARP.

    Scope: add range.type and the refusal reason to the default slot 133 placement line, and a five-second x2w-d3d12 placed buffers by backing line (shared / unaligned / mapped / uncovered / create-failed, count and bytes, with the GPU-written share of each). Test: a source-built fixture that places one buffer of each class on WARP and checks the counters, with a negative control that misclassifies one class. Logging and counters only; no change to which path a placement takes. Leaves (a), (c), (d) and (e) alone. PR will target main.

  2. legacy-code-archaeologist commented on Dec 1, 2026

    @legacy-code-archaeologist
    Contributor

    Claiming (d) one adapter-facts line at start-up.

    Environment: Windows 11 Pro 10.0.26100, in-box WARP (the hardware adapters here are an NVIDIA Quadro M1000M at D3D12 FL 11_0 and an Intel HD 530), VS 2026 BuildTools, Windows SDK 10.0.26100.

    Scope: query D3D12_FEATURE_ARCHITECTURE1 and D3D12_FEATURE_EXISTING_HEAPS once where the runtime creates its desktop device. Log one x2w-d3d12 adapter facts: line with uma, cache_coherent_uma, existing_heaps, and the local and non-local video memory from the adapter. A fixture will check that the line appears exactly once on WARP with existing_heaps=1. Rows 1–2 are not changed in this PR.

    AI-assisted.

  3. RomainROCH commented on Dec 1, 2026

    @RomainROCH

    For item (e), an independent MIT-licensed D3D12 fixture provides a preliminary check of the proposed single-buffer geometry (not a claim or a runtime integration).

    On Windows 11 build 26100, system WARP 10.0.26100.9818, one placed buffer over an existing 64 KiB heap exposes two overlapping logical byte ranges. CPU-to-GPU visibility passes, and after an explicit fence both GPU readback and direct CPU observation return 10111213a0a1a2a3a4a5a6a7. The one-byte shifted-write negative control fails both post-fence checks (exit 2). On this particular shared cross-adapter heap, omitting the resource cross-adapter flag also returns E_INVALIDARG despite existing-heaps support.

    Reproduction commands and scope · Raw log

    This covers one queue and logical subranges, not two runtime placement wrappers, resource-state integration, physical adapters or Windows 10. It may be useful as an independent control for the proposed fixture.

    Physical adapter follow-up for (e). On Windows 11 build 26100 and in-box D3D12 10.0.26100.9818, a GTX 970M (driver 32.0.15.8253) reproduced the WARP bytes in the original 64 KiB fixture. An Intel HD Graphics 530 (31.0.101.2115) reported feature level 12.1 and EXISTING_HEAPS=0, so the test skipped it before allocation or queue submission.

    WARP and the GTX both passed a DIRECT → COPY → DIRECT handoff with explicit fences and COMMON at each handoff. After the final fence and release, recommitting the same virtual address returned zeroed backing. The second generation read 50515253e0e1e2e3e4e5e6e7 through both paths. Shifting that write by one byte failed both checks while the first generation stayed clean. The scope is two logical ranges inside one buffer.

    Reproduction and capability matrix · Raw output

  4. lukaslw-lab commented on Dec 1, 2026

    @lukaslw-lab
    Contributor

    Data point for row 12 / the uncovered class, from one native Mesh86 run (main 1c634037, X2W_REFUSE_FIXED_MESH=1, X2W_NATIVE_MESH86=1, 600 s, row 12 alias off):

    Two Mesh86 pipelines are refused at binding for a mesh t0 read through a descriptor table, root 1 at table offset 0x40, 8 bytes needed:

    x2w-mesh86 native <key>: indirect command refused (mesh_bind): an input is in title memory outside any placed buffer
    

    The descriptor's address is in application memory that no placement covers. This is not the #3640 shape (root 0, 0xAC0, a 174 MiB placed buffer). The same run's census line ends at uncovered 50/1094444, so these may be among those 50. Log lines are capped, so the counts are samples.

    I haven't tried X2W_TRANSLATED_INDIRECT_ADDRESS_ALIAS on it yet. Counts only.

    AI-assisted.

  5. SimSalabimse commented on Dec 1, 2026

    @SimSalabimse
    Contributor

    I'll take (c): split the upload budget category by creator (upload ring / snapshot pool, slot 27/127, slot 70 fallback, slot 148 pages, linear staging, Mesh86 cache, plus an explicit other bucket so totals don't change). Each creator gets its own column in the budget log and in startup_resource_budget, with a sum check against the old total. I'll keep it clear of #3491's report line. Fork first, then a PR, plus a test-PC game run so we can see who owns the ~16,000 UPLOAD objects.

    AI-Assisted

  6. SimSalabimse commented on Dec 1, 2026

    @SimSalabimse
    Contributor

    I'll take the GPU-to-CPU half of (f): counters for Map calls on READBACK-heap resources, copies and resolves whose destination has application memory, and the refusals of those destinations (ResolveQueryData already refuses "destination has title memory"; Copy* currently forwards them). Logging and counters only; the #3640 top-10 GPU-written buffers stay with that trace. A source-built fixture will exercise each class, and a test-PC game run will show whether any count is non-zero (a follow-up issue only if so).

    AI-Assisted

  7. timbot103 commented on Dec 1, 2026

    @timbot103
    Contributor

    Claiming item (e) first PR (standalone fixture only): one desktop placed buffer over an existing 64 KiB+ MEM_PRIVATE heap exposing two unaligned overlapping logical buffer ranges, verifying bidirectional CPU->GPU and GPU->CPU visibility plus negative controls on both WARP and hardware (no runtime integration yet, per the design proposal above).

    Environment: Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100, NVIDIA GeForce RTX 5080 (driver 621.40) + WARP.

    AI-assisted.

  8. timbot103 commented on Dec 1, 2026

    @timbot103
    Contributor

    The standalone D3D12 fixture for item (e) (no runtime integration) is up in #3723.

    Verified in both Debug and Release on WARP (10.0.26100.9818) and NVIDIA GeForce RTX 5080 (32.0.16.2140, Windows 11 26200, D3D12_FEATURE_EXISTING_HEAPS=1; D3D12 debug layer unavailable on this host, 0x887a002d): CPU→GPU, GPU→CPU, GPU→GPU UAV-barrier echo, and displaced-offset negative control (--offset-control / --corrupt-offset exit code 3) all pass on both adapters.

    AI-assisted.

  9. added 2 commits that reference this issue on Dec 2, 2026
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