diff --git a/test_conformance/common/vulkan_wrapper/vulkan_list_map.cpp b/test_conformance/common/vulkan_wrapper/vulkan_list_map.cpp index a5ca09018d..4b25e2cf18 100644 --- a/test_conformance/common/vulkan_wrapper/vulkan_list_map.cpp +++ b/test_conformance/common/vulkan_wrapper/vulkan_list_map.cpp @@ -268,6 +268,57 @@ VulkanBufferList::~VulkanBufferList() } } +////////////////////////////////////// +// VulkanImage1DList implementation // +////////////////////////////////////// + +VulkanImage1DList::VulkanImage1DList(const VulkanImage1DList &image1DList) {} + +VulkanImage1DList::VulkanImage1DList( + size_t numImages, std::vector &deviceMemory, + uint64_t baseOffset, uint64_t interImageOffset, const VulkanDevice &device, + VulkanFormat format, uint32_t width, uint32_t mipLevels, + VulkanImageTiling vulkanImageTiling, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) +{ + for (size_t i2DIdx = 0; i2DIdx < numImages; i2DIdx++) + { + VulkanImage1D *image2D = new VulkanImage1D( + device, format, width, vulkanImageTiling, mipLevels, + externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode); + add(*image2D); + deviceMemory[i2DIdx]->bindImage( + *image2D, baseOffset + (i2DIdx * interImageOffset)); + } +} + +VulkanImage1DList::VulkanImage1DList( + size_t numImages, const VulkanDevice &device, VulkanFormat format, + uint32_t width, VulkanImageTiling vulkanImageTiling, uint32_t mipLevels, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) +{ + for (size_t bIdx = 0; bIdx < numImages; bIdx++) + { + VulkanImage1D *image2D = new VulkanImage1D( + device, format, width, vulkanImageTiling, mipLevels, + externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode); + add(*image2D); + } +} + +VulkanImage1DList::~VulkanImage1DList() +{ + for (size_t i2DIdx = 0; i2DIdx < m_wrapperList.size(); i2DIdx++) + { + VulkanImage1D &image2D = m_wrapperList[i2DIdx]; + delete &image2D; + } +} + ////////////////////////////////////// // VulkanImage2DList implementation // ////////////////////////////////////// @@ -319,6 +370,57 @@ VulkanImage2DList::~VulkanImage2DList() } } +////////////////////////////////////// +// VulkanImage3DList implementation // +////////////////////////////////////// + +VulkanImage3DList::VulkanImage3DList(const VulkanImage3DList &image3DList) {} + +VulkanImage3DList::VulkanImage3DList( + size_t numImages, std::vector &deviceMemory, + uint64_t baseOffset, uint64_t interImageOffset, const VulkanDevice &device, + VulkanFormat format, uint32_t width, uint32_t height, uint32_t depth, + uint32_t mipLevels, VulkanImageTiling vulkanImageTiling, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) +{ + for (size_t i2DIdx = 0; i2DIdx < numImages; i2DIdx++) + { + VulkanImage3D *image3D = new VulkanImage3D( + device, format, width, height, depth, vulkanImageTiling, mipLevels, + externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode); + add(*image3D); + deviceMemory[i2DIdx]->bindImage( + *image3D, baseOffset + (i2DIdx * interImageOffset)); + } +} + +VulkanImage3DList::VulkanImage3DList( + size_t numImages, const VulkanDevice &device, VulkanFormat format, + uint32_t width, uint32_t height, uint32_t depth, + VulkanImageTiling vulkanImageTiling, uint32_t mipLevels, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) +{ + for (size_t bIdx = 0; bIdx < numImages; bIdx++) + { + VulkanImage3D *image3D = new VulkanImage3D( + device, format, width, height, depth, vulkanImageTiling, mipLevels, + externalMemoryHandleType, imageCreateFlag, imageUsage, sharingMode); + add(*image3D); + } +} + +VulkanImage3DList::~VulkanImage3DList() +{ + for (size_t i2DIdx = 0; i2DIdx < m_wrapperList.size(); i2DIdx++) + { + VulkanImage3D &image3D = m_wrapperList[i2DIdx]; + delete &image3D; + } +} //////////////////////////////////////// // VulkanImageViewList implementation // //////////////////////////////////////// diff --git a/test_conformance/common/vulkan_wrapper/vulkan_list_map.hpp b/test_conformance/common/vulkan_wrapper/vulkan_list_map.hpp index 7dd099c090..2ec57256d7 100644 --- a/test_conformance/common/vulkan_wrapper/vulkan_list_map.hpp +++ b/test_conformance/common/vulkan_wrapper/vulkan_list_map.hpp @@ -202,6 +202,35 @@ class VulkanBufferList : public VulkanList { virtual ~VulkanBufferList(); }; +class VulkanImage1DList : public VulkanList { +protected: + VulkanImage1DList(const VulkanImage1DList &image1DList); + +public: + VulkanImage1DList( + size_t numImages, std::vector &deviceMemory, + uint64_t baseOffset, uint64_t interImageOffset, + const VulkanDevice &device, VulkanFormat format, uint32_t width, + uint32_t mipLevels, VulkanImageTiling vulkanImageTiling, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + VulkanImage1DList( + size_t numImages, const VulkanDevice &device, VulkanFormat format, + uint32_t width, VulkanImageTiling vulkanImageTiling, + uint32_t mipLevels = 1, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + virtual ~VulkanImage1DList(); +}; + class VulkanImage2DList : public VulkanList { protected: VulkanImage2DList(const VulkanImage2DList &image2DList); @@ -232,6 +261,36 @@ class VulkanImage2DList : public VulkanList { virtual ~VulkanImage2DList(); }; +class VulkanImage3DList : public VulkanList { +protected: + VulkanImage3DList(const VulkanImage3DList &image3DList); + +public: + VulkanImage3DList( + size_t numImages, std::vector &deviceMemory, + uint64_t baseOffset, uint64_t interImageOffset, + const VulkanDevice &device, VulkanFormat format, uint32_t width, + uint32_t height, uint32_t depth, uint32_t mipLevels, + VulkanImageTiling vulkanImageTiling, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + VulkanImage3DList( + size_t numImages, const VulkanDevice &device, VulkanFormat format, + uint32_t width, uint32_t height, uint32_t depth, + VulkanImageTiling vulkanImageTiling, uint32_t mipLevels = 1, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + virtual ~VulkanImage3DList(); +}; + class VulkanImageViewList : public VulkanList { protected: VulkanImageViewList(const VulkanImageViewList &imageViewList); diff --git a/test_conformance/common/vulkan_wrapper/vulkan_wrapper.cpp b/test_conformance/common/vulkan_wrapper/vulkan_wrapper.cpp index b187181f3f..d175ba6fb4 100644 --- a/test_conformance/common/vulkan_wrapper/vulkan_wrapper.cpp +++ b/test_conformance/common/vulkan_wrapper/vulkan_wrapper.cpp @@ -1810,6 +1810,36 @@ const VulkanMemoryTypeList &VulkanImage::getMemoryTypeList() const VulkanImage::operator VkImage() const { return m_vkImage; } +////////////////////////////////// +// VulkanImage1D implementation // +////////////////////////////////// + +VulkanImage1D::VulkanImage1D(const VulkanImage1D &image1D): VulkanImage(image1D) +{} + +VulkanImage1D::VulkanImage1D( + const VulkanDevice &device, VulkanFormat format, uint32_t width, + VulkanImageTiling imageTiling, uint32_t numMipLevels, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) + : VulkanImage(device, VULKAN_IMAGE_TYPE_1D, format, + VulkanExtent3D(width, 1, 1), numMipLevels, 1, + externalMemoryHandleType, imageCreateFlag, imageTiling, + imageUsage, sharingMode) +{} + +VulkanImage1D::~VulkanImage1D() {} + +VulkanExtent3D VulkanImage1D::getExtent3D(uint32_t mipLevel) const +{ + uint32_t width = std::max(m_extent3D.getWidth() >> mipLevel, uint32_t(1)); + uint32_t height = 1; + uint32_t depth = 1; + + return VulkanExtent3D(width, height, depth); +} + ////////////////////////////////// // VulkanImage2D implementation // ////////////////////////////////// @@ -1840,6 +1870,37 @@ VulkanExtent3D VulkanImage2D::getExtent3D(uint32_t mipLevel) const return VulkanExtent3D(width, height, depth); } +////////////////////////////////// +// VulkanImage3D implementation // +////////////////////////////////// + +VulkanImage3D::VulkanImage3D(const VulkanImage3D &image3D): VulkanImage(image3D) +{} + +VulkanImage3D::VulkanImage3D( + const VulkanDevice &device, VulkanFormat format, uint32_t width, + uint32_t height, uint32_t depth, VulkanImageTiling imageTiling, + uint32_t numMipLevels, + VulkanExternalMemoryHandleType externalMemoryHandleType, + VulkanImageCreateFlag imageCreateFlag, VulkanImageUsage imageUsage, + VulkanSharingMode sharingMode) + : VulkanImage(device, VULKAN_IMAGE_TYPE_3D, format, + VulkanExtent3D(width, height, depth), numMipLevels, 1, + externalMemoryHandleType, imageCreateFlag, imageTiling, + imageUsage, sharingMode) +{} + +VulkanImage3D::~VulkanImage3D() {} + +VulkanExtent3D VulkanImage3D::getExtent3D(uint32_t mipLevel) const +{ + uint32_t width = std::max(m_extent3D.getWidth() >> mipLevel, uint32_t(1)); + uint32_t height = std::max(m_extent3D.getHeight() >> mipLevel, uint32_t(1)); + uint32_t depth = std::max(m_extent3D.getDepth() >> mipLevel, uint32_t(1)); + + return VulkanExtent3D(width, height, depth); +} + //////////////////////////////////// // VulkanImageView implementation // //////////////////////////////////// diff --git a/test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp b/test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp index a520dceea7..f9f547b829 100644 --- a/test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp +++ b/test_conformance/common/vulkan_wrapper/vulkan_wrapper.hpp @@ -494,6 +494,47 @@ class VulkanImage { operator VkImage() const; }; +class VulkanImage1D : public VulkanImage { +protected: + VkImageView m_vkImageView; + +public: + VulkanImage1D( + const VulkanDevice &device, VulkanFormat format, uint32_t width, + VulkanImageTiling imageTiling, uint32_t numMipLevels = 1, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + virtual ~VulkanImage1D(); + virtual VulkanExtent3D getExtent3D(uint32_t mipLevel = 0) const; + + VulkanImage1D(const VulkanImage1D &image1D); +}; + +class VulkanImage3D : public VulkanImage { +protected: + VkImageView m_vkImageView; + +public: + VulkanImage3D( + const VulkanDevice &device, VulkanFormat format, uint32_t width, + uint32_t height, uint32_t depth, VulkanImageTiling imageTiling, + uint32_t numMipLevels = 1, + VulkanExternalMemoryHandleType externalMemoryHandleType = + VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_NONE, + VulkanImageCreateFlag imageCreateFlag = VULKAN_IMAGE_CREATE_FLAG_NONE, + VulkanImageUsage imageUsage = + VULKAN_IMAGE_USAGE_SAMPLED_STORAGE_TRANSFER_SRC_DST, + VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE); + virtual ~VulkanImage3D(); + virtual VulkanExtent3D getExtent3D(uint32_t mipLevel = 0) const; + + VulkanImage3D(const VulkanImage3D &image3D); +}; + class VulkanImage2D : public VulkanImage { protected: VkImageView m_vkImageView; diff --git a/test_conformance/common/vulkan_wrapper/vulkan_wrapper_types.hpp b/test_conformance/common/vulkan_wrapper/vulkan_wrapper_types.hpp index 86d7381322..5164ade5cc 100644 --- a/test_conformance/common/vulkan_wrapper/vulkan_wrapper_types.hpp +++ b/test_conformance/common/vulkan_wrapper/vulkan_wrapper_types.hpp @@ -44,7 +44,9 @@ class VulkanBuffer; class VulkanOffset3D; class VulkanExtent3D; class VulkanImage; +class VulkanImage1D; class VulkanImage2D; +class VulkanImage3D; class VulkanImageView; class VulkanDeviceMemory; class VulkanSemaphore; @@ -59,7 +61,9 @@ class VulkanQueueList; class VulkanCommandBufferList; class VulkanDescriptorSetLayoutList; class VulkanBufferList; +class VulkanImage1DList; class VulkanImage2DList; +class VulkanImage3DList; class VulkanImageViewList; class VulkanDeviceMemoryList; class VulkanSemaphoreList; diff --git a/test_conformance/vulkan/CMakeLists.txt b/test_conformance/vulkan/CMakeLists.txt index 9c9cc7d472..33eacffe2c 100644 --- a/test_conformance/vulkan/CMakeLists.txt +++ b/test_conformance/vulkan/CMakeLists.txt @@ -25,6 +25,8 @@ set (${MODULE_NAME}_SOURCES test_vulkan_interop_buffer.cpp test_vulkan_interop_image.cpp test_vulkan_api_consistency.cpp + test_vulkan_api_consistency_for_3dimages.cpp + test_vulkan_api_consistency_for_1dimages.cpp test_vulkan_platform_device_info.cpp vulkan_interop_common.cpp ../../test_common/harness/genericThread.cpp diff --git a/test_conformance/vulkan/main.cpp b/test_conformance/vulkan/main.cpp index aec3f7c52a..4f560f96b2 100644 --- a/test_conformance/vulkan/main.cpp +++ b/test_conformance/vulkan/main.cpp @@ -157,6 +157,8 @@ test_definition test_list[] = { ADD_TEST(buffer_single_queue), ADD_TEST(image_multiple_queue), ADD_TEST(consistency_external_buffer), ADD_TEST(consistency_external_image), + ADD_TEST(consistency_external_for_3dimage), + ADD_TEST(consistency_external_for_1dimage), ADD_TEST(consistency_external_semaphore), ADD_TEST(platform_info), ADD_TEST(device_info) }; diff --git a/test_conformance/vulkan/procs.h b/test_conformance/vulkan/procs.h index 37bf7869c0..d5465d7a28 100644 --- a/test_conformance/vulkan/procs.h +++ b/test_conformance/vulkan/procs.h @@ -28,6 +28,14 @@ extern int test_consistency_external_image(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements); +extern int test_consistency_external_for_3dimage(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements); +extern int test_consistency_external_for_1dimage(cl_device_id device, + cl_context context, + cl_command_queue queue, + int num_elements); extern int test_consistency_external_semaphore(cl_device_id device, cl_context context, cl_command_queue queue, diff --git a/test_conformance/vulkan/test_vulkan_api_consistency_for_1dimages.cpp b/test_conformance/vulkan/test_vulkan_api_consistency_for_1dimages.cpp new file mode 100644 index 0000000000..2df210081c --- /dev/null +++ b/test_conformance/vulkan/test_vulkan_api_consistency_for_1dimages.cpp @@ -0,0 +1,206 @@ +#include +#include +#include +#if !defined(__APPLE__) +#include +#include +#else +#include +#include +#endif + +#include +#include +#include +#include +#include "harness/testHarness.h" +#include "harness/typeWrappers.h" +#include "harness/deviceInfo.h" + +int test_consistency_external_for_1dimage(cl_device_id deviceID, + cl_context _context, + cl_command_queue _queue, + int num_elements) +{ + cl_int errNum; + VulkanDevice vkDevice; + + // Context and command queue creation + cl_platform_id platform = NULL; + cl_context context = NULL; + cl_command_queue cmd_queue = NULL; + + cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 }; + errNum = clGetPlatformIDs(1, &platform, NULL); + test_error(errNum, "Failed to get platform id"); + + contextProperties[1] = (cl_context_properties)platform; + + context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, + NULL, NULL, &errNum); + test_error(errNum, "Unable to create context with properties"); + + cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum); + test_error(errNum, "Unable to create command queue"); + + cl_device_id devList[] = { deviceID, NULL }; + +#ifdef _WIN32 + if (!is_extension_available(devList[0], "cl_khr_external_memory_win32")) + { + throw std::runtime_error("Device does not support" + "cl_khr_external_memory_win32 extension \n"); + } +#else + if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd")) + { + throw std::runtime_error( + "Device does not support cl_khr_external_memory_opaque_fd " + "extension \n"); + } +#endif + uint32_t width = 256; + cl_image_desc image_desc; + memset(&image_desc, 0x0, sizeof(cl_image_desc)); + cl_image_format img_format = { 0 }; + + VulkanExternalMemoryHandleType vkExternalMemoryHandleType = + getSupportedVulkanExternalMemoryHandleTypeList()[0]; + + VulkanImageTiling vulkanImageTiling = + vkClExternalMemoryHandleTilingAssumption( + deviceID, vkExternalMemoryHandleType, &errNum); + ASSERT_SUCCESS(errNum, "Failed to query OpenCL tiling mode"); + + VulkanImage1D vkImage1D = + VulkanImage1D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, + vulkanImageTiling, 1, vkExternalMemoryHandleType); + + const VulkanMemoryTypeList& memoryTypeList = vkImage1D.getMemoryTypeList(); + uint64_t totalImageMemSize = vkImage1D.getSize(); + + log_info("Memory type index: %u\n", (uint32_t)memoryTypeList[0]); + log_info("Memory type property: %d\n", + memoryTypeList[0].getMemoryTypeProperty()); + log_info("Image size : %lu\n", totalImageMemSize); + + VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory( + vkDevice, vkImage1D, memoryTypeList[0], vkExternalMemoryHandleType); + vkDeviceMem->bindImage(vkImage1D, 0); + + void* handle = NULL; + int fd; + std::vector extMemProperties{ + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)devList[0], + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR, + }; + switch (vkExternalMemoryHandleType) + { +#ifdef _WIN32 + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT: + handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = check_external_memory_handle_type( + devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR); + extMemProperties.push_back( + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR); + extMemProperties.push_back((cl_mem_properties)handle); + break; + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT: + handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = check_external_memory_handle_type( + devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR); + extMemProperties.push_back( + (cl_mem_properties) + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR); + extMemProperties.push_back((cl_mem_properties)handle); + break; +#else + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD: + fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = 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); + break; +#endif + default: + errNum = TEST_FAIL; + log_error("Unsupported external memory handle type \n"); + break; + } + if (errNum != CL_SUCCESS) + { + log_error("Checks failed for " + "CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR\n"); + return TEST_FAIL; + } + extMemProperties.push_back(0); + + const VkImageCreateInfo VulkanImageCreateInfo = + vkImage1D.getVkImageCreateInfo(); + + errNum = getCLImageInfoFromVkImageInfo( + &VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc); + if (errNum != CL_SUCCESS) + { + log_error("getCLImageInfoFromVkImageInfo failed!!!"); + return TEST_FAIL; + } + + clMemWrapper image; + + // Pass valid properties, image_desc and image_format + image = clCreateImageWithProperties( + context, extMemProperties.data(), CL_MEM_READ_WRITE, &img_format, + &image_desc, NULL /* host_ptr */, &errNum); + test_error(errNum, "Unable to create Image with Properties"); + image.reset(); + + // Passing properties, image_desc and image_format all as NULL + image = clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE, NULL, + NULL, NULL, &errNum); + test_failure_error( + errNum, CL_INVALID_IMAGE_DESCRIPTOR, + "Image creation must fail with CL_INVALID_IMAGE_DESCRIPTOR " + "when all are passed as NULL"); + + image.reset(); + + // Passing NULL properties and a valid image_format and image_desc + image = + clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE, + &img_format, &image_desc, NULL, &errNum); + test_error(errNum, + "Unable to create image with NULL properties " + "with valid image format and image desc"); + + image.reset(); + + // Passing image_format as NULL + image = clCreateImageWithProperties(context, extMemProperties.data(), + CL_MEM_READ_WRITE, NULL, &image_desc, + NULL, &errNum); + test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, + "Image creation must fail with " + "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR" + "when image desc passed as NULL"); + + image.reset(); + + // Passing image_desc as NULL + image = clCreateImageWithProperties(context, extMemProperties.data(), + CL_MEM_READ_WRITE, &img_format, NULL, + NULL, &errNum); + test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR, + "Image creation must fail with " + "CL_INVALID_IMAGE_DESCRIPTOR " + "when image desc passed as NULL"); + image.reset(); + + if (cmd_queue) clReleaseCommandQueue(cmd_queue); + if (context) clReleaseContext(context); + + return TEST_PASS; +} diff --git a/test_conformance/vulkan/test_vulkan_api_consistency_for_3dimages.cpp b/test_conformance/vulkan/test_vulkan_api_consistency_for_3dimages.cpp new file mode 100644 index 0000000000..f8a7861cec --- /dev/null +++ b/test_conformance/vulkan/test_vulkan_api_consistency_for_3dimages.cpp @@ -0,0 +1,210 @@ +#include +#include +#include +#if !defined(__APPLE__) +#include +#include +#else +#include +#include +#endif + +#include +#include +#include +#include +#include "harness/testHarness.h" +#include "harness/typeWrappers.h" +#include "harness/deviceInfo.h" +#include + + +int test_consistency_external_for_3dimage(cl_device_id deviceID, + cl_context _context, + cl_command_queue _queue, + int num_elements) +{ + cl_int errNum; + VulkanDevice vkDevice; + + // Context and command queue creation + cl_platform_id platform = NULL; + cl_context context = NULL; + cl_command_queue cmd_queue = NULL; + + cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, 0, 0 }; + errNum = clGetPlatformIDs(1, &platform, NULL); + test_error(errNum, "Failed to get platform id"); + + contextProperties[1] = (cl_context_properties)platform; + + context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, + NULL, NULL, &errNum); + test_error(errNum, "Unable to create context with properties"); + + cmd_queue = clCreateCommandQueue(context, deviceID, 0, &errNum); + test_error(errNum, "Unable to create command queue"); + + cl_device_id devList[] = { deviceID, NULL }; + +#ifdef _WIN32 + if (!is_extension_available(devList[0], "cl_khr_external_memory_win32")) + { + throw std::runtime_error("Device does not support" + "cl_khr_external_memory_win32 extension \n"); + } +#else + if (!is_extension_available(devList[0], "cl_khr_external_memory_opaque_fd")) + { + throw std::runtime_error( + "Device does not support cl_khr_external_memory_opaque_fd " + "extension \n"); + } +#endif + uint32_t width = 256; + uint32_t height = 16; + uint32_t depth = 10; + cl_image_desc image_desc; + memset(&image_desc, 0x0, sizeof(cl_image_desc)); + cl_image_format img_format = { 0 }; + + VulkanExternalMemoryHandleType vkExternalMemoryHandleType = + getSupportedVulkanExternalMemoryHandleTypeList()[0]; + + VulkanImageTiling vulkanImageTiling = + vkClExternalMemoryHandleTilingAssumption( + deviceID, vkExternalMemoryHandleType, &errNum); + ASSERT_SUCCESS(errNum, "Failed to query OpenCL tiling mode"); + + VulkanImage3D vkImage3D = + VulkanImage3D(vkDevice, VULKAN_FORMAT_R8G8B8A8_UNORM, width, height, + depth, vulkanImageTiling, 1, vkExternalMemoryHandleType); + + const VulkanMemoryTypeList& memoryTypeList = vkImage3D.getMemoryTypeList(); + uint64_t totalImageMemSize = vkImage3D.getSize(); + + log_info("Memory type index: %u\n", (uint32_t)memoryTypeList[0]); + log_info("Memory type property: %d\n", + memoryTypeList[0].getMemoryTypeProperty()); + log_info("Image size : %lu\n", totalImageMemSize); + + VulkanDeviceMemory* vkDeviceMem = new VulkanDeviceMemory( + vkDevice, vkImage3D, memoryTypeList[0], vkExternalMemoryHandleType); + vkDeviceMem->bindImage(vkImage3D, 0); + + void* handle = NULL; + int fd; + std::vector extMemProperties{ + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR, + (cl_mem_properties)devList[0], + (cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_END_KHR, + }; + switch (vkExternalMemoryHandleType) + { +#ifdef _WIN32 + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_NT: + handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = check_external_memory_handle_type( + devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR); + extMemProperties.push_back( + (cl_mem_properties)CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR); + extMemProperties.push_back((cl_mem_properties)handle); + break; + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT: + handle = vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = check_external_memory_handle_type( + devList[0], CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR); + extMemProperties.push_back( + (cl_mem_properties) + CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KMT_KHR); + extMemProperties.push_back((cl_mem_properties)handle); + break; +#else + case VULKAN_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD: + fd = (int)vkDeviceMem->getHandle(vkExternalMemoryHandleType); + errNum = 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); + break; +#endif + default: + errNum = TEST_FAIL; + log_error("Unsupported external memory handle type \n"); + break; + } + if (errNum != CL_SUCCESS) + { + log_error("Checks failed for " + "CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR\n"); + return TEST_FAIL; + } + extMemProperties.push_back(0); + + const VkImageCreateInfo VulkanImageCreateInfo = + vkImage3D.getVkImageCreateInfo(); + + errNum = getCLImageInfoFromVkImageInfo( + &VulkanImageCreateInfo, totalImageMemSize, &img_format, &image_desc); + if (errNum != CL_SUCCESS) + { + log_error("getCLImageInfoFromVkImageInfo failed!!!"); + return TEST_FAIL; + } + + clMemWrapper image; + + // Pass valid properties, image_desc and image_format + image = clCreateImageWithProperties( + context, extMemProperties.data(), CL_MEM_READ_WRITE, &img_format, + &image_desc, NULL /* host_ptr */, &errNum); + test_error(errNum, "Unable to create Image with Properties"); + image.reset(); + + // Passing properties, image_desc and image_format all as NULL + image = clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE, NULL, + NULL, NULL, &errNum); + test_failure_error( + errNum, CL_INVALID_IMAGE_DESCRIPTOR, + "Image creation must fail with CL_INVALID_IMAGE_DESCRIPTOR " + "when all are passed as NULL"); + + image.reset(); + + // Passing NULL properties and a valid image_format and image_desc + image = + clCreateImageWithProperties(context, NULL, CL_MEM_READ_WRITE, + &img_format, &image_desc, NULL, &errNum); + test_error(errNum, + "Unable to create image with NULL properties " + "with valid image format and image desc"); + + image.reset(); + + // Passing image_format as NULL + image = clCreateImageWithProperties(context, extMemProperties.data(), + CL_MEM_READ_WRITE, NULL, &image_desc, + NULL, &errNum); + test_failure_error(errNum, CL_INVALID_IMAGE_FORMAT_DESCRIPTOR, + "Image creation must fail with " + "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR" + "when image desc passed as NULL"); + + image.reset(); + + // Passing image_desc as NULL + image = clCreateImageWithProperties(context, extMemProperties.data(), + CL_MEM_READ_WRITE, &img_format, NULL, + NULL, &errNum); + test_failure_error(errNum, CL_INVALID_IMAGE_DESCRIPTOR, + "Image creation must fail with " + "CL_INVALID_IMAGE_DESCRIPTOR " + "when image desc passed as NULL"); + image.reset(); + + if (cmd_queue) clReleaseCommandQueue(cmd_queue); + if (context) clReleaseContext(context); + + return TEST_PASS; +}