Skip to content

Tests: align XMemVirtualQuery buffers and verify CPU flags - #650

Open
yaandrei2000 wants to merge 1 commit into
xcl-dev:mainfrom
yaandrei2000:fix/xmem-virtual-query-test-alignment
Open

yaandrei2000 wants to merge 1 commit into
xcl-dev:mainfrom
yaandrei2000:fix/xmem-virtual-query-test-alignment

Conversation

@yaandrei2000

@yaandrei2000 yaandrei2000 commented Nov 24, 2026 •

Copy link
Copy Markdown

Fix intermittent failures in the XMemVirtualQuery tests. The old byte array could be misaligned for VirtualQueryEx on Windows x64. Zero-initialized flags could also mask a missing write for reserved or guarded pages. Related to #656.

What is in it

  • In crates/xcl/src/hle/kernelx.rs, share a C-layout QueryInfo between the two tests. Check the buffer layout, start each query with cpu_flags = u32::MAX, and verify MEM_RESERVE for the reserved case and MEM_COMMIT with PAGE_READWRITE | PAGE_GUARD for the guard case.

Tested

Tested commit 7fdea657c96e45e9630b6db9016d7b5f8b7746cb in a clean worktree based on f4ce27ceb6d1b0576d0c659b713b674778bf1968. Windows 11 build 26300.9974, Ryzen 5 5500, GTX 1660 Ti (driver 617.42), Rust 1.88.0 (x86_64-pc-windows-msvc), debug, DXC 1.9.2609.5.

$env:XCL_DXC_DIR = 'C:\Tools\DXC\bin\x64'
cargo test -p xcl --lib xmem_virtual_query -- --test-threads=1
cargo build --workspace
cargo test --workspace --no-fail-fast -- --test-threads=4
  • Both focused tests passed on the final commit with the original runtime. In a separate experiment on the same test diff, a temporary mutation wrote cpu_flags only for readable pages. Both tests from 53301d8 still passed. Both updated tests failed on the reserved and guard-page cases with cpu_flags & 3 == 3 (expected 0).
  • The workspace run on the final commit completed all 17 test binaries. Cargo reported 698 passed, 3 failed, and 41 ignored (exit 101).
  • The control run used the same build and --no-fail-fast commands on clean f4ce27c. It reported 697 passed, 4 failed, and 41 ignored. Both trees failed the cubemap VRAM reuse assertion in placed_title_textures_share_vram_and_preserve_pixels. The resulting poisoned locks also failed transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory. Clean main also failed xmem_virtual_query_marks_cpu_readable_memory (returned 0, expected 1). Cubemap check #447 and Poisoned test locks #673
  • Cargo counts two Wave64 SKIPPED results as passes in each workspace run: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware.

Earlier independent checks of 53301d8

  • RTX 4060, driver 621.01, i5-12600KF, Windows 11 build 26200, Rust 1.90.0, debug. cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on the exact commit reported 688 passed, 0 failed, 41 ignored, and two Wave64 skips included in the pass count. Both focused tests passed. NVIDIA report
  • Radeon RX 9060 XT (RDNA4), driver 32.0.32029.2010, Ryzen 7 5700X, Windows 11 build 26200, Rust 1.100.0, debug. A local merge of 53301d8 onto 91f9a5e reported 692 passed, 0 failed, 41 ignored, and 0 skips. Both focused tests passed. The commands were cargo build --workspace and cargo test --workspace -- --test-threads=4. AMD report

Regression run

Please apply the test-only label after reviewing this revision.

Not tested

Retail titles, cases requiring external XCL_SAMPLE_* data, release builds, and the updated tests on AMD GPUs.

AI use

ChatGPT (GPT-6.2) helped diagnose and write the original fix. OpenAI Codex (GPT-6 family, exact variant unavailable) strengthened the tests, ran and checked the mutation and workspace tests, and drafted this description.

@xelerb-debug

Copy link
Copy Markdown

