Last updated: 2026-09-07

Vulkan Runtime

Vulkan Command

All API Sections

Create reusable compute command pools and command buffers.

The decode runtime uses these wrappers to record dispatches, insert barriers, and synchronize submitted compute work.

2 exports 23 methods src/vulkan/command.zig

2 exports shown

struct

CommandPool

#
pub const CommandPool = struct

Command pool for allocating command buffers.

src/vulkan/command.zig:57

Methods

2

method

CommandPool.init

#
pub fn init(instance: *const Instance) !CommandPool

Create a command pool bound to the selected compute queue family.

Parameters
instance
Active Vulkan instance and logical device.
Returns

A CommandPool ready to allocate compute command buffers.

src/vulkan/command.zig:66

method

CommandPool.deinit

#
pub fn deinit(self: *CommandPool) void

Destroy the underlying Vulkan command pool.

Parameters
self
Command pool to tear down in place.

src/vulkan/command.zig:89

struct

CommandBuffer

#
pub const CommandBuffer = struct

A recorded command buffer that can be submitted and replayed.

src/vulkan/command.zig:96

Methods

21

method

CommandBuffer.init

#
pub fn init(instance: *const Instance, pool: *const CommandPool) !CommandBuffer

Allocate a primary command buffer and fence from a compute command pool.

Parameters
instance
Active Vulkan instance and logical device.
pool
Command pool used for command buffer allocation.
Returns

A CommandBuffer paired with a completion fence.

src/vulkan/command.zig:110

method

CommandBuffer.begin

#
pub fn begin(self: *CommandBuffer) !void

Begin recording a reusable command buffer.

Parameters
self
Command buffer to begin recording into.
Returns

`error.BeginCommandBufferFailed` when Vulkan rejects the begin request.

Notes

Use `reset()` or wait for prior submissions before recording into the same buffer again.

src/vulkan/command.zig:150

method

CommandBuffer.beginOneTime

#
pub fn beginOneTime(self: *CommandBuffer) !void

Begin recording for a single submit-and-discard style workload.

Parameters
self
Command buffer to begin recording into.
Returns

`error.BeginCommandBufferFailed` when Vulkan rejects the begin request.

Notes

This sets `VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT` so the driver can optimize transient work.

src/vulkan/command.zig:166

method

CommandBuffer.dispatch

#
pub fn dispatch( self: *CommandBuffer, pipeline: *const Pipeline, descriptor_set: vk.c.VkDescriptorSet, group_count_x: u32, group_count_y: u32, group_count_z: u32, ) void

Record a compute dispatch with an already-created descriptor set.

Parameters
self
Command buffer currently being recorded.
pipeline
Compute pipeline to bind before dispatch.
descriptor_set
Descriptor set bound at set `0`.
group_count_x
Workgroup count in the X dimension.
group_count_y
Workgroup count in the Y dimension.
group_count_z
Workgroup count in the Z dimension.
Notes

This helper binds pipeline and descriptors only; required barriers must be recorded separately.

src/vulkan/command.zig:186

method

CommandBuffer.dispatchWithPush

#
pub fn dispatchWithPush( self: *CommandBuffer, pipeline: *const Pipeline, descriptor_set: vk.c.VkDescriptorSet, push_data: []const u8, group_count_x: u32, group_count_y: u32, group_count_z: u32, ) void

Record a compute dispatch that also uploads a serialized push-constant block.

Parameters
self
Command buffer currently being recorded.
pipeline
Compute pipeline to bind before dispatch.
descriptor_set
Descriptor set bound at set `0`.
push_data
Raw bytes copied into the pipeline's push-constant range at offset `0`.
group_count_x
Workgroup count in the X dimension.
group_count_y
Workgroup count in the Y dimension.
group_count_z
Workgroup count in the Z dimension.
Notes

The caller is responsible for matching `push_data` to the shader layout declared by `pipeline`.

src/vulkan/command.zig:222

method

CommandBuffer.pushDescAndDispatch

