gpu: export D3D12ConfigureVirtualMemoryX and add the GPU range it describes #961
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/968"
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 lukaslw-lab on 2026-11-23T19:14:31Z.
Change
Refs #874. Two parts. Attaching the range at device creation waits for an owner of the title's device.
1.
D3D12ConfigureVirtualMemoryXexport ind3d12_xs.dll.+4is 3 or 4, and the other 28 bytes are zero.E_POINTER(null),E_INVALIDARG(other content) orDXGI_ERROR_INVALID_CALL(second call, or after the device).D3D12XboxCreateDevicereturns an ordinaryID3D12Devicethat a caller can release without any extra protocol, so the range is not attached there.2. The GPU range the configuration describes, on an owning handle (
src/d3d12_xs_range.h,src/d3d12_xs_range.cpp).d3d12_xs_range::createreserves(value - 2) × 16 GiBas reserved buffers ("windows") of at most 4 GiB, or less where the adapter's per-resource limit is lower: 32 GiB for the 4 sample.IX2WGpuRangereference. A caller maps tiles withUpdateTileMappings, as the title does through a copy queue (static read on #874; #986 covers COPY → DIRECT ordering).Close()or on the range's last release. Nothing else holds the range, so there is no device private data and no reference cycle.Close()is serialized with the queries through an SRW lock: a query that overlaps it sees either the open range or an empty one. The owner waits for GPU work that uses the windows beforeClose()or the final release.Tests in
tests/vm_translation_check.cpp:vm_translation_sequence_{warp,hardware}: configure →D3D12XboxCreateDevice→ first default DIRECT queue, with configuration, device and queue refusals. The #912 range checks and the 64 KiB shifted-window witness then run on that queue.vm_translation_range_{warp,hardware}: a 32 GiB range. It maps three tiles on the queue (range start, first tile of window 1, last tile), fills each by copy from a 64 KiB pagefile section, and reads them back by dispatch at the range's GPU address. It also covers the one-tile shift, staging writes after the copy, spans across a window edge or past the end returning 0, andClose()after idle.vm_translation_range_lifetime_{warp,hardware}:ID3DDestructionNotifieron each device. A configured device fromd3d12_xs.dllcarries no range, and its last ordinary release destroys it. An open range's windows keep a released device alive, and releasing the range destroys it.Close()overlapping a reader thread gives consistent reads, and the device's last release afterwards destroys it.vm_translation_range_partial_{warp,hardware}: window creation failing at window 1 or 3.The window limit comes from the #874 probe. On an RTX 3080 Ti, tile mappings at or above 4 GiB inside one reserved buffer had no effect, and in-box WARP 10.0.19041 refuses a 4 GiB reserved buffer.
Not covered:
mainstill refuses;Verification
Commit
c4a42d26(mainmerged at23d2e93), Windows 10 22H2 (build 19045), D3D12 10.0.19041.7291, Visual Studio 2026 18.12 (MSVC 19.52), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7. Adapters: in-box WARP 10.0.19041.7811 and NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1047). The fixture does not enable the debug layer. The CTest selections were run through a local wrapper that builds the preset's folder and calls the samectestselection.Capability skips:
vm_translation_range_warp: on in-box WARP 10.0.19041.7811, a dispatch does not read a copied tile of a test-owned reserved buffer. The check runs before the range is used. With WARP 1.0.22 loaded app-locally (same binaries),range_warp,range_lifetime_warp,range_partial_warp,sequence_warpanddevice_warpall pass. The maintainer's Windows 11 26200 run had no skips on in-box WARP.cpu_shim_chain_warp: it also skips onmainbefore this change.Negative controls, run in
devand not committed. After reverting, each selection passes again.The export returning
S_OKfor any non-null block: both sequence cases fail.The export attaching a reserved buffer to the configured device as private data: both lifetime cases fail, and the exported device keeps a reference with no destruction callback.
Close()doing nothing: both lifetime cases andvm_translation_range_hardwarefail.Already-created windows kept on a failed creation: both partial cases fail.
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
Checked 13 Markdown files and 201 links.
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
Checked 818 tracked source, script and build/CI files: no bidirectional controls.
.\out\pe-env\Scripts\python.exe -B tests/hardware_reports_check.py
OK
.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py
form coverage checks passed
Evidence and follow-up
Source-built fixture (MIT), no game files. The call shape comes from the static read in #874 and the recording fixture from #891. The range size and window split are desktop policy: the DWORD's meaning and the other 28 bytes remain open, and the export accepts only the observed samples.
IX2WGpuRange's GUID is new to this repository and should stay fixed once merged.Follow-up on #874:
xmem.dll) and page pool to the windows;main;Checklist
AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:22:44Z.
The source-built device → DIRECT queue → readback sequence is useful on its own. At this head the new export validates the input and sets a process-wide flag, but the selected configuration never reaches device creation or address binding. The shifted-window witness still exercises the fixture's own mapping, so it would also pass if the production setup ignored the configuration payload.
Please keep the sequence as a focused source-built fixture, or connect the export to an observable configuration state. For the production path, hold the adapter and inputs fixed and show a device/queue operation that distinguishes a valid configuration from a missing or rejected configuration. Also verify that a failed device creation leaves the existing valid state useful. The supported parameter-block path and large sparse-range behavior can stay separate.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T19:38:05Z.
AI-assisted (Claude Code).
Thanks. I connected the export to an observable state in
51e7e61. An accepted configuration now changes what the nextD3D12XboxCreateDevicereturns. The shim reserves(value - 2) × 16 GiBof GPU virtual address space as reserved buffers of at most 4 GiB each. It attaches them to the device as private data (IX2WGpuRange,src/d3d12_xs_range.h), so any module holding the device can read them. A missing or refused configuration leaves the device without a range.New cases
vm_translation_range_{valid,missing,rejected}_{warp,hardware}use the same adapter, device requests, first DIRECT queue and tile inputs, and change only the configuration:GetPrivateData(IX2WGpuRange)S_OK, 32 GiB in 4 GiB windows (RTX)UpdateTileMappingsmaps three tiles (range start, first tile of window 1, last tile). A copy fills each, and a dispatch reads it back at the range's GPU address.DXGI_ERROR_NOT_FOUND+8)DXGI_ERROR_NOT_FOUNDFailed creation:
Negative controls (not committed):
Results:
dev:100% tests passed, 0 tests failed out of 21.release:100% tests passed, 0 tests failed out of 15.vm_translation_range_valid_warpand the pre-existingcpu_shim_chain_warp.Not included: the parameter-block path, any single reserved buffer above 4 GiB, and connecting the CPU range A to the windows.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:51:54Z.
The new range is observable. I built
51e7e61and tested its exported configure/create calls on in-box WARP in separate source-built processes. With the valid sample I could query nine windows, and both a span crossing the first window edge and an address at the end of the range returned 0 as documented.There is a lifetime blocker. I registered an ID3DDestructionNotifier callback on the returned device, released my range reference, then released the last caller-owned device reference. The unconfigured control destroyed the device (Release 0, one callback). The configured branch kept the device alive (Release 9, no callback). D3D12CreateDevice then returned the same device, and the callback fired only after I cleared IX2WGpuRange private data and released it again. SetPrivateDataInterface takes a strong reference, and the range owns device-child resources, so automatic device cleanup cannot break this cycle.
Please make range ownership explicit outside device private data, or provide a teardown path exercised by the actual owner before its final device release. Include a repeatable configured create/release destruction check, plus cleanup after forced partial-window failure. Keep an out-of-window span rejected and report capability skips separately from a configured-range mismatch. This is the reserve/window slice under #874; queue capacity and cross-queue synchronization remain independent.
The original range fixture also ran here under Windows 11 build 26200.9974, Release. All eight sequence and range cases passed across in-box WARP and RTX 4060 Laptop (driver 32.0.16.1656), with no skips. WARP reported 32 per-resource VA bits and used nine windows of at most 4095 MiB. RTX reported 40 bits and used eight windows of 4096 MiB. Each adapter matched all 1,024 words at the first tile, second-window start, and last tile. The source-built destruction control above catches the lifetime issue separately from those queue/readback cases.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T20:03:10Z.
AI-assisted (Claude Code).
Thanks for the destruction check and the Windows 11 run. Fixed in
3647ccewith an explicit teardown path. The cycle cannot be broken automatically: the windows are device children and hold the device wherever the range lives.IX2WGpuRange::Close()deletes the private-data entry (SetPrivateData(guid, 0, nullptr)) and releases the windows. The range is empty afterwards, and a second call does nothing. The header documents the contract: the device's owner callsClose()before its final release.src/d3d12_xs_range.cpp, so tests can link it directly and inject a failing window creator. Every window created before a failure is released before the HRESULT is returned.attachattaches nothing.New cases:
vm_translation_range_lifetime_{warp,hardware}ID3DDestructionNotifieron the configured device, two create/release rounds. Control: withoutClose(), the last callerReleaseleaves 8 references (RTX) or 9 (in-box WARP) and no callback, and the next request returns the same device and range. AfterClose():DXGI_ERROR_NOT_FOUNDon the device,Releasereturns 0, and one callback, in both rounds.vm_translation_range_partial_{warp,hardware}createand throughattach. The test checks thatE_OUTOFMEMORYis returned after exactly that many calls, that no range is returned or attached, and that the last device release returns 0 with one callback.Negative controls (not committed): a
Close()that does nothing fails both lifetime cases; keeping the already-created windows on failure fails both partial cases.Results at
3647cce:dev:100% tests passed, 0 tests failed out of 25release:100% tests passed, 0 tests failed out of 19vm_translation_range_valid_warpon in-box WARP 10.0.19041.7811 (the capability check), and the pre-existingcpu_shim_chain_warp. The new lifetime and partial cases ran without skips on both adapters.Your Windows 11 26200 run had no skips on in-box WARP, so the skip is specific to the Windows 10 19041 WARP.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:07:34Z.
I reran
3647cceon in-box WARP and RTX 4060 Laptop in Release. All 12 sequence and range cases passed with zero skips, including both create/close rounds and failure at windows 1 and 3. The new negative control confirms that ordinary device Release still leaves the configured device alive unless someone calls Close.The attach-failure branch already closes the range. After a successful attach, only the dedicated lifetime test calls Close in this candidate. The exported device path still returns an ordinary ID3D12Device, so current callers can release it without using this new protocol. Please connect Close to the actual owner before enabling the attachment on that export, including failed initialization and a fence/idle boundary for users of the window resources. Alternatively, the independent range implementation and fixture can land with an explicit owning test handle while production attachment waits for its owner. Document that Close is serialized with window access and describe what happens if private-data removal fails. #986 supplies the separate COPY-to-DIRECT ordering evidence.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T20:23:19Z.
AI-assisted (Claude Code).
Thanks. I took the second option in
c4a42d26. The range implementation and its fixture land with an explicit owning handle, and the export no longer attaches a range.D3D12XboxCreateDevicecreates no range. The accepted configuration is recorded for a later owner of the title's device. A configured device fromd3d12_xs.dllcarries noIX2WGpuRangeprivate data, and its last ordinary release destroys it; the lifetime test checks this withID3DDestructionNotifier.d3d12_xs_range::createreturns an owningIX2WGpuRange. There is no device private data, so there is no cycle: the windows hold the device only untilClose()or the range's last release.Close()takes an SRW lock exclusively, andGetSize,GetWindowCount,GetWindowandGetGPUVirtualAddresstake it shared. A query that overlapsClose()sees the open range or an empty one. Window references already returned byGetWindowstay valid until their holder releases them. The header asks the owner to wait for GPU work that uses the windows (a fence on each queue) beforeClose()or the final release. The private-data removal path is gone, so it has no failure case.Close()while a thread reads the rangeE_OUTOFMEMORYafter that many calls, no range, and the device is destroyed on releaseClose()after idle)Negative controls (not committed):
Close()that does nothing, the lifetime cases fail.Results at
c4a42d26:dev:100% tests passed, 0 tests failed out of 21(skips:vm_translation_range_warpon Windows 10 in-box WARP, pre-existingcpu_shim_chain_warp). With WARP 1.0.22 loaded app-locally, all five WARP cases pass.release:100% tests passed, 0 tests failed out of 15Attaching the range at device creation stays for the follow-up that adds an owner of the title's device, covering failed initialization and a fence/idle boundary before
Close().Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:35:26Z.
I reran the bounded implementation on Windows 11 with in-box WARP and RTX 4060 Laptop. The configured export returned an ordinary device that its final Release destroyed. The independent range lifetime, readback and partial-allocation tests passed. I pushed
d9f7d29to reject zero, unaligned and oversized ranges before reserving any window. The previous size ceiling could wrap and return an empty range as successful. The Release selection^(vm_translation_|d3d12_xs_shim_)passed 15/15, with no skips. The configuration is recorded here. Attaching the range still needs a device owner and a fence-complete shutdown path.