Test report for 53301d8 (this PR's head)

Tested

  • NVIDIA GeForce RTX 4060 (driver 621.01), Intel Core i5-12600KF, Windows 11 Pro build 26200, Rust 1.90.0 (stable-x86_64-pc-windows-msvc), debug
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on the head: 688 passed, 0 failed, 41 ignored (lib: 648 passed, 0 failed, 21 ignored; integration tests and doc-tests: 40 passed, 0 failed, 20 ignored)
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • On the base commit (cedf8ce), cargo test -p xcl --lib xmem_virtual_query fails xmem_virtual_query_marks_cpu_readable_memory 3 times out of 3. It also failed on 508a0c7. With this PR, both xmem_virtual_query tests pass.
  • Root cause, measured: VirtualQueryEx returns 0 with ERROR_NOACCESS (998) when the output buffer sits at an offset of 1 or 4 from a 16-byte-aligned buffer, and succeeds at offsets 0 and 8. The old [u8; 64] buffer has 1-byte alignment, so whether the test passed depended on the stack layout. On Rust 1.90 it failed every run, and adding any local variable made it pass. QueryInfo takes the 8-byte alignment of MEMORY_BASIC_INFORMATION, which fixes this.
  • The PR merges into the current main (dd2ae9a) without conflicts (git merge-tree); the merged tree was not tested.

Not tested

  • AMD / RDNA GPUs, wave64 paths, release build, the merged tree with current main

AI use

  • Claude Code, Claude Opus 5.5: ran the tests above and wrote this report; I checked it before posting.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 53301d8c86b0d799a1fa18792a2df87acecb6751 on AMD RDNA4. I merged it onto current main 91f9a5e locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 692 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 652 passed, 0 failed, 21 ignored
  • 0 SKIPPED; xmem_virtual_query_marks_cpu_readable_memory and xmem_virtual_query_excludes_guard_pages pass.

Review: Duplicate of #656 (open), which fixes the same misaligned buffer with an align(8) wrapper and also clears the buffer between the two queries; this one uses a #[repr(C)] struct with offset_of checks (cpu_flags at 48, size 64), which documents the layout. Only one should land. The fix itself is right: MEMORY_BASIC_INFORMATION needs 8-byte alignment.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

Use aligned storage for VirtualQueryEx and seed the output flags so the
tests catch a missing write for reserved and guarded pages. Check the
state and protection returned for the guard page.

When a temporary mutation wrote flags only for readable pages, both
tests in 53301d8 passed and both updated tests failed.

Assisted-by: OpenAI Codex (GPT-6 family, exact variant unavailable)
@yaandrei2000
yaandrei2000 force-pushed the fix/xmem-virtual-query-test-alignment branch from 53301d8 to 7fdea65 Compare November 24, 2026 04:06
@yaandrei2000 yaandrei2000 changed the title Tests: fix XMemVirtualQuery buffer alignment Tests: align XMemVirtualQuery buffers and verify CPU flags Nov 24, 2026
@ItsMrDubey

Copy link
Copy Markdown

Test report for 7fdea657c96e45e9630b6db9016d7b5f8b7746cb (this PR's head)

Tested

  • NVIDIA GeForce RTX 4070 Ti 12 GB (Ada), driver 617.14; Intel Core i9-10900K, 32 GB RAM; Windows 11 Pro build 26300
  • Rust 1.88.0 (stable-x86_64-pc-windows-msvc), debug; DXC 1.9.2602.17 from Windows SDK 10.0.26100
cargo build --workspace
cargo test --workspace --no-fail-fast -- --test-threads=4

17 test binaries: 698 passed, 3 failed, 41 ignored. Same machine, main 64b3f3559: 700 passed, 1 failed, 41 ignored.

This PR's tests:

  • hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory: ok
  • hle::kernelx::tests::xmem_virtual_query_excludes_guard_pages: ok

On this machine the failure is not intermittent: xmem_virtual_query_marks_cpu_readable_memory fails on main 64b3f3559 on every run (5 of 5 single-test reruns, XMemVirtualQuery returns 0), and passes with this PR.

Failures:

SKIPPED (no wave64 on this GPU): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

AI use: Claude Code (Claude Opus 5.5) ran the builds and tests and wrote this report from their output.

@madaraXor

Copy link
Copy Markdown
Contributor

Tested on Windows 10 with Rust 1.90, where main fails this test every time

  • main 6efdabc, then the same tree with this PR's diff applied (gh pr diff 650, head 7fdea65). AMD Radeon RX 6700 XT, Ryzen 5 5600X, Windows 10 Pro 22H2 (19045.6466), Rust 1.90.0 stable-x86_64-pc-windows-msvc, debug.
  • xcl-<hash>.exe kernelx::tests::xmem_virtual_query --test-threads=1, 5 runs each:
    • main: xmem_virtual_query_marks_cpu_readable_memory fails 5 of 5 (panic at kernelx.rs:2070); xmem_virtual_query_excludes_guard_pages passes.
    • with this PR: both pass 5 of 5.
  • The cause on this machine, from a temporary probe on 09940bb (reverted): the [0u8; 64] buffer sat at an address 4 mod 8 and VirtualQueryEx failed with ERROR_NOACCESS (998), so XMemVirtualQuery returned 0.

Not tested: the whole suite with this PR applied; #656 (same failure, smaller change).

AI use: Claude Code, Claude Opus 5.5 ran the tests and wrote this comment.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 7fdea657 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 7fdea657c96e45e9630b6db9016d7b5f8b7746cb
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14809 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

On current main 568e7db, this test fails every time on my machine. It passes with this PR merged on top.

Tested

  • RTX 3060 12 GB, Windows 11 Home 26200, Rust 1.90.0 MSVC, debug.
  • cargo test --workspace -- --test-threads=4 on main 568e7db: 1097 passed, 1 failed, 26 ignored. The failure is hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, at kernelx.rs:2285 (CPU flag left: 0, right: 1). SKIPPED tests: the wave64 ones (this adapter has no wave64) and ir_text_assembles_signs_and_runs (no dxil.dll).
  • cargo test -p xcl --lib xmem_virtual_query_marks on main: failed 5 of 5 runs.
  • This PR's head 7fdea65 merged onto 568e7db (clean merge), cargo test -p xcl --lib xmem_virtual_query: 2 passed, 0 failed in each of 5 runs.

Not tested

  • The rest of the suite on the merged tree, and the retail title (this is a test-only change).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@throny throny added the off-goal Does not bear on the current goal (world loading); waits until it is reached label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants