vulkan: explicitly query supported semaphore handle types

Mercifully much easier than buffers/images
parent ec190ee7
Pipeline #3359 passed with stages
in 3 minutes and 13 seconds
......@@ -20,11 +20,11 @@
#include "../common.h"
#include "../context.h"
#if defined(__unix__)
#ifdef __unix__
#define VK_HAVE_UNIX 1
#endif
#if defined(_WIN32)
#ifdef _WIN32
#define VK_HAVE_WIN32 1
#endif
......@@ -87,6 +87,7 @@ struct vk_ctx {
VK_FUN(vkGetPhysicalDeviceProperties2KHR);
VK_FUN(vkGetPhysicalDeviceImageFormatProperties2KHR);
VK_FUN(vkGetPhysicalDeviceExternalBufferPropertiesKHR);
VK_FUN(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR);
// Device-level function pointers
VK_FUN(vkCmdPushDescriptorSetKHR);
......
......@@ -88,7 +88,10 @@ static const struct vk_ext vk_device_extensions[] = {
#endif
}, {
.name = VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
.funs = (struct vk_ext_fun[]) {{0}},
.funs = (struct vk_ext_fun[]) {
VK_INST_FUN(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR),
{0},
},
}, {
.name = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME,
.funs = (struct vk_ext_fun[]) {
......
......@@ -218,18 +218,33 @@ static void vk_setup_formats(struct pl_gpu *gpu)
static pl_handle_caps vk_sync_handle_caps(struct vk_ctx *vk)
{
pl_handle_caps ret = 0;
pl_handle_caps caps = 0;
#ifdef VK_HAVE_UNIX
if (vk->vkGetSemaphoreFdKHR)
ret |= PL_HANDLE_FD;
#endif
#ifdef VK_HAVE_WIN32
if (vk->vkGetSemaphoreWin32HandleKHR)
ret |= (PL_HANDLE_WIN32 | PL_HANDLE_WIN32_KMT);
#endif
if (!vk->vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)
return caps;
return ret;
for (int i = 0; vk_handle_list[i]; i++) {
enum pl_handle_type type = vk_handle_list[i];
VkPhysicalDeviceExternalSemaphoreInfoKHR info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR,
.handleType = vk_handle_type(type),
};
VkExternalSemaphorePropertiesKHR props = {
.sType = VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES_KHR,
};
vk->vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(vk->physd, &info, &props);
VkExternalSemaphoreFeatureFlagsKHR flags = props.externalSemaphoreFeatures;
if ((props.compatibleHandleTypes & info.handleType) &&
(flags & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR))
{
caps |= type;
}
}
return caps;
}
const struct pl_gpu *pl_gpu_create_vk(struct vk_ctx *vk)
......
......@@ -397,29 +397,19 @@ void vk_malloc_destroy(struct vk_malloc **ma_ptr)
pl_handle_caps vk_malloc_handle_caps(struct vk_malloc *ma)
{
struct vk_ctx *vk = ma->vk;
pl_handle_caps ret = 0;
pl_handle_caps caps = 0;
static const pl_handle_caps cap_list[] = {
#ifdef VK_HAVE_UNIX
PL_HANDLE_FD,
#endif
#ifdef VK_HAVE_WIN32
PL_HANDLE_WIN32,
PL_HANDLE_WIN32_KMT,
#endif
};
for (int i = 0; i < PL_ARRAY_SIZE(cap_list); i++) {
for (int i = 0; vk_handle_list[i]; i++) {
// Try seeing if we could allocate a "basic" buffer using these
// capabilities, with no fancy buffer usage. More specific checks will
// happen down the line at VkBuffer creation time, but this should give
// us a rough idea of what the driver supports.
enum pl_handle_type cap = cap_list[i];
if (buf_export_check(vk, VK_BUFFER_USAGE_TRANSFER_DST_BIT, cap))
ret |= cap;
enum pl_handle_type type = vk_handle_list[i];
if (buf_export_check(vk, VK_BUFFER_USAGE_TRANSFER_DST_BIT, type))
caps |= type;
}
return ret;
return caps;
}
void vk_free_memslice(struct vk_malloc *ma, struct vk_memslice slice)
......
......@@ -159,3 +159,14 @@ bool vk_external_mem_check(const VkExternalMemoryPropertiesKHR *props,
return true;
}
const enum pl_handle_type vk_handle_list[] = {
#ifdef VK_HAVE_UNIX
PL_HANDLE_FD,
#endif
#ifdef VK_HAVE_WIN32
PL_HANDLE_WIN32,
PL_HANDLE_WIN32_KMT,
#endif
0
};
......@@ -30,6 +30,9 @@ VkExternalMemoryHandleTypeFlagBitsKHR vk_handle_type(enum pl_handle_type);
bool vk_external_mem_check(const VkExternalMemoryPropertiesKHR *props,
enum pl_handle_type handle_type);
// Static list of external handle types we should try probing for
extern const enum pl_handle_type vk_handle_list[];
// Convenience macros to simplify a lot of common boilerplate
#define VK_ASSERT(res, str) \
do { \
......
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