From 25d5ed596354cc97ce0063b67b2df83b433129e6 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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/samples/extensions/khr/externalmemory/vulkan_utils.h b/samples/extensions/khr/externalmemory/vulkan_utils.h index 130bc45e..ddc1d078 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 @@ -263,6 +269,7 @@ find_suitable_device(VkInstance instance, struct cl_device_candidate* cl_candidates = (struct cl_device_candidate*)malloc( cl_device_count * sizeof(struct cl_device_candidate)); + const size_t cl_devices_with_ext = cl_device_count; cl_device_count = 0; for (cl_uint platform_id = 0; platform_id < platform_count; ++platform_id) @@ -275,7 +282,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 +299,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++; } } }