vk: Remove stale finishme for stencil image views
[mesa.git] / src / vulkan / anv_meta.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29
30 #include "anv_private.h"
31 #include "anv_nir_builder.h"
32
33 static nir_shader *
34 build_nir_vertex_shader(bool attr_flat)
35 {
36 nir_builder b;
37
38 const struct glsl_type *vertex_type = glsl_vec4_type();
39
40 nir_builder_init_simple_shader(&b, MESA_SHADER_VERTEX);
41
42 nir_variable *pos_in = nir_variable_create(b.shader, "a_pos",
43 vertex_type,
44 nir_var_shader_in);
45 pos_in->data.location = VERT_ATTRIB_GENERIC0;
46 nir_variable *pos_out = nir_variable_create(b.shader, "gl_Position",
47 vertex_type,
48 nir_var_shader_out);
49 pos_in->data.location = VARYING_SLOT_POS;
50 nir_copy_var(&b, pos_out, pos_in);
51
52 /* Add one more pass-through attribute. For clear shaders, this is used
53 * to store the color and for blit shaders it's the texture coordinate.
54 */
55 const struct glsl_type *attr_type = glsl_vec4_type();
56 nir_variable *attr_in = nir_variable_create(b.shader, "a_attr", attr_type,
57 nir_var_shader_in);
58 attr_in->data.location = VERT_ATTRIB_GENERIC1;
59 nir_variable *attr_out = nir_variable_create(b.shader, "v_attr", attr_type,
60 nir_var_shader_out);
61 attr_out->data.location = VARYING_SLOT_VAR0;
62 attr_out->data.interpolation = attr_flat ? INTERP_QUALIFIER_FLAT :
63 INTERP_QUALIFIER_SMOOTH;
64 nir_copy_var(&b, attr_out, attr_in);
65
66 return b.shader;
67 }
68
69 static nir_shader *
70 build_nir_clear_fragment_shader()
71 {
72 nir_builder b;
73
74 const struct glsl_type *color_type = glsl_vec4_type();
75
76 nir_builder_init_simple_shader(&b, MESA_SHADER_FRAGMENT);
77
78 nir_variable *color_in = nir_variable_create(b.shader, "v_attr",
79 color_type,
80 nir_var_shader_in);
81 color_in->data.location = VARYING_SLOT_VAR0;
82 color_in->data.interpolation = INTERP_QUALIFIER_FLAT;
83 nir_variable *color_out = nir_variable_create(b.shader, "f_color",
84 color_type,
85 nir_var_shader_out);
86 color_out->data.location = FRAG_RESULT_DATA0;
87 nir_copy_var(&b, color_out, color_in);
88
89 return b.shader;
90 }
91
92 static nir_shader *
93 build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim)
94 {
95 nir_builder b;
96
97 nir_builder_init_simple_shader(&b, MESA_SHADER_FRAGMENT);
98
99 const struct glsl_type *color_type = glsl_vec4_type();
100
101 nir_variable *tex_pos_in = nir_variable_create(b.shader, "v_attr",
102 glsl_vec4_type(),
103 nir_var_shader_in);
104 tex_pos_in->data.location = VARYING_SLOT_VAR0;
105
106 const struct glsl_type *sampler_type =
107 glsl_sampler_type(tex_dim, false, false, glsl_get_base_type(color_type));
108 nir_variable *sampler = nir_variable_create(b.shader, "s_tex", sampler_type,
109 nir_var_uniform);
110 sampler->data.descriptor_set = 0;
111 sampler->data.binding = 0;
112
113 nir_tex_instr *tex = nir_tex_instr_create(b.shader, 1);
114 tex->sampler_dim = tex_dim;
115 tex->op = nir_texop_tex;
116 tex->src[0].src_type = nir_tex_src_coord;
117 tex->src[0].src = nir_src_for_ssa(nir_load_var(&b, tex_pos_in));
118 tex->dest_type = nir_type_float; /* TODO */
119
120 switch (tex_dim) {
121 case GLSL_SAMPLER_DIM_2D:
122 tex->coord_components = 2;
123 break;
124 case GLSL_SAMPLER_DIM_3D:
125 tex->coord_components = 3;
126 break;
127 default:
128 assert(!"Unsupported texture dimension");
129 }
130
131 tex->sampler = nir_deref_var_create(tex, sampler);
132
133 nir_ssa_dest_init(&tex->instr, &tex->dest, 4, "tex");
134 nir_builder_instr_insert(&b, &tex->instr);
135
136 nir_variable *color_out = nir_variable_create(b.shader, "f_color",
137 color_type,
138 nir_var_shader_out);
139 color_out->data.location = FRAG_RESULT_DATA0;
140 nir_store_var(&b, color_out, &tex->dest.ssa);
141
142 return b.shader;
143 }
144
145 static void
146 anv_device_init_meta_clear_state(struct anv_device *device)
147 {
148 struct anv_shader_module vsm = {
149 .nir = build_nir_vertex_shader(true),
150 };
151
152 struct anv_shader_module fsm = {
153 .nir = build_nir_clear_fragment_shader(),
154 };
155
156 VkShader vs;
157 anv_CreateShader(anv_device_to_handle(device),
158 &(VkShaderCreateInfo) {
159 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
160 .module = anv_shader_module_to_handle(&vsm),
161 .pName = "main",
162 }, &vs);
163
164 VkShader fs;
165 anv_CreateShader(anv_device_to_handle(device),
166 &(VkShaderCreateInfo) {
167 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
168 .module = anv_shader_module_to_handle(&fsm),
169 .pName = "main",
170 }, &fs);
171
172 /* We use instanced rendering to clear multiple render targets. We have two
173 * vertex buffers: the first vertex buffer holds per-vertex data and
174 * provides the vertices for the clear rectangle. The second one holds
175 * per-instance data, which consists of the VUE header (which selects the
176 * layer) and the color (Vulkan supports per-RT clear colors).
177 */
178 VkPipelineVertexInputStateCreateInfo vi_create_info = {
179 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
180 .bindingCount = 2,
181 .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
182 {
183 .binding = 0,
184 .strideInBytes = 12,
185 .stepRate = VK_VERTEX_INPUT_STEP_RATE_VERTEX
186 },
187 {
188 .binding = 1,
189 .strideInBytes = 32,
190 .stepRate = VK_VERTEX_INPUT_STEP_RATE_INSTANCE
191 },
192 },
193 .attributeCount = 3,
194 .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
195 {
196 /* VUE Header */
197 .location = 0,
198 .binding = 1,
199 .format = VK_FORMAT_R32G32B32A32_UINT,
200 .offsetInBytes = 0
201 },
202 {
203 /* Position */
204 .location = 1,
205 .binding = 0,
206 .format = VK_FORMAT_R32G32B32_SFLOAT,
207 .offsetInBytes = 0
208 },
209 {
210 /* Color */
211 .location = 2,
212 .binding = 1,
213 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
214 .offsetInBytes = 16
215 }
216 }
217 };
218
219 anv_graphics_pipeline_create(anv_device_to_handle(device),
220 &(VkGraphicsPipelineCreateInfo) {
221 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
222
223 .stageCount = 2,
224 .pStages = (VkPipelineShaderStageCreateInfo[]) {
225 {
226 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
227 .stage = VK_SHADER_STAGE_VERTEX,
228 .shader = vs,
229 .pSpecializationInfo = NULL
230 }, {
231 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
232 .stage = VK_SHADER_STAGE_FRAGMENT,
233 .shader = fs,
234 .pSpecializationInfo = NULL,
235 }
236 },
237 .pVertexInputState = &vi_create_info,
238 .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
239 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
240 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
241 .primitiveRestartEnable = false,
242 },
243 .pRasterState = &(VkPipelineRasterStateCreateInfo) {
244 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO,
245 .depthClipEnable = true,
246 .rasterizerDiscardEnable = false,
247 .fillMode = VK_FILL_MODE_SOLID,
248 .cullMode = VK_CULL_MODE_NONE,
249 .frontFace = VK_FRONT_FACE_CCW
250 },
251 .pDepthStencilState = &(VkPipelineDepthStencilStateCreateInfo) {
252 .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
253 .depthTestEnable = true,
254 .depthWriteEnable = true,
255 .depthCompareOp = VK_COMPARE_OP_ALWAYS,
256 .depthBoundsTestEnable = false,
257 .stencilTestEnable = true,
258 .front = (VkStencilOpState) {
259 .stencilPassOp = VK_STENCIL_OP_REPLACE,
260 .stencilCompareOp = VK_COMPARE_OP_ALWAYS,
261 },
262 .back = (VkStencilOpState) {
263 .stencilPassOp = VK_STENCIL_OP_REPLACE,
264 .stencilCompareOp = VK_COMPARE_OP_ALWAYS,
265 },
266 },
267 .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
268 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
269 .attachmentCount = 1,
270 .pAttachments = (VkPipelineColorBlendAttachmentState []) {
271 { .channelWriteMask = VK_CHANNEL_A_BIT |
272 VK_CHANNEL_R_BIT | VK_CHANNEL_G_BIT | VK_CHANNEL_B_BIT },
273 }
274 },
275 .flags = 0,
276 },
277 &(struct anv_graphics_pipeline_create_info) {
278 .use_repclear = true,
279 .disable_viewport = true,
280 .disable_vs = true,
281 .use_rectlist = true
282 },
283 &device->meta_state.clear.pipeline);
284
285 anv_DestroyShader(anv_device_to_handle(device), vs);
286 anv_DestroyShader(anv_device_to_handle(device), fs);
287 ralloc_free(vsm.nir);
288 ralloc_free(fsm.nir);
289 }
290
291 #define NUM_VB_USED 2
292 struct anv_saved_state {
293 struct anv_vertex_binding old_vertex_bindings[NUM_VB_USED];
294 struct anv_descriptor_set *old_descriptor_set0;
295 struct anv_pipeline *old_pipeline;
296 struct anv_dynamic_ds_state *old_ds_state;
297 struct anv_dynamic_cb_state *old_cb_state;
298 };
299
300 static void
301 anv_cmd_buffer_save(struct anv_cmd_buffer *cmd_buffer,
302 struct anv_saved_state *state)
303 {
304 state->old_pipeline = cmd_buffer->state.pipeline;
305 state->old_descriptor_set0 = cmd_buffer->state.descriptors[0].set;
306 memcpy(state->old_vertex_bindings, cmd_buffer->state.vertex_bindings,
307 sizeof(state->old_vertex_bindings));
308 state->old_ds_state = cmd_buffer->state.ds_state;
309 state->old_cb_state = cmd_buffer->state.cb_state;
310 }
311
312 static void
313 anv_cmd_buffer_restore(struct anv_cmd_buffer *cmd_buffer,
314 const struct anv_saved_state *state)
315 {
316 cmd_buffer->state.pipeline = state->old_pipeline;
317 cmd_buffer->state.descriptors[0].set = state->old_descriptor_set0;
318 memcpy(cmd_buffer->state.vertex_bindings, state->old_vertex_bindings,
319 sizeof(state->old_vertex_bindings));
320
321 cmd_buffer->state.vb_dirty |= (1 << NUM_VB_USED) - 1;
322 cmd_buffer->state.dirty |= ANV_CMD_BUFFER_PIPELINE_DIRTY;
323 cmd_buffer->state.descriptors_dirty |= VK_SHADER_STAGE_VERTEX_BIT;
324
325 if (cmd_buffer->state.ds_state != state->old_ds_state) {
326 cmd_buffer->state.ds_state = state->old_ds_state;
327 cmd_buffer->state.dirty |= ANV_CMD_BUFFER_DS_DIRTY;
328 }
329
330 if (cmd_buffer->state.cb_state != state->old_cb_state) {
331 cmd_buffer->state.cb_state = state->old_cb_state;
332 cmd_buffer->state.dirty |= ANV_CMD_BUFFER_CB_DIRTY;
333 }
334 }
335
336 struct vue_header {
337 uint32_t Reserved;
338 uint32_t RTAIndex;
339 uint32_t ViewportIndex;
340 float PointWidth;
341 };
342
343 struct clear_instance_data {
344 struct vue_header vue_header;
345 VkClearColorValue color;
346 };
347
348 static void
349 meta_emit_clear(struct anv_cmd_buffer *cmd_buffer,
350 int num_instances,
351 struct clear_instance_data *instance_data,
352 VkClearDepthStencilValue ds_clear_value)
353 {
354 struct anv_device *device = cmd_buffer->device;
355 struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
356 struct anv_state state;
357 uint32_t size;
358
359 const float vertex_data[] = {
360 /* Rect-list coordinates */
361 0.0, 0.0, ds_clear_value.depth,
362 fb->width, 0.0, ds_clear_value.depth,
363 fb->width, fb->height, ds_clear_value.depth,
364
365 /* Align to 16 bytes */
366 0.0, 0.0, 0.0,
367 };
368
369 size = sizeof(vertex_data) + num_instances * sizeof(*instance_data);
370 state = anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, size, 16);
371
372 /* Copy in the vertex and instance data */
373 memcpy(state.map, vertex_data, sizeof(vertex_data));
374 memcpy(state.map + sizeof(vertex_data), instance_data,
375 num_instances * sizeof(*instance_data));
376
377 struct anv_buffer vertex_buffer = {
378 .device = cmd_buffer->device,
379 .size = size,
380 .bo = &device->dynamic_state_block_pool.bo,
381 .offset = state.offset
382 };
383
384 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer), 0, 2,
385 (VkBuffer[]) {
386 anv_buffer_to_handle(&vertex_buffer),
387 anv_buffer_to_handle(&vertex_buffer)
388 },
389 (VkDeviceSize[]) {
390 0,
391 sizeof(vertex_data)
392 });
393
394 if (cmd_buffer->state.pipeline != anv_pipeline_from_handle(device->meta_state.clear.pipeline))
395 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer),
396 VK_PIPELINE_BIND_POINT_GRAPHICS,
397 device->meta_state.clear.pipeline);
398
399 /* We don't need anything here, only set if not already set. */
400 if (cmd_buffer->state.rs_state == NULL)
401 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer),
402 device->meta_state.shared.rs_state);
403
404 if (cmd_buffer->state.vp_state == NULL)
405 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer),
406 cmd_buffer->state.framebuffer->vp_state);
407
408 if (cmd_buffer->state.ds_state == NULL)
409 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer),
410 device->meta_state.shared.ds_state);
411
412 if (cmd_buffer->state.cb_state == NULL)
413 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer),
414 device->meta_state.shared.cb_state);
415
416 ANV_CALL(CmdDraw)(anv_cmd_buffer_to_handle(cmd_buffer),
417 3, num_instances, 0, 0);
418 }
419
420 void
421 anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer *cmd_buffer,
422 struct anv_render_pass *pass,
423 const VkClearValue *clear_values)
424 {
425 struct anv_saved_state saved_state;
426
427 if (pass->has_stencil_clear_attachment)
428 anv_finishme("stencil clear");
429
430 /* FINISHME: Rethink how we count clear attachments in light of
431 * 0.138.2 -> 0.170.2 diff.
432 */
433 if (pass->num_color_clear_attachments == 0 &&
434 !pass->has_depth_clear_attachment)
435 return;
436
437 struct clear_instance_data instance_data[pass->num_color_clear_attachments];
438 uint32_t color_attachments[pass->num_color_clear_attachments];
439 uint32_t ds_attachment = VK_ATTACHMENT_UNUSED;
440 VkClearDepthStencilValue ds_clear_value = {0};
441
442 int layer = 0;
443 for (uint32_t i = 0; i < pass->attachment_count; i++) {
444 const struct anv_render_pass_attachment *att = &pass->attachments[i];
445
446 if (att->load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
447 if (anv_format_is_color(att->format)) {
448 instance_data[layer] = (struct clear_instance_data) {
449 .vue_header = {
450 .RTAIndex = i,
451 .ViewportIndex = 0,
452 .PointWidth = 0.0
453 },
454 .color = clear_values[i].color,
455 };
456 color_attachments[layer] = i;
457 layer++;
458 } else if (att->format->depth_format) {
459 assert(ds_attachment == VK_ATTACHMENT_UNUSED);
460 ds_attachment = i;
461 ds_clear_value = clear_values[ds_attachment].depthStencil;
462 }
463 } else if (att->stencil_load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
464 assert(att->format->has_stencil);
465 anv_finishme("stencil clear");
466 }
467 }
468
469 anv_cmd_buffer_save(cmd_buffer, &saved_state);
470
471 struct anv_subpass subpass = {
472 .input_count = 0,
473 .color_count = pass->num_color_clear_attachments,
474 .color_attachments = color_attachments,
475 .depth_stencil_attachment = ds_attachment,
476 };
477
478 anv_cmd_buffer_begin_subpass(cmd_buffer, &subpass);
479
480 meta_emit_clear(cmd_buffer, pass->num_color_clear_attachments,
481 instance_data, ds_clear_value);
482
483 /* Restore API state */
484 anv_cmd_buffer_restore(cmd_buffer, &saved_state);
485 }
486
487 static VkImageViewType
488 meta_blit_get_src_image_view_type(const struct anv_image *src_image)
489 {
490 switch (src_image->type) {
491 case VK_IMAGE_TYPE_1D:
492 return VK_IMAGE_VIEW_TYPE_1D;
493 case VK_IMAGE_TYPE_2D:
494 return VK_IMAGE_VIEW_TYPE_2D;
495 case VK_IMAGE_TYPE_3D:
496 return VK_IMAGE_VIEW_TYPE_3D;
497 default:
498 assert(!"bad VkImageType");
499 return 0;
500 }
501 }
502
503 static uint32_t
504 meta_blit_get_dest_view_base_array_slice(const struct anv_image *dest_image,
505 const VkImageSubresourceCopy *dest_subresource,
506 const VkOffset3D *dest_offset)
507 {
508 switch (dest_image->type) {
509 case VK_IMAGE_TYPE_1D:
510 case VK_IMAGE_TYPE_2D:
511 return dest_subresource->arrayLayer;
512 case VK_IMAGE_TYPE_3D:
513 /* HACK: Vulkan does not allow attaching a 3D image to a framebuffer,
514 * but meta does it anyway. When doing so, we translate the
515 * destination's z offset into an array offset.
516 */
517 return dest_offset->z;
518 default:
519 assert(!"bad VkImageType");
520 return 0;
521 }
522 }
523
524 static void
525 anv_device_init_meta_blit_state(struct anv_device *device)
526 {
527 /* We don't use a vertex shader for clearing, but instead build and pass
528 * the VUEs directly to the rasterization backend. However, we do need
529 * to provide GLSL source for the vertex shader so that the compiler
530 * does not dead-code our inputs.
531 */
532 struct anv_shader_module vsm = {
533 .nir = build_nir_vertex_shader(false),
534 };
535
536 struct anv_shader_module fsm_2d = {
537 .nir = build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_2D),
538 };
539
540 struct anv_shader_module fsm_3d = {
541 .nir = build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_3D),
542 };
543
544 VkShader vs;
545 anv_CreateShader(anv_device_to_handle(device),
546 &(VkShaderCreateInfo) {
547 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
548 .module = anv_shader_module_to_handle(&vsm),
549 .pName = "main",
550 }, &vs);
551
552 VkShader fs_2d;
553 anv_CreateShader(anv_device_to_handle(device),
554 &(VkShaderCreateInfo) {
555 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
556 .module = anv_shader_module_to_handle(&fsm_2d),
557 .pName = "main",
558 }, &fs_2d);
559
560 VkShader fs_3d;
561 anv_CreateShader(anv_device_to_handle(device),
562 &(VkShaderCreateInfo) {
563 .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO,
564 .module = anv_shader_module_to_handle(&fsm_3d),
565 .pName = "main",
566 }, &fs_3d);
567
568 VkPipelineVertexInputStateCreateInfo vi_create_info = {
569 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
570 .bindingCount = 2,
571 .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
572 {
573 .binding = 0,
574 .strideInBytes = 0,
575 .stepRate = VK_VERTEX_INPUT_STEP_RATE_VERTEX
576 },
577 {
578 .binding = 1,
579 .strideInBytes = 5 * sizeof(float),
580 .stepRate = VK_VERTEX_INPUT_STEP_RATE_VERTEX
581 },
582 },
583 .attributeCount = 3,
584 .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
585 {
586 /* VUE Header */
587 .location = 0,
588 .binding = 0,
589 .format = VK_FORMAT_R32G32B32A32_UINT,
590 .offsetInBytes = 0
591 },
592 {
593 /* Position */
594 .location = 1,
595 .binding = 1,
596 .format = VK_FORMAT_R32G32_SFLOAT,
597 .offsetInBytes = 0
598 },
599 {
600 /* Texture Coordinate */
601 .location = 2,
602 .binding = 1,
603 .format = VK_FORMAT_R32G32B32_SFLOAT,
604 .offsetInBytes = 8
605 }
606 }
607 };
608
609 VkDescriptorSetLayoutCreateInfo ds_layout_info = {
610 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
611 .count = 1,
612 .pBinding = (VkDescriptorSetLayoutBinding[]) {
613 {
614 .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
615 .arraySize = 1,
616 .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
617 .pImmutableSamplers = NULL
618 },
619 }
620 };
621 anv_CreateDescriptorSetLayout(anv_device_to_handle(device), &ds_layout_info,
622 &device->meta_state.blit.ds_layout);
623
624 anv_CreatePipelineLayout(anv_device_to_handle(device),
625 &(VkPipelineLayoutCreateInfo) {
626 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
627 .descriptorSetCount = 1,
628 .pSetLayouts = &device->meta_state.blit.ds_layout,
629 },
630 &device->meta_state.blit.pipeline_layout);
631
632 VkPipelineShaderStageCreateInfo pipeline_shader_stages[] = {
633 {
634 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
635 .stage = VK_SHADER_STAGE_VERTEX,
636 .shader = vs,
637 .pSpecializationInfo = NULL
638 }, {
639 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
640 .stage = VK_SHADER_STAGE_FRAGMENT,
641 .shader = {0}, /* TEMPLATE VALUE! FILL ME IN! */
642 .pSpecializationInfo = NULL
643 },
644 };
645
646 const VkGraphicsPipelineCreateInfo vk_pipeline_info = {
647 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
648 .stageCount = ARRAY_SIZE(pipeline_shader_stages),
649 .pStages = pipeline_shader_stages,
650 .pVertexInputState = &vi_create_info,
651 .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
652 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
653 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
654 .primitiveRestartEnable = false,
655 },
656 .pRasterState = &(VkPipelineRasterStateCreateInfo) {
657 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO,
658 .depthClipEnable = true,
659 .rasterizerDiscardEnable = false,
660 .fillMode = VK_FILL_MODE_SOLID,
661 .cullMode = VK_CULL_MODE_NONE,
662 .frontFace = VK_FRONT_FACE_CCW
663 },
664 .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
665 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
666 .attachmentCount = 1,
667 .pAttachments = (VkPipelineColorBlendAttachmentState []) {
668 { .channelWriteMask = VK_CHANNEL_A_BIT |
669 VK_CHANNEL_R_BIT | VK_CHANNEL_G_BIT | VK_CHANNEL_B_BIT },
670 }
671 },
672 .flags = 0,
673 .layout = device->meta_state.blit.pipeline_layout,
674 };
675
676 const struct anv_graphics_pipeline_create_info anv_pipeline_info = {
677 .use_repclear = false,
678 .disable_viewport = true,
679 .disable_scissor = true,
680 .disable_vs = true,
681 .use_rectlist = true
682 };
683
684 pipeline_shader_stages[1].shader = fs_2d;
685 anv_graphics_pipeline_create(anv_device_to_handle(device),
686 &vk_pipeline_info, &anv_pipeline_info,
687 &device->meta_state.blit.pipeline_2d_src);
688
689 pipeline_shader_stages[1].shader = fs_3d;
690 anv_graphics_pipeline_create(anv_device_to_handle(device),
691 &vk_pipeline_info, &anv_pipeline_info,
692 &device->meta_state.blit.pipeline_3d_src);
693
694 anv_DestroyShader(anv_device_to_handle(device), vs);
695 anv_DestroyShader(anv_device_to_handle(device), fs_2d);
696 anv_DestroyShader(anv_device_to_handle(device), fs_3d);
697 ralloc_free(vsm.nir);
698 ralloc_free(fsm_2d.nir);
699 ralloc_free(fsm_3d.nir);
700 }
701
702 static void
703 meta_prepare_blit(struct anv_cmd_buffer *cmd_buffer,
704 struct anv_saved_state *saved_state)
705 {
706 struct anv_device *device = cmd_buffer->device;
707
708 anv_cmd_buffer_save(cmd_buffer, saved_state);
709
710 /* We don't need anything here, only set if not already set. */
711 if (cmd_buffer->state.rs_state == NULL)
712 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer),
713 device->meta_state.shared.rs_state);
714 if (cmd_buffer->state.ds_state == NULL)
715 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer),
716 device->meta_state.shared.ds_state);
717
718 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer),
719 device->meta_state.shared.cb_state);
720 }
721
722 struct blit_region {
723 VkOffset3D src_offset;
724 VkExtent3D src_extent;
725 VkOffset3D dest_offset;
726 VkExtent3D dest_extent;
727 };
728
729 static void
730 meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
731 struct anv_image *src_image,
732 struct anv_image_view *src_iview,
733 VkOffset3D src_offset,
734 VkExtent3D src_extent,
735 struct anv_image *dest_image,
736 struct anv_image_view *dest_iview,
737 VkOffset3D dest_offset,
738 VkExtent3D dest_extent)
739 {
740 struct anv_device *device = cmd_buffer->device;
741
742 VkImageView dest_iview_h = anv_image_view_to_handle(dest_iview);
743 VkAttachmentView dest_aview_h = { .handle = dest_iview_h.handle };
744
745 VkDescriptorPool dummy_desc_pool = { .handle = 1 };
746
747 struct blit_vb_data {
748 float pos[2];
749 float tex_coord[3];
750 } *vb_data;
751
752 unsigned vb_size = sizeof(struct vue_header) + 3 * sizeof(*vb_data);
753
754 struct anv_state vb_state =
755 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, vb_size, 16);
756 memset(vb_state.map, 0, sizeof(struct vue_header));
757 vb_data = vb_state.map + sizeof(struct vue_header);
758
759 vb_data[0] = (struct blit_vb_data) {
760 .pos = {
761 dest_offset.x + dest_extent.width,
762 dest_offset.y + dest_extent.height,
763 },
764 .tex_coord = {
765 (float)(src_offset.x + src_extent.width) / (float)src_iview->extent.width,
766 (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
767 (float)(src_offset.z + src_extent.depth) / (float)src_iview->extent.depth,
768 },
769 };
770
771 vb_data[1] = (struct blit_vb_data) {
772 .pos = {
773 dest_offset.x,
774 dest_offset.y + dest_extent.height,
775 },
776 .tex_coord = {
777 (float)src_offset.x / (float)src_iview->extent.width,
778 (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
779 (float)(src_offset.z + src_extent.depth) / (float)src_iview->extent.depth,
780 },
781 };
782
783 vb_data[2] = (struct blit_vb_data) {
784 .pos = {
785 dest_offset.x,
786 dest_offset.y,
787 },
788 .tex_coord = {
789 (float)src_offset.x / (float)src_iview->extent.width,
790 (float)src_offset.y / (float)src_iview->extent.height,
791 (float)src_offset.z / (float)src_iview->extent.depth,
792 },
793 };
794
795 struct anv_buffer vertex_buffer = {
796 .device = device,
797 .size = vb_size,
798 .bo = &device->dynamic_state_block_pool.bo,
799 .offset = vb_state.offset,
800 };
801
802 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer), 0, 2,
803 (VkBuffer[]) {
804 anv_buffer_to_handle(&vertex_buffer),
805 anv_buffer_to_handle(&vertex_buffer)
806 },
807 (VkDeviceSize[]) {
808 0,
809 sizeof(struct vue_header),
810 });
811
812 VkDescriptorSet set;
813 anv_AllocDescriptorSets(anv_device_to_handle(device), dummy_desc_pool,
814 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT,
815 1, &device->meta_state.blit.ds_layout, &set);
816 anv_UpdateDescriptorSets(anv_device_to_handle(device),
817 1, /* writeCount */
818 (VkWriteDescriptorSet[]) {
819 {
820 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
821 .destSet = set,
822 .destBinding = 0,
823 .destArrayElement = 0,
824 .count = 1,
825 .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
826 .pDescriptors = (VkDescriptorInfo[]) {
827 {
828 .imageView = anv_image_view_to_handle(src_iview),
829 .imageLayout = VK_IMAGE_LAYOUT_GENERAL
830 },
831 }
832 }
833 }, 0, NULL);
834
835 VkFramebuffer fb;
836 anv_CreateFramebuffer(anv_device_to_handle(device),
837 &(VkFramebufferCreateInfo) {
838 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
839 .attachmentCount = 1,
840 .pAttachments = (VkAttachmentBindInfo[]) {
841 {
842 .view = dest_aview_h,
843 .layout = VK_IMAGE_LAYOUT_GENERAL
844 }
845 },
846 .width = dest_iview->extent.width,
847 .height = dest_iview->extent.height,
848 .layers = 1
849 }, &fb);
850
851 VkRenderPass pass;
852 anv_CreateRenderPass(anv_device_to_handle(device),
853 &(VkRenderPassCreateInfo) {
854 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
855 .attachmentCount = 1,
856 .pAttachments = &(VkAttachmentDescription) {
857 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
858 .format = dest_iview->format->vk_format,
859 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
860 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
861 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
862 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
863 },
864 .subpassCount = 1,
865 .pSubpasses = &(VkSubpassDescription) {
866 .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION,
867 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
868 .inputCount = 0,
869 .colorCount = 1,
870 .pColorAttachments = &(VkAttachmentReference) {
871 .attachment = 0,
872 .layout = VK_IMAGE_LAYOUT_GENERAL,
873 },
874 .pResolveAttachments = NULL,
875 .depthStencilAttachment = (VkAttachmentReference) {
876 .attachment = VK_ATTACHMENT_UNUSED,
877 .layout = VK_IMAGE_LAYOUT_GENERAL,
878 },
879 .preserveCount = 1,
880 .pPreserveAttachments = &(VkAttachmentReference) {
881 .attachment = 0,
882 .layout = VK_IMAGE_LAYOUT_GENERAL,
883 },
884 },
885 .dependencyCount = 0,
886 }, &pass);
887
888 ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
889 &(VkRenderPassBeginInfo) {
890 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
891 .renderPass = pass,
892 .framebuffer = fb,
893 .renderArea = {
894 .offset = { dest_offset.x, dest_offset.y },
895 .extent = { dest_extent.width, dest_extent.height },
896 },
897 .clearValueCount = 0,
898 .pClearValues = NULL,
899 }, VK_RENDER_PASS_CONTENTS_INLINE);
900
901 VkPipeline pipeline;
902
903 switch (src_image->type) {
904 case VK_IMAGE_TYPE_1D:
905 anv_finishme("VK_IMAGE_TYPE_1D");
906 pipeline = device->meta_state.blit.pipeline_2d_src;
907 break;
908 case VK_IMAGE_TYPE_2D:
909 pipeline = device->meta_state.blit.pipeline_2d_src;
910 break;
911 case VK_IMAGE_TYPE_3D:
912 pipeline = device->meta_state.blit.pipeline_3d_src;
913 break;
914 default:
915 unreachable(!"bad VkImageType");
916 }
917
918 if (cmd_buffer->state.pipeline != anv_pipeline_from_handle(pipeline)) {
919 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer),
920 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
921 }
922
923 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer),
924 anv_framebuffer_from_handle(fb)->vp_state);
925
926 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer),
927 VK_PIPELINE_BIND_POINT_GRAPHICS,
928 device->meta_state.blit.pipeline_layout, 0, 1,
929 &set, 0, NULL);
930
931 ANV_CALL(CmdDraw)(anv_cmd_buffer_to_handle(cmd_buffer), 3, 1, 0, 0);
932
933 ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
934
935 /* At the point where we emit the draw call, all data from the
936 * descriptor sets, etc. has been used. We are free to delete it.
937 */
938 anv_descriptor_set_destroy(device, anv_descriptor_set_from_handle(set));
939 anv_DestroyFramebuffer(anv_device_to_handle(device), fb);
940 anv_DestroyRenderPass(anv_device_to_handle(device), pass);
941 }
942
943 static void
944 meta_finish_blit(struct anv_cmd_buffer *cmd_buffer,
945 const struct anv_saved_state *saved_state)
946 {
947 anv_cmd_buffer_restore(cmd_buffer, saved_state);
948 }
949
950 static VkFormat
951 vk_format_for_cpp(int cpp)
952 {
953 switch (cpp) {
954 case 1: return VK_FORMAT_R8_UINT;
955 case 2: return VK_FORMAT_R8G8_UINT;
956 case 3: return VK_FORMAT_R8G8B8_UINT;
957 case 4: return VK_FORMAT_R8G8B8A8_UINT;
958 case 6: return VK_FORMAT_R16G16B16_UINT;
959 case 8: return VK_FORMAT_R16G16B16A16_UINT;
960 case 12: return VK_FORMAT_R32G32B32_UINT;
961 case 16: return VK_FORMAT_R32G32B32A32_UINT;
962 default:
963 unreachable("Invalid format cpp");
964 }
965 }
966
967 static void
968 do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
969 struct anv_bo *src, uint64_t src_offset,
970 struct anv_bo *dest, uint64_t dest_offset,
971 int width, int height, VkFormat copy_format)
972 {
973 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
974
975 VkImageCreateInfo image_info = {
976 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
977 .imageType = VK_IMAGE_TYPE_2D,
978 .format = copy_format,
979 .extent = {
980 .width = width,
981 .height = height,
982 .depth = 1,
983 },
984 .mipLevels = 1,
985 .arraySize = 1,
986 .samples = 1,
987 .tiling = VK_IMAGE_TILING_LINEAR,
988 .usage = 0,
989 .flags = 0,
990 };
991
992 VkImage src_image;
993 image_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
994 anv_CreateImage(vk_device, &image_info, &src_image);
995
996 VkImage dest_image;
997 image_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
998 anv_CreateImage(vk_device, &image_info, &dest_image);
999
1000 /* We could use a vk call to bind memory, but that would require
1001 * creating a dummy memory object etc. so there's really no point.
1002 */
1003 anv_image_from_handle(src_image)->bo = src;
1004 anv_image_from_handle(src_image)->offset = src_offset;
1005 anv_image_from_handle(dest_image)->bo = dest;
1006 anv_image_from_handle(dest_image)->offset = dest_offset;
1007
1008 struct anv_image_view src_iview;
1009 anv_image_view_init(&src_iview, cmd_buffer->device,
1010 &(VkImageViewCreateInfo) {
1011 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1012 .image = src_image,
1013 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1014 .format = copy_format,
1015 .channels = {
1016 VK_CHANNEL_SWIZZLE_R,
1017 VK_CHANNEL_SWIZZLE_G,
1018 VK_CHANNEL_SWIZZLE_B,
1019 VK_CHANNEL_SWIZZLE_A
1020 },
1021 .subresourceRange = {
1022 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1023 .baseMipLevel = 0,
1024 .mipLevels = 1,
1025 .baseArrayLayer = 0,
1026 .arraySize = 1
1027 },
1028 },
1029 cmd_buffer);
1030
1031 struct anv_image_view dest_iview;
1032 anv_color_attachment_view_init(&dest_iview, cmd_buffer->device,
1033 &(VkAttachmentViewCreateInfo) {
1034 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1035 .image = dest_image,
1036 .format = copy_format,
1037 .mipLevel = 0,
1038 .baseArraySlice = 0,
1039 .arraySize = 1,
1040 },
1041 cmd_buffer);
1042
1043 meta_emit_blit(cmd_buffer,
1044 anv_image_from_handle(src_image),
1045 &src_iview,
1046 (VkOffset3D) { 0, 0, 0 },
1047 (VkExtent3D) { width, height, 1 },
1048 anv_image_from_handle(dest_image),
1049 &dest_iview,
1050 (VkOffset3D) { 0, 0, 0 },
1051 (VkExtent3D) { width, height, 1 });
1052
1053 anv_DestroyImage(vk_device, src_image);
1054 anv_DestroyImage(vk_device, dest_image);
1055 }
1056
1057 void anv_CmdCopyBuffer(
1058 VkCmdBuffer cmdBuffer,
1059 VkBuffer srcBuffer,
1060 VkBuffer destBuffer,
1061 uint32_t regionCount,
1062 const VkBufferCopy* pRegions)
1063 {
1064 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1065 ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
1066 ANV_FROM_HANDLE(anv_buffer, dest_buffer, destBuffer);
1067
1068 struct anv_saved_state saved_state;
1069
1070 meta_prepare_blit(cmd_buffer, &saved_state);
1071
1072 for (unsigned r = 0; r < regionCount; r++) {
1073 uint64_t src_offset = src_buffer->offset + pRegions[r].srcOffset;
1074 uint64_t dest_offset = dest_buffer->offset + pRegions[r].destOffset;
1075 uint64_t copy_size = pRegions[r].copySize;
1076
1077 /* First, we compute the biggest format that can be used with the
1078 * given offsets and size.
1079 */
1080 int cpp = 16;
1081
1082 int fs = ffs(src_offset) - 1;
1083 if (fs != -1)
1084 cpp = MIN2(cpp, 1 << fs);
1085 assert(src_offset % cpp == 0);
1086
1087 fs = ffs(dest_offset) - 1;
1088 if (fs != -1)
1089 cpp = MIN2(cpp, 1 << fs);
1090 assert(dest_offset % cpp == 0);
1091
1092 fs = ffs(pRegions[r].copySize) - 1;
1093 if (fs != -1)
1094 cpp = MIN2(cpp, 1 << fs);
1095 assert(pRegions[r].copySize % cpp == 0);
1096
1097 VkFormat copy_format = vk_format_for_cpp(cpp);
1098
1099 /* This is maximum possible width/height our HW can handle */
1100 uint64_t max_surface_dim = 1 << 14;
1101
1102 /* First, we make a bunch of max-sized copies */
1103 uint64_t max_copy_size = max_surface_dim * max_surface_dim * cpp;
1104 while (copy_size > max_copy_size) {
1105 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1106 dest_buffer->bo, dest_offset,
1107 max_surface_dim, max_surface_dim, copy_format);
1108 copy_size -= max_copy_size;
1109 src_offset += max_copy_size;
1110 dest_offset += max_copy_size;
1111 }
1112
1113 uint64_t height = copy_size / (max_surface_dim * cpp);
1114 assert(height < max_surface_dim);
1115 if (height != 0) {
1116 uint64_t rect_copy_size = height * max_surface_dim * cpp;
1117 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1118 dest_buffer->bo, dest_offset,
1119 max_surface_dim, height, copy_format);
1120 copy_size -= rect_copy_size;
1121 src_offset += rect_copy_size;
1122 dest_offset += rect_copy_size;
1123 }
1124
1125 if (copy_size != 0) {
1126 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1127 dest_buffer->bo, dest_offset,
1128 copy_size / cpp, 1, copy_format);
1129 }
1130 }
1131
1132 meta_finish_blit(cmd_buffer, &saved_state);
1133 }
1134
1135 void anv_CmdCopyImage(
1136 VkCmdBuffer cmdBuffer,
1137 VkImage srcImage,
1138 VkImageLayout srcImageLayout,
1139 VkImage destImage,
1140 VkImageLayout destImageLayout,
1141 uint32_t regionCount,
1142 const VkImageCopy* pRegions)
1143 {
1144 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1145 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1146 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1147
1148 const VkImageViewType src_iview_type =
1149 meta_blit_get_src_image_view_type(src_image);
1150
1151 struct anv_saved_state saved_state;
1152
1153 meta_prepare_blit(cmd_buffer, &saved_state);
1154
1155 for (unsigned r = 0; r < regionCount; r++) {
1156 struct anv_image_view src_iview;
1157 anv_image_view_init(&src_iview, cmd_buffer->device,
1158 &(VkImageViewCreateInfo) {
1159 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1160 .image = srcImage,
1161 .viewType = src_iview_type,
1162 .format = src_image->format->vk_format,
1163 .channels = {
1164 VK_CHANNEL_SWIZZLE_R,
1165 VK_CHANNEL_SWIZZLE_G,
1166 VK_CHANNEL_SWIZZLE_B,
1167 VK_CHANNEL_SWIZZLE_A
1168 },
1169 .subresourceRange = {
1170 .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
1171 .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
1172 .mipLevels = 1,
1173 .baseArrayLayer = pRegions[r].srcSubresource.arrayLayer,
1174 .arraySize = 1
1175 },
1176 },
1177 cmd_buffer);
1178
1179 const VkOffset3D dest_offset = {
1180 .x = pRegions[r].destOffset.x,
1181 .y = pRegions[r].destOffset.y,
1182 .z = 0,
1183 };
1184
1185 const uint32_t dest_array_slice =
1186 meta_blit_get_dest_view_base_array_slice(dest_image,
1187 &pRegions[r].destSubresource,
1188 &pRegions[r].destOffset);
1189
1190 if (pRegions[r].srcSubresource.arraySize > 1)
1191 anv_finishme("FINISHME: copy multiple array layers");
1192
1193 if (pRegions[r].extent.depth > 1)
1194 anv_finishme("FINISHME: copy multiple depth layers");
1195
1196 struct anv_image_view dest_iview;
1197 anv_color_attachment_view_init(&dest_iview, cmd_buffer->device,
1198 &(VkAttachmentViewCreateInfo) {
1199 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1200 .image = destImage,
1201 .format = dest_image->format->vk_format,
1202 .mipLevel = pRegions[r].destSubresource.mipLevel,
1203 .baseArraySlice = dest_array_slice,
1204 .arraySize = 1,
1205 },
1206 cmd_buffer);
1207
1208 meta_emit_blit(cmd_buffer,
1209 src_image, &src_iview,
1210 pRegions[r].srcOffset,
1211 pRegions[r].extent,
1212 dest_image, &dest_iview,
1213 dest_offset,
1214 pRegions[r].extent);
1215 }
1216
1217 meta_finish_blit(cmd_buffer, &saved_state);
1218 }
1219
1220 void anv_CmdBlitImage(
1221 VkCmdBuffer cmdBuffer,
1222 VkImage srcImage,
1223 VkImageLayout srcImageLayout,
1224 VkImage destImage,
1225 VkImageLayout destImageLayout,
1226 uint32_t regionCount,
1227 const VkImageBlit* pRegions,
1228 VkTexFilter filter)
1229
1230 {
1231 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1232 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1233 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1234
1235 const VkImageViewType src_iview_type =
1236 meta_blit_get_src_image_view_type(src_image);
1237
1238 struct anv_saved_state saved_state;
1239
1240 anv_finishme("respect VkTexFilter");
1241
1242 meta_prepare_blit(cmd_buffer, &saved_state);
1243
1244 for (unsigned r = 0; r < regionCount; r++) {
1245 struct anv_image_view src_iview;
1246 anv_image_view_init(&src_iview, cmd_buffer->device,
1247 &(VkImageViewCreateInfo) {
1248 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1249 .image = srcImage,
1250 .viewType = src_iview_type,
1251 .format = src_image->format->vk_format,
1252 .channels = {
1253 VK_CHANNEL_SWIZZLE_R,
1254 VK_CHANNEL_SWIZZLE_G,
1255 VK_CHANNEL_SWIZZLE_B,
1256 VK_CHANNEL_SWIZZLE_A
1257 },
1258 .subresourceRange = {
1259 .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
1260 .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
1261 .mipLevels = 1,
1262 .baseArrayLayer = pRegions[r].srcSubresource.arrayLayer,
1263 .arraySize = 1
1264 },
1265 },
1266 cmd_buffer);
1267
1268 const VkOffset3D dest_offset = {
1269 .x = pRegions[r].destOffset.x,
1270 .y = pRegions[r].destOffset.y,
1271 .z = 0,
1272 };
1273
1274 const uint32_t dest_array_slice =
1275 meta_blit_get_dest_view_base_array_slice(dest_image,
1276 &pRegions[r].destSubresource,
1277 &pRegions[r].destOffset);
1278
1279 if (pRegions[r].srcSubresource.arraySize > 1)
1280 anv_finishme("FINISHME: copy multiple array layers");
1281
1282 if (pRegions[r].destExtent.depth > 1)
1283 anv_finishme("FINISHME: copy multiple depth layers");
1284
1285 struct anv_image_view dest_iview;
1286 anv_color_attachment_view_init(&dest_iview, cmd_buffer->device,
1287 &(VkAttachmentViewCreateInfo) {
1288 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1289 .image = destImage,
1290 .format = dest_image->format->vk_format,
1291 .mipLevel = pRegions[r].destSubresource.mipLevel,
1292 .baseArraySlice = dest_array_slice,
1293 .arraySize = 1,
1294 },
1295 cmd_buffer);
1296
1297 meta_emit_blit(cmd_buffer,
1298 src_image, &src_iview,
1299 pRegions[r].srcOffset,
1300 pRegions[r].srcExtent,
1301 dest_image, &dest_iview,
1302 dest_offset,
1303 pRegions[r].destExtent);
1304 }
1305
1306 meta_finish_blit(cmd_buffer, &saved_state);
1307 }
1308
1309 static VkImage
1310 make_image_for_buffer(VkDevice vk_device, VkBuffer vk_buffer, VkFormat format,
1311 VkImageUsageFlags usage,
1312 const VkBufferImageCopy *copy)
1313 {
1314 ANV_FROM_HANDLE(anv_buffer, buffer, vk_buffer);
1315
1316 VkExtent3D extent = copy->imageExtent;
1317 if (copy->bufferRowLength)
1318 extent.width = copy->bufferRowLength;
1319 if (copy->bufferImageHeight)
1320 extent.height = copy->bufferImageHeight;
1321 extent.depth = 1;
1322
1323 VkImage vk_image;
1324 VkResult result = anv_CreateImage(vk_device,
1325 &(VkImageCreateInfo) {
1326 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1327 .imageType = VK_IMAGE_TYPE_2D,
1328 .format = format,
1329 .extent = extent,
1330 .mipLevels = 1,
1331 .arraySize = 1,
1332 .samples = 1,
1333 .tiling = VK_IMAGE_TILING_LINEAR,
1334 .usage = usage,
1335 .flags = 0,
1336 }, &vk_image);
1337 assert(result == VK_SUCCESS);
1338
1339 ANV_FROM_HANDLE(anv_image, image, vk_image);
1340
1341 /* We could use a vk call to bind memory, but that would require
1342 * creating a dummy memory object etc. so there's really no point.
1343 */
1344 image->bo = buffer->bo;
1345 image->offset = buffer->offset + copy->bufferOffset;
1346
1347 return anv_image_to_handle(image);
1348 }
1349
1350 void anv_CmdCopyBufferToImage(
1351 VkCmdBuffer cmdBuffer,
1352 VkBuffer srcBuffer,
1353 VkImage destImage,
1354 VkImageLayout destImageLayout,
1355 uint32_t regionCount,
1356 const VkBufferImageCopy* pRegions)
1357 {
1358 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1359 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1360 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
1361 const VkFormat orig_format = dest_image->format->vk_format;
1362 struct anv_saved_state saved_state;
1363
1364 meta_prepare_blit(cmd_buffer, &saved_state);
1365
1366 for (unsigned r = 0; r < regionCount; r++) {
1367 VkFormat proxy_format = orig_format;
1368 VkImageAspect proxy_aspect = pRegions[r].imageSubresource.aspect;
1369
1370 if (orig_format == VK_FORMAT_S8_UINT) {
1371 proxy_format = VK_FORMAT_R8_UINT;
1372 proxy_aspect = VK_IMAGE_ASPECT_COLOR;
1373 }
1374
1375 VkImage srcImage = make_image_for_buffer(vk_device, srcBuffer,
1376 proxy_format, VK_IMAGE_USAGE_SAMPLED_BIT, &pRegions[r]);
1377
1378 struct anv_image_view src_iview;
1379 anv_image_view_init(&src_iview, cmd_buffer->device,
1380 &(VkImageViewCreateInfo) {
1381 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1382 .image = srcImage,
1383 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1384 .format = proxy_format,
1385 .channels = {
1386 VK_CHANNEL_SWIZZLE_R,
1387 VK_CHANNEL_SWIZZLE_G,
1388 VK_CHANNEL_SWIZZLE_B,
1389 VK_CHANNEL_SWIZZLE_A
1390 },
1391 .subresourceRange = {
1392 .aspectMask = 1 << proxy_aspect,
1393 .baseMipLevel = 0,
1394 .mipLevels = 1,
1395 .baseArrayLayer = 0,
1396 .arraySize = 1
1397 },
1398 },
1399 cmd_buffer);
1400
1401 const VkOffset3D dest_offset = {
1402 .x = pRegions[r].imageOffset.x,
1403 .y = pRegions[r].imageOffset.y,
1404 .z = 0,
1405 };
1406
1407 const uint32_t dest_array_slice =
1408 meta_blit_get_dest_view_base_array_slice(dest_image,
1409 &pRegions[r].imageSubresource,
1410 &pRegions[r].imageOffset);
1411
1412 if (pRegions[r].imageExtent.depth > 1)
1413 anv_finishme("FINISHME: copy multiple depth layers");
1414
1415 struct anv_image_view dest_iview;
1416 anv_color_attachment_view_init(&dest_iview, cmd_buffer->device,
1417 &(VkAttachmentViewCreateInfo) {
1418 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1419 .image = anv_image_to_handle(dest_image),
1420 .format = proxy_format,
1421 .mipLevel = pRegions[r].imageSubresource.mipLevel,
1422 .baseArraySlice = dest_array_slice,
1423 .arraySize = 1,
1424 },
1425 cmd_buffer);
1426
1427 meta_emit_blit(cmd_buffer,
1428 anv_image_from_handle(srcImage),
1429 &src_iview,
1430 (VkOffset3D) { 0, 0, 0 },
1431 pRegions[r].imageExtent,
1432 dest_image,
1433 &dest_iview,
1434 dest_offset,
1435 pRegions[r].imageExtent);
1436
1437 anv_DestroyImage(vk_device, srcImage);
1438 }
1439
1440 meta_finish_blit(cmd_buffer, &saved_state);
1441 }
1442
1443 void anv_CmdCopyImageToBuffer(
1444 VkCmdBuffer cmdBuffer,
1445 VkImage srcImage,
1446 VkImageLayout srcImageLayout,
1447 VkBuffer destBuffer,
1448 uint32_t regionCount,
1449 const VkBufferImageCopy* pRegions)
1450 {
1451 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1452 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1453 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
1454 struct anv_saved_state saved_state;
1455
1456 const VkImageViewType src_iview_type =
1457 meta_blit_get_src_image_view_type(src_image);
1458
1459 meta_prepare_blit(cmd_buffer, &saved_state);
1460
1461 for (unsigned r = 0; r < regionCount; r++) {
1462 if (pRegions[r].imageSubresource.arraySize > 1)
1463 anv_finishme("FINISHME: copy multiple array layers");
1464
1465 if (pRegions[r].imageExtent.depth > 1)
1466 anv_finishme("FINISHME: copy multiple depth layers");
1467
1468 struct anv_image_view src_iview;
1469 anv_image_view_init(&src_iview, cmd_buffer->device,
1470 &(VkImageViewCreateInfo) {
1471 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1472 .image = srcImage,
1473 .viewType = src_iview_type,
1474 .format = src_image->format->vk_format,
1475 .channels = {
1476 VK_CHANNEL_SWIZZLE_R,
1477 VK_CHANNEL_SWIZZLE_G,
1478 VK_CHANNEL_SWIZZLE_B,
1479 VK_CHANNEL_SWIZZLE_A
1480 },
1481 .subresourceRange = {
1482 .aspectMask = 1 << pRegions[r].imageSubresource.aspect,
1483 .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
1484 .mipLevels = 1,
1485 .baseArrayLayer = pRegions[r].imageSubresource.arrayLayer,
1486 .arraySize = 1
1487 },
1488 },
1489 cmd_buffer);
1490
1491 VkFormat dest_format = src_image->format->vk_format;
1492 if (dest_format == VK_FORMAT_S8_UINT) {
1493 dest_format = VK_FORMAT_R8_UINT;
1494 }
1495
1496 VkImage destImage = make_image_for_buffer(vk_device, destBuffer,
1497 dest_format, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, &pRegions[r]);
1498
1499 struct anv_image_view dest_iview;
1500 anv_color_attachment_view_init(&dest_iview, cmd_buffer->device,
1501 &(VkAttachmentViewCreateInfo) {
1502 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1503 .image = destImage,
1504 .format = dest_format,
1505 .mipLevel = 0,
1506 .baseArraySlice = 0,
1507 .arraySize = 1,
1508 },
1509 cmd_buffer);
1510
1511 meta_emit_blit(cmd_buffer,
1512 anv_image_from_handle(srcImage),
1513 &src_iview,
1514 pRegions[r].imageOffset,
1515 pRegions[r].imageExtent,
1516 anv_image_from_handle(destImage),
1517 &dest_iview,
1518 (VkOffset3D) { 0, 0, 0 },
1519 pRegions[r].imageExtent);
1520
1521 anv_DestroyImage(vk_device, destImage);
1522 }
1523
1524 meta_finish_blit(cmd_buffer, &saved_state);
1525 }
1526
1527 void anv_CmdUpdateBuffer(
1528 VkCmdBuffer cmdBuffer,
1529 VkBuffer destBuffer,
1530 VkDeviceSize destOffset,
1531 VkDeviceSize dataSize,
1532 const uint32_t* pData)
1533 {
1534 stub();
1535 }
1536
1537 void anv_CmdFillBuffer(
1538 VkCmdBuffer cmdBuffer,
1539 VkBuffer destBuffer,
1540 VkDeviceSize destOffset,
1541 VkDeviceSize fillSize,
1542 uint32_t data)
1543 {
1544 stub();
1545 }
1546
1547 void anv_CmdClearColorImage(
1548 VkCmdBuffer cmdBuffer,
1549 VkImage _image,
1550 VkImageLayout imageLayout,
1551 const VkClearColorValue* pColor,
1552 uint32_t rangeCount,
1553 const VkImageSubresourceRange* pRanges)
1554 {
1555 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1556 ANV_FROM_HANDLE(anv_image, image, _image);
1557 struct anv_saved_state saved_state;
1558
1559 anv_cmd_buffer_save(cmd_buffer, &saved_state);
1560
1561 for (uint32_t r = 0; r < rangeCount; r++) {
1562 for (uint32_t l = 0; l < pRanges[r].mipLevels; l++) {
1563 for (uint32_t s = 0; s < pRanges[r].arraySize; s++) {
1564 struct anv_image_view iview;
1565 anv_color_attachment_view_init(&iview, cmd_buffer->device,
1566 &(VkAttachmentViewCreateInfo) {
1567 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1568 .image = _image,
1569 .format = image->format->vk_format,
1570 .mipLevel = pRanges[r].baseMipLevel + l,
1571 .baseArraySlice = pRanges[r].baseArrayLayer + s,
1572 .arraySize = 1,
1573 },
1574 cmd_buffer);
1575
1576 VkImageView iview_h = anv_image_view_to_handle(&iview);
1577 VkAttachmentView aview_h = { .handle = iview_h.handle };
1578
1579 VkFramebuffer fb;
1580 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer->device),
1581 &(VkFramebufferCreateInfo) {
1582 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
1583 .attachmentCount = 1,
1584 .pAttachments = (VkAttachmentBindInfo[]) {
1585 {
1586 .view = aview_h,
1587 .layout = VK_IMAGE_LAYOUT_GENERAL
1588 }
1589 },
1590 .width = iview.extent.width,
1591 .height = iview.extent.height,
1592 .layers = 1
1593 }, &fb);
1594
1595 VkRenderPass pass;
1596 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer->device),
1597 &(VkRenderPassCreateInfo) {
1598 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
1599 .attachmentCount = 1,
1600 .pAttachments = &(VkAttachmentDescription) {
1601 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
1602 .format = iview.format->vk_format,
1603 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
1604 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
1605 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
1606 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
1607 },
1608 .subpassCount = 1,
1609 .pSubpasses = &(VkSubpassDescription) {
1610 .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION,
1611 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
1612 .inputCount = 0,
1613 .colorCount = 1,
1614 .pColorAttachments = &(VkAttachmentReference) {
1615 .attachment = 0,
1616 .layout = VK_IMAGE_LAYOUT_GENERAL,
1617 },
1618 .pResolveAttachments = NULL,
1619 .depthStencilAttachment = (VkAttachmentReference) {
1620 .attachment = VK_ATTACHMENT_UNUSED,
1621 .layout = VK_IMAGE_LAYOUT_GENERAL,
1622 },
1623 .preserveCount = 1,
1624 .pPreserveAttachments = &(VkAttachmentReference) {
1625 .attachment = 0,
1626 .layout = VK_IMAGE_LAYOUT_GENERAL,
1627 },
1628 },
1629 .dependencyCount = 0,
1630 }, &pass);
1631
1632 ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
1633 &(VkRenderPassBeginInfo) {
1634 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1635 .renderArea = {
1636 .offset = { 0, 0, },
1637 .extent = {
1638 .width = iview.extent.width,
1639 .height = iview.extent.height,
1640 },
1641 },
1642 .renderPass = pass,
1643 .framebuffer = fb,
1644 .clearValueCount = 1,
1645 .pClearValues = NULL,
1646 }, VK_RENDER_PASS_CONTENTS_INLINE);
1647
1648 struct clear_instance_data instance_data = {
1649 .vue_header = {
1650 .RTAIndex = 0,
1651 .ViewportIndex = 0,
1652 .PointWidth = 0.0
1653 },
1654 .color = *pColor,
1655 };
1656
1657 meta_emit_clear(cmd_buffer, 1, &instance_data,
1658 (VkClearDepthStencilValue) {0});
1659
1660 ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
1661 }
1662 }
1663 }
1664
1665 /* Restore API state */
1666 anv_cmd_buffer_restore(cmd_buffer, &saved_state);
1667 }
1668
1669 void anv_CmdClearDepthStencilImage(
1670 VkCmdBuffer cmdBuffer,
1671 VkImage image,
1672 VkImageLayout imageLayout,
1673 const VkClearDepthStencilValue* pDepthStencil,
1674 uint32_t rangeCount,
1675 const VkImageSubresourceRange* pRanges)
1676 {
1677 stub();
1678 }
1679
1680 void anv_CmdClearColorAttachment(
1681 VkCmdBuffer cmdBuffer,
1682 uint32_t colorAttachment,
1683 VkImageLayout imageLayout,
1684 const VkClearColorValue* pColor,
1685 uint32_t rectCount,
1686 const VkRect3D* pRects)
1687 {
1688 stub();
1689 }
1690
1691 void anv_CmdClearDepthStencilAttachment(
1692 VkCmdBuffer cmdBuffer,
1693 VkImageAspectFlags aspectMask,
1694 VkImageLayout imageLayout,
1695 const VkClearDepthStencilValue* pDepthStencil,
1696 uint32_t rectCount,
1697 const VkRect3D* pRects)
1698 {
1699 stub();
1700 }
1701
1702 void anv_CmdResolveImage(
1703 VkCmdBuffer cmdBuffer,
1704 VkImage srcImage,
1705 VkImageLayout srcImageLayout,
1706 VkImage destImage,
1707 VkImageLayout destImageLayout,
1708 uint32_t regionCount,
1709 const VkImageResolve* pRegions)
1710 {
1711 stub();
1712 }
1713
1714 void
1715 anv_device_init_meta(struct anv_device *device)
1716 {
1717 anv_device_init_meta_clear_state(device);
1718 anv_device_init_meta_blit_state(device);
1719
1720 ANV_CALL(CreateDynamicRasterState)(anv_device_to_handle(device),
1721 &(VkDynamicRasterStateCreateInfo) {
1722 .sType = VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO,
1723 },
1724 &device->meta_state.shared.rs_state);
1725
1726 ANV_CALL(CreateDynamicColorBlendState)(anv_device_to_handle(device),
1727 &(VkDynamicColorBlendStateCreateInfo) {
1728 .sType = VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO
1729 },
1730 &device->meta_state.shared.cb_state);
1731
1732 ANV_CALL(CreateDynamicDepthStencilState)(anv_device_to_handle(device),
1733 &(VkDynamicDepthStencilStateCreateInfo) {
1734 .sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO
1735 },
1736 &device->meta_state.shared.ds_state);
1737 }
1738
1739 void
1740 anv_device_finish_meta(struct anv_device *device)
1741 {
1742 /* Clear */
1743 anv_DestroyPipeline(anv_device_to_handle(device),
1744 device->meta_state.clear.pipeline);
1745
1746 /* Blit */
1747 anv_DestroyPipeline(anv_device_to_handle(device),
1748 device->meta_state.blit.pipeline_2d_src);
1749 anv_DestroyPipeline(anv_device_to_handle(device),
1750 device->meta_state.blit.pipeline_3d_src);
1751 anv_DestroyPipelineLayout(anv_device_to_handle(device),
1752 device->meta_state.blit.pipeline_layout);
1753 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
1754 device->meta_state.blit.ds_layout);
1755
1756 /* Shared */
1757 anv_DestroyDynamicRasterState(anv_device_to_handle(device),
1758 device->meta_state.shared.rs_state);
1759 anv_DestroyDynamicColorBlendState(anv_device_to_handle(device),
1760 device->meta_state.shared.cb_state);
1761 anv_DestroyDynamicDepthStencilState(anv_device_to_handle(device),
1762 device->meta_state.shared.ds_state);
1763 }