Skip to content

Commit

Permalink
Test windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Beanavil committed Dec 14, 2023
1 parent c0ae855 commit 3016659
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
35 changes: 18 additions & 17 deletions samples/extensions/khr/externalmemory/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,6 @@ bool cl_check_external_memory_handle_type(
exit(EXIT_FAILURE);
}

// Vulkan function to export a:
// - POSIX file descriptor or
// - a Windows handle
// referencing the payload of a Vulkan device memory object.
const char* vk_get_memory_function_name =
#ifdef _WIN32
"vkGetMemoryWin32HandleKHR"
#else
"vkGetMemoryFdKHR"
#endif
;

int main(int argc, char* argv[])
{
cl_int error = CL_SUCCESS;
Expand Down Expand Up @@ -513,14 +501,27 @@ int main(int argc, char* argv[])
fd_info_y.handleType = vk_external_memory_handle_type;
int fd_y;

// We need to get the pointer to the vkGetMemoryFdKHR function because it's
// from extension VK_KHR_external_memory_fd.
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR =
// We need to get the pointer to the
// vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from
// extension VK_KHR_external_memory_fd. This Vulkan function exports a POSIX
// file descriptor/Windows handle referencing the payload of a Vulkan device
// memory object.
#ifdef _WIN32
PFN_vkGetMemoryWin32HandleKHR vkGetMemoryWin32HandleKHR;
*(PFN_vkGetMemoryWin32HandleKHR*)&vkGetMemoryWin32HandleKHR =
(PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr(
vk_device, "vkGetMemoryWin32HandleKHR");
VK_CHECK(vkGetMemoryWin32HandleKHR(vk_device, &fd_info_x, &fd_x));
VK_CHECK(vkGetMemoryWin32HandleKHR(vk_device, &fd_info_y, &fd_y));
#else
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR;
*(PFN_vkGetMemoryFdKHR*)&vkGetMemoryFdKHR =
(PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device,
vk_get_memory_function_name);

"vkGetMemoryFdKHR");
VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x));
VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y));
#endif


// Create OpenCL buffers from Vulkan external memory file descriptors.
cl_mem_properties ext_mem_props_x[] = {
Expand Down
36 changes: 18 additions & 18 deletions samples/extensions/khr/externalmemory/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,6 @@ bool cl_check_external_memory_handle_type(
return it != supported_handle_types.end();
}

// Vulkan function to export a:
// - POSIX file descriptor or
// - a Windows handle
// referencing the payload of a Vulkan device memory object.
const std::string vk_get_memory_function_name =
#ifdef _WIN32
std::string{ "vkGetMemoryWin32HandleKHR" }
#else
std::string{ "vkGetMemoryFdKHR" }
#endif
;

int main(int argc, char* argv[])
{
try
Expand Down Expand Up @@ -432,14 +420,26 @@ int main(int argc, char* argv[])
fd_info_y.handleType = vk_external_memory_handle_type;
int fd_y;

// We need to get the pointer to the vkGetMemoryFdKHR function because
// it's from extension VK_KHR_external_memory_fd.
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR =
(PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(
vk_device, vk_get_memory_function_name.c_str());

// We need to get the pointer to the
// vkGetMemoryFdKHR/vkGetMemoryWin32HandleKHR function because it's from
// extension VK_KHR_external_memory_fd. This Vulkan function exports a
// POSIX file descriptor/Windows handle referencing the payload of a
// Vulkan device memory object.
#ifdef _WIN32
PFN_vkGetMemoryWin32HandleKHR vkGetMemoryWin32HandleKHR;
*(PFN_vkGetMemoryWin32HandleKHR*)&vkGetMemoryWin32HandleKHR =
(PFN_vkGetMemoryWin32HandleKHR)vkGetDeviceProcAddr(
vk_device, "vkGetMemoryWin32HandleKHR");
VK_CHECK(vkGetMemoryWin32HandleKHR(vk_device, &fd_info_x, &fd_x));
VK_CHECK(vkGetMemoryWin32HandleKHR(vk_device, &fd_info_y, &fd_y));
#else
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR;
*(PFN_vkGetMemoryFdKHR*)&vkGetMemoryFdKHR =
(PFN_vkGetMemoryFdKHR)vkGetDeviceProcAddr(vk_device,
"vkGetMemoryFdKHR");
VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_x, &fd_x));
VK_CHECK(vkGetMemoryFdKHR(vk_device, &fd_info_y, &fd_y));
#endif

// Create OpenCL buffers from Vulkan external memory file descriptors.
std::vector<cl_mem_properties> ext_mem_props_x = {
Expand Down

0 comments on commit 3016659

Please sign in to comment.