MuertoExcobito
MuertoExcobito

Reputation: 10049

Vulkan: difference between vkGetInstanceProcAddress and vkGetDeviceProcAddress

vkGetInstanceProcAddr and vkGetDeviceProcAddr are completely missing from the API documentation. However they are required to perform commands with swapchains (and thus make any meaningful Vulkan app). Furthermore, the cube/tri demos that come with the SDK use them very inconsistently.

Are these two methods interchangeable, and if not, what's the difference?

Upvotes: 10

Views: 4450

Answers (2)

ratchet freak
ratchet freak

Reputation: 48226

vkGetInstanceProcAddress is to get the function pointer that will always work with any device created from the instance passed in.

However the functions returned may include dispatch logic (typically to account for extensions that may or may not be enabled for the device) that may slow down the call. This is why the vkGetDeviceProcAddress exist to get the function that doesn't have dispatch logic. You are not obliged to use them but it may help get some extra speed.

This is especially noticeable when you have activated several layers:

enter image description here

With the device specific function pointer the final dispatch can be removed:

enter image description here
images from the khonos loader and layer interface document

If you only use 1 device then the order of operations for the application would be:

  1. get vkGetInstanceProcAddress from the platform/loader.

  2. load vkCreateInstance from it and the extension and layer queries. (using null as the instance parameter)

  3. create the instance. (you will use this as first parameter for loading the other functions)

  4. load vkEnumeratePhysicalDevices and related to query devices.

  5. create the device with vkCreateDevice specifying the extensions you want.

  6. load all the other functions you will need with vkGetDeviceProcAddress and passing the device as the first parameter.

Upvotes: 19

JonA
JonA

Reputation: 11

Above answer is correct. I will add that for WSI extensions, the Windows,Linux and Android loaders have all stated they will export the WSI extension entry points. Thus, on these platforms vkGetInstanceProcAddr and vkGetDeviceProcAddr is NOT needed to be used to get WSI entry points. But in general extension entry points need to be retrieved via vkGet*ProcAddr in Vulkan.

Upvotes: 1

Related Questions