Recompiler: emit DXR 1.1 RayQuery and acceleration-structure SRVs #3659
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3659"
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 Kalmarv on 2026-12-02T04:41:58Z.
Add direct-DXIL DXR 1.1
RayQueryemission andRaytracingAccelerationStructureSRV support togpu::dxil::Shader. Nothing calls the new helpers yet, so default runtime behavior is unchanged; Live caller: #3705 (XCL_HW_RT_TRAVERSE=1swaps GPURT traversal loops forheap_accel_struct+trace_any_hit/trace_translucent). Part of #1751.Related: #2189 lowers
RayQuerythrough the HLSL path (gpu/recomp/rayquery.rs); this PR is the direct-DXIL emitter (gpu/dxil), with no shared files.(Why this is 951 lines and not split further: ~205 lines are the direct-DXIL
RayQueryemitter andShaderplumbing, and ~746 lines are the DXIL 1.9 validator, shader-model guard, and WARP execution tests for this same emitter, kept together becauseCONTRIBUTING.mdrequires new code to ship with its tests.)What is in it
crates/xcl/src/gpu/dxil/ray_query.rs:RaytracingAccelerationStructureSRV bindings (statict#binding andResourceDescriptorHeapindexing requiring SM 6.6+, resource kind 16, U32 element type, PSV0SrvRaw).dx.op.allocateRayQuery(requiring SM 6.5+),rayQuery_TraceRayInline,rayQuery_Proceed,rayQuery_Abort,rayQuery_CommitNonOpaqueTriangleHit, andrayQuery_StateScalar/rayQuery_StateVector(committed and candidate status, type,t, barycentrics, instance index / ID, geometry, primitive, front face). State queries carryReadOnlyso optimization/CSE never merges or hoists them acrossProceed.Shader::trace_any_hit(opaque first-hit shadow query withSKIP_PROCEDURAL_PRIMITIVESso procedural AABB candidates cannot stall the single-Proceedsearch; the only planned producer (the opt-inXCL_HW_RTshadow builder) builds triangle geometry only) andShader::trace_translucent(FORCE_NON_OPAQUEProceedloop that commits back faces and tracks the nearest front face).t0and descriptor heap, using 48 single-triangle BLAS instances under one TLAS so the comparison tests DXIL emission without depending on WARP's multi-triangle BLAS builder, which dropped one triangle in one Windows CI run (not reproduced locally)), non-zero primitive index readout on a 2-triangle BLAS, first hit, procedural-AABB skip intrace_any_hit, translucent back-face commit,FRONT_COUNTERCLOCKWISE, negative-determinant mirrored instance transform (object-space winding per DXR spec),front1/back2, and fronts-only against a CPU walk andf64Möller–Trumbore reference.crates/xcl/src/gpu/dxil/shader.rs&crates/xcl/src/gpu/dxil/mod.rs:ray_query, addFeature::RaytracingTier1_1(metadata bit 25, container bit0x100000), addkind::RT_ACCELERATION_STRUCTURE(16), and register DXR 1.1 opcodes (178..=183NoUnwind,184..=212 | 214 | 215ReadOnly) indxc_fn_attrs.Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5 (01b62ad47).cargo build --release -p xcl(commit5bfb227466149a342e2b1a4e10cfdc4f8aef495a): succeeded, 39 warnings (0 new vsmain).cargo test -p xcl --lib -- gpu::dxil::ray_query --nocapture: 4 passed, 0 failed, 0 ignored (ray_query_kernels_validate,ray_query_rejects_sm_below_6_5,heap_accel_struct_rejects_sm_below_6_6,warp_ray_query_matches_console_bvh_walk), plus 100 pinned-affinity runs (50 at0xF, 50 at0x3,0/100failures)..\scripts\test.ps1(debug build + benches + workspace tests--test-threads=4, commit5bfb227466149a342e2b1a4e10cfdc4f8aef495a): 2978 passed, 0 failed, 52 ignored across 43 test binaries.no wave64(RTX 5070 Ti is wave32-only), 2no heap windows(XCL_HEAP_WINDOWSopt-in off by default).Regression run
Not tested
RayQuery(tested on WARP DXR 1.1 and validated with DXC 1.9 here; live shader traversal callers are in the stacked follow-up PRs).AI use
Claude Opus 5.5): wrote the direct-DXILRayQueryemitter and WARP reference tests, and audited the diff, optimizer safety (ReadOnlystate queries acrossProceed), and DXR object-space winding semantics.Gemini 4 Neon): extracted the standalone PR onmain, extended the WARP test suite for deterministic front/back-face, mirrored-transform, procedural-AABB, and single-triangle-instance BLAS semantics, applied review fixes, ran the full build/test/smoke suite, and drafted the PR description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:08:06Z.
Review (head
9c33b8cc, diff read, not a merge-check):accel_struct,ray_query*,trace_any_hitortrace_translucent, and no open PR does. #2189, the PR that does consume RayQuery, goes through the HLSL path. The direct-DXIL path lowersimage_bvh_intersect_rayone node at a time (gpu/dxil/lower_image.rs~979). Swapping that for a whole-traversal query needs a traversal-region matcher, and only the HLSL stack has one (#2188). So 1021 lines would land for a consumer whose shape is unknown, and nobody can check whether the two high-level helpers fit it. The size reason in the description (tests have to ship with the code) is fine. The missing consumer is the problem: hold this until the caller exists, or ship it stacked under the caller.trace_any_hitcan report a miss on a hit.gpu/dxil/ray_query.rs~135 callsProceedonce and assumes "all candidates are opaque". Per the DXR spec,FORCE_OPAQUEdoes not stop procedural (AABB) candidates being handed to the shader. If the structure holds AABB geometry, the firstProceedstops on that candidate andCOMMITTED_STATUSis stillCOMMITTED_NOTHING, so a shadow ray that would have hit a triangle further on comes back as a miss. Fix: addRAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES(0x200) to the constant flags, or loop the waytrace_translucentdoes.ray_query.rs~728-822 rebuilds the scene up to twice when it sees a "dropped triangle" pattern, and ~381 scansd3d10warp.dllfor its file version. The description says the retry never ran in 940/940 runs once the scene got its own submit. As written, though, a real regression that loses hits on one triangle in a fresh build passes on a retry. The cause was never found. Dropping the retry and failing hard would keep the test strict and make it much shorter.finish()feature drop is untested and probably never fires.shader.rs~550 removesRaytracingTier1_1when noallocateRayQuerysurvives. ButallocateRayQueryisNoUnwindand not inremovable's prefix list (module/opt.rs~523-531), and its result feeds a voidTraceRayInline, so DCE never removes it. No test builds a shader where the drop happens. Also,ray_query(~75) andheap_accel_struct(~69) do not checkself.sm. A caller that builds a shader below SM 6.5 (6.6 for the heap path) only finds out if validation runs.Fine: by reading, the
dx.opopcodes 178-182 and 184-215, the overload suffixes (Proceed.i1,StateScalar.i32/f32/i1,StateVector.f32with ani8component) and the function attributes (NoUnwindfor allocate/trace/proceed/abort/commit,ReadOnlyfor state reads, 213 left out) all match DXC. Shader flag bit 25 and container bit 0x100000 are right, and so are resource kind 16 withstruct.RaytracingAccelerationStructure, U32 element type and PSVSrvRaw. The optimizer only CSEsReadNonecalls, so state reads are not merged acrossProceed. No file overlap with #3662, which only hooks the builder DLL.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T10:35:45Z.
merge-check
base:
1c8b551475head:
9c33b8cc57merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 2 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: hle::d3d12x::uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom, hle::d3d12x::uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3659#issuecomment-7340427796 and its findings stand. Most serious: 1021 lines with no caller, and
trace_any_hitcan report a miss when the ray meets AABB geometry. The 2 failing tests are this machine's intermittentuma_driver"Map gave X, wanted Y" failures, seen on other PRs and not in code this PR touches.performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (9c33b8cc): 1652 -> 1688 frames shown (102 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 17001 MB, 0 device removals, 0 crashes.verdict: not yet: 1021 lines with no caller, and
trace_any_hitcan report a miss when the ray meets AABB geometry (see the review); the build, the rest of the suite and the smoke run are finehardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T14:17:43Z.
@Foniass Thanks for the review! Rebased onto
main(5eaadb54c) and updated tobd104a36b:trace_any_hitprocedural AABB handling: addedRAY_FLAG_SKIP_PROCEDURAL_PRIMITIVES(0x200) totrace_any_hitso procedural AABB candidates cannot stop the single-Proceedsearch before a triangle behind them.ray_query_kernels_validatenow asserts the emittedallocateRayQueryflags (i32 525) and fails without the flag; we also added a WARP procedural-AABB + triangle case (though on WARP 10.0.26100 that WARP check still passes without the flag, likely due to TLAS instance visit order, so the disassembly check is what pins the flag). Note also that the only planned producer (the opt-inXCL_HW_RTshadow builder) builds triangle geometry only.finish()feature drop: removed the untestedinfer_type_features()RaytracingTier1_1removal andShader::calls(), and addedassert!(self.sm >= (6, 5))inray_query()andassert!(self.sm >= (6, 6))inheap_accel_struct()with#[should_panic]unit tests.d3d10warp.dllscanner: removed the ~150-line retry loop and version scanner; kept the own-submitbuild_sceneand fail hard immediately on any mismatch.heap_accel_struct,trace_any_hit, andtrace_translucent) are opening right behind this PR; I will link the live caller PR here as soon as it is open.Verified
bd104a36bwithcargo build --release -p xcl(39 warnings, 0 new),scripts/test.ps1(2978 passed, 0 failed, 52 ignored, 24 SKIPPED GPU on RTX 5070 Ti), and a fresh 60 s smoke pair against5eaadb54c.AI use: Antigravity (Gemini 4 Neon) applied the fixes and ran the build/test/smoke verification; Claude Code (Claude Opus 5.5) reviewed the diff and drafted the verification checks.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T14:32:58Z.
Note on the
Build and test (Windows, no GPU)failure onbd104a36b(warp_ray_query_matches_console_bvh_walkmissed a closer triangle on ray 41 and hit the triangle behind it): investigating by pinning the test to 2–4 cores to reproduce and test build flags (or split the 48-triangle BLAS into 1-triangle BLASes under one TLAS if WARP's multi-triangle builder is nondeterministic) rather than rerunning or re-adding a retry.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T15:06:52Z.
Updated in
5bfb22746to fix the Windows CI failure onwarp_ray_query_matches_console_bvh_walkwithout adding a retry:bd104a36bon locald3d10warp.dll10.0.26100.9711at reduced core counts:0/100failures at affinity0xF(4 cores),0/100at0x3(2 cores), and0/100across 4-way concurrent runs on0xF(0/300total; did not reproduce locally).crates/xcl/src/gpu/dxil/ray_query.rs): Restructuredbuild_sceneto build 48 separate 1-triangle BLASes under one TLAS of 48 identity instances ([instance_index, instance_id, geometry, primitive] == [prim, 7, 0, 0]) so the strict console-walk comparison tests our DXIL emission without depending on WARP's multi-triangle BLAS builder (which dropped one triangle in one Windows CI run). Added an explicit non-zeroCOMMITTED_PRIMITIVE_INDEX([0, 1, 0, 1]) check on the 2-triangleblas_fbinsem_tlasso multi-primitive index readout stays covered.gpu::dxil::ray_query(4/4), 100 pinned affinity runs (50at0xF+50at0x3,0/100failures), fullscripts/test.ps1, and fresh back-to-back default smoke; PR body updated.Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T16:00:54Z.
Live caller is now open: #3705 (
XCL_HW_RT_TRAVERSE=1swaps GPURT traversal loops forheap_accel_struct+trace_any_hit/trace_translucent, stacked on #3704, #3700, #3697, and #3662). Added the link to the PR body as well.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T18:02:59Z.
merge-check
base:
5eaadb54c1head:
5bfb227466merge: clean
build: ok
tests: 2978 passed, 0 failed, 52 ignored; 28 skipped, the same as on main
review: 2 medium, 2 nits (below)
performance: 60 s smoke run: 1422 → 1659 frames (116 % of main), peak commit 17184 → 16435 MB, no device removal, no crash
title run: not run
verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Follow-up on
5bfb2274; my last review was on9c33b8cc. The PR adds DXIL emitters for inline ray queries (gpu/dxil/ray_query.rs) with GPU tests against WARP. Three of the four earlier findings are fixed. The one left (nothing calls the new helpers yet) is allowed by CONTRIBUTING and is the maintainer's call. Nothing blocks: the suite passes and the smoke run is clean.Medium
gpu/dxil/ray_query.rscallsaccel_struct,ray_query*,trace_any_hitortrace_translucent, so their shape isn't checked against a real consumer. The hw_rt PRs opened since (#3697 / #3700 / #3704 / #3705) may be those consumers; this review didn't check them. CONTRIBUTING allows new code that isn't called yet.Nit
DXIL:, which isn't in the AGENTS.md list; the PR title usesRecompiler:.Checked and fine
trace_any_hitno longer misses a hit behind AABBs (flags 0x20D,ray_query.rs~139, with a disassembly assert at ~343-347).finish()feature drop is removed, with SM 6.5 / 6.6 guards (~71, ~78) andshould_panictests.dxc_fn_attrsarms and the PSVSrvRaw/ kind 16 arm apply only when RayQuery ops or acceleration-structure bindings are emitted, and nothing emits them yet.How this was tested
5eaadb54, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main5eaadb54and on this merge; presents per 2 s at the end: 60 60 60.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-02T19:12:16Z.
merge-check
base:
c53e969602head:
5bfb227466verdict: not yet: the emitted DXIL and shader-model guards passed, and the workspace abort was shared with main. The WARP runner lacked DXR 1.1 on this host, so this report did not verify ray-query results against the BVH reference.
Windows / AMD RDNA4 (native D3D12) — DXIL inline ray-query validation on
5bfb227Clean merge onto
mainatc53e969(merge commitf6e66b56178ccd8bd3acbea4aaa01cd16693cfea).git diff --checkwas clean.Setup
d3d12SDKLayers.dll, DXC 1.9.2609.5Tested
cargo build --workspacepassed.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both builds. The baseline table row is from a prior run of the same commit, machine, SDK, and command.SKIPPEDnoticesmainCounts are partial because two test processes aborted on each build.
main— none observed in comparable results.--test-threads=1 --show-output --nocapture. One of those returned withSKIPPED no DXR 1.1 on WARP, so 3 checks exercised their assertions. The validator test passed, and both lower shader-model guards panicked as expected (RayQuery below 6.5, heap acceleration-structure SRV below 6.6).uploads_start_from_each_subresources_statepassed.Shared failures and process aborts
fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsreported failures on both builds.gpu_compute_e2etest processes exited with0xc0000409on both builds.Diff review
The selected checks covered emitted ray-query kernels and the shader-model gates. The execution fixture explicitly selects WARP, which lacked DXR 1.1 on this host.
Not tested
Remaining workspace tests after the aborts, ray-query execution against the BVH reference on WARP or the AMD hardware, and retail smoke (tier 1).
AI use
Codex (GPT-6) merged and built the PR, ran the tests, compared the results with
main, reviewed the diff, and drafted this report.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:54Z.
Code review location:
crates/xcl/src/gpu/dxil/ray_query.rs; line 62Medium:
ray_queryonly requires SM 6.5, but both ways to get an acceleration structure need SM 6.6:accel_struct(no guard) andheap_accel_struct(guarded at 6.6).Shader::new(_, (6, 5))plusaccel_struct(0, 0)andtrace_any_hitpasses every assertion but emitscreateHandleFromBinding/annotateHandle(ops 217/216), which only exist in SM 6.6, so the output is invalid DXIL. The 6.5 guard andray_query_rejects_sm_below_6_5claim support the builder can't produce. Adding the 6.6 assert toaccel_struct(or raisingray_query's guard) would make it consistent.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:55:54Z.
Review: COMMENTED
Review of
5bfb2274: 2 finding(s) (2 medium), most severe first.crates/xcl/src/gpu/dxil/shader.rs:510: see below.crates/xcl/src/gpu/dxil/ray_query.rs:62:ray_queryonly requires SM 6.5, but both ways to get an acceleration structure need SM 6.6:accel_struct(no guard) andheap_accel_struct(guarded at 6.6). (inline)On lines outside the diff:
crates/xcl/src/gpu/dxil/shader.rs:510:infer_type_featuresnever clearsFeature::RaytracingTier1_1when the optimizer removes every RayQuery op, though it does for heap indexing, int64 atomics and the other flags. If a translated shader callstrace_any_hitin a branch thatoptimize()folds away as unreachable,ray_query()has already set the feature, so the container declares Raytracing tier 1.1 with no RayQuery op left, and the validator rejects the shader with 'Flags must match usage', the caseinfer_type_featuresexists to prevent. Recomputing the flag from the remaining ops would fix it.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T19:56:00Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.