Skip to content

Commit

Permalink
Add testing for sync_fd (#1747)
Browse files Browse the repository at this point in the history
Modify the external semaphore extension test
to use SYNC_FD, if available on the device.

Deleted tests that are not compatible with blocking
semaphores.
  • Loading branch information
lakshmih authored Aug 1, 2023
1 parent e29d0fd commit aa23f34
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 435 deletions.
57 changes: 44 additions & 13 deletions test_conformance/common/vulkan_wrapper/opencl_vulkan_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,42 @@ clExternalSemaphore::clExternalSemaphore(
cl_int err = 0;
cl_device_id devList[] = { deviceId, NULL };

#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_semaphore_win32"))
{
throw std::runtime_error("Device does not support "
"cl_khr_external_semaphore_win32 extension\n");
}
#elif !defined(__APPLE__)
if (!is_extension_available(devList[0],
"cl_khr_external_semaphore_opaque_fd"))
switch (externalSemaphoreHandleType)
{
throw std::runtime_error(
"Device does not support cl_khr_external_semaphore_opaque_fd "
"extension \n");
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
if (!is_extension_available(devList[0],
"cl_khr_external_semaphore_opaque_fd"))
{
throw std::runtime_error("Device does not support "
"cl_khr_external_semaphore_opaque_fd "
"extension \n");
}
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT:
if (!is_extension_available(devList[0],
"cl_khr_external_semaphore_win32"))
{
throw std::runtime_error(
"Device does not support "
"cl_khr_external_semaphore_win32 extension\n");
}
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD:
if (!is_extension_available(devList[0],
"cl_khr_external_semaphore_sync_fd"))
{
throw std::runtime_error(
"Device does not support cl_khr_external_semaphore_sync_fd "
"extension \n");
}
break;
default:
throw std::runtime_error(
"Unsupported external semaphore handle type\n");
break;
}
#endif

std::vector<cl_semaphore_properties_khr> sema_props{
(cl_semaphore_properties_khr)CL_SEMAPHORE_TYPE_KHR,
Expand Down Expand Up @@ -803,6 +824,16 @@ clExternalSemaphore::clExternalSemaphore(
sema_props.push_back((cl_semaphore_properties_khr)handle);
#endif
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD:
err = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_SYNC_FD_KHR);
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR));
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_HANDLE_SYNC_FD_KHR));
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_LIST_END_KHR));
break;
default:
ASSERT(0);
log_error("Unsupported external memory handle type\n");
Expand Down
30 changes: 30 additions & 0 deletions test_conformance/common/vulkan_wrapper/vulkan_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ getSupportedVulkanExternalSemaphoreHandleTypeList()
}
externalSemaphoreHandleTypeList.push_back(
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT);
#elif defined(__ANDROID__)
externalSemaphoreHandleTypeList.push_back(
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD);
#else
externalSemaphoreHandleTypeList.push_back(
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD);
Expand Down Expand Up @@ -480,6 +483,33 @@ const std::vector<VulkanFormat> getSupportedVulkanFormatList()
return formatList;
}

cl_external_semaphore_handle_type_khr getCLSemaphoreTypeFromVulkanType(
VulkanExternalSemaphoreHandleType vulkanExternalSemaphoreHandleType)
{
cl_external_semaphore_handle_type_khr clExternalSemaphoreHandleTypeKhr = 0;
switch (vulkanExternalSemaphoreHandleType)
{
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
clExternalSemaphoreHandleTypeKhr =
CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR;
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
clExternalSemaphoreHandleTypeKhr =
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR;
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT:
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
clExternalSemaphoreHandleTypeKhr =
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR;
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD:
clExternalSemaphoreHandleTypeKhr = CL_SEMAPHORE_HANDLE_SYNC_FD_KHR;
break;
default: break;
}
return clExternalSemaphoreHandleTypeKhr;
}

uint32_t getVulkanFormatElementSize(VulkanFormat format)
{
switch (format)
Expand Down
2 changes: 2 additions & 0 deletions test_conformance/common/vulkan_wrapper/vulkan_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const std::vector<VulkanFormat> getSupportedVulkanFormatList();
uint32_t getVulkanFormatElementSize(VulkanFormat format);
const char* getVulkanFormatGLSLFormat(VulkanFormat format);
const char* getVulkanFormatGLSLTypePrefix(VulkanFormat format);
cl_external_semaphore_handle_type_khr getCLSemaphoreTypeFromVulkanType(
VulkanExternalSemaphoreHandleType vulkanExternalSemaphoreHandleType);

std::string prepareVulkanShader(
std::string shaderCode,
Expand Down
2 changes: 2 additions & 0 deletions test_conformance/common/vulkan_wrapper/vulkan_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ VulkanInstance::VulkanInstance(): m_vkInstance(VK_NULL_HANDLE)

#if defined(_WIN32) || defined(_WIN64)
const char *vulkanLoaderLibraryName = "vulkan-1.dll";
#elif defined(__ANDROID__)
const char *vulkanLoaderLibraryName = "libvulkan.so";
#elif defined(__linux__)
const char *vulkanLoaderLibraryName = "libvulkan.so.1";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ enum VulkanExternalSemaphoreHandleType
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_KMT =
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT_KHR,
VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD =
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
};

enum VulkanBufferUsage
Expand Down
Loading

0 comments on commit aa23f34

Please sign in to comment.