Skip to content

D3D12.X: hook Write32/64BitValueBottomOfPipe2X (#137/#138) and ResourceBarrierX (#140) - #3270

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/list-sync-bop2x-barrier-x
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/list-sync-bop2x-barrier-x

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What is in it

Three newer-layout console command-list methods were unhooked in real::console_slots(Kind::CommandList):

  • Slot #137: Write32BitValueBottomOfPipe2X
  • Slot #138: Write64BitValueBottomOfPipe2X
  • Slot #140: ResourceBarrierX

Titles calling these methods fell through to unhooked console-extension stubs, silently dropping bottom-of-pipe marker/timestamp writes, their associated synchronization, and extended resource barrier batches (and leaving the ResourceBarrierX supplemental-actions out-parameter uninitialized).

This change:

  • Adds list_x::write32_bottom_2x and list_x::write64_bottom_2x in crates/xcl/src/hle/d3d12x/list_x.rs matching the 5-argument ABI (va, value, sync_flags, control_flags, flags): emits flush_barrier(this) on DIRECT/COMPUTE lists when sync_flags != 0 || control_flags != 0, forwards BOTTOM_TIMESTAMPS (flags & 0x4 != 0) on 64-bit writes through write64_bottom_timestamp_x, records W32B2/W64B2 and note_write64_recorded, and writes MARKER_OUT otherwise.
  • Adds list_x::resource_barrier_ext_x in crates/xcl/src/hle/d3d12x/list_x.rs for ResourceBarrierX: zeroes any non-null supplemental-actions out-parameter (actions: *mut u64) via unaligned write and forwards (this, n, barriers) through resource_barrier_x even when PREVENT_PIPELINE_SYNC (0x10000) is set.
  • Hooks (137, l::write32_bottom_2x), (138, l::write64_bottom_2x), and (140, l::resource_barrier_ext_x) in crates/xcl/src/hle/d3d12x/real.rs::console_slots(Kind::CommandList).
  • Adds unit, console-vtable, and D3D12 GPU tests covering slot wiring, sync_flags/control_flags barrier gating, BOTTOM_TIMESTAMPS 64-bit GPU execution, and ResourceBarrierX Texture2D transitions with non-null actions.

Tested

Hardware and toolchain: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11 Pro (Build 26200), rustc 1.99.0 (b940084d7), DXC 1.9 (dxcompiler 1.9.2609.5, dxil 1.9.2609.5), debug + release builds.

  • cargo test -p xcl --lib -- bop2x_and_resource_barrier_ext_x cache_flushes_are_uav_barriers console_slots_hook_sync_bop2x --test-threads=1 --nocapture: 4 passed, 0 failed (includes gpu_bop2x_and_resource_barrier_ext_x_execute_cleanly executing on RTX 5070 Ti).
  • cargo test --workspace -- --test-threads=4: 2611 passed, 0 failed, 49 ignored (26 GPU tests reported SKIPPED: 21 no wave64, 3 #1426 f16 compiler refusals, 2 no heap windows).

Regression run

Baseline (origin/main ancestor f0e8fdd5, 150 s on RTX 5070 Ti):

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

This PR (61d9d4b9, 150 s on RTX 5070 Ti):

xcl-smoke v1
commit: 61d9d4b908e67425fb842cd6d7bb259de19e66f0
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 2170 (PresentX 2170)
presents per 2 s (last 3): 45 0 0
device removals: 0
crashes: 0
peak commit: 32085 MB

Not tested

  • Titles that depend on non-zero supplemental action bits returned via the ResourceBarrierX actions out-parameter (currently zeroed) or on deferred pipeline synchronization when PREVENT_PIPELINE_SYNC is set.
  • Older-layout (d3d12_x) command lists where slot indices differ from the newer console layout.
  • Multi-adapter or non-NVIDIA GPUs (AMD/Intel).

AI use

Antigravity (Gemini) assisted with auditing the command-list slot layout, drafting the handlers and unit/GPU tests, and formatting this PR description. All code was reviewed, built, and verified locally on RTX 5070 Ti with the full workspace test suite and 150 s smoke run.

…) and ResourceBarrierX (xcl-dev#140)

Slots xcl-dev#137 (Write32BitValueBottomOfPipe2X), xcl-dev#138 (Write64BitValueBottomOfPipe2X), and xcl-dev#140 (ResourceBarrierX) on newer-layout console command lists fell through to unhooked console-extension stubs, silently dropping bottom-of-pipe marker/timestamp writes and extended resource barrier batches.

- Add list_x::write32_bottom_2x and list_x::write64_bottom_2x with the 5-argument ABI (va, value, sync_flags, control_flags, flags), emitting a UAV barrier on DIRECT/COMPUTE lists when sync_flags or control_flags are non-zero, forwarding BOTTOM_TIMESTAMPS on 64-bit writes, and writing MARKER_OUT otherwise.
- Add list_x::resource_barrier_ext_x for ResourceBarrierX, zeroing any non-null supplemental-actions out-parameter and forwarding the barrier batch through resource_barrier_x even when PREVENT_PIPELINE_SYNC is requested.
- Wire slots xcl-dev#137, xcl-dev#138, and xcl-dev#140 in real.rs::console_slots(Kind::CommandList) and add unit, vtable, and D3D12 GPU tests.
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@andrewDoing

Copy link
Copy Markdown
Contributor

Ordinary marker values from guest vtable slots 137 and 138 reached CPU memory on RTX 5070 (616.92), head 61d9d4b9, in five fresh-process runs. I called both slots on an adopted native DIRECT list from a synthetic caller whose exact function range was registered with XCL as a guest image, so the slot guards selected the console handlers.

I used aligned CPU-backed destinations outside unified memory, slot 137 with sync_flags=1 and slot 138 with control_flags=1, both with final flags=0. The initial DWORD and QWORD stayed unchanged through list close. I submitted through XCL's queue ExecuteCommandLists hook. Its log identified two deferred CPU writes. All five runs eventually produced 89abcdef and 12345678fedcba98; the DWORD immediately after the first destination remained 55667788.

One boundary worth keeping explicit in a regression: a subsequent native D3D12 fence can finish before the CPU worker publishes these stores. On the first observation after that fence, four runs still had both original values and one already had both final values. All reached the final values within the bounded five-second observation. The QWORD was checked as two DWORDs, matching the worker's store widths. This does not establish atomic QWORD visibility or an ordering defect in guest waits; the test isolates ordinary CPU-backed markers, without timestamps or a dependent guest wait.

AI-assisted fixture and verification.

@andrewDoing

Copy link
Copy Markdown
Contributor

Follow-up on the guest ordering boundary in the marker-only control. On the same head 61d9d4b9 and RTX 5070 (616.92), both CPU-backed markers were visible when the dependent two-list submission returned, in five fresh processes. The check ran before signaling a native fence and without polling for either marker.

  • A synthetic registered guest caller used ordinary slots 137/138 on the first DIRECT list. On a second DIRECT list it used newer-layout slots 73/74 (Wait32BitValueX and Wait64BitValueX) with equality, a full DWORD mask, and the full QWORD value. The fixture selected the newer layout explicitly and used separate allocators.
  • Before submission, both destinations still held their initial values. A read-only check of the captured production plan found both waits unsatisfied, widths 4 and 8, and the second list dependent on the first list's deferred CPU writes.
  • I passed the two lists, in producer/consumer order, to the production queue submission hook in one call. Immediately on return, the destinations read 89abcdef and 12345678fedcba98; the neighboring guard remained 55667788. The subsequent native fence also completed.

This covers same-queue, same-batch dependent waits on ordinary markers to CPU-backed memory. It does not establish atomic QWORD publication or cross-queue ordering.

AI-assisted fixture and verification.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 61d9d4b, diff read, not a merge-check: CI is red, so not built or run here yet):

Fine: it reuses write, timestamp and flush_barrier (which already skips copy lists and bundles), and the GPU test uses skip_test.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: b2b1f10
head: 61d9d4b
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2905 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: re-check of the head I reviewed earlier (61d9d4b; my review comment has the details), now run because the PR's only red CI was the pipeline_library race fixed on main. Findings: (1) Nothing shows a title calls these slots or that they take these arguments. On main #137 / #138 / #140 are logged stubs that return 0 and do nothing. resource_barrier_ext_x (list_x.rs ~5014-5022) writes 8 bytes through its 5th argument, read from the caller's stack; if the method takes fewer arguments, that's a write to a random address where main did nothing. A log of a title calling them (arguments and return address) would settle the slots and signatures. (2) The three slots are added to console_slots (real.rs ~1677-1679) for every console layout, not split by layout as #139 is. (3) write64_bottom_2x (~4293) tests flags & BOTTOM_TIMESTAMPS (0x3), while the description says 0x4; if the 2X flags mean something else, a fence value becomes a timestamp and CPU waits on it time out. (4) AI use says "Antigravity (Gemini)", not an exact model. Fine: it reuses write, timestamp and flush_barrier (which skips copy lists and bundles), and the GPU test uses skip_test. The smoke below shows whether the retail title reaches these slots in 60 s.
performance: 60 s smoke of a retail title, main b2b1f10 vs this merge (466fef3e): 1671 -> 1680 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17394 -> 19088 MB, 0 device removals, 0 crashes. No line in this run's log shows the title calling the three slots, so the run checks only that adding them breaks nothing. Peak commit is 11 % above main in this one run, which is within today's run-to-run spread on this machine.
verdict: not yet: nothing shows a title calls slots #137 / #138 / #140 or takes these arguments, and resource_barrier_ext_x writes through a 5th stack argument where main's stub writes nothing (finding 1); the retail title in this run never reached them
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 61d9d4b9: 4 finding(s). 4 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

// the newer layout's (called before anything tells the layouts apart)
(131, l::flush_cache_range_x as usize),
(132, l::flush_cache_range_x as usize),
(137, l::write32_bottom_2x as usize),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#137/#138/#140 are hooked for every list regardless of layout, but they're only known to be these methods on the newer layout, where the console methods sit two slots later (NEWER_LIST_SLOTS). On the older layout #138 is probably ResourceBarrierX. It would now go to write64_bottom_2x, which reads (n, barriers_ptr, ...) as (va, value, ...), writes to address n and drops the barrier batch. Before this it hit a logged no-op stub. Installing these through guard::make_layout_split with QUEUE_SHIFTED (older = the existing stub) keeps the older layout as it was.

flush_barrier(this);
}
record_write_trace(this, va, value, flags, "W64B2");
if flags & BOTTOM_TIMESTAMPS != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests the 2X flags against BOTTOM_TIMESTAMPS (0x3, the older Write64BitValueBottomOfPipeX bits), but the PR description says the 2X timestamp bit is 0x4, so one of the two is wrong. If it's 0x4, timestamp requests write the literal value (usually 0), and calls with bits 0x1/0x2 set for something else become timestamps and lose their marker value. The GPU test passes BOTTOM_TIMESTAMPS itself, so it can't catch this.

_flags: u32,
actions: *mut u64,
) {
if !actions.is_null() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain about this one: the supplemental-actions out-param is written as a full u64. If the console type is a 32-bit flags value, this also zeroes the 4 bytes after it on the title's stack. Is the width confirmed?

) {
if !actions.is_null() {
actions.write_unaligned(0);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain about this one: this assumes ResourceBarrierX's array uses the 32-byte console D3D12_RESOURCE_BARRIER stride. If the X call takes a larger extended struct, every barrier after the first in an n>1 batch is decoded from the wrong offset. The tests only use n=1.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants