Creates a new ComputePass instance.
The graphics device.
Optionalcomputes: Compute[] = []
The compute instances the pass dispatches. Defaults to an empty array.
Frame passes which need to be executed after this pass. This pass does not own them, and does not destroy them: whoever adds a pass to the list destroys it.
Frame passes which need to be executed before this pass. The engine does not change this list, so the passes in it execute every frame this pass executes. This pass does not own them, and does not destroy them: whoever adds a pass to the list destroys it.
The compute instances the pass dispatches, in order. Add instances to the array, or remove them from it, to change them. The pass does not own them.
The graphics device.
True if the frame pass is enabled and execute function will be called. Note that before and after functions are called regardless of this flag. Set it before the frame renders, at the latest in frameUpdate, as the frame graph decides which passes to merge from it.
Called when the pass renders, right after it executes: for a render pass once its GPU render pass has ended, and after FramePass#after. The results the pass writes can be read back here, as a read records its copy when it is requested, and so right after the pass. Reads should not be immediate, as that submits the work of the frame recorded so far. Like after, it is called even if FramePass#executeEnabled is false, but not when the pass is disabled. A render pass with this callback is not merged with the pass after it into a single GPU render pass, so the callback runs outside of one.
Called when the pass renders, right before it executes: after FramePass#before, and for a render pass before its GPU render pass starts. Work recorded here, such as setting the parameters of the pass, or clearing a buffer it writes to, executes right before the pass. Like before, it is called even if FramePass#executeEnabled is false, but not when the pass is disabled. A render pass with this callback is not merged with the pass before it into a single GPU render pass, so the callback runs outside of one.
Gets whether the frame pass is enabled.
Sets whether the frame pass is enabled. A disabled pass is skipped when the frame is built, together with its FramePass#beforePasses and FramePass#afterPasses, and its frameUpdate is not called. To skip only the execution of the pass, while still updating it and its before and after passes, use FramePass#executeEnabled instead. Change it before the frame is built: the frameUpdate of a pass, or of its before-passes, cannot disable the pass itself. Defaults to true.
Gets the name of the pass.
Sets the name of the pass, which identifies it in debug output, GPU profiling and graphics debuggers. Defaults to the name of its class, which minified builds can shorten, so set it explicitly for a readable name.
Gets the index of the XR view the pass executes in.
Sets the index of the XR view the pass executes in, when the frame renders multiple XR views and the pass executes with the passes rendering them, such as in the before passes of a camera. It executes at its position in that view, after what the view renders before it, such as its depth prepass. Use -1 to execute it once before all the views, and so before what they render. When the frame does not render multiple XR views, or the pass executes outside of them, such as in the after passes of a camera, it executes when the index is -1 or 0. Defaults to 0.
Called while the pass renders, after FramePass#execute. It is called even when FramePass#executeEnabled is false and the pass did not execute, so an override using the results of the execution can skip that work while executeEnabled is false.
Called while the pass renders, before FramePass#execute. It is called even when FramePass#executeEnabled is false and the pass does not execute, so an override preparing only for the execution can skip that work while executeEnabled is false.
Releases the pass. It empties ComputePass#computes, without destroying the compute instances, which are destroyed by whoever created them.
Dispatches the compute instances in ComputePass#computes, in order, in a single compute pass labelled with FramePass#name. Does nothing when there are none.
Called each frame the pass is added to the frame, while the frame is built and before anything renders, and before its FramePass#beforePasses and FramePass#afterPasses are added. Override to update the pass for the frame, for example to resize its render targets, to set the textures it reads, to add or remove its before and after passes and enable or disable them, or to set its FramePass#executeEnabled. It cannot disable the pass itself. It is not called for a disabled pass, nor when the pass is rendered on its own with FramePass#render.
Called when the pass is disabled, by setting FramePass#enabled to false while it is true. Override to release what the pass does not need while it is disabled, such as its render targets.
Called when the pass is enabled, by setting FramePass#enabled to true while it is false. Override to recreate what FramePass#onDisable released.
Renders the pass, as FramePass#render describes. When the frame renders multiple XR views, it executes only in the view selected by ComputePass#xrViewIndex, and is skipped in the others.
A frame pass which dispatches a list of compute instances, in order, in a single compute pass. It schedules compute work at a position in the frame, for example after a camera renders, to process its scene depth and color maps in the same frame. To dispatch compute instances right away instead, when called, use GraphicsDevice#computeDispatch. Compute shaders are only supported on WebGPU, see GraphicsDevice#supportsCompute. On other devices the pass executes without dispatching anything.
Adding the pass to a frame
Add the pass to the CameraComponent#beforePasses or the CameraComponent#afterPasses of a camera, to dispatch it before or after the camera renders, or to the FramePass#beforePasses or FramePass#afterPasses of another pass. It can also be rendered on its own, with FramePass#render. Set its FramePass#name, which labels the dispatch in GPU profiling. The pass does not destroy its compute instances, and the camera does not destroy the pass: whoever creates them destroys them.
The dispatch
Each compute instance is dispatched with the dispatch size and parameters set on it, typically set before the frame renders, or in FramePass#onBefore. Use onBefore also to prepare the buffers the shaders write, for example to clear them, and FramePass#onAfter to read the results back, as a read requested there is recorded right after the dispatch. The pass executes at most once in a frame.
XR views
When the frame renders multiple XR views, ComputePass#xrViewIndex selects the view the pass executes in. As a compute instance is dispatched at most once in a frame, dispatching for several views needs a compute pass for each, with separate compute instances.
Example