xref: /aosp_15_r20/external/mesa3d/src/vulkan/util/vk_alloc.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker  * Copyright © 2015 Intel Corporation
3*61046927SAndroid Build Coastguard Worker  *
4*61046927SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker  *
11*61046927SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker  * Software.
14*61046927SAndroid Build Coastguard Worker  *
15*61046927SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*61046927SAndroid Build Coastguard Worker  * IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker  */
23*61046927SAndroid Build Coastguard Worker #ifndef VK_ALLOC_H
24*61046927SAndroid Build Coastguard Worker #define VK_ALLOC_H
25*61046927SAndroid Build Coastguard Worker 
26*61046927SAndroid Build Coastguard Worker /* common allocation inlines for vulkan drivers */
27*61046927SAndroid Build Coastguard Worker 
28*61046927SAndroid Build Coastguard Worker #include <stdio.h>
29*61046927SAndroid Build Coastguard Worker #include <string.h>
30*61046927SAndroid Build Coastguard Worker #include <vulkan/vulkan_core.h>
31*61046927SAndroid Build Coastguard Worker 
32*61046927SAndroid Build Coastguard Worker #include "util/u_math.h"
33*61046927SAndroid Build Coastguard Worker #include "util/macros.h"
34*61046927SAndroid Build Coastguard Worker #include "util/u_printf.h"
35*61046927SAndroid Build Coastguard Worker 
36*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
37*61046927SAndroid Build Coastguard Worker extern "C" {
38*61046927SAndroid Build Coastguard Worker #endif
39*61046927SAndroid Build Coastguard Worker 
40*61046927SAndroid Build Coastguard Worker const VkAllocationCallbacks *
41*61046927SAndroid Build Coastguard Worker vk_default_allocator(void);
42*61046927SAndroid Build Coastguard Worker 
43*61046927SAndroid Build Coastguard Worker static inline void *
vk_alloc(const VkAllocationCallbacks * alloc,size_t size,size_t align,VkSystemAllocationScope scope)44*61046927SAndroid Build Coastguard Worker vk_alloc(const VkAllocationCallbacks *alloc,
45*61046927SAndroid Build Coastguard Worker          size_t size, size_t align,
46*61046927SAndroid Build Coastguard Worker          VkSystemAllocationScope scope)
47*61046927SAndroid Build Coastguard Worker {
48*61046927SAndroid Build Coastguard Worker    return alloc->pfnAllocation(alloc->pUserData, size, align, scope);
49*61046927SAndroid Build Coastguard Worker }
50*61046927SAndroid Build Coastguard Worker 
51*61046927SAndroid Build Coastguard Worker static inline void *
vk_zalloc(const VkAllocationCallbacks * alloc,size_t size,size_t align,VkSystemAllocationScope scope)52*61046927SAndroid Build Coastguard Worker vk_zalloc(const VkAllocationCallbacks *alloc,
53*61046927SAndroid Build Coastguard Worker           size_t size, size_t align,
54*61046927SAndroid Build Coastguard Worker           VkSystemAllocationScope scope)
55*61046927SAndroid Build Coastguard Worker {
56*61046927SAndroid Build Coastguard Worker    void *mem = vk_alloc(alloc, size, align, scope);
57*61046927SAndroid Build Coastguard Worker    if (mem == NULL)
58*61046927SAndroid Build Coastguard Worker       return NULL;
59*61046927SAndroid Build Coastguard Worker 
60*61046927SAndroid Build Coastguard Worker    memset(mem, 0, size);
61*61046927SAndroid Build Coastguard Worker 
62*61046927SAndroid Build Coastguard Worker    return mem;
63*61046927SAndroid Build Coastguard Worker }
64*61046927SAndroid Build Coastguard Worker 
65*61046927SAndroid Build Coastguard Worker static inline void *
vk_realloc(const VkAllocationCallbacks * alloc,void * ptr,size_t size,size_t align,VkSystemAllocationScope scope)66*61046927SAndroid Build Coastguard Worker vk_realloc(const VkAllocationCallbacks *alloc,
67*61046927SAndroid Build Coastguard Worker            void *ptr, size_t size, size_t align,
68*61046927SAndroid Build Coastguard Worker            VkSystemAllocationScope scope)
69*61046927SAndroid Build Coastguard Worker {
70*61046927SAndroid Build Coastguard Worker    return alloc->pfnReallocation(alloc->pUserData, ptr, size, align, scope);
71*61046927SAndroid Build Coastguard Worker }
72*61046927SAndroid Build Coastguard Worker 
73*61046927SAndroid Build Coastguard Worker static inline void
vk_free(const VkAllocationCallbacks * alloc,void * data)74*61046927SAndroid Build Coastguard Worker vk_free(const VkAllocationCallbacks *alloc, void *data)
75*61046927SAndroid Build Coastguard Worker {
76*61046927SAndroid Build Coastguard Worker    if (data == NULL)
77*61046927SAndroid Build Coastguard Worker       return;
78*61046927SAndroid Build Coastguard Worker 
79*61046927SAndroid Build Coastguard Worker    alloc->pfnFree(alloc->pUserData, data);
80*61046927SAndroid Build Coastguard Worker }
81*61046927SAndroid Build Coastguard Worker 
82*61046927SAndroid Build Coastguard Worker static inline char *
vk_strdup(const VkAllocationCallbacks * alloc,const char * s,VkSystemAllocationScope scope)83*61046927SAndroid Build Coastguard Worker vk_strdup(const VkAllocationCallbacks *alloc, const char *s,
84*61046927SAndroid Build Coastguard Worker           VkSystemAllocationScope scope)
85*61046927SAndroid Build Coastguard Worker {
86*61046927SAndroid Build Coastguard Worker    if (s == NULL)
87*61046927SAndroid Build Coastguard Worker       return NULL;
88*61046927SAndroid Build Coastguard Worker 
89*61046927SAndroid Build Coastguard Worker    size_t size = strlen(s) + 1;
90*61046927SAndroid Build Coastguard Worker    char *copy = (char *)vk_alloc(alloc, size, 1, scope);
91*61046927SAndroid Build Coastguard Worker    if (copy == NULL)
92*61046927SAndroid Build Coastguard Worker       return NULL;
93*61046927SAndroid Build Coastguard Worker 
94*61046927SAndroid Build Coastguard Worker    memcpy(copy, s, size);
95*61046927SAndroid Build Coastguard Worker 
96*61046927SAndroid Build Coastguard Worker    return copy;
97*61046927SAndroid Build Coastguard Worker }
98*61046927SAndroid Build Coastguard Worker 
99*61046927SAndroid Build Coastguard Worker static inline char *
vk_vasprintf(const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope,const char * fmt,va_list args)100*61046927SAndroid Build Coastguard Worker vk_vasprintf(const VkAllocationCallbacks *alloc,
101*61046927SAndroid Build Coastguard Worker              VkSystemAllocationScope scope,
102*61046927SAndroid Build Coastguard Worker              const char *fmt, va_list args)
103*61046927SAndroid Build Coastguard Worker {
104*61046927SAndroid Build Coastguard Worker    size_t size = u_printf_length(fmt, args) + 1;
105*61046927SAndroid Build Coastguard Worker    char *ptr = (char *)vk_alloc(alloc, size, 1, scope);
106*61046927SAndroid Build Coastguard Worker    if (ptr != NULL)
107*61046927SAndroid Build Coastguard Worker       vsnprintf(ptr, size, fmt, args);
108*61046927SAndroid Build Coastguard Worker 
109*61046927SAndroid Build Coastguard Worker    return ptr;
110*61046927SAndroid Build Coastguard Worker }
111*61046927SAndroid Build Coastguard Worker 
112*61046927SAndroid Build Coastguard Worker PRINTFLIKE(3, 4) static inline char *
vk_asprintf(const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope,const char * fmt,...)113*61046927SAndroid Build Coastguard Worker vk_asprintf(const VkAllocationCallbacks *alloc,
114*61046927SAndroid Build Coastguard Worker             VkSystemAllocationScope scope,
115*61046927SAndroid Build Coastguard Worker             const char *fmt, ...)
116*61046927SAndroid Build Coastguard Worker {
117*61046927SAndroid Build Coastguard Worker    va_list args;
118*61046927SAndroid Build Coastguard Worker    va_start(args, fmt);
119*61046927SAndroid Build Coastguard Worker    char *ptr = vk_vasprintf(alloc, scope, fmt, args);
120*61046927SAndroid Build Coastguard Worker    va_end(args);
121*61046927SAndroid Build Coastguard Worker 
122*61046927SAndroid Build Coastguard Worker    return ptr;
123*61046927SAndroid Build Coastguard Worker }
124*61046927SAndroid Build Coastguard Worker 
125*61046927SAndroid Build Coastguard Worker static inline void *
vk_alloc2(const VkAllocationCallbacks * parent_alloc,const VkAllocationCallbacks * alloc,size_t size,size_t align,VkSystemAllocationScope scope)126*61046927SAndroid Build Coastguard Worker vk_alloc2(const VkAllocationCallbacks *parent_alloc,
127*61046927SAndroid Build Coastguard Worker           const VkAllocationCallbacks *alloc,
128*61046927SAndroid Build Coastguard Worker           size_t size, size_t align,
129*61046927SAndroid Build Coastguard Worker           VkSystemAllocationScope scope)
130*61046927SAndroid Build Coastguard Worker {
131*61046927SAndroid Build Coastguard Worker    if (alloc)
132*61046927SAndroid Build Coastguard Worker       return vk_alloc(alloc, size, align, scope);
133*61046927SAndroid Build Coastguard Worker    else
134*61046927SAndroid Build Coastguard Worker       return vk_alloc(parent_alloc, size, align, scope);
135*61046927SAndroid Build Coastguard Worker }
136*61046927SAndroid Build Coastguard Worker 
137*61046927SAndroid Build Coastguard Worker static inline void *
vk_zalloc2(const VkAllocationCallbacks * parent_alloc,const VkAllocationCallbacks * alloc,size_t size,size_t align,VkSystemAllocationScope scope)138*61046927SAndroid Build Coastguard Worker vk_zalloc2(const VkAllocationCallbacks *parent_alloc,
139*61046927SAndroid Build Coastguard Worker            const VkAllocationCallbacks *alloc,
140*61046927SAndroid Build Coastguard Worker            size_t size, size_t align,
141*61046927SAndroid Build Coastguard Worker            VkSystemAllocationScope scope)
142*61046927SAndroid Build Coastguard Worker {
143*61046927SAndroid Build Coastguard Worker    void *mem = vk_alloc2(parent_alloc, alloc, size, align, scope);
144*61046927SAndroid Build Coastguard Worker    if (mem == NULL)
145*61046927SAndroid Build Coastguard Worker       return NULL;
146*61046927SAndroid Build Coastguard Worker 
147*61046927SAndroid Build Coastguard Worker    memset(mem, 0, size);
148*61046927SAndroid Build Coastguard Worker 
149*61046927SAndroid Build Coastguard Worker    return mem;
150*61046927SAndroid Build Coastguard Worker }
151*61046927SAndroid Build Coastguard Worker 
152*61046927SAndroid Build Coastguard Worker static inline void
vk_free2(const VkAllocationCallbacks * parent_alloc,const VkAllocationCallbacks * alloc,void * data)153*61046927SAndroid Build Coastguard Worker vk_free2(const VkAllocationCallbacks *parent_alloc,
154*61046927SAndroid Build Coastguard Worker          const VkAllocationCallbacks *alloc,
155*61046927SAndroid Build Coastguard Worker          void *data)
156*61046927SAndroid Build Coastguard Worker {
157*61046927SAndroid Build Coastguard Worker    if (alloc)
158*61046927SAndroid Build Coastguard Worker       vk_free(alloc, data);
159*61046927SAndroid Build Coastguard Worker    else
160*61046927SAndroid Build Coastguard Worker       vk_free(parent_alloc, data);
161*61046927SAndroid Build Coastguard Worker }
162*61046927SAndroid Build Coastguard Worker 
163*61046927SAndroid Build Coastguard Worker /* A multi-pointer allocator
164*61046927SAndroid Build Coastguard Worker  *
165*61046927SAndroid Build Coastguard Worker  * When copying data structures from the user (such as a render pass), it's
166*61046927SAndroid Build Coastguard Worker  * common to need to allocate data for a bunch of different things.  Instead
167*61046927SAndroid Build Coastguard Worker  * of doing several allocations and having to handle all of the error checking
168*61046927SAndroid Build Coastguard Worker  * that entails, it can be easier to do a single allocation.  This struct
169*61046927SAndroid Build Coastguard Worker  * helps facilitate that.  The intended usage looks like this:
170*61046927SAndroid Build Coastguard Worker  *
171*61046927SAndroid Build Coastguard Worker  *    VK_MULTIALLOC(ma)
172*61046927SAndroid Build Coastguard Worker  *    vk_multialloc_add(&ma, &main_ptr, 1);
173*61046927SAndroid Build Coastguard Worker  *    vk_multialloc_add(&ma, &substruct1, substruct1Count);
174*61046927SAndroid Build Coastguard Worker  *    vk_multialloc_add(&ma, &substruct2, substruct2Count);
175*61046927SAndroid Build Coastguard Worker  *
176*61046927SAndroid Build Coastguard Worker  *    if (!vk_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
177*61046927SAndroid Build Coastguard Worker  *       return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
178*61046927SAndroid Build Coastguard Worker  */
179*61046927SAndroid Build Coastguard Worker struct vk_multialloc {
180*61046927SAndroid Build Coastguard Worker     size_t size;
181*61046927SAndroid Build Coastguard Worker     size_t align;
182*61046927SAndroid Build Coastguard Worker 
183*61046927SAndroid Build Coastguard Worker     uint32_t ptr_count;
184*61046927SAndroid Build Coastguard Worker     void **ptrs[16];
185*61046927SAndroid Build Coastguard Worker };
186*61046927SAndroid Build Coastguard Worker 
187*61046927SAndroid Build Coastguard Worker #define VK_MULTIALLOC(_name) \
188*61046927SAndroid Build Coastguard Worker    struct vk_multialloc _name = { .align = 1 }
189*61046927SAndroid Build Coastguard Worker 
190*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void
vk_multialloc_add_size_align(struct vk_multialloc * ma,void ** ptr,size_t size,size_t align)191*61046927SAndroid Build Coastguard Worker vk_multialloc_add_size_align(struct vk_multialloc *ma,
192*61046927SAndroid Build Coastguard Worker                              void **ptr, size_t size, size_t align)
193*61046927SAndroid Build Coastguard Worker {
194*61046927SAndroid Build Coastguard Worker    assert(util_is_power_of_two_nonzero_uintptr(align));
195*61046927SAndroid Build Coastguard Worker    if (size == 0) {
196*61046927SAndroid Build Coastguard Worker       *ptr = NULL;
197*61046927SAndroid Build Coastguard Worker       return;
198*61046927SAndroid Build Coastguard Worker    }
199*61046927SAndroid Build Coastguard Worker 
200*61046927SAndroid Build Coastguard Worker    size_t offset = ALIGN_POT(ma->size, align);
201*61046927SAndroid Build Coastguard Worker    ma->size = offset + size;
202*61046927SAndroid Build Coastguard Worker    ma->align = MAX2(ma->align, align);
203*61046927SAndroid Build Coastguard Worker 
204*61046927SAndroid Build Coastguard Worker    /* Store the offset in the pointer. */
205*61046927SAndroid Build Coastguard Worker    *ptr = (void *)(uintptr_t)offset;
206*61046927SAndroid Build Coastguard Worker 
207*61046927SAndroid Build Coastguard Worker    assert(ma->ptr_count < ARRAY_SIZE(ma->ptrs));
208*61046927SAndroid Build Coastguard Worker    ma->ptrs[ma->ptr_count++] = ptr;
209*61046927SAndroid Build Coastguard Worker }
210*61046927SAndroid Build Coastguard Worker 
211*61046927SAndroid Build Coastguard Worker #define vk_multialloc_add_size(_ma, _ptr, _type, _size) \
212*61046927SAndroid Build Coastguard Worker    do { \
213*61046927SAndroid Build Coastguard Worker       _type **_tmp = (_ptr); \
214*61046927SAndroid Build Coastguard Worker       (void)_tmp; \
215*61046927SAndroid Build Coastguard Worker       vk_multialloc_add_size_align((_ma), (void **)(_ptr), \
216*61046927SAndroid Build Coastguard Worker                                    (_size), alignof(_type)); \
217*61046927SAndroid Build Coastguard Worker    } while(0)
218*61046927SAndroid Build Coastguard Worker 
219*61046927SAndroid Build Coastguard Worker #define vk_multialloc_add(_ma, _ptr, _type, _count) \
220*61046927SAndroid Build Coastguard Worker    vk_multialloc_add_size(_ma, _ptr, _type, (_count) * sizeof(**(_ptr)));
221*61046927SAndroid Build Coastguard Worker 
222*61046927SAndroid Build Coastguard Worker #define VK_MULTIALLOC_DECL_SIZE(_ma, _type, _name, _size) \
223*61046927SAndroid Build Coastguard Worker    _type *_name; \
224*61046927SAndroid Build Coastguard Worker    vk_multialloc_add_size(_ma, &_name, _type, _size);
225*61046927SAndroid Build Coastguard Worker 
226*61046927SAndroid Build Coastguard Worker #define VK_MULTIALLOC_DECL(_ma, _type, _name, _count) \
227*61046927SAndroid Build Coastguard Worker    VK_MULTIALLOC_DECL_SIZE(_ma, _type, _name, (_count) * sizeof(_type));
228*61046927SAndroid Build Coastguard Worker 
229*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void *
vk_multialloc_alloc(struct vk_multialloc * ma,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope)230*61046927SAndroid Build Coastguard Worker vk_multialloc_alloc(struct vk_multialloc *ma,
231*61046927SAndroid Build Coastguard Worker                     const VkAllocationCallbacks *alloc,
232*61046927SAndroid Build Coastguard Worker                     VkSystemAllocationScope scope)
233*61046927SAndroid Build Coastguard Worker {
234*61046927SAndroid Build Coastguard Worker    void *ptr = vk_alloc(alloc, ma->size, ma->align, scope);
235*61046927SAndroid Build Coastguard Worker    if (!ptr)
236*61046927SAndroid Build Coastguard Worker       return NULL;
237*61046927SAndroid Build Coastguard Worker 
238*61046927SAndroid Build Coastguard Worker    /* Fill out each of the pointers with their final value.
239*61046927SAndroid Build Coastguard Worker     *
240*61046927SAndroid Build Coastguard Worker     *   for (uint32_t i = 0; i < ma->ptr_count; i++)
241*61046927SAndroid Build Coastguard Worker     *      *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
242*61046927SAndroid Build Coastguard Worker     *
243*61046927SAndroid Build Coastguard Worker     * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
244*61046927SAndroid Build Coastguard Worker     * constant, GCC is incapable of figuring this out and unrolling the loop
245*61046927SAndroid Build Coastguard Worker     * so we have to give it a little help.
246*61046927SAndroid Build Coastguard Worker     */
247*61046927SAndroid Build Coastguard Worker    STATIC_ASSERT(ARRAY_SIZE(ma->ptrs) == 16);
248*61046927SAndroid Build Coastguard Worker #define _VK_MULTIALLOC_UPDATE_POINTER(_i) \
249*61046927SAndroid Build Coastguard Worker    if ((_i) < ma->ptr_count) \
250*61046927SAndroid Build Coastguard Worker       *ma->ptrs[_i] = (char *)ptr + (uintptr_t)*ma->ptrs[_i]
251*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(0);
252*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(1);
253*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(2);
254*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(3);
255*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(4);
256*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(5);
257*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(6);
258*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(7);
259*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(8);
260*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(9);
261*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(10);
262*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(11);
263*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(12);
264*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(13);
265*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(14);
266*61046927SAndroid Build Coastguard Worker    _VK_MULTIALLOC_UPDATE_POINTER(15);
267*61046927SAndroid Build Coastguard Worker #undef _VK_MULTIALLOC_UPDATE_POINTER
268*61046927SAndroid Build Coastguard Worker 
269*61046927SAndroid Build Coastguard Worker    return ptr;
270*61046927SAndroid Build Coastguard Worker }
271*61046927SAndroid Build Coastguard Worker 
272*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void *
vk_multialloc_alloc2(struct vk_multialloc * ma,const VkAllocationCallbacks * parent_alloc,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope)273*61046927SAndroid Build Coastguard Worker vk_multialloc_alloc2(struct vk_multialloc *ma,
274*61046927SAndroid Build Coastguard Worker                      const VkAllocationCallbacks *parent_alloc,
275*61046927SAndroid Build Coastguard Worker                      const VkAllocationCallbacks *alloc,
276*61046927SAndroid Build Coastguard Worker                      VkSystemAllocationScope scope)
277*61046927SAndroid Build Coastguard Worker {
278*61046927SAndroid Build Coastguard Worker    return vk_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
279*61046927SAndroid Build Coastguard Worker }
280*61046927SAndroid Build Coastguard Worker 
281*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void *
vk_multialloc_zalloc(struct vk_multialloc * ma,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope)282*61046927SAndroid Build Coastguard Worker vk_multialloc_zalloc(struct vk_multialloc *ma,
283*61046927SAndroid Build Coastguard Worker                      const VkAllocationCallbacks *alloc,
284*61046927SAndroid Build Coastguard Worker                      VkSystemAllocationScope scope)
285*61046927SAndroid Build Coastguard Worker {
286*61046927SAndroid Build Coastguard Worker    void *ptr = vk_multialloc_alloc(ma, alloc, scope);
287*61046927SAndroid Build Coastguard Worker 
288*61046927SAndroid Build Coastguard Worker    if (ptr == NULL)
289*61046927SAndroid Build Coastguard Worker       return NULL;
290*61046927SAndroid Build Coastguard Worker 
291*61046927SAndroid Build Coastguard Worker    memset(ptr, 0, ma->size);
292*61046927SAndroid Build Coastguard Worker 
293*61046927SAndroid Build Coastguard Worker    return ptr;
294*61046927SAndroid Build Coastguard Worker }
295*61046927SAndroid Build Coastguard Worker 
296*61046927SAndroid Build Coastguard Worker static ALWAYS_INLINE void *
vk_multialloc_zalloc2(struct vk_multialloc * ma,const VkAllocationCallbacks * parent_alloc,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope)297*61046927SAndroid Build Coastguard Worker vk_multialloc_zalloc2(struct vk_multialloc *ma,
298*61046927SAndroid Build Coastguard Worker                       const VkAllocationCallbacks *parent_alloc,
299*61046927SAndroid Build Coastguard Worker                       const VkAllocationCallbacks *alloc,
300*61046927SAndroid Build Coastguard Worker                       VkSystemAllocationScope scope)
301*61046927SAndroid Build Coastguard Worker {
302*61046927SAndroid Build Coastguard Worker    return vk_multialloc_zalloc(ma, alloc ? alloc : parent_alloc, scope);
303*61046927SAndroid Build Coastguard Worker }
304*61046927SAndroid Build Coastguard Worker 
305*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
306*61046927SAndroid Build Coastguard Worker }
307*61046927SAndroid Build Coastguard Worker #endif
308*61046927SAndroid Build Coastguard Worker 
309*61046927SAndroid Build Coastguard Worker #endif
310