Skip to content

kernelx: VirtualAllocEx for this process is the title's allocator - #1796

Closed
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:kernelx/virtualallocex-title-memory
Closed

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:kernelx/virtualallocex-title-memory

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Addresses XCL-BT-030 from #1488.

VirtualAllocEx forwarded every call to Windows with the console's allocation flags sanitised — for GetCurrentProcess(), which is the title's own memory, that meant MEM_GRAPHICS was dropped and the title got a plain Windows reservation the GPU has no address for. VirtualAlloc is where the console's memory actually comes from: placeholders, the sparse windows, video memory in the unified region, 64 KiB pages, and the write-watched graphics fallback. VirtualFreeEx already routes this process back to VirtualFree for exactly those allocations (kernelx.rs:454-464) — the allocation side did not match.

This routes VirtualAllocEx(GetCurrentProcess(), …) to VirtualAlloc, the same way VirtualFreeEx routes to VirtualFree.

What is in it

  • crates/xcl/src/hle/kernelx.rs: VirtualAllocEx sends this process to VirtualAlloc; other processes stay Windows' VirtualAllocEx. Test virtual_alloc_ex_for_this_process_is_the_titles_allocator (a MEM_RESERVE | MEM_GRAPHICS allocation must be inside the unified region or a sparse window, then VirtualFreeEx releases it).

Evidence it fails without the fix:
VirtualAllocEx(GetCurrentProcess()) must land in the title's memory, got 0x25c95970000 — a host reservation with the graphics flag dropped; with the fix it is a sparse-window/unified address and test result: ok.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 893 passed, 0 failed, 42 ignored (SKIPPED: 2 no wave64; 1 no heap windows; 1 cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib virtual_alloc_ex_for_this_process: 1 passed, 0 failed

Regression run

main (e9e94ce, clean tree, no local changes):

xcl-smoke v1
commit: e9e94ce665d16bb0e2d2e4cb6b37e149f0d27721
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1646 (PresentX 1646)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14489 MB

PR (c702d7d, clean tree, no local changes):

xcl-smoke v1
commit: c702d7d573f6b829d77b633c83a160f91f2f31c0
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14613 MB

Not tested

  • a title that calls VirtualAllocEx(GetCurrentProcess(), …) for a normal (non-graphics) allocation and then writes to it before committing (the unified/sparse path handles commits, but no game here was traced doing it)
  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: checked XCL-BT-030 against VirtualAlloc/VirtualFreeEx, wrote the fix and test (and confirmed it fails without it), rebased onto e9e94ce, ran the test suite and scripts/smoke.ps1 regression runs with Scripts: smoke blocks print the game folder's name #677's title hashing, and drafted this PR description.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
VirtualAllocEx forwarded every call to Windows' VirtualAllocEx with the
console's allocation flags sanitised, so for this process - the title's
own memory - MEM_GRAPHICS was dropped and the title got a plain
reservation the GPU has no address for. VirtualAlloc is where the
console's memory comes from: placeholders, the sparse windows, video
memory in the unified region, 64 KiB pages, the write-watched graphics
fallback. VirtualFreeEx already routed this process back to VirtualFree
for exactly those allocations; the allocation side did not.

Route VirtualAllocEx(GetCurrentProcess(), ...) to VirtualAlloc, as
VirtualFreeEx does to VirtualFree.

Assisted-by: OpenCode (Gemini 4 Neon)
@b3IKK
b3IKK force-pushed the kernelx/virtualallocex-title-memory branch from 1475636 to c702d7d Compare November 24, 2026 21:15
@b3IKK

b3IKK commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto e9e94ce (which also brought #677's anonymised itle: line into scripts/smoke.ps1) and re-ran the test suite and both smoke runs: 893 passed, 0 failed, 42 ignored; blocks pasted above are from the new script.

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head c702d7d (on its base e9e94ce).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip pso_measurement_compiles_an_exact_synthetic_record: 891 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: virtual_alloc_ex_for_this_process_is_the_titles_allocator.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 893 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • Two tests were skipped with --skip on NVIDIA. Both fail on main 7f7e768 too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. heap_window_out_of_memory_falls_back_to_the_switch_form skips when XCL_HEAP_WINDOWS is unset (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), and shaders::tests::pso_measurement_compiles_an_exact_synthetic_record skipped because Developer Mode was off. Developer Mode was turned on before the AMD run, and there pso_measurement_compiles_an_exact_synthetic_record ran and passed.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.

Thanks!

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Test report for exact head c702d7d.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88, 32-lane waves), Intel i9-12900K, 64 GB; Rust 1.100.0 MSVC; DXC 1.9.2602.17; tests in debug, title runs in release.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on c702d7d as it is (its own base): 893 passed, 0 failed, 42 ignored. SKIPPED: 4 lines (no wave64 on this adapter, and the like).
  • scripts/smoke.ps1, the retail title, 60 s, release builds, main 568e7db first, then this head:

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15852 MB

PR:

xcl-smoke v1
commit: c702d7d573f6b829d77b633c83a160f91f2f31c0
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16068 MB

Not tested: AMD, the head merged onto current main, a world load.

AI use: Claude Code (Claude Opus 5.5) ran this and wrote the report; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

@throny

throny commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that this PR makes the same change as #1564 (for #1488): #1607, group D91. They suggest keeping #1564. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@raylitebull raylitebull added the duplicate This issue or pull request already exists label Nov 28, 2026
@raylitebull

Copy link
Copy Markdown
Member

Closing as a duplicate of #1564 (confirmed by 2+ contributors in #1607, group D91). Thanks for the contribution — feel free to comment if this covers something #1564 does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants