Skip to content

D3D12.X: a CPU cycle break also publishes its value into title memory - #2078

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
iggyvilla:xcl-cycle-break-publishes-value
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
iggyvilla:xcl-cycle-break-publishes-value

Conversation

@iggyvilla

Copy link
Copy Markdown
Collaborator

Part of #1164 (the remaining local change: publishing a CPU cycle-break's released value into title memory; the gate timeout and XCL_GPU_WAIT_RELEASE_MS are left out because they overlap #1046).

When signal_write64_pairs (SignalAction::CpuCycleBreak) or break_cycles_before_title_signal breaks a Write64BitValue* / Wait64BitValueX GPU cycle on the CPU, XCL signalled the per-VA PC fence and updated cpu_signaled_max, but did not write the released value into the title's memory. Any CPU poll or memory-checking wait on that counter never saw it move while the blocked queue had not yet executed its write.

This change publishes the released value with AtomicU64::fetch_max right before signalling the fence (skipping val == 0 as well as null or non-8-byte-aligned addresses):

  • Committed coherent UMA: takes the O(1) Uma::in_committed_window shortcut without calling VirtualQuery. publish_cpu_cycle_break's committed-UMA path now matches main (Memory: skip VirtualQuery on committed coherent UMA windows in cpu_writes and kernelx #1005), whose in_committed_window shortcut is also preserved inside the shared cpu_writes::u64_writable_now helper.
  • Plain title memory outside UMA: reuses the shared cpu_writes::max_u64_now helper (VirtualQuery + MEM_COMMIT + !PAGE_GUARD + RW/ERW + region-end check). This path only runs on cycle breaks (rare, warning-throttled), never on per-draw or per-submit hot paths, and has the same best-effort TOCTOU trade-off before the atomic write as cpu_writes::write_u64_now.
  • Sparse UMA windows: intentionally skipped (Uma::is_sparse). CPU writes into a sparse window dirty its write-watched page and cause sparse::before_execute to upload the surrounding 64-byte chunk to tiled VRAM, which can overwrite adjacent GPU-written data. Existing cpu_writes paths (Write::Immediate and Write::ReadbackU64) do not need a sparse check because they only ever receive addresses outside unified memory (real::uma_window_buffer is None), whereas SyncCell tracks Write64BitValue* across both UMA and non-UMA addresses.
  • Monotonicity: fetch_max never rewinds a counter that already advanced, and break_cycles_before_title_signal now skips non_monotonic cells too. Note that an earlier-queued non-UMA Write::Immediate completing later on xcl-cpu-writes still writes via plain 32-bit stores in cpu_writes::write_now; changing write_now is left out of this PR to avoid changing existing write-worker behaviour and overlapping D3D12.X: retain deferred Write64 until the producer fence completes #850 / D3D12.X: honour OS QPC timestamp flags and atomic 64-bit CPU writes (#103) #317.

What is in it

  • crates/xcl/src/hle/d3d12x/cpu_writes.rs: extract u64_writable_now from write_u64_now (keeping main's Memory: skip VirtualQuery on committed coherent UMA windows in cpu_writes and kernelx #1005 Uma::in_committed_window shortcut before VirtualQuery) and expose pub(super) unsafe fn max_u64_now. One behaviour change in the existing write_u64_now: it now also ignores a null or non-8-byte-aligned va (the check moved into the shared helper); before, it stored through such an address.
  • crates/xcl/src/hle/d3d12x/list_x.rs: add publish_cpu_cycle_break / publish_cpu_cycle_break_with, call it before fence.Signal(val) in SignalAction::CpuCycleBreak and break_cycles_before_title_signal (adding a non_monotonic guard to the mixed-cycle site), and add unit test publish_cpu_cycle_break_uses_fetch_max_and_skips_sparse_or_unwritable and GPU test cpu_cycle_break_publishes_value_to_title_memory_and_keeps_it_monotonic.

Tested

  • AMD Radeon RX 6650 XT (RDNA2, 8 GB VRAM, driver 32.0.21045.29003), AMD Ryzen 7 5700X, 32 GB RAM, Windows 11 (10.0.26300), rustc 1.100.0 (0ef1bc386 2026-11-09). Debug for tests; release (cargo build --release -p xcl) for smoke runs. Head commit 49a25463d62b14bc2dec833b6efc58b09382528e on main 3da2abb81606df622610e009f0430de99aa9881c.
  • Targeted tests (--test-threads=1):
    • cargo test -p xcl --lib cycle_break -- --test-threads=1: 2 passed, 0 failed, 0 ignored.
    • cargo test -p xcl --lib hle::d3d12x::cpu_writes -- --test-threads=1: 2 passed, 0 failed, 0 ignored.
    • Existing cycle/split tests (cross_queue_cycle_and_same_queue_fifo_do_not_deadlock, rotating_queue_self_deadlock_and_non_monotonic_rescue_do_not_hang, mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares): 3 passed, 0 failed, 0 ignored.
  • Full workspace suite (cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4): 1112 passed, 1 failed, 46 ignored, 8 SKIPPED lines (across 4 tests).
    • SKIPPED:
      • gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: 4 sub-cases (f16 arithmetic wave32/wave64: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's)); f16 packed wave32/wave64: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's)))
      • gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: 2 sub-cases (f32 conversions wave32/wave64: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's)))
      • shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)
      • heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
    • The 1 failure (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: seed 540: res[833] = 0x7, CPU 0x6) is pre-existing on main 3da2abb81606df622610e009f0430de99aa9881c in DXIL code untouched by this PR: running cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 -- --test-threads=1 on plain 3da2abb failed 3/3 deterministically with the exact same seed 540: res[833] = 0x7, CPU 0x6.

Regression run
Four 60 s smoke runs were executed back-to-back in main, head, head, main order from the same worktree and executable path (main 3da2abb vs head 49a2546, clean trees, scripts/smoke.ps1 -Game C:\games\retail):

  • run 1 (main): 1560 frames (PresentX 1560), peak commit 18752 MB (steady 20–60 s median 16115 MB)
  • run 2 (head): 1570 frames (PresentX 1570), peak commit 17178 MB (steady 20–60 s median 15854 MB)
  • run 3 (head): 1579 frames (PresentX 1579), peak commit 17294 MB (steady 20–60 s median 15774 MB)
  • run 4 (main): 1577 frames (PresentX 1578), peak commit 19043 MB (steady 20–60 s median 16021 MB)

Steady-state commit (~15.8–16.1 GB) and peak commit (~17.2–19.0 GB) match between main and this PR; none of the runs hit CpuCycleBreak. Pair 2 (runs 3 and 4) is pasted verbatim below:

main:

xcl-smoke v1
commit: 3da2abb81606df622610e009f0430de99aa9881c
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1577 (PresentX 1578)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19043 MB

This PR:

xcl-smoke v1
commit: 49a25463d62b14bc2dec833b6efc58b09382528e
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1579)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17294 MB

Related

Not tested

AI use

  • Antigravity with Gemini 4 Neon: wrote the implementation and tests, rebased onto 3da2abb, ran the targeted tests, full workspace test suite, main fuzz reproduction, and paired 60 s regression smoke runs, and wrote this PR description.
  • Claude Code with Claude Sonnet 5.5: reviewed the initial diff (caught cpu_writes helper reuse, the non_monotonic guard in break_cycles_before_title_signal, and a test that passed without the fix), and verified the outbox counts, smoke blocks, and diff against the saved files.

When a Write64BitValue* cycle is broken on the CPU (SignalAction::CpuCycleBreak
in signal_write64_pairs, or a mixed title-fence cycle in
break_cycles_before_title_signal), XCL signalled the per-VA PC fence and
updated cpu_signaled_max without writing the released value into the title's
memory. A title polling that counter on the CPU (or a Wait64 checking memory)
never saw it move while the blocked queue had not yet executed its write.

Publish the released value with AtomicU64::fetch_max right before signalling
the fence, skipping sparse UMA windows (where CPU writes dirty write-watched
pages and upload stale sibling bytes into VRAM) and non-monotonic cells.
Committed coherent UMA takes an O(1) path; non-UMA title memory reuses a
shared max_u64_now helper in cpu_writes.rs (off the hot path: cycle breaks
only).

Part of xcl-dev#1164

Assisted-by: Antigravity (Gemini 4 Neon)
@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 49a2546 (on its base 3da2abb).

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::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1101 passed, 0 failed, 44 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: publish_cpu_cycle_break_uses_fetch_max_and_skips_sparse_or_unwritable, cpu_cycle_break_publishes_value_to_title_memory_and_keeps_it_monotonic.
  • 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: 1112 passed, 0 failed, 46 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 cbc296a 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 const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_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.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with main (1373 here; 1371 and 1356 on the two main runs). No line about a CPU cycle break appears in the log, so I cannot tell whether this run reached it; this is a regression run only.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: f5c5bdf0e91035f8f1404f46f4f2f7aedc259e7f
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1371 (PresentX 1371)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 49a25463d62b14bc2dec833b6efc58b09382528e
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1373 (PresentX 1373)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The second main run: 1356 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head, a run that reaches a CPU cycle break, native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@thehollowedone

Copy link
Copy Markdown

Independent native Windows run on 49a2546, clean detached checkout. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, DXC 1.8.2502.11.

  • cargo build --workspace --offline --locked -j 4 passed.
  • cargo test --offline --locked -j 4 -p xcl --lib cycle_break -- --nocapture --test-threads=1 finished with 2 passed, 0 failed, zero skips. The tests checked monotonic publication to title memory and skipped sparse or unwritable destinations.
  • cargo test --workspace --offline --locked --no-fail-fast -j 4 -- --nocapture --test-threads=4 finished with 1113 passed, 0 failed, 46 ignored. Cargo's pass count includes 25 runtime skip notices (20 native wave64, 3 unsupported per-lane forms, 1 driver-cache control unavailable, 1 no heap windows).

This run used workspace fixtures. Retail world-load behavior remains unverified by this run. AI use: Codex (GPT-6, exact variant unspecified) ran the tests and drafted this report.

@throny throny removed the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@raylitebull
raylitebull merged commit 915839c into xcl-dev:main Nov 25, 2026
4 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
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.

7 participants