Skip to content

Memory: use a 2 MiB grain for allocator page size two - #3092

Open
Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:codex/gdkx-two-mib-page-grain
Open

Prime1997 wants to merge 1 commit into
xcl-dev:nvidia-devfrom
Prime1997:codex/gdkx-two-mib-page-grain

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Correct XMemAllocDefault graphics PageSize=2 rounding from 4 MiB to 2 MiB while preserving larger explicit alignment, overflow checks and recorded allocation/free accounting.

What is in it

  • One page-grain correction, related comments and three bounded fixtures in kernelx.rs; README behavior note.
  • The test title now checks 2 MiB alignment and the first/last words within that allocation, preserving its null, zeroing and free checks.

Tested

  • Windows build 26200 x64; Intel Core i5-10400; RTX 3060 Ti, driver 32.0.16.1714; Rust 1.100.0 MSVC, debug profile with debug symbols disabled.
  • 3 passed, 0 failed, 0 ignored, 0 reported skips. Restoring the original 4 MiB grain fails all three controls. Fixtures check boundary rounding, other page codes, overflow, owned allocation charging and release.
  • cargo test --locked -p xcl --lib --target-dir <private-target> -- --exact --test-threads=1 --nocapture hle::kernelx::tests::xmem_graphics_page_size_two_uses_two_mib_grain hle::kernelx::tests::xmem_graphics_page_grain_preserves_other_codes_and_checks_overflow hle::kernelx::tests::xmem_two_mib_layout_accounts_and_releases_owned_memory
  • The three focused results above are historical, from the preserved patch on NVIDIA ba9d1f947. The previous PR head was d40a1540f6497eabcbe36793f4a6c1c2254d91ac. New squashed head f00e1c4fec6207ed99489947b0180caefaf57c53 includes the test-title correction and has not been run individually. Source review and git diff --check passed; they are not native-test coverage.

Regression run
Pending. No retail smoke blocks are claimed.

Not tested

  • The full suite and retail regression on this individual PR head, AMD, or launch readiness. A separate seven-fix candidate 5d0833553c68d2afa327c913cd9a22f17ec6f45e includes this correction; its full suite and release build are pending. Those combined results will be reported separately and will not establish an individual PR smoke run.
  • This does not implement physical-page clusters, XMemVirtualAlloc flag routing, allocator hooks or native fallback alignment. Memory: preserve XMem graphics alignment in the Windows fallback #1343 owns the separate fallback-alignment issue and retains the older grain.

AI use
Codex (GPT-6) implemented and independently reviewed the change and ran the reported checks. API contracts were checked against local GDK documentation; no SDK code, headers, binaries, samples or documentation text are included.

Optional temporary Discord for coordinating contributor work, testing and comparing results.

@Prime1997
Prime1997 force-pushed the codex/gdkx-two-mib-page-grain branch from 0153bbd to d40a154 Compare November 28, 2026 03:38
@Prime1997
Prime1997 marked this pull request as ready for review November 28, 2026 03:39
@DarkPanda69

DarkPanda69 commented Nov 28, 2026 •

Copy link
Copy Markdown

Update for head f00e1c4 (same parent e48e74c): same command, 62 passed, 0 failed, 1 ignored, the three new tests ok.

Run on a Ryzen 7 5800X PC (the AMD side was listed as untested, but as far as I can see these tests only reserve CPU memory with VirtualAlloc and create no D3D12 device): the three new tests pass, and nothing else in kernelx changes.

Tested: at the PR head d40a154 against its merge-base with nvidia-dev, e48e74c (the diff doesn't apply as a patch on today's nvidia-dev 01b94f5). Debug, Rust 1.100.0, Windows 11 Pro 26200, XCL_ADAPTER=Radeon (RX 9070 XT).

  • cargo test -p xcl --lib -- hle::kernelx::tests:: --test-threads=1 --nocapture: merge-base 59 passed, 0 failed, 1 ignored; PR 62 passed, 0 failed, 1 ignored, no SKIPPED.
  • The only changes are xmem_graphics_page_size_two_uses_two_mib_grain, xmem_graphics_page_grain_preserves_other_codes_and_checks_overflow and xmem_two_mib_layout_accounts_and_releases_owned_memory, all ok.

Not tested: the whole suite, a title, the RTX 3060 (no GPU path in these tests that I could see).

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of #3092 head d40a1540, based on nvidia-dev e48e74ca. RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC, DXC 1.8.2502.11.

The three new allocator fixtures passed on this exact head (3/0/0, no reported skip). The full cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 finished 1,900 passed, 5 failed, 48 ignored across 40 targets, with 26 explicit SKIPPED notices. Three of the five failures were the test-title e2e cases. All three hit the same stale expectation in tests/testtitle/src/main.rs: it still requires page-size code 2 to return a 4 MiB-aligned allocation and reads its 4 MiB end, while this PR changes that grain to 2 MiB. The observed address was 2 MiB aligned and failed the old check.

