Recompiler: replace tn[4]/id[4] local arrays in bvh_intersect with scalars #2292
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2302"
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?
Imported from ivall/xcl. Originally posted by fixgep on 2026-11-25T13:15:07Z.
Part of #2088. Replaces local array and vector-subscript indexing (
tn[4],id[4],pairs[5],child[k]) and scalar?:ternaries inPRELUDE_MEM'sbvh_intersecthelper (crates/xcl/src/gpu/recomp/emit.rs) with scalar registers and branchlessselectoperations.At
-O0(> 8 MBHLSL), DXC emitted 5 stackallocas and dynamicgetelementptrsequences perbvh_intersectcall site; at-O1and-O3, per-ktype == 5ubranches inside the unrolled loop,if (tn[j] < tn[i])swap diamonds, and scalar?:ternaries on triangle offsets bloated control-flow graphs and slowed both DXC and cold NVIDIA PSO compilation.What is in it
crates/xcl/src/gpu/recomp/emit.rs: replaces[unroll] for k+tn[4]/id[4]/pairs[5]/child[k]inbvh_intersectwith a singletype == 5ubox-load branch (bvh_box16_bounds), 4 scalarbvh_box_tevaluations (tn0..tn3,id0..id3), a branchless 5-stepbvh_swapsorting network insideif (sort), andselectfor GPURT triangle offsets,tri_retmode selection, and hit/bad-ray selection; integratesmain'sbvh_grow_lo/bvh_grow_hiULP expansion (computingvalid = all(mn <= mx)before growing bounds),tri_ret, andbad_rayearly return intobvh_box_tandbvh_intersect; addsbvh_intersect_uses_scalars_without_local_arrays.crates/xcl/src/gpu/recomp/tests.rs: adds DXIL IR validation/zero-alloca testbvh_intersect_dxil_has_zero_allocas_and_validates(-O0,-O1,-O3), wave32/split-wave64 edge-case parity testgpu_bvh_intersect_scalar_matches_reference, and manual cold PSO benchmarkbench_cold_bvh_intersect_pso(updated forbvh_grow_hi/bvh_grow_lo,bad_ray, andtri_ret).Controlled synthetic benchmark from
30985d3(32IMAGE_BVH(64)_INTERSECT_RAYcalls in anS_CBRANCH_VCCNZtraversal loop, dynamicsort,mem_windows = 4, median of 3 timestamp-salted runs on NVIDIA GeForce RTX 3060 / driver32.0.15.9144, DXC1.9.2602.17, warm re-create verified50–69 ms):alloca/gep/br/phi-O3baseline-O3scalar-O1baseline-O1scalar-O0baseline-O0scalarTested
32.0.16.2140), AMD Ryzen 5 7500F 6-Core Processor, Windows 11 x64,rustc 1.100.0 (0ef1bc386 2026-11-09), Windows SDK DXC1.9.2602.17, debug & release (rebased headb1d353e4onupstream/main6bfb5c51).cargo build -j 4 --workspace,cargo test -j 4 --workspace --no-run, andcargo build -j 4 --release -p xclall exited0with 0 new warnings incrates/xcl/src/gpu/recomp/emit.rsortests.rs.cargo test -j 4 -p xcl --lib gpu::recomp -- --test-threads=1(RTX 3060): 532 passed, 0 failed, 22 ignored (SKIPPED: 21no wave64forms).cargo test -j 4 -p xcl --lib bvh -- --test-threads=1(RTX 3060): 29 passed, 0 failed, 1 ignored (bench_cold_bvh_intersect_pso; 0SKIPPED— all 7 GPU BVH tests includinggpu_bvh_box_grow_nan_inactivation_and_tri_mode0,gpu_bvh_intersect_scalar_matches_reference,gpu_bvh_triangle_types_2_and_3,gpu_bvh64_intersect_ray_across_memory_windows_and_grazing, andgpu_bvh_node_in_an_unmapped_window_returns_a_misspassed).XCL_ADAPTER=warp cargo test -j 4 -p xcl --lib gpu::recomp -- --test-threads=1: 532 passed, 0 failed, 22 ignored (SKIPPED: 324 GPU wave tests without wave32/wave64 shader support on WARP).XCL_ADAPTER=warp cargo test -j 4 -p xcl --lib bvh -- --test-threads=1: 29 passed, 0 failed, 1 ignored (SKIPPED: 7no wave64).cargo test -j 4 -p xcl --lib -- --test-threads=4(via--workspacerun): 2759 passed, 0 failed, 32 ignored (SKIPPED: 22no wave64, 1no heap windows (opt-in: XCL_HEAP_WINDOWS=1), 1ShaderCacheControl0x887A002D).cargo test -j 4 -p xcl --test '*' --no-fail-fast -- --test-threads=4(38 targets): 142 passed, 1 failed (two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsingpu_two_pass_cache_e2e, which passed when rerun standalone viacargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1: 1 passed, 0 failed), 20 ignored (SKIPPED: 1heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows;XCL_SAMPLE_*unset).Regression run
Not tested
no wave64on RTX 3060 and WARP).XCL_SAMPLE_*retail shader packs (unset).ID3D12Device9::ShaderCacheControlcache disable (Windows Developer Mode not active) and post-rebase rerun ofbench_cold_bvh_intersect_pso(benchmark table above is from pre-rebase30985d3).AI use
Antigravity (Gemini 4 Hydrogen): replaced
bvh_intersectarray indexing and scalar ternaries with scalar registers andselecthelpers incrates/xcl/src/gpu/recomp/emit.rs, wrote the synthetic IR/GPU parity tests and cold NVIDIA PSO benchmark, rebased ontoupstream/main(6bfb5c51) carryingbvh_grow_lo/bvh_grow_hi,tri_ret, and bad-ray early return intobvh_box_t/bvh_intersect, and ran the build, targeted/workspace test, and smoke checks.Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T13:25:40Z.
The native wave64 run listed as untested (on RDNA4 rather than RDNA2), plus an RTX 3060: the new test passes on both.
Head
30985d3applied onmain1a0bbe3, debug, Windows 11 Pro 26200,cargo test -p xcl --lib -- gpu:: --test-threads=4:gpu_bvh_intersect_scalar_matches_referenceok, with nono wave64skip. 632 passed, 2 failed, 23 ignored, 6 SKIPPED; the 2 failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: RDNA2,
XCL_SAMPLE_*shader packs, cold-cache PSO timing.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-11-25T13:32:55Z.
Independent Turing validation of
30985d3f48b605d1cdc9d4c39256afcb14ffea1a(parent1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6). On this machine, DXC compilation improved in all three modes; median first PSO creation improved at O0 but was slower at O1/O3 in this run.Two test-only commits based on this PR head are available for cherry-pick:
Tested
Windows 11 Pro 26200, i7-9750H, 32 GB RAM, Quadro RTX 3000 6 GB (driver
32.0.15.9706/597.06), DXC1.9.2609.5, Rust/Cargo1.100.0, AC power.XCL_ADAPTER=nvidia;XCL_SAMPLE_*,XCL_DIRECT_DXIL, andXCL_HEAP_WINDOWSunset. Incremental compilation and profile debug symbols disabled.cargo build --workspace --lockedpassed.cargo test --workspace --locked --no-fail-fast -- --test-threads=4completed: 1252 passed, 1 failed, 47 ignored (exit 101). The new scalar-source, DXIL-validation and GPU-reference tests, plus the existinggpu_bvh_intersect_ray, passed. There were 27 explicitSKIPPEDrecords: 20 native-wave64, 3 unsupported f16 forms (#1426), 2 missing D3D12 debug layer, 1 unavailable cache control, 1 disabled heap-window path. These records are separate from the harness totals.hle::d3d12x::bind::tests::execute_indirect_reads_the_arguments_written_before_it: 20/40 mismatches, zero results on even trials. This matches a historical full-suite log with unchangedcrates/xclrelative to the parent, but that historical run enabledXCL_HEAP_WINDOWS=1. A fresh isolated parent-runtime attempt failed earlier inCreateComputePipelineStatewith0x80070057, so it is inconclusive as a matched parent comparison; its adapter was not confirmed. I am not claiming a fresh baseline reproduction of the 20/40 failure.Synthetic compilation measurements
The modified manual benchmark passed (release, 450.26 s). It retains the supplied 32-call BVH traversal workload, dynamic sort, four memory windows, and split-wave64. The embedded baseline helper matches the parent helper after accessor/comment normalization. No other compiler/GPU workload was launched by this validation.
DXC was faster in all 12 pairs. First PSO creation was slower in 3/4 pairs at both O3 and O1, faster in 4/4 at O0. First-PSO ranges, base/scalar in ms: O3
11467.27–13423.64 / 12152.26–12653.75; O110123.84–12353.89 / 10960.94–12429.38; O019661.46–24402.34 / 14159.85–18141.12. Repeat creation across all samples was27.50–50.09 ms.ShaderCacheControl(DISABLE)failed with0x887A002D. Salts/fingerprints distinguish the inputs and direct compilation bypasses XCL's disk cache, but implicit driver-cache state is not proven cold. Four pairs are descriptive measurements, not statistical significance or a general NVIDIA speedup. Process-commit deltas are not peak-memory measurements.Supplemental commands (with the linked test-only changes):
Not tested: native wave64/AMD, retail shader packs or titles, GPU execution throughput, frame rate, time to first playable frame, or guaranteed cold-cache performance.
AI use: Codex and three agents prepared these test-only extensions, checked BVH semantics and benchmark arithmetic, ran the local validation, and wrote this report. The exact model identifier is unavailable in this session. This is a measured test report, not a formal code-review approval.
upstream-sync referenced this pull request2026-11-25 15:05:51 +00:00
Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T14:23:16Z.
Independent RX 6800M (RDNA2 native-wave64) check of exact PR head
30985d3f48b605d1cdc9d4c39256afcb14ffea1a.Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver
30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. I selected the discrete GPU withXCL_ADAPTER=6800Mand required wave64 withXCL_REQUIRE_GPU=wave64.I ran the clean-head
bvh_intersect_focused tests twice, once withXCL_DIRECT_DXIL=1and once withXCL_DIRECT_DXIL=0. Each run finished 4 passed, 0 failed, 1 ignored, with noSKIPPEDline. Passing tests were the scalar-source check,bvh_intersect_dxil_has_zero_allocas_and_validates, the existing GPU BVH ray fixture, andgpu_bvh_intersect_scalar_matches_reference. The manual cold-PSO benchmark was the ignored test.The new reference fixture's
gpu_waves()runs both native wave64 and wave32 on this selected adapter. It compares per-lane sorted and unsorted box32/box16 child IDs and GPURT triangle results, including ties, misses, invalid bounds, NaNs, axis-parallel rays, and negativetmax. The DXIL inspection fixture validated O0, O1, and default output and checked for zero local array allocations.Limits: This is focused synthetic correctness evidence on RDNA2. I did not run the full workspace suite, title smoke, sampled shader packs, GPU throughput, or cold PSO timing on this head. I am not claiming a performance change.
AI use: OpenAI Codex (GPT-6; exact variant unavailable in this session) ran the tests, checked the exact head and clean worktree, and drafted this report. No game data was used.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-25T14:50:56Z.
Focused HLSL-path verification on exact head
30985d3f48b605d1cdc9d4c39256afcb14ffea1awith the Windows SDK's DXC 1.8.Tested
cargo test --locked -p xcl --lib bvh_intersect -- --nocapture --test-threads=1withXCL_DIRECT_DXIL=0and each adapter selected viaXCL_ADAPTER. Each run gave 4 passed, 0 failed, 1 ignored (the manual cold-PSO benchmark) and no skips.Not tested
The benchmark, retail inputs, the parent, the full workspace suite and game regression runs.
AI use
OpenAI Codex (GPT-6.2 Sol) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by MarcosMDev on 2026-11-25T16:08:31Z.
Test report:
30985d3on an RTX 4060: suite green, and this PR's own synthetic benchmark shows a driver gain only at-O0on this card. No game data was used.Suite,
cargo build --workspace, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4, debug, a separate target folder per commit:1a0bbe3: 1250 passed, 0 failed, 46 ignoredbench_cold_bvh_intersect_pso, release, nothing else of ours running, a new exe basename (ShaderCacheControlreturned0x887A002D, so the driver cache stayed on; the second call took 4 ms at most). Medians of the benchmark's 3 runs:-O1-O0The scalar form was slower in all 3 pairs at O3 and at
-O1, and faster in all 3 at-O0. Allocas at O3 are 0 on both sides already. The benchmark builds the base form first in every pair, so an order effect is possible; I did not swap it. An earlier run overlapped other work, so I leave its numbers out.So on this card the DXC time improves at every level, but I do not reproduce the −18 % cold PSO at
-O3reported from an RTX 3060.RTX 4060 8 GB (32.0.16.2101), Ryzen 7 5700X, 24 GB, Windows 11 26200, rustc 1.100.0, DXC 1.9.2609.5. Not tested: any title, retail shaders, AMD / Intel, GPU time, the branch merged with today's
main(it conflicts).AI use: Claude Code (Claude Opus 5.5) read the diff, ran the tests and the benchmark, and wrote this.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T17:41:07Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-25T17:44:46Z.
Ran the bvh_intersect tests at
30985d3:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.
The new
bvh_intersect_dxil_has_zero_allocas_and_validatesandgpu_bvh_intersect_scalar_matches_referencepass, as doesbvh_intersect_uses_scalars_without_local_arrays; the ignored one is the manual release benchmark.What this adds: the author tested an Ampere RTX 3060 with Windows SDK DXC 1.9.2602.17; this is a Blackwell wave32 part with DXC 1.9.2609.5. The new GPU parity test ran on the real adapter here. I did not repeat the cold PSO timing benchmark.
Not tested: the cold PSO A/B timings, a paired 60 s smoke run, native wave64 hardware, AMD and Intel GPUs, Wine, release profile, retail title data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
upstream-sync referenced this pull request2026-11-25 20:07:08 +00:00
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:47:31Z.
Triage (#1607) – head
b1d353e#1542 targets the same cost in
PRELUDE_MEM'sbvh_intersect(the box-node loop repeated at every inlined BVH instruction), but in the opposite direction:[unroll]to[loop], so one copy of the slab test remains and the arrays stay.tn[4]/id[4]/pairs[5]and writes four scalarbvh_box_tcalls with a branchless sorting network.Both edit the same lines, so at most one can land; the measurements in the two descriptions are the basis for choosing.
The box offsets (16/28 + 24k, 16 + 12k) and the sorting network match the old loop. The rebase onto main (
b1d353e4) carries thebvh_grow_lo/hibounds intobvh_box_tand keepstri_retand the bad-ray early return; it also turns the triangle path's ternaries intoselect.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by fixgep on 2026-12-01T17:29:27Z.
@Foniass Rebased onto
upstream/main(6bfb5c51->b1d353e4):bvh_grow_lo/bvh_grow_hi(preserving the pre-growthmn <= mxvalidity check),tri_ret, and thebad_rayearly return are now integrated intobvh_box_tandbvh_intersectalongside the scalar register / sorting-network path. Bothgpu_bvh_box_grow_nan_inactivation_and_tri_mode0andgpu_bvh_intersect_scalar_matches_referencepass on RTX 3060, and the paired 60 s smoke run is updated in the description.Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-03T11:13:09Z.
merge-check
base:
0c725d5da2head:
b1d353e446merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 3019 passed, 0 failed, 57 ignored; SKIPPED: 25, the same as base (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none. Base alone: 3015 passed, 1 failed, 56 ignored; the one was
cpu_watchdog_signal_with_inflight_gpu_signal_completes_cleanlywith E_OUTOFMEMORY in the parallel run, and it passed in 50 of 50 further runs of its modulereview: read the whole diff (2 files, +394 -33). The results are right; the speed-up is not there any more on this head.
bvh_intersectand this PR's into one compute shader and ran both on random nodes and rays (box32, box16, triangle types 0 to 3; ties, inverted boxes, NaN, infinities, signed zeros, all grow values, sort on and off). They gave the same four words in 65,536,000 of 65,536,000 cases, at the default level, at-O1and at-Od. About 4.8 million of the cases had a hit. A control with one sorting step removed differed in 112,386 cases.cargo test -p xcl --lib bvh: 29 passed, 0 failed withXCL_DIRECT_DXIL=0and with=1.dxil/lower_image.rs). So this change only reaches shaders that go through HLSL: the ones the direct translator refuses, or withXCL_DIRECT_DXIL=0.16c2fd08, a few commits earlier. Nothing undercrates/xcl/src/gpuchanged between the two.performance: slower on this card at the levels XCL normally uses. This is the PR's own
bench_cold_bvh_intersect_psoon that merge (debug build). Its baseline text is the same as main's code; I checked that by script.-O3)-O1(HLSL over 1 MB)-O0(HLSL over 8 MB)The order does not explain it: with the PR's form built first, one run each gave +38 % DXC time at the default level and +73 % at
-O1. The table in the description is from30985d3, before the rebase brought inbvh_grow_lo/bvh_grow_hi, and it is the only place that shows a gain at-O1and-O3. MarcosMDev and jeroenhaentjens had already measured a slower driver compile at those two levels on the old head. I did not look into which part of the new form costs DXC the time.verdict: not yet: the change is meant to make compiles faster, and on this head it makes them slower at the default level and at
-O1hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300, DXC 1.9.2602.17 / Claude Code (Claude Opus 5.5)
@fixgep could you rerun the benchmark on the rebased head? The description lists that rerun under Not tested.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.