D3D12.X: sanitize PATCH without HS and console topology types in graphics PSO fallbacks #3371

Open
Kalmarv wants to merge 1 commit from upstream-pr/3371 into main
Kalmarv commented 2026-11-29 10:54:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T10:54:58Z.


What is in it
Sanitize invalid or unsupported PrimitiveTopologyType values across all three graphics pipeline fallback and rewrite paths in crates/xcl/src/hle/d3d12x/real.rs (rebased onto main 3b6a91ed, preserving sanitize_integer_rt_blend(..., logic_op_supported())):

  • fallback_stream now handles D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY (subobject 14), rewriting any topology type outside POINT/LINE/TRIANGLE (1..=3) — including console RECT_LIST_TYPE (19), UNDEFINED (0), and PATCH (4) after fallback_stream strips HS/DS — to D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE (3).
  • pc_topology_type now checks whether the descriptor actually retains a non-empty Hull Shader (HS) and rewrites PATCH (4) without HS (for example after standin_graphics or graphics_pso fallback strips HS/DS) as well as console-only or undefined topology types to D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE (3), keeping PATCH only when HS is present.
  • rewrite_graphics_stream now checks has_hs when validating subobject 14 (PRIMITIVE_TOPOLOGY), rewriting PATCH without HS and any out-of-range/console topology type to default_topo.
  • Added unit and WARP D3D12 tests in hle::d3d12x::real::pso_topology_sanitize_tests covering pc_topology_type, fallback_stream, and rewrite_graphics_stream with PATCH (with and without HS), console RECT_LIST_TYPE (19), and UNDEFINED (0).

