Skip to content

D3D12.X: pipelines in two passes are drawn (console MS via DispatchMesh, VS+GS via Draw*) - #215

Open
RemingtonWilcox wants to merge 1 commit into
ivall:mainfrom
RemingtonWilcox:two-pass-draws
Open

RemingtonWilcox wants to merge 1 commit into
ivall:mainfrom
RemingtonWilcox:two-pass-draws

Conversation

@RemingtonWilcox

Copy link
Copy Markdown
Contributor

Console mesh (NGG) and VS+GS pipelines are already translated into two passes at PSO creation
(real::finish_two_pass: a compute pass writing one record per group + a pass-through mesh pipeline), but nothing
ran them. graphics_bound treated the mesh PSO as a PC pipeline and issued DrawInstanced on it, and the console
list's DispatchMesh was a stub. So every MS and GS draw of a title was dropped. Only the test harness
(runner::mesh_draw_split) ran both passes.

This runs them at draw time:

  • bind::two_pass: compute PSO + ABI root signature, io from the kept graphics root arguments, a record buffer
    of groups · record_dwords in the list's upload memory, Dispatch(groups), UAV barrier, then the mesh PSO and
    DispatchMesh(groups · mesh_groups_per_record).
  • MS: the console list's DispatchMesh is hooked at Recompiler: OMOD / CLAMP on f64 results, conversions and integer ops … #126 (and Recompiler: f16 add / sub / fma rounded once under a directed mode (#… #128 on the newer layout). The slot is inferred from
    the PC order after RSSetShadingRate / RSSetShadingRateImage (MS and GS programs translate with the title's memory windows #124 / Revise factual report on ivall/xcl project status #125), not seen in a title. The handler only
    acts with a console mesh pipeline bound. Otherwise it logs the arguments and drops the call like the stub, so a
    retail log will confirm or refute the slot.
  • GS: DrawInstanced / DrawIndexedInstanced first run a generated vertex-fetch compute shader
    (gpu::recomp::fetch, built at PSO creation from the input layout, elements matched to the ES's ISG1 by semantic).
    It fills io[IO_GS_VERTICES] in window 0 from the bound vertex and index buffers, and then the two passes run over
    ceil(prims / 21) groups.
  • A Draw* with a mesh pipeline bound, and ExecuteIndirect with any two-pass pipeline, are skipped and logged instead of
    being sent to the driver. Indirect two-pass draws need a GPU-side bound on the record buffer (follow-up).

Tests without game data (hle::d3d12x::two_pass_tests): a synthetic console MS container and a synthetic ES+GS pair
go through the real pipeline hooks. Draws are recorded through the console list's handlers on a list made as for a
title, and the target is read back and checked per pixel (MS: two groups' triangles, value = group; GS: both
triangles' parallelograms by DrawInstanced, and one through 16-bit indices at an odd offset by DrawIndexedInstanced).

Tested on RTX 3090 (driver 616.92, Windows 11): cargo test --workspace -- --test-threads=2 all green (library: 542 passed; every integration test binary passed; the retail-pack tests skip themselves without XCL_SAMPLE_RPF).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…sh, VS+GS via Draw*)

Console MS (NGG) and VS+GS pipelines were translated into two passes at PSO
creation, but nothing ran them: draws sent DrawInstanced to the driver with a
mesh PSO bound, and the console list's DispatchMesh was a stub.

- bind::two_pass: compute PSO + ABI root signature over the kept graphics root
  arguments, record buffer in the list's upload memory, Dispatch, UAV barrier,
  then the mesh PSO and DispatchMesh(groups * mesh_groups_per_record).
- MS: console list ivall#126 (ivall#128 on the newer layout) hooked as DispatchMesh,
  inferred from the PC order after RSSetShadingRate(Image) at ivall#124/ivall#125; it acts
  only with a console mesh pipeline bound, otherwise logs its arguments and drops.
- GS: DrawInstanced / DrawIndexedInstanced run a generated vertex fetch
  (gpu::recomp::fetch, built at PSO creation from the input layout) into window
  0, then the two passes.
- Draw* with a mesh pipeline and ExecuteIndirect with a two-pass pipeline are
  skipped and logged instead of reaching the driver.
- GPU tests without game data: synthetic MS and ES+GS containers through the
  real pipeline hooks, drawn through the console list handlers, read back.

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

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

I checked this against #199 (rect lists through a generated GS), which touches the same three files, and merge-tested the two together. They don't collide in behaviour, and neither needs to change for the other. This PR does need a rebase on main, though.

Rebase needed (with main, not with #199). This branch starts from 38b05b7. On current main (6da33fa) it conflicts in bind.rs, where main changed bind_abi after 38b05b7. 7495271 made a compute shader take no more user SGPRs than it has: pso_user_sgprs, console_list::inline_for / user_data_for, with the wait for a background pipeline moved ahead of them. Your refactor moves that code into abi_views + set_abi. To test the merge I resolved it like this:

  • abi_views keeps main's argument logic and takes the pipeline (abi_views(this, pso, gfx, res, io_patch));
  • bind_abi passes its pso;
  • two_pass passes 0, since it calls with gfx = true, where main's user-SGPR limit doesn't apply.

That resolution builds and passes everything below. When you rebase, please check that the two-pass compute pass should really get the graphics-side user data. That is unchanged from your branch.

With #199: no collision. bind.rs, list_x.rs and real.rs merge without conflicts apart from the main conflict above. In the merged code:

  • A console VS+GS pipeline of topology type 19 goes to translated_gs_pso (your two passes) before D3D12.X: rect lists drawn whole through a generated geometry shader #199 decides whether to add its rect-list GS. That decision is only for a translated VS+PS pipeline with no GS. So a GS pipeline never gets the generated GS, and real::has_rect_list_gs is false for it.
  • Draws: gs_draw runs first and returns for a two-pass GS pipeline, and graphics_bound returns None for a mesh pipeline. So main's draw_rects (the CPU rect expansion) and D3D12.X: rect lists drawn whole through a generated geometry shader #199's skip in it never see either kind. That is right: expanding a rect on the CPU in front of a console GS would hand the GS two triangles where the console gives it one primitive.
  • A rect-list draw (topology 17) with a GS pipeline: list_x stores 17 as TRIANGLELIST, so gs_draw accepts it and gives the GS 3-vertex primitives. The GS output is drawn as it is, with no rect completion. That matches what AMD's drivers imply: PAL's GraphicsPipeline::CalculateOutputNumVertices accepts only point, line and triangle output when a GS or mesh shader is present. This comes from driver source, not a measurement.

Small notes, none blocking:

  • two_pass_tests::ready() returns early on a missing DXC, device, unified memory or mesh-shader tier, after a println!. That counts as a pass and doesn't go through runner::skip_test, so XCL_REQUIRE_GPU can't turn a skip into a failure. Here both tests drew (no "skipping" in --nocapture output).
  • Nothing tests a rect-list draw (17) with a console GS pipeline. If you want that case covered, I can add it on top of this PR after the rebase. It would be gpu_console_gs_pipeline_draws_through_draw_instanced with topology 17, expecting the same image as with 4.

Tested

  • RTX 5070 Ti (16 GB), NVIDIA 610.74, Windows 11, MSVC, debug.
  • A local merge: D3D12.X: rect lists drawn whole through a generated geometry shader #199 at 7ac4048 (on main 6da33fa) + this PR at 6904870, with the abi_views resolution above. Not pushed.
  • cargo test -p xcl --lib -- --test-threads=2: 594 passed, 0 failed, 20 ignored. Two wave64 tests skip because this GPU has no 64-lane waves. Among the passes:
  • No game files: synthetic programs only.

Not tested

AI use: Claude Code, Claude Opus 5.5.

@srcamarda

Copy link
Copy Markdown

AMD run of 6904870 merged onto main 9ab7d76, plus what a retail log says about slot #126, and a frame-rate regression with its cause.

Merge: the same bind.rs conflict @Kalmarv describes, resolved his way:

  • abi_views(this, pso, gfx, res, io_patch);
  • main's wait and user-SGPR limit apply only on the compute side: user_sgprs = if gfx { None } else { pso_user_sgprs(resolve_wait(pso)) };
  • bind_abi passes its pso, two_pass passes 0;
  • the conflict block keeps this PR's io_patch loop (main's root-signature binding lives in bind_abi / set_abi here).

Tested

  • RX 7800 XT (RDNA3, driver 32.0.32029.2010, native 64-lane waves), Ryzen 5 5600G, Windows 11 26300, Rust 1.100.0 MSVC, DXC 1.8.2502.11
  • two_pass / fetch tests: 6 passed, including gpu_console_mesh_pipeline_draws_through_dispatch_mesh and gpu_console_gs_pipeline_draws_through_draw_instanced. No SKIPPED.
  • cargo test --workspace -- --test-threads=4: 655 passed, 0 failed, 40 ignored. XCL_SPLIT_WAVE64=1 cargo test -p xcl --lib: 615 passed, 0 failed.

Slot #126 in a retail title: called once a frame, not DispatchMesh

On main the title (the newer one in the README table) calls #126 once per frame: 1 291 stub calls in a run of 1 291 frames, [STUB] … ID3D12GraphicsCommandList10::#126 (not on PC) first called from main_game.exe+0x3263e. With this PR, the first calls log:

D3D12.X: command list DispatchMesh slot called (0x0, 0x7783fa00, 0x75e5dba0) without a console mesh pipeline bound (pipeline 0x0) – dropped

The arguments look like addresses, not group counts, so here #126 is probably not DispatchMesh. This title's mesh pipelines are the "MS in the AS slot" ones main refuses, so its draws never reach the two-pass path.

The regression: 10–13 % fewer frames, from dispatch_mesh's resolve_wait

scripts/smoke.ps1, 90 s, XCL_NETWORK=0, release. Each binary starts with a cold translation cache, then runs warm:

build cold warm warm
main 9ab7d76 1 129 1 164 1 100
this PR (merged) 814 1 032 961
this PR without the #126 / #128 entries 974 1 218 1 164
this PR, dispatch_mesh not waiting (below) 1 258 1 158 1 071

No crash or device removal anywhere, and the same peak commit (~17.2 GB). Apart from the eight DispatchMesh slot called warnings, the logs have the same messages in the same counts.

The cause is dispatch_mesh → bound_two_pass → pso_async::resolve_wait on whatever pipeline is bound at that call, once a frame. For a pipeline still in the background, it waits for it, or builds it on the title's render thread when no worker has started it. main's stub returned at once. A non-waiting check gives main's frames back, and the PR's own tests still pass (6 / 6, lib 615 / 0):

 pub(super) unsafe extern "system" fn dispatch_mesh(this: *mut c_void, x: u32, y: u32, z: u32) {
-    let Some((real, tp)) = bound_two_pass(this).filter(|(_, tp)| tp.kind == "MS") else {
+    // not `bound_two_pass`: a title calls this slot once a frame with other pipelines bound, and
+    // `resolve_wait` would wait for (or build here) a pipeline still in the background; one still
+    // being built is not known to be a mesh pipeline yet and the call is dropped, as by the stub
+    let real = super::pso_async::resolve(with(this, |s| s.pso));
+    let Some((real, tp)) = super::real::two_pass_of(real).map(|tp| (real, tp)).filter(|(_, tp)| tp.kind == "MS") else {

Trade-off: a real DispatchMesh issued while its mesh pipeline is still building is dropped for that frame instead of waited for. Your call whether that is acceptable, or whether the slot should first be confirmed in a title before it is hooked at all.

Regression run (gpu: names a virtual display adapter here, but XCL ran on the RX 7800 XT). The second warm run of each binary, as printed by the script:

main:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: SudoMaker Virtual Display Adapter
title: main_game.exe
seconds: 90
exit: 0x0
frames shown: 1164 (PresentX 1164)
presents per 2 s (last 3): 25 25 24
device removals: 0
crashes: 0
peak commit: 17183 MB

this PR merged onto main (local merge commit, no extra changes):

xcl-smoke v1
commit: 9b12bbfa39032e64d7df1a6accc52abf40bf3e78
gpu: SudoMaker Virtual Display Adapter
title: main_game.exe
seconds: 90
exit: 0x0
frames shown: 1032 (PresentX 1032)
presents per 2 s (last 3): 26 25 24
device removals: 0
crashes: 0
peak commit: 17189 MB

Not tested

  • A title whose MS / GS draws reach the two passes; NVIDIA; the PR's head on its own (only the merge with main).
  • The two experiment builds ran with uncommitted changes on top of the merge, so their smoke blocks are not pasted.

AI use

  • Claude Code with Claude Opus 5.5: resolved the merge, ran the tests and the smoke runs, found the cause by the two builds above, wrote this report.

@MKS2508

MKS2508 commented Nov 23, 2026

Copy link
Copy Markdown

Retail-title confirmation of the DispatchMesh slot, on a GPU without mesh shaders

Ran this branch's head (6904870, built from pull/215/head) against a retail title
(game_scarlett_master.exe 1.0.2.1) on AMD Radeon RX 5700 (RDNA1, no D3D12 mesh shaders),
Windows 11, Rust 1.99.1, release build.

The slot is confirmed — the hook fires and the title calls it every frame:

xcl: D3D12.X: command list DispatchMesh slot called (0x0, 0x85ff7b0, 0x9472da30)
     without a console mesh pipeline bound (pipeline 0x0) – dropped
600 frames presented

So #126 is right from a real title, not only from the synthetic tests.

The bound pipeline is 0x0 in every call: on this adapter the mesh PSOs are never created, so the
calls are dropped exactly as designed. That is not a defect of the branch — but it does mean the
branch cannot change what this GPU draws. The remaining gap for non-mesh adapters is on the PSO
creation side, not the draw hook.

Tested

  • AMD Radeon RX 5700 (8150 MiB VRAM), Windows 11, release, Rust stable 1.99.1
  • cargo build --release -p xcl at 6904870
  • title ran to the menus: 600 frames presented
  • the startup line agrees: WARNING: no mesh shaders: the game's geometry and NGG programs are not drawn

Not tested

  • An adapter with mesh shaders, so the compute + DispatchMesh pairing itself is untested here.
  • GS (Draw* two passes) — this title's log shows no GS two-pass pipeline reaching that path.
  • The frame rate is not reported: the machine had another process on the GPU in that window.

AI use

  • Claude Code

@grahamster2

grahamster2 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

I logged what the retail title does with its "mesh pipeline with its MS … in the AS slot – refused" pipelines (the minimap ones in HANDOFF). This bears on how this PR's console-MS draws would reach them. Before anyone writes code for it there is a design question, at the end.

What the streams hold (main 0e946cf + local logging only, RTX 3080, driver 610.88, release build)

  • The title makes 2,929 of these pipelines in a 240 s run. Main logs 40 refusals, one per distinct MS container. I logged the subobject list of the first six, in two runs, and all six were the same, as (type, payload bytes):
    (0,8) (24,16) (2,16) (3,16) (4,16) (5,16) (8,328) (9,4) (10,44) (21,56) (17,8) (12,16) (14,4) (15,36) (16,4)
    That is the order of a graphics desc (RS, VS, PS, DS, HS, GS, blend, …), but type 24 sits where the VS would be. There is no type 1 and no type 25, and the stream has an INPUT_LAYOUT (12) and a PRIMITIVE_TOPOLOGY (14). The container in 24 parses with stage MS.
  • In these runs the title creates no other mesh pipeline: nothing with a console MS in type 25, and none of the "AS … (MS …) – not supported yet" streams.
  • xcl shaders shaders.rpf: 9,282 programs with DXIL stage MS (hardware stage NGG), 0 with stage AS.

Translating them instead of refusing them (local env switch: the 24 container is passed on as the MS, through main's translated_mesh_stream / two passes)

  • Two 120 s runs from the same build, switch on and off (XCL_FRAME_DUMP=300). The title stays at its first-run menus in both:
    • on: 3,314 frames, no crash, no device removal, last_frame_dump frame 3020 with 517,959 / 518,400 non-dark samples;
    • off (main's refusal): 3,286 frames, the same frame 3020 with the same 517,959 / 518,400 non-dark samples.
      So at the menus, translating them no longer blacks out the image on current main. Each of the 16 "console code so far" lines in each run shows 0 skipped draws and 0 draws with PC pipelines.
  • With the switch on, 3–4 of them are built on first bind (lazy) in each run. I logged every Draw*, ExecuteIndirect, Dispatch and stubbed list slot that ran on the thread whose last SetPipelineState bound one of them. None of those calls came while it was bound. So these runs don't show which call draws them. That needs a run in the world, where the minimap is drawn, and I couldn't get there headless.

Design question: what is console subobject 24 here?

  1. The console's MS type. The console numbers MS as 24, with no gap at PC's 23, so the console types after it would sit one below PC's. Then XCL should read console 24 as MS, check what 25 and up mean in the console's streams, and the pipeline is drawn by DispatchMesh (this PR's Recompiler: OMOD / CLAMP on f64 results, conversions and integer ops … #126 / Recompiler: f16 add / sub / fma rounded once under a directed mode (#… #128).
  2. An NGG program in the VS slot of an ordinary graphics pipeline. The input layout and topology point this way. It would be drawn with Draw* / DrawIndexed*, so it needs a vertex fetch in front, like this PR's GS path, and the DispatchMesh slot doesn't apply.

Until a world run shows the draw call, should main keep refusing them, or translate them as MS? The second is measured above as no change at the menus, but it isn't drawn yet. I'm not writing code for this until that's decided. I can rerun with this logging on top of this PR once it's rebased.

AI-assisted (Claude Code, Claude Opus 5.5): ran the logging build and the runs, and wrote this comment. The numbers come from those runs.

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