Skip to content

Commit

Permalink
Address review comments and fix code format issue
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhnv committed Apr 19, 2024
1 parent 413b2d5 commit 57f90bb
Showing 1 changed file with 83 additions and 68 deletions.
151 changes: 83 additions & 68 deletions test_conformance/common/vulkan_wrapper/opencl_vulkan_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,27 +517,26 @@ cl_int check_external_semaphore_handle_type(
cl_int errNum = CL_SUCCESS;

errNum =
clGetDeviceInfo(deviceID, queryParamName,
0, NULL, &handle_type_size);
clGetDeviceInfo(deviceID, queryParamName, 0, NULL, &handle_type_size);

if (handle_type_size == 0)
{
log_error("Device does not support %s semaphore\n",
queryParamName == CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR
? "importing"
: "exporting");
? "importing"
: "exporting");
return CL_INVALID_VALUE;
}

handle_type =
(cl_external_semaphore_handle_type_khr *)malloc(handle_type_size);

errNum =
clGetDeviceInfo(deviceID, queryParamName,
handle_type_size, handle_type, NULL);
errNum = clGetDeviceInfo(deviceID, queryParamName, handle_type_size,
handle_type, NULL);

test_error(errNum,
"Unable to query supported device semaphore handle types list");
test_error(
errNum,
"Unable to query supported device semaphore handle types list\n");

for (i = 0; i < handle_type_size; i++)
{
Expand Down Expand Up @@ -907,6 +906,8 @@ clExternalExportableSemaphore::clExternalExportableSemaphore(

cl_int err = 0;
cl_device_id devList[] = { deviceId, NULL };
cl_external_semaphore_handle_type_khr clSemaphoreHandleType =
getCLSemaphoreTypeFromVulkanType(externalSemaphoreHandleType);
m_externalHandleType = externalSemaphoreHandleType;
m_externalSemaphore = nullptr;
m_device = deviceId;
Expand All @@ -918,9 +919,7 @@ clExternalExportableSemaphore::clExternalExportableSemaphore(
};
sema_props.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR);
sema_props.push_back(
(cl_semaphore_properties_khr)getCLSemaphoreTypeFromVulkanType(
externalSemaphoreHandleType));
sema_props.push_back((cl_semaphore_properties_khr)clSemaphoreHandleType);
sema_props.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_EXPORT_HANDLE_TYPES_LIST_END_KHR);
sema_props.push_back(
Expand All @@ -939,66 +938,82 @@ clExternalExportableSemaphore::clExternalExportableSemaphore(
"clCreateSemaphoreWithPropertiesKHRptr failed! ");
}

if (m_externalHandleType == VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD)
switch (m_externalHandleType)
{
err = clGetSemaphoreHandleForTypeKHRptr(
m_externalSemaphore, m_device, CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR,
sizeof(int), &fd, nullptr);
if (err != CL_SUCCESS)
{
throw std::runtime_error("Failed to export OpenCL semaphore\n");
}
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD: {
err = clGetSemaphoreHandleForTypeKHRptr(
m_externalSemaphore, m_device, clSemaphoreHandleType,
sizeof(int), &fd, nullptr);
if (err != CL_SUCCESS)
{
throw std::runtime_error("Failed to export OpenCL semaphore\n");
}

VkImportSemaphoreFdInfoKHR vkImportSemaphoreFdInfoKHR = {};
vkImportSemaphoreFdInfoKHR.sType =
VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
vkImportSemaphoreFdInfoKHR.semaphore = m_deviceSemaphore;
vkImportSemaphoreFdInfoKHR.fd = fd;
vkImportSemaphoreFdInfoKHR.pNext = nullptr;
vkImportSemaphoreFdInfoKHR.handleType =
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
vkImportSemaphoreFdInfoKHR.flags = 0;

if (vkImportSemaphoreFdKHR(m_deviceSemaphore.getDevice(),
&vkImportSemaphoreFdInfoKHR)
!= VK_SUCCESS)
{
throw std::runtime_error(
"Failed to import semaphore in Vulkan\n");
}
}
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT: {
err = clGetSemaphoreHandleForTypeKHRptr(
m_externalSemaphore, m_device, clSemaphoreHandleType,
sizeof(void *), (void *)&handle, nullptr);
if (err != CL_SUCCESS)
{
throw std::runtime_error("Failed to export OpenCL semaphore\n");
}

VkImportSemaphoreFdInfoKHR vkImportSemaphoreFdInfoKHR = {};
vkImportSemaphoreFdInfoKHR.sType =
VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
vkImportSemaphoreFdInfoKHR.semaphore = m_deviceSemaphore;
vkImportSemaphoreFdInfoKHR.fd = fd;
vkImportSemaphoreFdInfoKHR.pNext = nullptr;
vkImportSemaphoreFdInfoKHR.handleType =
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR;
vkImportSemaphoreFdInfoKHR.flags = 0;

if (vkImportSemaphoreFdKHR(m_deviceSemaphore.getDevice(),
&vkImportSemaphoreFdInfoKHR)
!= VK_SUCCESS)
{
throw std::runtime_error("Failed to import semaphore in Vulkan\n");
}
}
#ifdef _WIN32
else
{
err = clGetSemaphoreHandleForTypeKHRptr(
m_externalSemaphore, m_device,
getCLSemaphoreTypeFromVulkanType(m_externalHandleType),
sizeof(void*), (void*)&handle, nullptr);
if (err != CL_SUCCESS)
{
throw std::runtime_error("Failed to export OpenCL semaphore\n");
}

VkImportSemaphoreWin32HandleInfoKHR
vkImportSemaphoreWin32HandleInfoKHR = {};
vkImportSemaphoreWin32HandleInfoKHR.sType =
VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR;
vkImportSemaphoreWin32HandleInfoKHR.pNext = nullptr;
vkImportSemaphoreWin32HandleInfoKHR.semaphore = m_deviceSemaphore;
vkImportSemaphoreWin32HandleInfoKHR.flags = 0;
vkImportSemaphoreWin32HandleInfoKHR.handleType =
(VkExternalSemaphoreHandleTypeFlagsKHR)m_externalHandleType;
vkImportSemaphoreWin32HandleInfoKHR.handle = (HANDLE)handle;
vkImportSemaphoreWin32HandleInfoKHR.name = nullptr;

if (vkImportSemaphoreWin32HandleKHR(
m_deviceSemaphore.getDevice(),
&vkImportSemaphoreWin32HandleInfoKHR)
!= VK_SUCCESS)
{
throw std::runtime_error("Failed to import semaphore in Vulkan\n");
}
}
VkImportSemaphoreWin32HandleInfoKHR
vkImportSemaphoreWin32HandleInfoKHR = {};
vkImportSemaphoreWin32HandleInfoKHR.sType =
VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR;
vkImportSemaphoreWin32HandleInfoKHR.pNext = nullptr;
vkImportSemaphoreWin32HandleInfoKHR.semaphore = m_deviceSemaphore;
vkImportSemaphoreWin32HandleInfoKHR.flags = 0;
vkImportSemaphoreWin32HandleInfoKHR.handleType =
(VkExternalSemaphoreHandleTypeFlagBits)m_externalHandleType;
vkImportSemaphoreWin32HandleInfoKHR.handle = (HANDLE)handle;
vkImportSemaphoreWin32HandleInfoKHR.name = nullptr;

if (vkImportSemaphoreWin32HandleKHR(
m_deviceSemaphore.getDevice(),
&vkImportSemaphoreWin32HandleInfoKHR)
!= VK_SUCCESS)
{
throw std::runtime_error(
"Failed to import semaphore in Vulkan\n");
}
#else
log_error(
"Opaque D3DKMT and NT handles are only supported on Windows\n");
ASSERT(0);
#endif
}
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD:
// Do nothing, imported after each signal from OpenCL
break;
default:
log_error("Unsupported external semaphore handle type\n");
ASSERT(0);
break;
}
}

clExternalExportableSemaphore::~clExternalExportableSemaphore()
Expand Down

0 comments on commit 57f90bb

Please sign in to comment.