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]);