From 0db57da9daec5b7c15ea91189643e402bf2899ee Mon Sep 17 00:00:00 2001 From: Duncan Brawley Date: Wed, 31 Jul 2024 14:26:38 +0100 Subject: [PATCH] [Bindless][Exp] Fix urBindlessImagesImageGetInfoExp failing with mipmap images This patch fixes a crash due to urBindlessImagesImageGetInfoExp expecting a CUarray instead of a CUmipmappedArray. --- source/adapters/cuda/image.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/adapters/cuda/image.cpp b/source/adapters/cuda/image.cpp index 2b3d3ad667..91e47c5631 100644 --- a/source/adapters/cuda/image.cpp +++ b/source/adapters/cuda/image.cpp @@ -953,8 +953,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageGetInfoExp( ur_context_handle_t, ur_exp_image_mem_native_handle_t hImageMem, ur_image_info_t propName, void *pPropValue, size_t *pPropSizeRet) { + CUarray hCUarray; + CUresult Err = cuMipmappedArrayGetLevel( + &hCUarray, reinterpret_cast(hImageMem), 0); + + // If cuMipmappedArrayGetLevel failed, hImageMem is already CUarray. + if (Err != CUDA_SUCCESS) { + hCUarray = reinterpret_cast(hImageMem); + } + CUDA_ARRAY3D_DESCRIPTOR ArrayDesc; - UR_CHECK_ERROR(cuArray3DGetDescriptor(&ArrayDesc, (CUarray)hImageMem)); + UR_CHECK_ERROR(cuArray3DGetDescriptor(&ArrayDesc, hCUarray)); switch (propName) { case UR_IMAGE_INFO_WIDTH: if (pPropValue) {