Commit cd7d4be8 authored by Niklas Haas's avatar Niklas Haas

vulkan: fix external memory vs external semaphore type confusion

These are different enums, with different legal members. Not only does
this avoid a warning, it also avoids future disaster by conflating the
two.
parent bd502804
Pipeline #4985 passed with stages
in 2 minutes and 15 seconds
......@@ -228,7 +228,7 @@ static pl_handle_caps vk_sync_handle_caps(struct vk_ctx *vk)
VkPhysicalDeviceExternalSemaphoreInfoKHR info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR,
.handleType = vk_handle_type(type),
.handleType = vk_sync_handle_type(type),
};
VkExternalSemaphorePropertiesKHR props = {
......@@ -260,7 +260,7 @@ static pl_handle_caps vk_tex_handle_caps(struct vk_ctx *vk, bool import)
// Query whether creation of a "basic" dummy texture would work
VkPhysicalDeviceExternalImageFormatInfoKHR ext_pinfo = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO_KHR,
.handleType = vk_handle_type(handle_type),
.handleType = vk_mem_handle_type(handle_type),
};
VkPhysicalDeviceImageFormatInfo2KHR pinfo = {
......@@ -803,7 +803,7 @@ static const struct pl_tex *vk_tex_create(const struct pl_gpu *gpu,
VkExternalMemoryImageCreateInfoKHR ext_info = {
.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR,
.handleTypes = vk_handle_type(handle_type),
.handleTypes = vk_mem_handle_type(handle_type),
};
VkImageCreateInfo iinfo = {
......@@ -2698,7 +2698,7 @@ static const struct pl_sync *vk_sync_create(const struct pl_gpu *gpu,
VkExportSemaphoreCreateInfoKHR einfo = {
.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR,
.handleTypes = vk_handle_type(handle_type),
.handleTypes = vk_sync_handle_type(handle_type),
};
switch (handle_type) {
......
......@@ -177,7 +177,7 @@ static bool buf_external_check(struct vk_ctx *vk, VkBufferUsageFlags usage,
VkPhysicalDeviceExternalBufferInfoKHR info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO_KHR,
.usage = usage,
.handleType = vk_handle_type(handle_type),
.handleType = vk_mem_handle_type(handle_type),
};
VkExternalBufferPropertiesKHR props = {
......@@ -217,7 +217,7 @@ static struct vk_slab *slab_alloc(struct vk_malloc *ma, struct vk_heap *heap,
VkExportMemoryAllocateInfoKHR ext_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
.handleTypes = vk_handle_type(slab->handle_type),
.handleTypes = vk_mem_handle_type(slab->handle_type),
};
VkMemoryAllocateInfo minfo = {
......@@ -624,7 +624,6 @@ bool vk_malloc_import(struct vk_malloc *ma, enum pl_handle_type handle_type,
struct vk_memslice *out)
{
struct vk_ctx *vk = ma->vk;
int fd = -1;
#ifndef VK_HAVE_UNIX
......@@ -633,6 +632,7 @@ bool vk_malloc_import(struct vk_malloc *ma, enum pl_handle_type handle_type,
#else
int fd = -1;
if (handle_type != PL_HANDLE_DMA_BUF) {
PL_ERR(vk, "Importing external memory is only supported for PL_HANDLE_DMA_BUF.");
return false;
......@@ -648,7 +648,7 @@ bool vk_malloc_import(struct vk_malloc *ma, enum pl_handle_type handle_type,
};
VK(vk->vkGetMemoryFdPropertiesKHR(vk->dev,
vk_handle_type(handle_type),
vk_mem_handle_type(handle_type),
shared_mem->handle.fd,
&fdprops));
......
......@@ -123,7 +123,7 @@ const char *vk_obj_str(VkDebugReportObjectTypeEXT obj)
}
VkExternalMemoryHandleTypeFlagBitsKHR
vk_handle_type(enum pl_handle_type handle_type)
vk_mem_handle_type(enum pl_handle_type handle_type)
{
if (!handle_type)
return 0;
......@@ -142,6 +142,25 @@ vk_handle_type(enum pl_handle_type handle_type)
abort();
}
VkExternalSemaphoreHandleTypeFlagBitsKHR
vk_sync_handle_type(enum pl_handle_type handle_type)
{
if (!handle_type)
return 0;
switch (handle_type) {
case PL_HANDLE_FD:
return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
case PL_HANDLE_WIN32:
return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR;
case PL_HANDLE_WIN32_KMT:
return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR;
case PL_HANDLE_DMA_BUF: abort();
}
abort();
}
bool vk_external_mem_check(const VkExternalMemoryPropertiesKHR *props,
enum pl_handle_type handle_type,
bool import)
......@@ -149,7 +168,7 @@ bool vk_external_mem_check(const VkExternalMemoryPropertiesKHR *props,
VkExternalMemoryFeatureFlagsKHR flags = props->externalMemoryFeatures;
// No support for this handle type;
if (!(props->compatibleHandleTypes & vk_handle_type(handle_type)))
if (!(props->compatibleHandleTypes & vk_mem_handle_type(handle_type)))
return false;
if (import) {
......
......@@ -24,7 +24,8 @@ const char *vk_res_str(VkResult res);
const char *vk_obj_str(VkDebugReportObjectTypeEXT obj);
// Enum translation boilerplate
VkExternalMemoryHandleTypeFlagBitsKHR vk_handle_type(enum pl_handle_type);
VkExternalMemoryHandleTypeFlagBitsKHR vk_mem_handle_type(enum pl_handle_type);
VkExternalSemaphoreHandleTypeFlagBitsKHR vk_sync_handle_type(enum pl_handle_type);
// Check for compatibility of a VkExternalMemoryProperties
bool vk_external_mem_check(const VkExternalMemoryPropertiesKHR *props,
......
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