Fork me on GitHub


Safe Rust wrapper around the Vulkan API


Now that we have all the needed ingredients, we can create the command buffer that will execute our compute pipeline. This is called a dispatch operation.

Creating a command buffer is similar to the example operation in a previous section.

use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage};
use vulkano::pipeline::PipelineBindPoint;

let mut builder = AutoCommandBufferBuilder::primary(

        0, // 0 is the index of our set
    .dispatch([1024, 1, 1])

let command_buffer =;

First, we bind the pipeline and then the descriptor sets, indicating the type of set, the layout and the descriptor sets we are going to use. Here "set" could have actually been many, were we wold indicated our desired with an index. Because we only have one, the index is 0.

As explained in the compute pipeline section, we want to spawn 1024 work groups. This value is indicated by the actual .dispatch() method.

Just like we already covered, we submit the command buffer:

let future = sync::now(device.clone())
    .then_execute(queue.clone(), command_buffer)

This just schedules the operation for execution and tells the GPU to signal when finished. We have to wait for it to complete:


Once complete, we can check that the pipeline has been correctly executed:

let content =;
for (n, val) in content.iter().enumerate() {
    assert_eq!(*val, n as u32 * 12);

println!("Everything succeeded!");

Next: Creating an image