#
pub fn pushDescAndDispatch( self: *CommandBuffer, pipeline: *const Pipeline, push_desc_fn: ?PushDescriptorFn, buffer_infos: []const vk.c.VkDescriptorBufferInfo, push_data: []const u8, group_count_x: u32, group_count_y: u32, group_count_z: u32, ) void

Record a compute dispatch using `VK_KHR_push_descriptor`.

Parameters
self
Command buffer currently being recorded.
pipeline
Compute pipeline whose set-0 layout was created for push descriptors.
push_desc_fn
Loaded `vkCmdPushDescriptorSetKHR` function pointer.
buffer_infos
Storage-buffer bindings to push into set `0`; at most 8 entries.
push_data
Raw bytes copied into the pipeline's push-constant range at offset `0`; may be empty.
group_count_x
Workgroup count in the X dimension.
group_count_y
Workgroup count in the Y dimension.
group_count_z
Workgroup count in the Z dimension.
Notes

Asserts that `push_desc_fn` is non-null and `buffer_infos.len <= 8`.

src/vulkan/command.zig:268

method

CommandBuffer.pushDescAndDispatchIndirect

#
pub fn pushDescAndDispatchIndirect( self: *CommandBuffer, pipeline: *const Pipeline, push_desc_fn: ?PushDescriptorFn, buffer_infos: []const vk.c.VkDescriptorBufferInfo, push_data: []const u8, indirect_buffer: vk.c.VkBuffer, indirect_offset: vk.c.VkDeviceSize, ) void

Record a push-descriptor compute dispatch whose group counts are read from a device buffer.

The indirect buffer must contain a `VkDispatchIndirectCommand` at the given byte offset.

Parameters
self
Command buffer currently being recorded.
pipeline
Compute pipeline whose set-0 layout was created for push descriptors.
push_desc_fn
Loaded `vkCmdPushDescriptorSetKHR` function pointer.
buffer_infos
Storage-buffer bindings to push into set `0`; at most 8 entries.
push_data
Raw bytes copied into the pipeline's push-constant range at offset `0`; may be empty.
indirect_buffer
Device buffer containing the `VkDispatchIndirectCommand` group counts.
indirect_offset
Byte offset into `indirect_buffer` where the command struct begins.
Notes

Asserts that `push_desc_fn` is non-null and `buffer_infos.len <= 8`.

src/vulkan/command.zig:333

method

CommandBuffer.computeBufferBarrier

#
pub fn computeBufferBarrier(self: *const CommandBuffer, buffer: vk.c.VkBuffer, size: vk.c.VkDeviceSize) void

Insert a buffer-specific compute barrier (only synchronizes the given buffer).

May allow the driver to avoid flushing unrelated caches.

src/vulkan/command.zig:410

method

CommandBuffer.computeToIndirectBufferBarrier

#
pub fn computeToIndirectBufferBarrier(self: *const CommandBuffer, buffer: vk.c.VkBuffer, size: vk.c.VkDeviceSize) void

Insert a compute-shader-write to indirect-command-read barrier.

Needed when a shader writes VkDispatchIndirectCommand records consumed by vkCmdDispatchIndirect later in the same command buffer.

src/vulkan/command.zig:439

method

CommandBuffer.computeBuffersBarrier

#
pub fn computeBuffersBarrier(self: *const CommandBuffer, ranges: []const BufferRange) void

Insert a multi-buffer compute barrier covering several specific buffer ranges in one vkCmdPipelineBarrier call.

Lets the driver flush only the named buffer caches instead of a global memory barrier — when downstream ops only depend on a known subset of pending writes, unrelated in-flight writes can keep flowing. Up to 8 ranges supported in the inline buffer; larger calls fall back to global.

src/vulkan/command.zig:476

method

CommandBuffer.computeBarrier

#
pub fn computeBarrier(self: *const CommandBuffer) void

Insert a compute-to-compute pipeline barrier (shader write → shader read).

Parameters
self
Command buffer currently being recorded.
Notes

Uses a coarse global memory barrier; prefer buffer barriers for fine-grained sync.

src/vulkan/command.zig:517

method

CommandBuffer.computeToTransferBarrier

#
pub fn computeToTransferBarrier(self: *const CommandBuffer) void