Tested

  • Verified both new tests in hle::d3d12x::real::pso_topology_sanitize_tests failed before the fix (PATCH without HS must become TRIANGLE and WARP CreateGraphicsPipelineState returning E_INVALIDARG (0x80070057) for a PATCH fallback desc) and passed after (2 passed, 0 failed).
  • After rebase onto 3b6a91ed: cargo test -p xcl --lib -- pso_blend_and_tsharp_tests:: (8 passed, 0 failed, including logic-op tests from #2856).
  • Full workspace (cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests:: with DXC 1.9 on NVIDIA GeForce RTX 5070 Ti, wave32): xcl --lib passed 2575 tests (including all pso_topology_sanitize_tests and pso_blend_and_tsharp_tests) and hit only the 4 pre-existing main (3b6a91ed) geometry test failures (geometry_tests::msg_gs_done_emits_in_dxil, geometry_tests::gpu_geometry_msg_gs_done_records, lower_mem::stage_guard_tests::geometry_export_rejected, lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits) fixed in #3411.

Regression run

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
xcl-smoke v1
commit: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1530 (PresentX 1530)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33060 MB

Not tested

  • Retail titles that submit CreatePipelineState streams with D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH or console RECT_LIST on AMD/Intel drivers (verified on WARP and RTX 5070 Ti only).
  • test_title_runs_and_game_folder_is_untouched and uma_driver::tests:: were skipped in the workspace run; wave64 GPU tests were skipped on this wave32 RTX 5070 Ti.

AI use
Assisted with locating the unsanitized topology type paths in real.rs, drafting the fix and synthetic unit/WARP tests, rebasing onto main, and running the test and smoke verification suite; all diffs and test results were reviewed directly.

<!-- greyfinch-sync:ivall/xcl:issue:5550018925 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T10:54:58Z. --- **What is in it** Sanitize invalid or unsupported `PrimitiveTopologyType` values across all three graphics pipeline fallback and rewrite paths in `crates/xcl/src/hle/d3d12x/real.rs` (rebased onto `main` `3b6a91ed`, preserving `sanitize_integer_rt_blend(..., logic_op_supported())`): - `fallback_stream` now handles `D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY` (subobject `14`), rewriting any topology type outside `POINT`/`LINE`/`TRIANGLE` (`1..=3`) — including console `RECT_LIST_TYPE` (`19`), `UNDEFINED` (`0`), and `PATCH` (`4`) after `fallback_stream` strips `HS`/`DS` — to `D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE` (`3`). - `pc_topology_type` now checks whether the descriptor actually retains a non-empty Hull Shader (`HS`) and rewrites `PATCH` (`4`) without `HS` (for example after `standin_graphics` or `graphics_pso` fallback strips `HS`/`DS`) as well as console-only or undefined topology types to `D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE` (`3`), keeping `PATCH` only when `HS` is present. - `rewrite_graphics_stream` now checks `has_hs` when validating subobject `14` (`PRIMITIVE_TOPOLOGY`), rewriting `PATCH` without `HS` and any out-of-range/console topology type to `default_topo`. - Added unit and WARP D3D12 tests in `hle::d3d12x::real::pso_topology_sanitize_tests` covering `pc_topology_type`, `fallback_stream`, and `rewrite_graphics_stream` with `PATCH` (with and without `HS`), console `RECT_LIST_TYPE` (`19`), and `UNDEFINED` (`0`). **Tested** - Verified both new tests in `hle::d3d12x::real::pso_topology_sanitize_tests` failed before the fix (`PATCH without HS must become TRIANGLE` and WARP `CreateGraphicsPipelineState` returning `E_INVALIDARG` (`0x80070057`) for a `PATCH` fallback desc) and passed after (`2 passed, 0 failed`). - After rebase onto `3b6a91ed`: `cargo test -p xcl --lib -- pso_blend_and_tsharp_tests::` (`8 passed, 0 failed`, including logic-op tests from `#2856`). - Full workspace (`cargo test --workspace -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::` with DXC 1.9 on NVIDIA GeForce RTX 5070 Ti, wave32): `xcl --lib` passed `2575` tests (including all `pso_topology_sanitize_tests` and `pso_blend_and_tsharp_tests`) and hit only the 4 pre-existing `main` (`3b6a91ed`) geometry test failures (`geometry_tests::msg_gs_done_emits_in_dxil`, `geometry_tests::gpu_geometry_msg_gs_done_records`, `lower_mem::stage_guard_tests::geometry_export_rejected`, `lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits`) fixed in `#3411`. **Regression run** ``` 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 ``` ``` xcl-smoke v1 commit: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1530 (PresentX 1530) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 33060 MB ``` **Not tested** - Retail titles that submit `CreatePipelineState` streams with `D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH` or console `RECT_LIST` on AMD/Intel drivers (verified on WARP and RTX 5070 Ti only). - `test_title_runs_and_game_folder_is_untouched` and `uma_driver::tests::` were skipped in the workspace run; wave64 GPU tests were skipped on this wave32 RTX 5070 Ti. **AI use** Assisted with locating the unsanitized topology type paths in `real.rs`, drafting the fix and synthetic unit/WARP tests, rebasing onto `main`, and running the test and smoke verification suite; all diffs and test results were reviewed directly.
Aniseto commented 2026-11-29 12:57:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T12:57:17Z.


Ran the PSO topology sanitization tests at c7705119 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_topology_sanitize_tests -- --test-threads=1
2 passed; 0 failed; 0 ignored; 0 measured; 2508 filtered out      (exit 0)

Both tests pass on a real NVIDIA adapter: PATCH without a hull shader and console-only/undefined topology types are rewritten to triangles in the three PSO fallback paths. The thread already reports a full suite on RTX 5070 Ti from the author; this adds an independent run on driver 32.0.16.2140 for the focused group. No title run was made.

Not tested: a retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:ivall/xcl:comment:7256182321 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7256182321). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-29T12:57:17Z. --- Ran the PSO topology sanitization tests at `c7705119` on an NVIDIA Blackwell desktop part: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_topology_sanitize_tests -- --test-threads=1 2 passed; 0 failed; 0 ignored; 0 measured; 2508 filtered out (exit 0) ``` Both tests pass on a real NVIDIA adapter: `PATCH` without a hull shader and console-only/undefined topology types are rewritten to triangles in the three PSO fallback paths. The thread already reports a full suite on RTX 5070 Ti from the author; this adds an independent run on driver 32.0.16.2140 for the focused group. No title run was made. Not tested: a retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Aniseto commented 2026-11-29 14:21:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T14:21:06Z.


Re-ran the PSO topology sanitization tests at 8a21a4be after the head moved from c7705119; this is a new response in the same thread, not an edit of my earlier report: https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7256182321

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_topology_sanitize_tests -- --test-threads=1
2 passed; 0 failed; 0 ignored; 0 measured; 2614 filtered out      (exit 0)

Both tests still pass at the new head: PATCH without a hull shader and console-only/undefined topology types are rewritten to triangles. This adds the new head and driver 32.0.16.2140 as dimensions. No title run was made.

Not tested: a retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:ivall/xcl:comment:7257235311 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7257235311). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-29T14:21:06Z. --- Re-ran the PSO topology sanitization tests at `8a21a4be` after the head moved from `c7705119`; this is a new response in the same thread, not an edit of my earlier report: https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7256182321 Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_topology_sanitize_tests -- --test-threads=1 2 passed; 0 failed; 0 ignored; 0 measured; 2614 filtered out (exit 0) ``` Both tests still pass at the new head: `PATCH` without a hull shader and console-only/undefined topology types are rewritten to triangles. This adds the new head and driver 32.0.16.2140 as dimensions. No title run was made. Not tested: a retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Foniass commented 2026-12-01 05:10:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:10:11Z.


