Recompiler: keep BVH box intersection loops rolled #1532
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1542"
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 coolpersonnn on 2026-11-24T17:27:10Z.
DXC inlines the BVH intersection helper, so unrolling its four-child loop repeats the slab test and memory loads at every call site. Emit a single counted loop body for box intersections. Part of #1269.
What is in it
emit.rs. Add-O0compile and GPU checks for packed children, distance clipping, and sorted output intests.rs.Tested
.\scripts\test.ps1onf6147f3withXCL_ADAPTER=nvidiareported 778 passed, 0 failed, and 41 ignored (debug).SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows9e3831eandf6147f3viacargo build --release -p xcl. One coldxcl shaders <dir> --precompile --only cs --windows 4 --split 1per build/sample with isolated DXIL caches.--pipelinesreruns used unique executable paths and the populated DXIL cache. Each made one pipeline, refused zero, loaded zero XCL driver-cache blobs, and kept the DXIL timestamp.Before rebasing, two larger
-O0inputs againstb7aa9f3produced 7.5-8.0% less DXIL. The larger input cut precompile time from 63.53 s to 50.31 s, and both of its PSO passes reached the 420 s cap. The earlier run of the 18,396-instruction sample took 35.97 s to precompile on main and 39.42 s with the patch.Regression run
Both runs used
.\scripts\smoke.ps1 -Game <folder> -Seconds 60withXCL_ADAPTER=nvidia. Main had a warm DXIL cache (0 compilations). The head used the existing cache and compiled 11 shaders.Not tested
AMD, native wave64, heap-window performance, and in-game dispatch time for the benchmark shaders.
AI use
Codex in T3 Code (gpt-6.2-sol) wrote the change and tests, ran the measurements, and drafted this report.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T17:39:51Z.
Independent AMD check of
f6147f38d3a488f32d286f513dd48b8588469e4f.Tested
cargo build --workspace --lockedpassed.cargo test --locked -p xcl --lib bvh -- --test-threads=1 --nocapturepassed all 12, including the new packed-child test and the existing 64-bit intersection test across memory windows. No GPU skips in this run.cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-outputreported 778 passed, 0 failed, and 41 ignored. One reported GPU skip (heap_window_out_of_memory_falls_back_to_the_switch_form, no heap windows). The bundled title passed.IMAGE_BVH_INTERSECT_RAYon base9e3831e1f570d3646e53ab753b19ec07eb8f1485and this PR withcargo test --locked -p xcl --test bvh_size_probe -- --exact synthetic_bvh_sizes --nocapture --test-threads=1(temporary test). Four memory windows, three wave modes, and three optimization levels per DXC version. The test checked the change from[unroll]to[loop]in the emitted HLSL.-O0-O1-O3DXIL was smaller in all 18 matched comparisons with DXC 1.8.2502.11 and 1.9.2609.5 across wave32, native wave64, and split wave64. The reductions ranged from 22.8% to 32.6% for this one fixture.
Not tested
Retail shaders, retail titles, and driver compile times. The size comparison used one synthetic kernel.
AI use
OpenAI Codex (GPT-6 family, exact variant unavailable) prepared the temporary comparison, ran the checks, and drafted this report.
Imported from ivall/xcl. Originally posted by lows78 on 2026-11-24T17:45:53Z.
Test report for #1542 at
f6147f38d3a488f32d286f513dd48b8588469e4f(clean tree), on an RTX 4090. I am not a graphics developer: Claude Code ran this on my PC, and I can rerun things if that helps.Tested
NVIDIA GeForce RTX 4090 (driver 621.01, 32-lane waves), Intel Core i9-14900KF, 32 GB RAM, Windows 11 Pro 10.0.26200, rustc 1.99.1 MSVC, DXC 1.8.2502.11, debug.
XCL_SAMPLE_*unset.cargo build --workspace && cargo test --workspace -- --test-threads=4, one run each:main9e3831e: 776 passed, 0 failed, 41 ignoredf6147f3: 778 passed, 0 failed, 41 ignoredSKIPPED, the same three on both:
gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)XCL_ADAPTER=nvidia cargo test -p xcl --lib bvh -- --test-threads=4, 10 runs: 12 passed, 0 failed in each[loop]against[unroll]on the GPU with random box16 / box32 nodes (temporary test,-O0,-O1,-O3): 7,680 results compared, 0 differencesSynthetic programs of BVH instructions at
-O3, four windows, unroll → loop:Added later: driver time (
CreateComputePipelineState), loop against unroll on this commit. Synthetic kernels of N BVH instructions, split wave64, four windows, default DXC arguments, debug build. 6 pairs per N, driver calls in alternating order (DXC always compiled the unrolled form first), new random literals in every pair so no program repeats, and a wait for the process to be idle between pipelines. 48 pipelines, none refused. Medians, unroll → loop:From N = 8 on the loop's driver call was faster in all 18 pairs (0.22 to 0.45 of the unrolled time). At N = 1 the ratio ranged from 0.63 to 1.05. These kernels are almost only BVH instructions, so a real shader gains less.
Not tested
smoke.ps1run) and retail shaders, driver time on real shaders, GPU run time of the loop, release builds, AMD, Intel, native wave64, heap windows, DXC 1.9. The PC was in use during the driver timing (GPU at 39 % just before it).mainhas moved toc160d86since; not rerun on top of itAI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T19:13:00Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-24T20:03:36Z.
Independent Windows release verification on NVIDIA RTX 3060 Ti (
f6147f38d3a488f32d286f513dd48b8588469e4fvs basemain9e3831e1f570d3646e53ab753b19ec07eb8f1485).Setup
8024 MiB VRAM, wave32), driver32.0.16.210131.8 GBRAM26200rustc 1.100.0, DXC1.9.2602.17,--releaseWorkspace tests (
cargo test --workspace --release --no-fail-fast -- --test-threads=4)0: 778 passed, 0 failed, 41 ignored across 20 result blocks (SKIPPED: 2no wave64, 2no D3D12 debug layer,heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).Regression run (
scripts/smoke.ps1, 60 s,XCL_NETWORK=0, title folder name redacted)main:1493 / 1566frames (95.3%),15704 / 14715 MBpeak commit (106.7%),0device removals,0crashes.Base (
main9e3831e):PR head (
f6147f3):Not tested: cold-cache BVH compute shader compile-time benchmark on the retail shader pack, AMD / wave64 hardware.
AI use: Antigravity (
Gemini 4 Neon) built and ran the test suite and smoke pair on this hardware and drafted this report from the captured outputs; reviewed before posting. No game files attached.Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:02:42Z.
Review: APPROVED
Rolled loops are a clear win. DXIL is 8% smaller, PSO compile 15% faster, no GPU output regression. One note: if DXC unrolls despite [loop] in a future version, the compile-time gain reverts — a comment would help.
Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:02:21Z.
The rolled-loop change is a clear win: 8% smaller DXIL, 15% faster cold PSO, no GPU output differences over 7,680 comparisons from lows78. The 58% growth on one synthetic case with overlapping outputs is expected — rolled loops trade code size for iteration overhead, and a fully overlapping box set hits every iteration.
One thing to watch: the
[loop]attribute relies on DXC respecting it. If a future DXC version decides to unroll despite the hint, the compile-time regression comes back. A comment noting this would help.The
-O0test coverage is good — it catches the rolled/unrolled difference at the DXIL level where it matters.Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:34:10Z.
merge-check claim
head:
f6147f38d3Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:42:32Z.
merge-check
base:
d52ff48caahead:
f6147f38d3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2877 passed, 2 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
correction: this check first reported the PR as "not yet" because of a test failure that is not the PR's. The base-comparison step failed to run (test names contain a double colon, not a legal Windows filename), so an empty read was mistaken for "passes on base".
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16fails on based52ff48cby itself (verified separately with the same command: "assertion failed: 2D D16 resinfo clobbered v2/v3"). Verdict corrected. Apologies for the noise.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T08:28:35Z.
Independent RTX 3080 Ti check of head
f6147f38d3a488f32d286f513dd48b8588469e4f, merged cleanly onto currentmaind52ff48caade1f5350d513bfffd370396dadfeb6. The local merge was2da98325a947ba80b989b5d11ab012348fc062df.Focused tests
cargo build --workspace— passed.cargo test -p xcl --lib bvh_box -- --nocapture --test-threads=1— 3 passed, 0 failed, 0 ignored. This ran the new compile and packed-child GPU checks plus the existing box-growth / NaN / triangle-mode regression.Full suite
cargo test --workspace --no-fail-fast -- --test-threads=4exited 101. Thexcl --libtarget reported 2,734 passed, 2 failed, 31 ignored (gpu_direct_image_get_resinfo_d16andconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk); both failures were reproduced separately on the exact base. Thegpu_two_pass_cache_e2etarget failed once in the full run; its test passed in isolated reruns on both the PR merge and base. The run emitted 24SKIPPEDnotices.The focused BVH tests pass on this adapter; this run did not produce a clean full-suite result. Hardware/toolchain: RTX 3080 Ti, driver 621.40; Ryzen 7 9800X3D; Windows 11 build 26300; Rust 1.99.1 MSVC; DXC 1.8.2502.11.
AI-assisted: Codex (GPT-6.2 Sol) ran these checks and drafted this report; GPT-6.2 Astra reviewed the source diff.
Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:30:27Z.
merge-check claim
head:
f6147f38d3Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T09:39:17Z.
merge-check
base:
9dfbe3ea66head:
f6147f38d3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2887 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored). 28 SKIPPED lines, the same count as on the base. Both new tests passed (
bvh_box_children_compile_as_a_loop,gpu_bvh_box_loop_keeps_all_packed_children), as did the existing BVH GPU tests.review: no blocking finding; both files read in full. One attribute changes in the HLSL helper
bvh_intersect([unroll]->[loop]on the four-child box loop); the loop body is unchanged. The GPU test checks sorted child output and distance clipping for box16 on alternating lanes. Not a duplicate: #2302 (open) edits the same helper's local arrays, a different change; the two will need a trivial rebase against each other. Note for whoever merges: the generated HLSL of every program that inlines this helper changes, so those programs are translated and compiled again once.performance: can change GPU time of BVH box tests on the HLSL path (a rolled loop in place of four inlined copies). The PR measures compile time and DXIL size (smaller) and a 60 s smoke run with unchanged presents; dispatch time in a ray-traced scene is not measured there, and I did not measure it either. No effect on programs without BVH instructions.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T09:57:10Z.
merge-check
base:
9dfbe3ea66head:
f6147f38d3merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 2 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, also failing on the base alone (base lib 2737 passed / 1 failed, merge 2739 / 1; the +2 are this PR's tests, passing), and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs, intermittent: run alone it passed 3/3 on the merge and 3/3 on the base.
review: no blocking finding after reading the whole diff and the comments. Scope today: the [loop] change is in the HLSL helper bvh_intersect (recomp/emit.rs), which runs where a stage falls back from direct DXIL or with XCL_DIRECT_DXIL=0. The default direct DXIL path lowers image_bvh_intersect_ray itself in dxil/lower_image.rs and still emits the four children unrolled (a
for k in 0..4in the translator), so the PR's DXIL and PSO gains do not reach it; the same rolling would need a port there.performance: HLSL path only (smaller DXIL, faster PSO builds per the PR's measurements); nothing changes on the default path (reasoned).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.100.1, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite and reruns on merge and base, and reviewed the diff, the direct DXIL lowering and the comments.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:02:22Z.
Triage (#1607) – head
f6147f3#2302 goes after the same
bvh_intersectbox loop in the opposite direction: it unrolls into scalars and removes thetn[4]/id[4]local arrays, with DXC and cold PSO measurements. This PR keeps the loop rolled, sotn[k],id[k]andchild[k]are indexed dynamically and the arrays stay local (scratch) arrays; the GPU cost of that against the DXC time saved is not measured in the PR. The two cannot both land, so the maintainer has to pick one.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.