startup: log video memory and process commit every 5 s #3493
No reviewers
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!3493
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3491"
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 17:40 UTC · original
Leyukaka:runtime-video-memory-line→main· +212 −25 · 4 files · 2 commits · openRefs #3476
Adds the diagnostic line suggested in #3476:
QueryVideoMemoryInfolocal / non-local and the process commit, logged right after the existingx2w-d3d12 views noted ... placed buffers ...line, so the placed-buffer count can be read against memory on any run. It is always on;X2W_D3D12_BUDGETis not needed.New line
local/nonlocal:CurrentUsage/Budgetof each segment group;n/awhen the adapter declines that query.process_commit:PrivateUsagefromK32GetProcessMemoryInfo.x2w-d3d12 video memory unavailable (no DXGI adapter); process_commit=<bytes> bytesis logged once, thenx2w-d3d12 process_commit=<bytes> byteson later intervals.Changes (
src/startup_stubs/d3d12_xs_device.cpp)QueryVideoMemoryInfocalls move out ofreport_budgetintosample_video_memory. It runs once per report in the existing 5 s block ofqueue_present, never per frame. Thex2w-budgetline uses the same sample instead of querying on its own; its format is unchanged.ComPtrlocals, released on return.K32GetProcessMemoryInfois exported by kernel32, so there is no new link dependency.last_reportbecomes an atomic claimed withcompare_exchange_strong, andstarteda function-local static set on the first present. Heartbeat timing is unchanged.The only behaviour change is the new line.
Tests
New
startup_video_memory_line_warp(tests/startup_video_memory_line_check.cpp): a wrapped WARP queue presents, waits 5.1 s and presents again. It checks that exactly one video memory line follows the placed-buffer totals line, with numeric readings for each segment WARP answers, that nox2w-budgetline appears withX2W_D3D12_BUDGET=0, and that the missing-adapter text is logged once while the process commit keeps reporting.Mutations, each restored afterwards:
report_video_memory(video)callstartup_video_memory_line_warpfailsfirst_calls(no_adapter, 1)->2startup_video_memory_line_warpfailsBase
26df1826. Merges cleanly with #3482 and #3484.Not covered
@Not-Saii on GitHub · 2026-11-29 22:48 UTC · original · reviewed
Review of head
926c74922c5483171e58a7d3d1af53351105f90d(merges cleanly with currentmain).Thanks: the change is small and does what it says, the 5 s report now samples once and shares the sample with
x2w-budget, and the CAS onlast_reportalso removes a latent double report. In the base code, a thread whosenowwas older than another thread's freshly storedlast_reportcomputednow - last_reportas an unsigned underflow. No downloads, network calls or agent-config changes; the new CMake fragment follows thestartup_present_logpattern.Checked: the sample runs only inside the 5 s block, never per frame. The only added per-call cost is a magic-static guard and a relaxed atomic load. The device, factory and adapter are
ComPtrlocals and the only new static is the no-adapter counter. The line is always on, as asked in the linked issue. No new switch, sotools/startup/run_presets.jsonneeds no change.Findings
MUST: none.
SHOULD
src/startup_stubs/d3d12_xs_device.cpp:7595(called from:7925):CreateDXGIFactory1+EnumAdapterByLuidused to run only withX2W_D3D12_BUDGET=1. Now every run pays for it inside the title's Present call every 5 s. Factory creation enumerates adapters and can take milliseconds on some systems. Please cache theIDXGIAdapter3once (keyed by the device LUID) and reuse it, or measure and state the added time per report. ThePresententry of thetime inside the stand-inline already includes it.x2w-budgetline on the refactored path. The new test runs only withX2W_D3D12_BUDGET=0, and thestartup_resource_budget_*tests never reach the 5 s report. I ran the new fixture by hand withX2W_D3D12_BUDGET=1: thex2w-budgetline appeared with the samelocal=/nonlocal=values as the video memory line. As expected, the fixture then printed its FAIL because it asserts no budget line. Please add a second registration withX2W_D3D12_BUDGET=1that asserts onex2w-budget local=line whoselocal=/nonlocal=fields equal the video memory line's.docs/startup-runtime.md:3911-3912describes the five-secondx2w-d3d12 views notedline, but the new always-on line and itsn/aand no-adapter forms are documented nowhere. The#d3d12-resource-budgetsection also still reads as if the budget line were the only place video memory is reported.--presetor build directory. "4 capability skips" doesn't say which tests skipped. The Windows build and WARP version are missing. The two mutations are a good negative control.NIT
5.
:7628-7633: the main line puts the unit in its header (process_commit=<n>), but the no-adapter forms end inprocess_commit=<n> bytes. Pick one.6.
tests/startup_video_memory_line_check.cpp:37-44: the earlyreturn 1paths afterX2W_TRAP_LOGis set leave the per-PID log file in the build directory.7. The fixture sleeps 5.1 s, so consider a
COSTproperty in the fragment (tests/cmake/README.md) soctest --parallelstarts it early.What the tests prove
startup_video_memory_line_warp: on a wrapped WARP queue, the 5 s report emits exactly one video memory line, directly after the placed-buffer totals. Each segment WARP answers gets numericusage/budget(each one it declines getsn/a), and the process commit is nonzero. WithX2W_D3D12_BUDGET=0nox2w-budgetline appears. The null-queue hook shows the no-adapter text is logged once, with later calls falling back to the commit-only line. Not covered: a hardware adapter, the budget-on path, and theEnumWarpAdapterLUID fallback specifically.startup_resource_budget_*andstartup_present_log(_control): neighbouring regression checks. They don't reach the 5 s report.Isolated run (Windows Sandbox, networking disabled, PR tree exported at the head SHA)
startup_video_memory_line_warp(5.46 s),startup_resource_budget_warp_debug0,startup_resource_budget_warp_debug0_inline_control,startup_resource_budget_hardware_debug0,startup_resource_budget_hardware_debug0_inline_control,startup_present_log,startup_present_log_control. The_controland_inline_controlcases pass by printing their expected FAIL line.startup_resource_budget_{warp,hardware}_debug1and..._debug1_inline_control.D3D12GetDebugInterfacefails because the debug layer is unavailable (nod3d12SDKLayers.dllin the sandbox).devpreset). Debug layer: unavailable. The new test uses WARP only. Video-memory numbers seen through vGPU may differ from bare metal.Mutations (scratch copy, each restored; restored file hash matches head)
report_video_memory(video);inqueue_presentwith a no-opstartup_video_memory_line_warpfails:FAIL: expected one WARP sample with the placed-buffer totals ...startup_video_memory_line_warppassesCI
The Windows PR job (run 46290965004) ran the
prpreset, 82/82 passed. It compiledd3d12_xs_device.cppbut did not build or runstartup_video_memory_line_warpor anystartup_resource_budget_*test; none of this PR's tests are in theprfilter. The Linux Python and gfx1013 jobs passed, but they don't exercise this change.Verdict: COMMENT. No blocking issue, and the PR's test catches the change being reverted. SHOULD 1 (an always-on factory creation on the Present thread) and SHOULD 2 (no test of the budget-on path) are worth addressing before merge.
@Not-Saii on GitHub · 2026-11-30 00:06 UTC · original · reviewed
Re-review at head
2ecdce61182428f0e7f14865479c3d181deb909c(previous review:926c7492). It merges cleanly with currentmain.Thanks for the quick turnaround. The cache, the budget-on test, the docs and the test cleanup all address what I raised.
What changed since
926c7492One commit,
2ecdce61:video_memory_adapter(LUID)(src/startup_stubs/d3d12_xs_device.cpp:7589-7611) creates the DXGI factory and looks up the adapter once per LUID, behind a mutex. Failed lookups are cached too.sample_video_memory(:7613) now costs aGetDevice, the cache lookup and twoQueryVideoMemoryInfocalls per report.startup_video_memory_line_budget_warp, plusCOST 5for both tests.bytes.No downloads, network calls, agent-config changes or new build commands. The CMake change only adds a second
add_testof the same executable.Earlier findings
d3d12_xs_device.cpp:7589-7611, one lookup per LUIDx2w-budgetline on the shared-sample pathtests/cmake/startup_video_memory_line.cmake:11-16,tests/startup_video_memory_line_check.cpp:80-93(one budget line after the video line, samelocal=/nonlocal=text, an all-n/asample refused)docs/startup-runtime.md:1857-1871and:3871-3872bytesunit differed between the formsd3d12_xs_device.cpp:7644,:7646tests/startup_video_memory_line_check.cpp:19-27(the stream is destroyed before the guard)COSTfor the 5 s testtests/cmake/startup_video_memory_line.cmake:12New findings
MUST: none.
SHOULD
d3d12_xs_device.cpp:7593-7594). The cache is a function-local static map ofComPtr<IDXGIAdapter3>, so this module's CRT teardown releases those adapters on process exit as well as onFreeLibrary.src/startup_stubs/d3d12_teardown.hsets the rule for statics that hold desktop graphics objects: detach on process exit, release on unload (#2572). The present sampler is kept alive withnewfor the same reason (:7558). Please follow one of those patterns, or say why DXGI adapters are safe to release at exit. I have not seen a failure from this. It is a risk read from the code against the module's own rule, not an observed crash.ComPtrlocals released on return, and it showsprocess_commit=<bytes> bytesfor the no-adapter forms. It doesn't mentionstartup_video_memory_line_budget_warpor the cache. The AGENTS.md evidence fields from the last review are still missing: the head commit under test, the commands with--preset, the names of the skipped tests, and the Windows build.NIT: none new.
What the tests prove
startup_video_memory_line_warp: one video memory line, directly after the placed-buffer totals, with a numeric reading for each segment WARP answers and a nonzero process commit. Nox2w-budgetline with the budget off. The no-adapter text is logged once, then the commit-only line.startup_video_memory_line_budget_warp: withX2W_D3D12_BUDGET=1, exactly onex2w-budgetline follows the video line and carries the samelocal=/nonlocal=text. On WARP that waslocal=0/482684314 nonlocal=0/0. A sample with no DXGI reading is refused, so dropping the sample is caught.Isolated run (Windows Sandbox, networking off, PR tree exported at the head SHA; merge base
26df1826available for comparison)Head leg: 12 passed, 0 failed, 0 skipped (77).
startup_video_memory_line_warp,startup_video_memory_line_budget_warp,startup_resource_budget_{warp,hardware}_debug{0,1}and their_inline_controlcases,startup_present_log,startup_present_log_control.Environment:
devpreset, MSVC 14.44.35207, CMake 3.31.6.hr=0x00000000. Thestartup_resource_budget_*_debug1fixtures reportdebug layer: 0x00000000 enabled. The two video memory fixtures create their WARP device directly, so they run without it.Mutation (scratch copy; the restored file's hash matches head)
report_budget(video)->report_budget(VideoMemorySample{})atd3d12_xs_device.cpp:7982(the budget line no longer gets the shared sample)d3d12_xs.dll,startup_video_memory_line_check.exeandstartup_present_log.exechanged.startup_video_memory_line_budget_warpfails withFAIL: expected one budget line with the heartbeat's WARP memory sample. The other 11 pass, includingstartup_video_memory_line_warp.The previous run caught removing or moving the
report_video_memory(video)call. That part of the test has not changed.CI
The Windows PR job (run 46322245948) ran the
prpreset, 82/82 passed. It compiledd3d12_xs_device.cppbut ran neither video memory test, because neither is in theprfilter. The Linux job passed all 267 checks. The gfx1013 job passed, but it doesn't exercise this change.Verdict: COMMENT. Every earlier code finding is fixed and the new test catches its mutant. I'd approve once the adapter cache follows the teardown rule in
d3d12_teardown.h(or the PR explains why it doesn't need to) and the PR body matches the code.@Jess-Doit on GitHub · 2026-11-30 01:52 UTC · original
Two small suggestions on the cached video-memory adapter, from a local version of the same change (it also covers both of tedin7's review notes on #2256):
EnumAdapterByLuidor WARP match fails (for example a transient factory failure), later samples reportn/apermanently. Retrying an empty entry on the next sample keeps the cost low, since samples are 5 s apart.QueryVideoMemoryInforeturnsDXGI_ERROR_DEVICE_REMOVEDorDXGI_ERROR_DEVICE_RESET, dropping the entry lets the next sample look the adapter up again instead of querying a stale reference.Separately,
resource_budget.hstill relies on a transitivewindows.h. Including it directly there was the other #2256 note, and it fits in this PR if you want it.With both changes, the eight budget tests and a repeated heartbeat check passed on a GTX 1060 and WARP. The resource-retire failures on that card also fail on clean main. Happy to share the branch if useful.
Ready for more review
@R0Y00 on GitHub · 2026-12-03 08:42 UTC · original
I trial-merged
2ecdce61withmaind2e6a4ed. A small resolution is to use main’s existingadapter_for(device)insample_video_memory, once per five-second sample. That also retries an unavailable adapter on the next heartbeat instead of caching a failed lookup. Keep both main’s adapter facts and the GPU-to-CPU census; emit the new video-memory sample immediately after theviews noted ... placed buffers ...line and before the later census lines. Putting it after those lines made both WARP fixtures fail their adjacency assertion even though the sample was valid. With that ordering, MSVC Debug passedstartup_video_memory_line_warp, its budget variant, and both GPU-to-CPU line checks (4/4, including the misattribution control). This was a local integration; the PR branch still needs to be updated.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.