Rect lists: the CPU expansion finds the rect's corner, not always v1 #266
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!266
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-266"
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 22:07 UTC · original
Kalmarv:fix/rect-list-cpu-corner→main· +294 −22 · 2 files · 1 commits · openTitle: Rect lists: the CPU expansion finds the rect's corner, not always v1
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:
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)r600_exa.c, drawn asDI_PT_RECTLISTinr6xx_accel.c); the full-screen passesdraw_rectswas written fromThe 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. 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 onesmainmakes.bind.rs,expand_rect_streams: one corner for a rect whose vertices come from several vertex buffers, and every slot's six vertices use it (review by shdann: each slot on its own could find another corner and pair a position with another corner's attribute). It is found from the positions alone where the input layout names them (review by Alpha325: with every word voting, another attribute could outvote the position). Where the layout does not, it is found from the words of all slots, as if they were one interleaved vertex.crates/xcl/src/hle/d3d12x/real.rs,layout_positionandrect_position: where a rect list pipeline's input layout has the position, as slot, byte offset and bytes. That is its element namedPOSITIONorSV_Position(index 0), two to four 32-bit floats read per vertex. It is noted when a translated rect list pipeline is made (translated_graphics_pso) and forgotten with the pipeline.bind.rs,draw_rectscopies each rect from every slot, looks up where the bound pipeline has the position and calls it; nothing else there changes. This path only runs for a rect list pipeline without the rect list GS, forDrawInstancedwith vertex buffers.bind.rsrects_expanded_on_the_cpu_have_the_corner_opposite_their_own,a_rect_split_over_vertex_buffers_has_one_corneranda_rects_corner_is_found_from_its_positions; inreal.rsrect_list_pipelines_know_where_their_layout_has_the_position. +294/−22 in all, about 125 of them the tests.Overlap: #267 and #533 edit
bind.rs, and #267 also adds five lines toforget_psoinreal.rs, which this PR adds to as well. Both already conflict withmain18c105ainbind.rs, as #150 and #164 do inreal.rs. The other open PRs that touchbind.rsorreal.rsmerge with this head without conflicts in these two files (git merge-tree): #214, #236, #292, #303, #310, #317, #433, #466, #473, #539, #541, #562, #567, #578, #625, #630, #634, #637. No open PR or issue is about rect lists.Tested
14fecf8, one commit onmain18c105a. It was rebased from7f08b78on508a0c7: #574 and this PR each added a test at the same place inbind.rs's test module, and both are kept; no other line of the commit changed.cargo test --workspace -- --test-threads=4(debug) on6bf3305, onmain06c9f55: 1269 passed, 0 failed, 46 ignored (thexcllibrary: 1200 passed, 26 ignored). SKIPPED: 25 notices from 15 GPU tests (21 for no wave64, three refused per-lane cases, one for no heap windows), the same asmain06c9f55, which gave 1265 passed, 0 failed, 46 ignored.7f08b78, onmain508a0c7, hung in #344 on its own (a watchdog stopped the run after 240 s without output) and ran 685 passed, 0 failed, 41 ignored with #443's commit (16fc79d) on top.14fecf8did not hang in its one run, without #443.cargo test -p xcl --lib -- hle::d3d12x::bind::tests rect_liston14fecf8: 16 passed, 0 failed. Those are the eight tests ofbind.rs(one of themmain's new one from #574), the four ofreal.rs's rect list pipelines and four of the rect list GS; the four tests named above need no GPU.b224d77the fourth position is (−1,1) in both (a scratch test:no fourth corner at (1,1): [(0.0, 0.0, 1.0, 1.0), (1.0, 0.0, 0.5, 0.5), (0.0, 1.0, 0.5, 0.5), (0.0, 0.0, 1.0, 1.0), (0.0, 1.0, 0.5, 0.5), (-1.0, 1.0, 1.0, 1.0)]). With the positions named it is (1,1) and every vertex carries its own position's attribute. Without them it is still (−1,1); the test asserts both.Position, three floats, in slot 1 at offset 4 gives (1, 4, 12), and is forgotten with the pipeline. No position: a pipeline that is not a rect list, a layout without the name, 16-bit floats, a per-instance element, index 1, and an appended element after another of its slot.e30794ddid, it fails:[(0.0, 0.0, 10.0), (1.0, 0.0, 20.0), (1.0, 1.0, 30.0), (0.0, 0.0, 10.0), (1.0, 1.0, 30.0), (0.0, 1.0, 20.0)]. With one corner for the rect it passes.main's rule: with the corner fixed at v1 it stops atcorner 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]].mainhas this arithmetic inline indraw_rects, where a test cannot call it.expand_rectas ofe30794d, one vertex buffer): 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.6bf3305merged with currentmain, thank you:cargo test -p xcl --lib(the library only, not the workspace), all passed, 0 failed, 27 ignored (#266).main9ab7d76and the previous heade30794d(another title), no crash or device removal (https://github.com/ivall/xcl/pull/266#issuecomment-7115653227).Regression run
Our own runs with
scripts/smoke.ps1, 120 s each, one after the other on the machine under Tested (RTX 5070 Ti), release builds from clean trees, on the direct route:XCL_DIRECT_DXIL=1, each run with its own XCL cache that starts from the same list of used pipelines (the driver's own cache untouched).mainat0829441(a newermainthan this PR's base06c9f55, which it contains), then this PR's head6bf3305.main:
PR:
PR vs
main: 1298 / 1323 frames (98 %), peak commit 30981 / 30938 MB (100 %); device removals 0 and crashes 0 on the PR run, 0 and 0 onmain.Not tested
draw_rects: the smoke runs above are a regression check only.17 - DI_PT_RECTLIST: Rect List); they do not say how the fourth vertex is derived.draw_rectsitself (a console command list, title vertex buffers, the upload memory) has no test, as onmain; only the expansion it calls does.POSITIONorSV_Position, a position that is not 32-bit floats, and one appended (D3D12_APPEND_ALIGNED_ELEMENT) after other elements of its slot are expanded from the words of all slots. There an attribute in which the corner alone differs from the other two vertices can outvote the position, and the corner is then taken as v1, as before this PR. The same goes for rect list pipelines with a console GS or with PC shaders, which note no position.draw_rects(the bound pipeline, a stand-in resolved, to the slot's stream) has no test, like the rest ofdraw_rects.main.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.AI use
18c105aand the runs on14fecf8🤖 Generated with Claude Code
@Kalmarv on GitHub · 2026-11-23 22:08 UTC · original
Regression run wanted. We have no title on our machine. If you can run
scripts/smoke.ps1 -Game <your title folder>twice, once built frommain(9ab7d76) and once from this PR's head (e30794d), please paste bothxcl-smokeblocks here. I'll copy them into the description under Regression run, with your name and hardware.🤖 Claude Opus 5.5
@theaustinayers on GitHub · 2026-11-23 22:21 UTC · original
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 firstWin32_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):this PR's head (
e30794d):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 on GitHub · 2026-11-23 22:33 UTC · original
@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). Whenmainleaves the GS out it says why, once per reason. Could you search themainrun's log forrect list drawn as trianglesand paste the lines you find?… is an integer output (flat)orthe PS reads a flat attribute: those are the two refusals #293 removes, so your title would reach it, and a smoke run of #293 there would cover the change itself.a PC pixel shader, a driver rejection, or no such line at all: #293 changes nothing for these pipelines.No need for another run if the log from the one above is still there.
🤖 Claude Fable 5.2, Claude Opus 5.5
@shdann on GitHub · 2026-11-24 00:43 UTC · original
At
bind.rs:278,draw_rectscallsexpand_rectindependently for each bound slot. Consider positions(0,0), (1,0), (0,1)in slot 0 and scalar attributes10,20,30in slot 1. The positions select corner 0, so their first triangle uses vertices[0,1,3]. The scalar values tie and select the fallback corner 1, so their first triangle uses[0,1,2]. The generated position gets attribute 30 instead of 40. Could you compute one corner and vertex order per rectangle from the positions, reuse it across slots, and cover this split-stream case? Static review ate30794d, assisted by OpenAI Codex (GPT-6).@Kalmarv on GitHub · 2026-11-24 01:07 UTC · original
Thanks, @shdann, that was right: each slot picked its own corner, and your example paired the fourth position (1,1) with 30.
Changed in
b224d77(squashed into the PR's commit, rebased onmain2997c9a):draw_rectsnow picks one corner and vertex order for each rect and uses them for every bound slot (expand_rect_streamsinbind.rs). The rect list path has no input-layout semantics, so it can't tell which slot holds the positions. The corner is found from the words of all slots together, as if they were one interleaved vertex. In your example the positions decide it (corner v0), and the scalar adds no vote.a_rect_split_over_vertex_buffers_has_one_corner, your case: positions (0,0) (1,0) (0,1) in one buffer, 10 + 10x + 20y in another. Every output vertex must carry the attribute of its own position. With the old per-slot corner it fails, giving(1,1)→ 30 and(0,1)→ 20. With the change it passes.🤖 Claude Opus 5.5
@Alpha325 on GitHub · 2026-11-24 01:27 UTC · original
I tested clean head
b224d77699f6af5452169e9eae1773e8ded56e94. All sixhle::d3d12x::bind::testspassed in release mode. A separate synthetic probe using the unchanged rectangle helpers found a case the split-stream test doesn't cover.(0,0), (1,0), (0,1).float2attribute stream:(1,1), (0.5,0.5), (0.5,0.5). Each component is affine:1 - 0.5*x - 0.5*y.(1,1). Actual:(-1,1). With constant attributes, the same positions expand correctly.The position words give
alone = [0,1,1]. The two attribute words change that to[2,1,1], so the tie falls back to v1. All streams still agree on one corner, but it's the wrong one.Can the CPU path use position data for corner selection when the layout identifies it? If that data isn't available, this seems worth documenting as a limitation of the fallback.
AI use: OpenAI Codex (GPT-6.2 Sol) ran the tests, wrote the synthetic probe, and drafted this report.
@Kalmarv on GitHub · 2026-11-24 02:20 UTC · original
Thanks, @Alpha325, confirmed. On
b224d77your two streams give the fourth position (−1,1), and the same data in one interleaved buffer does too.Changed in
7f08b78(squashed into the PR's commit, rebased onmain508a0c7):POSITIONorSV_Position(index 0, two to four 32-bit floats per vertex): slot, byte offset and size (layout_positioninreal.rs).draw_rectsfinds the corner from those bytes alone and uses it for every slot.a_rects_corner_is_found_from_its_positions, your case in two buffers and in one: the fourth position is (1,1) and every vertex carries its own position's attribute. A second test covers which layouts give a position.rect_cornerand under Not tested. The name is the title's convention; XCL does not follow the vertex shader's code from its inputs to SV_Position. A layout without such an element, a position that is not 32-bit floats, and one appended after other elements of its slot are still expanded from the words of all slots. There your case still gives (−1,1), and the test asserts that too.Tested on an RTX 5070 Ti (driver 610.74), debug: the bind and rect list tests on
7f08b78, 15 passed, 0 failed. The whole suite on7f08b78alone hung in #344, as the earlier head did. With #443's commit (16fc79d) on top it ran 685 passed, 0 failed, 41 ignored, with 2 GPU tests skipped (no wave64). Our title smoke pair on7f08b78is in the description. Not tested: which names a retail title's rect list layouts use.🤖 Claude Fable 5.2
@MesshM on GitHub · 2026-11-24 05:08 UTC · original
Test run of
14fecf8d1b3a0cca75bd876d3f580587c2160206on AMD RDNA4. I merged it onto currentmaind5442d2locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 708 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 667 passed, 0 failed, 21 ignoredSKIPPED;a_rects_corner_is_found_from_its_positions,a_rect_split_over_vertex_buffers_has_one_cornerand thegpu_rect_list_*tests pass.Review: The CPU expansion now takes the rect's missing corner from its positions instead of assuming a vertex order, and the GPU rect-list tests agree. I found nothing to change.
Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@DavidM1911 on GitHub · 2026-11-25 15:14 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.@Kalmarv on GitHub · 2026-11-26 01:00 UTC · original · edited 2026-11-26 01:06 UTC
I'm closing and reopening this right away only to rerun CI on today's
main(b49be18). The failedBuild and testran on amainfrom before #2420, and #2420 fixed the test that failed,a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier. The PR's code doesn't touch that test.@DavidM1911 the head
6bf3305now merges intomainb49be18without conflicts.Edit: the first rerun still built GitHub's earlier merge ref, on
mainbd2ac50from before #2420. The merge ref is onb49be18now, so I reopened it once more.AI use: Claude Code (Claude Opus 5.5) read the CI log, checked the merge with
git merge-treeand wrote this.@DavidM1911 on GitHub · 2026-11-26 02:45 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.