Skip to content

D3D12.X: rect lists drawn whole through a generated geometry shader - #199

Merged
ivall merged 6 commits into
ivall:mainfrom
Kalmarv:fix/rect-lists
Nov 23, 2026
Merged

ivall merged 6 commits into
ivall:mainfrom
Kalmarv:fix/rect-lists

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Closes #189. Based on main 956a476. Commits 9bd8908 (the change), ae8145d and 9ec1bfe (tests).

Problem

The console's rect lists (IASetPrimitiveTopology(17), AMD's DI_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)

  • AMD PAL, 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.
  • Mesa radeonsi (main 330203b), the driver for current AMD GPUs: si_draw_rectangle draws 3 vertices as SI_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.
  • xf86-video-ati r600_exa.c (R600Solid, R600AppendCopyVertex; DI_PT_RECTLIST in r6xx_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.
  • A retail title's full-screen passes, as reported downstream (see Credit): (−1,1) (−1,−1) (1,−1) with uv (0,0) (0,1) (1,1), so the corner is v1 and the implied one is (1,1) with uv (1,0).

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_pso adds 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:

    • integer VS outputs;
    • a PS that reads flat (an integer input or v_interp_mov_f32, pso::ps_reads_flat);
    • a PC PS.

    Which vertex gives a rect's flat values is not established.

Overlap with #162: standin_graphics now calls pc_topology_type, the same one-line change #162 makes. Whichever lands second drops its copy.

Relation to #195

#195 expands non-indexed DrawInstanced rect lists on the CPU (bind::draw_rects: v0 v1 v2, then v0 v2 v3). If both land as they are, two things go wrong:

  • Double draw. A pipeline that has this GS would get both. The second CPU triangle is three corners of the same rect, so the GS completes it to the whole rect too (gpu_rect_list_fullscreen_order checks this). Each rect would then be drawn twice: the same picture when opaque, wrong with blending.
  • No GS on stream pipelines. Retail game shows its first menus: depth views, buffers outside unified memory, rect lists #195's pc_stream_types rewrites the stream's type 19 to 3 before stream_pipeline reads 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_f32 is detected; v_interp_p1/p2 is 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:

    • corners at v0 (radeonsi order), v1 (r600 order) and v2 each cover the rectangle, with the attribute (the vertex's NDC) equal to the pixel's NDC everywhere, the implied corner's quarter included;
    • without the GS (today's form), part of the rectangle stays clear;
    • a non-rectangle triangle and an unequal-w one draw the same with and without the GS.
  • gpu_rect_list_fullscreen_order (GPU), plain HLSL VS/PS around the GS:

    • the downstream full-screen order covers every pixel with its uv, at w 1 and 2;
    • without the GS, about half the pixels are drawn;
    • the CPU expansion's second triangle (v0, v2, v3) is completed to the whole rect as well.
  • 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):

    • this branch (9ec1bfe): 573 passed, 0 failed, 39 ignored, in each of three runs;
    • main (956a476): 569 passed in each of three runs; the difference is the four new tests;
    • two wave64 tests skip on this GPU, which has no 64-lane waves, on both.

    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

  • Mesh/NGG and console-GS pipelines that draw rect lists.
  • Three vertices with unequal w; whether the hardware reconstructs those is not established.
  • Rects with flat attributes (refused, see above).
  • How the console culls a rect (the GS keeps the first triangle's winding).
  • TwoDRectList.
  • No game was run with this change.

Open points from an independent review (follow-up commit coming)

  • If the driver rejects the pipeline with the generated GS, there is no retry without it, so the rect would draw nothing instead of half (translated_graphics_pso). I'll add one retry with GS cleared.
  • A stream pipeline of type 19 whose VS is a PC shader now reaches the untranslated fallback still as type 19, where main had already mapped it to TRIANGLE. I'll normalise it there.

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 added a commit to Kalmarv/xcl that referenced this pull request Nov 23, 2026
…stream rect lists

From the review of ivall#199:
- translated_graphics_pso: when the driver refuses a pipeline with the
  generated rect list GS, it is made once more without it
  (retry_without_rect_gs) and a note is logged, so each rect is drawn as
  its first triangle, as before, rather than by the dummy shaders.
- A stream pipeline of type 19 that is not translated (HS/DS, a
  translation error) gets the PC's topology type before the driver sees it
  (untranslated_stream_desc), as at 956a476, where the stream path mapped
  it. dev_create_graphics_pso's body is now graphics_pso, with a flag
  for descs from a stream; a direct CreateGraphicsPipelineState is
  unchanged.
- rect_list_gs compares clip-space x and y directly: w is one already.

Tests (CPU): a_refused_rect_list_gs_is_retried_without_it (injected
refusal), untranslated_stream_rect_lists_get_the_pcs_topology_type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

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) and untranslated_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_corners and gpu_rect_list_fullscreen_order also 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

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

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 added a commit to Kalmarv/xcl that referenced this pull request Nov 23, 2026
…stream rect lists

From the review of ivall#199:
- translated_graphics_pso: when the driver refuses a pipeline with the
  generated rect list GS, it is made once more without it
  (retry_without_rect_gs) and a note is logged, so each rect is drawn as
  its first triangle, as before, rather than by the dummy shaders.
- A stream pipeline of type 19 that is not translated (HS/DS, a
  translation error) gets the PC's topology type before the driver sees it
  (untranslated_stream_desc), as at 956a476, where the stream path mapped
  it. dev_create_graphics_pso's body is now graphics_pso, with a flag
  for descs from a stream; a direct CreateGraphicsPipelineState is
  unchanged.
- rect_list_gs compares clip-space x and y directly: w is one already.

Tests (CPU): a_refused_rect_list_gs_is_retried_without_it (injected
refusal), untranslated_stream_rect_lists_get_the_pcs_topology_type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main eaa36b6 and force-pushed: head 287d67a, the five earlier commits plus one new one.

What main changed: 38b05b7 brought #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_order shows the second half being completed). The new commit 287d67a makes draw_rects skip a pipeline that has the GS: real::has_rect_list_gs is checked on the resolved pipeline. The CPU expansion still handles rect lists on the pipelines the GS refuses. Its test is rect_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_graphics calls pc_topology_type, the same one-line change.

On the corner rule (#189): the GS does not assume v0 + v2 − v1.

  • It takes the clip-space x and y of the three vertices, which share one positive w. The corner is the vertex k whose x equals one other vertex's x and whose y equals the third's (an exact compare). The fourth vertex is d = a + b − k, for the position and for every output.
  • v0 + v2 − v1 is the case k = v1. That is the order of the R600 EXA driver and of the retail full-screen pass reported downstream. Mesa radeonsi's blits put the corner at v0 (d = v1 + v2 − v0). With that order, main's draw_rects would make (x2, 2·y1 − y2) instead of (x2, y2).
  • Three vertices that aren't such corners, or that differ in w, stay the one triangle they make.
  • How the console's hardware picks the corner for an arbitrary order hasn't been measured. PAL only says "three 2D axis-aligned rectangle vertices", and the drivers' own orders differ, so the GS follows the positions.
  • The provoking vertex isn't established either. The GS refuses pipelines whose VS has integer outputs or whose PS reads flat; they keep the single triangle, and now draw_rects covers 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.
  • CPU tests: the generator, flat detection, the no-GS retry, untranslated stream rect lists, has_rect_list_gs, and the draw_rects skip.
  • On 287d67a the six rect CPU tests pass. The full cargo test --lib, with the GPU tests, on the RTX 5070 Ti follows.

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Main still has bind::draw_rects from #195. Once this is rebased on main (6da33fa) with the has_rect_list_gs check in draw_rects, I will run it on an RX 9070 together with the retail game's menu.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Full run on the RTX 5070 Ti (NVIDIA 610.74), cargo test -p xcl --lib -- --test-threads=2 at 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 main 6da33fa without conflicts.

AI use: Claude Code, Claude Opus 5.5.

Kalmarv and others added 6 commits November 23, 2026 16:12
The console's rect lists (IASetPrimitiveTopology 17, AMD's DI_PT_RECTLIST;
pipeline topology type 19) were drawn as triangle lists: each rect as the
triangle of its three vertices, half of it. A translated VS+PS pipeline of
topology type 19 now gets a pass-through GS (emit::rect_list_gs, declared
from the VS's own output struct) that adds the fourth corner.

The three vertices are corners of a screen-aligned rectangle (AMD PAL
palCmdBuffer.h: "Each rect is three 2D axis-aligned rectangle vertices"),
and the corner between the other two is not always v0: Mesa radeonsi's
blits send (x1,y1), (x1,y2), (x2,y1), xf86-video-ati's r600 EXA (x1,y1),
(x1,y2), (x2,y2). The corner is the vertex sharing x with one of the others
and y with the other; the fourth vertex is a + b - corner, its outputs
likewise (both drivers' texture coordinates rely on that).

Bounded to what is established: three vertices with one positive w (then
clip and screen space agree and so do the interpolation modes); others stay
one triangle. Refused, keeping the old triangle form: integer VS outputs, a
PS that reads flat (an integer input or v_interp_mov_f32), a PC PS - which
vertex gives a rect's flat values is not established. The stream path keeps
type 19 for the translated pipeline; the graphics stand-in maps it.

Tests: rect_list_gs_outputs, rect_list_ps_reads_flat (CPU);
gpu_rect_list_corners: corners at v0, v1, v2 cover the rect with the
attribute linear everywhere, part stays clear without the GS, and a
non-rectangle or unequal-w triangle draws the same with and without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gpu_rect_list_fullscreen_order draws the three corners a downstream build
(theaustinayers/xcl build 5, linked in ivall#189) reports from a retail title's
full-screen passes: positions (-1,1) (-1,-1) (1,-1), texture coordinates
(0,0) (0,1) (1,1), so the shared corner is v1 and the implied one is (1,1)
with (1,0). Plain HLSL VS/PS around emit::rect_list_gs on a 16x16 target:
every pixel must carry its texture coordinate, for w 1 and 2; without the
GS (the negative control) only about half the pixels are drawn.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ted too

gpu_rect_list_fullscreen_order also draws the other half of the full-screen
rect as a triangle: v0, v2 and the implied corner, what a draw expanded to
two triangles a rect on the CPU sends next (ivall#195). Those are three corners
of the same rect, so the GS completes it to the whole rect as well. A draw
expanded on the CPU must therefore not also get this GS, or each rect is
drawn twice (the same image when opaque, wrong with blending).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…stream rect lists

From the review of ivall#199:
- translated_graphics_pso: when the driver refuses a pipeline with the
  generated rect list GS, it is made once more without it
  (retry_without_rect_gs) and a note is logged, so each rect is drawn as
  its first triangle, as before, rather than by the dummy shaders.
- A stream pipeline of type 19 that is not translated (HS/DS, a
  translation error) gets the PC's topology type before the driver sees it
  (untranslated_stream_desc), as at 956a476, where the stream path mapped
  it. dev_create_graphics_pso's body is now graphics_pso, with a flag
  for descs from a stream; a direct CreateGraphicsPipelineState is
  unchanged.
- rect_list_gs compares clip-space x and y directly: w is one already.

Tests (CPU): a_refused_rect_list_gs_is_retried_without_it (injected
refusal), untranslated_stream_rect_lists_get_the_pcs_topology_type.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
For ivall#195, which expands rect lists to two triangles a rect on the CPU: a
draw on a pipeline that has the GS must not be expanded too, since each
half is three corners of the rect and the GS would complete both.
has_rect_list_gs(pso) answers that, for a pipeline as is_translated_graphics
takes it. A pipeline made again without the GS (retry_without_rect_gs) is not
noted, and forget_pso drops the entry with the pipeline's address.

Test (CPU): pipelines_with_the_rect_list_gs_are_known_until_forgotten.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Main expands a DrawInstanced of a rect list on the CPU (bind::draw_rects,
from ivall#195): v0 v1 v2, then v0 v2 v3. On a pipeline with the rect list GS
each of those halves is three corners of the rect, so the GS completed
both and every rect was drawn twice (gpu_rect_list_fullscreen_order shows
the second half completed). draw_rects now leaves a pipeline with the GS
alone (cpu_rect_expansion: real::has_rect_list_gs of the resolved
pipeline); it still expands rect lists on the pipelines the GS refuses.

Test (CPU): rect_lists_with_the_rect_list_gs_are_not_expanded_on_the_cpu.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on main 6da33fa: head 7ac4048. The has_rect_list_gs check in draw_rects is the top commit, 7ac4048 "Rect lists: no CPU expansion for a pipeline with the rect list GS" (it was 287d67a on eaa36b6). Its test is rect_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, including gpu_rect_list_corners, gpu_rect_list_fullscreen_order and the draw_rects skip. The full lib run (556 passed, 0 failed) was on 287d67a, the same patches on eaa36b6.

AI use: Claude Code, Claude Opus 5.5.

@ivall
ivall merged commit f0a917b into ivall:main Nov 23, 2026
1 check passed
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Merged (main d4f17ca). Checked on an RX 9070 (RDNA4) with 11 PRs merged together on main af20b4b: 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). With draw_rects skipping pipelines that have the rect list GS, as you added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rect-list expansion for VS+PS pipelines

2 participants