• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_DESCRIPTOR_SET_H
12 #define VN_DESCRIPTOR_SET_H
13 
14 #include "vn_common.h"
15 
16 enum vn_descriptor_type {
17    VN_DESCRIPTOR_TYPE_SAMPLER,
18    VN_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
19    VN_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
20    VN_DESCRIPTOR_TYPE_STORAGE_IMAGE,
21    VN_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
22    VN_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
23    VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
24    VN_DESCRIPTOR_TYPE_STORAGE_BUFFER,
25    VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
26    VN_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
27    VN_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
28    VN_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK,
29    VN_DESCRIPTOR_TYPE_MUTABLE_EXT,
30 
31    /* add new enum types before this line */
32    VN_NUM_DESCRIPTOR_TYPES,
33 };
34 
35 /* TODO refactor struct to track enum vn_descriptor_type type.
36  * On VkDescriptorSetLayout creation. When we check against
37  * VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK, it will be against
38  * VN_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK instead
39  */
40 struct vn_descriptor_set_layout_binding {
41    VkDescriptorType type;
42    uint32_t count;
43    bool has_immutable_samplers;
44    BITSET_DECLARE(mutable_descriptor_types, VN_NUM_DESCRIPTOR_TYPES);
45 };
46 
47 struct vn_descriptor_set_layout {
48    struct vn_object_base base;
49 
50    struct vn_refcount refcount;
51 
52    uint32_t last_binding;
53    bool has_variable_descriptor_count;
54    bool is_push_descriptor;
55 
56    /* bindings must be the last field in the layout */
57    struct vn_descriptor_set_layout_binding bindings[];
58 };
59 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set_layout,
60                                base.base,
61                                VkDescriptorSetLayout,
62                                VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
63 
64 struct vn_descriptor_pool_state {
65    uint32_t set_count;
66    uint32_t iub_binding_count;
67    uint32_t descriptor_counts[VN_NUM_DESCRIPTOR_TYPES];
68 };
69 
70 struct vn_descriptor_pool_state_mutable {
71    uint32_t max;
72    uint32_t used;
73    BITSET_DECLARE(types, VN_NUM_DESCRIPTOR_TYPES);
74 };
75 
76 struct vn_descriptor_pool {
77    struct vn_object_base base;
78 
79    VkAllocationCallbacks allocator;
80    bool async_set_allocation;
81    struct vn_descriptor_pool_state max;
82    struct vn_descriptor_pool_state used;
83 
84    struct list_head descriptor_sets;
85 
86    uint32_t mutable_states_count;
87    struct vn_descriptor_pool_state_mutable *mutable_states;
88 };
89 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_pool,
90                                base.base,
91                                VkDescriptorPool,
92                                VK_OBJECT_TYPE_DESCRIPTOR_POOL)
93 
94 struct vn_update_descriptor_sets {
95    uint32_t write_count;
96    VkWriteDescriptorSet *writes;
97    VkDescriptorImageInfo *images;
98    VkDescriptorBufferInfo *buffers;
99    VkBufferView *views;
100    VkWriteDescriptorSetInlineUniformBlock *iubs;
101 };
102 
103 struct vn_descriptor_set {
104    struct vn_object_base base;
105 
106    struct vn_descriptor_set_layout *layout;
107    uint32_t last_binding_descriptor_count;
108 
109    struct list_head head;
110 };
111 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set,
112                                base.base,
113                                VkDescriptorSet,
114                                VK_OBJECT_TYPE_DESCRIPTOR_SET)
115 
116 struct vn_descriptor_update_template_entry {
117    size_t offset;
118    size_t stride;
119 };
120 
121 struct vn_descriptor_update_template {
122    struct vn_object_base base;
123 
124    bool is_push_descriptor;
125    VkPipelineBindPoint pipeline_bind_point;
126    struct vn_pipeline_layout *pipeline_layout;
127 
128    mtx_t mutex;
129    struct vn_update_descriptor_sets *update;
130 
131    struct vn_descriptor_update_template_entry entries[];
132 };
133 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template,
134                                base.base,
135                                VkDescriptorUpdateTemplate,
136                                VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
137 
138 bool
139 vn_should_sanitize_descriptor_set_writes(
140    uint32_t write_count,
141    const VkWriteDescriptorSet *writes,
142    VkPipelineLayout pipeline_layout_handle);
143 
144 struct vn_update_descriptor_sets *
145 vn_update_descriptor_sets_parse_writes(
146    uint32_t write_count,
147    const VkWriteDescriptorSet *writes,
148    const VkAllocationCallbacks *alloc,
149    VkPipelineLayout pipeline_layout_handle);
150 
151 struct vn_update_descriptor_sets *
152 vn_update_descriptor_set_with_template_locked(
153    struct vn_descriptor_update_template *templ,
154    struct vn_descriptor_set *set,
155    const void *data);
156 
157 void
158 vn_descriptor_set_layout_destroy(struct vn_device *dev,
159                                  struct vn_descriptor_set_layout *layout);
160 
161 static inline struct vn_descriptor_set_layout *
vn_descriptor_set_layout_ref(struct vn_device * dev,struct vn_descriptor_set_layout * layout)162 vn_descriptor_set_layout_ref(struct vn_device *dev,
163                              struct vn_descriptor_set_layout *layout)
164 {
165    vn_refcount_inc(&layout->refcount);
166    return layout;
167 }
168 
169 static inline void
vn_descriptor_set_layout_unref(struct vn_device * dev,struct vn_descriptor_set_layout * layout)170 vn_descriptor_set_layout_unref(struct vn_device *dev,
171                                struct vn_descriptor_set_layout *layout)
172 {
173    if (vn_refcount_dec(&layout->refcount))
174       vn_descriptor_set_layout_destroy(dev, layout);
175 }
176 
177 #endif /* VN_DESCRIPTOR_SET_H */
178