vulkan: Use image row pitch (#2077)

When importing a Vulkan external image, query and
pass OpenCL a row pitch if OpenCL is assuming linear for the imported
external handle type. Additionally fix a bug where OpenCL is being told
to create mipmapped images at all times.

---------

Co-authored-by: dcrawley <dcrawley@qti.qualcomm.com>
This commit is contained in:
joshqti
2024-10-22 09:48:41 -07:00
committed by GitHub
parent ec6394488a
commit 5026b1be00
4 changed files with 34 additions and 3 deletions

View File

@@ -477,12 +477,13 @@ getCLImageInfoFromVkImageInfo(const VkImageCreateInfo *VulkanImageCreateInfo,
throw std::runtime_error("get2DImageDimensions failed!!!");
}
img_desc->image_depth = 0; // VulkanImageCreateInfo->extent.depth;
img_desc->image_depth =
static_cast<size_t>(VulkanImageCreateInfo->extent.depth);
img_desc->image_array_size = 0;
img_desc->image_row_pitch = 0; // Row pitch set to zero as host_ptr is NULL
img_desc->image_slice_pitch =
img_desc->image_row_pitch * img_desc->image_height;
img_desc->num_mip_levels = 1;
img_desc->num_mip_levels = 0;
img_desc->num_samples = 0;
img_desc->buffer = NULL;
@@ -676,6 +677,14 @@ clExternalMemoryImage::clExternalMemoryImage(
std::vector<cl_mem_properties> extMemProperties1;
cl_device_id devList[] = { deviceId, NULL };
VulkanImageTiling vulkanImageTiling =
vkClExternalMemoryHandleTilingAssumption(
deviceId, externalMemoryHandleType, &errcode_ret);
if (CL_SUCCESS != errcode_ret)
{
throw std::runtime_error("Failed to query OpenCL tiling mode");
}
#ifdef _WIN32
if (!is_extension_available(devList[0], "cl_khr_external_memory_win32"))
{
@@ -747,6 +756,15 @@ clExternalMemoryImage::clExternalMemoryImage(
throw std::runtime_error("getCLImageInfoFromVkImageInfo failed!!!");
}
// If OpenCL will assume linear, query the Vulkan image's row pitch,
// otherwise it may not match OpenCL's assumption of the row pitch.
if (vulkanImageTiling == VULKAN_IMAGE_TILING_LINEAR)
{
VkSubresourceLayout subresourceLayout = image2D.getSubresourceLayout();
image_desc.image_row_pitch = subresourceLayout.rowPitch;
image_desc.image_slice_pitch = subresourceLayout.depthPitch;
}
extMemProperties1.push_back(
(cl_mem_properties)CL_MEM_DEVICE_HANDLE_LIST_KHR);
extMemProperties1.push_back((cl_mem_properties)devList[0]);

View File

@@ -100,7 +100,8 @@
VK_FUNC_DECL(vkEnumerateDeviceExtensionProperties) \
VK_FUNC_DECL(vkGetPhysicalDeviceSurfaceSupportKHR) \
VK_FUNC_DECL(vkImportSemaphoreFdKHR) \
VK_FUNC_DECL(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR)
VK_FUNC_DECL(vkGetPhysicalDeviceExternalSemaphorePropertiesKHR) \
VK_FUNC_DECL(vkGetImageSubresourceLayout)
#define VK_WINDOWS_FUNC_LIST \
VK_FUNC_DECL(vkGetMemoryWin32HandleKHR) \
VK_FUNC_DECL(vkGetSemaphoreWin32HandleKHR) \
@@ -200,5 +201,6 @@
#define vkGetMemoryWin32HandleKHR _vkGetMemoryWin32HandleKHR
#define vkGetSemaphoreWin32HandleKHR _vkGetSemaphoreWin32HandleKHR
#define vkImportSemaphoreWin32HandleKHR _vkImportSemaphoreWin32HandleKHR
#define vkGetImageSubresourceLayout _vkGetImageSubresourceLayout
#endif //_vulkan_api_list_hpp_

View File

@@ -1870,6 +1870,16 @@ VulkanExtent3D VulkanImage2D::getExtent3D(uint32_t mipLevel) const
return VulkanExtent3D(width, height, depth);
}
VkSubresourceLayout VulkanImage2D::getSubresourceLayout() const
{
VkImageSubresource subresource = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 0 };
VkSubresourceLayout subresourceLayout = { 0 };
vkGetImageSubresourceLayout(m_device, m_vkImage, &subresource,
&subresourceLayout);
return subresourceLayout;
}
//////////////////////////////////
// VulkanImage3D implementation //
//////////////////////////////////

View File

@@ -552,6 +552,7 @@ public:
VulkanSharingMode sharingMode = VULKAN_SHARING_MODE_EXCLUSIVE);
virtual ~VulkanImage2D();
virtual VulkanExtent3D getExtent3D(uint32_t mipLevel = 0) const;
virtual VkSubresourceLayout getSubresourceLayout() const;
VulkanImage2D(const VulkanImage2D &image2D);
};