• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2022 Collabora Ltd
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "vk_descriptor_set_layout.h"
25 
26 #include "vk_alloc.h"
27 #include "vk_common_entrypoints.h"
28 #include "vk_device.h"
29 
30 static void
vk_descriptor_set_layout_init(struct vk_device * device,struct vk_descriptor_set_layout * layout)31 vk_descriptor_set_layout_init(struct vk_device *device,
32                               struct vk_descriptor_set_layout *layout)
33 {
34    vk_object_base_init(device, &layout->base,
35                        VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT);
36 
37    layout->ref_cnt = 1;
38 }
39 
40 void *
vk_descriptor_set_layout_zalloc(struct vk_device * device,size_t size)41 vk_descriptor_set_layout_zalloc(struct vk_device *device, size_t size)
42 {
43    /* Because we're reference counting and lifetimes may not be what the
44     * client expects, these have to be allocated off the device and not as
45     * their own object.
46     */
47    struct vk_descriptor_set_layout *layout =
48       vk_zalloc(&device->alloc, size, 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
49    if (!layout)
50       return NULL;
51 
52    vk_descriptor_set_layout_init(device, layout);
53 
54    return layout;
55 }
56 
57 void *
vk_descriptor_set_layout_multizalloc(struct vk_device * device,struct vk_multialloc * ma)58 vk_descriptor_set_layout_multizalloc(struct vk_device *device,
59                                      struct vk_multialloc *ma)
60 {
61    /* Because we're reference counting and lifetimes may not be what the
62     * client expects, these have to be allocated off the device and not as
63     * their own object.
64     */
65    struct vk_descriptor_set_layout *layout =
66       vk_multialloc_zalloc(ma, &device->alloc,
67                            VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
68    if (!layout)
69       return NULL;
70 
71    vk_descriptor_set_layout_init(device, layout);
72 
73    return layout;
74 }
75 
76 VKAPI_ATTR void VKAPI_CALL
vk_common_DestroyDescriptorSetLayout(VkDevice _device,VkDescriptorSetLayout descriptorSetLayout,UNUSED const VkAllocationCallbacks * pAllocator)77 vk_common_DestroyDescriptorSetLayout(VkDevice _device,
78                                      VkDescriptorSetLayout descriptorSetLayout,
79                                      UNUSED const VkAllocationCallbacks *pAllocator)
80 {
81    VK_FROM_HANDLE(vk_device, device, _device);
82    VK_FROM_HANDLE(vk_descriptor_set_layout, layout, descriptorSetLayout);
83 
84    if (layout == NULL)
85       return;
86 
87    vk_descriptor_set_layout_unref(device, layout);
88 }
89