d3d12: support unplaced buffer memory SRVs in device slot 70 #2387
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2395"
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 Holastor on 2026-11-25T15:10:06Z.
Summary
Device slot 70 (
device_memory_srvind3d12_xs.dll) creates shader resource views from raw memory addresses. Previously, buffer SRVs required an existing placed buffer wrapper registered via slot 133 (CreatePlacedResourceX) or committed buffer via slot 127 (CreateCommittedResource). When an SRV was requested for raw or sub-allocated buffer addresses that were not explicitly placed via slot 133 (for example dynamic buffers or direct allocations in title memory heaps), calls were refused withbuffer_unavailable.This change adds backing for unplaced buffer memory SRVs:
unplaced_buffer_extentcalculates 64 KiB page-aligned extents and spans with arithmetic overflow checks and a 256 MiB sanity limit.unplaced_memory_buffervalidates committed coverage viameasure_placed_bufferand verifies no conflicting placed aliases exist inplaced_buffer_range.D3D12_FEATURE_EXISTING_HEAPSforMEM_PRIVATEmemory, it opens the existing allocation heap viaOpenExistingHeapFromAddressand creates a placed resource alias at the page-aligned offset.D3D12_HEAP_TYPE_UPLOADand synchronizes memory via hostmemcpyboth at creation and upon reuse.clear_unplaced_buffers).--mutate unplaced-extent,--mutate unplaced-covers) tostartup_memory_srv_buffer_check, and leavesbuf1unplaced indraw_address_buffer_srvsto test unplaced buffer sampling on WARP and hardware instartup_address_buffer_srv_{warp,hardware}.Verification
Commands executed locally (Windows 11 Build 26100, MSVC 19.51, AMD Radeon RX 6600M driver 32.0.21045.11001):
Output:
startup_memory_srv_buffer: Passedstartup_memory_srv_buffer_height_control: Passed (negative control failed as expected)startup_memory_srv_buffer_exact-fit_control: Passed (negative control failed as expected)startup_memory_srv_buffer_first-32_control: Passed (negative control failed as expected)startup_memory_srv_buffer_unplaced-extent_control: Passed (negative control failed as expected)startup_memory_srv_buffer_unplaced-covers_control: Passed (negative control failed as expected)startup_address_buffer_srv_warp: Passed (warp: buffer memory SRV (raw base, raw interior, unplaced buffer, structured, refused unaligned, refused acceleration structure view) exact)startup_address_buffer_srv_hardware: Passed (hardware: buffer memory SRV (raw base, raw interior, unplaced buffer, structured, refused unaligned, refused acceleration structure view) exact)All passed cleanly.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:16:37Z.
Review: COMMENTED
Review of head
2794451c(device slot 70: backing for buffer memory SRVs that are not placed in slot 133/127).Checked (diff against origin/main):
unplaced_memory_bufferind3d12_memory_srv.inlis only reached whenexisting_memory_bufferfinds nothing, so placed and committed paths are unchanged.address_resource_overlap,unplaced_buffer_extent(64 KiB page extent, overflow checks, 256 MiB cap),measure_placed_buffer(...).covered, andplaced_buffer_range(no alias conflict).unplaced_buffer_covers, then the committed status is re-measured. Upload-backed entries are re-copied on every hit, so the view sees title writes. Lock order is the same everywhere (unplaced_buffer_mutex, thenplaced_mutex).clear_unplaced_buffersis called when the device wrapper reachesrefs == 0and drops the budget tickets and the wrapper reference.FirstElement = (address - base) / element_bytes.startup_memory_srv_buffercovers the two new pure helpers (extent, cover) and has two new negative controls (unplaced-extent,unplaced-covers) registered in CMake.startup_address_srv.cppnow leavesbuf1unplaced (a realVirtualAllocpage), so the existingstartup_address_buffer_srv_*WARP run reads the buffer back through an unplaced SRV and compares exact bytes.docs/startup-runtime.mdmatch the code, and the check list there is updated.Notes (not blocking):
D3D12_FEATURE_EXISTING_HEAPSand is not reachable on WARP, so only the upload fallback is checked by the WARP run.I found no correctness bug. Win2025 WARP dev and release run follows.
AI-assisted; commands listed were executed locally (
python3 merge_check.py 2395,gh pr diff 2395,gh pr list --state all --search).Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:08:04Z.
APPROVED. Unplaced buffer memory SRVs in device slot 70.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:22:16Z.
Win2025 WARP receipt for head
bc6fa004after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
bc6fa0045d3e39f6f12b9e333a5c127bf3d09028:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):3.34s(configure0.00s)ctest --preset dev -R 'startup_memory_srv_buffer|startup_address_buffer_srv|startup_address_srv|startup_memory_srv' --parallel 6 --no-tests=error --output-on-failure): 24/24 passed (1.29s:startup_memory_srv_diag_hardware0.66s,startup_address_srv_warp0.67s,startup_memory_srv_diag_supported_control_warp0.69s,startup_memory_srv_census0.02s,startup_memory_srv_as0.02s,startup_memory_srv_buffer_exact-fit_control0.01s,startup_memory_srv_buffer0.01s,startup_memory_srv_as_alignment_control0.01s,startup_memory_srv_buffer_first-32_control0.01s,startup_memory_srv_report0.01s,startup_memory_srv_as_offset_control0.01s,startup_address_buffer_srv_hardware0.75s,startup_memory_srv_as_state_control0.02s,startup_memory_srv_buffer_height_control0.02s,startup_memory_srv_buffer_unplaced-extent_control0.02s,startup_memory_srv_diag_warp0.79s,startup_memory_srv_buffer_unplaced-covers_control0.03s,startup_memory_srv_volume0.03s,startup_memory_srv_volume_layout_control0.02s,startup_memory_srv_volume_2d-view_control0.02s,startup_memory_srv_volume_3d-view_control0.02s,startup_memory_srv_volume_mips-overflow_control0.01s,startup_address_buffer_srv_warp0.84s,startup_address_srv_hardware0.51s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):1.38s(configure0.00s)ctest --preset release -R 'startup_memory_srv_buffer|startup_address_buffer_srv|startup_address_srv|startup_memory_srv' --parallel 6 --no-tests=error --output-on-failure): 24/24 passed (1.17s:startup_memory_srv_buffer_first-32_control0.02s,startup_memory_srv_as0.02s,startup_memory_srv_report0.02s,startup_memory_srv_as_alignment_control0.02s,startup_memory_srv_buffer_height_control0.02s,startup_memory_srv_buffer0.02s,startup_memory_srv_buffer_exact-fit_control0.02s,startup_memory_srv_as_state_control0.02s,startup_memory_srv_as_offset_control0.02s,startup_memory_srv_census0.02s,startup_memory_srv_buffer_unplaced-extent_control0.02s,startup_memory_srv_buffer_unplaced-covers_control0.02s,startup_memory_srv_volume0.02s,startup_memory_srv_volume_layout_control0.02s,startup_memory_srv_volume_2d-view_control0.02s,startup_memory_srv_volume_3d-view_control0.02s,startup_memory_srv_volume_mips-overflow_control0.02s,startup_address_srv_hardware0.60s,startup_address_srv_warp0.61s,startup_address_buffer_srv_warp0.62s,startup_memory_srv_diag_warp0.57s,startup_memory_srv_diag_supported_control_warp0.56s,startup_memory_srv_diag_hardware0.57s,startup_address_buffer_srv_hardware0.46s)sccache: 8/8 hits; wall12.0sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-25T19:53:33Z.
Rebased onto current main (
6d2d3bed), dropping intermediate merge commits and resolving the conflict inrelease()(d3d12_xs_device.cpp) betweenclear_unplaced_buffersandretire_drop_recording.Branch now carries only the 2 topic commits (
733163c5and703102b4).Verified on Windows 11 x64 (MSVC 19.44 + AMD Radeon RX 6600M & WARP):
ctest --preset dev -R 'startup_memory_srv_buffer|startup_address_buffer_srv|startup_address_srv|startup_memory_srv' --parallel 6 --no-tests=error --output-on-failurePR is now marked mergeable.
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T20:03:18Z.
Hardware run and Windows 11 MSVC build at head
8ebd5da8.Environment: Windows 11 Pro build 26300.9974, Debug (
devpreset), MSVC toolset 14.44.35207 (cl 19.44.35230.0), driver 32.0.16.2101. The three hardware tests printadapter=NVIDIA GeForce RTX 3070 Ti driver=32.0.16.2101. The runs were serial (-j1).Build:
cmake --build --preset devexited 0 (this PR changes C++ insrc/startup_stubs/, so the build was rerun at this head).Tests:
ctest --preset dev --no-tests=error -j1 -R '^startup_memory_srv_buffer|^startup_address_buffer_srv_warp$|^startup_address_srv_warp$' -E hardware -V: 8/8 passed. These arestartup_memory_srv_buffer, its five controls (height,exact-fit,first-32,unplaced-extent,unplaced-covers) and the two WARP tests,startup_address_srv_warpandstartup_address_buffer_srv_warp.ctest --preset dev --no-tests=error -j1 -R '^startup_address_buffer_srv_hardware$|^startup_address_srv_hardware$|^startup_memory_srv_diag_hardware$' -V: 3/3 passed. 0 capability skips (77).The five controls run
startup_memory_srv_buffer_check.exe --mutate <name>and each prints itsFAILline (for exampleFAIL resource height 2andFAIL unplaced extent crossing page); the test passes because the control fails as designed.The hardware tests print:
startup_address_buffer_srv_hardware:buffer memory SRV (raw base, raw interior, unplaced buffer, structured, refused unaligned, refused acceleration structure view) exact.startup_address_srv_hardware:ordinary view, alternating addresses, zero/interior/mismatched updates; all 32 RGBA pixels exact.startup_memory_srv_diag_hardware:BC1 refusal counted and named past the line limit; zero entry counted for pipeline 4599b146e6d5a03f with zero words; R8 accepted and sampled. Its census listsmemory SRV refusals (slot 70): total 9(null_address 8,unsupported_description 1) andmemory SRV writes (slot 70): calls 1, distinct entries 1.The WARP tests print
adapter=Microsoft Basic Render Driver driver=10.0.26100.9818and the same exact-result lines.These logs do not show whether the unplaced buffer used the existing-heap alias or the UPLOAD fallback, and they do not print a debug-layer status; I make no claim about either from this run.
On the PR so far: the author's comment reports
24/24 passedonAMD Radeon RX 6600Mand WARP. A WARP receipt on Windows Server 2025 appears for an earlier head. I found no NVIDIA run on this head.Not covered by this run: NVIDIA only (RTX 3070 Ti); no AMD or Intel GPU; no Release build; the wider
ctest -R '^startup_'suite was not run; the fail-first run onmainwas not repeated; the debug-layer status and the alias versus fallback path were not observed.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:15:43Z.
Review: COMMENTED
Review of head
8ebd5da8(comment only).Checked:
unplaced_buffer_extent,unplaced_buffer_covers): overflow guards, 64 KiB alignment and the 256 MiB cap look correct.unplaced-extent,unplaced-covers). The WARP and hardware draw test now leavesbuf1unplaced, so the new path is read back on a real device.Commands executed locally:
gh pr update-branch,python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD. The C++ test needs D3D12 headers, so it was not built on Linux. Its negative controls are exercised on Win2025 (receipt in the next comment).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:42:17Z.
Review: COMMENTED
Review of the PR change (head before the branch update:
f3ab4035; the update only merges main).What I checked
unplaced_buffer_extent/unplaced_buffer_covers(memory_srv_buffer.h): overflow guards, 64 KiB alignment and the 256 MiB limit are correct; the end-of-range check cannot wrap.unplaced_memory_buffer(d3d12_memory_srv.inl): refuses uncovered memory, overlap with live resources and nearby placed aliases; cache hits re-verify commit status and the allocation base; teardown inclear_unplaced_buffersreleases budgets and refs.existing_memory_bufferfails, so the placed/committed paths are unchanged.startup_memory_srv_buffer_checkwith two new negative controls (unplaced-extent,unplaced-covers) and leavesbuf1unplaced in the WARP/hardware readback test, so the sampled value is checked on a real D3D12 device.Non-blocking notes
Commands run locally (Linux, PR worktree)
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py: passedpython3 tests/bidi_controls_check.py: passedAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:15:44Z.
Win2025 WARP receipt for head
8ebd5da8after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
8ebd5da8c89c8fbc4132d214ce4195ccc6e02dd9:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):62.31s(configure0.00s)ctest --preset dev -R 'startup_memory_srv_buffer|startup_address_buffer_srv' --parallel 2 --no-tests=error --output-on-failure): 8/8 passed (1.93s:startup_memory_srv_buffer_height_control0.07s,startup_memory_srv_buffer0.12s,startup_memory_srv_buffer_first-32_control0.03s,startup_memory_srv_buffer_exact-fit_control0.04s,startup_memory_srv_buffer_unplaced-extent_control0.02s,startup_memory_srv_buffer_unplaced-covers_control0.03s,startup_address_buffer_srv_warp1.41s,startup_address_buffer_srv_hardware1.43s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):4.97s(configure0.00s)ctest --preset release -R 'startup_memory_srv_buffer|startup_address_buffer_srv' --parallel 2 --no-tests=error --output-on-failure): 8/8 passed (1.44s:startup_memory_srv_buffer0.05s,startup_memory_srv_buffer_height_control0.02s,startup_memory_srv_buffer_exact-fit_control0.02s,startup_memory_srv_buffer_first-32_control0.02s,startup_memory_srv_buffer_unplaced-extent_control0.02s,startup_memory_srv_buffer_unplaced-covers_control0.02s,startup_address_buffer_srv_warp1.06s,startup_address_buffer_srv_hardware1.08s)sccache: 6/59 hits; wall78.0sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:47:36Z.
Win2025 WARP receipt for head
2613d7a6after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
2613d7a6efde3e8e285d7c0cd8ec783b008f34d7:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):1.59s(configure0.00s)ctest --preset dev -R 'startup_memory_srv_buffer|startup_address_buffer_srv_warp' --parallel 2 --no-tests=error --output-on-failure): 7/7 passed (0.99s:startup_memory_srv_buffer_unplaced-covers_control0.02s,startup_memory_srv_buffer_unplaced-extent_control0.01s,startup_memory_srv_buffer0.01s,startup_memory_srv_buffer_exact-fit_control0.02s,startup_memory_srv_buffer_height_control0.01s,startup_memory_srv_buffer_first-32_control0.02s,startup_address_buffer_srv_warp0.83s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_memory_srv_buffer_check startup_stream_consumer -- -j 2):1.73s(configure0.00s)ctest --preset release -R 'startup_memory_srv_buffer|startup_address_buffer_srv_warp' --parallel 2 --no-tests=error --output-on-failure): 7/7 passed (0.86s:startup_memory_srv_buffer_first-32_control0.01s,startup_memory_srv_buffer_unplaced-covers_control0.01s,startup_memory_srv_buffer_unplaced-extent_control0.01s,startup_memory_srv_buffer_exact-fit_control0.01s,startup_memory_srv_buffer_height_control0.01s,startup_memory_srv_buffer0.01s,startup_address_buffer_srv_warp0.70s)sccache: 8/54 hits; wall15.1sAI-assisted; commands listed were executed locally.