d3d12_xs: rect-list pipelines from PSO streams: map console topology type 0x13 and expand the draws to full rects #280

Closed
GDAgent wants to merge 2 commits from upstream-pr/280 into main
GDAgent commented 2026-11-23 11:10:41 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T11:10:41Z.


Library / area: d3d12_xs (mesh_pso.rs translate_stream, rectlist.rs, cl2_state.rs, dbcount.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: the console debug D3D12 driver xgs12_10d.dll 10.0.22000.3160 (RVAs for that file), plus a logging run of The Matrix Awakens (Xbox Series X build).

Console PSO streams for rect-list pipelines carry PRIMITIVE_TOPOLOGY type 0x13. The PC runtime accepts only types 1..4, so these pipelines were created with a type it rejects.

Evidence:

  • Validator: CreateGraphicsPipelineState validation checks the topology type of non-mesh pipelines with t <= 0x20 && bit t of 0x1_0008_001E (RVA 0x7b16b..0x7b185, message 674 "Invalid primitive topology type."). Besides 1..4, it accepts 0x13 and 0x20.
  • IA topologies: IASetPrimitiveTopology accepts the extra IA topologies 17..20. A table at RVA 0x231960 sends them to the hardware primitive types 0x11 (RECTLIST), 0x12 (LINELOOP), 0x13 (QUADLIST) and 0x14 (QUADSTRIP).
  • Title run: a logging run (150 s) saw stream PSOs of console type 0x3 (44), 0x13 (27), 0x1 (2) and 0x2 (1). The title set IA topologies 4, 5, 1 and 17 (never 19 or 20). 24 of the 30 PSOs that the RECTLIST (17) draws were issued with were console type 0x13; the other 6 were not stream-built, so their type was not logged.

So type 0x13 is the rect-list pipeline type.

Changes:

  • translate_stream rewrites type 0x13 to TRIANGLE (3) in streams without a mesh shader and logs the first eight rewrites. Mesh streams keep the PSV0-derived topology (#176). Type 0x20 is also accepted by the console validator, but no title use of it has been seen, so it is passed through unchanged.
  • The rect draws themselves are expanded by the existing RECTLIST expansion (rectlist.rs), which until now only worked for pipelines created from a D3D12_GRAPHICS_PIPELINE_STATE_DESC. It binds a variant of the pipeline with a generated geometry shader that emits two triangles per rect, (v0, v1, v3) and (v0, v3, v2), with the fourth corner v3 = v1 + v2 - v0 in screen space (position and perspective attributes are interpolated through 1/w, noperspective attributes are affine, flat ones come from v0).
  • New: the same variant is built from a pipeline stream. dbcount::note_stream_pso already keeps the stream of every pipeline; rectlist::expand_stream applies the same refusal rules as the desc path (no vertex shader, an existing GS/HS/DS, stream output, a non-triangle topology type) plus mesh pipelines and view instancing, fills or appends the GS subobject, sets or appends the topology type subobject (TRIANGLE), and clears a cached pipeline blob. cl2_state binds it when topology 17 is set or a stream-built graphics pipeline is set while 17 is active, and rebinds the original pipeline when the topology changes. Occlusion counting replays (dbcount) of such draws get the expansion too.

Tests:

  • mesh_pso tests: 0x13 is rewritten to 3; 0x20, 2 and 4 are unchanged in a VS/PS stream.
  • rectlist CPU tests: the stream refusals, and the subobject edits (GS filled or appended, topology forced to 3, cached blob cleared, the result parses as a stream).
  • WARP test (cargo test -p d3d12_xs --lib warp_rectlist -- --ignored): the existing rect-list draw checks now also run on a pipeline created with CreatePipelineState: every pixel of the rect is compared with the expected perspective-correct UV (Draw w=1, DrawIndexed with w=(2,1.5,1.5), pipeline set after the topology, RSSetDepthBiasX while 17 is set, and a rect followed by a triangle-list draw that must not get a fourth corner). The stream case fails without the expansion change and passes with it.
  • cargo test -p d3d12_xs --lib -- --test-threads=1 (with TOMBOX_REMOVED_EXIT_MS=off): 660 passed, 5 failed, 72 ignored. 4 of them fail on main here as well (alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement, placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap, title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes, xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs); the fifth, dbcount::tests::translated_pixel_shaders_with_uavs_keep_their_source, fails now and then in a full single-threaded run (a pointer-keyed map sees an address reused from an earlier test) and passes on rerun (3 of 3).
  • Native Windows 11; not run under Proton.

Not verified in a title: the expansion is checked on WARP with a synthetic pipeline. A run of The Matrix Awakens with this change has not been done yet; the rect draws there are expected to be full rects now, but that is not confirmed.

  • Tests pass
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6557952416 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T11:10:41Z. --- **Library / area:** `d3d12_xs` (`mesh_pso.rs` `translate_stream`, `rectlist.rs`, `cl2_state.rs`, `dbcount.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** the console debug D3D12 driver `xgs12_10d.dll` 10.0.22000.3160 (RVAs for that file), plus a logging run of The Matrix Awakens (Xbox Series X build). Console PSO streams for rect-list pipelines carry `PRIMITIVE_TOPOLOGY` type **0x13**. The PC runtime accepts only types 1..4, so these pipelines were created with a type it rejects. Evidence: - **Validator:** `CreateGraphicsPipelineState` validation checks the topology type of non-mesh pipelines with `t <= 0x20 && bit t of 0x1_0008_001E` (RVA `0x7b16b..0x7b185`, message 674 "Invalid primitive topology type."). Besides 1..4, it accepts 0x13 and 0x20. - **IA topologies:** `IASetPrimitiveTopology` accepts the extra IA topologies 17..20. A table at RVA `0x231960` sends them to the hardware primitive types 0x11 (`RECTLIST`), 0x12 (`LINELOOP`), 0x13 (`QUADLIST`) and 0x14 (`QUADSTRIP`). - **Title run:** a logging run (150 s) saw stream PSOs of console type 0x3 (44), 0x13 (27), 0x1 (2) and 0x2 (1). The title set IA topologies 4, 5, 1 and 17 (never 19 or 20). 24 of the 30 PSOs that the `RECTLIST` (17) draws were issued with were console type 0x13; the other 6 were not stream-built, so their type was not logged. So type 0x13 is the rect-list pipeline type. Changes: - `translate_stream` rewrites type 0x13 to `TRIANGLE` (3) in streams without a mesh shader and logs the first eight rewrites. Mesh streams keep the PSV0-derived topology (#176). Type 0x20 is also accepted by the console validator, but no title use of it has been seen, so it is passed through unchanged. - The rect draws themselves are expanded by the existing `RECTLIST` expansion (`rectlist.rs`), which until now only worked for pipelines created from a `D3D12_GRAPHICS_PIPELINE_STATE_DESC`. It binds a variant of the pipeline with a generated geometry shader that emits two triangles per rect, (v0, v1, v3) and (v0, v3, v2), with the fourth corner v3 = v1 + v2 - v0 in screen space (position and perspective attributes are interpolated through 1/w, `noperspective` attributes are affine, flat ones come from v0). - New: the same variant is built from a pipeline stream. `dbcount::note_stream_pso` already keeps the stream of every pipeline; `rectlist::expand_stream` applies the same refusal rules as the desc path (no vertex shader, an existing GS/HS/DS, stream output, a non-triangle topology type) plus mesh pipelines and view instancing, fills or appends the GS subobject, sets or appends the topology type subobject (TRIANGLE), and clears a cached pipeline blob. `cl2_state` binds it when topology 17 is set or a stream-built graphics pipeline is set while 17 is active, and rebinds the original pipeline when the topology changes. Occlusion counting replays (`dbcount`) of such draws get the expansion too. Tests: - `mesh_pso` tests: 0x13 is rewritten to 3; 0x20, 2 and 4 are unchanged in a VS/PS stream. - `rectlist` CPU tests: the stream refusals, and the subobject edits (GS filled or appended, topology forced to 3, cached blob cleared, the result parses as a stream). - WARP test (`cargo test -p d3d12_xs --lib warp_rectlist -- --ignored`): the existing rect-list draw checks now also run on a pipeline created with `CreatePipelineState`: every pixel of the rect is compared with the expected perspective-correct UV (Draw w=1, DrawIndexed with w=(2,1.5,1.5), pipeline set after the topology, RSSetDepthBiasX while 17 is set, and a rect followed by a triangle-list draw that must not get a fourth corner). The stream case fails without the expansion change and passes with it. - `cargo test -p d3d12_xs --lib -- --test-threads=1` (with `TOMBOX_REMOVED_EXIT_MS=off`): 660 passed, 5 failed, 72 ignored. 4 of them fail on `main` here as well (`alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement`, `placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap`, `title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes`, `xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs`); the fifth, `dbcount::tests::translated_pixel_shaders_with_uavs_keep_their_source`, fails now and then in a full single-threaded run (a pointer-keyed map sees an address reused from an earlier test) and passes on rerun (3 of 3). - Native Windows 11; not run under Proton. **Not verified in a title:** the expansion is checked on WARP with a synthetic pipeline. A run of The Matrix Awakens with this change has not been done yet; the rect draws there are expected to be full rects now, but that is not confirmed. - [x] Tests pass - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
omonkeyz commented 2026-11-23 11:20:05 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T11:20:05Z.


Thanks. A rect list (0x13) can't be mapped to plain TRIANGLE: each rect gives 3 vertices and implies the 4th, so a triangle list draws only half of every rect. How is the 4th vertex produced in your path?

This needs a real expansion: in the mesh/amplification path, emit 2 triangles per rect with the 4th corner derived as v1 + v2 - v0 (or reuse an existing rect-list expansion in d3d12_xs, if there is one), plus a WARP test that checks the whole rect is covered. It can't be merged as plain TRIANGLE.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7099466092 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099466092). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T11:20:05Z. --- Thanks. A rect list (0x13) can't be mapped to plain TRIANGLE: each rect gives 3 vertices and implies the 4th, so a triangle list draws only half of every rect. How is the 4th vertex produced in your path? This needs a real expansion: in the mesh/amplification path, emit 2 triangles per rect with the 4th corner derived as v1 + v2 - v0 (or reuse an existing rect-list expansion in d3d12_xs, if there is one), plus a WARP test that checks the whole rect is covered. It can't be merged as plain TRIANGLE.
omonkeyz commented 2026-11-23 11:29:55 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T11:29:55Z.


Correction to my last comment: I had the layers mixed up. This change rewrites the PSO topology type, not the IA draw topology, and TRIANGLE is the right PSO type for rect-list pipelines on PC, so the rewrite stands as a PSO-type fix. The half-rect issue is the separate gap you already describe: rectlist.rs doesn't expand draws on stream-built PSOs yet. It goes through d3d12_xs tests here and then into a release.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7099720994 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099720994). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T11:29:55Z. --- Correction to my last comment: I had the layers mixed up. This change rewrites the PSO topology type, not the IA draw topology, and TRIANGLE is the right PSO type for rect-list pipelines on PC, so the rewrite stands as a PSO-type fix. The half-rect issue is the separate gap you already describe: rectlist.rs doesn't expand draws on stream-built PSOs yet. It goes through d3d12_xs tests here and then into a release.
GDAgent commented 2026-11-23 11:30:12 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T11:30:12Z.


Agreed, mapping the type alone draws only half of each rect. I've pushed 025cc11 on top: it reuses the existing rect-list expansion in d3d12_xs (rectlist.rs) for pipelines built from a stream, which it previously refused ("no recorded PC description").

How the fourth vertex is produced: while topology 17 is set, the pipeline is replaced by a variant with a generated geometry shader. For each rect (v0, v1, v2) it emits two triangles, (v0, v1, v3) and (v0, v3, v2), with v3 = v1 + v2 - v0 in screen space. Position and perspective-correct attributes go through 1/w, so the corner lands on the parallelogram on screen and stays on the attribute plane. noperspective attributes are affine, and flat ones are taken from v0. The variant is built from the stream that dbcount::note_stream_pso already keeps: the GS subobject is filled or appended, the topology type is set to TRIANGLE, and a cached pipeline blob is cleared. The original pipeline comes back when the topology changes.

This doesn't go through the mesh/amplification path. 0x13 is only rewritten in streams without a mesh shader; mesh streams keep the PSV0 topology from #176.

WARP test: warp_rectlist_topology_17_on_a_stream_built_pso_covers_all_four_corners (run with cargo test -p d3d12_xs --lib warp_rectlist -- --ignored) builds the pipeline with CreatePipelineState and compares every pixel of the rect with the expected perspective-correct UV, for Draw, DrawIndexed with uneven w, the pipeline set after the topology, RSSetDepthBiasX, and a rect followed by a triangle-list draw. It fails without the change and passes with it. Details are in the updated description. I haven't run it in a title yet.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7099727083 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099727083). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T11:30:12Z. --- Agreed, mapping the type alone draws only half of each rect. I've pushed `025cc11` on top: it reuses the existing rect-list expansion in `d3d12_xs` (`rectlist.rs`) for pipelines built from a stream, which it previously refused ("no recorded PC description"). How the fourth vertex is produced: while topology 17 is set, the pipeline is replaced by a variant with a generated geometry shader. For each rect (v0, v1, v2) it emits two triangles, (v0, v1, v3) and (v0, v3, v2), with v3 = v1 + v2 - v0 in screen space. Position and perspective-correct attributes go through 1/w, so the corner lands on the parallelogram on screen and stays on the attribute plane. `noperspective` attributes are affine, and flat ones are taken from v0. The variant is built from the stream that `dbcount::note_stream_pso` already keeps: the GS subobject is filled or appended, the topology type is set to TRIANGLE, and a cached pipeline blob is cleared. The original pipeline comes back when the topology changes. This doesn't go through the mesh/amplification path. 0x13 is only rewritten in streams without a mesh shader; mesh streams keep the PSV0 topology from #176. WARP test: `warp_rectlist_topology_17_on_a_stream_built_pso_covers_all_four_corners` (run with `cargo test -p d3d12_xs --lib warp_rectlist -- --ignored`) builds the pipeline with `CreatePipelineState` and compares every pixel of the rect with the expected perspective-correct UV, for Draw, DrawIndexed with uneven w, the pipeline set after the topology, RSSetDepthBiasX, and a rect followed by a triangle-list draw. It fails without the change and passes with it. Details are in the updated description. I haven't run it in a title yet.
omonkeyz commented 2026-11-23 13:45:31 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T13:45:31Z.


Applied locally on main with your authorship kept (cherry-picked, 2014b35); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7102985720 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7102985720). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T13:45:31Z. --- Applied locally on main with your authorship kept (cherry-picked, 2014b35); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.
omonkeyz commented 2026-11-25 13:09:41 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:09:41Z.


Applied on main in 2014b35 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7163377558 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7163377558). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:09:41Z. --- Applied on main in 2014b35 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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
omonkeyz/xbox-emulator!280
No description provided.