startup-runtime: every non-aliased placed buffer keeps its own committed buffer for the process, and re-placing the same address adds another #3476
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#3476
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Leyukaka on GitHub · 2026-11-29 16:27 UTC · original
Commit
mainat36914379. Line numbers below are insrc/startup_stubs/d3d12_xs_device.cppat that commit.What the code does
device_place_resource_x(device slot 133) aliases guest memory only when the offset in the allocation is 64 KiB aligned, the range is covered and the allocation isMEM_PRIVATE(:5933-5936). Otherwise, or whenCreatePlacedResourcefails, it creates a committed default-heap buffer per call (:5970-5975, loggednot aliased). Nothing looks for an earlier buffer at the same address.release()(:1068-1094) removes the placement from the index (retire_placement) and ends its budget use, but keeps the desktop object: "The wrappers and their desktop objects stay alive for the process" (:1045).X2W_D3D12_RELEASE_RETIRED=1, is off by default and excludes buffers:retire_classifyreturnsRetireNever::buffer(:889) andpublish_placed_buffersets the same reason (:5767).D3D12 sizes a committed buffer in 64 KiB units, so each non-aliased placement holds at least 64 KiB until the process exits, whatever its width, and placing the same address again after a Release allocates a second one.
Measured
One long local run of the application (about 20 min), slot 133
not aliasedplacements, sizes rounded up to 64 KiB:The count did not level off. At the last sample 14,826 of the buffers are 8 bytes wide (0.9 GiB at 64 KiB each), and about 4,000 were created at an address that an earlier placement had already used. Aliased placements stayed at 56. Shorter runs ended near 3,975 buffers (1.1 GiB).
#2379 covers the same retention for committed textures; its retirement slices leave buffers out, and the reason counter there reported them as
never-class:buffer(8,178 buffers / 0.55 GB in one run, 5,163 / 339 MiB in another).Proposal
Aliased placements are not touched.
initial_state.retire_resource/drain_retired_resources,:6238,:6280): the release-time fence of every queue has passed, no list or submission holds it, and no tracked descriptor names it (retire_view_refs). The rule from #2379 stays: a live descriptor owns the resource until its slot is overwritten or its heap is destroyed. Todayretire_holdis taken for copies and texture binds only; a list that resolved a placed buffer by address (vertex, index, root and memory-SRV paths) takes no hold. A buffer would enter the class only where each such use records a hold, and stay retained otherwise. Opt-in, underX2W_D3D12_RELEASE_RETIRED.Test: a synthetic fixture that places and releases the same small unaligned buffer N times and checks that the number of live committed fallbacks stays bounded, with controls that a buffer named by a recorded or in-flight list, or by a live descriptor, is still readable after its Release, and a mutant that frees early.
Not covered: non-aliased placements that are never released, and the wrapper storage, which stays.
I'm working on this.
@lukaslw-lab on GitHub · 2026-11-29 16:57 UTC · original
Same class here, and one data point for proposal 2 before it is built.
On a 360 s startup run I had 9,182 copied 64 KiB placed buffers (0.60 GB by count), close to your 319 s row. I prototyped your step 2 locally: these buffers joined the retire class at final Release, waited for list holds, release fences and
retire_view_refs, and were freed by the drain. Result: 19,527 freed over two runs, 0 late reads, no device removal, but no measurable memory change:A fresh buffer freed the same way drops DXGI local at once, so the long-released ones are probably already evicted, and count × 64 KiB may overstate what the process pays. Logging
QueryVideoMemoryInfolocal / non-local and the process commit next to the count at your 928 s and 1,237 s points would show it: if they grow with the count, step 1 (reuse) is the part that pays off.On an older
mainI also listed the readers that bind a copied buffer without aretire_hold(the ExecuteIndirect index view, root CBV/SRV at draw, vertex/index views, copies). I can re-check them on currentmainand post the list with line numbers.@Leyukaka on GitHub · 2026-11-29 17:24 UTC · original
Reuse (step 1): I prototyped it on a branch, not opened as a PR. Our own check of it estimated that it would reuse few buffers: every shim use of a copied fallback goes through
placed_buffer_rangefirst, and after that the buffer is not eligible.A later long local run with the budget line on: local video memory went over budget from about 166 s. At the end textures were about 72% of it, about 6.5 GiB of them retained after the application released them (#2379's area). The 64 KiB placed-buffer fallbacks were about 401 MiB (6,360 retained).
So the placed buffers are a small share of it, which fits your A/B, and I will not open the reuse PR.
A
QueryVideoMemoryInfolocal / non-local and process commit line next to the buffer count is useful. I will add it as a diagnostic PR (Refs #3476) unless you prefer to do it.Yes to the re-check of the readers that bind a copied buffer without a
retire_holdon currentmain; please post the list with line numbers here.@lukaslw-lab on GitHub · 2026-11-30 00:41 UTC · original
Readers of a copied placed buffer (
Placement::copied_buffer, found throughplaced_buffer_range) onmain2ff74a6a, by reading. These are what a copied-buffer retire class would have to hold.No hold (neither
retire_holdnorretain_with_recording):srv … root)compute_root_srv_buffer,d3d12_compute_dispatch.inl:653-660(whenlist_copied_gpu_range):845; the only holds there are textures (:899) and tokens (:1104)indirect_table_buffer,d3d12_draw.inl:2692-2697d3d12_draw.inl:3482(buffer_view);d3d12_compute_dispatch.inl:1029,:1235list_execute_indirect,d3d12_xs_device.cpp:4114-4121(any placement, no alias check):4165(IASetIndexBuffer)d3d12_xs_device.cpp:4093-4099:4099placed_as_buffer,d3d12_memory_srv.inl:666-680:690; a descriptor, so it outlives any one recording: it needs a view ref, not a list holdresolve_placed_build,d3d12_xs_device.cpp:8365-8373Already held: fixed vertex views (
d3d12_draw.inl:2953), the draw index and table aliases (:3296,:3550, aliased buffers only), slot-57 mesh buffers (native_mesh57.inl:193), and copies (list_copy.inl:282-283).Go ahead with the
QueryVideoMemoryInfodiagnostic PR.