Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass VkInstance to CreateDevice. Fixup intercepted function attributes. #18

Merged
merged 1 commit into from Sep 23, 2020

Conversation

kuhar
Copy link
Contributor

@kuhar kuhar commented Sep 22, 2020

CreateDevice needs to know the exact instance when there is more than
one layer active:
https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap4.html#initialization-functionpointers.

Override EnumeratePhysicalDevices to keep a map from physical devices to
instances.

CreateDevice needs to know the exact instance when there is more than
one layer active:
https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap4.html#initialization-functionpointers.

Override EnumeratePhysicalDevices to keep a map from physical devices to
instances.
@kuhar kuhar merged commit f933a5e into google:main Sep 23, 2020
@paulthomson
Copy link

paulthomson commented Sep 24, 2020

Actually, it turns out there is a way to do this without tracking VkPhysicalDevice (in case you are interested). From my notes:

The following are dispatchable handles:

- VkInstance
- VkPhysicalDevice (same dispatch table as its VkInstance)

- VkDevice
- VkQueue (same dispatch table as its VkDevice)
- VkCommandBuffer (same dispatch table as its VkDevice)

Using the dispatch table pointer of such handles as keys means we don't need
to track physical devices, queues, or command buffers, unless we want to
store information about each of these objects.

In other words, instead of using VkInstance as a key (and the same idea applies for VkDevice), use the "dispatch table pointer" of the VkInstance, which you get using this function (please ignore the snake_case naming). And when you have a VkPhysicalDevice, use pretty much the same function to get the VkInstance dispatch table pointer, which you can then use to look-up the data you have for the VkInstance (which should include the VkInstance value itself).

Another example of where this is somewhat nice is in a frame counter layer. We don't need to track VkQueue; we can go straight from the VkQueue to the DeviceData.

On the other hand, tracking VkPhysicalDevices, VkQueues, etc. is also fine, especially if you need to track them anyway.

This advice is documented here:
https://github.com/KhronosGroup/Vulkan-Loader/blob/master/loader/LoaderAndLayerInterface.md#hash-maps

...although I feel it isn't explained very clearly.

@kuhar
Copy link
Contributor Author

kuhar commented Sep 24, 2020

Very cool, thanks @paulthomson. Always happy to have less work to do, we should switch to this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants