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

Closed
github-bot wants to merge 2 commits from gh-pr/280/head into gh-pr/280/base
Owner

@⁠GDAgent on GitHub · 2026-11-23 11:10 UTC · original
GDAgent:fix/d3d12-pso-topology-quad-rect → main · +328 −26 · 5 files · 2 commits · closed without merging

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
**@⁠GDAgent** on GitHub · 2026-11-23 11:10 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280) `GDAgent:fix/d3d12-pso-topology-quad-rect` → `main` · +328 −26 · 5 files · 2 commits · closed without merging **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
Console PSO streams for rect-list pipelines carry PRIMITIVE_TOPOLOGY
type 0x13. The PC runtime only accepts types 1..4, so these pipelines
were created with a type it rejects.

Evidence:
- The console debug D3D12 driver (xgs12_10d.dll 10.0.22000.3160)
  validates CreateGraphicsPipelineState topology types for 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. Its IASetPrimitiveTopology
  accepts the extra IA topologies 17..20, which its table at RVA
  0x231960 sends to the hardware primitive types 0x11 (RECTLIST),
  0x12 (LINELOOP), 0x13 (QUADLIST) and 0x14 (QUADSTRIP).
- In The Matrix Awakens (Xbox Series X build) a logging run 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), and 24 of
  the 30 PSOs that 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. translate_stream now
rewrites it to TRIANGLE (3) in streams without a mesh shader, the type
the existing RECTLIST expansion also gives its pipelines, and logs the
first eight rewrites. Mesh streams keep the PSV0-derived topology
(#176). Type 0x20 is accepted by the console validator too, but no
title use of it has been seen, so it is passed through unchanged.

Test: mesh_pso tests cover 0x13 (rewritten to 3) and 0x20, 2 and 4
(unchanged) in a VS/PS stream.
A rect-list draw (topology 17) is expanded by binding a variant of the
current pipeline with a generated geometry shader that emits the fourth
corner. Until now only pipelines created from a
D3D12_GRAPHICS_PIPELINE_STATE_DESC had a recorded description to build
that variant from. Pipelines created through CreatePipelineState (a
subobject stream) were refused with "no recorded PC description", so each
rect drew only its first triangle.

The stream of every pipeline is already kept by dbcount::note_stream_pso.
rectlist::expand_stream builds the variant from it: the same refusal rules
as the desc path (no vertex shader, an existing GS/HS/DS, stream output,
non-triangle topology type), plus mesh pipelines and view instancing; the
GS subobject is filled or appended, the primitive topology type subobject
is set to TRIANGLE (or appended), and a cached pipeline blob is cleared
because it cannot match the new pipeline. cl2_state binds the variant when
topology 17 is set or a stream-built graphics pipeline is set while it is
active, and rebinds the original pipeline when the topology changes.
Setting a stream-built graphics pipeline now also clears the
"variant bound" flag, as setting a desc-built one already did.

Occlusion counting replays (dbcount) of a rect draw on a stream-built
pipeline now get the rect expansion in their stream variants too.

Tests: CPU tests for the stream refusals and the subobject edits; the WARP
rect-list test now runs its draw checks (Draw, DrawIndexed with
perspective, pipeline set after the topology, RSSetDepthBiasX, rect then
triangle list) against a stream-built pipeline as well. That test fails
without this change and passes with it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:17:06 +00:00
github-bot closed this pull request 2026-11-26 06:17:06 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 11:20 UTC · original

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** on GitHub · 2026-11-23 11:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099466092) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 11:29 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-23 11:29 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099720994) 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.
Author
Owner

@⁠GDAgent on GitHub · 2026-11-23 11:30 UTC · original

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.

**@⁠GDAgent** on GitHub · 2026-11-23 11:30 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7099727083) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 13:45 UTC · original

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** on GitHub · 2026-11-23 13:45 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7102985720) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:09 UTC · original

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/280#issuecomment-7163377558) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.