Skip to content

hle,eh: reclaim partial physical frees, shard lazy VEH, harden dstorage/input/audio - #2004

Open
raylitebull wants to merge 2 commits into
xcl-dev:mainfrom
raylitebull:feat/world-sys-dstorage-and-phys
Open

raylitebull wants to merge 2 commits into
xcl-dev:mainfrom
raylitebull:feat/world-sys-dstorage-and-phys

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Hardens HLE world streaming, physical-page reclamation, lazy VEH sharding, monitor/mwait patching, audio buffer reuse, and GameInput/KBM playability:

  1. Physical pages & kernelx/lazy.rs:
    • Keeps XMemVirtualAlloc / physical fallbacks below the 40-bit VA ceiling via VirtualAlloc2; stops large AllocateTitlePhysicalPages pools from stealing pre-committed coherent UMA; skips committing lazy pages on reads while ensuring lazy pages before writes (uses existing upstream XMemIsToolsMemAvailable in kernelx.rs).
    • Replaces PHYS_BLOCKS counters with a per-page live bitmap (PhysBlock) for exact per-page liveness, double-free immunity, and immediate coalesced MEM_DECOMMIT + sparse::decommitted on partial FreeTitlePhysicalPages calls.
    • Shards the lazy-page table across 16 contiguous 4 MiB stripes (kernelx/lazy.rs) with atomic LAZY_COUNT / LAZY_COMMITTED_ANY fast paths and batched lazy::mark / unmark.
  2. DirectStorage streaming (dstorage.rs, dstorage/parallel.rs, dstorage/parallel_tests.rs):
    • Refreshes zero or stale (freed) physical page-table entries on write/read retry (0x89240009 prevention, using read_own so unmapped page arrays never fault per #509) and extends parallel decompression to physical-page destinations and supported BCPack requests.
  3. Monitorx/Mwaitx & EH (eh.rs):
    • Replaces the global SEEN mutex in emulate_console_only with a lock-free AtomicU16 bitmask and live-patches Monitorx -> nop;nop;nop and Mwaitx -> pause;nop via atomic aligned u64 CAS + FlushInstructionCache (opt-out via XCL_NO_PATCH_MONITORX=1).
  4. Audio (opus.rs, acphal.rs):
    • Caches/reuses unique Media Foundation IMFSample/IMFMediaBuffer pairs across MftDecoder packets; splits XApu stream locks to per-stream mutexes with reusable PCM/float scratch buffers and atomic progress throttling (preserving #471's Channel::connect clear).
  5. GameInput & KBM (gameinput.rs, kbm.rs):
    • Skips disconnected-pad XInput rumble stalls and deduplicates unchanged speeds; adds bounded GetNextReading/GetPreviousReading history; extends XCL_PRESS_AT for triggers/sticks/durations; adds Z/C bumper keys; gates mouse buttons on capture/non-sizing and guards zero-delta poll velocity decay (preserving #552's PlayStation HID fallback).

Part of #1833.

What is in it

  • crates/xcl/src/eh.rs, crates/xcl/src/hle/{acphal.rs, dstorage.rs, dstorage/parallel.rs, dstorage/parallel_tests.rs, gameinput.rs, kbm.rs, kernelx.rs, kernelx/lazy.rs, opus.rs} (10 files).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto d63071a (c57227f).
  • c57227f was rebased and trimmed onto d63071a (dropping the duplicate XMemIsToolsMemAvailable definition after #563 and integrating read_own in dstorage.rs::refresh_stale_pages after #509 via pure git during a local test hold); queued for GitHub Actions Build and test and fresh AMD / NVIDIA verification.
  • Earlier pre-rebase head 462a456 (onto 6567c5f) passed cargo check --workspace --tests, eh::tests (7/7), hle::acphal::tests (8/8), dstorage (30/30), hle::gameinput::tests (12/12), hle::kbm::tests (8/8), hle::kernelx::tests (37/37, 1 ignored), hle::kernelx::lazy::tests (3/3), and hle::opus::tests (14/14).

Regression run

  • Standalone scripts/smoke.ps1 pair and tests on rebased c57227f vs d63071a have not been run yet. AMD and NVIDIA reviewers are invited to verify c57227f vs d63071a (including scripts/smoke.ps1, DirectStorage streaming, and GameInput/KBM paths) and post results in the comments.

Not tested

  • cargo check / cargo test suite and 60 s scripts/smoke.ps1 pair on rebased head c57227f, full cargo test --workspace suite, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation, rebase onto d63071a, and unit tests; the author reviewed the diff.

@raylitebull

Copy link
Copy Markdown
Member Author

Overlap note: full credit to #565 (@ZekkJJ) for retaining recent GameInput readings for GetNextReading / GetPreviousReading in gameinput.rs.

If #565 lands first, we will drop the reading-history hunks from #2004 and keep #2004 focused on its independent eh, acphal, dstorage, kbm, kernelx, lazy, opus, and XCL_PRESS_AT / rumble changes.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 462a456 (on its base 6567c5f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, 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 gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 999 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: monitorx_and_mwaitx_patch_to_nop_and_pause_safely, xapu_reuses_stream_scratch_and_supports_concurrent_streams, parallel_decode_supports_physical_page_destinations_and_late_refresh, rumble_skips_disconnected_pad_and_deduplicates_unchanged_speeds, next_and_previous_reading_walk_state_changes_and_terminate, extended_scripted_actions_drive_triggers_sticks_and_durations, mouse_buttons_require_capture_and_not_sizing, high_frequency_zero_polls_do_not_prematurely_decay_velocity, xmem_tools_mem_and_40bit_virtual_alloc, physical_page_reads_skip_commit_writes_ensure_lazy_and_free_unmarks, partial_free_tracks_exact_liveness_decommits_homes_and_ignores_double_free, sharded_lazy_batch_spans_stripes_and_unmarks_cleanly, mft_decoder_reuses_cached_samples_across_packets.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1009 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (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), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

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.

…ility

- kernelx: keep plain XMemVirtualAlloc/physical fallbacks below the 40-bit VA
  ceiling via VirtualAlloc2 when available; stop large AllocateTitlePhysicalPages
  pools from stealing pre-committed coherent UMA; skip committing lazy/unmapped
  pages on read_physical_pages while ensuring lazy pages before writes; unmark
  freed lazy pages in FreeTitlePhysicalPages. (XMemIsToolsMemAvailable is
  already on main via xcl-dev#563.)
- dstorage: refresh zero or stale (freed) physical page-table entries via
  read_own (xcl-dev#476/xcl-dev#509 safe) on write/read retry; extend the parallel
  decompression pool to handle physical-page destinations and supported BCPack
  requests.
- gameinput & kbm: skip disconnected-pad XInput rumble stalls and deduplicate
  unchanged motor speeds; implement bounded reading history for GetNextReading /
  GetPreviousReading; extend XCL_PRESS_AT with triggers, sticks, LS/RS, and
  optional durations; add Z/C holdable bumper keys, require mouse capture and
  non-sizing for mouse buttons, and guard KBM mouse velocity against sub-0.5 ms
  zero-delta poll decay.
…x/mwaitx, and reuse XAPU/Opus buffers

- kernelx: replace PHYS_BLOCKS counters with a per-page live bitmap (PhysBlock)
  for exact per-page liveness, double-free immunity, and immediate coalesced
  MEM_DECOMMIT + sparse::decommitted on partial FreeTitlePhysicalPages calls
  even while sibling pages in multi-GB pools stay live. Batch lazy::mark/unmark
  across map_pages and FreeTitlePhysicalPages.
- kernelx/lazy: shard the lazy-page table across 16 contiguous 4 MiB stripes
  with atomic LAZY_COUNT / LAZY_COMMITTED_ANY fast paths so direct I/O checks
  and non-lazy faults avoid global RwLock contention and redundant VirtualQuery
  calls while parallel threads commit distinct regions concurrently.
- eh: replace the global SEEN mutex in emulate_console_only with a lock-free
  AtomicU16 bitmask, and race-safely live-patch Monitorx -> nop;nop;nop and
  Mwaitx -> pause;nop (with atomic aligned u64 CAS + FlushInstructionCache and
  XCL_NO_PATCH_MONITORX=1 opt-out) so worker spin loops stop taking #UD traps.
- opus & acphal: cache and reuse unique Media Foundation IMFSample/IMFMediaBuffer
  pairs across MftDecoder packets (verified via COM refcount); split XApu stream
  locks to per-stream Mutexes with bounded reusable PCM/float scratch buffers
  and lock-free AtomicU64 progress throttling.
@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 462a456, based on main 80f4819. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 462a4561b65ae153bf515c8378ceb3e091638df2
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1557 (PresentX 1558)
presents per 2 s (last 3): 57 26 18
device removals: 0
crashes: 0
peak commit: 26606 MB

No device removals or crashes; 98 % of main's frames, 105 % of its peak commit.

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@raylitebull
raylitebull force-pushed the feat/world-sys-dstorage-and-phys branch from 462a456 to c57227f Compare November 25, 2026 01:54
@raylitebull

Copy link
Copy Markdown
Member Author

Rebased and trimmed #2004 cleanly onto d63071a (4d7d3bb + c57227f):

  • Dropped #563 duplicate: removed our duplicate XMemIsToolsMemAvailable() definition from crates/xcl/src/hle/kernelx.rs (using #563's implementation on main).
  • Integrated #509 (#476): updated dstorage.rs::refresh_stale_pages to use read_own (ReadProcessMemory) so unmapped page arrays never fault while still refreshing stale/freed page entries.
  • Preserved #552 & #471: cleanly kept the PlayStation HID fallback in gameinput.rs and Channel::connect clear in acphal.rs.

Pushed c57227f for GitHub Actions Build and test and fresh verification.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants