Console CPU instructions: no VirtualQuery at every emulated instruction #306
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!306
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/306/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?
@imnicho on GitHub · 2026-11-23 23:00 UTC · original
imnicho:console-insn-no-query→main· +61 −2 · 1 files · 1 commits · merged 2026-11-23 23:48 UTCOn an Intel CPU the newer retail title of the README shows about half a frame a second on
main. Its main thread zeroes memory with CLZERO, and every emulated instruction asks Windows about memory:readabletwice about the code atrip, andis_writableabout the target of every CLZERO loop.VirtualQuerywalks a region to its end to size it – the title's code section forrip, and for the title's memset a committed window of unified memory (gpu/uma.rsnotes ~40 ms a call on a 4 GiB one). This takes those queries out. Part of #184.What the emulation does is unchanged: the loop's semantics are #290 / #295 and the
is_writableguards are planned in #278; none of them changes what the queries cost, and the hunks here are other lines.What is in it
crates/xcl/src/eh.rs,code_bytes_at: the pageripis on is taken as there, since the instruction that raised the exception was fetched from it; only code bytes on the next page are asked about. Testcode_bytes_on_the_instructions_page_are_not_asked_about(also: a CLZERO in the last bytes of a page with nothing mapped after it is still emulated).crates/xcl/src/eh.rs,is_writable: a committed window of unified memory is not asked about (uma::in_committed_window), as ingpu::shader::readable, which the single CLZERO used before #217.Tested
hardware: Intel Core i7-7700K (4 cores / 8 threads; no CLZERO, CLWB or MWAITX), 16 GB RAM, NVIDIA GeForce RTX 5080 (driver 610.47), Windows 10 22H2 (19045), rustc 1.100.0
stable-x86_64-pc-windows-msvc; debug for the tests, release for the title.cargo build --workspace && cargo test --workspace -- --test-threads=4ona99f64c: 652 passed, 0 failed, 40 ignored (SKIPPED GPU tests:gpu_wave32_program_in_wave64_hardware,gpu_geometry_wave32_prefix_count_over_a_mask– no wave64).game checked: the newer retail title of the README,
scripts/smoke.ps1for 60 s, the two builds alternating on the same warm shader cache. Frames shown:main9ab7d76/2953c11, this commit before its rebase)0e946cf/a99f64c, the blocks below)Every run ended by itself with exit 0, no crash and no device removal.
On
main(60565c4) three thread dumps of three runs had the title's main thread inVirtualQueryunder XCL's illegal-instruction handler.Regression run
main:
PR:
Not tested
rip: not measured separately.is_writablehas no unit test (it needs the process's unified memory); the title runs go through it.VirtualQuerya loop.AI use
Duplicate check before opening (2026-11-23 22:49 UTC,
main0e946cf): read #217, #227, #234, #253, #290, #295 and issue #278.🤖 Generated with Claude Code
@requiemsnkrp on GitHub · 2026-11-23 23:15 UTC · original
Tested
a99f64con NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.1714 / 617.14, 32-lane waves), Ryzen 5 5600X, Windows 11 Pro 25H2 (26200.9974), Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17 (Windows SDK), debug: pass.Tested
cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip test_title_draws_with_a_root_signature_under_the_debug_layer: 650 passed, 0 failed, 40 ignoredSKIPPED(no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardwareeh::tests::code_bytes_on_the_instructions_page_are_not_asked_about ... okmain4017f8fon the same machine, same command: 650 passed, 0 failed, 40 ignored, same 2 SKIPPED. The PR's base is0e946cf(before the #289 merge), so the same count includes this PR's new test.main4017f8f(git merge-tree), the merge result was not tested.test_title_runs_and_game_folder_is_untouched,test_title_draws_with_a_root_signature_under_the_debug_layer): they open the XCL game window and this PC was in use (the 2 "filtered out").Not tested
AI use: Claude Code with Claude Opus 5.5 (ran the tests and wrote this report).
@Kalmarv on GitHub · 2026-11-23 23:18 UTC · original
Reviewed
a99f64cmerged ontomain4017f8f(clean withgit merge-tree), looking at what the two skipped queries could miss. Nothing blocks it; three notes, the last one optional.The saving, measured. Scratch tests calling the same functions on
mainand on the merge (debug):mainis_writableof 64 KiB in the committed window, 256 MB of it touchedChecked for a stale answer
in_committed_windowis bounded by the committed size (gpu/uma.rs:473), and a title'sVirtualFreeof window memory returns the block to the allocator or zeroes it, never decommits (hle/kernelx.rs:344-352). What can differ is protection: the title'sVirtualProtectgoes straight to Windows (kernelx.rs:376). For a window page madePAGE_READONLYorPAGE_NOACCESS,is_writablesays false onmainand true on the merge (ran both), so an emulated CLZERO there would fault inside the handler instead of being passed on.gpu::shader::readablealready assumes the same onmain.ripis on: withreadable(rip, 1)gone, aripon a page that is not there kills the handler. Scratch test, a registered module with that page decommitted:mainreturns 0, the merge dies with an access violation. A CPU-raised exception cannot get there (the page was just executed, and the loader commits whole images,loader.rs:72), only a record raised by software with its own context, or another thread decommitting the code in between.main, 8.1 ms on the merge.Optional, covers 2 and 3:
ReadProcessMemoryon the own process read the 16 bytes in 0.17 µs in that region and returned 0 for the decommitted page. It is all or nothing (0 bytes when the next page was missing), so the part onrip's page and the part on the next need a call each.The PR's test passes on the merge. It also passes on
mainwithmain's expression under the namecode_bytes_at: it holds the behaviour (the byte counts, the CLZERO at a page end), not the saving. That seems right for this change; the table is the other half.Tested
a99f64cmerged onto4017f8fas13c7501;main4017f8fas the control.cargo test -p xcl --lib -- eh::tests::: 4 passed, 0 failed on the merge.emulate_console_onlyandis_writabledirectly: this CPU has CLZERO.Not tested
🤖 Claude Fable 5.2
@ivall on GitHub · 2026-11-23 23:48 UTC · original
Merged (
2b4bb43). Checked on an RX 9070 (RDNA4) on main2b4bb43together with #306, #288 and #294:cargo build --workspace && cargo test --workspace -- --test-threads=4- 630 unit tests passed, 0 failed; the retail game reaches its menus and starts loading the world (stopped at ~150 s by the machine's commit limit, not by the game). The merge conflicted with #290'scmp_eflagsand its tests ineh.rs; both are kept.