merge-check
base: d0832e614f
head: 8a21a4be2f
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 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: read the whole diff (real.rs, +180/-4, mostly tests). It changes the default path: rect-list (19) and UNDEFINED (0) stream PSOs, refused as stand-ins on main and built during the title's call, now get stand-ins and build in the background; tessellation PSOs (HS + DS + PATCH), which failed to create on main, now give the title a dummy pipeline that draws nothing. Findings: (1) possible topology mismatch (from reading, not run). ia_set_topology_x passes patch-list topologies (33..=64) through unchanged, so the title's patch-list draws now run against a TRIANGLE-type dummy PSO, which D3D12 treats as invalid with undefined behaviour (~10137-10141, ~9939). The dummy VS emits one point, so the risk is driver behaviour rather than a visible picture. Remapping the IA topology for these draws, or saying how it was checked, would settle it. (2) The description doesn't mention the default-path change to rect-list / UNDEFINED PSOs. (3) AI use names no tool or model, no issue is linked, the commit area is d3d12x: (not D3D12.X:), and the test report skips two groups and has no ignored / SKIPPED counts. Fine: stripping HS/DS in fallback_stream makes rewriting PATCH there correct, rect lists map to TRIANGLE as apply_topology maps 17, and the tests fail on main and use skip_test.
performance: 60 s smoke of a retail title, main d0832e61 vs this merge (245aa96c): 1516 -> 1679 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17220 MB, 0 device removals, 0 crashes. The title doesn't show whether it draws with patch-list topologies or rect lists.
verdict: safe to merge (finding 1 is worth settling: remap the IA topology for patch-list draws hitting the dummy TRIANGLE PSO, or say how it was checked)
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.

<!-- greyfinch-sync:ivall/xcl:comment:7301490542 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7301490542). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:10:11Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 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: read the whole diff (real.rs, +180/-4, mostly tests). It changes the default path: rect-list (19) and UNDEFINED (0) stream PSOs, refused as stand-ins on main and built during the title's call, now get stand-ins and build in the background; tessellation PSOs (HS + DS + PATCH), which failed to create on main, now give the title a dummy pipeline that draws nothing. Findings: (1) possible topology mismatch (from reading, not run). `ia_set_topology_x` passes patch-list topologies (33..=64) through unchanged, so the title's patch-list draws now run against a TRIANGLE-type dummy PSO, which D3D12 treats as invalid with undefined behaviour (~10137-10141, ~9939). The dummy VS emits one point, so the risk is driver behaviour rather than a visible picture. Remapping the IA topology for these draws, or saying how it was checked, would settle it. (2) The description doesn't mention the default-path change to rect-list / UNDEFINED PSOs. (3) AI use names no tool or model, no issue is linked, the commit area is `d3d12x:` (not `D3D12.X:`), and the test report skips two groups and has no ignored / SKIPPED counts. Fine: stripping HS/DS in `fallback_stream` makes rewriting PATCH there correct, rect lists map to TRIANGLE as `apply_topology` maps 17, and the tests fail on main and use `skip_test`. performance: 60 s smoke of a retail title, main d0832e61 vs this merge (245aa96c): 1516 -> 1679 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17220 MB, 0 device removals, 0 crashes. The title doesn't show whether it draws with patch-list topologies or rect lists. verdict: safe to merge (finding 1 is worth settling: remap the IA topology for patch-list draws hitting the dummy TRIANGLE PSO, or say how it was checked) 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.
brainhay5 commented 2026-12-01 06:23:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T06:23:10Z.


