Skip to content

D3D12.X: record shared view-heap use for two-pass draws - #3324

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/two-pass-shared-view-heap
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:fix/two-pass-shared-view-heap

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

  1. All four two-pass MS/GS bind paths in crates/xcl/src/hle/d3d12x/bind.rs (bind_two_pass_stage, the sliced dispatch_mesh path, defer_dispatch_mesh / defer_execute_indirect, and flush_two_pass) called list_x::ensure_view_heap(this) directly, discarded its bool return value, bypassed the per-recording (s.heap_bound, s.shared_view_bound) cache, and never called list_x::note_shared_view_heap_use(this). As a result, a command-list segment containing only two-pass MS/GS draws reported uses_shared_view_heap == false, allowing SHARED_VIEW_EPOCHS / with_quiescent_shared_view_heap (XCL_TEXTURE_BUDGET_EVICT=1) to treat the shared view heap as quiescent while two-pass draws were still reading ResourceDescriptorHeap.
  2. In crates/xcl/src/hle/d3d12x/list_x.rs, ensure_view_heap returned false early whenever both view_raw and sampler_raw were None (for example under default XCL_HEAP_WINDOWS=0 when no default sampler heap was injected), even if set_descriptor_heaps_x had already bound the shared view heap (b.shared_view_heap == true).

Fix

  • crates/xcl/src/hle/d3d12x/list_x.rs: Split ensure_view_heap into ensure_view_heap_with(this, view_raw, sampler_raw) so the early return when view_raw.is_none() && sampler_raw.is_none() reads LISTS[this].bindings.shared_view_heap instead of unconditionally returning false. Added #[cfg(test)] helpers uses_shared_view_heap_for_test / seed_shared_view_heap_for_test and unit test ensure_view_heap_preserves_already_bound_shared_view_heap.
  • crates/xcl/src/hle/d3d12x/bind.rs: Extracted ensure_view_heap_cached and note_shared_view_use, and updated emit_two_pass_stage / record_two_pass_stage, bind_two_pass_stage, sliced dispatch_mesh, defer_dispatch_mesh, defer_execute_indirect, flush_two_pass, and bind_abi_with_root_resolved to share the per-recording heap cache and record list_x::note_shared_view_heap_use only when two-pass stages or deferred draws actually emit with the shared view heap bound (failed stage binds, dropped un-flushed deferred draws, and state-only flushes do not mark use). Added deterministic unit tests two_pass_stage_records_shared_view_heap_use_and_caches_heap_check and flush_two_pass_records_shared_view_heap_use_only_when_draws_emit.
  • crates/xcl/src/hle/d3d12x/vram.rs: Added #[cfg(test)] with_srv_tracking_for_test holding VRAM_TEST_LOCK with a panic-safe RAII reset guard for deterministic parallel unit testing.

Tested

  • cargo check --workspace --all-targets — clean (0 errors).
  • Targeted unit tests (XCL_HEAP_WINDOWS=0): cargo test -p xcl --lib -- ensure_view_heap_preserves two_pass_stage_records_shared_view_heap flush_two_pass_records_shared_view_heap shared_view_use shared_view_heap --nocapture — 7 passed, 0 failed.
  • Targeted unit + GPU tests (XCL_HEAP_WINDOWS=1 on NVIDIA GeForce RTX 5070 Ti): cargo test -p xcl --lib -- ensure_view_heap_preserves two_pass_stage_records_shared_view_heap flush_two_pass_records_shared_view_heap two_pass_binds_set_the_shared_view_heap --nocapture — 4 passed, 0 failed.
  • Full workspace GPU suite on NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074, XCL_DXC_DIR set to DXC 1.9.2609.5): cargo test --workspace -- --test-threads=4 — exit 0, all test binaries passed.

Regression run

Baseline (main ancestor f0e8fdd5c3942ddd399d5ee11384c8595c5aacff):

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

Branch (9baafc68bd714190aa02a3c31a18041c7edefbec, warm cache; an initial cold-blob run hit a pre-existing title watchdog crash during a 34.6 s compute PSO driver compile, after which the warm-cache run completed cleanly):

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

Not tested

  • End-to-end title run with XCL_TEXTURE_BUDGET_EVICT=1 enabled simultaneously with XCL_TWO_PASS_BATCH=2 under active VRAM pressure (the shared view-heap epoch capture and flush/reset/bind gating are covered by the new unit tests and existing vram/list_x epoch tests).
  • AMD / Intel adapters (tested on NVIDIA GeForce RTX 5070 Ti only).

AI use

Written and verified with an AI coding assistant; all code edits, unit tests, GPU test runs, and smoke verification were reviewed and executed locally.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Review (head 9baafc6, diff read, not a merge-check):

  • The fix is still lost on one path. In kickoff_x, take_kickoff_effects_before_close reads uses_shared_view_heap (list_x.rs ~5244, the take at ~1327) before flush_two_pass(this, RunEnd::Segment) runs (~5251), and that flush is where this PR now sets the flag (bind.rs ~2390). So on a list with no title_list wrapper, deferred two-pass draws still lose the flag at KickoffX, and it carries over to the next recording, which is the bug the PR describes. It is only reached with XCL_TWO_PASS_BATCH and XCL_TEXTURE_BUDGET_EVICT set.
  • The "reached under the default" claim for the second fix looks overstated: the sampler heap is created on demand.
  • The description has no full-suite counts or model name. The smoke run ends at 0 0 0 presents. CI is red on a title_textures flake (Tests: a title-queue upload waits for at least the mappings made before it #3278 fixes that).

Suggested verdict: not yet (move the flag set before the take, or take the effects after the flush).

(Review written with Claude Code, Claude Opus 5.5; the first point was traced in the code.)

KickoffX flushes the deferred two-pass draws before it takes the recording's effects: on a list without a title_list wrapper the effects were taken first, so the shared view-heap use (and the pipeline state and native generations) the flush records stayed in the list's state for its next recording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the fix/two-pass-shared-view-heap branch from 9baafc6 to c0533b6 Compare November 30, 2026 23:35
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Re-review (head c0533b6, diff read, not a merge-check: the PR description check fails, so not built or run here yet). Follow-up to my review of 9baafc6.

  • KickoffX ordering: fixed. The flush now runs before the effects are taken (list_x.rs ~5237 vs ~5247), which also refreshes bound_pso and the native generations. But there's no test that fails without it; CONTRIBUTING asks for one.
  • The smoke block names 9baafc6, not the head c0533b6, which is why PR description fails. Rerun scripts/smoke.ps1 on the head.
  • "Reached under the default" is still in the description. The ensure_view_heap_with early return change (~6017-6024) is right, but ensure_global_sampler_heap (~5928) creates the sampler heap whenever a device exists, so that branch needs no device or a failed heap creation, not just XCL_HEAP_WINDOWS=0.
  • Tested still has no pass/fail/ignored/SKIPPED counts, and AI use names no model (the commit trailer says Claude Opus 5.5).
  • Outside this PR, low confidence: the list-split path reads its carried state (~4571) before its flush (~4636), so bound_pso may be stale there when the deferred draws set a pipeline.

Fine: flush_two_pass records the heap use only when draws are emitted, the check reuses the bind_abi cache (cleared on Reset, ClearState, a list split and the title's SetDescriptorHeaps, which also flushes the deferred draws first), and the two-pass tests cover both bind paths and the flush cases. Everything beyond the heap check needs XCL_TWO_PASS_BATCH=2 or XCL_TEXTURE_BUDGET_EVICT=1.

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

Test report (not a merge-check: PR description red)
base: b2b1f10
head: c0533b6
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: not repeated here; my review of this same head is at #3324 (comment), and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. The first run of this merge lost the lib test binary to the known driver-cache access violation (#1487); this is the rerun.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
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 c0533b64: 2 finding(s). 2 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.

) -> Result<(), String> {
// the pair is translated with heap windows when they are on (`pso::mem_windows`): as `bind_abi`
super::list_x::ensure_view_heap(this);
let shared_view_bound = ensure_view_heap_cached(this);

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.

The two-pass paths (bind_two_pass_stage, sliced dispatch_mesh, defer_*) now use the per-recording heap cache instead of calling list_x::ensure_view_heap on every stage. That removes the re-check that bound the shared view and sampler heaps once they existed. With XCL_HEAP_WINDOWS=1, if a recording's first ensure runs before console_heap::global_heap() or the shared sampler heap exists, the cache stores (heap_bound=true, shared_view_bound=false), and later two-pass stages in that recording never bind the now-existing shared heap. The translated MS/GS shaders then index ResourceDescriptorHeap with the title's heaps or none, giving wrong descriptors or device removal. The use also isn't recorded, so eviction treats the heap as unused. Before this PR, every stage called ensure_view_heap and recovered.

if let Some((mesh, stages, shared_view_bound)) = &staged {
let stage = if compute { &stages[slice as usize] } else { mesh };
emit_two_pass_stage(list, stage, compute);
record_two_pass_stage(this, list, stage, compute, *shared_view_bound);

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.

record_two_pass_stage notes shared-view use only when emit_two_pass_stage returns true, but the caller still issues list.Dispatch / pc_dm when the stage emitted nothing. With a null rs/pso, the Dispatch or DispatchMesh runs with whatever pipeline and root signature were bound before. If that pipeline reads the shared view heap and was carried across KickoffX or split_recording via init_pso, the new segment's uses_shared_view_heap stays false, so SHARED_VIEW_EPOCHS misses a GPU read of the shared heap and eviction can free it under that read. Before the new gating this under-report couldn't happen. Either skip the dispatch when nothing was emitted, or note the use whenever a dispatch is issued.

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 area:memory Virtual/physical memory, arenas, VRAM budget, UMA 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.

3 participants