Skip to content

D3D12.X: stencil, topology and scissor sets go into deferred two-pass runs - #3036

Merged
raylitebull merged 1 commit into
xcl-dev:nvidia-devfrom
Kalmarv:nvd-two-pass-state
Nov 28, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:nvidia-devfrom
Kalmarv:nvd-two-pass-state

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

With XCL_TWO_PASS_BATCH=2 (off by default) a run of deferred two-pass draws is recorded before nearly every other title call on the list. On the title we run, OMSetStencilRef was the most frequent single reason a run ended (470,956 of 1,048,576 run ends), ahead of a full batch record buffer (249,518), IASetPrimitiveTopology (90,177), the console's method #142 (69,975; a stub in XCL: it records nothing) and RSSetScissorRects (32,433), so runs were 12.7 draws long. These sets now go into the run and are made among its mesh passes where the title made them; #142 no longer ends a run. Runs are then 24.3 draws long. Nothing changes without XCL_TWO_PASS_BATCH=2. Part of #2688.

What is in it

  • hle/d3d12x/bind.rs: RunItem / Step / Cmd StencilRef, Topology, Scissors, queued by queue_stencil_ref, queue_topology, queue_scissors while the list defers, and set among the mesh passes in the title's order (batch_commands, emit_commands); a run with no draws applies them as they came (flush_two_pass). keeps_two_pass_batch keeps slots 20, 22, 24 and the newer layout's 142.
  • hle/d3d12x/list_x.rs: the console's IASetPrimitiveTopology, OMSetStencilRef and RSSetScissorRects go into the run when it takes them (apply_* for the rest).
  • Tests: the kept slots; state_sets_in_a_run_come_between_the_mesh_passes_in_the_titles_order (stencil, scissor, topology and empty scissor sets between draws: the mesh passes and sets in the order and with the state the unbatched path gives them, none among the compute passes).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), Ryzen 9 9950X, Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug tests, release smoke; DXC 1.9.2609 via XCL_DXC_DIR.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on 6f3ad70 (with CARGO_PROFILE_DEV_DEBUG=0: no debug info, for disk space): 1825 passed, 8 failed, 48 ignored. The same command on nvidia-dev a5e2d851: 1822 passed, 10 failed, 48 ignored.
  • Failed here and on a5e2d851 as well: async_compute_pso_registers_real_pso_and_not_standin, console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly, hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays, hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels, split_compute_prefers_the_offline_whole_pipeline, two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.
  • 26 SKIPPED: 8 no wave64; 1 const_mask, wave64: no wave64; 1 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)); 1 f16 arithmetic, wave64: no wave64; 1 f32 arithmetic, wave64: no wave64; 1 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)); 1 f16 packed, wave64: no wave64; 1 f32 compares, wave64: no wave64; 1 mask_ff0_flbit, wave64: no wave64; 1 f64, wave64: no wave64; 1 integer arithmetic, wave64: no wave64; 1 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)); 1 f32 conversions, wave64: no wave64; 1 integer carries, wave64: no wave64; 1 f32 rounding, wave64: no wave64; 1 f32 transcendentals, wave64: no wave64; 1 f32 three-source, wave64: no wave64; 1 no heap windows (opt-in: XCL_HEAP_WINDOWS=1); 1 no heap windows.
  • On the title (timed 480 s runs on the hardware above, one run each; with the change: our team branch's build 75d9b05e, which has it; without: the same build plus two local switches set to restore the old run ends; same env: XCL_TWO_PASS_BATCH=2, XCL_TWO_PASS_SHARED=1, XCL_UMA_UPLOAD_PRIORITY=1, XCL_VRAM_HOT_PRIORITY=1, XCL_DECLARED_LDS=1, XCL_PER_LANE=1, and XCL_TWO_PASS_INDIRECT_MB=4, a knob of our branch that is not in this PR): 10.2-10.3 fps with the runs ended as before, 11.1-11.2 fps with this change, steady to 526 s, no errors, no device removal. A repeat of both: 10.1 and 10.6 fps. So +0.5 to +0.9 fps over two pairs (run-to-run spread about 0.5 fps). Two-pass compute passes per frame 317 before, 168 with it.
  • For context (not this PR): on 75d9b05e with the same env, XCL_TWO_PASS_BATCH=1 ran 6.6-6.7 fps. So mode 2 with nvidia-dev's run ends (on our build, with a 4 MiB indirect reservation where nvidia-dev reserves 32 MiB) was worth about +3.6 fps against mode 1 on this card and title. The default is mode 0 (off).
  • Picture (the runs' dumped frames, compared by a teammate agent; severe transient obstruction = 25 % or more of a doorway's normally bright pixels darkened, in the last ~78 s): first pair, both in the scene's common state: 7 of 30 frames with this change, 0 of 27 without (for the run without: median mask overlap 97.8 % with a reference run, median edge shift 0 px). Repeat pair, both in the scene's other state: 2 of 28 with this change, 2 of 27 without (frames 4580 / 4640 of the run without lost 57 % / 43 % of those pixels). So the obstructions also occur without this change; two runs per arm do not show equal rates either way.
  • CI: Build and test (Windows, no GPU) is red on nvidia-dev itself and on every PR into it, this one included: the lib test process ends with 0x887a0020 in a sparse test on the runner's software adapter, with no test reported failed. Tests: sparse tests take CI's Basic Render Driver for a software device #2837 fixes that test; nothing here touches it.

Regression run
150 s runs, same title, same env (XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_DIRECT_SPLIT_INSTRUCTIONS=0 XCL_PSO_JOURNAL=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=120000, DXC 1.9); the head with XCL_TWO_PASS_BATCH=2 as well (the mode this change acts in). The main run from a hard-link copy of our team branch's DXIL cache; the base and head runs from hard-link copies of one cache warmed on nvidia-dev a5e2d851 (on this branch the title starts after about 75-90 s of startup shader preparation, so 60 s would end inside it).

A commit of main (b49be183, the last one before the shader preparation screen of #2555):

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

The base, nvidia-dev a5e2d851:

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

This PR's head:

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

Not tested

  • AMD, Intel, Wine. Whether the intermittent obstructions above are as frequent with and without the change (two runs per arm). Titles other than this one. The older console layout (no Pr/newer title startup #142 there; slots 20, 22, 24 are kept in both).

AI use

  • The queueing was written on our team branch with Antigravity (Gemini 4 Neon), as its commits there record. Claude Code (Claude Opus 5.5) split it out of those commits onto nvidia-dev, wrote the new test, ran the suite and the smoke on the hardware above and wrote this description. The timed runs and the picture comparison were run by teammate agents (strange: Claude Code; batman: Codex).

🤖 Generated with Claude Code

… runs

With XCL_TWO_PASS_BATCH=2 a run of deferred two-pass draws was recorded
before every title call except the root signature / argument sets,
SetPipelineState to a two-pass pipeline, ExecuteIndirect and
DispatchMesh. On the retail title we run, OMSetStencilRef ended most
runs, then IASetPrimitiveTopology, the console's stub method xcl-dev#142 and
RSSetScissorRects (run ends at 533 s: 470,956 / 90,177 / 69,975 / 32,433
of 1,048,576), so runs were 12.7 draws long.

OMSetStencilRef, IASetPrimitiveTopology and RSSetScissorRects now go into
the run (RunItem / Step / Cmd StencilRef, Topology, Scissors) and are set
among the mesh passes where the title made them, so each mesh pass draws
with the state of its draw; a run with no draws applies them as they
came. The newer layout's xcl-dev#142, which XCL stubs (it records nothing), no
longer ends a run. Runs are then 24.3 draws long.

Measured on the title (RTX 5070 Ti, timed 480 s runs, one each, same
build and env with XCL_TWO_PASS_BATCH=2): 10.2-10.3 fps with runs ended
as before, 11.1-11.2 fps with this.

Tests: the kept slots, and runs with stencil / topology / scissor sets
between draws give each mesh pass the state and order the unbatched path
gives it.

Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #3036 at head 6f3ad70ccc22acb777205cdea1d512bf24421299 (1 commit; exact parent & merge-base: a5e2d851a503fc0e04609f773ea53f2d2c4e3269, ancestor of nvidia-dev).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12, Wave32-only Ada), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted tests & build (6f3ad70c)

Command Result
cargo test --release -p xcl --lib -- --nocapture state_sets_in_a_run_come_between_the_mesh_passes_in_the_titles_order (3 consecutive runs) 1 passed; 0 failed; 0 ignored; 1727 filtered out × 3 (0.00s, 0.00s, 0.00s, 0 skipped)
cargo test --release -p xcl --lib -- --nocapture hle::d3d12x::bind:: hle::d3d12x::list_x:: (3 consecutive runs) 104 passed; 0 failed; 0 ignored; 1624 filtered out × 3 (0.88s, 0.89s, 0.91s; 103 executed + 1 self-skipped two_pass_binds_set_the_shared_view_heap: no heap windows (opt-in: XCL_HEAP_WINDOWS=1))
cargo build --release -p xcl Clean build (2m 05s, exit 0, 0 new warnings in bind.rs or list_x.rs)

Paired quiet 60 s retail smoke (title: 29640639, XCL_PREPARE=0, XCL_NETWORK=0)

Exact parent & merge-base (a5e2d851a503fc0e04609f773ea53f2d2c4e3269, nvidia-dev ancestor):

xcl-smoke v1
commit: a5e2d851a503fc0e04609f773ea53f2d2c4e3269
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1513 (PresentX 1513)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14868 MB

PR #3036 (6f3ad70ccc22acb777205cdea1d512bf24421299):

xcl-smoke v1
commit: 6f3ad70ccc22acb777205cdea1d512bf24421299
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1587 (PresentX 1587)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14690 MB

Limits of coverage

  • state_sets_in_a_run_come_between_the_mesh_passes_in_the_titles_order (1/1, 0 skipped) and hle::d3d12x::bind:: + hle::d3d12x::list_x:: (103 executed + 1 opt-in XCL_HEAP_WINDOWS=1 self-skip) passed 3/3, directly verifying that OMSetStencilRef, IASetPrimitiveTopology, and RSSetScissorRects queue into active deferred two-pass runs and replay between mesh passes in title order.
  • Both smokes were run with XCL_PREPARE=0 and XCL_NETWORK=0 (0 device removals, 0 crashes, steady 60 Hz; steady-state memory at ~58.3 s: 14603 MB committed, 6115 MB local, 4732 MB non-local); visual correctness of interleaved stencil/topology/scissor state changes in complex in-world scenes was not separately inspected beyond the 60 s startup smoke and unit test.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check

base: d1be810

head: 6f3ad70

merge: clean uncommitted trial merge into the current nvidia-dev tip; only bind.rs and list_x.rs changed (+158/-15).

build: cargo build --offline --locked --workspace -> ok on the trial merge.

tests: cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture -> 1,827 passed, 9 failed, 48 ignored across 45 targets; 26 explicit GPU SKIPPED notices. The exact PR parent a5e2d851 produced 1,826 passed, the same 9 failed, 48 ignored, and 26 skips. The unmerged head 6f3ad70c also produced 1,827/9/48 and 26 skips. The nine failing invocations match across all three runs: mesh HLSL compute cache (1), texture upload (2), console MS slot (1), async compute PSO (1), split compute (2 targets), and two-pass driver cache (2 targets). The new state-order regression passed on the head (1/0/0/0).

review: I traced both changed files. Deferred stencil, topology, and scissor sets replay in title order before the corresponding mesh passes; the compute passes precede them and these setters change graphics state. No new source-level blocker found in this diff. This does not establish visual parity for the author's intermittent obstruction reports.

performance: the feature remains off by default. With batching enabled, fewer fixed-state calls force a run flush; I did not measure frame time on this GPU.

verdict: not yet: the PR's Build and test (Windows, no GPU) check is red at the software-adapter sparse test (0x887a0020); PR description is green. The branch's CI repair must land and this head's checks must be rerun before merging.

hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), rustc 1.99.1 MSVC; OpenAI Codex (GPT-6.2 Sol) traced the source and ran the three suites.

Not tested here: a title run, opt-in batching performance, AMD, Intel, or Wine.

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 6f3ad70

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d1be810 (nvidia-dev)
head: 6f3ad70
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1825 passed, 8 failed, 48 ignored (27 SKIPPED lines). The 8 failures are the base's own on this GPU, the same six names with and without the PR (#2771 and #2788 fix three of them). Base alone: 1824 passed, 8 failed, 48 ignored.
review: deferral needs XCL_TWO_PASS_BATCH=2 (off by default); by default the new queue calls return after one atomic load and no draw changes. One default-path edge worth a line: in rs_set_scissors_x a call with a non-null pointer and a count of 0 no longer clears the recorded scissors (the base set them to empty), so a later restore after a list split would re-apply stale rectangles. Replay order under the switch is right: the state sets go among the mesh passes only, compute passes come first. World-run note: this PR has been part of the local build this card used for 16 world runs yesterday (d1be810 plus a stack of open PRs, 5 to 30 minutes each, switches of this PR left at their defaults); nothing in those runs pointed at it.
performance: by default one small Vec allocation per scissor call (reasoned).
verdict: safe to merge (suggest restoring the count-0 clear, here or as a follow-up)
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 unless said).

@raylitebull
raylitebull merged commit 23fb987 into xcl-dev:nvidia-dev Nov 28, 2026
1 of 2 checks passed
raylitebull pushed a commit that referenced this pull request Nov 29, 2026
… runs

With XCL_TWO_PASS_BATCH=2 a run of deferred two-pass draws was recorded
before every title call except the root signature / argument sets,
SetPipelineState to a two-pass pipeline, ExecuteIndirect and
DispatchMesh. On the retail title we run, OMSetStencilRef ended most
runs, then IASetPrimitiveTopology, the console's stub method #142 and
RSSetScissorRects (run ends at 533 s: 470,956 / 90,177 / 69,975 / 32,433
of 1,048,576), so runs were 12.7 draws long.

OMSetStencilRef, IASetPrimitiveTopology and RSSetScissorRects now go into
the run (RunItem / Step / Cmd StencilRef, Topology, Scissors) and are set
among the mesh passes where the title made them, so each mesh pass draws
with the state of its draw; a run with no draws applies them as they
came. The newer layout's #142, which XCL stubs (it records nothing), no
longer ends a run. Runs are then 24.3 draws long.

Measured on the title (RTX 5070 Ti, timed 480 s runs, one each, same
build and env with XCL_TWO_PASS_BATCH=2): 10.2-10.3 fps with runs ended
as before, 11.1-11.2 fps with this.

Tests: the kept slots, and runs with stencil / topology / scissor sets
between draws give each mesh pass the state and order the unbatched path
gives it.

Upstream PR #3036 (6f3ad70 on origin/main), cherry-picked:
the deferred runs of XCL_TWO_PASS_BATCH=2 go on across these sets on the
title run here too. No change to translated shaders.

(cherry picked from commit 6f3ad70)

Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SJTheGreat06 pushed a commit to SJTheGreat06/xcl that referenced this pull request Nov 29, 2026
… runs

With XCL_TWO_PASS_BATCH=2 a run of deferred two-pass draws was recorded
before every title call except the root signature / argument sets,
SetPipelineState to a two-pass pipeline, ExecuteIndirect and
DispatchMesh. On the retail title we run, OMSetStencilRef ended most
runs, then IASetPrimitiveTopology, the console's stub method xcl-dev#142 and
RSSetScissorRects (run ends at 533 s: 470,956 / 90,177 / 69,975 / 32,433
of 1,048,576), so runs were 12.7 draws long.

OMSetStencilRef, IASetPrimitiveTopology and RSSetScissorRects now go into
the run (RunItem / Step / Cmd StencilRef, Topology, Scissors) and are set
among the mesh passes where the title made them, so each mesh pass draws
with the state of its draw; a run with no draws applies them as they
came. The newer layout's xcl-dev#142, which XCL stubs (it records nothing), no
longer ends a run. Runs are then 24.3 draws long.

Measured on the title (RTX 5070 Ti, timed 480 s runs, one each, same
build and env with XCL_TWO_PASS_BATCH=2): 10.2-10.3 fps with runs ended
as before, 11.1-11.2 fps with this.

Tests: the kept slots, and runs with stencil / topology / scissor sets
between draws give each mesh pass the state and order the unbatched path
gives it.

Upstream PR xcl-dev#3036 (6f3ad70 on origin/main), cherry-picked:
the deferred runs of XCL_TWO_PASS_BATCH=2 go on across these sets on the
title run here too. No change to translated shaders.

(cherry picked from commit 6f3ad70)

Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

5 participants