merge-check claim
head: 8a21a4be2f

<!-- greyfinch-sync:ivall/xcl:comment:7302811438 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7302811438). Originally posted by [brainhay5](https://github.com/brainhay5) on 2026-12-01T06:23:10Z. --- merge-check claim head: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6
brainhay5 commented 2026-12-01 06:39:50 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by brainhay5 on 2026-12-01T06:39:50Z.


merge-check
base: d0832e614f
head: 8a21a4be2f
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 2 failed, 51 ignored; 29 SKIPPED lines
failing: a_preparation_worker_keeps_a_split_programs_abi_whole
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: not yet: adds failing test(s): a_preparation_worker_keeps_a_split_programs_abi_whole
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

<!-- greyfinch-sync:ivall/xcl:comment:7303129371 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7303129371). Originally posted by [brainhay5](https://github.com/brainhay5) on 2026-12-01T06:39:50Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 2 failed, 51 ignored; 29 SKIPPED lines failing: a_preparation_worker_keeps_a_split_programs_abi_whole failing: test_title_runs_and_game_folder_is_untouched review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review. performance: not assessed beyond the suite. verdict: not yet: adds failing test(s): a_preparation_worker_keeps_a_split_programs_abi_whole hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
bmjask commented 2026-12-02 02:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T02:14:28Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 9939

@@ -9934,6 +9934,14 @@ unsafe fn fallback_stream(desc: *const u8) -> Option<(Vec<u8>, [usize; 2])> {
                 let f = super::device_x::pc_view_format(u32::from_le_bytes(buf[at..at + 4].try_into().unwrap()));
                 buf[at..at + 4].copy_from_slice(&f.to_le_bytes());
             }
+            // PRIMITIVE_TOPOLOGY: console rect-list (19), UNDEFINED (0), and PATCH (4, since
+            // HS/DS are stripped above) are rejected by PC D3D12 on the dummy VS+PS stream.
+            14 if psize >= 4 => {

The stand-in and fallback PSOs now get TRIANGLE for a title's PATCH pipeline, but the draw-time IA topology isn't remapped. apply_topology in list_x.rs only maps RECT_LIST (17), so the title's N_CONTROL_POINT_PATCHLIST draws run on a TRIANGLE-type PSO. Before, a tessellation pipeline's stand-in failed to create. Now standin_stream, standin_graphics and the graphics_pso fallback (~8715) succeed, and the title's IASetPrimitiveTopology(PATCHLIST_3) + Draw no longer matches the PSO's PrimitiveTopologyType. That's invalid in D3D12: the debug layer reports it, and some drivers drop the draw or remove the device.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763824388 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#discussion_r4763824388). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T02:14:28Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 9939 ~~~~diff @@ -9934,6 +9934,14 @@ unsafe fn fallback_stream(desc: *const u8) -> Option<(Vec<u8>, [usize; 2])> { let f = super::device_x::pc_view_format(u32::from_le_bytes(buf[at..at + 4].try_into().unwrap())); buf[at..at + 4].copy_from_slice(&f.to_le_bytes()); } + // PRIMITIVE_TOPOLOGY: console rect-list (19), UNDEFINED (0), and PATCH (4, since + // HS/DS are stripped above) are rejected by PC D3D12 on the dummy VS+PS stream. + 14 if psize >= 4 => { ~~~~ --- The stand-in and fallback PSOs now get TRIANGLE for a title's PATCH pipeline, but the draw-time IA topology isn't remapped. `apply_topology` in list_x.rs only maps RECT_LIST (17), so the title's N_CONTROL_POINT_PATCHLIST draws run on a TRIANGLE-type PSO. Before, a tessellation pipeline's stand-in failed to create. Now standin_stream, standin_graphics and the graphics_pso fallback (~8715) succeed, and the title's IASetPrimitiveTopology(PATCHLIST_3) + Draw no longer matches the PSO's PrimitiveTopologyType. That's invalid in D3D12: the debug layer reports it, and some drivers drop the draw or remove the device.
bmjask commented 2026-12-02 02:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T02:14:28Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 10138

@@ -10126,8 +10134,11 @@ fn pc_topology_type(g: &mut D3D12_GRAPHICS_PIPELINE_STATE_DESC) {
         *f = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_target_format(f.0 as u32) as i32);
     }
     sanitize_integer_rt_blend(&mut g.BlendState, g.NumRenderTargets, &g.RTVFormats, logic_op_supported());
-    if !(1..=4).contains(&g.PrimitiveTopologyType.0) {
-        g.PrimitiveTopologyType = if g.HS.pShaderBytecode.is_null() { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH };
+    let has_hs = !g.HS.pShaderBytecode.is_null() && g.HS.BytecodeLength != 0;
+    let valid_topo = (1..=3).contains(&g.PrimitiveTopologyType.0)

Only half the HS<->PATCH rule is enforced. pc_topology_type leaves POINT/LINE/TRIANGLE unchanged when an HS is present, and rewrite_graphics_stream (~10710) has the same gap. A translated desc with HS+DS and PrimitiveTopologyType TRIANGLE (or a console type the PC enum maps into 1..=3) keeps TRIANGLE with an HS, and PC D3D12 rejects it with E_INVALIDARG. The PR describes this case ("keeping PATCH only when HS is present") as handled.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763824392 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#discussion_r4763824392). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T02:14:28Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 10138 ~~~~diff @@ -10126,8 +10134,11 @@ fn pc_topology_type(g: &mut D3D12_GRAPHICS_PIPELINE_STATE_DESC) { *f = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_target_format(f.0 as u32) as i32); } sanitize_integer_rt_blend(&mut g.BlendState, g.NumRenderTargets, &g.RTVFormats, logic_op_supported()); - if !(1..=4).contains(&g.PrimitiveTopologyType.0) { - g.PrimitiveTopologyType = if g.HS.pShaderBytecode.is_null() { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH }; + let has_hs = !g.HS.pShaderBytecode.is_null() && g.HS.BytecodeLength != 0; + let valid_topo = (1..=3).contains(&g.PrimitiveTopologyType.0) ~~~~ --- Only half the HS<->PATCH rule is enforced. `pc_topology_type` leaves POINT/LINE/TRIANGLE unchanged when an HS is present, and `rewrite_graphics_stream` (~10710) has the same gap. A translated desc with HS+DS and PrimitiveTopologyType TRIANGLE (or a console type the PC enum maps into 1..=3) keeps TRIANGLE with an HS, and PC D3D12 rejects it with E_INVALIDARG. The PR describes this case ("keeping PATCH only when HS is present") as handled.
bmjask commented 2026-12-02 02:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T02:14:28Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 10692

@@ -10678,7 +10689,8 @@ unsafe fn rewrite_graphics_stream(
         }
         rt_count = u32::from_le_bytes(p[32..36].try_into().unwrap());
     }
-    let default_topo = if subs.iter().any(|(ty, p)| *ty == 4 && payload_shader(p).is_some()) { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE };
+    let has_hs = subs.iter().any(|(ty, p)| *ty == 4 && payload_shader(p).is_some());

In rewrite_graphics_stream, has_hs uses payload_shader, which requires the HS bytes to be readable, but the HS subobject (type 4) still goes through the _ => out.raw arm unchanged. With an HS whose pointer is non-null but fails gpu::shader::readable (e.g. not yet mapped) and topology PATCH, has_hs is false and topology becomes TRIANGLE while the HS stays in the stream. The driver gets HS + TRIANGLE and rejects it, where before PATCH was kept and matched. The desc path (pc_topology_type) only checks pointer and length, so the two paths can disagree for the same HS. Using shader_bytes in both would fix that.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763824397 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#discussion_r4763824397). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T02:14:28Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 10692 ~~~~diff @@ -10678,7 +10689,8 @@ unsafe fn rewrite_graphics_stream( } rt_count = u32::from_le_bytes(p[32..36].try_into().unwrap()); } - let default_topo = if subs.iter().any(|(ty, p)| *ty == 4 && payload_shader(p).is_some()) { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE }; + let has_hs = subs.iter().any(|(ty, p)| *ty == 4 && payload_shader(p).is_some()); ~~~~ --- In `rewrite_graphics_stream`, `has_hs` uses `payload_shader`, which requires the HS bytes to be readable, but the HS subobject (type 4) still goes through the `_ => out.raw` arm unchanged. With an HS whose pointer is non-null but fails `gpu::shader::readable` (e.g. not yet mapped) and topology PATCH, has_hs is false and topology becomes TRIANGLE while the HS stays in the stream. The driver gets HS + TRIANGLE and rejects it, where before PATCH was kept and matched. The desc path (`pc_topology_type`) only checks pointer and length, so the two paths can disagree for the same HS. Using `shader_bytes` in both would fix that.
bmjask commented 2026-12-02 02:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T02:14:28Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 10137

@@ -10126,8 +10134,11 @@ fn pc_topology_type(g: &mut D3D12_GRAPHICS_PIPELINE_STATE_DESC) {
         *f = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_target_format(f.0 as u32) as i32);
     }
     sanitize_integer_rt_blend(&mut g.BlendState, g.NumRenderTargets, &g.RTVFormats, logic_op_supported());
