summaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_formats.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-07-13 12:18:15 -0700
committerJason Ekstrand <[email protected]>2017-07-15 08:59:38 -0700
commit0ee8d81718f059592ab484382c93073c43b71f54 (patch)
tree2481435b351d32554490cd96d52498e0c07896ad /src/intel/vulkan/anv_formats.c
parentc02da9cad6b5ed09c8dfcf600380974b8075d792 (diff)
anv: Implement VK_KHR_external_memory_*
Reviewed-by: Samuel Iglesias Gonsálvez <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/intel/vulkan/anv_formats.c')
-rw-r--r--src/intel/vulkan/anv_formats.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index 424db66ec22..c656d7e9828 100644
--- a/src/intel/vulkan/anv_formats.c
+++ b/src/intel/vulkan/anv_formats.c
@@ -650,12 +650,25 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties(
pImageFormatProperties);
}
+static const VkExternalMemoryPropertiesKHR prime_fd_props = {
+ /* If we can handle external, then we can both import and export it. */
+ .externalMemoryFeatures = VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT_KHR |
+ VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT_KHR,
+ /* For the moment, let's not support mixing and matching */
+ .exportFromImportedHandleTypes =
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
+ .compatibleHandleTypes =
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
+};
+
VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR(
VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceImageFormatInfo2KHR* base_info,
VkImageFormatProperties2KHR* base_props)
{
ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
+ const VkPhysicalDeviceExternalImageFormatInfoKHR *external_info = NULL;
+ VkExternalImageFormatPropertiesKHR *external_props = NULL;
VkResult result;
result = anv_get_image_format_properties(physical_device, base_info,
@@ -666,6 +679,9 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR(
/* Extract input structs */
vk_foreach_struct_const(s, base_info->pNext) {
switch (s->sType) {
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR:
+ external_info = (const void *) s;
+ break;
default:
anv_debug_ignored_stype(s->sType);
break;
@@ -675,12 +691,42 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2KHR(
/* Extract output structs */
vk_foreach_struct(s, base_props->pNext) {
switch (s->sType) {
+ case VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR:
+ external_props = (void *) s;
+ break;
default:
anv_debug_ignored_stype(s->sType);
break;
}
}
+ /* From the Vulkan 1.0.42 spec:
+ *
+ * If handleType is 0, vkGetPhysicalDeviceImageFormatProperties2KHR will
+ * behave as if VkPhysicalDeviceExternalImageFormatInfoKHR was not
+ * present and VkExternalImageFormatPropertiesKHR will be ignored.
+ */
+ if (external_info && external_info->handleType != 0) {
+ switch (external_info->handleType) {
+ case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+ if (external_props)
+ external_props->externalMemoryProperties = prime_fd_props;
+ break;
+ default:
+ /* From the Vulkan 1.0.42 spec:
+ *
+ * If handleType is not compatible with the [parameters] specified
+ * in VkPhysicalDeviceImageFormatInfo2KHR, then
+ * vkGetPhysicalDeviceImageFormatProperties2KHR returns
+ * VK_ERROR_FORMAT_NOT_SUPPORTED.
+ */
+ result = vk_errorf(VK_ERROR_FORMAT_NOT_SUPPORTED,
+ "unsupported VkExternalMemoryTypeFlagBitsKHR 0x%x",
+ external_info->handleType);
+ goto fail;
+ }
+ }
+
return VK_SUCCESS;
fail:
@@ -721,3 +767,36 @@ void anv_GetPhysicalDeviceSparseImageFormatProperties2KHR(
/* Sparse images are not yet supported. */
*pPropertyCount = 0;
}
+
+void anv_GetPhysicalDeviceExternalBufferPropertiesKHR(
+ VkPhysicalDevice physicalDevice,
+ const VkPhysicalDeviceExternalBufferInfoKHR* pExternalBufferInfo,
+ VkExternalBufferPropertiesKHR* pExternalBufferProperties)
+{
+ /* The Vulkan 1.0.42 spec says "handleType must be a valid
+ * VkExternalMemoryHandleTypeFlagBitsKHR value" in
+ * VkPhysicalDeviceExternalBufferInfoKHR. This differs from
+ * VkPhysicalDeviceExternalImageFormatInfoKHR, which surprisingly permits
+ * handleType == 0.
+ */
+ assert(pExternalBufferInfo->handleType != 0);
+
+ /* All of the current flags are for sparse which we don't support yet.
+ * Even when we do support it, doing sparse on external memory sounds
+ * sketchy. Also, just disallowing flags is the safe option.
+ */
+ if (pExternalBufferInfo->flags)
+ goto unsupported;
+
+ switch (pExternalBufferInfo->handleType) {
+ case VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR:
+ pExternalBufferProperties->externalMemoryProperties = prime_fd_props;
+ return;
+ default:
+ goto unsupported;
+ }
+
+ unsupported:
+ pExternalBufferProperties->externalMemoryProperties =
+ (VkExternalMemoryPropertiesKHR) {0};
+}