1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2019 Google LLC
3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * based in part on anv and radv which are:
6bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation
7bf215546Sopenharmony_ci * Copyright © 2016 Red Hat.
8bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen
9bf215546Sopenharmony_ci */
10bf215546Sopenharmony_ci
11bf215546Sopenharmony_ci#ifndef VN_DESCRIPTOR_SET_H
12bf215546Sopenharmony_ci#define VN_DESCRIPTOR_SET_H
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci#include "vn_common.h"
15bf215546Sopenharmony_ci
16bf215546Sopenharmony_cienum vn_descriptor_type {
17bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_SAMPLER,
18bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
19bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
20bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_STORAGE_IMAGE,
21bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
22bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
23bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
24bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_STORAGE_BUFFER,
25bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
26bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
27bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
28bf215546Sopenharmony_ci   VN_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK,
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci   /* add new enum types before this line */
31bf215546Sopenharmony_ci   VN_NUM_DESCRIPTOR_TYPES,
32bf215546Sopenharmony_ci};
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci/* TODO refactor struct to track enum vn_descriptor_type type.
35bf215546Sopenharmony_ci * On VkDescriptorSetLayout creation. When we check against
36bf215546Sopenharmony_ci * VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK, it will be against
37bf215546Sopenharmony_ci * VN_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK instead
38bf215546Sopenharmony_ci */
39bf215546Sopenharmony_cistruct vn_descriptor_set_layout_binding {
40bf215546Sopenharmony_ci   VkDescriptorType type;
41bf215546Sopenharmony_ci   uint32_t count;
42bf215546Sopenharmony_ci   bool has_immutable_samplers;
43bf215546Sopenharmony_ci};
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistruct vn_descriptor_set_layout {
46bf215546Sopenharmony_ci   struct vn_object_base base;
47bf215546Sopenharmony_ci
48bf215546Sopenharmony_ci   struct vn_refcount refcount;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci   uint32_t last_binding;
51bf215546Sopenharmony_ci   bool has_variable_descriptor_count;
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   /* bindings must be the last field in the layout */
54bf215546Sopenharmony_ci   struct vn_descriptor_set_layout_binding bindings[];
55bf215546Sopenharmony_ci};
56bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set_layout,
57bf215546Sopenharmony_ci                               base.base,
58bf215546Sopenharmony_ci                               VkDescriptorSetLayout,
59bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistruct vn_descriptor_pool_state {
62bf215546Sopenharmony_ci   uint32_t set_count;
63bf215546Sopenharmony_ci   uint32_t iub_binding_count;
64bf215546Sopenharmony_ci   uint32_t descriptor_counts[VN_NUM_DESCRIPTOR_TYPES];
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct vn_descriptor_pool {
68bf215546Sopenharmony_ci   struct vn_object_base base;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   VkAllocationCallbacks allocator;
71bf215546Sopenharmony_ci   bool async_set_allocation;
72bf215546Sopenharmony_ci   struct vn_descriptor_pool_state max;
73bf215546Sopenharmony_ci   struct vn_descriptor_pool_state used;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   struct list_head descriptor_sets;
76bf215546Sopenharmony_ci};
77bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_pool,
78bf215546Sopenharmony_ci                               base.base,
79bf215546Sopenharmony_ci                               VkDescriptorPool,
80bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_POOL)
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_cistruct vn_update_descriptor_sets {
83bf215546Sopenharmony_ci   uint32_t write_count;
84bf215546Sopenharmony_ci   VkWriteDescriptorSet *writes;
85bf215546Sopenharmony_ci   VkDescriptorImageInfo *images;
86bf215546Sopenharmony_ci   VkDescriptorBufferInfo *buffers;
87bf215546Sopenharmony_ci   VkBufferView *views;
88bf215546Sopenharmony_ci   VkWriteDescriptorSetInlineUniformBlock *iubs;
89bf215546Sopenharmony_ci};
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_cistruct vn_descriptor_set {
92bf215546Sopenharmony_ci   struct vn_object_base base;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci   struct vn_descriptor_set_layout *layout;
95bf215546Sopenharmony_ci   uint32_t last_binding_descriptor_count;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   struct list_head head;
98bf215546Sopenharmony_ci};
99bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set,
100bf215546Sopenharmony_ci                               base.base,
101bf215546Sopenharmony_ci                               VkDescriptorSet,
102bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_SET)
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cistruct vn_descriptor_update_template_entry {
105bf215546Sopenharmony_ci   size_t offset;
106bf215546Sopenharmony_ci   size_t stride;
107bf215546Sopenharmony_ci};
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_cistruct vn_descriptor_update_template {
110bf215546Sopenharmony_ci   struct vn_object_base base;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   mtx_t mutex;
113bf215546Sopenharmony_ci   struct vn_update_descriptor_sets *update;
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   struct vn_descriptor_update_template_entry entries[];
116bf215546Sopenharmony_ci};
117bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template,
118bf215546Sopenharmony_ci                               base.base,
119bf215546Sopenharmony_ci                               VkDescriptorUpdateTemplate,
120bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci#endif /* VN_DESCRIPTOR_SET_H */
123