Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Vulkan resources via named NT handle #1895

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 87 additions & 18 deletions test_conformance/common/vulkan_wrapper/opencl_vulkan_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,20 @@ clExternalMemory::clExternalMemory(
#ifdef _WIN32
log_info("Opaque file descriptors are not supported on Windows\n");
ASSERT(0);
#endif
#else
fd = (int)deviceMemory->getHandle(externalMemoryHandleType);
err = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_FD_KHR);
extMemProperties.push_back((cl_mem_properties)fd);
#endif
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
#ifndef _WIN32
log_info("Opaque NT handles are only supported on Windows\n");
ASSERT(0);
#else
log_info(" Opaque NT handles are only supported on Windows\n");
handle = deviceMemory->getHandle(externalMemoryHandleType);
err = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
Expand All @@ -627,11 +628,35 @@ clExternalMemory::clExternalMemory(
extMemProperties.push_back((cl_mem_properties)handle);
#endif
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
#ifndef _WIN32
log_info("Opaque NT handles are only supported on Windows\n");
ASSERT(0);
#else
const std::wstring &name = deviceMemory->getName();
if (name.size())
{
err = check_external_memory_handle_type(
devList[0],
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
extMemProperties.push_back(
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
extMemProperties.push_back((cl_mem_properties)name.c_str());
}
else
{
throw std::runtime_error("Unsupported operation: import via "
"name but no name provided\n");
}
#endif
}
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
#ifndef _WIN32
log_info("Opaque D3DKMT handles are only supported on Windows\n");
ASSERT(0);
#else
handle = deviceMemory->getHandle(externalMemoryHandleType);
err = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
Expand All @@ -642,13 +667,13 @@ clExternalMemory::clExternalMemory(
#endif
break;
default:
ASSERT(0);
log_error("Unsupported external memory handle type\n");
ASSERT(0);
break;
}
if (CL_SUCCESS != err)
{
throw std::runtime_error("Unsupported external memory type\n ");
throw std::runtime_error("Unsupported external memory type\n");
}

extMemProperties.push_back(
Expand All @@ -663,7 +688,7 @@ clExternalMemory::clExternalMemory(
if (CL_SUCCESS != err)
{
log_error("clCreateBufferWithProperties failed with %d\n", err);
throw std::runtime_error("clCreateBufferWithProperties failed ");
throw std::runtime_error("clCreateBufferWithProperties failed\n");
}
}
clExternalMemoryImage::clExternalMemoryImage(
Expand Down Expand Up @@ -695,16 +720,33 @@ clExternalMemoryImage::clExternalMemoryImage(
{
#ifdef _WIN32
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT:
log_info("Opaque NT handles are only supported on Windows\n");
handle = deviceMemory.getHandle(externalMemoryHandleType);
errcode_ret = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties1.push_back(
(cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR);
extMemProperties1.push_back((cl_mem_properties)handle);
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
const std::wstring &name = deviceMemory.getName();
if (name.size())
{
errcode_ret = check_external_memory_handle_type(
devList[0],
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
extMemProperties1.push_back(
(cl_mem_properties)
CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_NAME_KHR);
extMemProperties1.push_back((cl_mem_properties)name.c_str());
}
else
{
throw std::runtime_error("Unsupported operation: import via "
"name but no name provided\n");
}
}
break;
case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT:
log_info("Opaque D3DKMT handles are only supported on Windows\n");
handle = deviceMemory.getHandle(externalMemoryHandleType);
errcode_ret = check_external_memory_handle_type(
devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR);
Expand All @@ -724,14 +766,15 @@ clExternalMemoryImage::clExternalMemoryImage(
break;
#endif
default:
ASSERT(0);
log_error("Unsupported external memory handle type\n");
ASSERT(0);
break;
}
if (CL_SUCCESS != errcode_ret)
{
throw std::runtime_error("Unsupported external memory type\n ");
throw std::runtime_error("Unsupported external memory type\n");
}

// Set cl_image_desc
size_t clImageFormatSize;
cl_image_desc image_desc;
Expand All @@ -744,7 +787,7 @@ clExternalMemoryImage::clExternalMemoryImage(
&VulkanImageCreateInfo, image2D.getSize(), &img_format, &image_desc);
if (CL_SUCCESS != errcode_ret)
{
throw std::runtime_error("getCLImageInfoFromVkImageInfo failed!!!");
throw std::runtime_error("getCLImageInfoFromVkImageInfo failed\n");
}

extMemProperties1.push_back(
Expand All @@ -758,7 +801,7 @@ clExternalMemoryImage::clExternalMemoryImage(
&image_desc, NULL, &errcode_ret);
if (CL_SUCCESS != errcode_ret)
{
throw std::runtime_error("clCreateImageWithProperties failed!!!");
throw std::runtime_error("clCreateImageWithProperties failed\n");
}
}

Expand Down Expand Up @@ -806,33 +849,59 @@ clExternalImportableSemaphore::clExternalImportableSemaphore(
switch (externalSemaphoreHandleType)
{
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD:
#ifdef _WIN32
log_info("Opaque file descriptors are not supported on Windows\n");
ASSERT(0);
#else
fd = (int)semaphore.getHandle(externalSemaphoreHandleType);
err = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props.push_back(
(cl_semaphore_properties_khr)CL_SEMAPHORE_HANDLE_OPAQUE_FD_KHR);
sema_props.push_back((cl_semaphore_properties_khr)fd);
#endif
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT:
#ifndef _WIN32
log_info("Opaque NT handles are only supported on Windows\n");
ASSERT(0);
#else
log_info(" Opaque NT handles are only supported on Windows\n");
handle = semaphore.getName().size()
? NULL
: semaphore.getHandle(externalSemaphoreHandleType);
handle = semaphore.getHandle(externalSemaphoreHandleType);
err = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props.push_back((cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KHR);
sema_props.push_back((cl_semaphore_properties_khr)handle);
#endif
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_NT_NAME: {
#ifndef _WIN32
log_info("Opaque NT handles are only supported on Windows\n");
ASSERT(0);
#else
const std::wstring &name = semaphore.getName();
if (name.size())
{
err = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR);
sema_props.push_back(
(cl_semaphore_properties_khr)
CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_NAME_KHR);
sema_props.push_back((cl_semaphore_properties_khr)name.c_str());
}
else
{
throw std::runtime_error("Unsupported operation: import via "
"name but no name provided\n");
}
#endif
}
break;
case VULKAN_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT:
#ifndef _WIN32
log_info("Opaque D3DKMT handles are only supported on Windows\n");
ASSERT(0);
#else
log_info(" Opaque D3DKMT handles are only supported on Windows\n");
handle = semaphore.getHandle(externalSemaphoreHandleType);
err = check_external_semaphore_handle_type(
devList[0], CL_SEMAPHORE_HANDLE_OPAQUE_WIN32_KMT_KHR);
Expand All @@ -850,8 +919,8 @@ clExternalImportableSemaphore::clExternalImportableSemaphore(
sema_props.push_back(static_cast<cl_semaphore_properties_khr>(-1));
break;
default:
ASSERT(0);
log_error("Unsupported external memory handle type\n");
ASSERT(0);
break;
}
if (CL_SUCCESS != err)
Expand Down
Loading
Loading