Commit 1ffb3583 authored by Brian Ho's avatar Brian Ho Committed by Commit Bot

gpu: Load vk functions for querying image/buffer properties

This CL registers a few functions in the Vulkan binding generator script
to be used for importing dma-bufs as VkImages [1] with the end
goal of supporting WebGPU on Chrome OS. In particular, we add:

- vkGetPhysicalDeviceImageFormatProperties2: allows us to query if the
physical device supports importing dma-bufs into Vulkan via the
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT flag [2].
- vkGetMemoryFdPropertiesKHR: allows us to list the types of memory that
our buffer backed by a dma-buf can be imported as.
- vkGetImageMemoryRequirements2: allows us to list the types of memory
supported by a given VkImage which can be compared to the output of
vkGetMemoryFdPropertiesKHR to determine a suitable memory type for
import.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1796049
[2] https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkExternalMemoryHandleTypeFlagBits.html

BUG=996470
TEST=ran the script and used the newly bound functions

Change-Id: I0f61e531009596d7237153f203084639e649afd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1794142Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Commit-Queue: Brian Ho <hob@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695296}
parent 8c9e135e
...@@ -70,6 +70,12 @@ VULKAN_INSTANCE_FUNCTIONS = [ ...@@ -70,6 +70,12 @@ VULKAN_INSTANCE_FUNCTIONS = [
'vkCreateImagePipeSurfaceFUCHSIA', 'vkCreateImagePipeSurfaceFUCHSIA',
] ]
}, },
{
'min_api_version': 'VK_VERSION_1_1',
'functions': [
'vkGetPhysicalDeviceImageFormatProperties2',
]
},
{ {
# vkGetPhysicalDeviceFeatures2() is defined in Vulkan 1.1 or suffixed in the # vkGetPhysicalDeviceFeatures2() is defined in Vulkan 1.1 or suffixed in the
# VK_KHR_get_physical_device_properties2 extension. # VK_KHR_get_physical_device_properties2 extension.
...@@ -141,6 +147,12 @@ VULKAN_DEVICE_FUNCTIONS = [ ...@@ -141,6 +147,12 @@ VULKAN_DEVICE_FUNCTIONS = [
'vkWaitForFences', 'vkWaitForFences',
] ]
}, },
{
'min_api_version': 'VK_VERSION_1_1',
'functions': [
'vkGetImageMemoryRequirements2',
]
},
{ {
'ifdef': 'defined(OS_ANDROID)', 'ifdef': 'defined(OS_ANDROID)',
'extension': 'extension':
...@@ -161,7 +173,8 @@ VULKAN_DEVICE_FUNCTIONS = [ ...@@ -161,7 +173,8 @@ VULKAN_DEVICE_FUNCTIONS = [
'ifdef': 'defined(OS_LINUX)', 'ifdef': 'defined(OS_LINUX)',
'extension': 'VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME', 'extension': 'VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME',
'functions': [ 'functions': [
'vkGetMemoryFdKHR' 'vkGetMemoryFdKHR',
'vkGetMemoryFdPropertiesKHR',
] ]
}, },
{ {
......
...@@ -246,6 +246,18 @@ bool VulkanFunctionPointers::BindInstanceFunctionPointers( ...@@ -246,6 +246,18 @@ bool VulkanFunctionPointers::BindInstanceFunctionPointers(
} }
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
if (api_version >= VK_VERSION_1_1) {
vkGetPhysicalDeviceImageFormatProperties2Fn =
reinterpret_cast<PFN_vkGetPhysicalDeviceImageFormatProperties2>(
vkGetInstanceProcAddrFn(
vk_instance, "vkGetPhysicalDeviceImageFormatProperties2"));
if (!vkGetPhysicalDeviceImageFormatProperties2Fn) {
DLOG(WARNING) << "Failed to bind vulkan entrypoint: "
<< "vkGetPhysicalDeviceImageFormatProperties2";
return false;
}
}
if (api_version >= VK_VERSION_1_1) { if (api_version >= VK_VERSION_1_1) {
vkGetPhysicalDeviceFeatures2Fn = vkGetPhysicalDeviceFeatures2Fn =
reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2>( reinterpret_cast<PFN_vkGetPhysicalDeviceFeatures2>(
...@@ -715,6 +727,17 @@ bool VulkanFunctionPointers::BindDeviceFunctionPointers( ...@@ -715,6 +727,17 @@ bool VulkanFunctionPointers::BindDeviceFunctionPointers(
return false; return false;
} }
if (api_version >= VK_VERSION_1_1) {
vkGetImageMemoryRequirements2Fn =
reinterpret_cast<PFN_vkGetImageMemoryRequirements2>(
vkGetDeviceProcAddrFn(vk_device, "vkGetImageMemoryRequirements2"));
if (!vkGetImageMemoryRequirements2Fn) {
DLOG(WARNING) << "Failed to bind vulkan entrypoint: "
<< "vkGetImageMemoryRequirements2";
return false;
}
}
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (gfx::HasExtension( if (gfx::HasExtension(
enabled_extensions, enabled_extensions,
...@@ -762,6 +785,15 @@ bool VulkanFunctionPointers::BindDeviceFunctionPointers( ...@@ -762,6 +785,15 @@ bool VulkanFunctionPointers::BindDeviceFunctionPointers(
<< "vkGetMemoryFdKHR"; << "vkGetMemoryFdKHR";
return false; return false;
} }
vkGetMemoryFdPropertiesKHRFn =
reinterpret_cast<PFN_vkGetMemoryFdPropertiesKHR>(
vkGetDeviceProcAddrFn(vk_device, "vkGetMemoryFdPropertiesKHR"));
if (!vkGetMemoryFdPropertiesKHRFn) {
DLOG(WARNING) << "Failed to bind vulkan entrypoint: "
<< "vkGetMemoryFdPropertiesKHR";
return false;
}
} }
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
......
...@@ -107,6 +107,9 @@ struct VulkanFunctionPointers { ...@@ -107,6 +107,9 @@ struct VulkanFunctionPointers {
nullptr; nullptr;
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
PFN_vkGetPhysicalDeviceImageFormatProperties2
vkGetPhysicalDeviceImageFormatProperties2Fn = nullptr;
PFN_vkGetPhysicalDeviceFeatures2 vkGetPhysicalDeviceFeatures2Fn = nullptr; PFN_vkGetPhysicalDeviceFeatures2 vkGetPhysicalDeviceFeatures2Fn = nullptr;
// Device functions // Device functions
...@@ -165,6 +168,8 @@ struct VulkanFunctionPointers { ...@@ -165,6 +168,8 @@ struct VulkanFunctionPointers {
PFN_vkUpdateDescriptorSets vkUpdateDescriptorSetsFn = nullptr; PFN_vkUpdateDescriptorSets vkUpdateDescriptorSetsFn = nullptr;
PFN_vkWaitForFences vkWaitForFencesFn = nullptr; PFN_vkWaitForFences vkWaitForFencesFn = nullptr;
PFN_vkGetImageMemoryRequirements2 vkGetImageMemoryRequirements2Fn = nullptr;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
PFN_vkGetAndroidHardwareBufferPropertiesANDROID PFN_vkGetAndroidHardwareBufferPropertiesANDROID
vkGetAndroidHardwareBufferPropertiesANDROIDFn = nullptr; vkGetAndroidHardwareBufferPropertiesANDROIDFn = nullptr;
...@@ -177,6 +182,7 @@ struct VulkanFunctionPointers { ...@@ -177,6 +182,7 @@ struct VulkanFunctionPointers {
#if defined(OS_LINUX) #if defined(OS_LINUX)
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHRFn = nullptr; PFN_vkGetMemoryFdKHR vkGetMemoryFdKHRFn = nullptr;
PFN_vkGetMemoryFdPropertiesKHR vkGetMemoryFdPropertiesKHRFn = nullptr;
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
#if defined(OS_FUCHSIA) #if defined(OS_FUCHSIA)
...@@ -261,6 +267,9 @@ struct VulkanFunctionPointers { ...@@ -261,6 +267,9 @@ struct VulkanFunctionPointers {
gpu::GetVulkanFunctionPointers()->vkCreateImagePipeSurfaceFUCHSIAFn gpu::GetVulkanFunctionPointers()->vkCreateImagePipeSurfaceFUCHSIAFn
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
#define vkGetPhysicalDeviceImageFormatProperties2 \
gpu::GetVulkanFunctionPointers()->vkGetPhysicalDeviceImageFormatProperties2Fn
#define vkGetPhysicalDeviceFeatures2 \ #define vkGetPhysicalDeviceFeatures2 \
gpu::GetVulkanFunctionPointers()->vkGetPhysicalDeviceFeatures2Fn gpu::GetVulkanFunctionPointers()->vkGetPhysicalDeviceFeatures2Fn
...@@ -350,6 +359,9 @@ struct VulkanFunctionPointers { ...@@ -350,6 +359,9 @@ struct VulkanFunctionPointers {
gpu::GetVulkanFunctionPointers()->vkUpdateDescriptorSetsFn gpu::GetVulkanFunctionPointers()->vkUpdateDescriptorSetsFn
#define vkWaitForFences gpu::GetVulkanFunctionPointers()->vkWaitForFencesFn #define vkWaitForFences gpu::GetVulkanFunctionPointers()->vkWaitForFencesFn
#define vkGetImageMemoryRequirements2 \
gpu::GetVulkanFunctionPointers()->vkGetImageMemoryRequirements2Fn
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#define vkGetAndroidHardwareBufferPropertiesANDROID \ #define vkGetAndroidHardwareBufferPropertiesANDROID \
gpu::GetVulkanFunctionPointers() \ gpu::GetVulkanFunctionPointers() \
...@@ -365,6 +377,8 @@ struct VulkanFunctionPointers { ...@@ -365,6 +377,8 @@ struct VulkanFunctionPointers {
#if defined(OS_LINUX) #if defined(OS_LINUX)
#define vkGetMemoryFdKHR gpu::GetVulkanFunctionPointers()->vkGetMemoryFdKHRFn #define vkGetMemoryFdKHR gpu::GetVulkanFunctionPointers()->vkGetMemoryFdKHRFn
#define vkGetMemoryFdPropertiesKHR \
gpu::GetVulkanFunctionPointers()->vkGetMemoryFdPropertiesKHRFn
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
#if defined(OS_FUCHSIA) #if defined(OS_FUCHSIA)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment