Skip to content

DXIL: filter OOB triangles, gate no-store emits, and clamp LDS in lower_geom - #2419

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-lower-geom-epilogue-oob
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-lower-geom-epilogue-oob

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1401
Part of #1833

Fixes three bugs in the direct DXIL ES+GS lowering (crates/xcl/src/gpu/dxil/lower_geom.rs) where geom_epilogue and gs_emit_cut could reserve phantom vertices, emit out-of-bounds triangle indices, or read split-wave64 LDS exchange scratch words.

What is in it

  • Lw::gs_emit_cut (crates/xcl/src/gpu/dxil/lower_geom.rs): guard vertex emission and triangle packing with k < maxv (<= 256), preventing out-of-range vertex counts and 10-bit packed index overflow.
  • Lw::geom_epilogue (crates/xcl/src/gpu/dxil/lower_geom.rs):
    • Gate each lane's emitted and ntri by has = (gs_base != u32::MAX) before computing vb/tv wave sums so a lane that calls s_sendmsg(emit) without a GS-phase LDS store reserves 0 vertex slots and emits 0 triangles.
    • Filter each lane's monotonic tri[j] ((tri[j] >> 20) < v_written, scanning only when a lane straddles maxv with 3 <= v_written < emitted, zero extra iterations on non-straddling lanes) to compute valid_ntri before tb/tt/np, guaranteeing every emitted triangle index is < nv.
    • Clamp the LDS dword index i to self.lds_top when self.split (matching lower_mem::lds_index) so wrapped LDS addresses cannot read the split-wave64 exchange scratch words.
  • gpu::dxil::lower_geom::tests (crates/xcl/src/gpu/dxil/lower_geom.rs):
    • split_epilogue_clamps_lds_to_lds_top_and_validates (pure-CPU / DXC 1.9): validates both native and split geometry DXIL and asserts split-mode disassembly emits umin(..., 8184) (lds_top) and icmp ult ..., 63 (k < maxv).
    • gpu_epilogue_filters_oob_triangles_and_no_store_emits (GPU-guarded mesh_draw): verifies (a) a 15-lane × 20-vertex wave exceeding max_vertices = 256 with a straddling lane outputs (nv = 256, np = 230) with all 230 triangles < 256 and exact final straddled triangle, and (b) a no-store emit lane followed by a valid lane outputs (nv = 3, np = 1) with exact lane-1 vertex data and triangle (0, 1, 2).

Tested

  • Rebased cleanly onto origin/main 3f277701 (preserving #2273's coalesced 4-word raw_store in geom_epilogue with the lw.split lds_top clamp before gs_load); merges cleanly against origin/main 2898511a.
  • Hardware / toolchain: NVIDIA GeForce RTX 4060 8 GB (driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 build 26200, rustc 1.100.0, DXC 1.9.2609.5, release profile (--release).
  • Failing-first (before fix, on origin/main 68a284a5): cargo test --release -p xcl --lib gpu::dxil::lower_geom::tests:: -- --nocapture: 0 passed, 2 failed (missing umin(..., 8184) LDS clamp and overflow header left: (256, 256), right: (256, 230)).
  • Targeted tests (after rebase onto 3f277701, commit 98692ec1):
    • RTX 4060 gpu::dxil::lower_geom::tests: 2 passed, 0 failed, 0 ignored (0.46 s, 0 skipped).
    • RTX 4060 gpu::dxil::geometry_tests: 3 passed, 0 failed, 0 ignored (0.37 s, 0 skipped, including geometry_epilogue_coalesces_header_and_vertex_stores).
    • WARP gpu::dxil::lower_geom::tests: 2 passed, 0 failed, 0 ignored (0.01 s; pure-CPU/DXC 1.9 test 0 skipped, GPU test cleanly SKIPPED: no GPU / DXC / mesh shaders).
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1358 passed, 1 failed, 46 ignored across 24 test binaries (182/182 gpu::dxil::* passed, 0 failed) — the sole failure is 3f277701's pre-#2420 gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier (fixed on main by #2420); 29 pre-existing SKIPPED lines (21 no wave64 on RTX 4060, 3 per-lane wave32 refused, 3 no D3D12 debug layer, 1 no heap windows, 1 cannot disable driver cache; 0 skipped in lower_geom::tests and geometry_tests).

Regression run

main:

xcl-smoke v1
commit: 3f2777019544c0ada2cd294aa792d3c378ff0df8
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1486 (PresentX 1486)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13989 MB

PR:

xcl-smoke v1
commit: 98692ec178f711dd8388ff7496cf95ce0691767f
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13987 MB

Not tested

  • Native wave64 GPU execution (AMD RDNA hardware) and D3D12 debug-layer test subsets (skipped on this RTX 4060 / non-debug-layer host; native wave64 DXIL translation and DXC 1.9 validation ran on CPU in split_epilogue_clamps_lds_to_lds_top_and_validates and geometry_forms_validate).
  • Retail titles other than title: 29640639.

AI use

  • Google Antigravity (Gemini 4 Neon) — audited gpu/dxil/lower_geom.rs, implemented the has gating, k < maxv guard, straddling-lane triangle filter, split lds_top clamp, and failing-first CPU/GPU tests, and ran targeted, WARP, workspace, and paired smoke verification.

@DarkPanda69

DarkPanda69 commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for head 98692ec: same result. Applied on main 2664021, gpu_epilogue_filters_oob_triangles_and_no_store_emits passes on the RX 9070 XT (native wave64) and the RTX 3060. Whole gpu:: filter: RX 9070 XT 694 passed, 2 failed (the #2115 fuzz seeds, same on main); RTX 3060 696 passed, 0 failed.


AMD native wave64 run (listed as untested), plus an RTX 3060: the new GPU test passes on both.

Head 2fe72c6 applied on main ae6f284, debug, Windows 11 Pro 26200, cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • RX 9070 XT (RDNA4, driver 32.0.32029.2010, waves 32..64): gpu_epilogue_filters_oob_triangles_and_no_store_emits ok. 684 passed, 3 failed, 22 ignored, 6 SKIPPED.
  • RTX 3060 (driver 32.0.16.1088): the new test ok; 686 passed, 1 failed, 22 ignored.

All failures are on main without this PR: a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier on both cards (fixed by #2379) and, on the RX 9070 XT, the AMD fuzz seeds tracked in #2115.

Not tested: the D3D12 debug layer (not installed here), a title with geometry shaders on the direct path.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

…er_geom

Fix three bugs in the direct DXIL ES+GS lowering (`gpu/dxil/lower_geom.rs`):

1. `geom_epilogue` summed `emitted` and `ntri` across the wave before
   checking `has = (gs_base != u32::MAX)`: a lane that called
   `s_sendmsg(emit)` without a GS-phase LDS store wrote 0 vertices yet
   still reserved phantom uninitialized vertex slots, shifted later
   lanes' `vb`, and emitted triangles referencing uninitialized vertices.
2. `geom_epilogue` clamped emitted vertices per lane to `v_written =
   min(emitted, maxv.saturating_sub(vb))` (`nv = min(tv, maxv)`), but
   did not filter `ntri` against `v_written`, so straddling and
   past-`maxv` lanes emitted triangles with vertex indices `>= nv` (and
   `gs_emit_cut` did not guard `k < maxv` before 10-bit index packing).
3. `geom_epilogue` loaded `@xcl_lds[(a >> 2) & 8191]` without clamping
   to `self.lds_top` in split wave64 mode (unlike `lower_mem::lds_index`),
   allowing wrapped addresses to read exchange scratch words.

Gate `emitted`/`ntri` by `has` before wave sums, guard `gs_emit_cut`
with `k < maxv`, filter each lane's monotonic `tri[j]` (`(tri[j] >> 20)
< v_written`) to compute `valid_ntri` before `tb`/`tt`/`np` (zero extra
iterations on non-straddling lanes), and clamp LDS indices to
`self.lds_top` when `self.split`.

Part of xcl-dev#1401
Part of xcl-dev#1833

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the fix-lower-geom-epilogue-oob branch from 2fe72c6 to 98692ec Compare November 25, 2026 19:12
@Decodere

Copy link
Copy Markdown
Contributor Author

Rebased #2419 cleanly onto 3f277701 (98692ec1): preserved #2273's coalesced header + 4-word raw_store in geom_epilogue (lower_geom.rs) alongside #2419's has/k < maxv/valid_ntri/lds_top clamp fixes.

Re-verified lower_geom::tests (2/0 RTX 4060 & WARP), geometry_tests (3/0, including #2273's coalescing test), gpu::dxil::* (182/182), and paired 60 s RTX 4060 smoke (3f277701 1486 frames / 13989 MB vs 98692ec1 1518 frames / 13987 MB, 0 device removals/crashes).

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 98692ec178f711dd8388ff7496cf95ce0691767f (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1356 passed, 3 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 98692ec178f711dd8388ff7496cf95ce0691767f
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1542 (PresentX 1542)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14002 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks for testing! That gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier failure comes from a pre-#2420 main base (#2074) and was fixed on main in #2420 (c56e7448).

This PR (#2419) only touches crates/xcl/src/gpu/dxil/lower_geom.rs, and CI Build and test on current main (as well as the independent RDNA4 passes on 98692ec1) is green (0 failures).

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concrete code-level defect found. The vertex/triangle cap logic, no-LDS-store filtering, and split LDS clamp look sound; coverage includes straddling OOB triangles and both split/native wave64. Nonblocking validation gap: no direct-path retail title with geometry shaders was tested. Please retain that limitation in the merge evidence.

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.

5 participants