Repository navigation
hk: run deep ray tracing pipelines as continuations on G17P (maxRayRecursionDepth 3 -> 31) - #278
Merged
Merged
Conversation
The ray tracing megakernel inlines every stage once per trace depth, so a closest-hit or miss with k trace sites costs (k * stages)^depth copies. G17P therefore reported a maxRayRecursionDepth of 3, and dEQP-VK.ray_tracing_pipeline.misc.recursiveTraces_*_4..15 were not supported. Pipelines deeper than that now split their raygen, closest-hit, miss and callable stages at every call with nir_lower_shader_calls, as the callable dispatcher already does, and run the parts from one scheduler loop. Every part, and the traversal with the intersection and any-hit stages inlined into it, is emitted once, so the code no longer grows with depth. Each call pushes a return record onto the invocation's scratch stack. Builtins a stage reads are hoisted to its entry, so resumed parts take them from their spills. The record carries the vertex position address instead, because an AABB hit has none to load. The stack is reserved for the declared depth and 31 callable frames. A call that would leave the reservation is skipped, so no call sequence can overflow it. A ray query or hit object that lives across a call, or hitObjectExecuteShaderEXT, keeps the inlined megakernel. Pipelines up to depth 3 compile exactly as before. G17P now reports the specification's maximum of 31. Signed-off-by: Diljit Singh <hey@djdev.me>
Author
|
Gate evidence for merging #278 (batch1, step 2 of a tree-checked sequence):
|
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
G17P reported
maxRayRecursionDepth = 3, sodEQP-VK.ray_tracing_pipeline.misc.recursiveTraces_{tri,AABB}_4..15(24 cases) were NotSupported, and applications that need deeper recursion could not create their pipelines.Why it was 3
The ray tracing megakernel inlines every stage once per trace depth (AGX has no call instruction). A closest-hit or miss shader with k trace sites therefore costs (k · stages)^depth copies, and
hk_rt_inlining_fits()refuses anything over 1 M instructions.What this changes
Pipelines with
maxPipelineRayRecursionDepth > 3now run their stages as continuations. Pipelines up to depth 3 compile exactly as before.traceRayEXT/executeCallableEXTwithnir_lower_shader_calls, as hk's callable dispatcher already does.hitObjectExecuteShaderEXT. Neither occurs in CTS above depth 3.Tests on the Neo (J700, G17P, kernel 7.3.0-neo.final)
The tested builds carry this commit's RT code on top of the RT CTS fix stack (#270-#274) and add a default-off diagnostic environment switch, not part of this PR, that forces continuation mode at every depth.
misc.recursiveTraces_{tri,AABB}_0..15AGX_MESA_DEBUG=shadersNIR+AIR dumps ofrecursiveTraces_tri_3, a nested-callable case and a trace-in-loop case are identical to the base (0 of 839,013 / 98,428 / 89,700 lines differ).ray_tracing_pipeline.*(8,442 cases, without the 1M-instance host builds)ray_query.*(4,988) and every 10thray_query.acceleration_structures.*(3,353)ray_tracing_pipeline.*case (2,111)rt.rays(4 configs) andrt.scenemedium/light, query andtrace=pipeline, 2 roundsForcing continuation mode at depth ≤ 3 is 2.2-2.4× slower on
rt.scene trace=pipeline(same images), so it stays limited to pipelines deeper than 3.Unit test
test-hk-rt-cache-controlbuilds a pipeline whose raygen, closest-hit and miss trace from every level, plus an any-hit and a recursive callable, at depths 3, 4, 8 and 31. It checks:meson test --suite asahipasses 131/131 in a debug build with asserts on (M5 local CI, since Actions is off for this repository).Known limitations
Merge
This merges after the Neo batch merge gate passes and
meson test --suite asahipasses on the exact merged tree.🤖 Generated with Claude Code