Skip to content

Bind compute PSO inside ComputeEncoder::dispatch()#1217

Merged
MarijnS95 merged 1 commit into
llvm:mainfrom
Traverse-Research:dispatch-pso
May 27, 2026
Merged

Bind compute PSO inside ComputeEncoder::dispatch()#1217
MarijnS95 merged 1 commit into
llvm:mainfrom
Traverse-Research:dispatch-pso

Conversation

@MarijnS95

@MarijnS95 MarijnS95 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

ComputeEncoder::dispatch() now takes a PipelineState & as its first argument and binds the PSO before issuing the dispatch, the same shape as RenderEncoder::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 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 compute PSO bind in createComputeCommands() (DX, VK, MTL) is removed.

🤖 Generated with Claude Code

Comment thread lib/API/MTL/MTLDevice.cpp Outdated
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>
@MarijnS95 MarijnS95 merged commit c967959 into llvm:main May 27, 2026
@MarijnS95 MarijnS95 deleted the dispatch-pso branch May 27, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants