Bind compute PSO inside ComputeEncoder::dispatch()#1217
Merged
Conversation
dispatch() now takes a PipelineState argument and binds it before issuing the dispatch, the same shape as RenderEncoder::drawInstanced(). Making the PSO a required parameter of dispatch() enforces at the type level that callers cannot forget to bind a pipeline (an invalid dispatch on every backend), and keeps the bind adjacent to the command it applies to instead of relying on a separate "last bound" state on the command list. It also hides per-API requirements behind the encoder: on Metal the threadgroup-size from the HLSL numthreads() annotation is read from shader reflection at pipeline creation and cached on MTLPipelineState, instead of leaking out as a setThreadGroupSize() call every caller had to remember. dispatch() just consumes the cached size, and we drop the encoder-state helpers ThreadsPerGroup / setThreadGroupSize() entirely. With the bind moved, the per-backend PSO bind in createComputeCommands() (DX, VK, MTL) is removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
manon-traverse
approved these changes
May 27, 2026
EmilioLaiso
approved these changes
May 27, 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.
ComputeEncoder::dispatch()now takes aPipelineState &as its first argument and binds the PSO before issuing the dispatch, the same shape asRenderEncoder::drawInstanced().Making the PSO a required parameter enforces at the type level that callers cannot forget to bind a pipeline (an invalid dispatch on every backend), and keeps the bind adjacent to the command it applies to instead of relying on separate "last bound" state on the command list. It also hides per-API requirements behind the encoder: on Metal the threadgroup-size from the HLSL
numthreads()annotation is read from shader reflection at pipeline creation and cached onMTLPipelineState, instead of leaking out as asetThreadGroupSize()call every caller had to remember.dispatch()just consumes the cached size, and we drop the encoder-state helpersThreadsPerGroup/setThreadGroupSize()entirely. With the bind moved, the per-backend compute PSO bind increateComputeCommands()(DX, VK, MTL) is removed.🤖 Generated with Claude Code