d3d12_xs: rect-list pipelines from PSO streams: map console topology type 0x13 and expand the draws to full rects #280
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!280
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/280/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingLibrary / area:
d3d12_xs(mesh_pso.rstranslate_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.dll10.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_TOPOLOGYtype 0x13. The PC runtime accepts only types 1..4, so these pipelines were created with a type it rejects.Evidence:
CreateGraphicsPipelineStatevalidation checks the topology type of non-mesh pipelines witht <= 0x20 && bit t of 0x1_0008_001E(RVA0x7b16b..0x7b185, message 674 "Invalid primitive topology type."). Besides 1..4, it accepts 0x13 and 0x20.IASetPrimitiveTopologyaccepts the extra IA topologies 17..20. A table at RVA0x231960sends them to the hardware primitive types 0x11 (RECTLIST), 0x12 (LINELOOP), 0x13 (QUADLIST) and 0x14 (QUADSTRIP).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_streamrewrites type 0x13 toTRIANGLE(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.RECTLISTexpansion (rectlist.rs), which until now only worked for pipelines created from aD3D12_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,noperspectiveattributes are affine, flat ones come from v0).dbcount::note_stream_psoalready keeps the stream of every pipeline;rectlist::expand_streamapplies 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_statebinds 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_psotests: 0x13 is rewritten to 3; 0x20, 2 and 4 are unchanged in a VS/PS stream.rectlistCPU 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).cargo test -p d3d12_xs --lib warp_rectlist -- --ignored): the existing rect-list draw checks now also run on a pipeline created withCreatePipelineState: 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(withTOMBOX_REMOVED_EXIT_MS=off): 660 passed, 5 failed, 72 ignored. 4 of them fail onmainhere 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).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.
missingwith a note@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: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.
@GDAgent on GitHub · 2026-11-23 11:30 UTC · original
Agreed, mapping the type alone draws only half of each rect. I've pushed
025cc11on top: it reuses the existing rect-list expansion ind3d12_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.
noperspectiveattributes are affine, and flat ones are taken from v0. The variant is built from the stream thatdbcount::note_stream_psoalready 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 withcargo test -p d3d12_xs --lib warp_rectlist -- --ignored) builds the pipeline withCreatePipelineStateand 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 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-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.Pull request closed