1 #include "vk_graphics_state.h"
2
3 #include "vk_alloc.h"
4 #include "vk_command_buffer.h"
5 #include "vk_common_entrypoints.h"
6 #include "vk_device.h"
7 #include "vk_log.h"
8 #include "vk_pipeline.h"
9 #include "vk_render_pass.h"
10 #include "vk_standard_sample_locations.h"
11 #include "vk_util.h"
12
13 #include <assert.h>
14
15 enum mesa_vk_graphics_state_groups {
16 MESA_VK_GRAPHICS_STATE_VERTEX_INPUT_BIT = (1 << 0),
17 MESA_VK_GRAPHICS_STATE_INPUT_ASSEMBLY_BIT = (1 << 1),
18 MESA_VK_GRAPHICS_STATE_TESSELLATION_BIT = (1 << 2),
19 MESA_VK_GRAPHICS_STATE_VIEWPORT_BIT = (1 << 3),
20 MESA_VK_GRAPHICS_STATE_DISCARD_RECTANGLES_BIT = (1 << 4),
21 MESA_VK_GRAPHICS_STATE_RASTERIZATION_BIT = (1 << 5),
22 MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT = (1 << 6),
23 MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT = (1 << 7),
24 MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT = (1 << 8),
25 MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT = (1 << 9),
26 MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT = (1 << 10),
27 MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT = (1 << 11),
28 MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT = (1 << 12),
29 };
30
31 static void
clear_all_dynamic_state(BITSET_WORD * dynamic)32 clear_all_dynamic_state(BITSET_WORD *dynamic)
33 {
34 /* Clear the whole array so there are no undefined bits at the top */
35 memset(dynamic, 0, sizeof(*dynamic) *
36 BITSET_WORDS(MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX));
37 }
38
39 static void
get_dynamic_state_groups(BITSET_WORD * dynamic,enum mesa_vk_graphics_state_groups groups)40 get_dynamic_state_groups(BITSET_WORD *dynamic,
41 enum mesa_vk_graphics_state_groups groups)
42 {
43 clear_all_dynamic_state(dynamic);
44
45 if (groups & MESA_VK_GRAPHICS_STATE_VERTEX_INPUT_BIT) {
46 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VI);
47 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VI_BINDINGS_VALID);
48 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VI_BINDING_STRIDES);
49 }
50
51 if (groups & MESA_VK_GRAPHICS_STATE_INPUT_ASSEMBLY_BIT) {
52 BITSET_SET(dynamic, MESA_VK_DYNAMIC_IA_PRIMITIVE_TOPOLOGY);
53 BITSET_SET(dynamic, MESA_VK_DYNAMIC_IA_PRIMITIVE_RESTART_ENABLE);
54 }
55
56 if (groups & MESA_VK_GRAPHICS_STATE_TESSELLATION_BIT) {
57 BITSET_SET(dynamic, MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS);
58 BITSET_SET(dynamic, MESA_VK_DYNAMIC_TS_DOMAIN_ORIGIN);
59 }
60
61 if (groups & MESA_VK_GRAPHICS_STATE_VIEWPORT_BIT) {
62 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VP_VIEWPORT_COUNT);
63 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VP_VIEWPORTS);
64 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VP_SCISSOR_COUNT);
65 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VP_SCISSORS);
66 BITSET_SET(dynamic, MESA_VK_DYNAMIC_VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE);
67 }
68
69 if (groups & MESA_VK_GRAPHICS_STATE_DISCARD_RECTANGLES_BIT) {
70 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DR_RECTANGLES);
71 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DR_ENABLE);
72 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DR_MODE);
73 }
74
75 if (groups & MESA_VK_GRAPHICS_STATE_RASTERIZATION_BIT) {
76 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE);
77 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_DEPTH_CLAMP_ENABLE);
78 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_DEPTH_CLIP_ENABLE);
79 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_POLYGON_MODE);
80 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_CULL_MODE);
81 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_FRONT_FACE);
82 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_CONSERVATIVE_MODE);
83 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE);
84 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_RASTERIZATION_ORDER_AMD);
85 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_PROVOKING_VERTEX);
86 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_RASTERIZATION_STREAM);
87 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_DEPTH_BIAS_ENABLE);
88 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS);
89 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_LINE_WIDTH);
90 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_LINE_MODE);
91 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_LINE_STIPPLE_ENABLE);
92 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RS_LINE_STIPPLE);
93 }
94
95 if (groups & MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT)
96 BITSET_SET(dynamic, MESA_VK_DYNAMIC_FSR);
97
98 if (groups & MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT) {
99 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_RASTERIZATION_SAMPLES);
100 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_SAMPLE_MASK);
101 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_ALPHA_TO_COVERAGE_ENABLE);
102 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_ALPHA_TO_ONE_ENABLE);
103 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS_ENABLE);
104 BITSET_SET(dynamic, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS);
105 }
106
107 if (groups & MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT) {
108 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_TEST_ENABLE);
109 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_WRITE_ENABLE);
110 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_COMPARE_OP);
111 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_ENABLE);
112 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_BOUNDS);
113 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_TEST_ENABLE);
114 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_OP);
115 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_COMPARE_MASK);
116 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_WRITE_MASK);
117 BITSET_SET(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_REFERENCE);
118 }
119
120 if (groups & MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT) {
121 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_LOGIC_OP_ENABLE);
122 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_LOGIC_OP);
123 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_ATTACHMENT_COUNT);
124 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_COLOR_WRITE_ENABLES);
125 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_BLEND_ENABLES);
126 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS);
127 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_WRITE_MASKS);
128 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_BLEND_CONSTANTS);
129 }
130
131 if (groups & MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT)
132 BITSET_SET(dynamic, MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP);
133
134 if (groups & MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT)
135 BITSET_SET(dynamic, MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP);
136
137 if (groups & MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT) {
138 BITSET_SET(dynamic, MESA_VK_DYNAMIC_RP_ATTACHMENTS);
139 BITSET_SET(dynamic, MESA_VK_DYNAMIC_ATTACHMENT_FEEDBACK_LOOP_ENABLE);
140 }
141 }
142
143 static enum mesa_vk_graphics_state_groups
fully_dynamic_state_groups(const BITSET_WORD * dynamic)144 fully_dynamic_state_groups(const BITSET_WORD *dynamic)
145 {
146 enum mesa_vk_graphics_state_groups groups = 0;
147
148 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_VI) &&
149 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_VI_BINDING_STRIDES) &&
150 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_VI_BINDINGS_VALID))
151 groups |= MESA_VK_GRAPHICS_STATE_VERTEX_INPUT_BIT;
152
153 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS) &&
154 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_TS_DOMAIN_ORIGIN))
155 groups |= MESA_VK_GRAPHICS_STATE_TESSELLATION_BIT;
156
157 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_FSR))
158 groups |= MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT;
159
160 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_TEST_ENABLE) &&
161 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_WRITE_ENABLE) &&
162 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_COMPARE_OP) &&
163 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_ENABLE) &&
164 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_BOUNDS) &&
165 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_TEST_ENABLE) &&
166 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_OP) &&
167 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_COMPARE_MASK) &&
168 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_WRITE_MASK) &&
169 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_DS_STENCIL_REFERENCE))
170 groups |= MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT;
171
172 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_LOGIC_OP_ENABLE) &&
173 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_LOGIC_OP) &&
174 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_ATTACHMENT_COUNT) &&
175 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_COLOR_WRITE_ENABLES) &&
176 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_ENABLES) &&
177 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS) &&
178 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_WRITE_MASKS) &&
179 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_CONSTANTS))
180 groups |= MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT;
181
182 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_COLOR_ATTACHMENT_MAP))
183 groups |= MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT;
184
185 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_INPUT_ATTACHMENT_MAP))
186 groups |= MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT;
187
188 return groups;
189 }
190
191 static void
validate_dynamic_state_groups(const BITSET_WORD * dynamic,enum mesa_vk_graphics_state_groups groups)192 validate_dynamic_state_groups(const BITSET_WORD *dynamic,
193 enum mesa_vk_graphics_state_groups groups)
194 {
195 #ifndef NDEBUG
196 BITSET_DECLARE(all_dynamic, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
197 get_dynamic_state_groups(all_dynamic, groups);
198
199 for (uint32_t w = 0; w < ARRAY_SIZE(all_dynamic); w++)
200 assert(!(dynamic[w] & ~all_dynamic[w]));
201 #endif
202 }
203
204 void
vk_get_dynamic_graphics_states(BITSET_WORD * dynamic,const VkPipelineDynamicStateCreateInfo * info)205 vk_get_dynamic_graphics_states(BITSET_WORD *dynamic,
206 const VkPipelineDynamicStateCreateInfo *info)
207 {
208 clear_all_dynamic_state(dynamic);
209
210 /* From the Vulkan 1.3.218 spec:
211 *
212 * "pDynamicState is a pointer to a VkPipelineDynamicStateCreateInfo
213 * structure defining which properties of the pipeline state object are
214 * dynamic and can be changed independently of the pipeline state. This
215 * can be NULL, which means no state in the pipeline is considered
216 * dynamic."
217 */
218 if (info == NULL)
219 return;
220
221 #define CASE(VK, MESA) \
222 case VK_DYNAMIC_STATE_##VK: \
223 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA); \
224 break;
225
226 #define CASE2(VK, MESA1, MESA2) \
227 case VK_DYNAMIC_STATE_##VK: \
228 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA1); \
229 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA2); \
230 break;
231
232 #define CASE3(VK, MESA1, MESA2, MESA3) \
233 case VK_DYNAMIC_STATE_##VK: \
234 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA1); \
235 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA2); \
236 BITSET_SET(dynamic, MESA_VK_DYNAMIC_##MESA3); \
237 break;
238
239 for (uint32_t i = 0; i < info->dynamicStateCount; i++) {
240 switch (info->pDynamicStates[i]) {
241 CASE3(VERTEX_INPUT_EXT, VI, VI_BINDINGS_VALID, VI_BINDING_STRIDES)
242 CASE( VERTEX_INPUT_BINDING_STRIDE, VI_BINDING_STRIDES)
243 CASE( VIEWPORT, VP_VIEWPORTS)
244 CASE( SCISSOR, VP_SCISSORS)
245 CASE( LINE_WIDTH, RS_LINE_WIDTH)
246 CASE( DEPTH_BIAS, RS_DEPTH_BIAS_FACTORS)
247 CASE( BLEND_CONSTANTS, CB_BLEND_CONSTANTS)
248 CASE( DEPTH_BOUNDS, DS_DEPTH_BOUNDS_TEST_BOUNDS)
249 CASE( STENCIL_COMPARE_MASK, DS_STENCIL_COMPARE_MASK)
250 CASE( STENCIL_WRITE_MASK, DS_STENCIL_WRITE_MASK)
251 CASE( STENCIL_REFERENCE, DS_STENCIL_REFERENCE)
252 CASE( CULL_MODE, RS_CULL_MODE)
253 CASE( FRONT_FACE, RS_FRONT_FACE)
254 CASE( PRIMITIVE_TOPOLOGY, IA_PRIMITIVE_TOPOLOGY)
255 CASE2(VIEWPORT_WITH_COUNT, VP_VIEWPORT_COUNT, VP_VIEWPORTS)
256 CASE2(SCISSOR_WITH_COUNT, VP_SCISSOR_COUNT, VP_SCISSORS)
257 CASE( DEPTH_TEST_ENABLE, DS_DEPTH_TEST_ENABLE)
258 CASE( DEPTH_WRITE_ENABLE, DS_DEPTH_WRITE_ENABLE)
259 CASE( DEPTH_COMPARE_OP, DS_DEPTH_COMPARE_OP)
260 CASE( DEPTH_BOUNDS_TEST_ENABLE, DS_DEPTH_BOUNDS_TEST_ENABLE)
261 CASE( STENCIL_TEST_ENABLE, DS_STENCIL_TEST_ENABLE)
262 CASE( STENCIL_OP, DS_STENCIL_OP)
263 CASE( RASTERIZER_DISCARD_ENABLE, RS_RASTERIZER_DISCARD_ENABLE)
264 CASE( DEPTH_BIAS_ENABLE, RS_DEPTH_BIAS_ENABLE)
265 CASE( PRIMITIVE_RESTART_ENABLE, IA_PRIMITIVE_RESTART_ENABLE)
266 CASE( DISCARD_RECTANGLE_EXT, DR_RECTANGLES)
267 CASE( DISCARD_RECTANGLE_ENABLE_EXT, DR_ENABLE)
268 CASE( DISCARD_RECTANGLE_MODE_EXT, DR_MODE)
269 CASE( SAMPLE_LOCATIONS_EXT, MS_SAMPLE_LOCATIONS)
270 CASE( FRAGMENT_SHADING_RATE_KHR, FSR)
271 CASE( LINE_STIPPLE_EXT, RS_LINE_STIPPLE)
272 CASE( PATCH_CONTROL_POINTS_EXT, TS_PATCH_CONTROL_POINTS)
273 CASE( LOGIC_OP_EXT, CB_LOGIC_OP)
274 CASE( COLOR_WRITE_ENABLE_EXT, CB_COLOR_WRITE_ENABLES)
275 CASE( TESSELLATION_DOMAIN_ORIGIN_EXT, TS_DOMAIN_ORIGIN)
276 CASE( DEPTH_CLAMP_ENABLE_EXT, RS_DEPTH_CLAMP_ENABLE)
277 CASE( POLYGON_MODE_EXT, RS_POLYGON_MODE)
278 CASE( RASTERIZATION_SAMPLES_EXT, MS_RASTERIZATION_SAMPLES)
279 CASE( SAMPLE_MASK_EXT, MS_SAMPLE_MASK)
280 CASE( ALPHA_TO_COVERAGE_ENABLE_EXT, MS_ALPHA_TO_COVERAGE_ENABLE)
281 CASE( ALPHA_TO_ONE_ENABLE_EXT, MS_ALPHA_TO_ONE_ENABLE)
282 CASE( LOGIC_OP_ENABLE_EXT, CB_LOGIC_OP_ENABLE)
283 CASE( COLOR_BLEND_ENABLE_EXT, CB_BLEND_ENABLES)
284 CASE( COLOR_BLEND_EQUATION_EXT, CB_BLEND_EQUATIONS)
285 CASE( COLOR_WRITE_MASK_EXT, CB_WRITE_MASKS)
286 CASE( RASTERIZATION_STREAM_EXT, RS_RASTERIZATION_STREAM)
287 CASE( CONSERVATIVE_RASTERIZATION_MODE_EXT, RS_CONSERVATIVE_MODE)
288 CASE( EXTRA_PRIMITIVE_OVERESTIMATION_SIZE_EXT, RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE)
289 CASE( DEPTH_CLIP_ENABLE_EXT, RS_DEPTH_CLIP_ENABLE)
290 CASE( SAMPLE_LOCATIONS_ENABLE_EXT, MS_SAMPLE_LOCATIONS_ENABLE)
291 CASE( PROVOKING_VERTEX_MODE_EXT, RS_PROVOKING_VERTEX)
292 CASE( LINE_RASTERIZATION_MODE_EXT, RS_LINE_MODE)
293 CASE( LINE_STIPPLE_ENABLE_EXT, RS_LINE_STIPPLE_ENABLE)
294 CASE( DEPTH_CLIP_NEGATIVE_ONE_TO_ONE_EXT, VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE)
295 CASE( ATTACHMENT_FEEDBACK_LOOP_ENABLE_EXT, ATTACHMENT_FEEDBACK_LOOP_ENABLE)
296 default:
297 unreachable("Unsupported dynamic graphics state");
298 }
299 }
300
301 /* attachmentCount is ignored if all of the states using it are dyanmic.
302 *
303 * TODO: Handle advanced blending here when supported.
304 */
305 if (BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_ENABLES) &&
306 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS) &&
307 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_CB_WRITE_MASKS))
308 BITSET_SET(dynamic, MESA_VK_DYNAMIC_CB_ATTACHMENT_COUNT);
309 }
310
311 #define IS_DYNAMIC(STATE) \
312 BITSET_TEST(dynamic, MESA_VK_DYNAMIC_##STATE)
313
314 #define IS_NEEDED(STATE) \
315 BITSET_TEST(needed, MESA_VK_DYNAMIC_##STATE)
316
317 static void
vk_vertex_input_state_init(struct vk_vertex_input_state * vi,const BITSET_WORD * dynamic,const VkPipelineVertexInputStateCreateInfo * vi_info)318 vk_vertex_input_state_init(struct vk_vertex_input_state *vi,
319 const BITSET_WORD *dynamic,
320 const VkPipelineVertexInputStateCreateInfo *vi_info)
321 {
322 assert(!IS_DYNAMIC(VI));
323
324 memset(vi, 0, sizeof(*vi));
325 if (!vi_info)
326 return;
327
328 for (uint32_t i = 0; i < vi_info->vertexBindingDescriptionCount; i++) {
329 const VkVertexInputBindingDescription *desc =
330 &vi_info->pVertexBindingDescriptions[i];
331
332 assert(desc->binding < MESA_VK_MAX_VERTEX_BINDINGS);
333 assert(desc->stride <= MESA_VK_MAX_VERTEX_BINDING_STRIDE);
334 assert(desc->inputRate <= 1);
335
336 const uint32_t b = desc->binding;
337 vi->bindings_valid |= BITFIELD_BIT(b);
338 vi->bindings[b].stride = desc->stride;
339 vi->bindings[b].input_rate = desc->inputRate;
340 vi->bindings[b].divisor = 1;
341 }
342
343 for (uint32_t i = 0; i < vi_info->vertexAttributeDescriptionCount; i++) {
344 const VkVertexInputAttributeDescription *desc =
345 &vi_info->pVertexAttributeDescriptions[i];
346
347 assert(desc->location < MESA_VK_MAX_VERTEX_ATTRIBUTES);
348 assert(desc->binding < MESA_VK_MAX_VERTEX_BINDINGS);
349 assert(vi->bindings_valid & BITFIELD_BIT(desc->binding));
350
351 const uint32_t a = desc->location;
352 vi->attributes_valid |= BITFIELD_BIT(a);
353 vi->attributes[a].binding = desc->binding;
354 vi->attributes[a].format = desc->format;
355 vi->attributes[a].offset = desc->offset;
356 }
357
358 const VkPipelineVertexInputDivisorStateCreateInfoKHR *vi_div_state =
359 vk_find_struct_const(vi_info->pNext,
360 PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_KHR);
361 if (vi_div_state) {
362 for (uint32_t i = 0; i < vi_div_state->vertexBindingDivisorCount; i++) {
363 const VkVertexInputBindingDivisorDescriptionKHR *desc =
364 &vi_div_state->pVertexBindingDivisors[i];
365
366 assert(desc->binding < MESA_VK_MAX_VERTEX_BINDINGS);
367 assert(vi->bindings_valid & BITFIELD_BIT(desc->binding));
368
369 const uint32_t b = desc->binding;
370 vi->bindings[b].divisor = desc->divisor;
371 }
372 }
373 }
374
375 static void
vk_dynamic_graphics_state_init_vi(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_vertex_input_state * vi)376 vk_dynamic_graphics_state_init_vi(struct vk_dynamic_graphics_state *dst,
377 const BITSET_WORD *needed,
378 const struct vk_vertex_input_state *vi)
379 {
380 if (IS_NEEDED(VI))
381 *dst->vi = *vi;
382
383 if (IS_NEEDED(VI_BINDINGS_VALID))
384 dst->vi_bindings_valid = vi->bindings_valid;
385
386 if (IS_NEEDED(VI_BINDING_STRIDES)) {
387 for (uint32_t b = 0; b < MESA_VK_MAX_VERTEX_BINDINGS; b++) {
388 if (vi->bindings_valid & BITFIELD_BIT(b))
389 dst->vi_binding_strides[b] = vi->bindings[b].stride;
390 else
391 dst->vi_binding_strides[b] = 0;
392 }
393 }
394 }
395
396 static void
vk_input_assembly_state_init(struct vk_input_assembly_state * ia,const BITSET_WORD * dynamic,const VkPipelineInputAssemblyStateCreateInfo * ia_info)397 vk_input_assembly_state_init(struct vk_input_assembly_state *ia,
398 const BITSET_WORD *dynamic,
399 const VkPipelineInputAssemblyStateCreateInfo *ia_info)
400 {
401 memset(ia, 0, sizeof(*ia));
402 if (!ia_info)
403 return;
404
405 /* From the Vulkan 1.3.224 spec:
406 *
407 * "VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY specifies that the topology
408 * state in VkPipelineInputAssemblyStateCreateInfo only specifies the
409 * topology class, and the specific topology order and adjacency must be
410 * set dynamically with vkCmdSetPrimitiveTopology before any drawing
411 * commands."
412 */
413 assert(ia_info->topology <= UINT8_MAX);
414 ia->primitive_topology = ia_info->topology;
415
416 ia->primitive_restart_enable = ia_info->primitiveRestartEnable;
417 }
418
419 static void
vk_dynamic_graphics_state_init_ia(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_input_assembly_state * ia)420 vk_dynamic_graphics_state_init_ia(struct vk_dynamic_graphics_state *dst,
421 const BITSET_WORD *needed,
422 const struct vk_input_assembly_state *ia)
423 {
424 dst->ia = *ia;
425 }
426
427 static void
vk_tessellation_state_init(struct vk_tessellation_state * ts,const BITSET_WORD * dynamic,const VkPipelineTessellationStateCreateInfo * ts_info)428 vk_tessellation_state_init(struct vk_tessellation_state *ts,
429 const BITSET_WORD *dynamic,
430 const VkPipelineTessellationStateCreateInfo *ts_info)
431 {
432 *ts = (struct vk_tessellation_state) {
433 .domain_origin = VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT,
434 };
435 if (!ts_info)
436 return;
437
438 if (!IS_DYNAMIC(TS_PATCH_CONTROL_POINTS)) {
439 assert(ts_info->patchControlPoints <= UINT8_MAX);
440 ts->patch_control_points = ts_info->patchControlPoints;
441 }
442
443 if (!IS_DYNAMIC(TS_DOMAIN_ORIGIN)) {
444 const VkPipelineTessellationDomainOriginStateCreateInfo *ts_do_info =
445 vk_find_struct_const(ts_info->pNext,
446 PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO);
447 if (ts_do_info != NULL) {
448 assert(ts_do_info->domainOrigin <= UINT8_MAX);
449 ts->domain_origin = ts_do_info->domainOrigin;
450 }
451 }
452 }
453
454 static void
vk_dynamic_graphics_state_init_ts(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_tessellation_state * ts)455 vk_dynamic_graphics_state_init_ts(struct vk_dynamic_graphics_state *dst,
456 const BITSET_WORD *needed,
457 const struct vk_tessellation_state *ts)
458 {
459 dst->ts = *ts;
460 }
461
462 static void
vk_viewport_state_init(struct vk_viewport_state * vp,const BITSET_WORD * dynamic,const VkPipelineViewportStateCreateInfo * vp_info)463 vk_viewport_state_init(struct vk_viewport_state *vp,
464 const BITSET_WORD *dynamic,
465 const VkPipelineViewportStateCreateInfo *vp_info)
466 {
467 memset(vp, 0, sizeof(*vp));
468 if (!vp_info)
469 return;
470
471 if (!IS_DYNAMIC(VP_VIEWPORT_COUNT)) {
472 assert(vp_info->viewportCount <= MESA_VK_MAX_VIEWPORTS);
473 vp->viewport_count = vp_info->viewportCount;
474 }
475
476 if (!IS_DYNAMIC(VP_VIEWPORTS)) {
477 assert(!IS_DYNAMIC(VP_VIEWPORT_COUNT));
478 typed_memcpy(vp->viewports, vp_info->pViewports,
479 vp_info->viewportCount);
480 }
481
482 if (!IS_DYNAMIC(VP_SCISSOR_COUNT)) {
483 assert(vp_info->scissorCount <= MESA_VK_MAX_SCISSORS);
484 vp->scissor_count = vp_info->scissorCount;
485 }
486
487 if (!IS_DYNAMIC(VP_SCISSORS)) {
488 assert(!IS_DYNAMIC(VP_SCISSOR_COUNT));
489 typed_memcpy(vp->scissors, vp_info->pScissors,
490 vp_info->scissorCount);
491 }
492
493 if (!IS_DYNAMIC(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE)) {
494 const VkPipelineViewportDepthClipControlCreateInfoEXT *vp_dcc_info =
495 vk_find_struct_const(vp_info->pNext,
496 PIPELINE_VIEWPORT_DEPTH_CLIP_CONTROL_CREATE_INFO_EXT);
497 if (vp_dcc_info != NULL)
498 vp->depth_clip_negative_one_to_one = vp_dcc_info->negativeOneToOne;
499 }
500 }
501
502 static void
vk_dynamic_graphics_state_init_vp(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_viewport_state * vp)503 vk_dynamic_graphics_state_init_vp(struct vk_dynamic_graphics_state *dst,
504 const BITSET_WORD *needed,
505 const struct vk_viewport_state *vp)
506 {
507 dst->vp.viewport_count = vp->viewport_count;
508 if (IS_NEEDED(VP_VIEWPORTS))
509 typed_memcpy(dst->vp.viewports, vp->viewports, vp->viewport_count);
510
511 dst->vp.scissor_count = vp->scissor_count;
512 if (IS_NEEDED(VP_SCISSORS))
513 typed_memcpy(dst->vp.scissors, vp->scissors, vp->scissor_count);
514
515 dst->vp.depth_clip_negative_one_to_one = vp->depth_clip_negative_one_to_one;
516 }
517
518 static void
vk_discard_rectangles_state_init(struct vk_discard_rectangles_state * dr,const BITSET_WORD * dynamic,const VkPipelineDiscardRectangleStateCreateInfoEXT * dr_info)519 vk_discard_rectangles_state_init(struct vk_discard_rectangles_state *dr,
520 const BITSET_WORD *dynamic,
521 const VkPipelineDiscardRectangleStateCreateInfoEXT *dr_info)
522 {
523 memset(dr, 0, sizeof(*dr));
524
525 if (dr_info == NULL)
526 return;
527
528 assert(dr_info->discardRectangleCount <= MESA_VK_MAX_DISCARD_RECTANGLES);
529 dr->mode = dr_info->discardRectangleMode;
530 dr->rectangle_count = dr_info->discardRectangleCount;
531
532 if (!IS_DYNAMIC(DR_RECTANGLES)) {
533 typed_memcpy(dr->rectangles, dr_info->pDiscardRectangles,
534 dr_info->discardRectangleCount);
535 }
536 }
537
538 static void
vk_dynamic_graphics_state_init_dr(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_discard_rectangles_state * dr)539 vk_dynamic_graphics_state_init_dr(struct vk_dynamic_graphics_state *dst,
540 const BITSET_WORD *needed,
541 const struct vk_discard_rectangles_state *dr)
542 {
543 dst->dr.enable = dr->rectangle_count > 0;
544 dst->dr.mode = dr->mode;
545 dst->dr.rectangle_count = dr->rectangle_count;
546 typed_memcpy(dst->dr.rectangles, dr->rectangles, dr->rectangle_count);
547 }
548
549 static void
vk_rasterization_state_init(struct vk_rasterization_state * rs,const BITSET_WORD * dynamic,const VkPipelineRasterizationStateCreateInfo * rs_info)550 vk_rasterization_state_init(struct vk_rasterization_state *rs,
551 const BITSET_WORD *dynamic,
552 const VkPipelineRasterizationStateCreateInfo *rs_info)
553 {
554 *rs = (struct vk_rasterization_state) {
555 .rasterizer_discard_enable = false,
556 .conservative_mode = VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT,
557 .extra_primitive_overestimation_size = 0.0f,
558 .rasterization_order_amd = VK_RASTERIZATION_ORDER_STRICT_AMD,
559 .provoking_vertex = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT,
560 .line.mode = VK_LINE_RASTERIZATION_MODE_DEFAULT_KHR,
561 .depth_clip_enable = IS_DYNAMIC(RS_DEPTH_CLAMP_ENABLE) ? VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP : VK_MESA_DEPTH_CLIP_ENABLE_FALSE,
562 .depth_bias.representation = VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT,
563 .depth_bias.exact = false,
564 };
565 if (!rs_info)
566 return;
567
568 if (!IS_DYNAMIC(RS_RASTERIZER_DISCARD_ENABLE))
569 rs->rasterizer_discard_enable = rs_info->rasterizerDiscardEnable;
570
571 /* From the Vulkan 1.3.218 spec:
572 *
573 * "If VkPipelineRasterizationDepthClipStateCreateInfoEXT is present in
574 * the graphics pipeline state then depth clipping is disabled if
575 * VkPipelineRasterizationDepthClipStateCreateInfoEXT::depthClipEnable
576 * is VK_FALSE. Otherwise, if
577 * VkPipelineRasterizationDepthClipStateCreateInfoEXT is not present,
578 * depth clipping is disabled when
579 * VkPipelineRasterizationStateCreateInfo::depthClampEnable is VK_TRUE.
580 */
581 if (!IS_DYNAMIC(RS_DEPTH_CLAMP_ENABLE)) {
582 rs->depth_clamp_enable = rs_info->depthClampEnable;
583 rs->depth_clip_enable = rs_info->depthClampEnable ?
584 VK_MESA_DEPTH_CLIP_ENABLE_FALSE :
585 VK_MESA_DEPTH_CLIP_ENABLE_TRUE;
586 }
587
588 rs->polygon_mode = rs_info->polygonMode;
589
590 rs->cull_mode = rs_info->cullMode;
591 rs->front_face = rs_info->frontFace;
592 rs->depth_bias.enable = rs_info->depthBiasEnable;
593 if ((rs_info->depthBiasEnable || IS_DYNAMIC(RS_DEPTH_BIAS_ENABLE)) &&
594 !IS_DYNAMIC(RS_DEPTH_BIAS_FACTORS)) {
595 rs->depth_bias.constant = rs_info->depthBiasConstantFactor;
596 rs->depth_bias.clamp = rs_info->depthBiasClamp;
597 rs->depth_bias.slope = rs_info->depthBiasSlopeFactor;
598 }
599 rs->line.width = rs_info->lineWidth;
600
601 vk_foreach_struct_const(ext, rs_info->pNext) {
602 switch (ext->sType) {
603 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT: {
604 const VkPipelineRasterizationConservativeStateCreateInfoEXT *rcs_info =
605 (const VkPipelineRasterizationConservativeStateCreateInfoEXT *)ext;
606 rs->conservative_mode = rcs_info->conservativeRasterizationMode;
607 rs->extra_primitive_overestimation_size =
608 rcs_info->extraPrimitiveOverestimationSize;
609 break;
610 }
611
612 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT: {
613 const VkPipelineRasterizationDepthClipStateCreateInfoEXT *rdc_info =
614 (const VkPipelineRasterizationDepthClipStateCreateInfoEXT *)ext;
615 rs->depth_clip_enable = rdc_info->depthClipEnable ?
616 VK_MESA_DEPTH_CLIP_ENABLE_TRUE :
617 VK_MESA_DEPTH_CLIP_ENABLE_FALSE;
618 break;
619 }
620
621 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT: {
622 const VkPipelineRasterizationLineStateCreateInfoKHR *rl_info =
623 (const VkPipelineRasterizationLineStateCreateInfoKHR *)ext;
624 rs->line.mode = rl_info->lineRasterizationMode;
625 if (!IS_DYNAMIC(RS_LINE_STIPPLE_ENABLE))
626 rs->line.stipple.enable = rl_info->stippledLineEnable;
627 if ((IS_DYNAMIC(RS_LINE_STIPPLE_ENABLE) || rs->line.stipple.enable) && !IS_DYNAMIC(RS_LINE_STIPPLE)) {
628 rs->line.stipple.factor = rl_info->lineStippleFactor;
629 rs->line.stipple.pattern = rl_info->lineStipplePattern;
630 }
631 break;
632 }
633
634 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_PROVOKING_VERTEX_STATE_CREATE_INFO_EXT: {
635 const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *rpv_info =
636 (const VkPipelineRasterizationProvokingVertexStateCreateInfoEXT *)ext;
637 rs->provoking_vertex = rpv_info->provokingVertexMode;
638 break;
639 }
640
641 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_RASTERIZATION_ORDER_AMD: {
642 const VkPipelineRasterizationStateRasterizationOrderAMD *rro_info =
643 (const VkPipelineRasterizationStateRasterizationOrderAMD *)ext;
644 rs->rasterization_order_amd = rro_info->rasterizationOrder;
645 break;
646 }
647
648 case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT: {
649 const VkPipelineRasterizationStateStreamCreateInfoEXT *rss_info =
650 (const VkPipelineRasterizationStateStreamCreateInfoEXT *)ext;
651 rs->rasterization_stream = rss_info->rasterizationStream;
652 break;
653 }
654
655 case VK_STRUCTURE_TYPE_DEPTH_BIAS_REPRESENTATION_INFO_EXT: {
656 const VkDepthBiasRepresentationInfoEXT *dbr_info =
657 (const VkDepthBiasRepresentationInfoEXT *)ext;
658 if (!IS_DYNAMIC(RS_DEPTH_BIAS_FACTORS)) {
659 rs->depth_bias.representation = dbr_info->depthBiasRepresentation;
660 rs->depth_bias.exact = dbr_info->depthBiasExact;
661 }
662 break;
663 }
664
665 default:
666 break;
667 }
668 }
669 }
670
671 static void
vk_dynamic_graphics_state_init_rs(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_rasterization_state * rs)672 vk_dynamic_graphics_state_init_rs(struct vk_dynamic_graphics_state *dst,
673 const BITSET_WORD *needed,
674 const struct vk_rasterization_state *rs)
675 {
676 dst->rs = *rs;
677 }
678
679 static void
vk_fragment_shading_rate_state_init(struct vk_fragment_shading_rate_state * fsr,const BITSET_WORD * dynamic,const VkPipelineFragmentShadingRateStateCreateInfoKHR * fsr_info)680 vk_fragment_shading_rate_state_init(
681 struct vk_fragment_shading_rate_state *fsr,
682 const BITSET_WORD *dynamic,
683 const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_info)
684 {
685 if (fsr_info != NULL) {
686 fsr->fragment_size = fsr_info->fragmentSize;
687 fsr->combiner_ops[0] = fsr_info->combinerOps[0];
688 fsr->combiner_ops[1] = fsr_info->combinerOps[1];
689 } else {
690 fsr->fragment_size = (VkExtent2D) { 1, 1 };
691 fsr->combiner_ops[0] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR;
692 fsr->combiner_ops[1] = VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR;
693 }
694 }
695
696 static void
vk_dynamic_graphics_state_init_fsr(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_fragment_shading_rate_state * fsr)697 vk_dynamic_graphics_state_init_fsr(
698 struct vk_dynamic_graphics_state *dst,
699 const BITSET_WORD *needed,
700 const struct vk_fragment_shading_rate_state *fsr)
701 {
702 dst->fsr = *fsr;
703 }
704
705 static void
vk_sample_locations_state_init(struct vk_sample_locations_state * sl,const VkSampleLocationsInfoEXT * sl_info)706 vk_sample_locations_state_init(struct vk_sample_locations_state *sl,
707 const VkSampleLocationsInfoEXT *sl_info)
708 {
709 sl->per_pixel = sl_info->sampleLocationsPerPixel;
710 sl->grid_size = sl_info->sampleLocationGridSize;
711
712 /* From the Vulkan 1.3.218 spec:
713 *
714 * VUID-VkSampleLocationsInfoEXT-sampleLocationsCount-01527
715 *
716 * "sampleLocationsCount must equal sampleLocationsPerPixel *
717 * sampleLocationGridSize.width * sampleLocationGridSize.height"
718 */
719 assert(sl_info->sampleLocationsCount ==
720 sl_info->sampleLocationsPerPixel *
721 sl_info->sampleLocationGridSize.width *
722 sl_info->sampleLocationGridSize.height);
723
724 assert(sl_info->sampleLocationsCount <= MESA_VK_MAX_SAMPLE_LOCATIONS);
725 typed_memcpy(sl->locations, sl_info->pSampleLocations,
726 sl_info->sampleLocationsCount);
727 }
728
729 static void
vk_multisample_state_init(struct vk_multisample_state * ms,const BITSET_WORD * dynamic,const VkPipelineMultisampleStateCreateInfo * ms_info)730 vk_multisample_state_init(struct vk_multisample_state *ms,
731 const BITSET_WORD *dynamic,
732 const VkPipelineMultisampleStateCreateInfo *ms_info)
733 {
734 memset(ms, 0, sizeof(*ms));
735 if (!ms_info)
736 return;
737
738 if (!IS_DYNAMIC(MS_RASTERIZATION_SAMPLES)) {
739 assert(ms_info->rasterizationSamples <= MESA_VK_MAX_SAMPLES);
740 ms->rasterization_samples = ms_info->rasterizationSamples;
741 }
742
743 ms->sample_shading_enable = ms_info->sampleShadingEnable;
744 ms->min_sample_shading = ms_info->minSampleShading;
745
746 /* From the Vulkan 1.3.218 spec:
747 *
748 * "If pSampleMask is NULL, it is treated as if the mask has all bits
749 * set to 1."
750 */
751 ms->sample_mask = ms_info->pSampleMask ? *ms_info->pSampleMask : ~0;
752
753 ms->alpha_to_coverage_enable = ms_info->alphaToCoverageEnable;
754 ms->alpha_to_one_enable = ms_info->alphaToOneEnable;
755
756 /* These get filled in by vk_multisample_sample_locations_state_init() */
757 ms->sample_locations_enable = false;
758 ms->sample_locations = NULL;
759 }
760
761 static bool
needs_sample_locations_state(const BITSET_WORD * dynamic,const VkPipelineSampleLocationsStateCreateInfoEXT * sl_info)762 needs_sample_locations_state(
763 const BITSET_WORD *dynamic,
764 const VkPipelineSampleLocationsStateCreateInfoEXT *sl_info)
765 {
766 return !IS_DYNAMIC(MS_SAMPLE_LOCATIONS) &&
767 (IS_DYNAMIC(MS_SAMPLE_LOCATIONS_ENABLE) ||
768 (sl_info != NULL && sl_info->sampleLocationsEnable));
769 }
770
771 static void
vk_multisample_sample_locations_state_init(struct vk_multisample_state * ms,struct vk_sample_locations_state * sl,const BITSET_WORD * dynamic,const VkPipelineMultisampleStateCreateInfo * ms_info,const VkPipelineSampleLocationsStateCreateInfoEXT * sl_info)772 vk_multisample_sample_locations_state_init(
773 struct vk_multisample_state *ms,
774 struct vk_sample_locations_state *sl,
775 const BITSET_WORD *dynamic,
776 const VkPipelineMultisampleStateCreateInfo *ms_info,
777 const VkPipelineSampleLocationsStateCreateInfoEXT *sl_info)
778 {
779 ms->sample_locations_enable =
780 IS_DYNAMIC(MS_SAMPLE_LOCATIONS_ENABLE) ||
781 (sl_info != NULL && sl_info->sampleLocationsEnable);
782
783 assert(ms->sample_locations == NULL);
784 if (!IS_DYNAMIC(MS_SAMPLE_LOCATIONS)) {
785 if (ms->sample_locations_enable) {
786 vk_sample_locations_state_init(sl, &sl_info->sampleLocationsInfo);
787 ms->sample_locations = sl;
788 } else if (!IS_DYNAMIC(MS_RASTERIZATION_SAMPLES)) {
789 /* Otherwise, pre-populate with the standard sample locations. If
790 * the driver doesn't support standard sample locations, it probably
791 * doesn't support custom locations either and can completely ignore
792 * this state.
793 */
794 ms->sample_locations =
795 vk_standard_sample_locations_state(ms_info->rasterizationSamples);
796 }
797 /* In the case that the rasterization samples are dynamic we cannot
798 * pre-populate with a specific set of standard sample locations
799 */
800 }
801 }
802
803 static void
vk_dynamic_graphics_state_init_ms(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_multisample_state * ms)804 vk_dynamic_graphics_state_init_ms(struct vk_dynamic_graphics_state *dst,
805 const BITSET_WORD *needed,
806 const struct vk_multisample_state *ms)
807 {
808 dst->ms.rasterization_samples = ms->rasterization_samples;
809 dst->ms.sample_mask = ms->sample_mask;
810 dst->ms.alpha_to_coverage_enable = ms->alpha_to_coverage_enable;
811 dst->ms.alpha_to_one_enable = ms->alpha_to_one_enable;
812 dst->ms.sample_locations_enable = ms->sample_locations_enable;
813
814 if (IS_NEEDED(MS_SAMPLE_LOCATIONS) && ms->sample_locations)
815 *dst->ms.sample_locations = *ms->sample_locations;
816 }
817
818 static void
vk_stencil_test_face_state_init(struct vk_stencil_test_face_state * face,const VkStencilOpState * info)819 vk_stencil_test_face_state_init(struct vk_stencil_test_face_state *face,
820 const VkStencilOpState *info)
821 {
822 face->op.fail = info->failOp;
823 face->op.pass = info->passOp;
824 face->op.depth_fail = info->depthFailOp;
825 face->op.compare = info->compareOp;
826 face->compare_mask = info->compareMask;
827 face->write_mask = info->writeMask;
828 face->reference = info->reference;
829 }
830
831 static void
vk_depth_stencil_state_init(struct vk_depth_stencil_state * ds,const BITSET_WORD * dynamic,const VkPipelineDepthStencilStateCreateInfo * ds_info)832 vk_depth_stencil_state_init(struct vk_depth_stencil_state *ds,
833 const BITSET_WORD *dynamic,
834 const VkPipelineDepthStencilStateCreateInfo *ds_info)
835 {
836 *ds = (struct vk_depth_stencil_state) {
837 .stencil.write_enable = true,
838 };
839 if (!ds_info)
840 return;
841
842 ds->depth.test_enable = ds_info->depthTestEnable;
843 ds->depth.write_enable = ds_info->depthWriteEnable;
844 ds->depth.compare_op = ds_info->depthCompareOp;
845 ds->depth.bounds_test.enable = ds_info->depthBoundsTestEnable;
846 ds->depth.bounds_test.min = ds_info->minDepthBounds;
847 ds->depth.bounds_test.max = ds_info->maxDepthBounds;
848 ds->stencil.test_enable = ds_info->stencilTestEnable;
849 vk_stencil_test_face_state_init(&ds->stencil.front, &ds_info->front);
850 vk_stencil_test_face_state_init(&ds->stencil.back, &ds_info->back);
851 }
852
853 static void
vk_dynamic_graphics_state_init_ds(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_depth_stencil_state * ds)854 vk_dynamic_graphics_state_init_ds(struct vk_dynamic_graphics_state *dst,
855 const BITSET_WORD *needed,
856 const struct vk_depth_stencil_state *ds)
857 {
858 dst->ds = *ds;
859 }
860
861 static bool
optimize_stencil_face(struct vk_stencil_test_face_state * face,VkCompareOp depthCompareOp,bool consider_write_mask)862 optimize_stencil_face(struct vk_stencil_test_face_state *face,
863 VkCompareOp depthCompareOp,
864 bool consider_write_mask)
865 {
866 /* If compareOp is ALWAYS then the stencil test will never fail and failOp
867 * will never happen. Set failOp to KEEP in this case.
868 */
869 if (face->op.compare == VK_COMPARE_OP_ALWAYS)
870 face->op.fail = VK_STENCIL_OP_KEEP;
871
872 /* If compareOp is NEVER or depthCompareOp is NEVER then one of the depth
873 * or stencil tests will fail and passOp will never happen.
874 */
875 if (face->op.compare == VK_COMPARE_OP_NEVER ||
876 depthCompareOp == VK_COMPARE_OP_NEVER)
877 face->op.pass = VK_STENCIL_OP_KEEP;
878
879 /* If compareOp is NEVER or depthCompareOp is ALWAYS then either the
880 * stencil test will fail or the depth test will pass. In either case,
881 * depthFailOp will never happen.
882 */
883 if (face->op.compare == VK_COMPARE_OP_NEVER ||
884 depthCompareOp == VK_COMPARE_OP_ALWAYS)
885 face->op.depth_fail = VK_STENCIL_OP_KEEP;
886
887 /* If the write mask is zero, nothing will be written to the stencil buffer
888 * so it's as if all operations are KEEP.
889 */
890 if (consider_write_mask && face->write_mask == 0) {
891 face->op.pass = VK_STENCIL_OP_KEEP;
892 face->op.fail = VK_STENCIL_OP_KEEP;
893 face->op.depth_fail = VK_STENCIL_OP_KEEP;
894 }
895
896 return face->op.fail != VK_STENCIL_OP_KEEP ||
897 face->op.depth_fail != VK_STENCIL_OP_KEEP ||
898 face->op.pass != VK_STENCIL_OP_KEEP;
899 }
900
901 void
vk_optimize_depth_stencil_state(struct vk_depth_stencil_state * ds,VkImageAspectFlags ds_aspects,bool consider_write_mask)902 vk_optimize_depth_stencil_state(struct vk_depth_stencil_state *ds,
903 VkImageAspectFlags ds_aspects,
904 bool consider_write_mask)
905 {
906 /* stencil.write_enable is a dummy right now that should always be true */
907 assert(ds->stencil.write_enable);
908
909 /* From the Vulkan 1.3.221 spec:
910 *
911 * "If there is no depth attachment then the depth test is skipped."
912 */
913 if (!(ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT))
914 ds->depth.test_enable = false;
915
916 /* From the Vulkan 1.3.221 spec:
917 *
918 * "...or if there is no stencil attachment, the coverage mask is
919 * unmodified by this operation."
920 */
921 if (!(ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT))
922 ds->stencil.test_enable = false;
923
924 /* If the depth test is disabled, we won't be writing anything. Make sure we
925 * treat the test as always passing later on as well.
926 */
927 if (!ds->depth.test_enable) {
928 ds->depth.write_enable = false;
929 ds->depth.compare_op = VK_COMPARE_OP_ALWAYS;
930 }
931
932 /* If the stencil test is disabled, we won't be writing anything. Make sure
933 * we treat the test as always passing later on as well.
934 */
935 if (!ds->stencil.test_enable) {
936 ds->stencil.write_enable = false;
937 ds->stencil.front.op.compare = VK_COMPARE_OP_ALWAYS;
938 ds->stencil.back.op.compare = VK_COMPARE_OP_ALWAYS;
939 }
940
941 /* If the stencil test is enabled and always fails, then we will never get
942 * to the depth test so we can just disable the depth test entirely.
943 */
944 if (ds->stencil.test_enable &&
945 ds->stencil.front.op.compare == VK_COMPARE_OP_NEVER &&
946 ds->stencil.back.op.compare == VK_COMPARE_OP_NEVER) {
947 ds->depth.test_enable = false;
948 ds->depth.write_enable = false;
949 }
950
951 /* If depthCompareOp is EQUAL then the value we would be writing to the
952 * depth buffer is the same as the value that's already there so there's no
953 * point in writing it.
954 */
955 if (ds->depth.compare_op == VK_COMPARE_OP_EQUAL)
956 ds->depth.write_enable = false;
957
958 /* If the stencil ops are such that we don't actually ever modify the
959 * stencil buffer, we should disable writes.
960 */
961 if (!optimize_stencil_face(&ds->stencil.front, ds->depth.compare_op,
962 consider_write_mask) &&
963 !optimize_stencil_face(&ds->stencil.back, ds->depth.compare_op,
964 consider_write_mask))
965 ds->stencil.write_enable = false;
966
967 /* If the depth test always passes and we never write out depth, that's the
968 * same as if the depth test is disabled entirely.
969 */
970 if (ds->depth.compare_op == VK_COMPARE_OP_ALWAYS && !ds->depth.write_enable)
971 ds->depth.test_enable = false;
972
973 /* If the stencil test always passes and we never write out stencil, that's
974 * the same as if the stencil test is disabled entirely.
975 */
976 if (ds->stencil.front.op.compare == VK_COMPARE_OP_ALWAYS &&
977 ds->stencil.back.op.compare == VK_COMPARE_OP_ALWAYS &&
978 !ds->stencil.write_enable)
979 ds->stencil.test_enable = false;
980 }
981
982 static void
vk_color_blend_state_init(struct vk_color_blend_state * cb,const BITSET_WORD * dynamic,const VkPipelineColorBlendStateCreateInfo * cb_info)983 vk_color_blend_state_init(struct vk_color_blend_state *cb,
984 const BITSET_WORD *dynamic,
985 const VkPipelineColorBlendStateCreateInfo *cb_info)
986 {
987 *cb = (struct vk_color_blend_state) {
988 .color_write_enables = BITFIELD_MASK(MESA_VK_MAX_COLOR_ATTACHMENTS),
989 };
990 if (!cb_info)
991 return;
992
993 cb->logic_op_enable = cb_info->logicOpEnable;
994 cb->logic_op = cb_info->logicOp;
995
996 assert(cb_info->attachmentCount <= MESA_VK_MAX_COLOR_ATTACHMENTS);
997 cb->attachment_count = cb_info->attachmentCount;
998 /* pAttachments is ignored if any of these is not set */
999 bool full_dynamic = IS_DYNAMIC(CB_BLEND_ENABLES) && IS_DYNAMIC(CB_BLEND_EQUATIONS) && IS_DYNAMIC(CB_WRITE_MASKS);
1000 for (uint32_t a = 0; a < cb_info->attachmentCount; a++) {
1001 const VkPipelineColorBlendAttachmentState *att = full_dynamic ? NULL : &cb_info->pAttachments[a];
1002
1003 cb->attachments[a] = (struct vk_color_blend_attachment_state) {
1004 .blend_enable = IS_DYNAMIC(CB_BLEND_ENABLES) || att->blendEnable,
1005 .src_color_blend_factor = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->srcColorBlendFactor,
1006 .dst_color_blend_factor = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->dstColorBlendFactor,
1007 .src_alpha_blend_factor = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->srcAlphaBlendFactor,
1008 .dst_alpha_blend_factor = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->dstAlphaBlendFactor,
1009 .write_mask = IS_DYNAMIC(CB_WRITE_MASKS) ? 0xf : att->colorWriteMask,
1010 .color_blend_op = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->colorBlendOp,
1011 .alpha_blend_op = IS_DYNAMIC(CB_BLEND_EQUATIONS) ? 0 : att->alphaBlendOp,
1012 };
1013 }
1014
1015 for (uint32_t i = 0; i < 4; i++)
1016 cb->blend_constants[i] = cb_info->blendConstants[i];
1017
1018 const VkPipelineColorWriteCreateInfoEXT *cw_info =
1019 vk_find_struct_const(cb_info->pNext, PIPELINE_COLOR_WRITE_CREATE_INFO_EXT);
1020 if (!IS_DYNAMIC(CB_COLOR_WRITE_ENABLES) && cw_info != NULL) {
1021 uint8_t color_write_enables = 0;
1022 assert(cb_info->attachmentCount == cw_info->attachmentCount);
1023 for (uint32_t a = 0; a < cw_info->attachmentCount; a++) {
1024 if (cw_info->pColorWriteEnables[a])
1025 color_write_enables |= BITFIELD_BIT(a);
1026 }
1027 cb->color_write_enables = color_write_enables;
1028 } else {
1029 cb->color_write_enables = BITFIELD_MASK(MESA_VK_MAX_COLOR_ATTACHMENTS);
1030 }
1031 }
1032
1033 static void
vk_input_attachment_location_state_init(struct vk_input_attachment_location_state * ial,const BITSET_WORD * dynamic,const VkRenderingInputAttachmentIndexInfoKHR * ial_info)1034 vk_input_attachment_location_state_init(struct vk_input_attachment_location_state *ial,
1035 const BITSET_WORD *dynamic,
1036 const VkRenderingInputAttachmentIndexInfoKHR *ial_info)
1037 {
1038 *ial = (struct vk_input_attachment_location_state) {
1039 .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
1040 .depth_att = MESA_VK_ATTACHMENT_UNUSED,
1041 .stencil_att = MESA_VK_ATTACHMENT_UNUSED,
1042 };
1043 if (!ial_info)
1044 return;
1045
1046 for (uint32_t a = 0; a < MIN2(ial_info->colorAttachmentCount,
1047 MESA_VK_MAX_COLOR_ATTACHMENTS); a++) {
1048 if (!ial_info->pColorAttachmentInputIndices) {
1049 ial->color_map[a] = a;
1050 } else if (ial_info->pColorAttachmentInputIndices[a] == VK_ATTACHMENT_UNUSED) {
1051 ial->color_map[a] = MESA_VK_ATTACHMENT_UNUSED;
1052 } else {
1053 ial->color_map[a] = ial_info->pColorAttachmentInputIndices[a];
1054 }
1055 }
1056 ial->depth_att = ial_info->pDepthInputAttachmentIndex != NULL ?
1057 *ial_info->pDepthInputAttachmentIndex : MESA_VK_ATTACHMENT_UNUSED;
1058 ial->stencil_att = ial_info->pStencilInputAttachmentIndex != NULL ?
1059 *ial_info->pStencilInputAttachmentIndex : MESA_VK_ATTACHMENT_UNUSED;
1060 }
1061
1062 static void
vk_color_attachment_location_state_init(struct vk_color_attachment_location_state * cal,const BITSET_WORD * dynamic,const VkRenderingAttachmentLocationInfoKHR * cal_info)1063 vk_color_attachment_location_state_init(struct vk_color_attachment_location_state *cal,
1064 const BITSET_WORD *dynamic,
1065 const VkRenderingAttachmentLocationInfoKHR *cal_info)
1066 {
1067 *cal = (struct vk_color_attachment_location_state) {
1068 .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
1069 };
1070 if (!cal_info)
1071 return;
1072
1073 for (uint32_t a = 0; a < MIN2(cal_info->colorAttachmentCount,
1074 MESA_VK_MAX_COLOR_ATTACHMENTS); a++) {
1075 cal->color_map[a] =
1076 cal_info->pColorAttachmentLocations == NULL ? a :
1077 cal_info->pColorAttachmentLocations[a] == VK_ATTACHMENT_UNUSED ?
1078 MESA_VK_ATTACHMENT_UNUSED : cal_info->pColorAttachmentLocations[a];
1079 }
1080 }
1081
1082 static void
vk_dynamic_graphics_state_init_cb(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_color_blend_state * cb)1083 vk_dynamic_graphics_state_init_cb(struct vk_dynamic_graphics_state *dst,
1084 const BITSET_WORD *needed,
1085 const struct vk_color_blend_state *cb)
1086 {
1087 dst->cb.logic_op_enable = cb->logic_op_enable;
1088 dst->cb.logic_op = cb->logic_op;
1089 dst->cb.color_write_enables = cb->color_write_enables;
1090 dst->cb.attachment_count = cb->attachment_count;
1091
1092 if (IS_NEEDED(CB_BLEND_ENABLES) ||
1093 IS_NEEDED(CB_BLEND_EQUATIONS) ||
1094 IS_NEEDED(CB_WRITE_MASKS)) {
1095 typed_memcpy(dst->cb.attachments, cb->attachments, cb->attachment_count);
1096 }
1097
1098 if (IS_NEEDED(CB_BLEND_CONSTANTS))
1099 typed_memcpy(dst->cb.blend_constants, cb->blend_constants, 4);
1100 }
1101
1102 static void
vk_dynamic_graphics_state_init_ial(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_input_attachment_location_state * ial)1103 vk_dynamic_graphics_state_init_ial(struct vk_dynamic_graphics_state *dst,
1104 const BITSET_WORD *needed,
1105 const struct vk_input_attachment_location_state *ial)
1106 {
1107 if (IS_NEEDED(INPUT_ATTACHMENT_MAP)) {
1108 typed_memcpy(dst->ial.color_map, ial->color_map, MESA_VK_MAX_COLOR_ATTACHMENTS);
1109 dst->ial.depth_att = ial->depth_att;
1110 dst->ial.stencil_att = ial->stencil_att;
1111 }
1112 }
1113
1114 static void
vk_dynamic_graphics_state_init_cal(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_color_attachment_location_state * cal)1115 vk_dynamic_graphics_state_init_cal(struct vk_dynamic_graphics_state *dst,
1116 const BITSET_WORD *needed,
1117 const struct vk_color_attachment_location_state *cal)
1118 {
1119 if (IS_NEEDED(COLOR_ATTACHMENT_MAP))
1120 typed_memcpy(dst->cal.color_map, cal->color_map, MESA_VK_MAX_COLOR_ATTACHMENTS);
1121 }
1122
1123 static void
vk_pipeline_flags_init(struct vk_graphics_pipeline_state * state,VkPipelineCreateFlags2KHR driver_rp_flags,bool has_driver_rp,const VkGraphicsPipelineCreateInfo * info,const BITSET_WORD * dynamic,VkGraphicsPipelineLibraryFlagsEXT lib)1124 vk_pipeline_flags_init(struct vk_graphics_pipeline_state *state,
1125 VkPipelineCreateFlags2KHR driver_rp_flags,
1126 bool has_driver_rp,
1127 const VkGraphicsPipelineCreateInfo *info,
1128 const BITSET_WORD *dynamic,
1129 VkGraphicsPipelineLibraryFlagsEXT lib)
1130 {
1131 VkPipelineCreateFlags2KHR valid_pipeline_flags = 0;
1132 VkPipelineCreateFlags2KHR valid_renderpass_flags = 0;
1133 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) {
1134 valid_renderpass_flags |=
1135 VK_PIPELINE_CREATE_2_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR |
1136 VK_PIPELINE_CREATE_2_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT;
1137 valid_pipeline_flags |=
1138 VK_PIPELINE_CREATE_2_RENDERING_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR |
1139 VK_PIPELINE_CREATE_2_RENDERING_FRAGMENT_DENSITY_MAP_ATTACHMENT_BIT_EXT;
1140 }
1141 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT) {
1142 valid_renderpass_flags |=
1143 VK_PIPELINE_CREATE_2_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT |
1144 VK_PIPELINE_CREATE_2_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT;
1145 if (!IS_DYNAMIC(ATTACHMENT_FEEDBACK_LOOP_ENABLE)) {
1146 valid_pipeline_flags |=
1147 VK_PIPELINE_CREATE_2_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT |
1148 VK_PIPELINE_CREATE_2_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT;
1149 }
1150 }
1151 const VkPipelineCreateFlags2KHR renderpass_flags =
1152 (has_driver_rp ? driver_rp_flags :
1153 vk_get_pipeline_rendering_flags(info)) & valid_renderpass_flags;
1154
1155 const VkPipelineCreateFlags2KHR pipeline_flags =
1156 vk_graphics_pipeline_create_flags(info) & valid_pipeline_flags;
1157
1158 bool pipeline_feedback_loop = pipeline_flags &
1159 (VK_PIPELINE_CREATE_2_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT |
1160 VK_PIPELINE_CREATE_2_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT);
1161
1162 bool renderpass_feedback_loop = renderpass_flags &
1163 (VK_PIPELINE_CREATE_2_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT |
1164 VK_PIPELINE_CREATE_2_DEPTH_STENCIL_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT);
1165
1166 state->pipeline_flags |= renderpass_flags | pipeline_flags;
1167 state->feedback_loop_not_input_only |=
1168 pipeline_feedback_loop || (!has_driver_rp && renderpass_feedback_loop);
1169 }
1170
1171 static void
vk_render_pass_state_init(struct vk_render_pass_state * rp,const struct vk_render_pass_state * old_rp,const struct vk_render_pass_state * driver_rp,const VkGraphicsPipelineCreateInfo * info,VkGraphicsPipelineLibraryFlagsEXT lib)1172 vk_render_pass_state_init(struct vk_render_pass_state *rp,
1173 const struct vk_render_pass_state *old_rp,
1174 const struct vk_render_pass_state *driver_rp,
1175 const VkGraphicsPipelineCreateInfo *info,
1176 VkGraphicsPipelineLibraryFlagsEXT lib)
1177 {
1178 /* If we already have render pass state and it has attachment info, then
1179 * it's complete and we don't need a new one. The one caveat here is that
1180 * we may need to add in some rendering flags.
1181 */
1182 if (old_rp != NULL && vk_render_pass_state_has_attachment_info(old_rp)) {
1183 *rp = *old_rp;
1184 return;
1185 }
1186
1187 *rp = (struct vk_render_pass_state) {
1188 .depth_attachment_format = VK_FORMAT_UNDEFINED,
1189 .stencil_attachment_format = VK_FORMAT_UNDEFINED,
1190 };
1191
1192 if (info->renderPass != VK_NULL_HANDLE && driver_rp != NULL) {
1193 *rp = *driver_rp;
1194 return;
1195 }
1196
1197 const VkPipelineRenderingCreateInfo *r_info =
1198 vk_get_pipeline_rendering_create_info(info);
1199
1200 if (r_info == NULL)
1201 return;
1202
1203 rp->view_mask = r_info->viewMask;
1204
1205 /* From the Vulkan 1.3.218 spec description of pre-rasterization state:
1206 *
1207 * "Fragment shader state is defined by:
1208 * ...
1209 * * VkRenderPass and subpass parameter
1210 * * The viewMask parameter of VkPipelineRenderingCreateInfo (formats
1211 * are ignored)"
1212 *
1213 * The description of fragment shader state contains identical text.
1214 *
1215 * If we have a render pass then we have full information. Even if we're
1216 * dynamic-rendering-only, the presence of a render pass means the
1217 * rendering info came from a vk_render_pass and is therefore complete.
1218 * Otherwise, all we can grab is the view mask and we have to leave the
1219 * rest for later.
1220 */
1221 if (info->renderPass == VK_NULL_HANDLE &&
1222 !(lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT)) {
1223 rp->attachments = MESA_VK_RP_ATTACHMENT_INFO_INVALID;
1224 return;
1225 }
1226
1227 assert(r_info->colorAttachmentCount <= MESA_VK_MAX_COLOR_ATTACHMENTS);
1228 rp->color_attachment_count = r_info->colorAttachmentCount;
1229 for (uint32_t i = 0; i < r_info->colorAttachmentCount; i++) {
1230 rp->color_attachment_formats[i] = r_info->pColorAttachmentFormats[i];
1231 if (r_info->pColorAttachmentFormats[i] != VK_FORMAT_UNDEFINED)
1232 rp->attachments |= MESA_VK_RP_ATTACHMENT_COLOR_BIT(i);
1233 }
1234
1235 rp->depth_attachment_format = r_info->depthAttachmentFormat;
1236 if (r_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED)
1237 rp->attachments |= MESA_VK_RP_ATTACHMENT_DEPTH_BIT;
1238
1239 rp->stencil_attachment_format = r_info->stencilAttachmentFormat;
1240 if (r_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED)
1241 rp->attachments |= MESA_VK_RP_ATTACHMENT_STENCIL_BIT;
1242
1243 const VkAttachmentSampleCountInfoAMD *asc_info =
1244 vk_get_pipeline_sample_count_info_amd(info);
1245 if (asc_info != NULL) {
1246 assert(asc_info->colorAttachmentCount == rp->color_attachment_count);
1247 for (uint32_t i = 0; i < asc_info->colorAttachmentCount; i++) {
1248 rp->color_attachment_samples[i] = asc_info->pColorAttachmentSamples[i];
1249 }
1250
1251 rp->depth_stencil_attachment_samples = asc_info->depthStencilAttachmentSamples;
1252 }
1253 }
1254
1255 static void
vk_dynamic_graphics_state_init_rp(struct vk_dynamic_graphics_state * dst,const BITSET_WORD * needed,const struct vk_render_pass_state * rp)1256 vk_dynamic_graphics_state_init_rp(struct vk_dynamic_graphics_state *dst,
1257 const BITSET_WORD *needed,
1258 const struct vk_render_pass_state *rp)
1259 {
1260 dst->rp.attachments = rp->attachments;
1261 }
1262
1263 #define FOREACH_STATE_GROUP(f) \
1264 f(MESA_VK_GRAPHICS_STATE_VERTEX_INPUT_BIT, \
1265 vk_vertex_input_state, vi); \
1266 f(MESA_VK_GRAPHICS_STATE_INPUT_ASSEMBLY_BIT, \
1267 vk_input_assembly_state, ia); \
1268 f(MESA_VK_GRAPHICS_STATE_TESSELLATION_BIT, \
1269 vk_tessellation_state, ts); \
1270 f(MESA_VK_GRAPHICS_STATE_VIEWPORT_BIT, \
1271 vk_viewport_state, vp); \
1272 f(MESA_VK_GRAPHICS_STATE_DISCARD_RECTANGLES_BIT, \
1273 vk_discard_rectangles_state, dr); \
1274 f(MESA_VK_GRAPHICS_STATE_RASTERIZATION_BIT, \
1275 vk_rasterization_state, rs); \
1276 f(MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT, \
1277 vk_fragment_shading_rate_state, fsr); \
1278 f(MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT, \
1279 vk_multisample_state, ms); \
1280 f(MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT, \
1281 vk_depth_stencil_state, ds); \
1282 f(MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT, \
1283 vk_color_blend_state, cb); \
1284 f(MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT, \
1285 vk_input_attachment_location_state, ial); \
1286 f(MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT, \
1287 vk_color_attachment_location_state, cal); \
1288 f(MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT, \
1289 vk_render_pass_state, rp);
1290
1291 static enum mesa_vk_graphics_state_groups
vk_graphics_pipeline_state_groups(const struct vk_graphics_pipeline_state * state)1292 vk_graphics_pipeline_state_groups(const struct vk_graphics_pipeline_state *state)
1293 {
1294 /* For now, we just validate dynamic state */
1295 enum mesa_vk_graphics_state_groups groups = 0;
1296
1297 #define FILL_HAS(STATE, type, s) \
1298 if (state->s != NULL) groups |= STATE
1299
1300 FOREACH_STATE_GROUP(FILL_HAS)
1301
1302 #undef FILL_HAS
1303
1304 return groups | fully_dynamic_state_groups(state->dynamic);
1305 }
1306
1307 void
vk_graphics_pipeline_get_state(const struct vk_graphics_pipeline_state * state,BITSET_WORD * set_state_out)1308 vk_graphics_pipeline_get_state(const struct vk_graphics_pipeline_state *state,
1309 BITSET_WORD *set_state_out)
1310 {
1311 /* For now, we just validate dynamic state */
1312 enum mesa_vk_graphics_state_groups groups = 0;
1313
1314 #define FILL_HAS(STATE, type, s) \
1315 if (state->s != NULL) groups |= STATE
1316
1317 FOREACH_STATE_GROUP(FILL_HAS)
1318
1319 #undef FILL_HAS
1320
1321 BITSET_DECLARE(set_state, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1322 get_dynamic_state_groups(set_state, groups);
1323 BITSET_ANDNOT(set_state, set_state, state->dynamic);
1324 memcpy(set_state_out, set_state, sizeof(set_state));
1325 }
1326
1327 static void
vk_graphics_pipeline_state_validate(const struct vk_graphics_pipeline_state * state)1328 vk_graphics_pipeline_state_validate(const struct vk_graphics_pipeline_state *state)
1329 {
1330 #ifndef NDEBUG
1331 /* For now, we just validate dynamic state */
1332 enum mesa_vk_graphics_state_groups groups =
1333 vk_graphics_pipeline_state_groups(state);
1334 validate_dynamic_state_groups(state->dynamic, groups);
1335 #endif
1336 }
1337
1338 static bool
may_have_rasterization(const struct vk_graphics_pipeline_state * state,const BITSET_WORD * dynamic,const VkGraphicsPipelineCreateInfo * info)1339 may_have_rasterization(const struct vk_graphics_pipeline_state *state,
1340 const BITSET_WORD *dynamic,
1341 const VkGraphicsPipelineCreateInfo *info)
1342 {
1343 if (state->rs) {
1344 /* We default rasterizer_discard_enable to false when dynamic */
1345 return !state->rs->rasterizer_discard_enable;
1346 } else {
1347 return IS_DYNAMIC(RS_RASTERIZER_DISCARD_ENABLE) ||
1348 !info->pRasterizationState->rasterizerDiscardEnable;
1349 }
1350 }
1351
1352 VkResult
vk_graphics_pipeline_state_fill(const struct vk_device * device,struct vk_graphics_pipeline_state * state,const VkGraphicsPipelineCreateInfo * info,const struct vk_render_pass_state * driver_rp,VkPipelineCreateFlags2KHR driver_rp_flags,struct vk_graphics_pipeline_all_state * all,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope,void ** alloc_ptr_out)1353 vk_graphics_pipeline_state_fill(const struct vk_device *device,
1354 struct vk_graphics_pipeline_state *state,
1355 const VkGraphicsPipelineCreateInfo *info,
1356 const struct vk_render_pass_state *driver_rp,
1357 VkPipelineCreateFlags2KHR driver_rp_flags,
1358 struct vk_graphics_pipeline_all_state *all,
1359 const VkAllocationCallbacks *alloc,
1360 VkSystemAllocationScope scope,
1361 void **alloc_ptr_out)
1362 {
1363 vk_graphics_pipeline_state_validate(state);
1364
1365 BITSET_DECLARE(dynamic, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1366 vk_get_dynamic_graphics_states(dynamic, info->pDynamicState);
1367
1368 /*
1369 * First, figure out which library-level shader/state groups we need
1370 */
1371
1372 VkGraphicsPipelineLibraryFlagsEXT lib;
1373 const VkGraphicsPipelineLibraryCreateInfoEXT *gpl_info =
1374 vk_find_struct_const(info->pNext, GRAPHICS_PIPELINE_LIBRARY_CREATE_INFO_EXT);
1375 const VkPipelineLibraryCreateInfoKHR *lib_info =
1376 vk_find_struct_const(info->pNext, PIPELINE_LIBRARY_CREATE_INFO_KHR);
1377
1378 VkPipelineCreateFlags2KHR pipeline_flags = vk_graphics_pipeline_create_flags(info);
1379
1380 VkShaderStageFlagBits allowed_stages;
1381 if (!(pipeline_flags & VK_PIPELINE_CREATE_2_LIBRARY_BIT_KHR)) {
1382 allowed_stages = VK_SHADER_STAGE_ALL_GRAPHICS |
1383 VK_SHADER_STAGE_TASK_BIT_EXT |
1384 VK_SHADER_STAGE_MESH_BIT_EXT;
1385 } else if (gpl_info) {
1386 allowed_stages = 0;
1387
1388 /* If we're creating a pipeline library without pre-rasterization,
1389 * discard all the associated stages.
1390 */
1391 if (gpl_info->flags &
1392 VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT) {
1393 allowed_stages |= (VK_SHADER_STAGE_VERTEX_BIT |
1394 VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1395 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT |
1396 VK_SHADER_STAGE_GEOMETRY_BIT |
1397 VK_SHADER_STAGE_TASK_BIT_EXT |
1398 VK_SHADER_STAGE_MESH_BIT_EXT);
1399 }
1400
1401 /* If we're creating a pipeline library without fragment shader,
1402 * discard that stage.
1403 */
1404 if (gpl_info->flags &
1405 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT)
1406 allowed_stages |= VK_SHADER_STAGE_FRAGMENT_BIT;
1407 } else {
1408 /* VkGraphicsPipelineLibraryCreateInfoEXT was omitted, flags should
1409 * be assumed to be empty and therefore no shader stage should be
1410 * considered.
1411 */
1412 allowed_stages = 0;
1413 }
1414
1415 for (uint32_t i = 0; i < info->stageCount; i++) {
1416 state->shader_stages |= info->pStages[i].stage & allowed_stages;
1417 }
1418
1419 /* In case we return early */
1420 if (alloc_ptr_out != NULL)
1421 *alloc_ptr_out = NULL;
1422
1423 if (gpl_info) {
1424 lib = gpl_info->flags;
1425 } else if ((lib_info && lib_info->libraryCount > 0) ||
1426 (pipeline_flags & VK_PIPELINE_CREATE_2_LIBRARY_BIT_KHR)) {
1427 /*
1428 * From the Vulkan 1.3.210 spec:
1429 * "If this structure is omitted, and either VkGraphicsPipelineCreateInfo::flags
1430 * includes VK_PIPELINE_CREATE_LIBRARY_BIT_KHR or the
1431 * VkGraphicsPipelineCreateInfo::pNext chain includes a
1432 * VkPipelineLibraryCreateInfoKHR structure with a libraryCount greater than 0,
1433 * it is as if flags is 0. Otherwise if this structure is omitted, it is as if
1434 * flags includes all possible subsets of the graphics pipeline."
1435 */
1436 lib = 0;
1437 } else {
1438 /* We're building a complete pipeline. From the Vulkan 1.3.218 spec:
1439 *
1440 * "A complete graphics pipeline always includes pre-rasterization
1441 * shader state, with other subsets included depending on that state.
1442 * If the pre-rasterization shader state includes a vertex shader,
1443 * then vertex input state is included in a complete graphics
1444 * pipeline. If the value of
1445 * VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable in
1446 * the pre-rasterization shader state is VK_FALSE or the
1447 * VK_DYNAMIC_STATE_RASTERIZER_DISCARD_ENABLE dynamic state is
1448 * enabled fragment shader state and fragment output interface state
1449 * is included in a complete graphics pipeline."
1450 */
1451 lib = VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT;
1452
1453 if (state->shader_stages & VK_SHADER_STAGE_VERTEX_BIT)
1454 lib |= VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT;
1455
1456 if (may_have_rasterization(state, dynamic, info)) {
1457 lib |= VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT;
1458 lib |= VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT;
1459 }
1460 }
1461
1462 /*
1463 * Next, turn those into individual states. Among other things, this
1464 * de-duplicates things like FSR and multisample state which appear in
1465 * multiple library groups.
1466 */
1467
1468 enum mesa_vk_graphics_state_groups needs = 0;
1469 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_VERTEX_INPUT_INTERFACE_BIT_EXT) {
1470 needs |= MESA_VK_GRAPHICS_STATE_VERTEX_INPUT_BIT;
1471 needs |= MESA_VK_GRAPHICS_STATE_INPUT_ASSEMBLY_BIT;
1472 }
1473
1474 /* Other stuff potentially depends on this so gather it early */
1475 struct vk_render_pass_state rp;
1476 if (lib & (VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT |
1477 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT |
1478 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT)) {
1479 vk_render_pass_state_init(&rp, state->rp, driver_rp, info, lib);
1480
1481 needs |= MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT;
1482
1483 /* If the old state was incomplete but the new one isn't, set state->rp
1484 * to NULL so it gets replaced with the new version.
1485 */
1486 if (state->rp != NULL &&
1487 !vk_render_pass_state_has_attachment_info(state->rp) &&
1488 !vk_render_pass_state_has_attachment_info(&rp))
1489 state->rp = NULL;
1490 }
1491
1492 if (lib & (VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT |
1493 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT)) {
1494 vk_pipeline_flags_init(state, driver_rp_flags, !!driver_rp, info, dynamic, lib);
1495 }
1496
1497 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_PRE_RASTERIZATION_SHADERS_BIT_EXT) {
1498 /* From the Vulkan 1.3.218 spec:
1499 *
1500 * VUID-VkGraphicsPipelineCreateInfo-stage-02096
1501 *
1502 * "If the pipeline is being created with pre-rasterization shader
1503 * state the stage member of one element of pStages must be either
1504 * VK_SHADER_STAGE_VERTEX_BIT or VK_SHADER_STAGE_MESH_BIT_EXT"
1505 */
1506 assert(state->shader_stages & (VK_SHADER_STAGE_VERTEX_BIT |
1507 VK_SHADER_STAGE_MESH_BIT_EXT));
1508
1509 if (state->shader_stages & (VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
1510 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT))
1511 needs |= MESA_VK_GRAPHICS_STATE_TESSELLATION_BIT;
1512
1513 if (may_have_rasterization(state, dynamic, info))
1514 needs |= MESA_VK_GRAPHICS_STATE_VIEWPORT_BIT;
1515
1516 needs |= MESA_VK_GRAPHICS_STATE_DISCARD_RECTANGLES_BIT;
1517 needs |= MESA_VK_GRAPHICS_STATE_RASTERIZATION_BIT;
1518 needs |= MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT;
1519 }
1520
1521 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT) {
1522 needs |= MESA_VK_GRAPHICS_STATE_FRAGMENT_SHADING_RATE_BIT;
1523
1524 /* From the Vulkan 1.3.218 spec:
1525 *
1526 * "Fragment shader state is defined by:
1527 * ...
1528 * - VkPipelineMultisampleStateCreateInfo if sample shading is
1529 * enabled or renderpass is not VK_NULL_HANDLE"
1530 *
1531 * and
1532 *
1533 * VUID-VkGraphicsPipelineCreateInfo-pMultisampleState-06629
1534 *
1535 * "If the pipeline is being created with fragment shader state
1536 * pMultisampleState must be NULL or a valid pointer to a valid
1537 * VkPipelineMultisampleStateCreateInfo structure"
1538 *
1539 * so we can reliably detect when to include it based on the
1540 * pMultisampleState pointer.
1541 */
1542 if (info->pMultisampleState != NULL)
1543 needs |= MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT;
1544
1545 /* From the Vulkan 1.3.218 spec:
1546 *
1547 * VUID-VkGraphicsPipelineCreateInfo-renderPass-06043
1548 *
1549 * "If renderPass is not VK_NULL_HANDLE, the pipeline is being
1550 * created with fragment shader state, and subpass uses a
1551 * depth/stencil attachment, pDepthStencilState must be a valid
1552 * pointer to a valid VkPipelineDepthStencilStateCreateInfo
1553 * structure"
1554 *
1555 * VUID-VkGraphicsPipelineCreateInfo-renderPass-06053
1556 *
1557 * "If renderPass is VK_NULL_HANDLE, the pipeline is being created
1558 * with fragment shader state and fragment output interface state,
1559 * and either of VkPipelineRenderingCreateInfo::depthAttachmentFormat
1560 * or VkPipelineRenderingCreateInfo::stencilAttachmentFormat are not
1561 * VK_FORMAT_UNDEFINED, pDepthStencilState must be a valid pointer to
1562 * a valid VkPipelineDepthStencilStateCreateInfo structure"
1563 *
1564 * VUID-VkGraphicsPipelineCreateInfo-renderPass-06590
1565 *
1566 * "If renderPass is VK_NULL_HANDLE and the pipeline is being created
1567 * with fragment shader state but not fragment output interface
1568 * state, pDepthStencilState must be a valid pointer to a valid
1569 * VkPipelineDepthStencilStateCreateInfo structure"
1570 *
1571 * In the first case, we'll have a real set of aspects in rp. In the
1572 * second case, where we have both fragment shader and fragment output
1573 * state, we will also have a valid set of aspects. In the third case
1574 * where we only have fragment shader state and no render pass, the
1575 * vk_render_pass_state will be incomplete.
1576 */
1577 if (!vk_render_pass_state_has_attachment_info(&rp) ||
1578 (rp.attachments & (MESA_VK_RP_ATTACHMENT_DEPTH_BIT |
1579 MESA_VK_RP_ATTACHMENT_STENCIL_BIT)))
1580 needs |= MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT;
1581
1582 needs |= MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT;
1583 }
1584
1585 if (lib & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT) {
1586 if (rp.attachments & MESA_VK_RP_ATTACHMENT_ANY_COLOR_BITS)
1587 needs |= MESA_VK_GRAPHICS_STATE_COLOR_BLEND_BIT;
1588
1589 needs |= MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT;
1590
1591 needs |= MESA_VK_GRAPHICS_STATE_COLOR_ATTACHMENT_MAP_BIT;
1592 }
1593
1594 /*
1595 * Next, Filter off any states we already have.
1596 */
1597
1598 #define FILTER_NEEDS(STATE, type, s) \
1599 if (state->s != NULL) needs &= ~STATE
1600
1601 FOREACH_STATE_GROUP(FILTER_NEEDS)
1602
1603 #undef FILTER_NEEDS
1604
1605 /* Filter dynamic state down to just what we're adding */
1606 BITSET_DECLARE(dynamic_filter, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1607 get_dynamic_state_groups(dynamic_filter, needs);
1608
1609 /* Attachment feedback loop state is part of the renderpass state in mesa
1610 * because attachment feedback loops can also come from the render pass,
1611 * but in Vulkan it is part of the fragment output interface. The
1612 * renderpass state also exists, possibly in an incomplete state, in other
1613 * stages for things like the view mask, but it does not contain the
1614 * feedback loop flags. In those other stages we have to ignore
1615 * VK_DYNAMIC_STATE_ATTACHMENT_FEEDBACK_LOOP_ENABLE_EXT, even though it is
1616 * part of a state group that exists in those stages.
1617 */
1618 if (!(lib &
1619 VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_OUTPUT_INTERFACE_BIT_EXT)) {
1620 BITSET_CLEAR(dynamic_filter,
1621 MESA_VK_DYNAMIC_ATTACHMENT_FEEDBACK_LOOP_ENABLE);
1622 }
1623
1624 BITSET_AND(dynamic, dynamic, dynamic_filter);
1625
1626 /* And add it in */
1627 BITSET_OR(state->dynamic, state->dynamic, dynamic);
1628
1629 /*
1630 * If a state is fully dynamic, we don't need to even allocate them. Do
1631 * this after we've filtered dynamic state because we still want them to
1632 * show up in the dynamic state but don't want the actual state.
1633 */
1634 needs &= ~fully_dynamic_state_groups(state->dynamic);
1635
1636 /* If we don't need to set up any new states, bail early */
1637 if (needs == 0)
1638 return VK_SUCCESS;
1639
1640 /*
1641 * Now, ensure that we have space for each of the states we're going to
1642 * fill. If all != NULL, we'll pull from that. Otherwise, we need to
1643 * allocate memory.
1644 */
1645
1646 VK_MULTIALLOC(ma);
1647
1648 #define ENSURE_STATE_IF_NEEDED(STATE, type, s) \
1649 struct type *new_##s = NULL; \
1650 if (needs & STATE) { \
1651 if (all == NULL) { \
1652 vk_multialloc_add(&ma, &new_##s, struct type, 1); \
1653 } else { \
1654 new_##s = &all->s; \
1655 } \
1656 }
1657
1658 FOREACH_STATE_GROUP(ENSURE_STATE_IF_NEEDED)
1659
1660 #undef ENSURE_STATE_IF_NEEDED
1661
1662 /* Sample locations are a bit special. We don't want to waste the memory
1663 * for 64 floats if we don't need to. Also, we set up standard sample
1664 * locations if no user-provided sample locations are available.
1665 */
1666 const VkPipelineSampleLocationsStateCreateInfoEXT *sl_info = NULL;
1667 struct vk_sample_locations_state *new_sl = NULL;
1668 if (needs & MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT) {
1669 if (info->pMultisampleState)
1670 sl_info = vk_find_struct_const(info->pMultisampleState->pNext,
1671 PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT);
1672 if (needs_sample_locations_state(dynamic, sl_info)) {
1673 if (all == NULL) {
1674 vk_multialloc_add(&ma, &new_sl, struct vk_sample_locations_state, 1);
1675 } else {
1676 new_sl = &all->ms_sample_locations;
1677 }
1678 }
1679 }
1680
1681 /*
1682 * Allocate memory, if needed
1683 */
1684
1685 if (ma.size > 0) {
1686 assert(all == NULL);
1687 *alloc_ptr_out = vk_multialloc_alloc2(&ma, &device->alloc, alloc, scope);
1688 if (*alloc_ptr_out == NULL)
1689 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
1690 }
1691
1692 /*
1693 * Create aliases for various input infos so we can use or FOREACH macro
1694 */
1695
1696 #define INFO_ALIAS(_State, s) \
1697 const VkPipeline##_State##StateCreateInfo *s##_info = info->p##_State##State
1698
1699 INFO_ALIAS(VertexInput, vi);
1700 INFO_ALIAS(InputAssembly, ia);
1701 INFO_ALIAS(Tessellation, ts);
1702 INFO_ALIAS(Viewport, vp);
1703 INFO_ALIAS(Rasterization, rs);
1704 INFO_ALIAS(Multisample, ms);
1705 INFO_ALIAS(DepthStencil, ds);
1706 INFO_ALIAS(ColorBlend, cb);
1707
1708 #undef INFO_ALIAS
1709
1710 const VkPipelineDiscardRectangleStateCreateInfoEXT *dr_info =
1711 vk_find_struct_const(info->pNext, PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT);
1712
1713 const VkPipelineFragmentShadingRateStateCreateInfoKHR *fsr_info =
1714 vk_find_struct_const(info->pNext, PIPELINE_FRAGMENT_SHADING_RATE_STATE_CREATE_INFO_KHR);
1715
1716 const VkRenderingInputAttachmentIndexInfoKHR *ial_info =
1717 vk_find_struct_const(info->pNext, RENDERING_INPUT_ATTACHMENT_INDEX_INFO_KHR);
1718 const VkRenderingAttachmentLocationInfoKHR *cal_info =
1719 vk_find_struct_const(info->pNext, RENDERING_ATTACHMENT_LOCATION_INFO_KHR);
1720
1721 /*
1722 * Finally, fill out all the states
1723 */
1724
1725 #define INIT_STATE_IF_NEEDED(STATE, type, s) \
1726 if (needs & STATE) { \
1727 type##_init(new_##s, dynamic, s##_info); \
1728 state->s = new_##s; \
1729 }
1730
1731 /* render pass state is special and we just copy it */
1732 #define vk_render_pass_state_init(s, d, i) *s = rp
1733
1734 FOREACH_STATE_GROUP(INIT_STATE_IF_NEEDED)
1735
1736 #undef vk_render_pass_state_init
1737 #undef INIT_STATE_IF_NEEDED
1738
1739 if (needs & MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT) {
1740 vk_multisample_sample_locations_state_init(new_ms, new_sl, dynamic,
1741 ms_info, sl_info);
1742 }
1743
1744 return VK_SUCCESS;
1745 }
1746
1747 #undef IS_DYNAMIC
1748 #undef IS_NEEDED
1749
1750 void
vk_graphics_pipeline_state_merge(struct vk_graphics_pipeline_state * dst,const struct vk_graphics_pipeline_state * src)1751 vk_graphics_pipeline_state_merge(struct vk_graphics_pipeline_state *dst,
1752 const struct vk_graphics_pipeline_state *src)
1753 {
1754 vk_graphics_pipeline_state_validate(dst);
1755 vk_graphics_pipeline_state_validate(src);
1756
1757 BITSET_OR(dst->dynamic, dst->dynamic, src->dynamic);
1758
1759 dst->shader_stages |= src->shader_stages;
1760
1761 dst->pipeline_flags |= src->pipeline_flags;
1762 dst->feedback_loop_not_input_only |= src->feedback_loop_not_input_only;
1763
1764 /* Render pass state needs special care because a render pass state may be
1765 * incomplete (view mask only). See vk_render_pass_state_init().
1766 */
1767 if (dst->rp != NULL && src->rp != NULL &&
1768 !vk_render_pass_state_has_attachment_info(dst->rp) &&
1769 vk_render_pass_state_has_attachment_info(src->rp))
1770 dst->rp = src->rp;
1771
1772 #define MERGE(STATE, type, state) \
1773 if (dst->state == NULL && src->state != NULL) dst->state = src->state;
1774
1775 FOREACH_STATE_GROUP(MERGE)
1776
1777 #undef MERGE
1778 }
1779
1780 static bool
is_group_all_dynamic(const struct vk_graphics_pipeline_state * state,enum mesa_vk_graphics_state_groups group)1781 is_group_all_dynamic(const struct vk_graphics_pipeline_state *state,
1782 enum mesa_vk_graphics_state_groups group)
1783 {
1784 /* Render pass is a bit special, because it contains always-static state
1785 * (e.g. the view mask). It's never all dynamic.
1786 */
1787 if (group == MESA_VK_GRAPHICS_STATE_RENDER_PASS_BIT)
1788 return false;
1789
1790 BITSET_DECLARE(group_state, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1791 BITSET_DECLARE(dynamic_state, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1792 get_dynamic_state_groups(group_state, group);
1793 BITSET_AND(dynamic_state, group_state, state->dynamic);
1794 return BITSET_EQUAL(dynamic_state, group_state);
1795 }
1796
1797 VkResult
vk_graphics_pipeline_state_copy(const struct vk_device * device,struct vk_graphics_pipeline_state * state,const struct vk_graphics_pipeline_state * old_state,const VkAllocationCallbacks * alloc,VkSystemAllocationScope scope,void ** alloc_ptr_out)1798 vk_graphics_pipeline_state_copy(const struct vk_device *device,
1799 struct vk_graphics_pipeline_state *state,
1800 const struct vk_graphics_pipeline_state *old_state,
1801 const VkAllocationCallbacks *alloc,
1802 VkSystemAllocationScope scope,
1803 void **alloc_ptr_out)
1804 {
1805 vk_graphics_pipeline_state_validate(old_state);
1806
1807 VK_MULTIALLOC(ma);
1808
1809 #define ENSURE_STATE_IF_NEEDED(STATE, type, s) \
1810 struct type *new_##s = NULL; \
1811 if (old_state->s && !is_group_all_dynamic(state, STATE)) { \
1812 vk_multialloc_add(&ma, &new_##s, struct type, 1); \
1813 }
1814
1815 FOREACH_STATE_GROUP(ENSURE_STATE_IF_NEEDED)
1816
1817 #undef ENSURE_STATE_IF_NEEDED
1818
1819 /* Sample locations are a bit special. */
1820 struct vk_sample_locations_state *new_sample_locations = NULL;
1821 if (old_state->ms && old_state->ms->sample_locations &&
1822 !BITSET_TEST(old_state->dynamic, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS)) {
1823 assert(old_state->ms->sample_locations);
1824 vk_multialloc_add(&ma, &new_sample_locations,
1825 struct vk_sample_locations_state, 1);
1826 }
1827
1828 if (ma.size > 0) {
1829 *alloc_ptr_out = vk_multialloc_alloc2(&ma, &device->alloc, alloc, scope);
1830 if (*alloc_ptr_out == NULL)
1831 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
1832 }
1833
1834 if (new_sample_locations) {
1835 *new_sample_locations = *old_state->ms->sample_locations;
1836 }
1837
1838 #define COPY_STATE_IF_NEEDED(STATE, type, s) \
1839 if (new_##s) { \
1840 *new_##s = *old_state->s; \
1841 } \
1842 state->s = new_##s;
1843
1844 FOREACH_STATE_GROUP(COPY_STATE_IF_NEEDED)
1845
1846 if (new_ms) {
1847 new_ms->sample_locations = new_sample_locations;
1848 }
1849
1850 state->shader_stages = old_state->shader_stages;
1851 BITSET_COPY(state->dynamic, old_state->dynamic);
1852
1853 #undef COPY_STATE_IF_NEEDED
1854
1855 state->pipeline_flags = old_state->pipeline_flags;
1856 state->feedback_loop_not_input_only =
1857 old_state->feedback_loop_not_input_only;
1858
1859 vk_graphics_pipeline_state_validate(state);
1860 return VK_SUCCESS;
1861 }
1862
1863 static const struct vk_dynamic_graphics_state vk_default_dynamic_graphics_state = {
1864 .rs = {
1865 .line = {
1866 .width = 1.0f,
1867 },
1868 },
1869 .fsr = {
1870 .fragment_size = {1u, 1u},
1871 .combiner_ops = {
1872 VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR,
1873 VK_FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_KHR,
1874 },
1875 },
1876 .ds = {
1877 .depth = {
1878 .bounds_test = {
1879 .min = 0.0f,
1880 .max = 1.0f,
1881 },
1882 },
1883 .stencil = {
1884 .write_enable = true,
1885 .front = {
1886 .compare_mask = -1,
1887 .write_mask = -1,
1888 },
1889 .back = {
1890 .compare_mask = -1,
1891 .write_mask = -1,
1892 },
1893 },
1894 },
1895 .cb = {
1896 .color_write_enables = 0xffu,
1897 .attachment_count = MESA_VK_MAX_COLOR_ATTACHMENTS,
1898 },
1899 .ial = {
1900 .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
1901 .depth_att = MESA_VK_ATTACHMENT_UNUSED,
1902 .stencil_att = MESA_VK_ATTACHMENT_UNUSED,
1903 },
1904 .cal = {
1905 .color_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
1906 },
1907 };
1908
1909 void
vk_dynamic_graphics_state_init(struct vk_dynamic_graphics_state * dyn)1910 vk_dynamic_graphics_state_init(struct vk_dynamic_graphics_state *dyn)
1911 {
1912 *dyn = vk_default_dynamic_graphics_state;
1913 }
1914
1915 void
vk_dynamic_graphics_state_clear(struct vk_dynamic_graphics_state * dyn)1916 vk_dynamic_graphics_state_clear(struct vk_dynamic_graphics_state *dyn)
1917 {
1918 struct vk_vertex_input_state *vi = dyn->vi;
1919 struct vk_sample_locations_state *sl = dyn->ms.sample_locations;
1920
1921 *dyn = vk_default_dynamic_graphics_state;
1922
1923 if (vi != NULL) {
1924 memset(vi, 0, sizeof(*vi));
1925 dyn->vi = vi;
1926 }
1927
1928 if (sl != NULL) {
1929 memset(sl, 0, sizeof(*sl));
1930 dyn->ms.sample_locations = sl;
1931 }
1932 }
1933
1934 void
vk_dynamic_graphics_state_fill(struct vk_dynamic_graphics_state * dyn,const struct vk_graphics_pipeline_state * p)1935 vk_dynamic_graphics_state_fill(struct vk_dynamic_graphics_state *dyn,
1936 const struct vk_graphics_pipeline_state *p)
1937 {
1938 /* This funciton (and the individual vk_dynamic_graphics_state_init_*
1939 * functions it calls) are a bit sloppy. Instead of checking every single
1940 * bit, we just copy everything and set the bits the right way at the end
1941 * based on what groups we actually had.
1942 */
1943 enum mesa_vk_graphics_state_groups groups = 0;
1944
1945 BITSET_DECLARE(needed, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
1946 BITSET_COPY(needed, p->dynamic);
1947 BITSET_NOT(needed);
1948
1949 /* We only want to copy these if the driver has filled out the relevant
1950 * pointer in the dynamic state struct. If not, they don't support them
1951 * as dynamic state and we should leave them alone.
1952 */
1953 if (dyn->vi == NULL)
1954 BITSET_CLEAR(needed, MESA_VK_DYNAMIC_VI);
1955 if (dyn->ms.sample_locations == NULL)
1956 BITSET_CLEAR(needed, MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS);
1957
1958 #define INIT_DYNAMIC_STATE(STATE, type, s) \
1959 if (p->s != NULL) { \
1960 vk_dynamic_graphics_state_init_##s(dyn, needed, p->s); \
1961 groups |= STATE; \
1962 }
1963
1964 FOREACH_STATE_GROUP(INIT_DYNAMIC_STATE);
1965
1966 #undef INIT_DYNAMIC_STATE
1967
1968 /* Feedback loop state is weird: implicit feedback loops from the
1969 * renderpass and dynamically-enabled feedback loops can in theory both be
1970 * enabled independently, so we can't just use one field; instead drivers
1971 * have to OR the pipeline state (in vk_render_pass_state::pipeline_flags)
1972 * and dynamic state. Due to this it isn't worth tracking
1973 * implicit render pass flags vs. pipeline flags in the pipeline state, and
1974 * we just combine the two in vk_render_pass_flags_init() and don't bother
1975 * setting the dynamic state from the pipeline here, instead just making
1976 * sure the dynamic state is reset to 0 when feedback loop state is static.
1977 */
1978 dyn->feedback_loops = 0;
1979
1980 get_dynamic_state_groups(dyn->set, groups);
1981
1982 /* Vertex input state is always included in a complete pipeline. If p->vi
1983 * is NULL, that means that it has been precompiled by the driver, but we
1984 * should still track vi_bindings_valid.
1985 */
1986 BITSET_SET(dyn->set, MESA_VK_DYNAMIC_VI_BINDINGS_VALID);
1987
1988 /* If the pipeline doesn't render any color attachments, we should still
1989 * keep track of the fact that it writes 0 attachments, even though none of
1990 * the other blend states will be initialized. Normally this would be
1991 * initialized with the other blend states.
1992 */
1993 if (!p->rp || !(p->rp->attachments & MESA_VK_RP_ATTACHMENT_ANY_COLOR_BITS)) {
1994 dyn->cb.attachment_count = 0;
1995 BITSET_SET(dyn->set, MESA_VK_DYNAMIC_CB_ATTACHMENT_COUNT);
1996 }
1997
1998 /* Mask off all but the groups we actually found */
1999 BITSET_AND(dyn->set, dyn->set, needed);
2000 }
2001
2002 #define SET_DYN_VALUE(dst, STATE, state, value) do { \
2003 if (!BITSET_TEST((dst)->set, MESA_VK_DYNAMIC_##STATE) || \
2004 (dst)->state != (value)) { \
2005 (dst)->state = (value); \
2006 assert((dst)->state == (value)); \
2007 BITSET_SET(dst->set, MESA_VK_DYNAMIC_##STATE); \
2008 BITSET_SET(dst->dirty, MESA_VK_DYNAMIC_##STATE); \
2009 } \
2010 } while(0)
2011
2012 #define SET_DYN_BOOL(dst, STATE, state, value) \
2013 SET_DYN_VALUE(dst, STATE, state, (bool)value);
2014
2015 #define SET_DYN_ARRAY(dst, STATE, state, start, count, src) do { \
2016 assert(start + count <= ARRAY_SIZE((dst)->state)); \
2017 STATIC_ASSERT(sizeof(*(dst)->state) == sizeof(*(src))); \
2018 const size_t __state_size = sizeof(*(dst)->state) * (count); \
2019 if (!BITSET_TEST((dst)->set, MESA_VK_DYNAMIC_##STATE) || \
2020 memcmp((dst)->state + start, src, __state_size)) { \
2021 memcpy((dst)->state + start, src, __state_size); \
2022 BITSET_SET(dst->set, MESA_VK_DYNAMIC_##STATE); \
2023 BITSET_SET(dst->dirty, MESA_VK_DYNAMIC_##STATE); \
2024 } \
2025 } while(0)
2026
2027 void
vk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state * dst,const struct vk_dynamic_graphics_state * src)2028 vk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state *dst,
2029 const struct vk_dynamic_graphics_state *src)
2030 {
2031 #define IS_SET_IN_SRC(STATE) \
2032 BITSET_TEST(src->set, MESA_VK_DYNAMIC_##STATE)
2033
2034 #define COPY_MEMBER(STATE, state) \
2035 SET_DYN_VALUE(dst, STATE, state, src->state)
2036
2037 #define COPY_ARRAY(STATE, state, count) \
2038 SET_DYN_ARRAY(dst, STATE, state, 0, count, src->state)
2039
2040 #define COPY_IF_SET(STATE, state) \
2041 if (IS_SET_IN_SRC(STATE)) SET_DYN_VALUE(dst, STATE, state, src->state)
2042
2043 if (IS_SET_IN_SRC(VI)) {
2044 assert(dst->vi != NULL);
2045 COPY_MEMBER(VI, vi->bindings_valid);
2046 u_foreach_bit(b, src->vi->bindings_valid) {
2047 COPY_MEMBER(VI, vi->bindings[b].stride);
2048 COPY_MEMBER(VI, vi->bindings[b].input_rate);
2049 COPY_MEMBER(VI, vi->bindings[b].divisor);
2050 }
2051 COPY_MEMBER(VI, vi->attributes_valid);
2052 u_foreach_bit(a, src->vi->attributes_valid) {
2053 COPY_MEMBER(VI, vi->attributes[a].binding);
2054 COPY_MEMBER(VI, vi->attributes[a].format);
2055 COPY_MEMBER(VI, vi->attributes[a].offset);
2056 }
2057 }
2058
2059 if (IS_SET_IN_SRC(VI_BINDINGS_VALID))
2060 COPY_MEMBER(VI_BINDINGS_VALID, vi_bindings_valid);
2061
2062 if (IS_SET_IN_SRC(VI_BINDING_STRIDES)) {
2063 assert(IS_SET_IN_SRC(VI_BINDINGS_VALID));
2064 u_foreach_bit(a, src->vi_bindings_valid) {
2065 COPY_MEMBER(VI_BINDING_STRIDES, vi_binding_strides[a]);
2066 }
2067 }
2068
2069 COPY_IF_SET(IA_PRIMITIVE_TOPOLOGY, ia.primitive_topology);
2070 COPY_IF_SET(IA_PRIMITIVE_RESTART_ENABLE, ia.primitive_restart_enable);
2071 COPY_IF_SET(TS_PATCH_CONTROL_POINTS, ts.patch_control_points);
2072 COPY_IF_SET(TS_DOMAIN_ORIGIN, ts.domain_origin);
2073
2074 COPY_IF_SET(VP_VIEWPORT_COUNT, vp.viewport_count);
2075 if (IS_SET_IN_SRC(VP_VIEWPORTS)) {
2076 assert(IS_SET_IN_SRC(VP_VIEWPORT_COUNT));
2077 COPY_ARRAY(VP_VIEWPORTS, vp.viewports, src->vp.viewport_count);
2078 }
2079
2080 COPY_IF_SET(VP_SCISSOR_COUNT, vp.scissor_count);
2081 if (IS_SET_IN_SRC(VP_SCISSORS)) {
2082 assert(IS_SET_IN_SRC(VP_SCISSOR_COUNT));
2083 COPY_ARRAY(VP_SCISSORS, vp.scissors, src->vp.scissor_count);
2084 }
2085
2086 COPY_IF_SET(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE,
2087 vp.depth_clip_negative_one_to_one);
2088
2089 COPY_IF_SET(DR_ENABLE, dr.enable);
2090 COPY_IF_SET(DR_MODE, dr.mode);
2091 if (IS_SET_IN_SRC(DR_RECTANGLES)) {
2092 COPY_MEMBER(DR_RECTANGLES, dr.rectangle_count);
2093 COPY_ARRAY(DR_RECTANGLES, dr.rectangles, src->dr.rectangle_count);
2094 }
2095
2096 COPY_IF_SET(RS_RASTERIZER_DISCARD_ENABLE, rs.rasterizer_discard_enable);
2097 COPY_IF_SET(RS_DEPTH_CLAMP_ENABLE, rs.depth_clamp_enable);
2098 COPY_IF_SET(RS_DEPTH_CLIP_ENABLE, rs.depth_clip_enable);
2099 COPY_IF_SET(RS_POLYGON_MODE, rs.polygon_mode);
2100 COPY_IF_SET(RS_CULL_MODE, rs.cull_mode);
2101 COPY_IF_SET(RS_FRONT_FACE, rs.front_face);
2102 COPY_IF_SET(RS_CONSERVATIVE_MODE, rs.conservative_mode);
2103 COPY_IF_SET(RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE,
2104 rs.extra_primitive_overestimation_size);
2105 COPY_IF_SET(RS_RASTERIZATION_ORDER_AMD, rs.rasterization_order_amd);
2106 COPY_IF_SET(RS_PROVOKING_VERTEX, rs.provoking_vertex);
2107 COPY_IF_SET(RS_RASTERIZATION_STREAM, rs.rasterization_stream);
2108 COPY_IF_SET(RS_DEPTH_BIAS_ENABLE, rs.depth_bias.enable);
2109 COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.constant);
2110 COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.clamp);
2111 COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.slope);
2112 COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.representation);
2113 COPY_IF_SET(RS_DEPTH_BIAS_FACTORS, rs.depth_bias.exact);
2114 COPY_IF_SET(RS_LINE_WIDTH, rs.line.width);
2115 COPY_IF_SET(RS_LINE_MODE, rs.line.mode);
2116 COPY_IF_SET(RS_LINE_STIPPLE_ENABLE, rs.line.stipple.enable);
2117 COPY_IF_SET(RS_LINE_STIPPLE, rs.line.stipple.factor);
2118 COPY_IF_SET(RS_LINE_STIPPLE, rs.line.stipple.pattern);
2119
2120 COPY_IF_SET(FSR, fsr.fragment_size.width);
2121 COPY_IF_SET(FSR, fsr.fragment_size.height);
2122 COPY_IF_SET(FSR, fsr.combiner_ops[0]);
2123 COPY_IF_SET(FSR, fsr.combiner_ops[1]);
2124
2125 COPY_IF_SET(MS_RASTERIZATION_SAMPLES, ms.rasterization_samples);
2126 COPY_IF_SET(MS_SAMPLE_MASK, ms.sample_mask);
2127 COPY_IF_SET(MS_ALPHA_TO_COVERAGE_ENABLE, ms.alpha_to_coverage_enable);
2128 COPY_IF_SET(MS_ALPHA_TO_ONE_ENABLE, ms.alpha_to_one_enable);
2129 COPY_IF_SET(MS_SAMPLE_LOCATIONS_ENABLE, ms.sample_locations_enable);
2130
2131 if (IS_SET_IN_SRC(MS_SAMPLE_LOCATIONS)) {
2132 assert(dst->ms.sample_locations != NULL);
2133 COPY_MEMBER(MS_SAMPLE_LOCATIONS, ms.sample_locations->per_pixel);
2134 COPY_MEMBER(MS_SAMPLE_LOCATIONS, ms.sample_locations->grid_size.width);
2135 COPY_MEMBER(MS_SAMPLE_LOCATIONS, ms.sample_locations->grid_size.height);
2136 const uint32_t sl_count = src->ms.sample_locations->per_pixel *
2137 src->ms.sample_locations->grid_size.width *
2138 src->ms.sample_locations->grid_size.height;
2139 COPY_ARRAY(MS_SAMPLE_LOCATIONS, ms.sample_locations->locations, sl_count);
2140 }
2141
2142 COPY_IF_SET(DS_DEPTH_TEST_ENABLE, ds.depth.test_enable);
2143 COPY_IF_SET(DS_DEPTH_WRITE_ENABLE, ds.depth.write_enable);
2144 COPY_IF_SET(DS_DEPTH_COMPARE_OP, ds.depth.compare_op);
2145 COPY_IF_SET(DS_DEPTH_BOUNDS_TEST_ENABLE, ds.depth.bounds_test.enable);
2146 if (IS_SET_IN_SRC(DS_DEPTH_BOUNDS_TEST_BOUNDS)) {
2147 COPY_MEMBER(DS_DEPTH_BOUNDS_TEST_BOUNDS, ds.depth.bounds_test.min);
2148 COPY_MEMBER(DS_DEPTH_BOUNDS_TEST_BOUNDS, ds.depth.bounds_test.max);
2149 }
2150
2151 COPY_IF_SET(DS_STENCIL_TEST_ENABLE, ds.stencil.test_enable);
2152 if (IS_SET_IN_SRC(DS_STENCIL_OP)) {
2153 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.front.op.fail);
2154 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.front.op.pass);
2155 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.front.op.depth_fail);
2156 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.front.op.compare);
2157 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.back.op.fail);
2158 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.back.op.pass);
2159 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.back.op.depth_fail);
2160 COPY_MEMBER(DS_STENCIL_OP, ds.stencil.back.op.compare);
2161 }
2162 if (IS_SET_IN_SRC(DS_STENCIL_COMPARE_MASK)) {
2163 COPY_MEMBER(DS_STENCIL_COMPARE_MASK, ds.stencil.front.compare_mask);
2164 COPY_MEMBER(DS_STENCIL_COMPARE_MASK, ds.stencil.back.compare_mask);
2165 }
2166 if (IS_SET_IN_SRC(DS_STENCIL_WRITE_MASK)) {
2167 COPY_MEMBER(DS_STENCIL_WRITE_MASK, ds.stencil.front.write_mask);
2168 COPY_MEMBER(DS_STENCIL_WRITE_MASK, ds.stencil.back.write_mask);
2169 }
2170 if (IS_SET_IN_SRC(DS_STENCIL_REFERENCE)) {
2171 COPY_MEMBER(DS_STENCIL_REFERENCE, ds.stencil.front.reference);
2172 COPY_MEMBER(DS_STENCIL_REFERENCE, ds.stencil.back.reference);
2173 }
2174
2175 COPY_IF_SET(CB_LOGIC_OP_ENABLE, cb.logic_op_enable);
2176 COPY_IF_SET(CB_LOGIC_OP, cb.logic_op);
2177 COPY_IF_SET(CB_ATTACHMENT_COUNT, cb.attachment_count);
2178 COPY_IF_SET(CB_COLOR_WRITE_ENABLES, cb.color_write_enables);
2179 if (IS_SET_IN_SRC(CB_BLEND_ENABLES)) {
2180 for (uint32_t a = 0; a < src->cb.attachment_count; a++)
2181 COPY_MEMBER(CB_BLEND_ENABLES, cb.attachments[a].blend_enable);
2182 }
2183 if (IS_SET_IN_SRC(CB_BLEND_EQUATIONS)) {
2184 for (uint32_t a = 0; a < src->cb.attachment_count; a++) {
2185 COPY_MEMBER(CB_BLEND_EQUATIONS,
2186 cb.attachments[a].src_color_blend_factor);
2187 COPY_MEMBER(CB_BLEND_EQUATIONS,
2188 cb.attachments[a].dst_color_blend_factor);
2189 COPY_MEMBER(CB_BLEND_EQUATIONS,
2190 cb.attachments[a].src_alpha_blend_factor);
2191 COPY_MEMBER(CB_BLEND_EQUATIONS,
2192 cb.attachments[a].dst_alpha_blend_factor);
2193 COPY_MEMBER(CB_BLEND_EQUATIONS, cb.attachments[a].color_blend_op);
2194 COPY_MEMBER(CB_BLEND_EQUATIONS, cb.attachments[a].alpha_blend_op);
2195 }
2196 }
2197 if (IS_SET_IN_SRC(CB_WRITE_MASKS)) {
2198 for (uint32_t a = 0; a < src->cb.attachment_count; a++)
2199 COPY_MEMBER(CB_WRITE_MASKS, cb.attachments[a].write_mask);
2200 }
2201 if (IS_SET_IN_SRC(CB_BLEND_CONSTANTS))
2202 COPY_ARRAY(CB_BLEND_CONSTANTS, cb.blend_constants, 4);
2203
2204 COPY_IF_SET(RP_ATTACHMENTS, rp.attachments);
2205
2206 if (IS_SET_IN_SRC(COLOR_ATTACHMENT_MAP)) {
2207 COPY_ARRAY(COLOR_ATTACHMENT_MAP, cal.color_map,
2208 MESA_VK_MAX_COLOR_ATTACHMENTS);
2209 }
2210
2211 COPY_IF_SET(ATTACHMENT_FEEDBACK_LOOP_ENABLE, feedback_loops);
2212
2213 #undef IS_SET_IN_SRC
2214 #undef MARK_DIRTY
2215 #undef COPY_MEMBER
2216 #undef COPY_ARRAY
2217 #undef COPY_IF_SET
2218
2219 for (uint32_t w = 0; w < ARRAY_SIZE(dst->dirty); w++) {
2220 /* If it's in the source but isn't set in the destination at all, mark
2221 * it dirty. It's possible that the default values just happen to equal
2222 * the value from src.
2223 */
2224 dst->dirty[w] |= src->set[w] & ~dst->set[w];
2225
2226 /* Everything that was in the source is now in the destination */
2227 dst->set[w] |= src->set[w];
2228 }
2229 }
2230
2231 void
vk_cmd_set_dynamic_graphics_state(struct vk_command_buffer * cmd,const struct vk_dynamic_graphics_state * state)2232 vk_cmd_set_dynamic_graphics_state(struct vk_command_buffer *cmd,
2233 const struct vk_dynamic_graphics_state *state)
2234 {
2235 vk_dynamic_graphics_state_copy(&cmd->dynamic_graphics_state, state);
2236 }
2237
2238 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetVertexInputEXT(VkCommandBuffer commandBuffer,uint32_t vertexBindingDescriptionCount,const VkVertexInputBindingDescription2EXT * pVertexBindingDescriptions,uint32_t vertexAttributeDescriptionCount,const VkVertexInputAttributeDescription2EXT * pVertexAttributeDescriptions)2239 vk_common_CmdSetVertexInputEXT(VkCommandBuffer commandBuffer,
2240 uint32_t vertexBindingDescriptionCount,
2241 const VkVertexInputBindingDescription2EXT* pVertexBindingDescriptions,
2242 uint32_t vertexAttributeDescriptionCount,
2243 const VkVertexInputAttributeDescription2EXT* pVertexAttributeDescriptions)
2244 {
2245 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2246 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2247
2248 uint32_t bindings_valid = 0;
2249 for (uint32_t i = 0; i < vertexBindingDescriptionCount; i++) {
2250 const VkVertexInputBindingDescription2EXT *desc =
2251 &pVertexBindingDescriptions[i];
2252
2253 assert(desc->binding < MESA_VK_MAX_VERTEX_BINDINGS);
2254 assert(desc->stride <= MESA_VK_MAX_VERTEX_BINDING_STRIDE);
2255 assert(desc->inputRate <= UINT8_MAX);
2256
2257 const uint32_t b = desc->binding;
2258 bindings_valid |= BITFIELD_BIT(b);
2259 dyn->vi->bindings[b].stride = desc->stride;
2260 dyn->vi->bindings[b].input_rate = desc->inputRate;
2261 dyn->vi->bindings[b].divisor = desc->divisor;
2262
2263 /* Also set bindings_strides in case a driver is keying off that */
2264 dyn->vi_binding_strides[b] = desc->stride;
2265 }
2266
2267 dyn->vi->bindings_valid = bindings_valid;
2268 SET_DYN_VALUE(dyn, VI_BINDINGS_VALID, vi_bindings_valid, bindings_valid);
2269
2270 uint32_t attributes_valid = 0;
2271 for (uint32_t i = 0; i < vertexAttributeDescriptionCount; i++) {
2272 const VkVertexInputAttributeDescription2EXT *desc =
2273 &pVertexAttributeDescriptions[i];
2274
2275 assert(desc->location < MESA_VK_MAX_VERTEX_ATTRIBUTES);
2276 assert(desc->binding < MESA_VK_MAX_VERTEX_BINDINGS);
2277 assert(bindings_valid & BITFIELD_BIT(desc->binding));
2278
2279 const uint32_t a = desc->location;
2280 attributes_valid |= BITFIELD_BIT(a);
2281 dyn->vi->attributes[a].binding = desc->binding;
2282 dyn->vi->attributes[a].format = desc->format;
2283 dyn->vi->attributes[a].offset = desc->offset;
2284 }
2285 dyn->vi->attributes_valid = attributes_valid;
2286
2287 BITSET_SET(dyn->set, MESA_VK_DYNAMIC_VI);
2288 BITSET_SET(dyn->set, MESA_VK_DYNAMIC_VI_BINDING_STRIDES);
2289 BITSET_SET(dyn->dirty, MESA_VK_DYNAMIC_VI);
2290 BITSET_SET(dyn->dirty, MESA_VK_DYNAMIC_VI_BINDING_STRIDES);
2291 }
2292
2293 void
vk_cmd_set_vertex_binding_strides(struct vk_command_buffer * cmd,uint32_t first_binding,uint32_t binding_count,const VkDeviceSize * strides)2294 vk_cmd_set_vertex_binding_strides(struct vk_command_buffer *cmd,
2295 uint32_t first_binding,
2296 uint32_t binding_count,
2297 const VkDeviceSize *strides)
2298 {
2299 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2300
2301 for (uint32_t i = 0; i < binding_count; i++) {
2302 SET_DYN_VALUE(dyn, VI_BINDING_STRIDES,
2303 vi_binding_strides[first_binding + i], strides[i]);
2304 }
2305 }
2306
2307 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,VkPrimitiveTopology primitiveTopology)2308 vk_common_CmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
2309 VkPrimitiveTopology primitiveTopology)
2310 {
2311 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2312 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2313
2314 SET_DYN_VALUE(dyn, IA_PRIMITIVE_TOPOLOGY,
2315 ia.primitive_topology, primitiveTopology);
2316 }
2317
2318 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,VkBool32 primitiveRestartEnable)2319 vk_common_CmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
2320 VkBool32 primitiveRestartEnable)
2321 {
2322 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2323 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2324
2325 SET_DYN_BOOL(dyn, IA_PRIMITIVE_RESTART_ENABLE,
2326 ia.primitive_restart_enable, primitiveRestartEnable);
2327 }
2328
2329 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer,uint32_t patchControlPoints)2330 vk_common_CmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer,
2331 uint32_t patchControlPoints)
2332 {
2333 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2334 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2335
2336 SET_DYN_VALUE(dyn, TS_PATCH_CONTROL_POINTS,
2337 ts.patch_control_points, patchControlPoints);
2338 }
2339
2340 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetTessellationDomainOriginEXT(VkCommandBuffer commandBuffer,VkTessellationDomainOrigin domainOrigin)2341 vk_common_CmdSetTessellationDomainOriginEXT(VkCommandBuffer commandBuffer,
2342 VkTessellationDomainOrigin domainOrigin)
2343 {
2344 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2345 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2346
2347 SET_DYN_VALUE(dyn, TS_DOMAIN_ORIGIN, ts.domain_origin, domainOrigin);
2348 }
2349
2350 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetViewport(VkCommandBuffer commandBuffer,uint32_t firstViewport,uint32_t viewportCount,const VkViewport * pViewports)2351 vk_common_CmdSetViewport(VkCommandBuffer commandBuffer,
2352 uint32_t firstViewport,
2353 uint32_t viewportCount,
2354 const VkViewport *pViewports)
2355 {
2356 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2357 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2358
2359 SET_DYN_ARRAY(dyn, VP_VIEWPORTS, vp.viewports,
2360 firstViewport, viewportCount, pViewports);
2361 }
2362
2363 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetViewportWithCount(VkCommandBuffer commandBuffer,uint32_t viewportCount,const VkViewport * pViewports)2364 vk_common_CmdSetViewportWithCount(VkCommandBuffer commandBuffer,
2365 uint32_t viewportCount,
2366 const VkViewport *pViewports)
2367 {
2368 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2369 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2370
2371 SET_DYN_VALUE(dyn, VP_VIEWPORT_COUNT, vp.viewport_count, viewportCount);
2372 SET_DYN_ARRAY(dyn, VP_VIEWPORTS, vp.viewports, 0, viewportCount, pViewports);
2373 }
2374
2375 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetScissor(VkCommandBuffer commandBuffer,uint32_t firstScissor,uint32_t scissorCount,const VkRect2D * pScissors)2376 vk_common_CmdSetScissor(VkCommandBuffer commandBuffer,
2377 uint32_t firstScissor,
2378 uint32_t scissorCount,
2379 const VkRect2D *pScissors)
2380 {
2381 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2382 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2383
2384 SET_DYN_ARRAY(dyn, VP_SCISSORS, vp.scissors,
2385 firstScissor, scissorCount, pScissors);
2386 }
2387
2388 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetScissorWithCount(VkCommandBuffer commandBuffer,uint32_t scissorCount,const VkRect2D * pScissors)2389 vk_common_CmdSetScissorWithCount(VkCommandBuffer commandBuffer,
2390 uint32_t scissorCount,
2391 const VkRect2D *pScissors)
2392 {
2393 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2394 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2395
2396 SET_DYN_VALUE(dyn, VP_SCISSOR_COUNT, vp.scissor_count, scissorCount);
2397 SET_DYN_ARRAY(dyn, VP_SCISSORS, vp.scissors, 0, scissorCount, pScissors);
2398 }
2399
2400 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthClipNegativeOneToOneEXT(VkCommandBuffer commandBuffer,VkBool32 negativeOneToOne)2401 vk_common_CmdSetDepthClipNegativeOneToOneEXT(VkCommandBuffer commandBuffer,
2402 VkBool32 negativeOneToOne)
2403 {
2404 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2405 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2406
2407 SET_DYN_BOOL(dyn, VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE,
2408 vp.depth_clip_negative_one_to_one, negativeOneToOne);
2409 }
2410
2411 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer,uint32_t firstDiscardRectangle,uint32_t discardRectangleCount,const VkRect2D * pDiscardRectangles)2412 vk_common_CmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer,
2413 uint32_t firstDiscardRectangle,
2414 uint32_t discardRectangleCount,
2415 const VkRect2D *pDiscardRectangles)
2416 {
2417 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2418 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2419
2420 SET_DYN_VALUE(dyn, DR_RECTANGLES, dr.rectangle_count, discardRectangleCount);
2421 SET_DYN_ARRAY(dyn, DR_RECTANGLES, dr.rectangles, firstDiscardRectangle,
2422 discardRectangleCount, pDiscardRectangles);
2423 }
2424
2425 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,VkBool32 rasterizerDiscardEnable)2426 vk_common_CmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
2427 VkBool32 rasterizerDiscardEnable)
2428 {
2429 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2430 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2431
2432 SET_DYN_BOOL(dyn, RS_RASTERIZER_DISCARD_ENABLE,
2433 rs.rasterizer_discard_enable, rasterizerDiscardEnable);
2434 }
2435
2436 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthClampEnableEXT(VkCommandBuffer commandBuffer,VkBool32 depthClampEnable)2437 vk_common_CmdSetDepthClampEnableEXT(VkCommandBuffer commandBuffer,
2438 VkBool32 depthClampEnable)
2439 {
2440 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2441 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2442
2443 SET_DYN_BOOL(dyn, RS_DEPTH_CLAMP_ENABLE,
2444 rs.depth_clamp_enable, depthClampEnable);
2445 }
2446
2447 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthClipEnableEXT(VkCommandBuffer commandBuffer,VkBool32 depthClipEnable)2448 vk_common_CmdSetDepthClipEnableEXT(VkCommandBuffer commandBuffer,
2449 VkBool32 depthClipEnable)
2450 {
2451 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2452 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2453
2454 SET_DYN_VALUE(dyn, RS_DEPTH_CLIP_ENABLE, rs.depth_clip_enable,
2455 depthClipEnable ? VK_MESA_DEPTH_CLIP_ENABLE_TRUE :
2456 VK_MESA_DEPTH_CLIP_ENABLE_FALSE);
2457 }
2458
2459 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetPolygonModeEXT(VkCommandBuffer commandBuffer,VkPolygonMode polygonMode)2460 vk_common_CmdSetPolygonModeEXT(VkCommandBuffer commandBuffer,
2461 VkPolygonMode polygonMode)
2462 {
2463 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2464 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2465
2466 SET_DYN_VALUE(dyn, RS_POLYGON_MODE, rs.polygon_mode, polygonMode);
2467 }
2468
2469 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCullMode(VkCommandBuffer commandBuffer,VkCullModeFlags cullMode)2470 vk_common_CmdSetCullMode(VkCommandBuffer commandBuffer,
2471 VkCullModeFlags cullMode)
2472 {
2473 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2474 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2475
2476 SET_DYN_VALUE(dyn, RS_CULL_MODE, rs.cull_mode, cullMode);
2477 }
2478
2479 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetFrontFace(VkCommandBuffer commandBuffer,VkFrontFace frontFace)2480 vk_common_CmdSetFrontFace(VkCommandBuffer commandBuffer,
2481 VkFrontFace frontFace)
2482 {
2483 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2484 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2485
2486 SET_DYN_VALUE(dyn, RS_FRONT_FACE, rs.front_face, frontFace);
2487 }
2488
2489 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetConservativeRasterizationModeEXT(VkCommandBuffer commandBuffer,VkConservativeRasterizationModeEXT conservativeRasterizationMode)2490 vk_common_CmdSetConservativeRasterizationModeEXT(
2491 VkCommandBuffer commandBuffer,
2492 VkConservativeRasterizationModeEXT conservativeRasterizationMode)
2493 {
2494 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2495 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2496
2497 SET_DYN_VALUE(dyn, RS_CONSERVATIVE_MODE, rs.conservative_mode,
2498 conservativeRasterizationMode);
2499 }
2500
2501 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetExtraPrimitiveOverestimationSizeEXT(VkCommandBuffer commandBuffer,float extraPrimitiveOverestimationSize)2502 vk_common_CmdSetExtraPrimitiveOverestimationSizeEXT(
2503 VkCommandBuffer commandBuffer,
2504 float extraPrimitiveOverestimationSize)
2505 {
2506 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2507 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2508
2509 SET_DYN_VALUE(dyn, RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE,
2510 rs.extra_primitive_overestimation_size,
2511 extraPrimitiveOverestimationSize);
2512 }
2513
2514 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetProvokingVertexModeEXT(VkCommandBuffer commandBuffer,VkProvokingVertexModeEXT provokingVertexMode)2515 vk_common_CmdSetProvokingVertexModeEXT(VkCommandBuffer commandBuffer,
2516 VkProvokingVertexModeEXT provokingVertexMode)
2517 {
2518 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2519 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2520
2521 SET_DYN_VALUE(dyn, RS_PROVOKING_VERTEX,
2522 rs.provoking_vertex, provokingVertexMode);
2523 }
2524
2525 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetAttachmentFeedbackLoopEnableEXT(VkCommandBuffer commandBuffer,VkImageAspectFlags aspectMask)2526 vk_common_CmdSetAttachmentFeedbackLoopEnableEXT(VkCommandBuffer commandBuffer,
2527 VkImageAspectFlags aspectMask)
2528 {
2529 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2530 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2531
2532 SET_DYN_VALUE(dyn, ATTACHMENT_FEEDBACK_LOOP_ENABLE,
2533 feedback_loops, aspectMask);
2534 }
2535
2536 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRasterizationStreamEXT(VkCommandBuffer commandBuffer,uint32_t rasterizationStream)2537 vk_common_CmdSetRasterizationStreamEXT(VkCommandBuffer commandBuffer,
2538 uint32_t rasterizationStream)
2539 {
2540 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2541 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2542
2543 SET_DYN_VALUE(dyn, RS_RASTERIZATION_STREAM,
2544 rs.rasterization_stream, rasterizationStream);
2545 }
2546
2547 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthBiasEnable(VkCommandBuffer commandBuffer,VkBool32 depthBiasEnable)2548 vk_common_CmdSetDepthBiasEnable(VkCommandBuffer commandBuffer,
2549 VkBool32 depthBiasEnable)
2550 {
2551 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2552 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2553
2554 SET_DYN_BOOL(dyn, RS_DEPTH_BIAS_ENABLE,
2555 rs.depth_bias.enable, depthBiasEnable);
2556 }
2557
2558 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthBias(VkCommandBuffer commandBuffer,float depthBiasConstantFactor,float depthBiasClamp,float depthBiasSlopeFactor)2559 vk_common_CmdSetDepthBias(VkCommandBuffer commandBuffer,
2560 float depthBiasConstantFactor,
2561 float depthBiasClamp,
2562 float depthBiasSlopeFactor)
2563 {
2564 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2565
2566 VkDepthBiasInfoEXT depth_bias_info = {
2567 .sType = VK_STRUCTURE_TYPE_DEPTH_BIAS_INFO_EXT,
2568 .depthBiasConstantFactor = depthBiasConstantFactor,
2569 .depthBiasClamp = depthBiasClamp,
2570 .depthBiasSlopeFactor = depthBiasSlopeFactor,
2571 };
2572
2573 cmd->base.device->dispatch_table.CmdSetDepthBias2EXT(commandBuffer,
2574 &depth_bias_info);
2575 }
2576
2577 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLineWidth(VkCommandBuffer commandBuffer,float lineWidth)2578 vk_common_CmdSetLineWidth(VkCommandBuffer commandBuffer,
2579 float lineWidth)
2580 {
2581 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2582 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2583
2584 SET_DYN_VALUE(dyn, RS_LINE_WIDTH, rs.line.width, lineWidth);
2585 }
2586
2587 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLineRasterizationModeEXT(VkCommandBuffer commandBuffer,VkLineRasterizationModeKHR lineRasterizationMode)2588 vk_common_CmdSetLineRasterizationModeEXT(VkCommandBuffer commandBuffer,
2589 VkLineRasterizationModeKHR lineRasterizationMode)
2590 {
2591 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2592 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2593
2594 SET_DYN_VALUE(dyn, RS_LINE_MODE, rs.line.mode, lineRasterizationMode);
2595 }
2596
2597 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLineStippleEnableEXT(VkCommandBuffer commandBuffer,VkBool32 stippledLineEnable)2598 vk_common_CmdSetLineStippleEnableEXT(VkCommandBuffer commandBuffer,
2599 VkBool32 stippledLineEnable)
2600 {
2601 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2602 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2603
2604 SET_DYN_BOOL(dyn, RS_LINE_STIPPLE_ENABLE,
2605 rs.line.stipple.enable, stippledLineEnable);
2606 }
2607
2608 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLineStippleKHR(VkCommandBuffer commandBuffer,uint32_t lineStippleFactor,uint16_t lineStipplePattern)2609 vk_common_CmdSetLineStippleKHR(VkCommandBuffer commandBuffer,
2610 uint32_t lineStippleFactor,
2611 uint16_t lineStipplePattern)
2612 {
2613 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2614 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2615
2616 SET_DYN_VALUE(dyn, RS_LINE_STIPPLE,
2617 rs.line.stipple.factor, lineStippleFactor);
2618 SET_DYN_VALUE(dyn, RS_LINE_STIPPLE,
2619 rs.line.stipple.pattern, lineStipplePattern);
2620 }
2621
2622 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetFragmentShadingRateKHR(VkCommandBuffer commandBuffer,const VkExtent2D * pFragmentSize,const VkFragmentShadingRateCombinerOpKHR combinerOps[2])2623 vk_common_CmdSetFragmentShadingRateKHR(VkCommandBuffer commandBuffer,
2624 const VkExtent2D *pFragmentSize,
2625 const VkFragmentShadingRateCombinerOpKHR combinerOps[2])
2626 {
2627 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2628 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2629
2630 SET_DYN_VALUE(dyn, FSR, fsr.fragment_size.width, pFragmentSize->width);
2631 SET_DYN_VALUE(dyn, FSR, fsr.fragment_size.height, pFragmentSize->height);
2632 SET_DYN_VALUE(dyn, FSR, fsr.combiner_ops[0], combinerOps[0]);
2633 SET_DYN_VALUE(dyn, FSR, fsr.combiner_ops[1], combinerOps[1]);
2634 }
2635
2636 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRasterizationSamplesEXT(VkCommandBuffer commandBuffer,VkSampleCountFlagBits rasterizationSamples)2637 vk_common_CmdSetRasterizationSamplesEXT(VkCommandBuffer commandBuffer,
2638 VkSampleCountFlagBits rasterizationSamples)
2639 {
2640 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2641 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2642
2643 assert(rasterizationSamples <= MESA_VK_MAX_SAMPLES);
2644
2645 SET_DYN_VALUE(dyn, MS_RASTERIZATION_SAMPLES,
2646 ms.rasterization_samples, rasterizationSamples);
2647 }
2648
2649 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetSampleMaskEXT(VkCommandBuffer commandBuffer,VkSampleCountFlagBits samples,const VkSampleMask * pSampleMask)2650 vk_common_CmdSetSampleMaskEXT(VkCommandBuffer commandBuffer,
2651 VkSampleCountFlagBits samples,
2652 const VkSampleMask *pSampleMask)
2653 {
2654 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2655 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2656
2657 VkSampleMask sample_mask = *pSampleMask & BITFIELD_MASK(MESA_VK_MAX_SAMPLES);
2658
2659 SET_DYN_VALUE(dyn, MS_SAMPLE_MASK, ms.sample_mask, sample_mask);
2660 }
2661
2662 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetAlphaToCoverageEnableEXT(VkCommandBuffer commandBuffer,VkBool32 alphaToCoverageEnable)2663 vk_common_CmdSetAlphaToCoverageEnableEXT(VkCommandBuffer commandBuffer,
2664 VkBool32 alphaToCoverageEnable)
2665 {
2666 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2667 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2668
2669 SET_DYN_VALUE(dyn, MS_ALPHA_TO_COVERAGE_ENABLE,
2670 ms.alpha_to_coverage_enable, alphaToCoverageEnable);
2671 }
2672
2673 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetAlphaToOneEnableEXT(VkCommandBuffer commandBuffer,VkBool32 alphaToOneEnable)2674 vk_common_CmdSetAlphaToOneEnableEXT(VkCommandBuffer commandBuffer,
2675 VkBool32 alphaToOneEnable)
2676 {
2677 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2678 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2679
2680 SET_DYN_VALUE(dyn, MS_ALPHA_TO_ONE_ENABLE,
2681 ms.alpha_to_one_enable, alphaToOneEnable);
2682 }
2683
2684 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,const VkSampleLocationsInfoEXT * pSampleLocationsInfo)2685 vk_common_CmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
2686 const VkSampleLocationsInfoEXT *pSampleLocationsInfo)
2687 {
2688 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2689 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2690
2691 SET_DYN_VALUE(dyn, MS_SAMPLE_LOCATIONS,
2692 ms.sample_locations->per_pixel,
2693 pSampleLocationsInfo->sampleLocationsPerPixel);
2694 SET_DYN_VALUE(dyn, MS_SAMPLE_LOCATIONS,
2695 ms.sample_locations->grid_size.width,
2696 pSampleLocationsInfo->sampleLocationGridSize.width);
2697 SET_DYN_VALUE(dyn, MS_SAMPLE_LOCATIONS,
2698 ms.sample_locations->grid_size.height,
2699 pSampleLocationsInfo->sampleLocationGridSize.height);
2700
2701 assert(pSampleLocationsInfo->sampleLocationsCount ==
2702 pSampleLocationsInfo->sampleLocationsPerPixel *
2703 pSampleLocationsInfo->sampleLocationGridSize.width *
2704 pSampleLocationsInfo->sampleLocationGridSize.height);
2705
2706 assert(pSampleLocationsInfo->sampleLocationsCount <=
2707 MESA_VK_MAX_SAMPLE_LOCATIONS);
2708
2709 SET_DYN_ARRAY(dyn, MS_SAMPLE_LOCATIONS,
2710 ms.sample_locations->locations,
2711 0, pSampleLocationsInfo->sampleLocationsCount,
2712 pSampleLocationsInfo->pSampleLocations);
2713 }
2714
2715 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetSampleLocationsEnableEXT(VkCommandBuffer commandBuffer,VkBool32 sampleLocationsEnable)2716 vk_common_CmdSetSampleLocationsEnableEXT(VkCommandBuffer commandBuffer,
2717 VkBool32 sampleLocationsEnable)
2718 {
2719 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2720 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2721
2722 SET_DYN_BOOL(dyn, MS_SAMPLE_LOCATIONS_ENABLE,
2723 ms.sample_locations_enable, sampleLocationsEnable);
2724 }
2725
2726 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthTestEnable(VkCommandBuffer commandBuffer,VkBool32 depthTestEnable)2727 vk_common_CmdSetDepthTestEnable(VkCommandBuffer commandBuffer,
2728 VkBool32 depthTestEnable)
2729 {
2730 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2731 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2732
2733 SET_DYN_BOOL(dyn, DS_DEPTH_TEST_ENABLE,
2734 ds.depth.test_enable, depthTestEnable);
2735 }
2736
2737 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthWriteEnable(VkCommandBuffer commandBuffer,VkBool32 depthWriteEnable)2738 vk_common_CmdSetDepthWriteEnable(VkCommandBuffer commandBuffer,
2739 VkBool32 depthWriteEnable)
2740 {
2741 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2742 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2743
2744 SET_DYN_BOOL(dyn, DS_DEPTH_WRITE_ENABLE,
2745 ds.depth.write_enable, depthWriteEnable);
2746 }
2747
2748 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthCompareOp(VkCommandBuffer commandBuffer,VkCompareOp depthCompareOp)2749 vk_common_CmdSetDepthCompareOp(VkCommandBuffer commandBuffer,
2750 VkCompareOp depthCompareOp)
2751 {
2752 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2753 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2754
2755 SET_DYN_VALUE(dyn, DS_DEPTH_COMPARE_OP, ds.depth.compare_op,
2756 depthCompareOp);
2757 }
2758
2759 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,VkBool32 depthBoundsTestEnable)2760 vk_common_CmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
2761 VkBool32 depthBoundsTestEnable)
2762 {
2763 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2764 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2765
2766 SET_DYN_BOOL(dyn, DS_DEPTH_BOUNDS_TEST_ENABLE,
2767 ds.depth.bounds_test.enable, depthBoundsTestEnable);
2768 }
2769
2770 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthBounds(VkCommandBuffer commandBuffer,float minDepthBounds,float maxDepthBounds)2771 vk_common_CmdSetDepthBounds(VkCommandBuffer commandBuffer,
2772 float minDepthBounds,
2773 float maxDepthBounds)
2774 {
2775 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2776 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2777
2778 SET_DYN_VALUE(dyn, DS_DEPTH_BOUNDS_TEST_BOUNDS,
2779 ds.depth.bounds_test.min, minDepthBounds);
2780 SET_DYN_VALUE(dyn, DS_DEPTH_BOUNDS_TEST_BOUNDS,
2781 ds.depth.bounds_test.max, maxDepthBounds);
2782 }
2783
2784 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetStencilTestEnable(VkCommandBuffer commandBuffer,VkBool32 stencilTestEnable)2785 vk_common_CmdSetStencilTestEnable(VkCommandBuffer commandBuffer,
2786 VkBool32 stencilTestEnable)
2787 {
2788 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2789 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2790
2791 SET_DYN_BOOL(dyn, DS_STENCIL_TEST_ENABLE,
2792 ds.stencil.test_enable, stencilTestEnable);
2793 }
2794
2795 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetStencilOp(VkCommandBuffer commandBuffer,VkStencilFaceFlags faceMask,VkStencilOp failOp,VkStencilOp passOp,VkStencilOp depthFailOp,VkCompareOp compareOp)2796 vk_common_CmdSetStencilOp(VkCommandBuffer commandBuffer,
2797 VkStencilFaceFlags faceMask,
2798 VkStencilOp failOp,
2799 VkStencilOp passOp,
2800 VkStencilOp depthFailOp,
2801 VkCompareOp compareOp)
2802 {
2803 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2804 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2805
2806 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2807 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.front.op.fail, failOp);
2808 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.front.op.pass, passOp);
2809 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.front.op.depth_fail, depthFailOp);
2810 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.front.op.compare, compareOp);
2811 }
2812
2813 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2814 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.back.op.fail, failOp);
2815 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.back.op.pass, passOp);
2816 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.back.op.depth_fail, depthFailOp);
2817 SET_DYN_VALUE(dyn, DS_STENCIL_OP, ds.stencil.back.op.compare, compareOp);
2818 }
2819 }
2820
2821 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer,VkStencilFaceFlags faceMask,uint32_t compareMask)2822 vk_common_CmdSetStencilCompareMask(VkCommandBuffer commandBuffer,
2823 VkStencilFaceFlags faceMask,
2824 uint32_t compareMask)
2825 {
2826 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2827 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2828
2829 /* We assume 8-bit stencil always */
2830 STATIC_ASSERT(sizeof(dyn->ds.stencil.front.write_mask) == 1);
2831
2832 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2833 SET_DYN_VALUE(dyn, DS_STENCIL_COMPARE_MASK,
2834 ds.stencil.front.compare_mask, (uint8_t)compareMask);
2835 }
2836 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2837 SET_DYN_VALUE(dyn, DS_STENCIL_COMPARE_MASK,
2838 ds.stencil.back.compare_mask, (uint8_t)compareMask);
2839 }
2840 }
2841
2842 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer,VkStencilFaceFlags faceMask,uint32_t writeMask)2843 vk_common_CmdSetStencilWriteMask(VkCommandBuffer commandBuffer,
2844 VkStencilFaceFlags faceMask,
2845 uint32_t writeMask)
2846 {
2847 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2848 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2849
2850 /* We assume 8-bit stencil always */
2851 STATIC_ASSERT(sizeof(dyn->ds.stencil.front.write_mask) == 1);
2852
2853 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2854 SET_DYN_VALUE(dyn, DS_STENCIL_WRITE_MASK,
2855 ds.stencil.front.write_mask, (uint8_t)writeMask);
2856 }
2857 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2858 SET_DYN_VALUE(dyn, DS_STENCIL_WRITE_MASK,
2859 ds.stencil.back.write_mask, (uint8_t)writeMask);
2860 }
2861 }
2862
2863 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetStencilReference(VkCommandBuffer commandBuffer,VkStencilFaceFlags faceMask,uint32_t reference)2864 vk_common_CmdSetStencilReference(VkCommandBuffer commandBuffer,
2865 VkStencilFaceFlags faceMask,
2866 uint32_t reference)
2867 {
2868 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2869 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2870
2871 /* We assume 8-bit stencil always */
2872 STATIC_ASSERT(sizeof(dyn->ds.stencil.front.write_mask) == 1);
2873
2874 if (faceMask & VK_STENCIL_FACE_FRONT_BIT) {
2875 SET_DYN_VALUE(dyn, DS_STENCIL_REFERENCE,
2876 ds.stencil.front.reference, (uint8_t)reference);
2877 }
2878 if (faceMask & VK_STENCIL_FACE_BACK_BIT) {
2879 SET_DYN_VALUE(dyn, DS_STENCIL_REFERENCE,
2880 ds.stencil.back.reference, (uint8_t)reference);
2881 }
2882 }
2883
2884 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLogicOpEnableEXT(VkCommandBuffer commandBuffer,VkBool32 logicOpEnable)2885 vk_common_CmdSetLogicOpEnableEXT(VkCommandBuffer commandBuffer,
2886 VkBool32 logicOpEnable)
2887 {
2888 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2889 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2890
2891 SET_DYN_BOOL(dyn, CB_LOGIC_OP_ENABLE, cb.logic_op_enable, logicOpEnable);
2892 }
2893
2894 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetLogicOpEXT(VkCommandBuffer commandBuffer,VkLogicOp logicOp)2895 vk_common_CmdSetLogicOpEXT(VkCommandBuffer commandBuffer,
2896 VkLogicOp logicOp)
2897 {
2898 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2899 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2900
2901 SET_DYN_VALUE(dyn, CB_LOGIC_OP, cb.logic_op, logicOp);
2902 }
2903
2904 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer,uint32_t attachmentCount,const VkBool32 * pColorWriteEnables)2905 vk_common_CmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer,
2906 uint32_t attachmentCount,
2907 const VkBool32 *pColorWriteEnables)
2908 {
2909 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2910 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2911
2912 assert(attachmentCount <= MESA_VK_MAX_COLOR_ATTACHMENTS);
2913
2914 uint8_t color_write_enables = 0;
2915 for (uint32_t a = 0; a < attachmentCount; a++) {
2916 if (pColorWriteEnables[a])
2917 color_write_enables |= BITFIELD_BIT(a);
2918 }
2919
2920 SET_DYN_VALUE(dyn, CB_COLOR_WRITE_ENABLES,
2921 cb.color_write_enables, color_write_enables);
2922 }
2923
2924 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetColorBlendEnableEXT(VkCommandBuffer commandBuffer,uint32_t firstAttachment,uint32_t attachmentCount,const VkBool32 * pColorBlendEnables)2925 vk_common_CmdSetColorBlendEnableEXT(VkCommandBuffer commandBuffer,
2926 uint32_t firstAttachment,
2927 uint32_t attachmentCount,
2928 const VkBool32 *pColorBlendEnables)
2929 {
2930 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2931 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2932
2933 for (uint32_t i = 0; i < attachmentCount; i++) {
2934 uint32_t a = firstAttachment + i;
2935 assert(a < ARRAY_SIZE(dyn->cb.attachments));
2936
2937 SET_DYN_BOOL(dyn, CB_BLEND_ENABLES,
2938 cb.attachments[a].blend_enable, pColorBlendEnables[i]);
2939 }
2940 }
2941
2942 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetColorBlendEquationEXT(VkCommandBuffer commandBuffer,uint32_t firstAttachment,uint32_t attachmentCount,const VkColorBlendEquationEXT * pColorBlendEquations)2943 vk_common_CmdSetColorBlendEquationEXT(VkCommandBuffer commandBuffer,
2944 uint32_t firstAttachment,
2945 uint32_t attachmentCount,
2946 const VkColorBlendEquationEXT *pColorBlendEquations)
2947 {
2948 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2949 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2950
2951 for (uint32_t i = 0; i < attachmentCount; i++) {
2952 uint32_t a = firstAttachment + i;
2953 assert(a < ARRAY_SIZE(dyn->cb.attachments));
2954
2955 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2956 cb.attachments[a].src_color_blend_factor,
2957 pColorBlendEquations[i].srcColorBlendFactor);
2958
2959 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2960 cb.attachments[a].dst_color_blend_factor,
2961 pColorBlendEquations[i].dstColorBlendFactor);
2962
2963 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2964 cb.attachments[a].color_blend_op,
2965 pColorBlendEquations[i].colorBlendOp);
2966
2967 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2968 cb.attachments[a].src_alpha_blend_factor,
2969 pColorBlendEquations[i].srcAlphaBlendFactor);
2970
2971 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2972 cb.attachments[a].dst_alpha_blend_factor,
2973 pColorBlendEquations[i].dstAlphaBlendFactor);
2974
2975 SET_DYN_VALUE(dyn, CB_BLEND_EQUATIONS,
2976 cb.attachments[a].alpha_blend_op,
2977 pColorBlendEquations[i].alphaBlendOp);
2978 }
2979 }
2980
2981 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetColorWriteMaskEXT(VkCommandBuffer commandBuffer,uint32_t firstAttachment,uint32_t attachmentCount,const VkColorComponentFlags * pColorWriteMasks)2982 vk_common_CmdSetColorWriteMaskEXT(VkCommandBuffer commandBuffer,
2983 uint32_t firstAttachment,
2984 uint32_t attachmentCount,
2985 const VkColorComponentFlags *pColorWriteMasks)
2986 {
2987 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
2988 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
2989
2990 for (uint32_t i = 0; i < attachmentCount; i++) {
2991 uint32_t a = firstAttachment + i;
2992 assert(a < ARRAY_SIZE(dyn->cb.attachments));
2993
2994 SET_DYN_VALUE(dyn, CB_WRITE_MASKS,
2995 cb.attachments[a].write_mask, pColorWriteMasks[i]);
2996 }
2997 }
2998
2999 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetBlendConstants(VkCommandBuffer commandBuffer,const float blendConstants[4])3000 vk_common_CmdSetBlendConstants(VkCommandBuffer commandBuffer,
3001 const float blendConstants[4])
3002 {
3003 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3004 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3005
3006 SET_DYN_ARRAY(dyn, CB_BLEND_CONSTANTS, cb.blend_constants,
3007 0, 4, blendConstants);
3008 }
3009
3010 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetColorBlendAdvancedEXT(VkCommandBuffer commandBuffer,uint32_t firstAttachment,uint32_t attachmentCount,const VkColorBlendAdvancedEXT * pColorBlendAdvanced)3011 vk_common_CmdSetColorBlendAdvancedEXT(VkCommandBuffer commandBuffer,
3012 uint32_t firstAttachment,
3013 uint32_t attachmentCount,
3014 const VkColorBlendAdvancedEXT* pColorBlendAdvanced)
3015 {
3016 unreachable("VK_EXT_blend_operation_advanced unsupported");
3017 }
3018
3019 void
vk_cmd_set_cb_attachment_count(struct vk_command_buffer * cmd,uint32_t attachment_count)3020 vk_cmd_set_cb_attachment_count(struct vk_command_buffer *cmd,
3021 uint32_t attachment_count)
3022 {
3023 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3024
3025 SET_DYN_VALUE(dyn, CB_ATTACHMENT_COUNT, cb.attachment_count, attachment_count);
3026 }
3027
3028 void
vk_cmd_set_rp_attachments(struct vk_command_buffer * cmd,enum vk_rp_attachment_flags attachments)3029 vk_cmd_set_rp_attachments(struct vk_command_buffer *cmd,
3030 enum vk_rp_attachment_flags attachments)
3031 {
3032 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3033
3034 SET_DYN_VALUE(dyn, RP_ATTACHMENTS, rp.attachments, attachments);
3035 }
3036
3037 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDiscardRectangleEnableEXT(VkCommandBuffer commandBuffer,VkBool32 discardRectangleEnable)3038 vk_common_CmdSetDiscardRectangleEnableEXT(VkCommandBuffer commandBuffer,
3039 VkBool32 discardRectangleEnable)
3040 {
3041 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3042 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3043
3044 SET_DYN_VALUE(dyn, DR_ENABLE, dr.enable, discardRectangleEnable);
3045 }
3046
3047 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDiscardRectangleModeEXT(VkCommandBuffer commandBuffer,VkDiscardRectangleModeEXT discardRectangleMode)3048 vk_common_CmdSetDiscardRectangleModeEXT(VkCommandBuffer commandBuffer,
3049 VkDiscardRectangleModeEXT discardRectangleMode)
3050 {
3051 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3052 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3053
3054 SET_DYN_VALUE(dyn, DR_MODE, dr.mode, discardRectangleMode);
3055 }
3056
3057 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetDepthBias2EXT(VkCommandBuffer commandBuffer,const VkDepthBiasInfoEXT * pDepthBiasInfo)3058 vk_common_CmdSetDepthBias2EXT(
3059 VkCommandBuffer commandBuffer,
3060 const VkDepthBiasInfoEXT* pDepthBiasInfo)
3061 {
3062 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3063 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3064
3065 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3066 rs.depth_bias.constant, pDepthBiasInfo->depthBiasConstantFactor);
3067 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3068 rs.depth_bias.clamp, pDepthBiasInfo->depthBiasClamp);
3069 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3070 rs.depth_bias.slope, pDepthBiasInfo->depthBiasSlopeFactor);
3071
3072 /** From the Vulkan 1.3.254 spec:
3073 *
3074 * "If pNext does not contain a VkDepthBiasRepresentationInfoEXT
3075 * structure, then this command is equivalent to including a
3076 * VkDepthBiasRepresentationInfoEXT with depthBiasExact set to VK_FALSE
3077 * and depthBiasRepresentation set to
3078 * VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT."
3079 */
3080 const VkDepthBiasRepresentationInfoEXT *dbr_info =
3081 vk_find_struct_const(pDepthBiasInfo->pNext, DEPTH_BIAS_REPRESENTATION_INFO_EXT);
3082 if (dbr_info) {
3083 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3084 rs.depth_bias.representation, dbr_info->depthBiasRepresentation);
3085 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3086 rs.depth_bias.exact, dbr_info->depthBiasExact);
3087 } else {
3088 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3089 rs.depth_bias.representation,
3090 VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT);
3091 SET_DYN_VALUE(dyn, RS_DEPTH_BIAS_FACTORS,
3092 rs.depth_bias.exact, false);
3093 }
3094 }
3095
3096 void
vk_cmd_set_rendering_attachment_locations(struct vk_command_buffer * cmd,const VkRenderingAttachmentLocationInfoKHR * info)3097 vk_cmd_set_rendering_attachment_locations(struct vk_command_buffer *cmd,
3098 const VkRenderingAttachmentLocationInfoKHR *info)
3099 {
3100 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3101
3102 assert(info->colorAttachmentCount <= MESA_VK_MAX_COLOR_ATTACHMENTS);
3103 for (uint32_t i = 0; i < info->colorAttachmentCount; i++) {
3104 const uint8_t val =
3105 info->pColorAttachmentLocations == NULL ? i :
3106 info->pColorAttachmentLocations[i] == VK_ATTACHMENT_UNUSED ?
3107 MESA_VK_ATTACHMENT_UNUSED : info->pColorAttachmentLocations[i];
3108 SET_DYN_VALUE(dyn, COLOR_ATTACHMENT_MAP, cal.color_map[i], val);
3109 }
3110 }
3111
3112 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRenderingAttachmentLocationsKHR(VkCommandBuffer commandBuffer,const VkRenderingAttachmentLocationInfoKHR * pLocationInfo)3113 vk_common_CmdSetRenderingAttachmentLocationsKHR(
3114 VkCommandBuffer commandBuffer,
3115 const VkRenderingAttachmentLocationInfoKHR* pLocationInfo)
3116 {
3117 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3118
3119 vk_cmd_set_rendering_attachment_locations(cmd, pLocationInfo);
3120 }
3121
3122 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRenderingInputAttachmentIndicesKHR(VkCommandBuffer commandBuffer,const VkRenderingInputAttachmentIndexInfoKHR * pLocationInfo)3123 vk_common_CmdSetRenderingInputAttachmentIndicesKHR(
3124 VkCommandBuffer commandBuffer,
3125 const VkRenderingInputAttachmentIndexInfoKHR* pLocationInfo)
3126 {
3127 VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
3128 struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
3129
3130 assert(pLocationInfo->colorAttachmentCount <= MESA_VK_MAX_COLOR_ATTACHMENTS);
3131 for (uint32_t i = 0; i < pLocationInfo->colorAttachmentCount; i++) {
3132 uint8_t val;
3133
3134 if (!pLocationInfo->pColorAttachmentInputIndices) {
3135 val = i;
3136 } else if (pLocationInfo->pColorAttachmentInputIndices[i] == VK_ATTACHMENT_UNUSED) {
3137 val = MESA_VK_ATTACHMENT_UNUSED;
3138 } else {
3139 val = pLocationInfo->pColorAttachmentInputIndices[i];
3140 }
3141
3142 SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP,
3143 ial.color_map[i], val);
3144 }
3145
3146 uint8_t depth_att =
3147 (pLocationInfo->pDepthInputAttachmentIndex == NULL ||
3148 *pLocationInfo->pDepthInputAttachmentIndex == VK_ATTACHMENT_UNUSED) ?
3149 MESA_VK_ATTACHMENT_UNUSED : *pLocationInfo->pDepthInputAttachmentIndex;
3150 uint8_t stencil_att =
3151 (pLocationInfo->pStencilInputAttachmentIndex == NULL ||
3152 *pLocationInfo->pStencilInputAttachmentIndex == VK_ATTACHMENT_UNUSED) ?
3153 MESA_VK_ATTACHMENT_UNUSED : *pLocationInfo->pStencilInputAttachmentIndex;
3154 SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, ial.depth_att, depth_att);
3155 SET_DYN_VALUE(dyn, INPUT_ATTACHMENT_MAP, ial.stencil_att, stencil_att);
3156 }
3157
3158 /* These are stubs required by VK_EXT_shader_object */
3159
3160 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetViewportWScalingEnableNV(VkCommandBuffer commandBuffer,VkBool32 viewportWScalingEnable)3161 vk_common_CmdSetViewportWScalingEnableNV(
3162 VkCommandBuffer commandBuffer,
3163 VkBool32 viewportWScalingEnable)
3164 {
3165 }
3166
3167 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageReductionModeNV(VkCommandBuffer commandBuffer,VkCoverageReductionModeNV coverageReductionMode)3168 vk_common_CmdSetCoverageReductionModeNV(
3169 VkCommandBuffer commandBuffer,
3170 VkCoverageReductionModeNV coverageReductionMode)
3171 {
3172 }
3173
3174 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageToColorEnableNV(VkCommandBuffer commandBuffer,VkBool32 coverageToColorEnable)3175 vk_common_CmdSetCoverageToColorEnableNV(
3176 VkCommandBuffer commandBuffer,
3177 VkBool32 coverageToColorEnable)
3178 {
3179 }
3180
3181 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageToColorLocationNV(VkCommandBuffer commandBuffer,uint32_t coverageToColorLocation)3182 vk_common_CmdSetCoverageToColorLocationNV(
3183 VkCommandBuffer commandBuffer,
3184 uint32_t coverageToColorLocation)
3185 {
3186 }
3187
3188 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageModulationModeNV(VkCommandBuffer commandBuffer,VkCoverageModulationModeNV coverageModulationMode)3189 vk_common_CmdSetCoverageModulationModeNV(
3190 VkCommandBuffer commandBuffer,
3191 VkCoverageModulationModeNV coverageModulationMode)
3192 {
3193 }
3194
3195 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageModulationTableEnableNV(VkCommandBuffer commandBuffer,VkBool32 coverageModulationTableEnable)3196 vk_common_CmdSetCoverageModulationTableEnableNV(
3197 VkCommandBuffer commandBuffer,
3198 VkBool32 coverageModulationTableEnable)
3199 {
3200 }
3201
3202 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetCoverageModulationTableNV(VkCommandBuffer commandBuffer,uint32_t coverageModulationTableCount,const float * pCoverageModulationTable)3203 vk_common_CmdSetCoverageModulationTableNV(
3204 VkCommandBuffer commandBuffer,
3205 uint32_t coverageModulationTableCount,
3206 const float* pCoverageModulationTable)
3207 {
3208 }
3209
3210 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetRepresentativeFragmentTestEnableNV(VkCommandBuffer commandBuffer,VkBool32 representativeFragmentTestEnable)3211 vk_common_CmdSetRepresentativeFragmentTestEnableNV(
3212 VkCommandBuffer commandBuffer,
3213 VkBool32 representativeFragmentTestEnable)
3214 {
3215 }
3216
3217 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetShadingRateImageEnableNV(VkCommandBuffer commandBuffer,VkBool32 shadingRateImageEnable)3218 vk_common_CmdSetShadingRateImageEnableNV(
3219 VkCommandBuffer commandBuffer,
3220 VkBool32 shadingRateImageEnable)
3221 {
3222 }
3223
3224 VKAPI_ATTR void VKAPI_CALL
vk_common_CmdSetViewportSwizzleNV(VkCommandBuffer commandBuffer,uint32_t firstViewport,uint32_t viewportCount,const VkViewportSwizzleNV * pViewportSwizzles)3225 vk_common_CmdSetViewportSwizzleNV(
3226 VkCommandBuffer commandBuffer,
3227 uint32_t firstViewport,
3228 uint32_t viewportCount,
3229 const VkViewportSwizzleNV* pViewportSwizzles)
3230 {
3231 }
3232
3233 const char *
vk_dynamic_graphic_state_to_str(enum mesa_vk_dynamic_graphics_state state)3234 vk_dynamic_graphic_state_to_str(enum mesa_vk_dynamic_graphics_state state)
3235 {
3236 #define NAME(name) \
3237 case MESA_VK_DYNAMIC_##name: return #name
3238
3239 switch (state) {
3240 NAME(VI);
3241 NAME(VI_BINDINGS_VALID);
3242 NAME(VI_BINDING_STRIDES);
3243 NAME(IA_PRIMITIVE_TOPOLOGY);
3244 NAME(IA_PRIMITIVE_RESTART_ENABLE);
3245 NAME(TS_PATCH_CONTROL_POINTS);
3246 NAME(TS_DOMAIN_ORIGIN);
3247 NAME(VP_VIEWPORT_COUNT);
3248 NAME(VP_VIEWPORTS);
3249 NAME(VP_SCISSOR_COUNT);
3250 NAME(VP_SCISSORS);
3251 NAME(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE);
3252 NAME(DR_RECTANGLES);
3253 NAME(DR_MODE);
3254 NAME(DR_ENABLE);
3255 NAME(RS_RASTERIZER_DISCARD_ENABLE);
3256 NAME(RS_DEPTH_CLAMP_ENABLE);
3257 NAME(RS_DEPTH_CLIP_ENABLE);
3258 NAME(RS_POLYGON_MODE);
3259 NAME(RS_CULL_MODE);
3260 NAME(RS_FRONT_FACE);
3261 NAME(RS_CONSERVATIVE_MODE);
3262 NAME(RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE);
3263 NAME(RS_RASTERIZATION_ORDER_AMD);
3264 NAME(RS_PROVOKING_VERTEX);
3265 NAME(RS_RASTERIZATION_STREAM);
3266 NAME(RS_DEPTH_BIAS_ENABLE);
3267 NAME(RS_DEPTH_BIAS_FACTORS);
3268 NAME(RS_LINE_WIDTH);
3269 NAME(RS_LINE_MODE);
3270 NAME(RS_LINE_STIPPLE_ENABLE);
3271 NAME(RS_LINE_STIPPLE);
3272 NAME(FSR);
3273 NAME(MS_RASTERIZATION_SAMPLES);
3274 NAME(MS_SAMPLE_MASK);
3275 NAME(MS_ALPHA_TO_COVERAGE_ENABLE);
3276 NAME(MS_ALPHA_TO_ONE_ENABLE);
3277 NAME(MS_SAMPLE_LOCATIONS_ENABLE);
3278 NAME(MS_SAMPLE_LOCATIONS);
3279 NAME(DS_DEPTH_TEST_ENABLE);
3280 NAME(DS_DEPTH_WRITE_ENABLE);
3281 NAME(DS_DEPTH_COMPARE_OP);
3282 NAME(DS_DEPTH_BOUNDS_TEST_ENABLE);
3283 NAME(DS_DEPTH_BOUNDS_TEST_BOUNDS);
3284 NAME(DS_STENCIL_TEST_ENABLE);
3285 NAME(DS_STENCIL_OP);
3286 NAME(DS_STENCIL_COMPARE_MASK);
3287 NAME(DS_STENCIL_WRITE_MASK);
3288 NAME(DS_STENCIL_REFERENCE);
3289 NAME(CB_LOGIC_OP_ENABLE);
3290 NAME(CB_LOGIC_OP);
3291 NAME(CB_ATTACHMENT_COUNT);
3292 NAME(CB_COLOR_WRITE_ENABLES);
3293 NAME(CB_BLEND_ENABLES);
3294 NAME(CB_BLEND_EQUATIONS);
3295 NAME(CB_WRITE_MASKS);
3296 NAME(CB_BLEND_CONSTANTS);
3297 NAME(ATTACHMENT_FEEDBACK_LOOP_ENABLE);
3298 NAME(COLOR_ATTACHMENT_MAP);
3299 default: unreachable("Invalid state");
3300 }
3301
3302 #undef NAME
3303 }
3304