kernelx: the finest system timer for the title (choppy audio, #260) #300
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!300
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/300/head"
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?
@AAigars on GitHub · 2026-11-23 22:42 UTC · original
AAigars:kernelx-timer-resolution→main· +47 −0 · 2 files · 1 commits · merged 2026-11-24 02:19 UTCFixes #260.
The choppy sound in the retail title is not the audio processor: the game mixes on the CPU and plays through Windows spatial audio (
ISpatialAudioClient, two static objects, 48 kHz float), and that stream was fed on time but with sound in only 34 % of its 10 ms passes. The mixer sleeps between 5.33 ms chunks, and without a finer timer Windows wakes it on its 15.6 ms tick, so it made a third of real time (5.33 / 15.6 = 34 %). XCL now asks for the finest timer Windows offers (0.5 ms) at start, and opts out of the Windows 11 power throttling that drops it while the window is hidden. With it every pass has sound.What is in it
kernelx::fine_timer(crates/xcl/src/hle/kernelx.rs):NtSetTimerResolutionto the finest resolutionNtQueryTimerResolutionreports,SetProcessInformation(ProcessPowerThrottling, IGNORE_TIMER_RESOLUTION), onetimer:log line; testfine_timer_makes_short_sleeps_short(20 × WindowsSleep(1), average under 5 ms: 15.4 ms without the fix, fails; passes with it)host_mainafterhle::init(crates/xcl/src/host.rs)Tested
cargo test --workspace --release -- --test-threads=4: 652 passed, 0 failed, 40 ignored (SKIPPED:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware– no wave64)<package id>1.0.2.1),XCL_NETWORK=0: the menu's sound is continuous instead of choppy. Measured with temporary logging on the game's spatial audio stream (not in this PR): before, sound in 172 of 500 passes per 5 s, evenly spread; after, 500 of 500 once the sound starts.Regression run
main:
PR:
5 frames fewer over 60 s (0.3 %) at the same rate at the end; one run each, so within run-to-run noise.
Not tested
AI use
@likecrank-dotcom on GitHub · 2026-11-23 22:49 UTC · original
Independent native Windows/NVIDIA validation of #300 at
9507d05496be7bd87ca769d95cdfec705a3bd6cf(clean checkout).Tested
cargo build --workspace: exit 0; one pre-existingfetch_updatedeprecation warning.cargo test --workspace -- --test-threads=4 --nocapture: exit 0; 652 passed, 0 failed, 40 ignored over 17 result blocks (lib: 612 passed, 0 failed, 20 ignored). The synthetic-title end-to-end test passes.fine_timer_makes_short_sleeps_shortpasses. Log:was 15.62 ms, now 0.50 ms; kept while the window is hidden: yes.Separate before/after probe, using the actual PR function
A small local Rust executable depends on this checkout's
xcllibrary. In one fresh process, it measures three batches of 20 calls to WindowsSleep(1), callsxcl::hle::kernelx::fine_timer()once, and measures three more batches.Instantmeasures each batch; nostd::thread::sleep, no title is loaded. It was run after the workspace tests ended, usingcargo run --offline --manifest-path <local-probe>/Cargo.toml.This reproduces a shorter wait after the timer request on this host. The before values are the measured 7-8 ms, not assumed to equal the queried 15.62 ms system resolution. This does not measure audio quality, mixer continuity, or game performance.
SKIPPED / Not tested
Four explicit skips:
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64);test_title_draws_with_a_root_signature_under_the_debug_layer(no d3d12SDKLayers.dll);uploads_start_from_each_subresources_state(no D3D12 debug layer, 0x887A002D). No XCL_SAMPLE variables were set. No retail title/smoke blocks, no listening test, no verification with an occluded/minimized title window, no power-use measurement, AMD, Wine or Windows 10. The opt-out API's reported success is not an independent check of hidden-window behavior.AI use
Codex wrote the local probe, executed the build/tests/probe and summarized the actual logs. Exact deployed model identifier is not exposed in this session. No runtime changes or game data published.
@mosin311aa on GitHub · 2026-11-23 23:07 UTC · original
Can confirm this fixes the choppy audio problem on my RTX 4070 Super system, no idea if this is the best solution though
@ryosen0 on GitHub · 2026-11-23 23:52 UTC · original
Data point on the intro slow stretch (our machine: RTX 3060 Ti 8 GB, Ryzen 7 9800X3D, driver 32.0.16.1742): the retail title's artwork intro runs at ~4.4-8.6 fps for roughly t=45-165 s, then a steady 30 fps. We measured the same dip with and without this PR + #294 in the stack (same graphics PRs otherwise, XCL_NETWORK=0, XCL_ACTIVITY=1):
So the dip is not the audio path on this hardware - noting it so nobody chases the timer / Opus work for it. In the no-audio run during the dip (t=90 s): 15252 MB committed by the process, video memory 6515 MB local + 4619 MB non-local on the 8 GB card, 3231 MB of target pages; by t=178 s it is 17071 MB / 7791 MB local. DXC compiles are all cache hits there (dxil_cache 25 hits, 0 misses). It looks like memory pressure and streaming, not compilation.
Separately, a 600 s run on an older stack (main
4017f8f+ #300 + #294 + #273/+#208 + #283/+#252, before #283 was merged) reached the character loading screen and then crashed at t=395 s with 0xc0000005 (write at 0xc43440110, game+0x35a47bc) at ~26.6 GB of commit - past the loading screen, so probably unrelated to this PR.AI use: GPT-6.2 Astra (API model selector) ran the builds/runs and wrote this report; the human contributor watched the runs.
@mastrr9 on GitHub · 2026-11-23 23:10 UTC · original · edited 2026-11-24 00:23 UTC
Independent static code & Win32 API audit of
9507d0549(code inspection only —cargo testnot run on macOS; no game files):Summary: Clean and matches Windows API semantics
PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION(kernelx.rs:1293-1299): SettingControlMask = PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTIONwithStateMask = 0matches Microsoft Learn for opting out of Windows 11's occluded/background timer-resolution throttling, and ignoring aFALSEreturn on Windows 10/Wine degrades gracefully.NtQueryTimerResolution/NtSetTimerResolution(kernelx.rs:1272-1273,1301-1307): Signatures ((u32, u8, *mut u32) -> i32) and parameter ordering (coarsest,finest,current) matchntdll, and the Windows kernel automatically releases per-processNtSetTimerResolutionrequests on process exit/crash.Two small notes
Fixes #260): Since #260 was updated to track both the 15.6 ms timer tick andxapureturning silence for Opus packets (#294), changingFixes #260.toPart of #260.avoids auto-closing #260 before #294 lands.ISpatialAudioClient): Your finding that the title mixes on the CPU and outputs throughISpatialAudioClientdirectly answers #294's open question ("Where the title's final mix goes is not found yet") — worth checking whether #294'sxaudio2::console_pcmdirect playback double-plays decodedxapuaudio on Windows oncexapuwrites real PCM into the title's buffer.(AI-assisted — Gemini 4 Neon)
Update: Windows 11 / RTX 5080 test run on
9507d0549Tested
rustc 1.100.0(MSVC), debug build in a clean worktree at9507d05496be7bd87ca769d95cdfec705a3bd6cf.cargo build --workspace && cargo test --workspace -- --test-threads=4: 652 passed, 0 failed, 40 ignored (xcllib: 612 passed, 0 failed, 20 ignored; all e2e/GPU suites passed).SKIPPEDGPU tests (2, wave32-only adapter):gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.hle::kernelx::tests::fine_timer_makes_short_sleeps_shortpassed.Not tested
scripts/smoke.ps1run on this machine (test suite only).AI use: test run orchestrated and reported with Antigravity (Gemini 4 Neon) on the hardware listed above.
@emirduran707 on GitHub · 2026-11-24 00:32 UTC · original
First AMD run: the sound plays cleanly with this PR.
Setup: AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.31044.16; Ryzen 5 5600, 32 GB; Windows 11 Pro 26300; release. Build:
maina6f5f7a+ this PR (9507d05) + #440 (be722a7, so the intro video runs at speed) + #435 (a94e151), merged locally. Same retail title as #260,XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_FRAME_DUMP=60, A pressed by hand on the first menu, a person listening.timer: finest resolution for the title (was 1.00 ms, now 0.50 ms; kept while the window is hidden: yes).xapu: … Opus packets decodedlines: 50 packets a second from the video on (960 frames each, so real time at 48 kHz), 100 a second once a second stream starts. Without this PR, onmain+ #440 only, the same stretch decoded about 17 packets a second (~0.34 of real time).Not tested / not attributed: the run ended at 161 s with
0xc0000005in title code (+0x23cf683, write at address 0) while the world streamed in, at 27 GB of process commit, with noE_OUTOFMEMORYlogged. With three PRs in the build and no longer baseline run on this machine I cannot tie it to any of them. NVIDIA, other titles.AI use: Claude Code with Claude Opus 5.5 read the run's log and wrote this report from my run; the listening is mine.
@Chrysana on GitHub · 2026-11-24 01:40 UTC · original
Test report for #300 at
9507d05on AMD RX 9070 XT, merged onto currentmain508a0c7(local merge1a47cac, clean, not pushed). A person listened to each run.Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0
x86_64-pc-windows-msvc, release builds. Retail title 1.0.2.1.XCL_NETWORK=0 XCL_RUN_SECONDS=60 XCL_ACTIVITY=1 XCL_PRESS_A_AT=14,17,21 xcl run <folder>, one run per build.main508a0c7main+ #300main+ #300 + #451 (1f282c7, local mergee6daa0e)timer: finest resolution for the title (was 1.00 ms, now 0.50 ms; kept while the window is hidden: yes). Another program had already set the system timer to 1 ms; the title's audio was choppy anyway.report.json's xapu counters are the same in all three runs (23 Opus packets, 21768 frames, about 0.45 s). So the intro's sound doesn't go through xapu. It comes from the title's CPU mix, and it seems to need the video running at speed.Fixes #260if this merges first.Not tested: the test suite and
smoke.ps1on this PR (none of the above is a regression run); gameplay past the intro; the cause of the single stutter; Windows 10.AI use: Claude Code with Claude Opus 5.5 built the merges, ran the title and read the logs and
report.json, and wrote this report. The listening was done by me.@Kalmarv on GitHub · 2026-11-24 02:17 UTC · original · edited 2026-11-24 02:23 UTC
Regression run for this PR's head on Windows.
Tested
cargo build --release -p xcl) from clean checkouts0e946cfc68244edee1fba6e0425371f687a05ccd(a commit on main with no code change from this PR's base9ab7d76); PR head:9507d05496be7bd87ca769d95cdfec705a3bd6cf, no uncommitted changesscripts/smoke.ps1 -Game <title folder> -Seconds 60on a retail title, main first, after one 60 s warm-up run of main; both sides start from the same learned coherent-window sizetimer: finest resolution for the title (was 1.00 ms, now 0.50 ms; kept while the window is hidden: yes); main's run has no timer lineRegression run
main:
PR:
Not tested
cargo test --workspace(not run for this report)🤖 Claude Opus 5.5
xcl shadersout of EcoQoS execution-speed throttling #2777