Creating a Logical Device

A logical device is the main interface between the application and the resources of the physical device

Once a GPU has been selected through creation of a physical device, the application needs a way to interface with it. This is where a logical device is used.

What is a logical device?

A logical device is considered an application view of the GPU and is the main interface between the application and the resources of the physical device.

It is used when creating and managing many resources including:
  • queues
  • memory resources
  • command buffers
  • graphics and compute pipelines.
It is also used to create other API objects such as images and buffers. This is why many vkCreate... calls will reference an application's logical device.

When a logical device is created a number of command queues are also created alongside it. The supported operations of these queues are specified by selecting the queue family they will originate from, as shown in the previous section. The logical device can control the GPU by submitting command buffers via its associated queues.

Example: initLogicalDevice()

In the code example, a queue is created alongside the logical device. This queue originates from the graphics queue family identified earlier, so should support rendering operations.

The device-level extensions are also loaded at the same time as the device is created, similar to how the instance-level extensions were loaded when the instance was created.

Finally, any Vulkan functions which require a logical device are initialised with their function pointers being loaded.