startup: stop the stand-ins' first-calls log counters at their limit #1980
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1987"
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 rasptum on 2026-11-24T22:37:05Z.
The stand-ins limit many log lines to the first N calls with
InterlockedIncrement(&counter) <= N, andx2w_local::first_callsinsrc/startup_stubs/local_log.huses the same expression. The counter counts every call. A consumer that polls a status in a loop drives it past 2^31; it turns negative, and from then on every call is logged again. In a local run this produced millions of lines a minute and stalled the process.x2w_local::first_callsnow stops incrementing at the limit, using a compare-exchange loop with no lock. Output for the first N calls is unchanged.xcrdapi.cpp(13),xg_xs.cpp(3),d3d12_draw.inl(3),runtime_proxy.cpp(tracked_logged) and theX2W_D3D12_DUMP_PSOper-slot gate ind3d12_xs_device.cpp. The device's ownfirst_callsforwards to the helper.render_draws,shown_framesand the runtime proxy's per-slotcall_counts.shape_checks: it checks< 32before incrementing, so it cannot wrap.checks & 63periodic device check: the mask still works after a wrap.startup_local_lognow expects the counter to stay at the limit (3, 0 for a zero or negative limit, exactly 10 under 4 threads). It also checks a counter set to0x7FFFFFFE: with a limit of 4, none of 16 calls may pass.startup_local_log_wrap_control(--mutate wrap) runs that wrap case with the old counting expression. It passes only on the lineFAIL first_calls passes no call at the wrap point, so any other failure makes the control fail.A local check, not part of this change: putting the old expression back into the header made
startup_local_logfail its saturation and wrap cases.Test (both presets, throttled build of the touched targets, plus
d3d12_xs_shimto compile the device file):startup_local_log: 92 cases;startup_local_log_wrap_controlpassed on its expected FAIL line).--preset release: 17 passed, 0 failed, 0 skipped.tests/docs_links_check.pyandtests/bidi_controls_check.pypass.docs/startup-runtime.md(Local switches) describes the saturating gate and names the new control.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T22:48:41Z.
Built and ran it; both ways back to the bug are caught
Windows 11 build 26300.9974, MSVC 19.44,
devpreset:startup_local_log_cache_failure_controldid not run because its executable was not in my build selection — my environment, not the PR. Thefour that ran are green, and the log-flood output the fix is about is visible in their output:
~1.1 million lines per second on the unusable path is the rate that made the counter matter; the fix keeps that burst to the configured
limit instead of letting it resume at 2^31.
Mutations
src/startup_stubs/local_log.hfirst_callsback toreturn InterlockedIncrement(&counter) <= limit;(the original bug)seen < limit→seen <= limit(off-by-one at the cap)The first is the important one: restoring the exact pre-change expression makes the fixture fail, so the regression it prevents is pinned
rather than assumed. The second shows the cap is the limit, not "somewhere near it" — an off-by-one would have let one extra line through
and left the counter at
limit + 1, which is the same class of runaway the fix exists to stop, just slower.Why the helper and not the call sites
The same expression appeared at 13 + 3 + 3 + 1 + 1 sites. Capping it once in
first_callsis the only version that cannot drift, and thecall sites that were converted are listed in the description so a reviewer can check the count rather than trust it. The three counters that
also feed statistics (
render_draws,shown_frames, runtime proxy slot counts) keeping their full count while logging only while positiveis the right split: a counter that stops counting breaks the statistic, a counter that keeps counting breaks the gate.
What is unverified
Nothing process-level beyond this fixture: the 2^31 turn is exercised by the counter arithmetic, not by driving a real provider past two
billion calls. Whether a title's own polling loop hits the same path is a claim about the provider, not about this header.
Verdict
Reviewed. The bug is real, the fix is in the one place that cannot be forgotten, and both the old expression and an off-by-one fail the
fixture.
Notes