Skip to content

D3D12.X: copy out-of-window two-pass indirect arguments into the window - #3079

Open
RodrigoTorreao wants to merge 287 commits into
xcl-dev:amd-devfrom
RodrigoTorreao:pr/stage-indirect-args
Open

RodrigoTorreao wants to merge 287 commits into
xcl-dev:amd-devfrom
RodrigoTorreao:pr/stage-indirect-args

Conversation

@RodrigoTorreao

@RodrigoTorreao RodrigoTorreao commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What is in it
A two-pass ExecuteIndirect (DispatchMesh) whose arguments or count are in a PC buffer outside the memory windows was skipped (its arguments are not in a console buffer in unified memory). The scale prelude reads arguments only through the windows. With a smaller coherent window (XCL_COHERENT_CAP_MB, and the RAM-based cap from #3068 on main), that is about 3 % of a retail world's draws. Reported in #2996 (lane 5).

  • The arguments and the count are resolved before anything is recorded (arg_source). A tracked console buffer whose range does not fit is refused, as before. Only an untracked PC buffer outside a bundle is copied.
  • stage_args_in_window checks each PC buffer's dimension and width first (pc_range_fits). It then takes space in the recording's own unified memory (ListState::arena, which is retired with the recording at its allocator's reset), and only after that records the copies. It records nothing unless every range fits and all space is taken.
  • The copy is CopyBufferRegion, with the source moved INDIRECT_ARGUMENT → COPY_SOURCE → back, and the window buffer moved back to COMMON after its implicit promotion. A draw with staged arguments does not hoist its prelude.
  • New tests: stage_args_tests (tracked out-of-range and overflow cases are refused, untracked buffers in a bundle are refused, a PC copy must fit its buffer).

Tested
RX 6750 XT 12 GB, 16 GB RAM, Windows 11 26200, driver 32.0.21045.29003. The retail title ran on Series S (lockhart) with a warm cache, XCL_PREPARE=0, XCL_COHERENT_CAP_MB=2048, XCL_TEXTURE_LEVEL_PAGES=1 and A pressed automatically.

amd-dev 7c795f5 this PR (e2d7249)
draws (skipped) 692,289 (19,587, 2.8 %) 682,998 (64, 0.01 %)
out-of-window two-pass skips logged 8 lines (power-of-two counter) 0
arguments staged - 16,384+ copies, none refused
GPU shared memory, peak / average 4.45 / 2.89 GB 4.37 / 2.86 GB
available RAM, min / average 0.11 / 1.34 GB 0.11 / 2.37 GB
end 217.8 s, 0x887a0007 207.5 s, 0x887a0007

Both runs end at #2619, which on this machine ends every Series S run between 215 and 318 s. An earlier run with the RT programs precompiled and XCL_RT_GATE=miss gave the same picture: skipped draws fell from 23,804 to 180, and the run still ended at #2619 (VA 0x0, 241 s).

Regression run
Same title, XCL_PREPARE=0, separate empty caches, run one after the other. Each side ran with its own scripts/smoke.ps1.

main b937fba:

xcl-smoke v1
commit: b937fbab2964b2c142f5d13662b91b00f99b9848
gpu: AMD Radeon RX 6750 XT
title: 2a4aef2e
seconds: 60
exit: 0x0
frames shown: 871 (PresentX 871)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17681 MB

This PR:

xcl-smoke v1
commit: e2d7249707cb9732e00fca85131d34491c9d9384
gpu: AMD Radeon RX 6750 XT
title: 2a4aef2e
seconds: 60
exit: 0x0
frames shown: 1246 (PresentX 1246)
presents per 2 s (last 3): 64 60 60
device removals: 0
crashes: 0
peak commit: 17330 MB

Full suite (cargo test --workspace --no-fail-fast -- --test-threads=4):

  • amd-dev: 1801 passed, 19 failed, 48 ignored.
  • PR: 1805 passed, 18 failed, 48 ignored. That is amd-dev plus the 3 new tests, plus one flaky amd-dev failure that passed here.

All 18 PR failures also fail on amd-dev.

Not tested

  • NVIDIA and Intel GPUs.
  • Lists recorded on several threads at once against a small window that fills: then the copy is refused and the draw is skipped, as before.
  • The debug layer. The source buffer's tracked state is taken to be INDIRECT_ARGUMENT, as the existing ExecuteIndirect path assumes.

AI use
Code, measurements and text were made with Claude Code (Claude Opus 5.5). I reviewed the change and ran every test on the hardware above.

🤖 Generated with Claude Code

notdxbi and others added 30 commits November 25, 2026 16:29
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.

Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own
table and writes a slot's pages after EnqueueRequest. At enqueue such a
slot can still name the pages of the slot's previous request, and the
snapshot taken then is what execute() wrote to (xcl-dev#289 rereads only the
entries that are 0). Over 16 000 requests a run were written into pages
the title had since reused: its objects got garbage pointers and it
crashed about 20 s into world loading; when the old pages were freed,
the request failed with E_ACCESS_VIOLATION.

The console reads the list when it runs the request. execute() now
reads it again (through read_own, as the snapshot) and takes it when it
differs and every page in it is allocated (kernelx::physical_pages_live).
A list that was on the enqueuing thread's stack keeps the snapshot: that
memory is reused once the call returns, and a page ID written there
since can belong to another live allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of xcl-dev#1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… done

When the GPU-wait watchdog releases a wait (xcl-dev#505), its lines say which
queues wait on which, but not what the GPU is running. With
XCL_GPU_CULPRIT=1 every dispatch XCL records (title lists,
console-recorded lists, ExecuteIndirect of a translated compute
pipeline) is wrapped in WriteBufferImmediate markers, in before and out
after, one pair of words per PC list in a readback buffer. At a release
the lists whose marker in is above their marker out are logged with the
dispatches between the two: console CS (fnv64 of the title's bytecode),
PC pipeline and groups.

On the retail title of xcl-dev#505 (RTX 5080) this named, at each stall, one
list with a run of 1-D dispatches of one CS whose first never finished;
not the same CS from run to run. DRED breadcrumbs were tried first: they
change the driver's pipeline cache keys, so every pipeline was built
again and the title never got past its start.

Off by default; without the variable nothing is recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in 36 upstream PRs from origin/main (xcl-dev#2310..xcl-dev#587) onto amd-dev (c7a18d8) while preserving all local AMD RDNA4 work (xcl-dev#615 pipelined presenter SRVs, xcl-dev#495/xcl-dev#1405 XCL_PAGE_ALIAS=1 hooks, xcl-dev#2306 level tiling timers, xcl-dev#1989 vtable fix, mesh user SGPRs).

Resolved 4 conflicts:
- console_list.rs: kept both mesh_arguments_go_in_user_sgprs_from_s16 and xcl-dev#2323 dispatch-heap tests
- real.rs: kept both effective_st depth-UAV tracking and xcl-dev#2280 pc_clear_for_desc
- vram.rs: kept Step::Tiling timer around level_tiling
- kernelx.rs: kept XCL_PAGE_ALIAS=1 hooks in physical_pages_live and XMemMapPhysicalPagesScatter

Assisted-by: Antigravity (Gemini 4 Neon High)
Both internal indirect-argument rewrite passes in bind.rs (guard_dispatch_args and make_scaled_args_buffer) emitted the exact DRED breadcrumb pattern (barrier, barrier, marker, Dispatch, barrier, marker) with an unlabeled pipeline and had root-binding and alignment hazards on AMD RDNA4:

1. Neither guard_indirect_pipeline nor scale_indirect_pipeline called dred::label_text (or SetName), so DRED printed the fallback stand-in label.
2. Both reused abi_root_signature (6 root UAVs + directly-indexed heap flags) while leaving slots unbound; SCALE_ARGS_HLSL statically references cnt (u4) via a ternary even when no count buffer is bound.
3. src_va and count_va were passed directly to SetComputeRootUnorderedAccessView even when args_off or count_off was not 16-byte aligned (e.g. 12-byte Dispatch argument strides or 4-byte count offsets).

Fix all three: label both pipelines for DRED, give args_pipeline a minimal root signature with every parameter unconditionally bound (binding u4 to consts_va when count is None and guarding cnt.Load with an if), align root UAV bases down to 256 bytes and pass the byte offset via io, guard GUARD_ARGS_HLSL divisions, and validate bundle/stride/offset bounds.

Assisted-by: Antigravity (Gemini 4 Neon High)
Console D16_UNORM_S8_UINT (118..=120) depth+UAV twins used R16_UNORM SRVs and a float fullscreen pass. Because 2^24-1 is not a multiple of 65535, hardware R16_UNORM conversion can differ by 1 ULP from float(k) * asfloat(0x37800080) computed by tiled-lighting DepthFunc = EQUAL vertex shaders, rejecting lighting draws on AMD RDNA4.

Read the R16_TYPELESS twin as R16_UINT in a dedicated fullscreen PSO returning float(val) * asfloat(0x37800080) for console formats 118..=120, and update the twin-plan unit test.

Assisted-by: Antigravity (Gemini 4 Neon High)
…olves

Command list xcl-dev#146 (uav_barrier_x) synced depth+UAV enhanced barriers and PlacedUav format-alias pairs, but never checked D3D12_BARRIER_TYPE_TEXTURE transitions on TitlePlaced format-alias writers (such as R9G9B9E5 lighting targets), leaving aliased SRVs stale under enhanced barriers.

Add format_alias::filter_enhanced_barriers and call sync_title_writers in uav_barrier_x. Also translate console target formats in resolve_subresource_x and resolve_subresource_region_x via device_x::pc_target_format.

Assisted-by: Antigravity (Gemini 4 Neon High)
buffer_view (used by CreateShaderResourceView and CreateUnorderedAccessView on buffer resources) returned empty V# descriptors for placed GPU-view buffers, and dev_create_cbv_x / buffer_words_at only fell back to read-only sparse::gpu_view mirrors (requiring XCL_GPU_VIEW_BUFFERS=1 and skipping UAVs).

Add real::resolve_uma_va(va, len) consulting kernelx::mirrors::mapped_source and mirrors::source with per-64-KiB-page contiguity verification inside UMA, wire it ahead of sparse::gpu_view::base_for in buffer_view, dev_create_cbv_x, and buffer_words_at, and add read-only sparse fallback to buffer_view.

Assisted-by: Antigravity (Gemini 4 Neon High)
Keep amd-dev 0 commits behind origin/main (xcl-dev#573, xcl-dev#2083, xcl-dev#2345, xcl-dev#2342).
Resolved 1 conflict in bind.rs: kept pso_for_draw(raw_pso) and bounds-checked commands_at/count_at while taking xcl-dev#2342 failed shared compute stand-in check.

Assisted-by: Antigravity (Gemini 4 Neon High)
map_pages and move_away previously called sparse::committed(at, PHYS_PAGE)
inside the per-page loop. When a large physical-page allocation (~2+ GB) lands
in a sparse UMA window (such as Series S / lockhart TileHeap), this issued
~34,000 separate 64 KiB UpdateTileMappings + queue.Signal calls (>31 s at
~64 MB/s), tripping the title's 30 s init watchdog.

Coalesce contiguous 64 KiB sparse-window commits in SparseCommitBatch across
map_pages, move_away_batched, MapTitlePhysicalPages, and
XMemMapPhysicalPagesScatter, flushing early on any overlapping decommit/unmap.
Reduces ~34,000 UpdateTileMappings calls to one batched commit per contiguous
run (~34 pool-heap calls, <100 ms).

Assisted-by: Antigravity (Gemini 4 Neon High)
Titles can enqueue DirectStorage requests with heap-backed
DestinationPageArray pointers, populate/map the physical page lists, and then
call Submit(). Auto-submitting the queue at half capacity let worker threads
run mid-batch against unpopulated page entries, dropping streamed geometry.

When the pending queue contains any non-stack DestinationPageArray request,
suppress the half-capacity auto-submit and wait for explicit Submit() (or full
queue capacity), while keeping normal half-capacity auto-submit for memory,
file, and stack-backed page-list requests.

Assisted-by: Antigravity (Gemini 4 Neon High)
VOP3 v_interp_p1ll_f16, v_interp_p1lv_f16, and v_interp_p2_f16 encode
(high << 8) | (chan << 6) | attr in SRC0 (OPR_ATTR). For attr63.w (attr=63,
chan=3, high=0), SRC0 == 0xFF == 255, which rdna2::decode's VALU fallback
literal scan mistook for a 32-bit inline literal and consumed the following
instruction word.

Skip fields explicitly typed as non-source operands (!is_src_type) during the
VALU fallback literal scan while keeping v_nop's empty-operand hidden shader
hash literals intact.

Assisted-by: Antigravity (Gemini 4 Neon High)
…shaders

On AMD RDNA4, GroupMemoryBarrierWithGroupSync (barrier::GROUP_SYNC) flushes
only LDS/TGSM, not L0/L1 global device memory. Shaders that perform global or
image UAV stores, atomics, or GLC=1 coherent loads and synchronize with
s_barrier can otherwise observe stale cache lines across waves/workgroups,
causing infinite spin-wait loops (0x887A0006 TDR) or corrupted buffers.

Pre-scan shaders via has_uav_write_or_glc and upgrade s_barrier to
barrier::ALL_SYNC (Direct DXIL) and AllMemoryBarrierWithGroupSync /
AllMemoryBarrier (HLSL) when the program writes/atomics global or image UAVs
or uses GLC=1, leaving pure-LDS/ALU shaders on GROUP_SYNC.

Assisted-by: Antigravity (Gemini 4 Neon High)
@RodrigoTorreao

Copy link
Copy Markdown
Contributor Author

Help wanted: test reports from any AMD or NVIDIA card with a smaller coherent window.

  1. Build amd-dev and this branch. Run the same title on each for the same time, with XCL_COHERENT_CAP_MB=2048 (or 1024), a warm cache and XCL_PREPARE=0.
  2. On amd-dev, the log shows two-pass ExecuteIndirect skipped: its arguments are not in a console buffer in unified memory. On this branch that line should be gone, and indirect arguments outside the memory windows copied into the coherent window should appear instead.
  3. Post draws and skipped draws (from console code so far), any device removal, and how each run ended.

AI-assisted (Claude Code with Claude Opus 5.5).

@akimfomin

Copy link
Copy Markdown
Contributor

PortBridge reproduced the two-recorder allocation case at f64494d. In the standalone Rust check, the normal control returns offsets [0, 256]. At the 4 MiB boundary, if both workers fetch the cursor before either resets it, both get offset [0, 0]. This checks the allocation sequence on CPU. GPU behavior on the XCL branch is still open.

PortBridge also surfaced Xbox2Windows #2332. Their synthetic WARP fixture distinguishes writer ordering (8/8 pixels with the queue wait versus 4/8 without) from consumer retirement (no slot reuse until completion). Your staging allocator differs, but these two controls map directly to its two remaining questions. Same-offset allocation at wrap and reuse of an in-flight slice need separate checks.

Would you prefer to enforce a single-recorder/queue scope here, or have PortBridge help check a queue-owned retirement variant? The synthetic Lab request has the exact pin and asks for generated inputs only.

@thehollowedone

Copy link
Copy Markdown
Contributor

On head f64494d, the fallback can also turn a known-invalid indirect range into a GPU copy. This is separate from the shared ring's wrap/reuse finding.

console_buffer(args) can find a tracked title buffer while args_off + max * stride exceeds its logical length. The Some((p, remaining)) fails the commands <= remaining guard, then the new wildcard arm calls stage_args_in_window anyway. The count path similarly folds an invalid tracked count_off + 4 into None. stage_args_in_window does not check the PC resource's dimension or offset + len <= Width before recording CopyBufferRegion. A tracked 16-byte title slice backed by a larger PC buffer, with args_off=4, max=1, and stride=16, is enough to distinguish the logical-range problem. A count at offset 16 has the analogous four-byte case.

Please distinguish unbacked/outside the window from tracked but out of range, reject the latter before recording any copy or barrier, and validate the effective PC offset and buffer width for the former. Resolve both args and count, plus bundle eligibility, before emitting either copy. A regression should cover those invalid ranges, an exact-end valid range, a non-buffer resource, and the error path where the args are valid but the count is invalid.

For the ring issue, a single atomic wrap fix would still allow a slot to be reused before another list or queue finishes reading it. One lifetime-safe direction is to stage into the existing recording-owned argument scratch, using disjoint spans for outputs and staged inputs, then feed the inline scaling pass; retain the source's actual D3D12 state and restore it after the copy. This is a design suggestion, not a tested patch.

On Windows 11 build 26300 with an RTX 3080 Ti (driver 621.35), I ran cargo test --offline --locked -j 4 -p xcl --lib gpu_two_pass_indirect_commands_keep_their_own_records -- --nocapture --test-threads=1 on the exact head: 1 passed, 0 failed, 0 ignored, no skips. That existing test covers two-pass command ordering, not this staging fallback. AI use: Codex (GPT-6.2 Sol) ran that test and checked the control flow; Codex (GPT-6.2 Astra) reviewed the memory and D3D12 lifetime requirements.

@SlopTart

Copy link
Copy Markdown

Two-lane data at head f64494d1, Linux/Wine, AMD vs NVIDIA:

Hardware

  • rig1: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT (Navi 31), Mesa 26.2.5 RADV, wine 11.0 (proton build)

  • rig2: i5-10600K, 16 GB DDR4, GTX 1070, nvidia 550.163.01, wine 10.0 under xvfb

  • two_pass_identity: rig1 5/5 green, rig2 5/5 green

  • gpu::recomp heap_window set: rig1 10/10 green; rig2 6 passed / 4 FAILED:

    • heap_window_tests::gpu_heap_windows_64bit_atomics_match_switch_form
    • heap_window_tests::gpu_heap_windows_divergent_lanes_match_switch_form
    • recomp::tests::gpu_heap_windows_reject_out_of_uma_aliasing
    • recomp::tests::gpu_heap_windows_reject_out_of_uma_aliasing_all_slots
  • gpu_two_pass_indirect_commands_keep_their_own_records (bind): rig1 green, rig2 FAILED

  • indirect_guard matched 0 tests at this head (module names moved in the stacked refactor), no number for it, not a pass

Context: on rig2, bind::gpu_two_pass_indirect... is green in the main suite at 753e8b1a but red at this head, and it was also red for rig2 on linux/stack-nvidia-dev 901384f7 (logged on #3067); rig1 is green on it everywhere. The gpu::recomp heap_window set lives behind the gpu:: filter our suites normally skip, so there is no main-suite baseline for those four - the reds above are their first counts on rig2.

Tested: the four test groups above at f64494d1 on both lanes.
Not tested: full suite on this head (big stacked diff), native Windows, real titles.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@Prime1997

Copy link
Copy Markdown
Collaborator

I’m preparing a narrow nvidia-dev follow-up and will link its draft here, preserving attribution to this existing indirect-argument work. The first supported standalone path is UPLOAD-heap arguments/counts: their invariant GENERIC_READ permits copies without guessing source transitions. It will validate both sources before recording, use recording-owned scratch, and require established resource retirement.

DEFAULT-heap/GPU-produced arguments remain unsupported until their exact state and lifetime are proved; this is not yet a fix for the whole missing-world symptom. The first checks cover mixed sources, count/bounds failures, output values and lifetime. No new test results are claimed here. Implementation and review use Codex (GPT-6).

Optional temporary Discord for coordinating contributor work, helping test and comparing results: https://discord.gg/gK3y7WRRY

@andrewDoing

Copy link
Copy Markdown
Contributor

I ran the five tests reported failing on the GTX 1070 / Wine lane above against head f64494d167f527a48a008fe3fbd7287b497398b0 on a native Windows RTX 5070 host (NVIDIA 616.92, DXC 1.8.2502.11). Each was run individually in a fresh process from the retained head-specific libtest binary, which also contains an unrelated test-only overlay.

All five passed with zero skips: gpu_two_pass_indirect_commands_keep_their_own_records, the 64-bit atomics and divergent-lanes heap-window tests, and both out-of-UMA alias rejection tests. The stock indirect test requests the default D3D12 adapter and does not log its LUID, so I cannot independently assert its adapter identity from that test's output.

This is a native-host control for the reported lane, not a diagnosis of the Wine failure. GPU generation, driver, and operating system all differ; no retail title or full suite was tested.

AI use: OpenAI Codex with GPT-6.2 Astra ran the checks; Codex reviewed and prepared this report.

@CharlyRien

Copy link
Copy Markdown
Contributor

Test report for f64494d and its base amd-dev 7c795f5, on NVIDIA with a 2 GB coherent window, following your steps. Short version: neither run reached the case this PR fixes, so this says nothing yet about the fix itself.

Tested

  • RTX 3090 24 GB with Resizable BAR off, driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631, Rust 1.100.0, release for the runs, debug for the suite.
  • The retail title, 200 s each through scripts/smoke.ps1 (main's copy for both), XCL_COHERENT_CAP_MB=2048, XCL_PREPARE=0, the same scripted A presses. The cache was cold on both sides (a fresh copy of a cache made under another translator identity; nothing was prepared for these two builds).
  • Window as the log reports it, on both: "3 sparse VRAM window(s) (12 GiB VA) + 1 coherent window(s) (2048 MB)"; the last "console code so far" line shows coherent 1851/2048 MB used on both.
amd-dev 7c795f5 this PR f64494d
draws with translated pipelines (skipped), last "console code so far" line 9,098 (0) at 160 s 9,282 (0) at 168 s
"its arguments are not in a console buffer in unified memory" lines 0 0
"indirect arguments outside the memory windows copied into the coherent window" lines 0 0
device removals, crashes 0, 0 0, 0
frames shown, peak commit 1,322, 21,204 MB 1,277, 17,826 MB

In these 200 s the title is still loading: the first two-pass DispatchMesh line of the PR's log comes at 198 s. So no out-of-window indirect argument was met on either side, nothing was staged, the ring did not wrap, and the question of two recorders sharing it (akimfomin's comment) did not come up here.

amd-dev:

xcl-smoke v1
commit: 7c795f5eefa0661eaf3f9f696d0cba3a75ce9628
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1322 (PresentX 1323)
presents per 2 s (last 3): 9 8 7
device removals: 0
crashes: 0
peak commit: 21204 MB

this PR:

xcl-smoke v1
commit: f64494d167f527a48a008fe3fbd7287b497398b0
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1277 (PresentX 1277)
presents per 2 s (last 3): 4 6 4
device removals: 0
crashes: 0
peak commit: 17826 MB
  • cargo test --workspace --no-fail-fast -- --test-threads=4, twice on the head and once on the base:
    • amd-dev 7c795f5: 1,803 passed, 17 failed, 48 ignored.
    • f64494d, second run: 1,803 passed, 17 failed, 48 ignored, the same 17 names as the base.
    • f64494d, first run: the xcl lib test binary aborted part-way (exit 0xc0000409). After hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit failed, a pipeline worker thread (xcl-pso-2) panicked with "misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1" in windows-core 0.62.2 src/interface.rs:41, a panic that cannot unwind. 1,074 lib tests had passed by then; the rest of that binary did not run. Every test that failed in that run is among the 17.
    • So the abort came once in two runs of the head and not in the one run of the base. The PR's diff changes only bind.rs (stage_args_in_window and its two callers in execute_indirect, and the prelude check in make_scaled_args_buffer), not the pipeline workers in pso_async.rs. These runs do not show where the abort comes from.
    • The five tests that failed on rig2 (GTX 1070, Wine) in SlopTart's comment passed here in every run: the four gpu::recomp heap-window tests (gpu_heap_windows_64bit_atomics_match_switch_form, gpu_heap_windows_divergent_lanes_match_switch_form, gpu_heap_windows_reject_out_of_uma_aliasing, gpu_heap_windows_reject_out_of_uma_aliasing_all_slots) and bind::tests::gpu_two_pass_indirect_commands_keep_their_own_records.

Not tested

  • The fix itself: a longer run into the world (or a warm cache) is needed to reach the two-pass ExecuteIndirect draws with arguments outside the windows.
  • Whether the lib binary's abort comes back in more runs (one in two here).
  • Resizable BAR on, other caps (1024), AMD, Intel.

AI use: Claude Code, model Claude Opus 5.5. It built both commits, ran the runs and the suites on the machine above, read the logs and wrote this. The person running these tests asked for this post.

Review of the first version found two problems:
- The shared 4 MiB ring could hand two recorders the same slot at the
  wrap. A slot could also be reused before an earlier list that read it
  had run on the GPU.
- A tracked console buffer with an out-of-range offset fell through to
  the GPU copy instead of being refused.

Arguments and the count are now resolved first. A tracked buffer the
range does not fit is refused. Only untracked PC buffers outside a
bundle are copied, after their buffer width is checked. The copy goes
into the recording's own unified memory (ListState::arena), which is
retired with the recording at its allocator's reset. Nothing is
recorded unless every range fits and all space is taken. New tests
cover the range checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown
Contributor

One more lifetime case on head f64494d: one ExecuteIndirect can stage its count over its own arguments. This does not need two GPU queues or submission of the other recorder's lists.

Reproducible reservation and GPU order
  1. Recorder A stages a 12-byte DispatchMesh argument (2, 1, 1) at ring offset 0. The next 256-byte reservation begins at 256.
  2. Before A stages its count, recorder B makes 16,383 more 12-byte staging reservations. Each advances the shared cursor by 256 bytes; it reaches exactly 4 MiB. B's recorded lists are never submitted.
  3. A stages a four-byte count of 1. fetch_add then wraps that reservation to offset 0. A's one submitted list copies arguments to [0, 12), then count to [0, 4), before make_scaled_args_buffer reads both. The scaling shader reads count 1 and argument X 1, so with capacity for two groups it emits one group rather than two.

Please keep both inputs in disjoint spans of one recording-owned allocation and retain them through the consuming submission. Reserving the two inputs together would prevent this particular self-alias; it would not by itself prevent reuse by another in-flight list. A focused regression can force the reservation order above, submit only A, and assert that the scaled X remains 2 with count 1.

This is a source-level execution trace; I did not run that GPU regression. AI use: Codex (GPT-6.2 Astra) found the schedule; Codex (GPT-6.2 Sol) checked the ring, call sites, and shader reads and wrote this review.

@RodrigoTorreao

Copy link
Copy Markdown
Contributor Author

Thanks @akimfomin and @thehollowedone, both findings were right. e2d72497 addresses both:

  • Shared ring (wrap race and reuse before retirement): the ring is gone. Staged bytes now go into the recording's own unified memory (ListState::arena / s.uma). That is the space XCL already uses for argument tables and io blocks, and it is retired with the recording at its allocator's reset. Two recorders never share a slot, and a slot is never reused while a list that reads it can still run.
  • Known-invalid ranges: arg_source now separates tracked but out of range (refused, as on amd-dev) from untracked PC buffer (staged). A bundle never stages. The arguments and the count are both resolved, the PC buffers' dimension and width are checked (pc_range_fits), and all space is taken before any barrier or copy is recorded. If any step fails, the list is left as it was and the draw is skipped. stage_args_tests covers the refused cases, including offset and address overflow.

The same A/B on the RX 6750 XT (Series S, XCL_COHERENT_CAP_MB=2048): skipped draws went from 19,587 (2.8 %) to 64. Every copy was staged and none was refused. Both runs end at #2619. Smoke against main b937fba, and the full suite (PR failures are a subset of amd-dev's), are in the updated description.

@Prime1997: thanks, glad to see it carried over to nvidia-dev. The recording-owned arena should work there too, if that branch has the same ListState.

AI-assisted (Claude Code with Claude Opus 5.5); run by me on the hardware above.

@thehollowedone

Copy link
Copy Markdown
Contributor

Thanks for the quick update. I checked new head e2d7249: the recording-owned arena removes the reported ring alias, and arg_source rejects tracked out-of-range inputs before staging. Two resource-state paths still need a GPU check before this revision is merge-ready:

  1. An untracked UPLOAD argument or count buffer is a valid indirect/copy source in GENERIC_READ. stage_args_in_window unconditionally records INDIRECT_ARGUMENT -> COPY_SOURCE -> INDIRECT_ARGUMENT for it. D3D12 requires UPLOAD resources to remain GENERIC_READ, which already contains both read states. Leave that source untransitioned; keep a state-correct path for DEFAULT resources.
  2. Two staged draws in one native list can use different arena offsets of the same window buffer resource. The first make_scaled_args_buffer dispatch reads it as a UAV. The next CopyBufferRegion writes that resource without a UNORDERED_ACCESS -> COPY_DEST transition. The first copy's COPY_DEST -> COMMON barrier precedes the shader read; it does not restore COMMON afterward. COMMON promotion does not reset between commands in one list. Track/transition the window resource for the next copy, coalescing barriers when arguments and count share it.

Please add a debug-layer/GPU case for an UPLOAD source and another for two staged draws in one list, checking both scaled outputs and the info queue. On a Windows 11 build 26300 host with an RTX 3080 Ti / 621.35, cargo test --offline --locked -j 4 -p xcl --lib stage_args_tests -- --test-threads=1 --nocapture passed 3/3, and the same command with filter gpu_two_pass_indirect_commands_keep_their_own_records and without --exact passed 1/1, zero skips. The latter uses the default D3D12 adapter without logging its identity and does not enter this staging fallback. These two findings are source-level traces, not measured GPU failures; I did not run the full suite or a title on this head.

AI use: Codex (GPT-6.2 Astra) traced the lifetime and state paths; Codex (GPT-6.2 Sol) checked the current source against D3D12's state rules, ran the focused tests, and wrote this review.

@oni-swr

oni-swr commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Tested (native Windows AMD RDNA3 data point; no native Windows AMD report was in the thread yet)

  • RX 7800 XT 16 GB (RDNA3), driver 32.0.31035.1003, Ryzen 7 5700X3D, 64 GB RAM, Windows 11 build 26200, Rust stable MSVC.

  • amd-dev base 7c795f5eefa0661eaf3f9f696d0cba3a75ce9628 vs this PR's head e2d7249707cb9732e00fca85131d34491c9d9384 (two commits on that same base), release builds from clean checkouts with --locked.

  • Tests at the head, run on this GPU with XCL_D3D12_DEBUG=1:

    • the three new stage_args_tests: 3 passed, 0 failed, 0 ignored;
    • gpu_two_pass (4 tests): 4 passed, 0 failed, 0 skipped;
    • gpu_heap_windows (4 tests): 4 passed, 0 failed, 0 skipped.

    The debug layer printed no D3D12 info-queue messages.

  • Paired scripts/smoke.ps1 run of a retail title, 200 s per arm, XCL_PREPARE=0, each arm with its own copy of the caches, default coherent window (no XCL_COHERENT_CAP_MB):

frames shown device removals crashes peak local VRAM peak commit
base 7c795f5e 5711 0 0 4720 MB 12397 MB
head e2d72497, run 2 5702 0 0 4761 MB 12423 MB

Both ended on 65536 draws with translated pipelines, 0 skipped, 0 dispatches skipped. The "two-pass ExecuteIndirect skipped" line, the "indirect arguments outside the memory windows copied" line and "out of range, not run" never appeared on either arm.

  • One head run was cut short. My first head run was stopped by my own watchdog at 97 s because free system commit fell below 6 GiB. Over about 30 s its host commit rose from about 13 GB to 19 GB and its process VRAM from 5.1 GB to 6.6 GB, and was still rising; the base arm was flat at 12.3 GB and 4.9 GB over the same window. I did not keep that run's log (my harness lost it), and a second head run, with logs kept, did not repeat it (flat at 12.3 GB commit and 4.9 GB VRAM for the whole run). So I cannot say what caused it, or whether it is related to this PR; it is one unexplained excursion in two head runs and one base run.

Not tested

  • The path this PR changes was not reached in the title run (the lines above stayed at 0 on both builds), so the smoke run is a regression check only, not evidence that the fix works. No smaller coherent window was tried.
  • The two resource-state paths thehollowedone asked about were not covered: (1) an untracked UPLOAD argument or count source transitioned out of GENERIC_READ, and (2) two staged draws in one list reusing the window buffer without a UAV to COPY_DEST barrier. The focused tests above do not exercise them, so "no debug-layer messages" says nothing about either.
  • Full suite, one run per arm, other GPUs, Wine.

AI use

Claude Code, Claude Sonnet 5.5, ran the builds, tests and paired runs and wrote this report.

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: e2d7249

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 7c795f5 (amd-dev)
head: e2d7249
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 on amd-dev 7c795f5 + this PR, RTX 4080 (32-lane NVIDIA): the lib test binary ended abnormally (0xc0000409) before its summary, as amd-dev alone did in the run next to it (0xc0000005) and as it did here in 3 of 6 runs before; so there are no lib counts for this tree from this card. Complete runs of the same base on this card (the two other trees of this batch) have 16 to 17 failures of their own on NVIDIA. I did not rerun: the verdict below does not hang on the counts.
review: the two points of the second review in the thread are unanswered, and I can follow both in the source. (1) The staging copy always records indirect-argument -> copy-source -> indirect-argument transitions for the source; for an untracked source on an upload heap that is not a valid state change. (2) The copy into the window buffer relies on that buffer being promoted from the common state and then adds an explicit copy-dest -> common transition; but the window buffers are the UAVs translated shaders read and write, so after an earlier dispatch or an earlier staged draw's scale pass in the same list the buffer is in the unordered-access state, from which neither the copy nor that transition is valid. That applies to the first staged copy too. Source reading only: I did not see it fail on a GPU, and no title run in the thread reached the staged path (0 staged copies logged). Fixed since the first review, as far as read: the staged bytes live in the recording's own arena, out-of-range buffers are refused before anything is recorded, the count buffer is resolved with the arguments, and nothing is shared between lists.
performance: only on the fallback path; the hoisted prelude is off for a draw that stages. No translator source.
verdict: not yet: the two resource-state points need an answer (or a test with the debug layer that reaches the staged path).
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up to my resource-state review on unchanged head e2d72497:

  1. The DEFAULT-source path needs the complete current read-state mask, not just a heap-type distinction. A title can transition a GPU-produced argument buffer from UAV to INDIRECT_ARGUMENT | NON_PIXEL_SHADER_RESOURCE, execute indirectly, then read the same buffer as a compute SRV. XCL forwards that combined buffer state, and D3D12 permits multiple read bits. Staging instead assumes and restores only INDIRECT_ARGUMENT. Track and restore the exact source state, including combined read bits, or decline staging where that state cannot be established. A one-list regression should GPU-write the arguments, establish the combined state, stage an indirect draw, then read the buffer as an SRV; check both outputs and the debug queue.

  2. The two reservations are not transactional. If arguments take the last available arena block and the four-byte count allocation fails, stage_args_in_window returns None before recording commands, but the first allocation remains held in s.uma until allocator reset. A later arguments-only draw on the same recording can then be skipped despite fitting before the refused call. Reserve both ranges as one checked transaction or roll back every partial reservation, including a newly acquired block. Force the second allocation to fail in a regression, then verify the next valid request still succeeds.

These are source-level execution traces, not GPU failures I measured. The existing review's UPLOAD and shared-window state issues remain separate. AI use: Codex (GPT-6.2 Astra) traced these paths; Codex (GPT-6.2 Sol) checked the current source and D3D12 state rules and wrote this follow-up.

@andrewDoing

Copy link
Copy Markdown
Contributor

I exercised the reservation consequence from the state/lifetime review on e2d7249. The distinction between a new block and an existing block matters for a rollback.

The bounded CPU harness compiled this head's exact Arena::take, used the staging loop's len.max(16) and 256-byte alignment, and supplied a one-block (64 KiB) allocation provider. No GPU command was recorded. In both rows, reserving arguments succeeded, reserving the four-byte count failed, then an arguments-only retry on the same arena was attempted:

Starting state Argument bytes Stock retry Retry after restoring arena cursor/end and returning newly appended blocks
Empty arena, one free block 65,536 Failed; 1 block still held Succeeded; 0 blocks held immediately after rollback
Existing block with 256 bytes already used, no free blocks 65,280 Failed; cursor consumed the existing tail Succeeded; original block stayed held

Releasing only newly acquired blocks misses the second case. Restoring only the cursor misses the first. The checkpoint must cover both fields and the block-list length, with exclusive access to the recording until commit or rollback; failures in destination-window resolution also need rollback before emitting barriers. This is an exact allocator-method control with a bounded provider, not an end-to-end ExecuteIndirect test or a claim about source-state barriers. OpenAI Codex prepared and ran the controls and drafted this note.

@andrewDoing

Copy link
Copy Markdown
Contributor

I confirmed the combined DEFAULT-buffer state review on exact head e2d72497 with the native D3D12 debug layer on RTX 5070 (616.92). This reached stage_args_in_window with a valid 12-byte indirect argument record in a DEFAULT buffer. Each control used one DIRECT list and a fresh process.

Source state established on the list Debug result after staging Execution
INDIRECT_ARGUMENT (0x200) Expected mask present; no warnings/errors through Close Native staging-copy readback returned [7,1,1]
INDIRECT_ARGUMENT + NON_PIXEL_SHADER_RESOURCE (0x240), stock Barrier message 527: declared Before=0x200, tracked=0x240. Subsequent AssertResourceState message 538: actual=0x200, missing bit 0x40 Recorded and closed only; never submitted
0x240, explicitly narrow to 0x200 before staging and restore 0x240 afterward Expected mask present; no warnings/errors through Close Native staging-copy readback returned [7,1,1]

The fixture established the incoming mask with a transition after a GPU copy into the DEFAULT argument buffer and asserted that mask before entering staging. On the stock combined-state path, Close itself returned success despite the debug-layer diagnostics. This gives a bounded regression check for both the incoming barrier and outgoing state without submitting an invalid list. The explicit transitions were a matched control in a fixture that knew the full mask; production would need that information from its caller/tracker. This tested the actual staging helper and its bytes, not mesh execution or title performance.

AI-assisted fixture and verification.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head e2d7249

Targets amd-dev, but the branch is based on an older amd-dev history (amd-dev was rewritten), so it shows ~300 base commits and conflicts; only f64494d and e2d7249 (bind.rs: arg_source, stage_args_in_window) belong here. The large line overlap with #3023, #3024, #3025 and #3061 is those shared base commits, not the same change.
#3105 (on main) addresses the same skip of two-pass ExecuteIndirect with arguments outside the windows, but only for UPLOAD-heap buffers and with its own staging; this PR copies any untracked PC buffer into the recording's arena.
Possible problem: stage_args_in_window transitions the source INDIRECT_ARGUMENT -> COPY_SOURCE -> back; if the title's buffer is in an UPLOAD heap (the case #3105 handles), barriers on it are invalid in D3D12.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head e2d7249, description read; base amd-dev, conflicts with it):

  • The branch carries 100 commits and +51,670 / -4,611 lines, so the diff GitHub shows isn't the change described (copying out-of-window two-pass indirect arguments into the window). It needs a rebase onto current amd-dev (or main) so that only its own commit(s) remain; until then it can't be reviewed or merge-checked. The conflict will likely shrink with the rebase.
  • Once rebased, a smoke pair with the coherent-window cap that makes ~3 % of world draws skip (AMD hive: one goal – the retail title (7952987A) past world load on AMD. RX 9070 XT and other RDNA owners, pick a lane #2996 lane 5), on the head commit, would show the fix.

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

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.