1 /*
2 * Copyright © 2021 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PANVK_SHADER_H
7 #define PANVK_SHADER_H
8
9 #ifndef PAN_ARCH
10 #error "PAN_ARCH must be defined"
11 #endif
12
13 #include "util/pan_ir.h"
14
15 #include "pan_desc.h"
16
17 #include "panvk_descriptor_set.h"
18 #include "panvk_macros.h"
19 #include "panvk_mempool.h"
20
21 #include "vk_pipeline_layout.h"
22
23 #include "vk_shader.h"
24
25 extern const struct vk_device_shader_ops panvk_per_arch(device_shader_ops);
26
27 #define MAX_VS_ATTRIBS 16
28
29 struct nir_shader;
30 struct pan_blend_state;
31 struct panvk_device;
32
33 enum panvk_varying_buf_id {
34 PANVK_VARY_BUF_GENERAL,
35 PANVK_VARY_BUF_POSITION,
36 PANVK_VARY_BUF_PSIZ,
37
38 /* Keep last */
39 PANVK_VARY_BUF_MAX,
40 };
41
42 struct panvk_graphics_sysvals {
43 struct {
44 struct {
45 float x, y, z;
46 } scale, offset;
47 } viewport;
48
49 struct {
50 float constants[4];
51 } blend;
52
53 struct {
54 uint32_t first_vertex;
55 uint32_t base_vertex;
56 uint32_t base_instance;
57 } vs;
58
59 struct {
60 uint32_t multisampled;
61 } fs;
62
63 #if PAN_ARCH <= 7
64 /* gl_Layer on Bifrost is a bit of hack. We have to issue one draw per
65 * layer, and filter primitives at the VS level.
66 */
67 int32_t layer_id;
68
69 struct {
70 uint64_t sets[MAX_SETS];
71 uint64_t vs_dyn_ssbos;
72 uint64_t fs_dyn_ssbos;
73 } desc;
74 #endif
75 };
76
77 struct panvk_compute_sysvals {
78 struct {
79 uint32_t x, y, z;
80 } base;
81 struct {
82 uint32_t x, y, z;
83 } num_work_groups;
84 struct {
85 uint32_t x, y, z;
86 } local_group_size;
87
88 #if PAN_ARCH <= 7
89 struct {
90 uint64_t sets[MAX_SETS];
91 uint64_t dyn_ssbos;
92 } desc;
93 #endif
94 };
95
96 #if PAN_ARCH <= 7
97 enum panvk_bifrost_desc_table_type {
98 PANVK_BIFROST_DESC_TABLE_INVALID = -1,
99
100 /* UBO is encoded on 8 bytes */
101 PANVK_BIFROST_DESC_TABLE_UBO = 0,
102
103 /* Images are using a <3DAttributeBuffer,Attribute> pair, each
104 * of them being stored in a separate table. */
105 PANVK_BIFROST_DESC_TABLE_IMG,
106
107 /* Texture and sampler are encoded on 32 bytes */
108 PANVK_BIFROST_DESC_TABLE_TEXTURE,
109 PANVK_BIFROST_DESC_TABLE_SAMPLER,
110
111 PANVK_BIFROST_DESC_TABLE_COUNT,
112 };
113 #endif
114
115 #define COPY_DESC_HANDLE(table, idx) ((table << 28) | (idx))
116 #define COPY_DESC_HANDLE_EXTRACT_INDEX(handle) ((handle) & BITFIELD_MASK(28))
117 #define COPY_DESC_HANDLE_EXTRACT_TABLE(handle) ((handle) >> 28)
118
119 struct panvk_shader {
120 struct vk_shader vk;
121 struct pan_shader_info info;
122 struct pan_compute_dim local_size;
123
124 struct {
125 uint32_t used_set_mask;
126
127 #if PAN_ARCH <= 7
128 struct {
129 uint32_t map[MAX_DYNAMIC_UNIFORM_BUFFERS];
130 uint32_t count;
131 } dyn_ubos;
132 struct {
133 uint32_t map[MAX_DYNAMIC_STORAGE_BUFFERS];
134 uint32_t count;
135 } dyn_ssbos;
136 struct {
137 struct panvk_priv_mem map;
138 uint32_t count[PANVK_BIFROST_DESC_TABLE_COUNT];
139 } others;
140 #else
141 struct {
142 uint32_t map[MAX_DYNAMIC_BUFFERS];
143 uint32_t count;
144 } dyn_bufs;
145 #endif
146 } desc_info;
147
148 const void *bin_ptr;
149 uint32_t bin_size;
150
151 struct panvk_priv_mem code_mem;
152
153 #if PAN_ARCH <= 7
154 struct panvk_priv_mem rsd;
155 #else
156 union {
157 struct panvk_priv_mem spd;
158 struct {
159 struct panvk_priv_mem pos_points;
160 struct panvk_priv_mem pos_triangles;
161 struct panvk_priv_mem var;
162 } spds;
163 };
164 #endif
165
166 const char *nir_str;
167 const char *asm_str;
168 };
169
170 struct panvk_shader_link {
171 struct {
172 struct panvk_priv_mem attribs;
173 } vs, fs;
174 unsigned buf_strides[PANVK_VARY_BUF_MAX];
175 };
176
177 static inline mali_ptr
panvk_shader_get_dev_addr(const struct panvk_shader * shader)178 panvk_shader_get_dev_addr(const struct panvk_shader *shader)
179 {
180 return shader != NULL ? panvk_priv_mem_dev_addr(shader->code_mem) : 0;
181 }
182
183 VkResult panvk_per_arch(link_shaders)(struct panvk_pool *desc_pool,
184 const struct panvk_shader *vs,
185 const struct panvk_shader *fs,
186 struct panvk_shader_link *link);
187
188 static inline void
panvk_shader_link_cleanup(struct panvk_pool * desc_pool,struct panvk_shader_link * link)189 panvk_shader_link_cleanup(struct panvk_pool *desc_pool,
190 struct panvk_shader_link *link)
191 {
192 panvk_pool_free_mem(desc_pool, link->vs.attribs);
193 panvk_pool_free_mem(desc_pool, link->fs.attribs);
194 }
195
196 bool panvk_per_arch(nir_lower_descriptors)(
197 nir_shader *nir, struct panvk_device *dev, uint32_t set_layout_count,
198 struct vk_descriptor_set_layout *const *set_layouts,
199 struct panvk_shader *shader);
200
201 #endif
202