summaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_device.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_device.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_device.c')
-rw-r--r--src/intel/vulkan/anv_device.c86
1 files changed, 81 insertions, 5 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index cacfb39bde6..34d4a675481 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -408,6 +408,10 @@ anv_physical_device_finish(struct anv_physical_device *device)
static const VkExtensionProperties global_extensions[] = {
{
+ .extensionName = VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
+ .specVersion = 1,
+ },
+ {
.extensionName = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
.specVersion = 1,
},
@@ -449,6 +453,14 @@ static const VkExtensionProperties device_extensions[] = {
.specVersion = 1,
},
{
+ .extensionName = VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
+ .specVersion = 1,
+ },
+ {
+ .extensionName = VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
+ .specVersion = 1,
+ },
+ {
.extensionName = VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
.specVersion = 1,
},
@@ -889,6 +901,8 @@ void anv_GetPhysicalDeviceProperties2KHR(
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2KHR* pProperties)
{
+ ANV_FROM_HANDLE(anv_physical_device, pdevice, physicalDevice);
+
anv_GetPhysicalDeviceProperties(physicalDevice, &pProperties->properties);
vk_foreach_struct(ext, pProperties->pNext) {
@@ -901,6 +915,16 @@ void anv_GetPhysicalDeviceProperties2KHR(
break;
}
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR: {
+ VkPhysicalDeviceIDPropertiesKHR *id_props =
+ (VkPhysicalDeviceIDPropertiesKHR *)ext;
+ memcpy(id_props->deviceUUID, pdevice->device_uuid, VK_UUID_SIZE);
+ memcpy(id_props->driverUUID, pdevice->driver_uuid, VK_UUID_SIZE);
+ /* The LUID is for Windows. */
+ id_props->deviceLUIDValid = false;
+ break;
+ }
+
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX: {
VkPhysicalDeviceMultiviewPropertiesKHX *properties =
(VkPhysicalDeviceMultiviewPropertiesKHX *)ext;
@@ -1544,11 +1568,31 @@ VkResult anv_AllocateMemory(
mem->map = NULL;
mem->map_size = 0;
- result = anv_bo_cache_alloc(device, &device->bo_cache,
- pAllocateInfo->allocationSize,
- &mem->bo);
- if (result != VK_SUCCESS)
- goto fail;
+ const VkImportMemoryFdInfoKHR *fd_info =
+ vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
+
+ /* The Vulkan spec permits handleType to be 0, in which case the struct is
+ * ignored.
+ */
+ if (fd_info && fd_info->handleType) {
+ /* At the moment, we only support the OPAQUE_FD memory type which is
+ * just a GEM buffer.
+ */
+ assert(fd_info->handleType ==
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+
+ result = anv_bo_cache_import(device, &device->bo_cache,
+ fd_info->fd, pAllocateInfo->allocationSize,
+ &mem->bo);
+ if (result != VK_SUCCESS)
+ goto fail;
+ } else {
+ result = anv_bo_cache_alloc(device, &device->bo_cache,
+ pAllocateInfo->allocationSize,
+ &mem->bo);
+ if (result != VK_SUCCESS)
+ goto fail;
+ }
assert(mem->type->heapIndex < pdevice->memory.heap_count);
if (pdevice->memory.heaps[mem->type->heapIndex].supports_48bit_addresses)
@@ -1567,6 +1611,38 @@ VkResult anv_AllocateMemory(
return result;
}
+VkResult anv_GetMemoryFdKHR(
+ VkDevice device_h,
+ const VkMemoryGetFdInfoKHR* pGetFdInfo,
+ int* pFd)
+{
+ ANV_FROM_HANDLE(anv_device, dev, device_h);
+ ANV_FROM_HANDLE(anv_device_memory, mem, pGetFdInfo->memory);
+
+ assert(pGetFdInfo->sType == VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR);
+
+ /* We support only one handle type. */
+ assert(pGetFdInfo->handleType ==
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+
+ return anv_bo_cache_export(dev, &dev->bo_cache, mem->bo, pFd);
+}
+
+VkResult anv_GetMemoryFdPropertiesKHR(
+ VkDevice device_h,
+ VkExternalMemoryHandleTypeFlagBitsKHR handleType,
+ int fd,
+ VkMemoryFdPropertiesKHR* pMemoryFdProperties)
+{
+ /* The valid usage section for this function says:
+ *
+ * "handleType must not be one of the handle types defined as opaque."
+ *
+ * Since we only handle opaque handles for now, there are no FD properties.
+ */
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR;
+}
+
void anv_FreeMemory(
VkDevice _device,
VkDeviceMemory _mem,