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