gpu: cap slot 133 existing heaps at 256 MiB and grow upload ring on demand #2767
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2775"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T07:42:12Z.
Grows
reserve_upload_ringincrementally from16 MiB, deferscommit_lazy_blockuntil an existing heap is opened (supporting nonzero 64 KiB-aligned offsets in lazy startup blocks), and adds an opt-in 256 MiB cap onslot 133OpenExistingHeapFromAddress. Fixes #2765. Refs #1199, #874.What changed
src/startup_stubs/d3d12_xs_device.cpp&src/startup_stubs/linear_buffer_backing.h(X2W_D3D12_CAP_EXISTING_HEAP=1, opt-in): the 256 MiB existing-heap cap is opt-in. The default keeps the formerly aliased path for >256 MiB private allocations, because a capped copied placement is refused byCopyBufferRegion(slot 15) astitle_backed_sourceand would lose a late guest write. With the cap on, allocations above 256 MiB (or unknown size) skipOpenExistingHeapFromAddressto avoid pinning multi-GiB blocks inWorkingSetSize/NonLocal.src/startup_stubs/placed_buffer_range.h(can_commit_lazy_placed_buffer): validatesaddress != nullptr,width > 0,VirtualQueryMEM_COMMIT+MEM_PRIVATE+ non-nullAllocationBase, 64 KiB offset alignment, allocation size within the cap (unbounded by default), and overflow-safe containment, then commits an eligible lazy block and re-measures so a nonzero aligned offset with aMEM_RESERVEprefix aliases. Out-of-bounds, unaligned,MEM_MAPPED, and acceleration-structure placements are never committed.reserve_upload_ring(d3d12_xs_device.cpp/d3d12_draw.inl): replaced the eager256 MiBupload allocation with chunked on-demand growth (UploadRingChunk: 16 MiB start, doubling to a 256 MiB total cap, chunks kept alive, returning(ID3D12Resource*, offset)).tests/startup_slot133_heap_cap_check.cpp+tests/cmake/startup_slot133_heap_cap.cmake: WARP + hardware CTests. Default (_debug0/_debug1): the 260 MiB placement aliases and a guest slot-15CopyBufferRegionobserves a late CPU write (0x2a->0x59before submit, fenced readback, all 65,536 bytes). Capped (_capped_warp/_capped_hardware,X2W_D3D12_CAP_EXISTING_HEAP=1): the 260 MiB copied fallback (heap 0/0, untouchedMEM_RESERVE), the 4 MiB + 64 MiB (+2 MiB) alias with late A-to-B readback, unaligned/out-of-bounds negative controls, and 16 -> 48 MiB ring growth.docs/startup-runtime.md: documents the opt-in cap and itstitle_backed_sourcelate-write rationale,can_commit_lazy_placed_buffer, and the 16 MiB ring growth.Verified (
1238de62, rebased on4bbe52ee)Run on Microsoft Basic Render Driver (WARP
10.0.26100.9818) and NVIDIA GeForce GTX 1660 SUPER (32.0.16.1074): default and capped variants both PASS.Fail-first mutants (temporary, reverted):
cap_existing_heap = trueby default: default late-write fails (65536 of 65536 readback bytes are not 0x59, sentinel0x6d;CopyBufferRegion skipped: title_backed_source).can_commit_lazy_placed_buffer+commit_lazy_block: capped variant fails64 MiB <= 256 MiB lazy block buffer is aliased.initial_chunk_bytes = u64{256} << 20: failsfirst upload reserves 16 MiB / 1 chunk (not 256 MiB).NOT established
_debug1CTests skipped (77) on this host without D3D12 SDK Layers.sync_title_source) can preserve late writes — a separate follow-up.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:47:41Z.
Review: COMMENTED
Review of head
f6a5bdb0(comment only, no approval).Code read
reserve_upload_ringnow keeps a list of chunks (16 MiB first, doubling, 256 MiB total). Old resources stay alive, so earlier GPU addresses stay valid. All callers ind3d12_draw.inlpass the chunk resource; I found no leftover use of the oldupload_ring.commit_lazy_blocknow runs only right before an existing heap is opened, and the 256 MiB cap matchesslot 70.Commands run
git diff --check origin/main...HEAD: cleanpython3 -B tests/docs_links_check.py: 23 files, 535 links okpython3 -B tests/bidi_controls_check.py: okWin2025 WARP (Build 26100), dev and release
d3d12_xs_shim startup_slot133_heap_cap_check startup_stream_consumer startup_resource_budget startup_resource_retire startup_placed_buffer_range_check^(startup_slot133_heap_cap|startup_placed_|startup_resource_budget|startup_resource_retire_warp|startup_linear_buffers)100% tests passed out of 20in dev and in release (7*_debug1skipped: no SDK Layers). The new tests ran:startup_slot133_heap_cap_warp_debug0,startup_slot133_heap_cap_hardware_debug0,startup_slot133_heap_cap_unbounded_warp.Merge
The PR says it fixes a blocker seen in a startup workload (#2765). We cannot check that on the game, so the merge is left to MasterDomino or @R0Y00, who can verify it there. Fixture results above are not executable results.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T07:42:20Z.
Codex Review Summary: ❌ Failed
This comment shows the latest Codex review activity on this pull request.
We couldn’t complete this review. Comment
@codex reviewto try again.f6a5bdbℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T07:42:23Z.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:56:23Z.
I reproduced a small-block alias regression at
f6a5bdb0. In startup_slot133_heap_cap_check.cpp, change the existing 64 MiB case from mid_block to mid_block + 2 * mib and leave the allocation lazy. This is aligned and below the cap, but both WARP and RTX 4060 Laptop debug1 fail at "64 MiB <= 256 MiB lazy block buffer is aliased". The zero and 64 KiB offsets pass because their commit granule includes the base.The span-only commit leaves a reserved prefix at 2 MiB. measure_placed_buffer therefore sets covered=false, so the heap-open branch rejects it before that branch can commit the lazy block. In an isolated order control, committing the eligible small block before measuring restored 2/2 passes while the existing 260 MiB case still kept its untouched range reserved. Please check alignment, allocation size and containment before committing an eligible small block, then remeasure. Keep the nonzero offset control and the late A-to-B readback from #2765. This is separate from ring growth.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T08:25:11Z.
Review: CHANGES_REQUESTED
I reran the exact
02b4085efixture with MSVC Debug and Release on Windows 11 build 26200. All five cases passed in each configuration, including the +2 MiB in-bounds alias, the alignment and bounds controls, and the 16→48 MiB ring growth. The small-block regression is fixed.There is a separate compatibility blocker in the new default cap. I extended only the source-built fixture: place an aligned 64 KiB buffer in the existing 260 MiB startup allocation, fill it with 0x2a, record guest list slot 15 CopyBufferRegion to a readback buffer primed with 0x6d, close the list, then change the guest source to 0x59 before submitting. Wait on the same queue's fence and check all 65,536 bytes.
WARP 10.0.26100.9818 and NVIDIA 32.0.16.1656, debug layer enabled. With the cap, slot 133 reports success with a copied buffer, but slot 15 skips it as
title_backed_source. The unbounded control keeps the real alias and observes the late write. This is a synthetic guest API regression, with no original EXE claim.Please keep the cap opt-in until the capped consumer can preserve the same copied-buffer contents, or keep the formerly aliased path for this case. The ring growth can land separately. Please keep the +2 MiB alias fix and the existing memory-budget checks with the scoped cap, and add the 260 MiB late-write followed by fenced readback above.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T08:12:26Z.
Fixed the nonzero-offset lazy-block aliasing regression at
02b4085e(rebased ontomain624f5927):src/startup_stubs/placed_buffer_range.h(can_commit_lazy_placed_buffer): checksaddress != nullptr,width > 0,VirtualQuery(address)returnsMEM_COMMITwithMEM_PRIVATEand non-nullAllocationBase, 64 KiB alignment ((start - base) % 0x10000 == 0), allocation size<= unplaced_max_span(256 MiB, unlessX2W_D3D12_UNBOUNDED_EXISTING_HEAP=1), and overflow-safe containment within the allocation before committing an eligible small lazy block.src/startup_stubs/d3d12_xs_device.cpp&src/startup_stubs/linear_buffer_backing.h: when!range.covered && !range.region_info && range.type == MEM_PRIVATE(because a[AllocationBase, address)prefix in a<= 256 MiBlazy startup block is stillMEM_RESERVE), verifiescan_commit_lazy_placed_buffer(...), callscommit_lazy_block(address), and re-runsmeasure_placed_bufferbefore opening the existing heap. Out-of-bounds, unaligned,MEM_MAPPED, acceleration-structure, and> 256 MiBblocks are never committed.tests/startup_slot133_heap_cap_check.cpp: moved the64 MiBlazy startup block case to nonzero offsetmid_block + 2 * mib(with[0, 2 MiB)MEM_RESERVE), verifiedexisting_heapaliasing + late CPU A-to-B write GPU readback, and added unaligned (+2 MiB + 0x100) and out-of-bounds (+64 MiB - 64 KiB,128 KiBwide) negative controls on a fresh64 MiBlazy block alongside the260 MiB(> 256 MiB) cap test.Verified on
02b4085e(devpreset):ctest --preset dev --no-tests=error -R '^(startup_slot133_heap_cap|startup_placed_|startup_resource_budget|startup_resource_retire_warp|startup_linear_buffers)' --output-on-failure: 13 passed, 7 skipped (*_debug1: SDK Layers not installed), 0 failed (startup_slot133_heap_cap_warp_debug0,startup_slot133_heap_cap_hardware_debug0,startup_slot133_heap_cap_unbounded_warpall passed).can_commit_lazy_placed_buffer+commit_lazy_blockind3d12_xs_device.cpp): failedFAIL: 64 MiB <= 256 MiB lazy block buffer is aliasedon both WARP and GTX 1660 SUPER.Also ran a combined local title diagnostic run (
main+#2773+#2775with-LazyMemoryandX2W_D3D12_LAZY_TEXTURES=1) over 300.06 s / 6,434 frames / 3,260 storage requests: host commit peak dropped from12,144 MiBon baselinemaindown to8,787 MiB(-3,357 MiB/-3.28 GiB), andNonLocaldropped from2,897 MiB(2,199 MiBexisting heaps) down to695 MiB(0 MiBexisting heaps).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T08:59:34Z.
Addressed the verified late-write regression at
1238de62(rebased onmain4bbe52ee).Resolution — the cap is now opt-in.
X2W_D3D12_CAP_EXISTING_HEAP=1gates the 256 MiB existing-heap cap; the default keeps the formerly aliased path, so a >256 MiB private placement still opens an existing heap and stays authoritative. This is the "keep the cap opt-in until the capped consumer can preserve the same copied-buffer contents" route: a capped copied placement is refused byCopyBufferRegion(slot 15) astitle_backed_source(list_copy.inlsync_title_sourcereturns true only forPlacement::aliased_buffer), which loses a late guest write. The oldX2W_D3D12_UNBOUNDED_EXISTING_HEAPswitch is removed.Kept as requested:
can_commit_lazy_placed_bufferfix (now commits an eligible lazy block of any size by default, capped at 256 MiB only with the opt-in).reserve_upload_ringgrowth and the memory-budget checks, exercised under the scoped cap variant.Added your exact 260 MiB late-write case (default variant): aligned 64 KiB buffer at +0 in the 260 MiB allocation, fill
0x2a, guest list slot 15CopyBufferRegioninto a readback buffer primed0x6d, close the list, change the guest source to0x59before submit, wait the same queue's fence, assert all 65,536 bytes ==0x59. The default alias observes the late write; the cap-on mutant reproduces the sentinel loss.Verified (
1238de62, dev preset, WARP10.0.26100.9818+ GTX 1660 SUPER32.0.16.1074):ctest --preset dev --no-tests=error -R '^(startup_slot133_heap_cap|startup_placed_|startup_resource_budget|startup_resource_retire_warp|linear_buffer_backing)': 51 tests, 0 failed (7*_debug1capability-skips, no SDK Layers). Default andcapvariants both PASS on WARP and hardware;linear_buffer_backingfamily 30/30.cap_existing_heap = trueby default -> default late-write fails65536 of 65536 readback bytes are not 0x59 (first at offset 0 = 0x6d ...)withCopyBufferRegion skipped: title_backed_source; (b) skip the pre-measurecommit_lazy_block-> cap variant fails64 MiB <= 256 MiB lazy block buffer is aliased.docs_links_check.py(24 files / 540 links),bidi_controls_check.py(2026 files),git diff --check: clean.Trade-off / follow-up: with the cap opt-in, the default no longer skips multi-GiB
OpenExistingHeapFromAddresspins, so that portion of the #2765 commit saving is gated until the copied-buffer consumer can preserve late writes. Makingsync_title_sourcerefresh a copied title-backed buffer from its title memory before the copy (the linear-buffercopied at submitmechanism) is the follow-up that would let the cap become default again; I can take that as a separate PR. The ring growth and the on-demandcommit_lazy_blockremain default.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T09:22:32Z.
Review: APPROVED
Rechecked exact
1238de62on Windows 11 build 26200, MSVC Debug and Release (/O2), WARP 10.0.26100.9818 plus RTX 4060 Laptop 32.0.16.1656.ctest --preset <dev|release> --no-tests=error -j 1 -R '^startup_slot133_heap_cap_' -Vpassed 6/6 in each configuration, zero skips. With the cap unset, guest slot 15 read all 65,536 bytes written after Close through the 260 MiB alias. With the explicit cap enabled, the fixture checked the separate fallback, untouched pages, +2 MiB small-block alias and 16→48 MiB upload-ring growth. The documented default preserves the case that blocked the previous head. This resolves my review on source-built coverage.