Repository navigation
Conversation
Not-Saii
left a comment
There was a problem hiding this comment.
Review of head 926c74922c5483171e58a7d3d1af53351105f90d (merges cleanly with current main).
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 on last_report also removes a latent double report. In the base code, a thread whose now was older than another thread's freshly stored last_report computed now - last_report as an unsigned underflow. No downloads, network calls or agent-config changes; the new CMake fragment follows the startup_present_log pattern.
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 ComPtr locals and the only new static is the no-adapter counter. The line is always on, as asked in the linked issue. No new switch, so tools/startup/run_presets.json needs 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.- No test covers the
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:
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. - Evidence in the PR body (AGENTS.md "Evidence"): it names the base but not the head commit under test. The commands have no
--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 in process_commit=<n> bytes. Pick one.
6. tests/startup_video_memory_line_check.cpp:37-44: the early return 1 paths after X2W_TRAP_LOG is set leave the per-PID log file in the build directory.
7. The fixture sleeps 5.1 s, so consider a COST property in the fragment (tests/cmake/README.md) so ctest --parallel starts 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)
cmake --preset dev -DX2W_WITH_OPUS=OFF
cmake --build --preset dev --target startup_video_memory_line_check startup_resource_budget startup_present_log
ctest --preset dev --no-tests=error --output-on-failure -V -R '^(startup_video_memory_line_warp|startup_resource_budget_(warp|hardware)_debug[01](_inline_control)?|startup_present_log(_control)?)$'
- Passed (7):
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. - Failed: none.
- Skipped 77 (4):
startup_resource_budget_{warp,hardware}_debug1and..._debug1_inline_control.D3D12GetDebugInterfacefails because the debug layer is unavailable (nod3d12SDKLayers.dllin the sandbox). - Environment: Windows 11 Enterprise 10.0.26100 (build 26100) in Windows Sandbox. Adapters: NVIDIA GeForce RTX 4090 through the sandbox vGPU (driver 10.0.26100.1150) plus Microsoft Remote Display Adapter. MSVC 14.44.35207, CMake 3.31.6, Debug (
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)
| Mutation | Result |
|---|---|
M1: replace report_video_memory(video); in queue_present with a no-op |
builds; startup_video_memory_line_warp fails: FAIL: expected one WARP sample with the placed-buffer totals ... |
| M2: move that call below the heartbeat line | builds; same failure (the line no longer directly follows the placed-buffer totals) |
| restored | builds; startup_video_memory_line_warp passes |
CI
The Windows PR job (run 46290965004) ran the pr preset, 82/82 passed. It compiled d3d12_xs_device.cpp but did not build or run startup_video_memory_line_warp or any startup_resource_budget_* test; none of this PR's tests are in the pr filter. 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.
Check the shared sample in the optional budget heartbeat and document the video memory and process commit formats.
Not-Saii
left a comment
There was a problem hiding this comment.
Re-review at head 2ecdce61182428f0e7f14865479c3d181deb909c (previous review: 926c7492). It merges cleanly with current main.
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 926c749
One 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.- New test
startup_video_memory_line_budget_warp, plusCOST 5for both tests. - The test's log file is removed by an RAII guard.
- Docs for the new line and its no-adapter forms.
- The no-adapter forms drop the trailing
bytes.
No downloads, network calls, agent-config changes or new build commands. The CMake change only adds a second add_test of the same executable.
Earlier findings
| # | Finding | Status |
|---|---|---|
| S1 | DXGI factory created every 5 s on the Present thread | Fixed: d3d12_xs_device.cpp:7589-7611, one lookup per LUID |
| S2 | No test of the x2w-budget line on the shared-sample path |
Fixed: tests/cmake/startup_video_memory_line.cmake:11-16, tests/startup_video_memory_line_check.cpp:80-93 (one budget line after the video line, same local=/nonlocal= text, an all-n/a sample refused) |
| S3 | New line undocumented | Fixed: docs/startup-runtime.md:1857-1871 and :3871-3872 |
| S4 | Evidence fields in the PR body | Open: see below |
| N5 | bytes unit differed between the forms |
Fixed: d3d12_xs_device.cpp:7644, :7646 |
| N6 | Log file left behind on early exits | Fixed: tests/startup_video_memory_line_check.cpp:19-27 (the stream is destroyed before the guard) |
| N7 | COST for the 5 s test |
Fixed: tests/cmake/startup_video_memory_line.cmake:12 |
New findings
MUST: none.
SHOULD
- Teardown of the adapter cache (
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. - The PR body is out of date. It still says the device, factory and adapter are
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.- No test covers the cache itself (one lookup per LUID, cached failures). That is acceptable for a diagnostic, but the PR body should say so.
Isolated run (Windows Sandbox, networking off, PR tree exported at the head SHA; merge base 26df1826 available for comparison)
cmake --preset dev -DX2W_WITH_OPUS=OFF (with the Agility 1.620.2 and WARP 1.0.22 directories)
cmake --build --preset dev --target startup_video_memory_line_check startup_resource_budget startup_present_log
ctest --preset dev --no-tests=error --output-on-failure -V -R '^(startup_video_memory_line_(budget_)?warp|startup_resource_budget_(warp|hardware)_debug[01](_inline_control)?|startup_present_log(_control)?)$'
Head leg: 12 passed, 0 failed, 0 skipped (77).
- Passed:
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. - The control cases pass by printing their expected FAIL line.
- No head failures, so no base comparison was needed.
Environment:
- Windows 11 Enterprise 10.0.26100 (build 26100), Debug
devpreset, MSVC 14.44.35207, CMake 3.31.6. - Adapters as the fixtures print them: NVIDIA GeForce RTX 4090 through the sandbox vGPU (driver 32.0.16.1088), and Microsoft Basic Render Driver (WARP 1.0.22.0).
- Debug layer: the probe returned
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. - Video-memory numbers through vGPU may differ from bare metal.
Mutation (scratch copy; the restored file's hash matches head)
| Mutant | Result |
|---|---|
report_budget(video) -> report_budget(VideoMemorySample{}) at d3d12_xs_device.cpp:7982 (the budget line no longer gets the shared sample) |
Rebuild check: d3d12_xs.dll, startup_video_memory_line_check.exe and startup_present_log.exe changed. startup_video_memory_line_budget_warp fails with FAIL: expected one budget line with the heartbeat's WARP memory sample. The other 11 pass, including startup_video_memory_line_warp. |
| restored | 12/12 pass |
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 pr preset, 82/82 passed. It compiled d3d12_xs_device.cpp but ran neither video memory test, because neither is in the pr filter. 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.
|
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):
Separately, 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 |
Refs #3474
Adds the diagnostic line suggested in #3474 (comment):
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 #3480 and #3482.Not covered