Skip to content

Rect lists: the CPU expansion finds the rect's corner, not always v1 - #266

Open
Kalmarv wants to merge 1 commit into
ivall:mainfrom
Kalmarv:fix/rect-list-cpu-corner
Open

Kalmarv wants to merge 1 commit into
ivall:mainfrom
Kalmarv:fix/rect-list-cpu-corner

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The CPU expansion of rect lists (#195) makes every rect's fourth corner as v0 + v2 − v1. On #189 (closed) the question was whether that holds for every vertex order. It does not: it is right when the rect's corner (the vertex between the other two) is v1, and for a rect with its corner at v0 it puts the fourth vertex outside the rect, at (x2, 2·y1 − y2). This PR finds the corner first.

Both orders are in use on AMD hardware:

order corner who sends it
(x1,y1) (x1,y2) (x2,y1) v0 Mesa r600 r600_draw_rectangle ("The hw rectangle has only 3 vertices, The 4th one is derived from the first 3"); Mesa radeonsi's blit VS, from the vertex index (load_vs_input_from_blit_sgpr); radv's meta passes (nir_gen_rect_vertices)
(x1,y1) (x1,y2) (x2,y2) v1 xf86-video-ati's r600 EXA (r600_exa.c, drawn as DI_PT_RECTLIST in r6xx_accel.c); the full-screen passes draw_rects was written from

The two r600 drivers run on the same chips, so the hardware does not take a fixed vertex as the corner. The rect list GS (#199) already finds the corner from the positions; only the CPU path assumed v1. Both drivers were read for the vertex orders; no code is taken from them.

What is in it

  • crates/xcl/src/hle/d3d12x/bind.rs, rect_corner: which of a rect's three vertices is the corner. The expansion still does not look at the vertex layout, so it goes by words: in a word two vertices share (an x or a y, and a texture coordinate that follows it) the third vertex is the far end of an edge, and the corner is the vertex that differs alone in the fewest words. No single such vertex (not three corners of a screen-aligned rect): v1, so those draws are expanded as before.
  • bind.rs, expand_rect: the fourth corner is a + b − corner, word by word as before (a word equal in all three vertices is kept). Both triangles start with v0 and keep the winding of v0 v1 v2. For a rect with its corner at v1 the six vertices are exactly the ones main makes.
  • bind.rs, draw_rects calls it; nothing else there changes. This path only runs for a rect list pipeline without the rect list GS, for DrawInstanced with vertex buffers.
  • bind.rs, test rects_expanded_on_the_cpu_have_the_corner_opposite_their_own. +126/−17 in all, about 55 of them the test.

Overlap: #215 edits draw_instanced three lines below draw_rects and already conflicts with main in bind.rs. #214 and #187 change one line each in bind.rs, elsewhere. No open PR or issue is about rect lists.

Tested

  • NVIDIA GeForce RTX 5070 Ti, driver 610.74; Ryzen 9 9950X; Windows 11 (10.0.26200); rustc 1.99.0; debug. Head e30794d, one commit on main 9ab7d76.
  • cargo test --workspace -- --test-threads=4: 652 passed, 0 failed, 40 ignored (the xcl library: 612 passed, 20 ignored). SKIPPED GPU tests: 2, both no wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware).
  • cargo test -p xcl --lib -- hle::d3d12x::bind::tests::rect: 2 passed, 0 failed (no GPU needed).
  • The new test, for the corner at v0, at v1 in both directions, and at v2: the six vertices are the rect's four corners, the two triangles are its halves along one diagonal, both wind as v0 v1 v2 and start with v0, the fourth corner's texture coordinate continues the others, and z, w and a packed colour are kept. Three vertices that are not rect corners give v0 + v2 − v1 as before.
  • It fails with main's rule: with the corner fixed at v1 it stops at corner v0: no vertex at [48.0, 24.0] in [[16.0, 8.0], [16.0, 24.0], [48.0, 8.0], [16.0, 8.0], [48.0, 8.0], [48.0, -8.0]]. main has this arithmetic inline in draw_rects, where a test cannot call it.
  • The expansion drawn on the GPU (a scratch test, not in the PR, same expand_rect): for each of the four orders 0 of 256 pixels wrong (rect covered, texture coordinate right), 36 wrong when only the three vertices are drawn.

Regression run

Run by @theaustinayers on a retail title (Ryzen 9 9950X3D, RTX 5090; the gpu: line names the integrated GPU, XCL ran on the 5090), comment. One 60 s run each, no input.

main:

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: AMD Radeon(TM) Graphics
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1078 (PresentX 1079)
presents per 2 s (last 3): 60 60 34
device removals: 0
crashes: 0
peak commit: 18216 MB

PR:

xcl-smoke v1
commit: e30794d41bf4ba75f68cfcb2894c40b1ba0cd81f
gpu: AMD Radeon(TM) Graphics
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1060 (PresentX 1060)
presents per 2 s (last 3): 60 32 8
device removals: 0
crashes: 0
peak commit: 18515 MB

The title's first screens draw rect lists through draw_rects with the corner at v1, so the changed function runs; no rect with its corner at v0 is known in it. The PR's run has 18 fewer frames (1060 against 1078, 1.7 %) and 299 MB more peak commit; with one run each and the title starting to stream near the end of the 60 s, that is not separated from run-to-run variation.

Not tested

  • The new corner-at-v0 branch on a real title: the regression run reaches only corner-v1 rects. Repeated smoke runs to separate the frame and commit difference from noise.
  • No console: the rect is the expectation, not a measurement of hardware. AMD's public register references (R6xx, SI, CIK) only name the primitive (17 - DI_PT_RECTLIST: Rect List); they do not say how the fourth vertex is derived.
  • draw_rects itself (a console command list, title vertex buffers, the upload memory) has no test, as on main; only the expansion it calls does.
  • The corner is found from words, not from the input layout. An attribute in which the corner alone differs from the other two vertices can make it a tie, and then the corner is taken as v1, as before this PR.
  • Still not expanded, as on main: indexed rect list draws, ExecuteIndirect, and vertices made from the vertex index alone, in pipelines without the GS. They draw half of each rect.
  • AMD and Intel GPUs.

AI use

  • Claude Code (Claude Fable 5.2): code, tests, sources and this description

draw_rects made every rect's fourth corner as v0 + v2 - v1, which is right
when the rect's corner (the vertex between the other two) is v1. Rects are
also sent with it at v0 - (x1,y1) (x1,y2) (x2,y1), as Mesa's r600 and
radeonsi blits do - and then the fourth vertex landed outside the rect, at
(x2, 2*y1 - y2).

The corner is now found from the vertices (the one that differs alone in
the fewest words; v1 when there is no single one, as before), and the
fourth corner is a + b - corner. Both triangles start with v0 and keep the
winding of v0 v1 v2. For a rect with its corner at v1 the six vertices are
the ones made before.

Assisted-by: Claude Code (Claude Fable 5.2)
Co-Authored-By: Claude <noreply@anthropic.com>
@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Regression run wanted. We have no title on our machine. If you can run scripts/smoke.ps1 -Game <your title folder> twice, once built from main (9ab7d76) and once from this PR's head (e30794d), please paste both xcl-smoke blocks here. I'll copy them into the description under Regression run, with your name and hardware.

🤖 Claude Opus 5.5

theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 23, 2026
…ect's corner

Their work, merged as it is. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@theaustinayers

Copy link
Copy Markdown
Collaborator

Regression run on a retail title, as asked. Both blocks are the unedited output of scripts/smoke.ps1 -Game <folder> (60 s, release builds, no uncommitted changes), run one after the other on the same machine.

Hardware: Ryzen 9 9950X3D, NVIDIA GeForce RTX 5090 (32 GB), Windows 11 Pro 26300, Rust 1.100.0.

Note on the gpu: line: the script prints the first Win32_VideoController, which on this PC is the CPU's integrated graphics. XCL itself ran on the RTX 5090 in both runs (D3D12.X: backend 'real' – NVIDIA GeForce RTX 5090 (32187 MiB VRAM) in the log). I left the blocks as the script wrote them.

main (9ab7d76):

xcl-smoke v1
commit: 9ab7d763197c7f420bff10cd9bf1310f07e2a9aa
gpu: AMD Radeon(TM) Graphics
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1078 (PresentX 1079)
presents per 2 s (last 3): 60 60 34
device removals: 0
crashes: 0
peak commit: 18216 MB

this PR's head (e30794d):

xcl-smoke v1
commit: e30794d41bf4ba75f68cfcb2894c40b1ba0cd81f
gpu: AMD Radeon(TM) Graphics
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1060 (PresentX 1060)
presents per 2 s (last 3): 60 32 8
device removals: 0
crashes: 0
peak commit: 18515 MB

What it covers: the title's first screens draw their full-screen passes as rect lists through draw_rects (corner at v1), so the changed code runs. No device removal and no crash in either run.

What it does not show: the PR's run has 18 fewer frames (1060 vs 1078) and 299 MB more peak commit. One run each, with no input, so I cannot say whether that is the change or run-to-run variation; the title starts streaming near the end of the 60 s, which is where the last "presents per 2 s" figures differ. I did not compare the picture between the two runs, and this title has no rect with its corner at v0 that I know of, so the new branch itself is not exercised.

Both runs were on my machine; Claude Code (Claude Fable 5.2) ran the script and wrote this report.

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@theaustinayers thank you, both blocks are in the description now.

One question from your note that the full-screen passes go through draw_rects: that path only runs for a rect list pipeline that did not get the rect list GS (#199). When main leaves the GS out it says why, once per reason. Could you search the main run's log for rect list drawn as triangles and paste the lines you find?

No need for another run if the log from the one above is still there.

🤖 Claude Fable 5.2, Claude Opus 5.5

T-Crypt added a commit to T-Crypt/bathyal that referenced this pull request Nov 23, 2026
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 23, 2026
…ds the rect's corner"

This reverts commit d0867d8, reversing
changes made to 207e287.
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.

2 participants