runtime: report process GPU memory from XMemGetWorkingSetStatistics #516
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/522"
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-22T08:56:14Z.
Change
The desktop
xmem.dllnow answersXMemGetWorkingSetStatistics(0x20000001, …)instead of reporting it as unsupported. It returnsTRUEand writes this process's GPU memory in bytes (DXGIQueryVideoMemoryInfoCurrentUsage, local + non-local, summed over adapters) to the qword at+8. No other byte is written. Windows can list one device under several LUIDs, so each LUID is identified by the PnP hardware keys of its physical adapters (D3DKMT), not by vendor/device ID. The value is published only when the total is complete and non-duplicated; otherwise, as for other selectors, the call returnsFALSE/ERROR_NOT_SUPPORTEDand leaves the output untouched. A null output returnsERROR_INVALID_PARAMETER.dxgi.dllandgdi32.dllare delay-loaded, soxmem.dllstill maps neither DXGI nor D3D12 at load.This resolves the "units, scope and selector meaning remain open" entry for this import in
docs/experiments.mdas far as the callers need it. There is no issue for it.Why bytes of GPU memory — call-site evidence from the upscaler DLL (RVAs) and the public SDK:
0x20000001and a 128-byte stack buffer; read only+8(0 on failure); use onlyafter - before0x2ea1/0x39a9, resource release (getter0x26b3twice from0x3b40), heap create0x7452/0x74d2(ID3D12Device::CreateHeap), heap release0x7568/0x75b1+0x40/+0x48of 96-byte per-effect records; the second only for aliasable resources/heapsEffectContextinKits/FidelityFX/backend/dx12/ffx_dx12.cppis 96 bytes withvramUsage { totalUsageInBytes, aliasableUsageInBytes }at offset 64, updated at the same four points with the same callback shapes, adding known sizes. v2.3.0 ships FSR upscaling 4.1.1, the version string in the inspected DLL. The cited files are on the MIT list in the SDK'sdocs/license.md.The console value's scope and the selector's meaning stay unconfirmed; the callers depend only on its differences.
docs/experiments.mdrecords this as a desktop policy.#511's
cpu_native_shim_startupchecked the unsupported reply with0x20000001. It now uses0x20000002, which stays unsupported, so the fixture's "xmem working set unsupported" step keeps its meaning (one line intests/cpu/shim_startup.cpp, plus the matching sentence in its docs section).Overlap: none open (#514 is closed). A trial merge onto current
upstream/mainis clean.Verification
Updated at
714d2f2(adapter identity and aggregation rules, after review): current results in this comment. The results below are from the earlier revision.Current commit
a4036daonupstream/main26544c6(includes #511 and #525): the 34xmem/working_set/shim_startup/shim_compute/era_/docs/delay-load/import/inventory tests pass locally. The same change at14da57dpassed all four workflow jobs on thewindows-2025runner in my fork, with 199/199 in the Debug job. The first CI run of this PR (25007ec) failedxmem_shim_working_set_warpthere with exactly double differences; that is the duplicate Basic Render Driver described above. The full local suite and the negative control below ran onef21b4b(on5889876). Windows 10 22H2 (build 19045), Visual Studio 18.12.1 (MSVC 19.52.37029), Windows SDK 10.0.26100, CMake 4.3.1, Python 3.13.7. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047, debug layer on; WARP: in-box.xmem_shim_exportsdxgi.dllandd3d12.dllare not loaded.xmem_shim_working_setamd_selector=1 rest_untouched=1 other_selector=0 error=50 null_output=0 error=87xmem_shim_working_set_warp,_hardwareadded=67108864 removed=67108864; 32 MiB committed buffer:added=33554432 removed=33554432(both adapters)Local-only, with
FFX_UPSCALER_IMAGEset to the fingerprinted upscaler DLL (reuses the existingffx_package_working_set_deltatranslation):Full suite:
229 tests: 209 passed, 19 skipped (capability, exit 77), 1 failed:
gpu_alias_lookup_writes_warp, the known Windows 10 in-box WARP failure (#332, #369). I excluded thepixel_aot_*_hardwaretests because they hit their timeouts on this PC under load. They don't loadxmem.dll, and all 14pixel_aot_*tests passed on this branch at the previous base,3f59c6a.Negative control (on
ef21b4b, withsrc/xmem_shim.cppreplaced by upstream's):xmem_shim_working_set,_warp,_hardwareand bothffx_package_working_set_xmem_*cases fail. Every heap and buffer reportsadded=0 removed=0, and the package counters staycreated total=+0 aliasable=+0. The unchanged tests (xmem_shim_exports,_allocation,_query,ffx_package_working_set_delta) still pass. With the change restored, 6/6 and 3/3 pass.Evidence and follow-up
0x20000001value moves by the allocation size, as the SDK's known-size accounting implies.ACCCpipelines, an open README item. Only NVIDIA and WARP were tested;CurrentUsagecomes from the Windows video memory manager, so other vendors are expected to behave the same.0x7390), with its two queries bound to thisxmem.dll, or the resource pair at0x2e30/0x3b40. That needs import-call and vtable-call support in the translation.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-23T12:07:06Z.
Review: DISMISSED
The per-node reads and the positive/negative aggregation cases address the earlier review. I found one remaining deduplication case on 42154de. The current sorted vectors use case-sensitive string equality. Feeding two 64 MiB LUID views whose hardware registry key differs only by letter case returns 128 MiB in a synthetic run of the actual total() helper. Registry key names identify the same object across case variants, and the PnP query does not document that every returned path is canonicalized. Use ordinal case-insensitive key identity consistently for equality and partial overlap. Add a mixed-case alias that counts once and a mixed-case partial overlap that still fails. https://learn.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regopenkeyexw
The PnP query also returns the number of characters written including the terminator. Please use that length, check it stays inside the buffer and describes a nonempty terminated key, and treat malformed output as unknown identity. Keep the existing rejection behavior for incomplete, conflicting and failed samples. https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/d3dkmthk/ns-d3dkmthk-_d3dkmt_query_physical_adapter_pnp_key
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-22T09:30:43Z.
The CI failure on
25007ecis fixed ina4036da. On the GPU-lesswindows-2025runner, DXGI lists the Microsoft Basic Render Driver twice (flags 0 andSOFTWARE, different LUIDs), and both report the same allocations. As a resultxmem_shim_working_set_warpmeasured exactly 2× (added=134217728for a 64 MiB heap). The shim now skips a software adapter when a non-software adapter with the same vendor and device ID is listed.I also rebased onto #511 and #525.
check_working_set()from #511 now uses selector0x20000002, which stays unsupported, so the fixture's "unsupported" step keeps its meaning. The same change passed all four workflow jobs on thewindows-2025runner in my fork (199/199 in the Debug job). Locally ata4036da, the 34 affected tests pass, includingcpu_native_shim_startupandcpu_shim_compute_*.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T09:56:47Z.
The hardware comparison also reproduces the 2× delta at
a4036daon Windows build 26200 with the RTX 4060 Laptop driver 32.0.16.1656. A 64 MiB heap changes the reported usage by 128 MiB, and a 32 MiB buffer changes it by 64 MiB. WARP passes. Two DXGI entries for 10de:28e0 have different LUIDs and both have flags 0. Their local counters both move from 7,294,976 to 74,403,840 on the same 64 MiB allocation. The Intel and Basic Render Driver counters stay at zero.For the process-wide Windows approximation, publish the qword at +8 only when the observed domains yield a complete, non-duplicated total. A genuine successful zero is valid. An incomplete enumeration, all queries failing, or overlapping active domains without reliable identity should return FALSE / ERROR_NOT_SUPPORTED and preserve the entire output. Matching PCI IDs or equal readings alone cannot establish identity because separate same-model adapters must each be counted.
Please retain this hardware mismatch as a regression reference and exercise the aggregation with synthetic results for aliases, distinct same-model adapters, genuine zero, and total query failure. A design limited to an explicitly bound device would need its narrower scope called out separately.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-22T12:12:52Z.
AI-assisted (Claude Code).
Reworked at
714d2f2(rebased onaefed61). The value at+8is published only when the total is complete and non-duplicated; otherwise the call returnsFALSE/ERROR_NOT_SUPPORTEDand leaves the output untouched.src/adapter_identity.cpp), not by vendor/device ID.src/xmem_gpu_usage.h): same keys count once and must agree; different keys are summed; an active adapter of unknown identity is accepted only when no other adapter is active; any failed reading or incomplete enumeration → no total. Zero is published.xmem_shim_working_set_aggregation.Negative control: with a plain sum, 9 of 13 cases fail.
Fork CI (GPU-less
windows-2025): 215/215, includingxmem_shim_working_set_warp. Local (RTX 3080 Ti, Windows 10 19045): allxmem/working-set tests pass; the two failures are unrelated (#332, and an x87 fixture that passes on the runner).Whether your two NVIDIA LUIDs share a PnP key I can't check here. If not, the hardware case still fails at 2×, and the adapter lines it now prints will show it. Could you rerun?
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T14:41:00Z.
Verification of
714d2f2on a hybrid laptop with two hardware adapters. Built from source with thedevpreset: Windows 11 26100.9168, MSVC 19.52.37029, SDK 10.0.26100. I ran:Result: 18/18 passed, with no skips. This includes
xmem_shim_working_set,_aggregation,_warpand_hardware, andcpu_working_set_delta.xmem_shim_working_set_hardwarelists three DXGI adapters. Each has its own LUID and its own PnP device key, so none is counted twice:8086:191b)10de:13b1)1414:008c)Every bracket reports exactly 1× the allocation, which is the 2× case from
a4036danow fixed:One observation, not a failure.
create_device(false)intests/xmem_shim_check.cpptakes the first non-software adapter. On this laptop that is the integrated Intel GPU, because DXGI lists it before the NVIDIA GPU. The measurement above was therefore made on adapter 0.XBOX2WINDOWS_ADAPTERdoes not affect this test: runs withQuadroandIntelprinted identical output. If a result on the discrete GPU of hybrid systems is wanted, the test could honor that variable like the offscreen checks do. The summed total over all three LUIDs still came out as 1× here.AI-assisted: run and summarized with Claude Code; outputs copied from the test log.
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T01:10:15Z.
AI-assisted (Claude Code).
Thanks @legacy-code-archaeologist for the hybrid-laptop run. Updated at
784104e, rebased on356a7be:7cf1112: the working-set change, unchanged apart from the rebase (no conflicts).784104e:xmem_shim_working_set_hardwarenow selects its adapter asoffscreen_checkdoes: high-performance order, then the first whose description containsXBOX2WINDOWS_ADAPTER, ignoring case. A filter that matches no adapter fails rather than skips. The test prints the adapter it measures (device adapter 10de:2208 NVIDIA GeForce RTX 3080 Ti). The shim is unchanged.On a hybrid laptop the allocations now land on the discrete GPU by default, which is where the duplicate-LUID 2× case was seen. Your 1× result was measured on the Intel adapter, so it didn't exercise that path.
Local, RTX 3080 Ti, Windows 10 19045:
XBOX2WINDOWS_ADAPTERrtx 3080,NVIDIAQuadroNo D3D12 hardware adapter matches XBOX2WINDOWS_ADAPTER=QuadroAll seven
xmem_shim_*scenarios pass. A rerun on the Quadro would be welcome:Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T08:21:26Z.
The PnP identity and hybrid-laptop 1× result address the duplicate-LUID case. One completeness gap remains at
784104e:process_bytes()callsQueryVideoMemoryInfo(0, ...)for both segment groups, even when a LUID has several physical nodes. The DXGI API reports usage for the requested node. A nonzero allocation on node 1 would be absent from a successful process total. Please prove the full node set and read both segments for every node, or explicitly reject domains where the single-node precondition cannot be established. Add an injected case with zero on node 0 and nonzero on node 1, and one with a failed segment lookup after a successful read. Use checked addition at the segment boundary as well, before passing the domain total to the existing checked aggregation. Keep the current duplicate-LUID and same-device-model controls.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T11:52:57Z.
Verification of
42154deon the same hybrid laptop with two hardware adapters: Windows 11 26100, MSVC 19.52,devpreset. The head merges cleanly withmainat523d9ac(git merge-tree).Result: 18/18 passed, with no skips.
xmem_shim_working_set_hardwarenow reports the node count of each adapter (device paths omitted here):All four heap and committed-buffer cases report
added == removed == size.xmem_shim_working_set_aggregationincludes the new per-node cases, each reportedok:single_node_segments total=69206016node1_only total=67108864node_count_unknown,segment_failed_after_read,node1_failed_after_node0,segment_overflow,node_overflowThe earlier duplicate-LUID and same-model controls (
basic_render_alias,same_model_distinct,alias_disagrees) still pass.Every adapter on this host has one node, so this run exercises the multi-node path only through the injected cases, not on hardware.
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T11:56:44Z.
AI-assisted (Claude Code).
Updated at
42154de(rebased onc3db335). Each LUID's value now covers every node:KMTQAITYPE_PHYSICALADAPTERCOUNT, which counts the physical adapters in the LUID's link; these are the DXGI nodes. If the count can't be read, the call returnsFALSE/ERROR_NOT_SUPPORTED.domain_bytes()reads local and non-local usage on every node. Segment, node and cross-adapter sums all go through one checkeddetail::add().Negative control: reading node 0 only fails 3 of the 7. The duplicate-LUID and same-model controls are unchanged. The package test
ffx_package_working_set_xmem_hardwarenow picks its adapter the same way asxmem_shim_working_set_hardware(sharedtests/xmem_test_device.h).Local (RTX 3080 Ti, Windows 10 19045) at
42154de: 31/31 area tests (2 mesh-shader skips on in-box WARP), 3/3ffx_package_working_set_*. The hardware test printsnodes=for each adapter (both 1 here). Thanks @legacy-code-archaeologist for the hybrid run: by default it now measures the Quadro. The full-suite result follows in a separate comment.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T11:56:45Z.
Full local
devsuite (RTX 3080 Ti, Windows 10 19045, in-box WARP): 422/425 passed, 43 capability skips. It ran before the rebase ontoc3db335and before the test-only move intotests/xmem_test_device.h; both are covered by the targeted reruns at42154deabove. The three failures are outside this change:gpu_alias_lookup_writes_warp: in-box WARP (#332)pixel_aot_title_loads_warp: in-box WARP, passes on WARP 1.0.22 (reported on #816)rdna2_tools_check: caused byPYTHONIOENCODING=utf-8in my shell; passes with it unset. Tracked in #844.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T12:22:30Z.
AI-assisted (Claude Code).
Updated at
629eb61(rebased one97090a).adapter_identity::same_device()compares keys withCompareStringOrdinal(..., TRUE)(ordinal, OS uppercase table).total()uses it for both alias equality and partial overlap, compared as sets, so key order and case no longer matter.adapter_identity::key_length()takes thepCchDestcount (including the terminator) and accepts it only when it fits the buffer and forms one nonempty, terminated key with no embedded NUL. Anything else leaves the identity unknown. Rejection of incomplete, conflicting and failed samples is unchanged.Negative controls: with a case-sensitive comparison the three mixed-case cases fail (the alias gives 128 MiB, as in your run). With the previous length handling, 4 of the 7 key cases are accepted.
Local (RTX 3080 Ti, Windows 10 19045) at
629eb61: 32/32 area tests (2 mesh-shader skips on in-box WARP), 3/3ffx_package_working_set_*.Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-23T12:47:01Z.
Full local
devsuite at629eb61(RTX 3080 Ti, Windows 10 19045): 425/427 passed, 44 capability skips. Both failures are known in-box WARP issues unrelated to this change (#332, #816).