[Metal] Make dispatchRays a self-contained encoder operation#1346
Open
MarijnS95 wants to merge 1 commit into
Open
[Metal] Make dispatchRays a self-contained encoder operation#1346MarijnS95 wants to merge 1 commit into
MarijnS95 wants to merge 1 commit into
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
176f60b to
9d708d8
Compare
This comment was marked as resolved.
This comment was marked as resolved.
The DX and Vulkan backends record a ray dispatch by creating an encoder and calling Encoder.dispatchRays() directly. Metal instead went through createRayTracingCommands, a device method that bound the descriptor heap and argument buffer, built and bound the IRDispatchRaysArgument, marked the RT resources resident, and only then called a thin dispatchRays(). Since Metal lowers raygen to a compute kernel, ray tracing now records through the shared createComputeCommands path (which already binds the heap and argument buffer and marks the common resources resident) by branching on P.isRayTracing(). The IRDispatchRaysArgument setup and RT-specific residency move into MTLComputeEncoder::dispatchRays, defined out-of-line so it can allocate via CB->Dev and keep the buffer alive in CB->KeepAliveOwned. The heap address for ResDescHeap, absent from the cross-backend signature, is remembered on the encoder via bindResourceHeap(). createRayTracingCommands is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
9d708d8 to
f3899bd
Compare
manon-traverse
approved these changes
Jun 30, 2026
EmilioLaiso
approved these changes
Jun 30, 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.
The DX and Vulkan backends record a ray dispatch by creating an encoder and calling
Encoder.dispatchRays()directly. Metal instead routed throughcreateRayTracingCommands, anMTLDevicemethod that bound the descriptor heap and top-level argument buffer, synthesized and bound theIRDispatchRaysArgument, marked the RT resources resident, and only then called a thindispatchRays().Since Metal lowers raygen to a compute kernel, ray tracing now records through the shared
createComputeCommandspath — which already binds the heap and argument buffer and marks the common resources resident — by branching onP.isRayTracing(). TheIRDispatchRaysArgumentconstruction, upload, binding, and RT-specific residency move intoMTLComputeEncoder::dispatchRays, defined out-of-line so it can allocate viaCB->Devand keep the buffer alive inCB->KeepAliveOwned.IRDispatchRaysArgument::ResDescHeapneeds the resource heap address, which isn't in the cross-backenddispatchRayssignature, so the encoder remembers the bound heap viabindResourceHeap().createRayTracingCommandsis removed.No behavioral change.
check-hlsl-mtl-feature-rtandcheck-hlsl-mtl-basicpass.