D3D12.X: rect lists drawn whole through a generated geometry shader #199
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!199
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/199/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?
@Kalmarv on GitHub · 2026-11-23 20:28 UTC · original
Kalmarv:fix/rect-lists→main· +471 −8 · 7 files · 6 commits · merged 2026-11-23 21:24 UTCCloses #189. Based on main
956a476. Commits 9bd8908 (the change), ae8145d and 9ec1bfe (tests).Problem
The console's rect lists (
IASetPrimitiveTopology(17), AMD'sDI_PT_RECTLIST; pipeline topology type 19) are drawn as triangle lists (list_x.rs,real.rs::pc_topology_type). Each rect is drawn as the triangle of its three vertices, so only half of it appears. HANDOFF lists this as open.What a rect list is (sources)
inc/core/palCmdBuffer.h:RectList = 0x5, ///< Each rect is three 2D axis-aligned rectangle vertices.The bounding box of an arbitrary triangle is a separate, optional topology,TwoDRectList.330203b), the driver for current AMD GPUs:si_draw_rectangledraws 3 vertices asSI_PRIM_RECTANGLE_LIST→V_008958_DI_PT_RECTLIST.gfx/si_nir_lower_vs_inputs.c(load_vs_input_from_blit_sgpr) gives vertex 0 = (x1,y1), 1 = (x1,y2), 2 = (x2,y1), so the shared corner is v0. Texture coordinates use the same selectors.r600_exa.c(R600Solid,R600AppendCopyVertex;DI_PT_RECTLISTinr6xx_accel.c) is older-generation (R600) evidence: v0 = (x1,y1), v1 = (x1,y2), v2 = (x2,y2), so the corner is v1. The copy's source coordinates at the implied corner are v0 + v2 − v1.So the corner between the other two is not a fixed vertex. The fourth vertex completes the axis-aligned rectangle, and the drivers rely on attributes continuing linearly to it. These semantics come from how AMD's drivers (PAL, Mesa, R600) use the topology. They were not measured on RDNA2 hardware.
Change
emit::rect_list_gs(outputs)generates a pass-through GS that declares the VS's own output struct (out_struct). It appends v0..v2 unchanged. When the three vertices have one equal positive clip w and one vertex shares x with one neighbour and y with the other (exact compare), it also emits a second triangle with d = a + b − corner for the position and every output, keeping the first triangle's winding. Any other three vertices stay the one triangle they make, as before. With equal w, clip and screen space agree, so every interpolation mode agrees too.pso::rect_list_gs(vs)builds it from the console VS's output signature, the list the translated VS's struct is declared from.real.rs::translated_graphics_psoadds it to a translated VS+PS pipeline of topology type 19 that has no GS. The GS sees the VS's outputs, so indexed draws and rects made from the vertex index alone are covered too. The stream path keeps type 19 for console-VS pipelines so that the translated path sees it.Refused, keeping today's triangle form plus a translation note:
v_interp_mov_f32,pso::ps_reads_flat);Which vertex gives a rect's flat values is not established.
Overlap with #162:
standin_graphicsnow callspc_topology_type, the same one-line change #162 makes. Whichever lands second drops its copy.Relation to #195
#195 expands non-indexed
DrawInstancedrect lists on the CPU (bind::draw_rects: v0 v1 v2, then v0 v2 v3). If both land as they are, two things go wrong:gpu_rect_list_fullscreen_orderchecks this). Each rect would then be drawn twice: the same picture when opaque, wrong with blending.pc_stream_typesrewrites the stream's type 19 to 3 beforestream_pipelinereads it, so stream pipelines would never get the GS.Proposed split: the GS where a pipeline has one. The CPU expansion only for rect-list draws on pipelines without it, the refused cases. Type 19 left in the stream for
translated_graphics_pso. The two branches merge without textual conflicts, and the four rect tests below pass on the merge (bf26412+ this branch). I'll rebase on whichever lands first.Tests
rect_list_gs_outputs(CPU): integer outputs are refused; the HLSL compiles with DXC as gs_6_6.rect_list_ps_reads_flat(CPU):v_interp_mov_f32is detected;v_interp_p1/p2is not flagged.gpu_rect_list_corners(GPU), with a translated VS+PS through the GS on a 16×16 target, per pixel within 1e-5:gpu_rect_list_fullscreen_order(GPU), plain HLSL VS/PS around the GS:On an RTX 5070 Ti (NVIDIA 610.74, Windows 11), the GPU tests and both CPU tests pass. Two mutations fail
gpu_rect_list_corners: the GS without the fourth corner, and the fourth corner without attribute extrapolation.The expected images are the rectangles and triangles defined above. They are not a hardware measurement, and nothing was run on AMD.
Workspace suite (
cargo test --workspace --no-fail-fast -- --test-threads=2, RTX 5070 Ti):956a476): 569 passed in each of three runs; the difference is the four new tests;One earlier run on this branch failed
hle::d3d12x::frame::tests::statistics_name_each_frames_origin_and_rescheduled_handles_outlive_the_clock_tick, with "each frame its own origin": the third frame's origin came 93 ticks before the second's. That is a timing test in a file this branch doesn't touch, and it passed in the other five runs here. It didn't fail on main in three suite runs or 25 runs of its own, so I couldn't show it fails there.Not covered
TwoDRectList.Open points from an independent review (follow-up commit coming)
translated_graphics_pso). I'll add one retry withGScleared.Credit
The full-screen corner order and the uvs come from theaustinayers' downstream build 5 (theaustinayers/xcl 73bd45a, "rect lists drawn as two triangles", now part of #195). YeetSkillet linked it in #189 and checked that order with a native D3D12 probe. No code was taken from it: the approaches differ (a CPU expansion of the vertex buffer there, a GS behind the translated VS here).
AI-assisted (Claude Code). No game data.
🤖 Generated with Claude Code
@Kalmarv on GitHub · 2026-11-23 20:32 UTC · original
The review's two follow-ups are in 4bbcf98. A pipeline the driver refuses with the generated GS is now retried once without it and logs a note, so each rect is drawn as its first triangle again instead of by the dummy shaders. Untranslated type-19 stream pipelines get TRIANGLE before they reach the driver, as on main. The corner test now compares clip-space x and y directly.
New CPU tests:
a_refused_rect_list_gs_is_retried_without_it(an injected refusal) anduntranslated_stream_rect_lists_get_the_pcs_topology_type. Each one fails when its fix is removed. On an RTX 5070 Ti, the 6 rect tests pass and the xcl lib tests give 542 passed, 0 failed.Second hardware, from an independent run at ae8145d:
gpu_rect_list_cornersandgpu_rect_list_fullscreen_orderalso pass on an RTX 2060 (NVIDIA 595.91.07, Linux, Wine 11.21 Staging + vkd3d-proton 30b0eb9 + DXVK 3.1.1), with the device found, nothing skipped and the without-GS controls holding.@ivall on GitHub · 2026-11-23 20:57 UTC · original
Main now draws rect lists through the CPU expansion from #195 (
bind::draw_rects: the fourth corner made on the CPU, vertex-buffer draws only). This would replace that with a generated GS, which also covers vertices a shader makes from the vertex index. It needs a rebase on main, and I can run it on an AMD card (RX 9070) after that.@Kalmarv on GitHub · 2026-11-23 21:03 UTC · original
Rebased on main
eaa36b6and force-pushed: head 287d67a, the five earlier commits plus one new one.What main changed:
38b05b7brought #195's CPU rect expansion (bind::draw_rects: v0 v1 v2, then v0 v2 v3). On a pipeline with this PR's GS, each of those halves is three corners of the rect too, so the GS completed both and every rect would have been drawn twice (gpu_rect_list_fullscreen_ordershows the second half being completed). The new commit 287d67a makesdraw_rectsskip a pipeline that has the GS:real::has_rect_list_gsis checked on the resolved pipeline. The CPU expansion still handles rect lists on the pipelines the GS refuses. Its test isrect_lists_with_the_rect_list_gs_are_not_expanded_on_the_cpu.Overlaps: #195's
draw_rects, now on main, as above. And #162:standin_graphicscallspc_topology_type, the same one-line change.On the corner rule (#189): the GS does not assume v0 + v2 − v1.
draw_rectswould make (x2, 2·y1 − y2) instead of (x2, y2).draw_rectscovers them.Tests:
gpu_rect_list_corners: the corner at v0, v1 and v2. Coverage and the interpolated attribute are checked at every pixel, a no-GS control draws part of the rect, and non-rect and unequal-w triangles are left alone.gpu_rect_list_fullscreen_order: the downstream order at w 1 and 2, plus the CPU expansion's second half.has_rect_list_gs, and thedraw_rectsskip.cargo test --lib, with the GPU tests, on the RTX 5070 Ti follows.@ivall on GitHub · 2026-11-23 21:09 UTC · original
Main still has
bind::draw_rectsfrom #195. Once this is rebased on main (6da33fa) with thehas_rect_list_gscheck indraw_rects, I will run it on an RX 9070 together with the retail game's menu.@Kalmarv on GitHub · 2026-11-23 21:09 UTC · original
Full run on the RTX 5070 Ti (NVIDIA 610.74),
cargo test -p xcl --lib -- --test-threads=2at 287d67a: 556 passed, 0 failed, 19 ignored; 2 wave64 tests skip (no 64-lane waves on this GPU). Both GPU rect tests (gpu_rect_list_corners,gpu_rect_list_fullscreen_order) and the 6 CPU rect tests pass. It merges onto main6da33fawithout conflicts.AI use: Claude Code, Claude Opus 5.5.
@Kalmarv on GitHub · 2026-11-23 21:12 UTC · original
Rebased on main
6da33fa: head7ac4048. Thehas_rect_list_gscheck indraw_rectsis the top commit,7ac4048"Rect lists: no CPU expansion for a pipeline with the rect list GS" (it was 287d67a oneaa36b6). Its test isrect_lists_with_the_rect_list_gs_are_not_expanded_on_the_cpu.On
7ac4048, RTX 5070 Ti (NVIDIA 610.74),cargo test --release -p xcl --lib rect -- --test-threads=1: 17 passed, includinggpu_rect_list_corners,gpu_rect_list_fullscreen_orderand thedraw_rectsskip. The full lib run (556 passed, 0 failed) was on 287d67a, the same patches oneaa36b6.AI use: Claude Code, Claude Opus 5.5.
@ivall on GitHub · 2026-11-23 21:24 UTC · original
Merged (main
d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on mainaf20b4b:cargo build --workspace && cargo test --workspace -- --test-threads=4- 605 unit tests passed, 0 failed (20 ignored), the integration and e2e tests passed; and the retail game still reaches its first menu at 30 fps (720 draws per 2 s). Withdraw_rectsskipping pipelines that have the rect list GS, as you added.mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175