Module 13 · Lesson 54 of 98

Vulkan's explicit model and why it won

Trace how Vulkan submits GPU work and explain why explicit synchronisation, lower CPU overhead, and SPIR-V suit embedded graphics and compute.

  • Beginner to advanced
  • 7 min read
  • 18 min lab
What you will need

Basic knowledge of GPU dispatches and buffers. The written exercises can be completed on Ubuntu 24.04 in WSL2 or a VM without GPU access.

Your place in the module
By the end you can 4 objectives
  • Distinguish the Vulkan instance, physical device, logical device, queue family, and queue.
  • Trace a command buffer from CPU recording to GPU execution.
  • Identify the dependency between a compute write and a graphics read.
  • Explain how Vulkan reduces CPU-side driver work and where SPIR-V fits.
Video coming soonVulkan's explicit model and why it won
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from The portability promise and its limits
  • One SYCL source can target NVIDIA, AMD, and Intel GPUs and CPUs when the implementation and deployment stack support them.
  • Device capabilities determine which variants can run, and measurements determine which legal variant performs best.
  • A catch around submission handles synchronous exceptions, while an async_handler receives deferred errors.
01

From an instance to a queue

3 min read

You have used high-level APIs that hide the GPU. Vulkan hands you the controls, and this lesson answers why its explicit model replaced OpenGL for compute on embedded.

An embedded Linux program can need GPU processing even when the board has no display attached. A camera program might process an image and pass the result to another stage without ever showing it. Linux DRM render nodes address the underlying access problem by giving userspace a way to access rendering functions without controlling a display. Vulkan makes a separate choice at the API level. A compute program can create a device and submit work without creating a window or a presentation surface. Linux DRM render nodes

A Vulkan program first creates a VkInstance. The instance establishes the program's connection to Vulkan and is where it requests any instance-level extensions or layers it needs. The program then enumerates VkPhysicalDevice handles through that instance. A physical-device handle identifies an implementation-exposed device and lets the program query properties, supported features, memory properties, and queue families. A software implementation can expose a physical device too, so enumeration alone does not establish that a board's GPU will execute the work.

A The program inspects those capabilities before choosing where to submit work. For example, VK_QUEUE_COMPUTE_BIT identifies a family whose queues support compute commands. A family can support both graphics and compute, so one queue from that family can serve both workloads. The family index identifies the group. The queue index identifies a queue within that group. The reported queue count tells the program how many queues it can request from the family, without promising that those queues will execute on separate hardware engines.

The program creates a VkDevice, called a logical device, from the selected physical device. At creation it requests queues from chosen families and enables the features and device extensions its workload requires. The logical device is the handle the program uses to create resources and obtain the requested VkQueue handles. Selecting a physical device and creating a logical device are distinct operations. The first identifies an implementation and its capabilities. The second configures how the program will use it.

Vulkan device and queue setupCreateinstanceSelectphysicaldeviceCheck queuefamiliesCapabilities and queuecountsCreatelogicaldeviceRequestqueues andenablefeaturesObtainqueueCreateinstanceSelectphysicaldeviceCheck queuefamiliesCapabilities and queuecountsCreatelogicaldeviceRequestqueues andenablefeaturesObtainqueue
The program queries queue families on the physical device, then requests queues when creating the logical device.

Consider a camera preview that applies a filter using compute and displays the result using graphics. If the selected device exposes a family with both capabilities, the program can request one queue for the two operations. A second queue is unnecessary for this design. A headless version can choose a compute-capable family and omit presentation setup altogether. Both versions start by checking what the implementation exposes on the target board.

02

Recording work and declaring dependencies

3 min read

A A CPU thread records commands such as binding a pipeline, dispatching compute work, or drawing. Recording prepares the commands for submission. The GPU can execute them after the program submits the command buffer to a compatible queue. Command buffers come from a command pool associated with a queue family, which ties them to queues from that family for submission.

Vulkan has no implicit global state for drawing or dispatch. OpenGL keeps mutable state in a context that is current to the calling thread. A draw uses the program and other bindings currently set in that context. In Vulkan, much of the configuration is specified in pipeline objects, while pipeline bindings and other command state are set during recording. If one command buffer binds a compute pipeline and dispatches a filter, recording another command buffer for a separate dispatch requires establishing the state that dispatch needs. Completing the first recording does not set a process-wide current pipeline.

Submission and completion are also distinct. A successful submission means the work has been submitted to the queue. If the CPU needs to reuse resources that the submission is still using, it needs a completion signal. A fence associated with the submission can give the CPU that signal. On Linux, the kernel driver underneath Vulkan also has to manage the buffers that this work reads and writes. The kernel's DRM memory-management documentation describes the buffer objects drivers use for GPU memory. Linux DRM memory management

