Skip to content

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

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-lower-geom-epilogue-oob
Nov 29, 2026
Merged

raylitebull merged 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.

@thehollowedone

thehollowedone commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: e429936
head: 98692ec
merge: clean; an uncommitted merge onto this base changed only crates/xcl/src/gpu/dxil/lower_geom.rs (+123/-20); git diff --cached --check passed
build: cargo build --offline --locked -j 4 --workspace -> ok on the merged tree
tests: cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 -> 2,127 passed, 10 failed, 48 ignored across 39 targets; 25 distinct GPU SKIPPED notices. Untouched base e429936c on this machine: 2,125 passed, the same 10 failed, 48 ignored. Both new lower_geom::tests passed on the RTX 3080 Ti. Failing names are listed below.
review: I read the full diff and the current geometry lowering. No runtime blocker found: emission stops at the per-lane record limit, the straddling lane counts only triangles whose vertices are written, and no-store lanes contribute zero. The change is absent from current main. Nonblocking test improvement: the GPU test always tries split wave64, even on a possible mesh-capable adapter with wave64 but no wave32; gate each form on its own capability. Neither fixture reaches the per-lane emit ceiling, so a dedicated cap case would strengthen its regression coverage.
performance: The default HLSL geometry route does not execute this direct-DXIL path. In explicit direct mode, the added emit guard is per message and the triangle scan runs only for a lane straddling the vertex cap; no frame-time measurement was made.
verdict: safe to merge
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, rustc 1.99.1 MSVC, DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the merge, build and tests and checked the diff; Codex (GPT-6.2 Astra) independently reviewed the low-level geometry and test paths.

Ten failures shared with the exact base
  • gpu::dxil::module::split::tests::dispatch_chain_oversized_loop_matches_whole
  • gpu::dxil::module::split::tests::dispatch_chain_wave32_live_loops
  • gpu::dxil::module::split::tests::dispatch_chain_wave64_live_loops_and_exchange
  • gpu::recomp::heap_window_tests::gpu_heap_flat_reads_match_guarded_and_root_output
  • gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk
  • gpu::recomp::tests::gpu_compute_mode_dispatch_abi
  • gpu::recomp::tests::gpu_float_cas_uses_ieee_equality
  • test_title_draws_with_a_root_signature_under_the_debug_layer
  • test_title_runs_and_game_folder_is_untouched
  • test_title_runs_under_the_debug_layer_with_dred

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 98692ec

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: e429936
head: 98692ec
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2128 passed, 9 failed, 48 ignored (26 SKIPPED lines). The 9 failures are main's own at e429936 on this GPU (reported with a bisect on #3041: they arrive with the merge of #2959); the set is identical with and without this PR. Base alone: 2126 passed, 9 failed, 48 ignored.
review: no blocking finding. The emit and cut loop stops at the record's vertex cap, which keeps the 10-bit indices in range; the filter for triangles that straddle the cap is sound (the indices only rise); the LDS clamp matches the one in the memory lowering on main. Minor: one CPU test compares a literal that depends on the current exchange layout. Open from the thread, not blocking: no direct-path title with a geometry shader was run, and the test does not reach the per-lane emit cap.
performance: none by default: direct DXIL only (XCL_DIRECT_DXIL=1), and only its users re-translate once.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Test report for merging this together with the other of #2102 / #2419 (both are ready to merge on their own): trial merge of both into main d8bd9a38, cargo build --workspace && cargo test --workspace -- --test-threads=4, RTX 4080 16 GB, 621.40:

So the two do not go in together as they are; whichever is merged second needs a rebase and a look at those two tests. I have not looked into which side is right.

AI use: Claude Code (Claude Fable 5.2) ran the suite and wrote this.

@raylitebull
raylitebull merged commit e872f23 into xcl-dev:main Nov 29, 2026
3 checks passed
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Correction to my report above: #2102 and #2419 do not clash with each other. Since #3203, kernel::translate_geometry refuses the split wave64 form when the program has an ES phase, and the new tests of both PRs call it that way, so they stop at that refusal. #3411 fixes the tests on main. Sorry for the wrong lead.

AI use: Claude Code (Claude Fable 5.2) wrote this; Claude Opus 5.5 found the cause.

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.

8 participants