-    if !(1..=4).contains(&g.PrimitiveTopologyType.0) {
-        g.PrimitiveTopologyType = if g.HS.pShaderBytecode.is_null() { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH };
+    let has_hs = !g.HS.pShaderBytecode.is_null() && g.HS.BytecodeLength != 0;

Not certain about this one: pc_topology_type now turns every PATCH without an HS into TRIANGLE, including VS + GS (patch input) pipelines with no tessellation, which D3D allows. Such a PSO built through the translated graphics_pso path (pc_topology_type at ~8001, where GS is kept) used to keep PATCH. Now its GS input primitive no longer matches, and CreateGraphicsPipelineState fails for a pipeline that was valid.

<!-- greyfinch-sync:ivall/xcl:review-comment:4763824401 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#discussion_r4763824401). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T02:14:28Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 10137 ~~~~diff @@ -10126,8 +10134,11 @@ fn pc_topology_type(g: &mut D3D12_GRAPHICS_PIPELINE_STATE_DESC) { *f = windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT(super::device_x::pc_target_format(f.0 as u32) as i32); } sanitize_integer_rt_blend(&mut g.BlendState, g.NumRenderTargets, &g.RTVFormats, logic_op_supported()); - if !(1..=4).contains(&g.PrimitiveTopologyType.0) { - g.PrimitiveTopologyType = if g.HS.pShaderBytecode.is_null() { D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE } else { D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH }; + let has_hs = !g.HS.pShaderBytecode.is_null() && g.HS.BytecodeLength != 0; ~~~~ --- Not certain about this one: `pc_topology_type` now turns every PATCH without an HS into TRIANGLE, including VS + GS (patch input) pipelines with no tessellation, which D3D allows. Such a PSO built through the translated graphics_pso path (`pc_topology_type` at ~8001, where GS is kept) used to keep PATCH. Now its GS input primitive no longer matches, and CreateGraphicsPipelineState fails for a pipeline that was valid.
bmjask commented 2026-12-02 02:14:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T02:14:28Z.

Review: COMMENTED


Review of 8a21a4be: 4 finding(s). 4 are inline.


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

<!-- greyfinch-sync:ivall/xcl:review:6143678945 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#pullrequestreview-6143678945). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T02:14:28Z. **Review:** COMMENTED --- Review of `8a21a4be`: 4 finding(s). 4 are inline. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
stijn-boer commented 2026-12-02 17:52:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-02T17:52:12Z.


merge-check
base: 817eb1fc9f
head: 8a21a4be2f
verdict: not yet: the workspace suite and retail smoke ended early on both builds. The changed fallback pipeline was verified on WARP and remains unverified on the AMD hardware.

Windows / AMD RDNA4 (native D3D12) — pipeline topology checks on 8a21a4b

Clean merge onto main at 817eb1f (merge commit 6b978c91197fc767eee3f2248e521778b2b2dfa2). git diff --check was clean.

Setup

  • AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332
  • Rust 1.100.0, debug builds, Agility SDK 1.620.2 with matching d3d12SDKLayers.dll, DXC 1.9.2609.5

Tested

cargo build --workspace passed. cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output exited 101 on both builds.

Build Passed Failed Ignored SKIPPED notices
main 340 3 23 0
Merged PR 340 3 23 0

Counts are partial because two test processes aborted on each build.

  • Tests that failed on the PR and passed on main — none observed in the comparable results.
  • Tests added by the PR — pso_topology_sanitize_tests:: ran in isolation with --test-threads=1 --show-output: 2 passed, 0 failed, 0 ignored, 0 skip notices. This includes software WARP pipeline creation and descriptor normalization.
  • Debug-layer coverage — both debug-layer E2E tests, including DRED, and uploads_start_from_each_subresources_state passed on both builds.
Shared failures and process aborts
  • fuzz_validate_and_gpu_1, fuzz_validate_and_gpu_3, and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs reported failures on both builds.
  • The library and gpu_compute_e2e test processes exited with 0xc0000409 on both builds.

Retail smoke

Ran scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary> with XCL_UMA_DRIVER=mixed for title hash 2c508222.

Build Exit Frames logged Device removals logged Peak commit
main 0xc0000409 None 0 1321 MB
Merged PR 0xc0000409 None 0 1320 MB

Diff review

The descriptor checks covered PATCH with and without hull shaders and normalization of RECT_LIST and UNDEFINED. The software pipeline check confirmed that WARP accepted the fallback descriptors.

Not tested

Remaining workspace tests after the aborts, retail frame performance, and creation and rendering of the changed fallback pipelines on the AMD hardware.

AI use

Codex (GPT-6) merged and built the PR, ran the tests, compared the results with main, reviewed the diff, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7353724869 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3371#issuecomment-7353724869). Originally posted by [stijn-boer](https://github.com/stijn-boer) on 2026-12-02T17:52:12Z. --- merge-check base: 817eb1fc9fb0763008ae5d8de1f7f586f442b51d head: 8a21a4be2f31f37bc37401f8e3cb17ec7fa438d6 verdict: not yet: the workspace suite and retail smoke ended early on both builds. The changed fallback pipeline was verified on WARP and remains unverified on the AMD hardware. **Windows / AMD RDNA4 (native D3D12) — pipeline topology checks on `8a21a4b`** Clean merge onto `main` at `817eb1f` (merge commit `6b978c91197fc767eee3f2248e521778b2b2dfa2`). `git diff --check` was clean. **Setup** - AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 7 5700X, Windows 10 21H2 build 19044.6332 - Rust 1.100.0, debug builds, Agility SDK 1.620.2 with matching `d3d12SDKLayers.dll`, DXC 1.9.2609.5 **Tested** `cargo build --workspace` passed. `cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output` exited 101 on both builds. | Build | Passed | Failed | Ignored | `SKIPPED` notices | |---|---:|---:|---:|---:| | `main` | 340 | 3 | 23 | 0 | | Merged PR | 340 | 3 | 23 | 0 | Counts are partial because two test processes aborted on each build. - **Tests that failed on the PR and passed on `main`** — none observed in the comparable results. - **Tests added by the PR** — `pso_topology_sanitize_tests::` ran in isolation with `--test-threads=1 --show-output`: 2 passed, 0 failed, 0 ignored, 0 skip notices. This includes software WARP pipeline creation and descriptor normalization. - **Debug-layer coverage** — both debug-layer E2E tests, including DRED, and `uploads_start_from_each_subresources_state` passed on both builds. <details><summary>Shared failures and process aborts</summary> - `fuzz_validate_and_gpu_1`, `fuzz_validate_and_gpu_3`, and `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` reported failures on both builds. - The library and `gpu_compute_e2e` test processes exited with `0xc0000409` on both builds. </details> **Retail smoke** Ran `scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary>` with `XCL_UMA_DRIVER=mixed` for title hash `2c508222`. | Build | Exit | Frames logged | Device removals logged | Peak commit | |---|---|---|---:|---:| | `main` | `0xc0000409` | None | 0 | 1321 MB | | Merged PR | `0xc0000409` | None | 0 | 1320 MB | **Diff review** The descriptor checks covered PATCH with and without hull shaders and normalization of RECT_LIST and UNDEFINED. The software pipeline check confirmed that WARP accepted the fallback descriptors. **Not tested** Remaining workspace tests after the aborts, retail frame performance, and creation and rendering of the changed fallback pipelines on the AMD hardware. **AI use** Codex (GPT-6) merged and built the PR, ran the tests, compared the results with `main`, reviewed the diff, and drafted this report.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3371:upstream-pr/3371'
git switch 'upstream-pr/3371'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3371'
git switch 'upstream-pr/3371'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3371'
git switch 'upstream-pr/3371'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3371'
git switch 'main'
git merge --squash 'upstream-pr/3371'
git switch 'main'
git merge --ff-only 'upstream-pr/3371'
git switch 'main'
git merge 'upstream-pr/3371'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3371
No description provided.