Now consider the camera preview on a queue that supports compute and graphics. The dispatch writes a filtered image and a later draw samples it. Recording the dispatch before the draw establishes where the commands appear in the command stream. The program still needs to specify that the draw's sampling depends on those compute writes. In this single-queue case, a pipeline barrier between the dispatch and draw can express the dependency. It identifies the compute shader writes as the source and the relevant graphics shader reads as the destination. If the image needs a layout transition for the next use, the program can express that transition with an image barrier.

A write followed by a readComputedispatchWritesfilteredimagePipelinebarrierOrdersaccess andmakeswritesvisibleDrawSamplesfilteredimageComputedispatchWritesfilteredimagePipelinebarrierOrdersaccess andmakeswritesvisibleDrawSamplesfilteredimage
A pipeline barrier connects the compute writes to the draw that samples the result.

The dependency addresses two questions. Execution ordering determines when the dependent read may proceed. Memory visibility determines whether that read can observe the producer's writes. A program that relies on recording order alone can appear to work on one implementation and still have a synchronisation bug. The barrier expresses the requirement even when the example appears to work without it.

OpenGL also exposes explicit synchronisation for operations that need it. For example, an OpenGL compute shader's image writes can require glMemoryBarrier before a later shader samples the image. Vulkan makes specifying dependencies a central responsibility of the application. That responsibility gives the program a way to describe the actual producer and consumer while leaving unrelated work outside the dependency.

03

Why embedded applications adopted Vulkan

3 min read

Vulkan became a successor to OpenGL and OpenGL ES for applications that combine graphics and compute and need more control over CPU overhead and GPU scheduling. OpenGL ES can run compute on implementations that expose compute support, and it remains in use on embedded targets. Vulkan adoption depends on the board's driver and the features it exposes. A program that needs a specific capability must check it on the intended target.

The first advantage is explicit synchronisation. In the preview example, the graphics shader needs the compute output. Work on an independent resource may have no such dependency. When the application describes which accesses depend on which writes, it can avoid waiting for the whole queue just to make one result safe to read. Vulkan also gives the application ways to express dependencies across queue submissions. The performance benefit depends on how the program specifies those dependencies and what the implementation can execute concurrently.

The second advantage is lower CPU-side driver overhead. With OpenGL's context model, an application can change pieces of state independently immediately before a draw. The implementation must account for the current combination of state as it prepares the work. Vulkan lets applications define much of that configuration when creating a pipeline and record sequences of commands before submission. A program can reuse suitable pipeline objects, submit a batch of commands together, and record independent command buffers on different CPU threads using separate command pools. Those choices can reduce work on the CPU thread responsible for keeping the GPU supplied.

Consider a preview that uses the same filter and drawing configuration on successive frames. Creating the same pipelines each frame would move setup work back into the frame loop. Creating them during setup and reusing them means the per-frame CPU work can focus on recording or submitting the commands for the current frame. On an embedded processor that also handles camera input and other application work, that CPU time matters. If the filter already spends most of its time waiting on memory bandwidth, a reduction in CPU submission overhead can leave the filter's GPU execution time essentially unchanged.

The third advantage is SPIR-V, the intermediate representation Vulkan accepts for graphics and compute shaders. A build can compile shader source to SPIR-V before deployment, then ship those modules with the application. That avoids source-language compilation in the application's Vulkan shader-loading path. The driver still translates and optimises the shader for its target GPU. The same SPIR-V module can be usable across implementations that support the Vulkan environment and capabilities it requires. The supported features still matter on every target.

What Vulkan makes explicitVulkanmechanismWhat itenablesSynchronisationGPUdependenciesWait forneeded writesCPU setupPipelines andcommandbuffersReuse setupand batchworkShaderdeploymentSPIR-VmodulesCompilesource beforedeployment
Explicit dependencies, reusable CPU-side setup, and a common shader input address different costs.

When reviewing a preview design, ask where each frame's result first becomes safe to sample, how much state setup the CPU repeats each frame, and what shader representation the application deploys. Those questions identify three separate reasons to choose Vulkan. They also explain why the API name alone cannot predict the frame rate on a particular board.

The next lesson, SPIR-V and the compute pipeline, follows the shader from source to the Vulkan compute pipeline and explains what the program binds before recording a dispatch.

Key takeaways

  • The physical device reports capabilities, and the logical device enables features and exposes requested queues.
  • Vulkan records work and state into command buffers for submission to compatible queues.
  • An explicit dependency orders a GPU producer and consumer and makes the producer's writes visible to the consumer.
  • Vulkan can reduce CPU submission overhead, and SPIR-V provides a common intermediate shader format for graphics and compute.
Reflect
  1. Explain to a colleague, in two sentences: distinguish the Vulkan instance, physical device, logical device, queue family, and queue.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close