From 89c9172f760dcc3d9f4e8b6e7631d9c80c091a56 Mon Sep 17 00:00:00 2001 From: Beatriz Navidad Vilches Date: Wed, 29 May 2024 10:45:54 +0200 Subject: [PATCH] Fix find_suitable_device logic to conditionally increment cl_device_count --- samples/extensions/khr/externalmemory/vulkan_utils.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.h b/samples/extensions/khr/externalmemory/vulkan_utils.h index 130bc45e..f2d82554 100644 --- a/samples/extensions/khr/externalmemory/vulkan_utils.h +++ b/samples/extensions/khr/externalmemory/vulkan_utils.h @@ -256,6 +256,12 @@ find_suitable_device(VkInstance instance, } } + if (!cl_device_count) + { + printf("No suitable OpenCL Vulkan-compatible devices available\n"); + goto platforms; + } + // For each OpenCL device, query its Vulkan-compatible device UUID and // add it to the list of candidates. The device must support the // cl_khr_device_uuid extension for us to be able to query the device's @@ -275,7 +281,7 @@ find_suitable_device(VkInstance instance, for (cl_uint cl_candidate_id = 0; cl_candidate_id < cl_platform_devices_count; - ++cl_candidate_id, ++cl_device_count) + ++cl_candidate_id) { cl_device_id device = cl_util_get_device( platform_id, cl_candidate_id, CL_DEVICE_TYPE_ALL, &error); @@ -292,6 +298,7 @@ find_suitable_device(VkInstance instance, memcpy(candidate.uuid, &vk_candidate_uuid, sizeof(cl_uchar) * CL_UUID_SIZE_KHR); cl_candidates[cl_device_count] = candidate; + cl_device_count++; } } }