Mesa (main): vulkan/wsi/wayland: create swapchain using vk_zalloc()

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 20 19:10:54 UTC 2021


Module: Mesa
Branch: main
Commit: 4cd187e71e784f3d08dedd82f658c5897d45b53a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4cd187e71e784f3d08dedd82f658c5897d45b53a

Author: Leandro Ribeiro <leandro.ribeiro at collabora.com>
Date:   Tue Jul  6 16:00:12 2021 -0300

vulkan/wsi/wayland: create swapchain using vk_zalloc()

In wsi_wl_surface_create_swapchain() we have a piece of code to init
some members of the chain to 0, in order to allow us to call
wsi_wl_swapchain_destroy() for cleanup.

Instead, we can use vk_zalloc() to allocate the chain, as it initializes
all members of the struct to zero. This help us to avoid problems when
people add new members to the struct and forget to initialize them.
Also, it makes the code look better.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro at collabora.com>
Reviewed-by: Simon Ser <contact at emersion.fr>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12451>

---

 src/vulkan/wsi/wsi_common_wayland.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index 4ad33e46941..97dd7eec4bf 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -1132,8 +1132,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
    int num_images = pCreateInfo->minImageCount;
 
    size_t size = sizeof(*chain) + num_images * sizeof(chain->images[0]);
-   chain = vk_alloc(pAllocator, size, 8,
-                      VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   chain = vk_zalloc(pAllocator, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
    if (chain == NULL)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
@@ -1144,16 +1143,6 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
       return result;
    }
 
-   /* Mark a bunch of stuff as NULL.  This way we can just call
-    * destroy_swapchain for cleanup.
-    */
-   for (uint32_t i = 0; i < num_images; i++) {
-      chain->images[i].buffer = NULL;
-      chain->images[i].data_ptr = NULL;
-   }
-   chain->surface = NULL;
-   chain->frame = NULL;
-
    bool alpha = pCreateInfo->compositeAlpha ==
                       VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
 



More information about the mesa-commit mailing list