Skip to content

Conversation

@cmarcelo
Copy link

@cmarcelo cmarcelo commented Oct 4, 2025

(UPDATED COMMIT MESSAGE)

VK_KHR_driver_properties requires VK_KHR_get_physical_device_properties2
extension. For Vulkan 1.2 both extensions are core, so nothing to do,
for Vulkan 1.1, the latter is core, so only need the former. For Vulkan
1.0 both extensions are required.

VK_KHR_driver_properties is a device extension that doesn't need to be
explicitly enabled here. As long as its supported it can be used in the
query on the physical device, before the logical device is created (i.e.
before device extensions can be enabled). See
https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#fundamentals-validusage-pNext.

VK_KHR_get_physical_device_properties2 is an instance extension,
required for the previous one. If the application hasn't enabled it,
do in its behalf. Also make sure when the extension is used, the KHR
version of the symbol is loaded.

This fixes vulkan_driver option in applications that ask for
Vulkan 1.0 (e.g. vkcube) but that the driver does support the extra
extensions.

@cmarcelo
Copy link
Author

cmarcelo commented Oct 4, 2025

src/vulkan.cpp Outdated
// VK_KHR_get_physical_device_properties2 became core in 1.1
if (instance_data->api_version < VK_API_VERSION_1_1)
enabled_extensions.insert(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
enabled_extensions.insert(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however Vulkan spec requires those to be enabled -- even if sometimes drivers work fine with just using extensions without enabling.

While correct in theory, enabling VK_KHR_driver_properties does nothing. It's a device extension, but only provides physical device level functionality. The property query on the physical device can be used long before a logical device is created. Enabling the extension anyway, while probably not harmful, is also pointless.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. For future reference, the spec section that allows this

Each structure included in the pNext chain must be defined at runtime by either:

- a core version which is supported
- an extension which is enabled
- a supported device extension in the case of physical-device-level functionality added by the device extension

https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#fundamentals-validusage-pNext

src/vulkan.cpp Outdated
goto FOUND;
// VK_KHR_get_physical_device_properties2 became core in 1.1
if (instance_data->api_version < VK_API_VERSION_1_1)
enabled_extensions.insert(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VK_KHR_get_physical_device_properties2 is a instance extension, not a device extension. So this is 100% the incorrect place to add it. The correct place to do it is vkCreateInstance. I remember issues with enabling instance extensions in layers, but they might actually be fixed now (KhronosGroup/Vulkan-Loader#547) so maybe give it a try.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was 100% incorrect. Moved the handling for this extension into vkCreateInstance.

Based on the issue linked (and other ones linked from there), my local test, and the fact that Renderdoc enables instance extensions in a modified environment, I opted for enabling the extension if required.
See code around vk_device_funcs.cpp in Renderdoc.

The alternative proposed would be to modify the api_version to use 1.1, but that wouldn't work with drivers that are 1.0 only. See code around vulkan-capture.c in OBS.

@cmarcelo cmarcelo force-pushed the vulkan-can-get-driver-info branch from 9814185 to 13924d9 Compare October 8, 2025 17:18
@DadSchoorse
Copy link
Contributor

Looks better now, just one thing that you need to pay attention to is that you actually use vkGetPhysicalDeviceProperties2KHR for Vulkan 1.0 instances, and not vkGetPhysicalDeviceProperties2. I don't think the dispatch table init here does that for you.

@cmarcelo cmarcelo force-pushed the vulkan-can-get-driver-info branch from 13924d9 to 78215f1 Compare October 10, 2025 16:36
@cmarcelo
Copy link
Author

cmarcelo commented Oct 10, 2025

Added code to handle a selected list of command aliases. Then added the vkGetPhysicalDeviceProperties2KHR name to that list.

Generated code now looks like this:

table->GetPhysicalDeviceFeatures2 = (PFN_vkGetPhysicalDeviceFeatures2) gpa(instance, "vkGetPhysicalDeviceFeatures2");
if (table->GetPhysicalDeviceFeatures2 == NULL)
    table->GetPhysicalDeviceFeatures2 = (PFN_vkGetPhysicalDeviceFeatures2) gpa(instance, "vkGetPhysicalDeviceFeatures2KHR");

@cmarcelo cmarcelo force-pushed the vulkan-can-get-driver-info branch from 78215f1 to 7711f38 Compare October 11, 2025 01:02
@cmarcelo
Copy link
Author

Updated again: this time don't try to extend the dispatch table, just load the right variant of vkGetPhysicalDeviceProperties2 (either non-KHR or KHR) when using it.

@cmarcelo cmarcelo force-pushed the vulkan-can-get-driver-info branch 3 times, most recently from 7065588 to e72445b Compare October 11, 2025 01:17
VK_KHR_driver_properties requires VK_KHR_get_physical_device_properties2
extension.  For Vulkan 1.2 both extensions are core, so nothing to do,
for Vulkan 1.1, the latter is core, so only need the former.  For Vulkan
1.0 both extensions are required.

VK_KHR_driver_properties is a device extension that doesn't need to be
explicitly enabled here.  As long as its supported it can be used in the
query on the physical device, before the logical device is created (i.e.
before device extensions can be enabled).  See
https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#fundamentals-validusage-pNext.

VK_KHR_get_physical_device_properties2 is an instance extension,
required for the previous one.  If the application hasn't enabled it,
do in its behalf.  Also make sure when the extension is used, the KHR
version of the symbol is loaded.

This fixes `vulkan_driver` option in applications that ask for
Vulkan 1.0 (e.g. vkcube) but that the driver does support the extra
extensions.
@cmarcelo cmarcelo force-pushed the vulkan-can-get-driver-info branch from e72445b to 3c78068 Compare October 11, 2025 01:18
Copy link
Contributor

@DadSchoorse DadSchoorse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants