D3D12.X: reject PAGE_GUARD/overflow in cpu_writes and handle stale fence wakeups #1379

Open
github-bot wants to merge 1 commit from github-bot/gh-1379 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 15:24 UTC · original
b3IKK:d3d12x/cpu-writes-guard-and-event → main · +112 −25 · 1 files · 1 commits · open

Fixes two bugs in crates/xcl/src/hle/d3d12x/cpu_writes.rs:

  • writable() and write_now() omitted the PAGE_GUARD check and overflow-checked arithmetic that write_u64_now() already performed, so a PAGE_GUARD page reported writable and could fault the worker thread on store, and large va + len values overflowed usize.
  • The worker reused one auto-reset event across jobs with a single WaitForSingleObject call: if an earlier job timed out and its fence completed later while waiting on a subsequent job, the stale signal woke the worker prematurely and applied bottom-of-pipe writes before the GPU finished.

This shares one is_writable_committed() helper across writable(), write_now(), and write_u64_now(), and extracts wait_for_fence() which resets the event before arming and loops until GetCompletedValue() >= value or the wait deadline expires.

What is in it

  • crates/xcl/src/hle/d3d12x/cpu_writes.rs: unify PAGE_GUARD + checked bounds in is_writable_committed(); add wait_for_fence() deadline loop with ResetEvent; add unit tests writable_and_write_now_reject_guard_page_and_overflow (verified failing before the fix) and wait_for_fence_ignores_stale_wakeup_from_timed_out_fence.

Since the last push: rebased onto main 06c9f55. main already has u64_writable_now with the PAGE_GUARD and alignment checks, so only the dword path and writable() share the new is_writable_committed; the u64 path stays main's. The wait_for_fence change merged unchanged.

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): 1267 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib cpu_writes: 5 passed, 0 failed (writable_and_write_now_reject_guard_page_and_overflow failed before the fix)

Regression run

main (426a5a7, clean tree, no local changes):

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

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

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

(The main block is 426a5a7, an ancestor of the current main, from the same machine and data folder.)

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto main 06c9f55, resolved the conflicts, ran the suite and the scripts/smoke.ps1 pair at the head above.
**@⁠b3IKK** on GitHub · 2026-11-24 15:24 UTC · [original](https://github.com/xcl-dev/xcl/pull/1379) `b3IKK:d3d12x/cpu-writes-guard-and-event` → `main` · +112 −25 · 1 files · 1 commits · open Fixes two bugs in `crates/xcl/src/hle/d3d12x/cpu_writes.rs`: - `writable()` and `write_now()` omitted the `PAGE_GUARD` check and overflow-checked arithmetic that `write_u64_now()` already performed, so a `PAGE_GUARD` page reported writable and could fault the worker thread on store, and large `va + len` values overflowed `usize`. - The worker reused one auto-reset event across jobs with a single `WaitForSingleObject` call: if an earlier job timed out and its fence completed later while waiting on a subsequent job, the stale signal woke the worker prematurely and applied bottom-of-pipe writes before the GPU finished. This shares one `is_writable_committed()` helper across `writable()`, `write_now()`, and `write_u64_now()`, and extracts `wait_for_fence()` which resets the event before arming and loops until `GetCompletedValue() >= value` or the wait deadline expires. **What is in it** - `crates/xcl/src/hle/d3d12x/cpu_writes.rs`: unify `PAGE_GUARD` + checked bounds in `is_writable_committed()`; add `wait_for_fence()` deadline loop with `ResetEvent`; add unit tests `writable_and_write_now_reject_guard_page_and_overflow` (verified failing before the fix) and `wait_for_fence_ignores_stale_wakeup_from_timed_out_fence`. **Since the last push**: rebased onto `main` `06c9f55`. `main` already has `u64_writable_now` with the `PAGE_GUARD` and alignment checks, so only the dword path and `writable()` share the new `is_writable_committed`; the u64 path stays `main`'s. The `wait_for_fence` change merged unchanged. **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`): **1267 passed, 0 failed, 46 ignored** (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib cpu_writes`: 5 passed, 0 failed (`writable_and_write_now_reject_guard_page_and_overflow` failed before the fix) **Regression run** main (`426a5a7`, clean tree, no local changes): ``` xcl-smoke v1 commit: 426a5a745db4d5e4b037449ede0b70cb342f5192 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15158 MB ``` PR (`aaf89e0`, clean tree, no local changes): ``` xcl-smoke v1 commit: aaf89e0c80efb787311646ace7ff3a3022ce841b gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1644 (PresentX 1644) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16189 MB ``` (The main block is `426a5a7`, an ancestor of the current `main`, from the same machine and data folder.) **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: rebased onto `main` `06c9f55`, resolved the conflicts, ran the suite and the `scripts/smoke.ps1` pair at the head above.
Three bugs in cpu_writes.rs:
- writable() and write_now() omitted the PAGE_GUARD check and checked
  arithmetic that write_u64_now() already performed, so a PAGE_GUARD page
  reported writable and crashed the worker on store, and large va + len
  overflowed usize.
- The worker reused a single auto-reset event across jobs with a single
  WaitForSingleObject call: if an earlier job timed out and its fence
  completed later while waiting on the next job, the stale event signal
  woke the worker prematurely and applied bottom-of-pipe writes before
  the GPU finished.

Share a single is_writable_committed() helper across writable(),
write_now(), and write_u64_now(), and reset/loop in wait_for_fence()
until GetCompletedValue() >= value or the wait budget expires.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:52:30 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 15:32 UTC · original · edited 2026-11-24 15:35 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 7b3fc47 (on its base 930e8b4).

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, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: writable_and_write_now_reject_guard_page_and_overflow, wait_for_fence_ignores_stale_wakeup_from_timed_out_fence.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored, no skips.

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.
**@⁠futurepro62** on GitHub · 2026-11-24 15:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1379#issuecomment-7136201131) · edited 2026-11-24 15:35 UTC Full-suite run, since this PR has no test report yet. Tested exact head `7b3fc47` (on its base `930e8b4`). **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, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **753 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `writable_and_write_now_reject_guard_page_and_overflow`, `wait_for_fence_ignores_stale_wakeup_from_timed_out_fence`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **753 passed, 0 failed, 41 ignored**, no skips. **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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 16:49 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 16:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/1379#issuecomment-7138269170) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:03 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 05:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1379#issuecomment-7183139114) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1379/head:github-bot/gh-1379'
git switch 'github-bot/gh-1379'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1379'
git switch 'github-bot/gh-1379'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1379'
git switch 'github-bot/gh-1379'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1379'
git switch 'main'
git merge --squash 'github-bot/gh-1379'
git switch 'main'
git merge --ff-only 'github-bot/gh-1379'
git switch 'main'
git merge 'github-bot/gh-1379'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.