d3d12: post-divide NDC dot-product corner selection and exact fourth corner for rectangle lists (RT-RECT-LIST-CORNER) #2478
Closed
leonida/mandy
lixonik wants to merge 0 commits from
rt-rect-list-corner into main
pull from: rt-rect-list-corner
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2478
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-rect-list-corner"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Fixes the rectangle-list fourth-corner selection and reconstruction in
runtime/src/rect_list_geometry.hfor packageRT-RECT-LIST-CORNER(#2464 Part B; builds on @kevincommits's numerical analysis in https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7219710234).Root cause removed
rect_list_geometry()picked the corner opposite the longest edge using pre-divide clip-space squared lengthsdx^2 + dy^2. That failed on:dx^2 + dy^2 == dx^2in float32 breaks the tie-break and flips the rectangle);w(e.g.,w = 1e20, wheredx^2 + dy^2overflows to+Inf);wacross vertices (where pre-divide distances pick the wrong corner).Computing post-divide NDC
(x/w, y/w)and selecting the vertex with the minimum signed incident-edge dot product (equivalently maxdot(e_in, e_out), unordered>=soNaN/w == 0deterministically falls back tov1) is algebraically identical to opposite-the-longest-side by the law of cosines for all triangles (including rotated rectangles, near-square, obtuse/acute, and degenerate) while keeping exact0.0dot product at any axis-aligned right angle.(((v0 + v1) + v2) - corner) - cornerwith direct(other_a, other_b, corner)selection and per-component bit-equality checks (OpBitcast+OpIEqual), preserving axis-aligned coordinates and constant/flat attributes bit-exact (0 ULP drift) while keeping the documented clip-spaceother_a + other_b - cornerrule uniformly forPositionand all interpolants (docs/d3d12_vulkan.md).for (const Corners& c : corners)loop header intact (git merge-treewith #1970 is conflict-free).Testing
main(ec91d695c):d3d12_rect_list_corner_testfails on 7 corner-rule cases (w=1e20 corner v2: 2080/4096 off plane;differing w=(1.875,1,1) corner v0&w=(1,1,1.875) corner v2: 2080/4096 missed each;thin strip 5000:1 corner v2&v1: 2048/4096 missed each;flat non-dyadic exact: 4096/4096 pixels drifted;differing w=(1.875,1,1) flat color: 2080/4096 missed).220aa322e):ctest -R "^(d3d12_rect_list_corner|indirect_topology_and_stats)$": 2/2 passed (d3d12_rect_list_corner_test: all 17 cases passed, 0.27 s).python -I tests/test_ctest_registration.py -v: 6/6 passed.python -I scripts/check_no_game_data.py ...andgit diff --check: clean.VK_LAYER_KHRONOS_validationnot installed locally;d3d12_rect_list_corner_testis self-contained withoutllvm-mcand skips with 77 whengeometryShaderor Vulkan is unavailable).AI-assisted (Antigravity, Gemini).
Independent Linux/Wine + NVIDIA check at head
4283e3ffa(merged cleanly ontoorigin/mainc0201a806alongside#2480,#2477,#2476,#2474).7.2.15,wine-11.22,clang-cl+xwincross-build, NVIDIA GeForce RTX 3070 Ti 8 GB, driver620.73.04, Ryzen 7 5800X, 32 GB RAM. No game files.d3d12_rect_list_cornerpassed (6.31 s) on RTX 3070 Ti under Wine.AI-assisted.
Tested for #2464 as Aslanek asked: unit tests and a game run on my machine; CI ignored for now as asked.
Reading (marked):
Limits: one machine, one run for the PR, one run for each main witness.
AI-assisted (Claude Code, Claude Opus 5.5)
Review of head 4283e3ffa (read against main 43a9d562d, which contains ec91d695c). The game run is in my RUN above. I suggest splitting this PR into two:
Ready to merge on its own: picking the corner in NDC with the dot product (I checked that it matches "longest side" through the law of cosines) and copying the vertices bit for bit. Both look sound to me.
Needs a source or a separate PR:
runtime/src/rect_list_geometry.h:273-287: whenwdiffers, the fourth corner is extrapolated in NDC and in 1/w.docs/d3d12_vulkan.md:3112still says the hardware uses "v2 + v3 - v1 for the position and every interpolant", and this PR keeps that line while its new text in the bullet just below describes the NDC and 1/w rule, so the doc now states both. I found no hardware measurement behind the new rule, so the test checks behaviour that the PR itself defines. Could you either drop this path from the PR or point to a console reference that confirms it?runtime/src/rect_list_geometry.h:281-283: when1/w4 <= 0, the position falls back tow4 = 1, but the attributes stay linearly extrapolated in clip space. Position and attributes then follow two different models. Thediffering w=(1,2,2)case (d3d12_rect_list_corner_test.cpp:253) uses a constant colour, so it checks coverage but not how varying attributes are extrapolated.Minor points:
for (std::size_t vi ...loop (rect_list_geometry.h:291) has a content conflict with #1970, which is still open, although the description says "orthogonal to #1970". The conflict is trivial:emitted.reserveagainst the indexed loop.d3d12_rect_list_corner_test.cpp:17announces a case 7 "tile 160x90" that is not in the list of cases.AI-assisted (Claude Code, Claude Opus 5.5)
@MoonEyes Thanks for the thorough review and testing! Addressed all four points in
220aa322e:1/wfourth-corner path (and its1/w4 <= 0->w4 = 1fallback):rect_list_geometry()now appliesexact_fourth(other_a, other_b, corner)uniformly to bothPositionand every interpolant, matchingdocs/d3d12_vulkan.md(v2 + v3 - v1) with no mixed position/attribute model and a much smaller SPIR-V body. Updateddocs/d3d12_vulkan.mdto note that differing-wfourth-corner behavior beyondv2 + v3 - v1is unmeasured on console hardware.for (const Corners& c : corners)verbatim; verifiedgit merge-treeagainst #1970 exits 0 with no conflicts.d3d12_rect_list_corner_test.cpp: Removed the stale case-7 tile note from the header comment and updated the differing-wcases tow = (1.875, 1, 1)(cornerv0) andw = (1, 1, 1.875)(cornerv2), where pre-divide clip-space lengths onmainpick the wrong corner while post-divide NDC picks the right corner and clip-spaceother_a + other_b - cornerproduces positivew4 = 0.125.Re-tested on RTX 5070 (Windows 11, driver 610.88, Vulkan 1.4.341,
VK_LAYER_KHRONOS_validationnot installed locally):main(rect_list_geometry.h): 7/17 cases fail (w=1e20, both differing-wsolid cases, both 5000:1 thin strips,flat non-dyadic exact, and differing-wflat color).220aa322e:d3d12_rect_list_corner(17/17 cases, 0.27 s) andindirect_topology_and_stats(0.03 s) both pass;test_ctest_registration.py(6/6) andcheck_no_game_data.pyclean.AI-assisted (Antigravity, Gemini).
Reviewed at head
220aa322eon Windows 11 (MSVC 202219.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK1.4.363.0).Verification
d3d12_rect_list_corner_test.d3d12_rect_list_corner_test(LEONIDA_VK_VALIDATION=1): all 17 corner-rule cases passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02).Notes (non-blocking)
other_a + other_b - cornersynthesis (rect_list_geometry.h:191-194,245-267) look clean and address the earlier1/wreview note.docs/d3d12_vulkan.md:3113;rect_list_geometry.h:221-243): The doc states degenerate/zero-W inputs fall back to the first vertex, but the shader divides bywwithout a zero-W guard (e.g.,(2,1,0), (0,0,1), (0.5,0.5,1)yields(-Inf,-Inf,+Inf)selecting vertex 2 under IEEE infinities, and Vulkan leaves division by zero unspecified; collinear(-1,0,1)also selects the middle vertex). Either guard zero-W explicitly or qualify the doc statement.Approve.
AI-assisted review + local MSVC/dual-GPU verification.
Approving. Merged onto current main (431ceba4f) with no conflicts, cross-built (clang-cl 19 + xwin) and ran under Wine 11.22 on llvmpipe:
d3d12_rect_list_cornerpasses, and so does the existingd3d12_rect_list(the console's rectangle and quad lists through the translated vs_m15 / ps_m15), so the rewrite keeps the real translated draws right. As a negative check I built the new test against main'srect_list_geometry.h: it fails, starting with thew=1e20case drawing the wrong colour (corner v2: pixel (0,0) got 0.5,0.125,0.25,0.5).I checked the math rather than the comment. With s_k the dot of the two edges at vertex k as the code forms them, the law of cosines gives s_k = c_k^2 - (a^2 + b^2 + c^2)/2, where c_k is the side opposite k: the sum term is the same for all three vertices, so the largest s_k is exactly the vertex opposite the longest side, as the comment says, without the old squared-length comparisons' tie losses. The unordered compares send NaN (w == 0) to v1 as documented.
exact_fourthis right per component: if a component of one non-corner vertex equals the corner's bits,a + b - cis exactly the other vertex's value, so returning it bit for bit only removes rounding. Theother_a/other_bpicks give (v2, v3), (v1, v3), (v1, v2) for corners v1, v2, v3, and the emitted triangles are unchanged. The new opcode numbers (OpBitcast 124, OpFDiv 136, OpIEqual 170, OpFUnordGreaterThanEqual 191) are right.One thing worth stating in the docs line, not a blocker: the corner is now chosen in post-divide NDC rather than clip-space x/y. That only changes the choice when the three w differ, which a screen-space rectangle shouldn't have, but it is a behaviour change for such input.
AI-assisted (Claude Code, Claude Opus 5.5).
VERIFY-2478-VEGA20-RADV: the same 17-cased3d12_rect_list_cornerfixture gave 7 failures on main33db04a70and 17/17 passes on220aa322emerged with that main, under Wine on gfx906 / RADV Mesa 26.0.8. All draws completed; Red was a pixel mismatch, not a build or feature skip.On main, each 5,000:1 strip missed 2,048 of 4,096 pixels. Each differing-
wcorner case missed 2,080, and the uniform large-wcase had 2,080 off-plane pixels. A constant non-dyadic color drifted in 1,024 pixels at uniformw; it was bit-exact on the merge. The adjacentd3d12_rect_listreadbacks passed on both trees.Captured geometry modules matched the corresponding main and merged emitters byte for byte. The CPU topology/statistics control also passed on both. Khronos synchronization validation was active: zero validation errors or sync hazards across the four hardware runs. Synthetic only.
AI-assisted.
@timbot103 I reproduced both corner-selection issues on the current head
220aa322e471cbfb2fd90ba711341163a1f9302d. On RTX 5070 (NVIDIA 610.88, Windows 10, Vulkan validation 1.4.363.1), I captured the six positions emitted by the generated geometry shader in each case. Both mixed signed-zero-W cases and the large finite-NDC case with the axes swapped emitted the wrong corner in all three fresh runs. Plain main02944d4ca1and main with a local correction each passed all six cases in three fresh runs.The local correction selects v1 for zero or non-finite W or non-finite projection. For large finite projected coordinates it scales both axes by the same power of two before calculating the edge dot products. The correction is still local because GitHub rejected the push under its commit-email protection. The new D3D12 raster assertions still need a CTest run with Windows SDK 10.0.26100 or newer.
AI-assisted. Codex (GPT-6).
I also ran the D3D12 raster fixture on RTX 5070 (610.88) with Khronos validation. I used the same extended fixture in both builds, with the pinned Agility SDK headers and a static CRT on Windows 10/MSVC 19.29.
220aa322e471cbfb2fd90ba711341163a1f9302d: 17/18 cases passed. The mixed-zero-W draw wrote 85 pixels below NDC Y = 0, where the target should stay clear.The permanent raster case checks positive zero. Negative zero and the large finite-NDC inputs were checked by capturing geometry-stage output in the separate probe above. The correction is still local.
AI-assisted. Codex (GPT-6).
Pushed the corner-selection fix from the checks above as
2171766479(re-committed with my GitHub noreply address so the fork accepts the push).python -I scripts/check_no_game_data.py: passed.git merge-tree --write-tree main HEAD: clean againstef32995848.AI-assisted (Antigravity, Gemini).
Verified by OreoFR — READY
d3d12_rect_list_cornerfails on main in 7 cases. Examples:w=1e20 corner v2: 2080 of 4096 pixels off plane, the two differing-w fills, the two 5000:1 thin strips, and the two exact-constant cases. The test's CMake registration was kept for the red run. The newmixed W with zerocase passes on main as well, since main also falls back to v1 there. It guards against the regression found on 220aa322e rather than reproducing a main bug.d3d12_rect_list_cornerpasses (18 cases); ctest (Ninja RelWithDebInfo, all targets, gta6rt launchers excluded) on main + this PR alone: 498 tests, new failures vs main: none (main alone: 497 tests, 1 failure: xbox_present, which fails here too)LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty), main + this PR; imports unchanged vs main (655 functions, no new DLL, no WS2_32)w, or a non-finite projected coordinate, selects v1. NaN bits compare above the infinity bits in the unsigned max.AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
RTX 3090 / 621.40, validation on, 217176647 merged onto main 20fe0c754: d3d12_rect_list_corner 18/18 pass (not on main); indirect_topology_and_stats pass (main pass). No validation errors.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.