mesa/src/vulkan/util
Paulo Zanoni b0653370d0 vulkan: don't zero-initialize STACK_ARRAY()'s stack array
STACK_ARRAY() is used in a lot of places. When games are running we
see STACK_ARRAY() arrays being used all the time: each queue
submission uses 6, WaitSemaphores and syncobj waiting also uses them:
they're constantly present in Vulkan runtime.

There's no need for STACK_ARRAY()'s stack array to be initialized,
callers cannot not depend on it. If the number of elements is greater
than STACK_ARRAY_SIZE, then STACK_ARRAY() will just malloc() the array
and return it not initialized: anybody depending of
zero-initialization is going to break when the array is big.

The reason why we're zero-intializing STACK_ARRAY()'s stack array is
to silence -Wmaybe-uninitialized warnings: see commit d7957df318
("vulkan: fix uninitialized variables"). I don't think that commit is
the ideal way to deal with the problem, so this patch proposes a
better solution.

The problem here is that zero-initializing it adds code we don't need
for every single caller. STACK_ARRAY() already has 63 callers and only
3 of them are affected by the -Wmaybe-uninitialized warining. So here
we undo what commit d7957df318 did and instead we fix the 3 cases
that actually generate the -Wmaybe-uninitialized warnings.

Gcc is only emitting those warinings because it knows that the number
of elements in the array may be zero, so the loops we have that set
elements to the array may end up do nothing, and then we pass the
array uninitialized to other functions.

For the cases related to vk_sync this is just returning VK_SUCCESS
earlier, instead of relying on the check that eventually happens at
__vk_sync_wait_many(). For the vkCmdWaitEvents() function, the Vulkan
spec says that "eventCount must be greater than 0", so the early
return doesn't hurt anybody either. In both cases we make the zero
case faster by not defining an 8-sized array, zero-initializing it,
then returning success without using it.

Reference: d7957df318 ("vulkan: fix uninitialized variables")
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28288>
2024-04-08 17:23:25 +00:00
..
gen_enum_to_str.py vk/enum2str: add more max enum vendors 2023-09-13 18:57:42 +00:00
meson.build vulkan: remove header files from lib source files 2024-03-08 21:42:07 +00:00
vk_alloc.c
vk_alloc.h vulkan/multialloc: bump max number to 16 2024-02-01 13:20:21 +00:00
vk_cmd_queue_gen.py vulkan/cmd_queue: Implement CmdBuildAccelerationStructuresKHR 2024-03-06 16:34:25 +00:00
vk_dispatch_table_gen.py vulkan/dispatch_table: add an uncompacted version of the table 2024-02-29 11:18:18 +00:00
vk_dispatch_trampolines_gen.py mesa/vulkan: use a simpler path for header in trampoline gen 2024-01-18 18:45:40 +00:00
vk_entrypoints.py vulkan: write beta extensions into generator scripts. 2023-05-04 02:40:06 +00:00
vk_entrypoints_gen.py vulkan: write beta extensions into generator scripts. 2023-05-04 02:40:06 +00:00
vk_extensions.py vulkan: write beta extensions into generator scripts. 2023-05-04 02:40:06 +00:00
vk_extensions_gen.py vulkan/util: drop redundant code gen from vk_extensions_gen.py 2024-02-01 19:29:48 +00:00
vk_format.c vk/util: update symbols that have become aliases for newer ones 2023-12-04 23:27:29 +00:00
vk_format.h vulkan: Move vk_format_is_alpha and vk_format_is_alpha_on_msb into vk_format.h from pvr 2024-03-28 04:11:52 +00:00
vk_icd_gen.py vk/util: print a nice error in vk_icd_gen.py when VK_HEADER_VERSION is not defined 2024-02-29 14:25:49 +00:00
vk_physical_device_features_gen.py vk/util: fix 'beta' check for physical device features 2024-01-31 20:47:30 +00:00
vk_physical_device_properties_gen.py vulkan/properties: Start looping from the next member in GPDP2 2024-02-20 09:16:23 +00:00
vk_struct_type_cast_gen.py vulkan: write beta extensions into generator scripts. 2023-05-04 02:40:06 +00:00
vk_synchronization_helpers_gen.py util,vulkan,mesa,compiler: Generate source files with utf8 encoding from mako template 2023-12-07 12:41:07 +00:00
vk_util.c Revert "meson/vulkan/util: allow venus to drop compiler deps" 2024-03-07 20:33:28 +00:00
vk_util.h vulkan: don't zero-initialize STACK_ARRAY()'s stack array 2024-04-08 17:23:25 +00:00