diff --git a/src/vulkan/runtime/vk_queue.c b/src/vulkan/runtime/vk_queue.c index b54dff90d5d..c8b55b58b0a 100644 --- a/src/vulkan/runtime/vk_queue.c +++ b/src/vulkan/runtime/vk_queue.c @@ -1037,6 +1037,10 @@ vk_queue_wait_before_present(struct vk_queue *queue, return VK_SUCCESS; const uint32_t wait_count = pPresentInfo->waitSemaphoreCount; + + if (wait_count == 0) + return VK_SUCCESS; + STACK_ARRAY(struct vk_sync_wait, waits, wait_count); for (uint32_t i = 0; i < wait_count; i++) { diff --git a/src/vulkan/runtime/vk_sync_binary.c b/src/vulkan/runtime/vk_sync_binary.c index 3d2720f9348..c10cabe348a 100644 --- a/src/vulkan/runtime/vk_sync_binary.c +++ b/src/vulkan/runtime/vk_sync_binary.c @@ -91,6 +91,9 @@ vk_sync_binary_wait_many(struct vk_device *device, enum vk_sync_wait_flags wait_flags, uint64_t abs_timeout_ns) { + if (wait_count == 0) + return VK_SUCCESS; + STACK_ARRAY(struct vk_sync_wait, timeline_waits, wait_count); for (uint32_t i = 0; i < wait_count; i++) { diff --git a/src/vulkan/runtime/vk_synchronization.c b/src/vulkan/runtime/vk_synchronization.c index 53fb56e686d..701474164e4 100644 --- a/src/vulkan/runtime/vk_synchronization.c +++ b/src/vulkan/runtime/vk_synchronization.c @@ -249,6 +249,9 @@ vk_common_CmdWaitEvents( VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, commandBuffer); struct vk_device *device = cmd_buffer->base.device; + if (eventCount == 0) + return; + STACK_ARRAY(VkDependencyInfo, deps, eventCount); /* Note that dstStageMask and srcStageMask in the CmdWaitEvent2() call diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 85807f410fa..d29db67a4d0 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -352,14 +352,14 @@ vk_spec_info_to_nir_spirv(const VkSpecializationInfo *spec_info, #define STACK_ARRAY_SIZE 8 -#ifdef __cplusplus -#define STACK_ARRAY_ZERO_INIT {} -#else -#define STACK_ARRAY_ZERO_INIT {0} -#endif - +/* Sometimes gcc may claim -Wmaybe-uninitialized for the stack array in some + * places it can't verify that when size is 0 nobody down the call chain reads + * the array. Please don't try to fix it by zero-initializing the array here + * since it's used in a lot of different places. An "if (size == 0) return;" + * may work for you. + */ #define STACK_ARRAY(type, name, size) \ - type _stack_##name[STACK_ARRAY_SIZE] = STACK_ARRAY_ZERO_INIT; \ + type _stack_##name[STACK_ARRAY_SIZE]; \ type *const name = \ ((size) <= STACK_ARRAY_SIZE ? _stack_##name : (type *)malloc((size) * sizeof(type)))