Insert a compute-to-transfer pipeline barrier (shader write → transfer read/write).

Parameters
self
Command buffer currently being recorded.
Notes

Use this before copying from or into buffers produced by compute shaders.

src/vulkan/command.zig:524

method

CommandBuffer.transferToComputeBarrier

#
pub fn transferToComputeBarrier(self: *const CommandBuffer) void

Insert a transfer-to-compute pipeline barrier (copy/upload → shader read).

Parameters
self
Command buffer currently being recorded.
Notes

Ensures prior transfer writes are visible before subsequent compute dispatches.

src/vulkan/command.zig:531

method

CommandBuffer.computeAndTransferBarrier

#
pub fn computeAndTransferBarrier(self: *const CommandBuffer) void

Insert a combined compute→compute+transfer barrier.

Shader writes become visible to both subsequent compute dispatches and transfer reads. Use when compute output feeds both a shader read and a buffer copy in the same stage.

src/vulkan/command.zig:538

method

CommandBuffer.transferToTransferBarrier

#
pub fn transferToTransferBarrier(self: *const CommandBuffer) void

Insert a transfer→transfer pipeline barrier (copy write → copy read).

by another vkCmdCopyBuffer in the same or a subsequent command buffer, and the caller wants strict-spec memory visibility without relying on implicit same-queue ordering semantics. This is the cross-CB safety net for effort-6 cycle 7's layer-0 stash buffers.

Parameters
self
Command buffer currently being recorded.
Notes

Needed when a vkCmdCopyBuffer writes a buffer whose contents are read

src/vulkan/command.zig:549

method

CommandBuffer.end

#
pub fn end(self: *const CommandBuffer) !void

Finalize command recording so the buffer can be submitted.

Parameters
self
Command buffer to finalize.
Returns

`error.EndCommandBufferFailed` when Vulkan rejects the recorded command stream.

src/vulkan/command.zig:561

method

CommandBuffer.submitAndWait

#
pub fn submitAndWait(self: *const CommandBuffer, queue: vk.c.VkQueue) !void

Submit the command buffer and block until the GPU signals completion.

Parameters
self
Recorded command buffer to submit.
queue
Queue to submit the work on.
Returns

`error.QueueSubmitFailed` or `error.FenceWaitFailed` when submission or synchronization fails.

Notes

The fence is reset before returning so the command buffer can be reused by a later step.

src/vulkan/command.zig:571

method

CommandBuffer.submit

#
pub fn submit(self: *const CommandBuffer, queue: vk.c.VkQueue) !void

Submit recorded work and return immediately.

Parameters
self
Recorded command buffer to submit.
queue
Queue to submit the work on.
Returns

`error.QueueSubmitFailed` when Vulkan rejects the submission.

Notes

Pair this with `waitForCompletion()` before resetting or re-recording the command buffer.

src/vulkan/command.zig:601

method

CommandBuffer.waitForCompletion

#
pub fn waitForCompletion(self: *const CommandBuffer) !void

Wait for the command buffer's fence to signal and then reset it.

Parameters
self
Command buffer whose most recent submission should complete before returning.
Returns

`error.FenceWaitFailed` when the wait operation fails.

Notes

After this returns, the command buffer can be reset and recorded again.

src/vulkan/command.zig:625

method

CommandBuffer.reset

#
pub fn reset(self: *const CommandBuffer) !void

Reset the command buffer so new commands can be recorded into it.

Parameters
self
Command buffer to reset.
Returns

`error.ResetCommandBufferFailed` when Vulkan rejects the reset request.

Notes

The caller must ensure the previous submission has completed before calling this.

src/vulkan/command.zig:635

method

CommandBuffer.deinit

#
pub fn deinit(self: *CommandBuffer, pool: *const CommandPool) void

Destroy the command buffer fence and free the command buffer back to its pool.

Parameters
self
Command buffer to tear down in place.
pool
Command pool that owns the Vulkan command buffer allocation.
Notes

Callers should ensure the GPU is no longer using the buffer before teardown.

src/vulkan/command.zig:644