29. Dispatching Commands
Dispatching commands (commands with Dispatch
in the name) provoke
work in a compute pipeline.
Dispatching commands are recorded into a command buffer and when executed by
a queue, will produce work which executes according to the bound compute
pipeline.
A compute pipeline must be bound to a command buffer before any dispatch
commands are recorded in that command buffer.
To record a dispatch, call:
// Provided by VK_VERSION_1_0
void vkCmdDispatch(
VkCommandBuffer commandBuffer,
uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ);
-
commandBuffer
is the command buffer into which the command will be recorded. -
groupCountX
is the number of local workgroups to dispatch in the X dimension. -
groupCountY
is the number of local workgroups to dispatch in the Y dimension. -
groupCountZ
is the number of local workgroups to dispatch in the Z dimension.
When the command is executed, a global workgroup consisting of
groupCountX
× groupCountY
× groupCountZ
local workgroups is assembled.
To record an indirect command dispatch, call:
// Provided by VK_VERSION_1_0
void vkCmdDispatchIndirect(
VkCommandBuffer commandBuffer,
VkBuffer buffer,
VkDeviceSize offset);
-
commandBuffer
is the command buffer into which the command will be recorded. -
buffer
is the buffer containing dispatch parameters. -
offset
is the byte offset intobuffer
where parameters begin.
vkCmdDispatchIndirect
behaves similarly to vkCmdDispatch except
that the parameters are read by the device from a buffer during execution.
The parameters of the dispatch are encoded in a
VkDispatchIndirectCommand structure taken from buffer
starting
at offset
.
The VkDispatchIndirectCommand
structure is defined as:
// Provided by VK_VERSION_1_0
typedef struct VkDispatchIndirectCommand {
uint32_t x;
uint32_t y;
uint32_t z;
} VkDispatchIndirectCommand;
-
x
is the number of local workgroups to dispatch in the X dimension. -
y
is the number of local workgroups to dispatch in the Y dimension. -
z
is the number of local workgroups to dispatch in the Z dimension.
The members of VkDispatchIndirectCommand
have the same meaning as the
corresponding parameters of vkCmdDispatch.
To record a dispatch using non-zero base values for the components of
WorkgroupId
, call:
// Provided by VK_VERSION_1_1
void vkCmdDispatchBase(
VkCommandBuffer commandBuffer,
uint32_t baseGroupX,
uint32_t baseGroupY,
uint32_t baseGroupZ,
uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ);
or the equivalent command
// Provided by VK_KHR_device_group
void vkCmdDispatchBaseKHR(
VkCommandBuffer commandBuffer,
uint32_t baseGroupX,
uint32_t baseGroupY,
uint32_t baseGroupZ,
uint32_t groupCountX,
uint32_t groupCountY,
uint32_t groupCountZ);
-
commandBuffer
is the command buffer into which the command will be recorded. -
baseGroupX
is the start value for the X component ofWorkgroupId
. -
baseGroupY
is the start value for the Y component ofWorkgroupId
. -
baseGroupZ
is the start value for the Z component ofWorkgroupId
. -
groupCountX
is the number of local workgroups to dispatch in the X dimension. -
groupCountY
is the number of local workgroups to dispatch in the Y dimension. -
groupCountZ
is the number of local workgroups to dispatch in the Z dimension.
When the command is executed, a global workgroup consisting of
groupCountX
× groupCountY
× groupCountZ
local workgroups is assembled, with WorkgroupId
values ranging from
[baseGroup*
, baseGroup*
+ groupCount*
) in each
component.
vkCmdDispatch is equivalent to
vkCmdDispatchBase(0,0,0,groupCountX,groupCountY,groupCountZ)
.