xref: /aosp_15_r20/external/mesa3d/src/vulkan/runtime/vk_descriptor_update_template.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2017 Intel Corporation
3  * Copyright © 2022 Collabora, Ltd
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 #ifndef VK_DESCRIPTOR_UPDATE_TEMPLATE_H
25 #define VK_DESCRIPTOR_UPDATE_TEMPLATE_H
26 
27 #include "vk_object.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 struct vk_descriptor_template_entry {
34    /** VkDescriptorUpdateTemplateEntry::descriptorType */
35    VkDescriptorType type;
36 
37    /** VkDescriptorUpdateTemplateEntry::dstBinding */
38    uint32_t binding;
39 
40    /** VkDescriptorUpdateTemplateEntry::dstArrayElement */
41    uint32_t array_element;
42 
43    /** VkDescriptorUpdateTemplateEntry::descriptorCount */
44    uint32_t array_count;
45 
46    /** VkDescriptorUpdateTemplateEntry::offset
47     *
48     * Offset into the user provided data */
49    size_t offset;
50 
51    /** VkDescriptorUpdateTemplateEntry::stride
52     *
53     * Stride between elements into the user provided data
54     */
55    size_t stride;
56 };
57 
58 struct vk_descriptor_update_template {
59    struct vk_object_base base;
60 
61    /** VkDescriptorUpdateTemplateCreateInfo::templateType */
62    VkDescriptorUpdateTemplateType type;
63 
64    /** VkDescriptorUpdateTemplateCreateInfo::pipelineBindPoint */
65    VkPipelineBindPoint bind_point;
66 
67    /** VkDescriptorUpdateTemplateCreateInfo::set
68     *
69     * The descriptor set this template corresponds to. This value is only
70     * valid if the template was created with the templateType
71     * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET.
72     */
73    uint8_t set;
74 
75    /** VkDescriptorUpdateTemplateCreateInfo::descriptorUpdateEntryCount */
76    uint32_t entry_count;
77 
78    /** Reference count.
79     *
80     * It is legal to enqueue a push template update to a secondary command
81     * buffer and destroy the template before executing the secondary. As
82     * capture-replay based secondaries reference the template, we need to
83     * reference count to extend the lifetime appropriately.
84     */
85    uint32_t ref_cnt;
86 
87    /** Entries of the template */
88    struct vk_descriptor_template_entry entries[0];
89 };
90 
91 static inline struct vk_descriptor_update_template *
vk_descriptor_update_template_ref(struct vk_descriptor_update_template * templ)92 vk_descriptor_update_template_ref(struct vk_descriptor_update_template *templ)
93 {
94    assert(templ && templ->ref_cnt >= 1);
95    p_atomic_inc(&templ->ref_cnt);
96    return templ;
97 }
98 
99 static inline void
vk_descriptor_update_template_unref(struct vk_device * device,struct vk_descriptor_update_template * templ)100 vk_descriptor_update_template_unref(struct vk_device *device,
101                                     struct vk_descriptor_update_template *templ)
102 {
103    assert(templ && templ->ref_cnt >= 1);
104    if (p_atomic_dec_zero(&templ->ref_cnt))
105       vk_object_free(device, NULL, templ);
106 }
107 
108 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_descriptor_update_template, base,
109                                VkDescriptorUpdateTemplate,
110                                VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* VK_DESCRIPTOR_UPDATE_TEMPLATE_H */
117