I changed only that test-title expectation locally, rebuilt the workspace, and ran cargo test --offline --locked -j 4 -p xcl --test e2e test_title -- --test-threads=1: 3 passed, 0 failed, 0 ignored. git diff --check passed. The candidate is below; please include the updated end-of-allocation zero check along with the alignment wording so the test does not probe beyond the new 2 MiB allocation.

Verified test-title correction
@@
-        // 4 MiB page-size semantics (XALLOC_PAGESIZE_4MB = 2 << 14): 4 MiB-aligned & zeroed
-        let attrs_4m = (1u64 << 29) | (2u64 << 14);
-        let big = XMemAlloc(0x1000, attrs_4m);
-        ensure!(!big.is_null() && (big as usize) % (4 << 20) == 0, "4MB page alloc not 4 MiB aligned: {big:?}");
-        ensure!(*(big as *const u64) == 0 && *((big as usize + (4 << 20) - 8) as *const u64) == 0, "4MB page alloc not zeroed");
-        XMemFree(big, attrs_4m);
+        // Page-size code 2 uses a 2 MiB grain: the returned allocation is aligned and zeroed.
+        let attrs_2m = (1u64 << 29) | (2u64 << 14);
+        let big = XMemAlloc(0x1000, attrs_2m);
+        ensure!(!big.is_null() && (big as usize) % (2 << 20) == 0, "2MB page alloc not 2 MiB aligned: {big:?}");
+        ensure!(*(big as *const u64) == 0 && *((big as usize + (2 << 20) - 8) as *const u64) == 0, "2MB page alloc not zeroed");
+        XMemFree(big, attrs_2m);

The other two suite failures were the mesh-cache test (DXIL not compiled yet, also reproduced on unchanged e48e74ca) and d32s8_targets_take_their_own_size_of_video_memory, which passed an isolated rerun on this head (1/0/0) and also failed in my #3090 concurrent suite. I have not resolved that concurrent failure or run paired retail smoke; this is not a merge-ready verdict.

AI use: Codex (GPT-6.2 Sol) inspected the patch, ran the tests, and verified the test-title correction.

Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 28, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 28, 2026
main gained 345 commits since 753e8b1, most of them bmjask's stack (xcl-dev#2959),
plus xcl-dev#2872, xcl-dev#3085 and xcl-dev#3086 from this branch. Conflicts, per PR:

- xcl-dev#2404 + xcl-dev#2633 (split chained ExecuteIndirect): main's xcl-dev#2959 took both over
  (ed98461, a05fbc4, 8626d5b: IndirectBuild/IndirectChain on a CBV root,
  one-command slicer, separate cache namespace). Main's side kept in
  dispatch_chain.rs, pso.rs (slicer, command signature, chain root),
  bind.rs (ExecuteIndirect path), device_x.rs (signature traits),
  pso_async.rs (no background whole build, so no build_waited_on), real.rs
  (ComputeBuild, driver_cache names) and shaders.rs (blob names). Dropped
  with them: slab_count, record_slicer, abi_signature_id names, the direct
  root-CBV constant blocks, list_x::predicated, the split.rs/runner.rs
  ExecuteIndirect test and the list_x chain-scratch test. Not in main: xcl-dev#2404
  ran the pieces before any whole form was built; main runs the whole form
  (built on the title's thread) until the indirect set is ready.
- xcl-dev#2707 (allocator reclaim): main has it (31930d8, 057f463, 8e7b566).
  alloc_pool.rs is main's, with xcl-dev#867's changes on top; bind.rs takes main's
  native_backing; xcl-dev#2707's tests and bind::push_uma_for_test go.
- xcl-dev#867 + xcl-dev#2477 (Wine vtables and fences), adapted to main's new code:
  real.rs keeps the in-place patching, UnadoptGuard and FenceProxy beside
  main's native_queue_* helpers; guards in cl_reset, bind_pipeline_exact,
  clear_pipeline_exact, reset_pc_allocator, the title ExecuteCommandLists
  closure and native_queue_execute; Signal/Wait unwrap the title's fence
  (also in native_queue_signal/wait); list_x guards in
  reset_reserved_segment and KickoffX's submit closures; create_raw_fence
  for main's new internal fences in alloc_pool.rs (SubmissionGate),
  title_textures.rs, present.rs, vram.rs, sparse.rs, cpu_writes.rs; tests
  as xcl-dev#2477 had them; runner.rs is main's plus submit_list.
- xcl-dev#1803 (heap addresses): kept, carried into main's PreparedSplit and
  PreparedAbiState (prepared_abi_io takes the heaps).
- xcl-dev#1368 (NodeMask 0): kept in compute_container, before main's per-node
  blob names, so names and pipeline use node 0.
- xcl-dev#1860, xcl-dev#2082 (cfg.rs, module/opt.rs): cfg.rs is 1567f72's version
  (xcl-dev#1860 on main's Succs); opt.rs is that plus xcl-dev#2082's arm and test.
- xcl-dev#2229 (rodata): kept through main's kernel.rs entry points;
  translate_entry_rodata loses wave32_only as main dropped per-GPU tables
  (3cde0cc); pso.rs and coverage.rs call it with main's options
  (no_remap, split for graphics); recomp Options keeps rodata and no_remap.
- xcl-dev#1975: kept in emit.rs and lower_valu.rs; its mesh barrier guard and its
  test dropped, main's wider guard (2ca9127) covers it; the now-unused
  lower::has_non_uniform_barrier goes.
- xcl-dev#2070 (64 MB stacks): pso_async::WORKER_STACK on main's worker, helper
  and preload threads; shaders.rs's piece threads on worker_thread.
- xcl-dev#2551 (whole forms prebuilt): split_whole_roots(false) is DirectChain,
  so the precompile builds every split program's whole form; main built it
  only for programs an earlier run used through ExecuteIndirect.
- xcl-dev#688 (dxc.rs imports), xcl-dev#2762 (host.rs log line), xcl-dev#3090 (list_x tests),
  arch/window-title-commit (present.rs with_commit on main's
  compiling_text), README.md: both sides.
- list_x.rs: main dropped title_textures::list_reset; main's side.
- sparse.rs, vram.rs: main's quarantine_tiles_for and per-device retire
  state, with create_raw_fence.
- xcl-dev#3090, xcl-dev#3092 tests: runner::device and Uma::block_len added from
  nvidia-dev (5 and 12 lines) so the lib tests compile.
- xcl-dev#751: its commit is already in main (b84e037, via xcl-dev#2844); it leaves the
  README table with xcl-dev#2404, xcl-dev#2633, xcl-dev#2707, xcl-dev#2872, xcl-dev#3085 and xcl-dev#3086.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Correct PageSize=2 rounding while preserving explicit alignment, checked sizes, and recorded allocation/free accounting. Update the test title's alignment and zeroing-tail probes to the same 2 MiB contract, keeping the tail read inside its allocation.

Three focused tests passed on the earlier preserved patch; restoring the old 4 MiB grain failed all three controls. The new squashed head has not been run individually. Full-suite and retail merge checks remain pending.

Assisted-by: Codex (GPT-6)
@Prime1997
Prime1997 force-pushed the codex/gdkx-two-mib-page-grain branch from d40a154 to f00e1c4 Compare November 28, 2026 07:35
@thehollowedone

Copy link
Copy Markdown
Contributor

Exact-head Windows/NVIDIA rerun of #3092 f00e1c4fec6207ed99489947b0180caefaf57c53, following my earlier report on the old head. The new head includes the test-title correction.

Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC. cargo build --offline --locked -j 4 --workspace passed. Then cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 finished 1,903 passed, 2 failed, 48 ignored across 40 targets, with 26 explicit GPU SKIPPED notices counted among the passes. All four e2e tests, including the three that failed with the old test-title binary, passed. The two failures were console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet, also reproduced on the old parent in my earlier report) and d32s8_targets_take_their_own_size_of_video_memory (passed 1/1 when rerun alone on this head). The full suite is therefore not green locally.

Regression run. I built release XCL separately from clean current main e429936c and the clean PR head, then ran scripts/smoke.ps1 -Seconds 60 -Title sample-title on the same title and RTX 3080 Ti with XCL_PREPARE=0 on both. This documented mode leaves ahead-of-time shader preparation out; the default-mode attempt timed out during startup before a smoke block existed. The two blocks below are the script's output, not hand-written:

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 3080 Ti
title: sample-title
seconds: 60
exit: 0x0
frames shown: 1163 (PresentX 1163)
presents per 2 s (last 3): 55 57 58
device removals: 0
crashes: 0
peak commit: 15107 MB
xcl-smoke v1
commit: f00e1c4fec6207ed99489947b0180caefaf57c53
gpu: NVIDIA GeForce RTX 3080 Ti
title: sample-title
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16802 MB

The PR run clears the stated frame and peak-commit thresholds (1,582 ≥ 80% of 1,163; 16,802 MB ≤ 125% of 15,107 MB). I would not attribute the frame difference to this change because cache warmth may differ. The author can paste these generated blocks under the PR description's Regression run section. No menu input was sent, so this pair covers startup/menu behavior, not world load or gameplay. AMD and Intel were not tested here.

AI use: Codex (GPT-6.2 Sol) ran the builds, suite and paired smoke, checked the counts, and wrote this report.

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