vk/0.170.2: Rework blits to use ImageSubresourceCopy
[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_attachment_view *dest_aview,
737 VkOffset3D dest_offset,
738 VkExtent3D dest_extent)
739 {
740 struct anv_device *device = cmd_buffer->device;
741 struct anv_image_view *dest_iview = &dest_aview->image_view;
742 VkDescriptorPool dummy_desc_pool = { .handle = 1 };
743
744 struct blit_vb_data {
745 float pos[2];
746 float tex_coord[3];
747 } *vb_data;
748
749 unsigned vb_size = sizeof(struct vue_header) + 3 * sizeof(*vb_data);
750
751 struct anv_state vb_state =
752 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, vb_size, 16);
753 memset(vb_state.map, 0, sizeof(struct vue_header));
754 vb_data = vb_state.map + sizeof(struct vue_header);
755
756 vb_data[0] = (struct blit_vb_data) {
757 .pos = {
758 dest_offset.x + dest_extent.width,
759 dest_offset.y + dest_extent.height,
760 },
761 .tex_coord = {
762 (float)(src_offset.x + src_extent.width) / (float)src_iview->extent.width,
763 (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
764 (float)(src_offset.z + src_extent.depth) / (float)src_iview->extent.depth,
765 },
766 };
767
768 vb_data[1] = (struct blit_vb_data) {
769 .pos = {
770 dest_offset.x,
771 dest_offset.y + dest_extent.height,
772 },
773 .tex_coord = {
774 (float)src_offset.x / (float)src_iview->extent.width,
775 (float)(src_offset.y + src_extent.height) / (float)src_iview->extent.height,
776 (float)(src_offset.z + src_extent.depth) / (float)src_iview->extent.depth,
777 },
778 };
779
780 vb_data[2] = (struct blit_vb_data) {
781 .pos = {
782 dest_offset.x,
783 dest_offset.y,
784 },
785 .tex_coord = {
786 (float)src_offset.x / (float)src_iview->extent.width,
787 (float)src_offset.y / (float)src_iview->extent.height,
788 (float)src_offset.z / (float)src_iview->extent.depth,
789 },
790 };
791
792 struct anv_buffer vertex_buffer = {
793 .device = device,
794 .size = vb_size,
795 .bo = &device->dynamic_state_block_pool.bo,
796 .offset = vb_state.offset,
797 };
798
799 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer), 0, 2,
800 (VkBuffer[]) {
801 anv_buffer_to_handle(&vertex_buffer),
802 anv_buffer_to_handle(&vertex_buffer)
803 },
804 (VkDeviceSize[]) {
805 0,
806 sizeof(struct vue_header),
807 });
808
809 VkDescriptorSet set;
810 anv_AllocDescriptorSets(anv_device_to_handle(device), dummy_desc_pool,
811 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT,
812 1, &device->meta_state.blit.ds_layout, &set);
813 anv_UpdateDescriptorSets(anv_device_to_handle(device),
814 1, /* writeCount */
815 (VkWriteDescriptorSet[]) {
816 {
817 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
818 .destSet = set,
819 .destBinding = 0,
820 .destArrayElement = 0,
821 .count = 1,
822 .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
823 .pDescriptors = (VkDescriptorInfo[]) {
824 {
825 .imageView = anv_image_view_to_handle(src_iview),
826 .imageLayout = VK_IMAGE_LAYOUT_GENERAL
827 },
828 }
829 }
830 }, 0, NULL);
831
832 VkFramebuffer fb;
833 anv_CreateFramebuffer(anv_device_to_handle(device),
834 &(VkFramebufferCreateInfo) {
835 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
836 .attachmentCount = 1,
837 .pAttachments = (VkAttachmentBindInfo[]) {
838 {
839 .view = anv_attachment_view_to_handle(dest_aview),
840 .layout = VK_IMAGE_LAYOUT_GENERAL
841 }
842 },
843 .width = dest_iview->extent.width,
844 .height = dest_iview->extent.height,
845 .layers = 1
846 }, &fb);
847
848 VkRenderPass pass;
849 anv_CreateRenderPass(anv_device_to_handle(device),
850 &(VkRenderPassCreateInfo) {
851 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
852 .attachmentCount = 1,
853 .pAttachments = &(VkAttachmentDescription) {
854 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
855 .format = dest_iview->format->vk_format,
856 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
857 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
858 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
859 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
860 },
861 .subpassCount = 1,
862 .pSubpasses = &(VkSubpassDescription) {
863 .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION,
864 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
865 .inputCount = 0,
866 .colorCount = 1,
867 .pColorAttachments = &(VkAttachmentReference) {
868 .attachment = 0,
869 .layout = VK_IMAGE_LAYOUT_GENERAL,
870 },
871 .pResolveAttachments = NULL,
872 .depthStencilAttachment = (VkAttachmentReference) {
873 .attachment = VK_ATTACHMENT_UNUSED,
874 .layout = VK_IMAGE_LAYOUT_GENERAL,
875 },
876 .preserveCount = 1,
877 .pPreserveAttachments = &(VkAttachmentReference) {
878 .attachment = 0,
879 .layout = VK_IMAGE_LAYOUT_GENERAL,
880 },
881 },
882 .dependencyCount = 0,
883 }, &pass);
884
885 ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
886 &(VkRenderPassBeginInfo) {
887 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
888 .renderPass = pass,
889 .framebuffer = fb,
890 .renderArea = {
891 .offset = { dest_offset.x, dest_offset.y },
892 .extent = { dest_extent.width, dest_extent.height },
893 },
894 .clearValueCount = 0,
895 .pClearValues = NULL,
896 }, VK_RENDER_PASS_CONTENTS_INLINE);
897
898 VkPipeline pipeline;
899
900 switch (src_image->type) {
901 case VK_IMAGE_TYPE_1D:
902 anv_finishme("VK_IMAGE_TYPE_1D");
903 pipeline = device->meta_state.blit.pipeline_2d_src;
904 break;
905 case VK_IMAGE_TYPE_2D:
906 pipeline = device->meta_state.blit.pipeline_2d_src;
907 break;
908 case VK_IMAGE_TYPE_3D:
909 pipeline = device->meta_state.blit.pipeline_3d_src;
910 break;
911 default:
912 unreachable(!"bad VkImageType");
913 }
914
915 if (cmd_buffer->state.pipeline != anv_pipeline_from_handle(pipeline)) {
916 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer),
917 VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
918 }
919
920 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer),
921 anv_framebuffer_from_handle(fb)->vp_state);
922
923 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer),
924 VK_PIPELINE_BIND_POINT_GRAPHICS,
925 device->meta_state.blit.pipeline_layout, 0, 1,
926 &set, 0, NULL);
927
928 ANV_CALL(CmdDraw)(anv_cmd_buffer_to_handle(cmd_buffer), 3, 1, 0, 0);
929
930 ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
931
932 /* At the point where we emit the draw call, all data from the
933 * descriptor sets, etc. has been used. We are free to delete it.
934 */
935 anv_descriptor_set_destroy(device, anv_descriptor_set_from_handle(set));
936 anv_DestroyFramebuffer(anv_device_to_handle(device), fb);
937 anv_DestroyRenderPass(anv_device_to_handle(device), pass);
938 }
939
940 static void
941 meta_finish_blit(struct anv_cmd_buffer *cmd_buffer,
942 const struct anv_saved_state *saved_state)
943 {
944 anv_cmd_buffer_restore(cmd_buffer, saved_state);
945 }
946
947 static VkFormat
948 vk_format_for_cpp(int cpp)
949 {
950 switch (cpp) {
951 case 1: return VK_FORMAT_R8_UINT;
952 case 2: return VK_FORMAT_R8G8_UINT;
953 case 3: return VK_FORMAT_R8G8B8_UINT;
954 case 4: return VK_FORMAT_R8G8B8A8_UINT;
955 case 6: return VK_FORMAT_R16G16B16_UINT;
956 case 8: return VK_FORMAT_R16G16B16A16_UINT;
957 case 12: return VK_FORMAT_R32G32B32_UINT;
958 case 16: return VK_FORMAT_R32G32B32A32_UINT;
959 default:
960 unreachable("Invalid format cpp");
961 }
962 }
963
964 static void
965 do_buffer_copy(struct anv_cmd_buffer *cmd_buffer,
966 struct anv_bo *src, uint64_t src_offset,
967 struct anv_bo *dest, uint64_t dest_offset,
968 int width, int height, VkFormat copy_format)
969 {
970 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
971
972 VkImageCreateInfo image_info = {
973 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
974 .imageType = VK_IMAGE_TYPE_2D,
975 .format = copy_format,
976 .extent = {
977 .width = width,
978 .height = height,
979 .depth = 1,
980 },
981 .mipLevels = 1,
982 .arraySize = 1,
983 .samples = 1,
984 .tiling = VK_IMAGE_TILING_LINEAR,
985 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
986 .flags = 0,
987 };
988
989 VkImage src_image, dest_image;
990 anv_CreateImage(vk_device, &image_info, &src_image);
991 anv_CreateImage(vk_device, &image_info, &dest_image);
992
993 /* We could use a vk call to bind memory, but that would require
994 * creating a dummy memory object etc. so there's really no point.
995 */
996 anv_image_from_handle(src_image)->bo = src;
997 anv_image_from_handle(src_image)->offset = src_offset;
998 anv_image_from_handle(dest_image)->bo = dest;
999 anv_image_from_handle(dest_image)->offset = dest_offset;
1000
1001 struct anv_image_view src_iview;
1002 anv_image_view_init(&src_iview, cmd_buffer->device,
1003 &(VkImageViewCreateInfo) {
1004 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1005 .image = src_image,
1006 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1007 .format = copy_format,
1008 .channels = {
1009 VK_CHANNEL_SWIZZLE_R,
1010 VK_CHANNEL_SWIZZLE_G,
1011 VK_CHANNEL_SWIZZLE_B,
1012 VK_CHANNEL_SWIZZLE_A
1013 },
1014 .subresourceRange = {
1015 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
1016 .baseMipLevel = 0,
1017 .mipLevels = 1,
1018 .baseArraySlice = 0,
1019 .arraySize = 1
1020 },
1021 },
1022 cmd_buffer);
1023
1024 struct anv_attachment_view dest_aview;
1025 anv_color_attachment_view_init(&dest_aview, cmd_buffer->device,
1026 &(VkAttachmentViewCreateInfo) {
1027 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1028 .image = dest_image,
1029 .format = copy_format,
1030 .mipLevel = 0,
1031 .baseArraySlice = 0,
1032 .arraySize = 1,
1033 },
1034 cmd_buffer);
1035
1036 meta_emit_blit(cmd_buffer,
1037 anv_image_from_handle(src_image),
1038 &src_iview,
1039 (VkOffset3D) { 0, 0, 0 },
1040 (VkExtent3D) { width, height, 1 },
1041 anv_image_from_handle(dest_image),
1042 &dest_aview,
1043 (VkOffset3D) { 0, 0, 0 },
1044 (VkExtent3D) { width, height, 1 });
1045
1046 anv_DestroyImage(vk_device, src_image);
1047 anv_DestroyImage(vk_device, dest_image);
1048 }
1049
1050 void anv_CmdCopyBuffer(
1051 VkCmdBuffer cmdBuffer,
1052 VkBuffer srcBuffer,
1053 VkBuffer destBuffer,
1054 uint32_t regionCount,
1055 const VkBufferCopy* pRegions)
1056 {
1057 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1058 ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
1059 ANV_FROM_HANDLE(anv_buffer, dest_buffer, destBuffer);
1060
1061 struct anv_saved_state saved_state;
1062
1063 meta_prepare_blit(cmd_buffer, &saved_state);
1064
1065 for (unsigned r = 0; r < regionCount; r++) {
1066 uint64_t src_offset = src_buffer->offset + pRegions[r].srcOffset;
1067 uint64_t dest_offset = dest_buffer->offset + pRegions[r].destOffset;
1068 uint64_t copy_size = pRegions[r].copySize;
1069
1070 /* First, we compute the biggest format that can be used with the
1071 * given offsets and size.
1072 */
1073 int cpp = 16;
1074
1075 int fs = ffs(src_offset) - 1;
1076 if (fs != -1)
1077 cpp = MIN2(cpp, 1 << fs);
1078 assert(src_offset % cpp == 0);
1079
1080 fs = ffs(dest_offset) - 1;
1081 if (fs != -1)
1082 cpp = MIN2(cpp, 1 << fs);
1083 assert(dest_offset % cpp == 0);
1084
1085 fs = ffs(pRegions[r].copySize) - 1;
1086 if (fs != -1)
1087 cpp = MIN2(cpp, 1 << fs);
1088 assert(pRegions[r].copySize % cpp == 0);
1089
1090 VkFormat copy_format = vk_format_for_cpp(cpp);
1091
1092 /* This is maximum possible width/height our HW can handle */
1093 uint64_t max_surface_dim = 1 << 14;
1094
1095 /* First, we make a bunch of max-sized copies */
1096 uint64_t max_copy_size = max_surface_dim * max_surface_dim * cpp;
1097 while (copy_size > max_copy_size) {
1098 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1099 dest_buffer->bo, dest_offset,
1100 max_surface_dim, max_surface_dim, copy_format);
1101 copy_size -= max_copy_size;
1102 src_offset += max_copy_size;
1103 dest_offset += max_copy_size;
1104 }
1105
1106 uint64_t height = copy_size / (max_surface_dim * cpp);
1107 assert(height < max_surface_dim);
1108 if (height != 0) {
1109 uint64_t rect_copy_size = height * max_surface_dim * cpp;
1110 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1111 dest_buffer->bo, dest_offset,
1112 max_surface_dim, height, copy_format);
1113 copy_size -= rect_copy_size;
1114 src_offset += rect_copy_size;
1115 dest_offset += rect_copy_size;
1116 }
1117
1118 if (copy_size != 0) {
1119 do_buffer_copy(cmd_buffer, src_buffer->bo, src_offset,
1120 dest_buffer->bo, dest_offset,
1121 copy_size / cpp, 1, copy_format);
1122 }
1123 }
1124
1125 meta_finish_blit(cmd_buffer, &saved_state);
1126 }
1127
1128 void anv_CmdCopyImage(
1129 VkCmdBuffer cmdBuffer,
1130 VkImage srcImage,
1131 VkImageLayout srcImageLayout,
1132 VkImage destImage,
1133 VkImageLayout destImageLayout,
1134 uint32_t regionCount,
1135 const VkImageCopy* pRegions)
1136 {
1137 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1138 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1139 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1140
1141 const VkImageViewType src_iview_type =
1142 meta_blit_get_src_image_view_type(src_image);
1143
1144 struct anv_saved_state saved_state;
1145
1146 meta_prepare_blit(cmd_buffer, &saved_state);
1147
1148 for (unsigned r = 0; r < regionCount; r++) {
1149 struct anv_image_view src_iview;
1150 anv_image_view_init(&src_iview, cmd_buffer->device,
1151 &(VkImageViewCreateInfo) {
1152 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1153 .image = srcImage,
1154 .viewType = src_iview_type,
1155 .format = src_image->format->vk_format,
1156 .channels = {
1157 VK_CHANNEL_SWIZZLE_R,
1158 VK_CHANNEL_SWIZZLE_G,
1159 VK_CHANNEL_SWIZZLE_B,
1160 VK_CHANNEL_SWIZZLE_A
1161 },
1162 .subresourceRange = {
1163 .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
1164 .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
1165 .mipLevels = 1,
1166 .baseArraySlice = pRegions[r].srcSubresource.arrayLayer,
1167 .arraySize = 1
1168 },
1169 },
1170 cmd_buffer);
1171
1172 const VkOffset3D dest_offset = {
1173 .x = pRegions[r].destOffset.x,
1174 .y = pRegions[r].destOffset.y,
1175 .z = 0,
1176 };
1177
1178 const uint32_t dest_array_slice =
1179 meta_blit_get_dest_view_base_array_slice(dest_image,
1180 &pRegions[r].destSubresource,
1181 &pRegions[r].destOffset);
1182
1183 if (pRegions[r].srcSubresource.arraySize > 1)
1184 anv_finishme("FINISHME: copy multiple array layers");
1185
1186 if (pRegions[r].extent.depth > 1)
1187 anv_finishme("FINISHME: copy multiple depth layers");
1188
1189 struct anv_attachment_view dest_aview;
1190 anv_color_attachment_view_init(&dest_aview, cmd_buffer->device,
1191 &(VkAttachmentViewCreateInfo) {
1192 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1193 .image = destImage,
1194 .format = dest_image->format->vk_format,
1195 .mipLevel = pRegions[r].destSubresource.mipLevel,
1196 .baseArraySlice = dest_array_slice,
1197 .arraySize = 1,
1198 },
1199 cmd_buffer);
1200
1201 meta_emit_blit(cmd_buffer,
1202 src_image, &src_iview,
1203 pRegions[r].srcOffset,
1204 pRegions[r].extent,
1205 dest_image, &dest_aview,
1206 dest_offset,
1207 pRegions[r].extent);
1208 }
1209
1210 meta_finish_blit(cmd_buffer, &saved_state);
1211 }
1212
1213 void anv_CmdBlitImage(
1214 VkCmdBuffer cmdBuffer,
1215 VkImage srcImage,
1216 VkImageLayout srcImageLayout,
1217 VkImage destImage,
1218 VkImageLayout destImageLayout,
1219 uint32_t regionCount,
1220 const VkImageBlit* pRegions,
1221 VkTexFilter filter)
1222
1223 {
1224 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1225 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1226 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1227
1228 const VkImageViewType src_iview_type =
1229 meta_blit_get_src_image_view_type(src_image);
1230
1231 struct anv_saved_state saved_state;
1232
1233 anv_finishme("respect VkTexFilter");
1234
1235 meta_prepare_blit(cmd_buffer, &saved_state);
1236
1237 for (unsigned r = 0; r < regionCount; r++) {
1238 struct anv_image_view src_iview;
1239 anv_image_view_init(&src_iview, cmd_buffer->device,
1240 &(VkImageViewCreateInfo) {
1241 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1242 .image = srcImage,
1243 .viewType = src_iview_type,
1244 .format = src_image->format->vk_format,
1245 .channels = {
1246 VK_CHANNEL_SWIZZLE_R,
1247 VK_CHANNEL_SWIZZLE_G,
1248 VK_CHANNEL_SWIZZLE_B,
1249 VK_CHANNEL_SWIZZLE_A
1250 },
1251 .subresourceRange = {
1252 .aspectMask = 1 << pRegions[r].srcSubresource.aspect,
1253 .baseMipLevel = pRegions[r].srcSubresource.mipLevel,
1254 .mipLevels = 1,
1255 .baseArraySlice = pRegions[r].srcSubresource.arrayLayer,
1256 .arraySize = 1
1257 },
1258 },
1259 cmd_buffer);
1260
1261 const VkOffset3D dest_offset = {
1262 .x = pRegions[r].destOffset.x,
1263 .y = pRegions[r].destOffset.y,
1264 .z = 0,
1265 };
1266
1267 const uint32_t dest_array_slice =
1268 meta_blit_get_dest_view_base_array_slice(dest_image,
1269 &pRegions[r].destSubresource,
1270 &pRegions[r].destOffset);
1271
1272 if (pRegions[r].srcSubresource.arraySize > 1)
1273 anv_finishme("FINISHME: copy multiple array layers");
1274
1275 if (pRegions[r].destExtent.depth > 1)
1276 anv_finishme("FINISHME: copy multiple depth layers");
1277
1278 struct anv_attachment_view dest_aview;
1279 anv_color_attachment_view_init(&dest_aview, cmd_buffer->device,
1280 &(VkAttachmentViewCreateInfo) {
1281 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1282 .image = destImage,
1283 .format = dest_image->format->vk_format,
1284 .mipLevel = pRegions[r].destSubresource.mipLevel,
1285 .baseArraySlice = dest_array_slice,
1286 .arraySize = 1,
1287 },
1288 cmd_buffer);
1289
1290 meta_emit_blit(cmd_buffer,
1291 src_image, &src_iview,
1292 pRegions[r].srcOffset,
1293 pRegions[r].srcExtent,
1294 dest_image, &dest_aview,
1295 dest_offset,
1296 pRegions[r].destExtent);
1297 }
1298
1299 meta_finish_blit(cmd_buffer, &saved_state);
1300 }
1301
1302 static VkImage
1303 make_image_for_buffer(VkDevice vk_device, VkBuffer vk_buffer, VkFormat format,
1304 const VkBufferImageCopy *copy)
1305 {
1306 ANV_FROM_HANDLE(anv_buffer, buffer, vk_buffer);
1307
1308 VkExtent3D extent = copy->imageExtent;
1309 if (copy->bufferRowLength)
1310 extent.width = copy->bufferRowLength;
1311 if (copy->bufferImageHeight)
1312 extent.height = copy->bufferImageHeight;
1313 extent.depth = 1;
1314
1315 VkImage vk_image;
1316 VkResult result = anv_CreateImage(vk_device,
1317 &(VkImageCreateInfo) {
1318 .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
1319 .imageType = VK_IMAGE_TYPE_2D,
1320 .format = format,
1321 .extent = extent,
1322 .mipLevels = 1,
1323 .arraySize = 1,
1324 .samples = 1,
1325 .tiling = VK_IMAGE_TILING_LINEAR,
1326 .usage = VK_IMAGE_USAGE_SAMPLED_BIT,
1327 .flags = 0,
1328 }, &vk_image);
1329 assert(result == VK_SUCCESS);
1330
1331 ANV_FROM_HANDLE(anv_image, image, vk_image);
1332
1333 /* We could use a vk call to bind memory, but that would require
1334 * creating a dummy memory object etc. so there's really no point.
1335 */
1336 image->bo = buffer->bo;
1337 image->offset = buffer->offset + copy->bufferOffset;
1338
1339 return anv_image_to_handle(image);
1340 }
1341
1342 void anv_CmdCopyBufferToImage(
1343 VkCmdBuffer cmdBuffer,
1344 VkBuffer srcBuffer,
1345 VkImage destImage,
1346 VkImageLayout destImageLayout,
1347 uint32_t regionCount,
1348 const VkBufferImageCopy* pRegions)
1349 {
1350 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1351 ANV_FROM_HANDLE(anv_image, dest_image, destImage);
1352 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
1353 const VkFormat orig_format = dest_image->format->vk_format;
1354 struct anv_saved_state saved_state;
1355
1356 meta_prepare_blit(cmd_buffer, &saved_state);
1357
1358 for (unsigned r = 0; r < regionCount; r++) {
1359 VkFormat proxy_format = orig_format;
1360 VkImageAspect proxy_aspect = pRegions[r].imageSubresource.aspect;
1361
1362 if (orig_format == VK_FORMAT_S8_UINT) {
1363 proxy_format = VK_FORMAT_R8_UINT;
1364 proxy_aspect = VK_IMAGE_ASPECT_COLOR;
1365 }
1366
1367 VkImage srcImage = make_image_for_buffer(vk_device, srcBuffer,
1368 proxy_format,
1369 &pRegions[r]);
1370
1371 struct anv_image_view src_iview;
1372 anv_image_view_init(&src_iview, cmd_buffer->device,
1373 &(VkImageViewCreateInfo) {
1374 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1375 .image = srcImage,
1376 .viewType = VK_IMAGE_VIEW_TYPE_2D,
1377 .format = proxy_format,
1378 .channels = {
1379 VK_CHANNEL_SWIZZLE_R,
1380 VK_CHANNEL_SWIZZLE_G,
1381 VK_CHANNEL_SWIZZLE_B,
1382 VK_CHANNEL_SWIZZLE_A
1383 },
1384 .subresourceRange = {
1385 .aspectMask = 1 << proxy_aspect,
1386 .baseMipLevel = 0,
1387 .mipLevels = 1,
1388 .baseArraySlice = 0,
1389 .arraySize = 1
1390 },
1391 },
1392 cmd_buffer);
1393
1394 const VkOffset3D dest_offset = {
1395 .x = pRegions[r].imageOffset.x,
1396 .y = pRegions[r].imageOffset.y,
1397 .z = 0,
1398 };
1399
1400 const uint32_t dest_array_slice =
1401 meta_blit_get_dest_view_base_array_slice(dest_image,
1402 &pRegions[r].imageSubresource,
1403 &pRegions[r].imageOffset);
1404
1405 if (pRegions[r].imageExtent.depth > 1)
1406 anv_finishme("FINISHME: copy multiple depth layers");
1407
1408 struct anv_attachment_view dest_aview;
1409 anv_color_attachment_view_init(&dest_aview, cmd_buffer->device,
1410 &(VkAttachmentViewCreateInfo) {
1411 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1412 .image = anv_image_to_handle(dest_image),
1413 .format = proxy_format,
1414 .mipLevel = pRegions[r].imageSubresource.mipLevel,
1415 .baseArraySlice = dest_array_slice,
1416 .arraySize = 1,
1417 },
1418 cmd_buffer);
1419
1420 meta_emit_blit(cmd_buffer,
1421 anv_image_from_handle(srcImage),
1422 &src_iview,
1423 (VkOffset3D) { 0, 0, 0 },
1424 pRegions[r].imageExtent,
1425 dest_image,
1426 &dest_aview,
1427 dest_offset,
1428 pRegions[r].imageExtent);
1429
1430 anv_DestroyImage(vk_device, srcImage);
1431 }
1432
1433 meta_finish_blit(cmd_buffer, &saved_state);
1434 }
1435
1436 void anv_CmdCopyImageToBuffer(
1437 VkCmdBuffer cmdBuffer,
1438 VkImage srcImage,
1439 VkImageLayout srcImageLayout,
1440 VkBuffer destBuffer,
1441 uint32_t regionCount,
1442 const VkBufferImageCopy* pRegions)
1443 {
1444 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1445 ANV_FROM_HANDLE(anv_image, src_image, srcImage);
1446 VkDevice vk_device = anv_device_to_handle(cmd_buffer->device);
1447 struct anv_saved_state saved_state;
1448
1449 const VkImageViewType src_iview_type =
1450 meta_blit_get_src_image_view_type(src_image);
1451
1452 meta_prepare_blit(cmd_buffer, &saved_state);
1453
1454 for (unsigned r = 0; r < regionCount; r++) {
1455 if (pRegions[r].imageSubresource.arraySize > 1)
1456 anv_finishme("FINISHME: copy multiple array layers");
1457
1458 if (pRegions[r].imageExtent.depth > 1)
1459 anv_finishme("FINISHME: copy multiple depth layers");
1460
1461 struct anv_image_view src_iview;
1462 anv_image_view_init(&src_iview, cmd_buffer->device,
1463 &(VkImageViewCreateInfo) {
1464 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
1465 .image = srcImage,
1466 .viewType = src_iview_type,
1467 .format = src_image->format->vk_format,
1468 .channels = {
1469 VK_CHANNEL_SWIZZLE_R,
1470 VK_CHANNEL_SWIZZLE_G,
1471 VK_CHANNEL_SWIZZLE_B,
1472 VK_CHANNEL_SWIZZLE_A
1473 },
1474 .subresourceRange = {
1475 .aspectMask = 1 << pRegions[r].imageSubresource.aspect,
1476 .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
1477 .mipLevels = 1,
1478 .baseArraySlice = pRegions[r].imageSubresource.arrayLayer,
1479 .arraySize = 1
1480 },
1481 },
1482 cmd_buffer);
1483
1484 VkFormat dest_format = src_image->format->vk_format;
1485 if (dest_format == VK_FORMAT_S8_UINT) {
1486 dest_format = VK_FORMAT_R8_UINT;
1487 }
1488
1489 VkImage destImage = make_image_for_buffer(vk_device, destBuffer,
1490 dest_format,
1491 &pRegions[r]);
1492
1493 struct anv_attachment_view dest_aview;
1494 anv_color_attachment_view_init(&dest_aview, cmd_buffer->device,
1495 &(VkAttachmentViewCreateInfo) {
1496 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1497 .image = destImage,
1498 .format = dest_format,
1499 .mipLevel = 0,
1500 .baseArraySlice = 0,
1501 .arraySize = 1,
1502 },
1503 cmd_buffer);
1504
1505 meta_emit_blit(cmd_buffer,
1506 anv_image_from_handle(srcImage),
1507 &src_iview,
1508 pRegions[r].imageOffset,
1509 pRegions[r].imageExtent,
1510 anv_image_from_handle(destImage),
1511 &dest_aview,
1512 (VkOffset3D) { 0, 0, 0 },
1513 pRegions[r].imageExtent);
1514
1515 anv_DestroyImage(vk_device, destImage);
1516 }
1517
1518 meta_finish_blit(cmd_buffer, &saved_state);
1519 }
1520
1521 void anv_CmdUpdateBuffer(
1522 VkCmdBuffer cmdBuffer,
1523 VkBuffer destBuffer,
1524 VkDeviceSize destOffset,
1525 VkDeviceSize dataSize,
1526 const uint32_t* pData)
1527 {
1528 stub();
1529 }
1530
1531 void anv_CmdFillBuffer(
1532 VkCmdBuffer cmdBuffer,
1533 VkBuffer destBuffer,
1534 VkDeviceSize destOffset,
1535 VkDeviceSize fillSize,
1536 uint32_t data)
1537 {
1538 stub();
1539 }
1540
1541 void anv_CmdClearColorImage(
1542 VkCmdBuffer cmdBuffer,
1543 VkImage _image,
1544 VkImageLayout imageLayout,
1545 const VkClearColorValue* pColor,
1546 uint32_t rangeCount,
1547 const VkImageSubresourceRange* pRanges)
1548 {
1549 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmdBuffer);
1550 ANV_FROM_HANDLE(anv_image, image, _image);
1551 struct anv_saved_state saved_state;
1552
1553 anv_cmd_buffer_save(cmd_buffer, &saved_state);
1554
1555 for (uint32_t r = 0; r < rangeCount; r++) {
1556 for (uint32_t l = 0; l < pRanges[r].mipLevels; l++) {
1557 for (uint32_t s = 0; s < pRanges[r].arraySize; s++) {
1558 struct anv_attachment_view aview;
1559 anv_color_attachment_view_init(&aview, cmd_buffer->device,
1560 &(VkAttachmentViewCreateInfo) {
1561 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO,
1562 .image = _image,
1563 .format = image->format->vk_format,
1564 .mipLevel = pRanges[r].baseMipLevel + l,
1565 .baseArraySlice = pRanges[r].baseArraySlice + s,
1566 .arraySize = 1,
1567 },
1568 cmd_buffer);
1569
1570 struct anv_image_view *iview = &aview.image_view;
1571
1572 VkFramebuffer fb;
1573 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer->device),
1574 &(VkFramebufferCreateInfo) {
1575 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
1576 .attachmentCount = 1,
1577 .pAttachments = (VkAttachmentBindInfo[]) {
1578 {
1579 .view = anv_attachment_view_to_handle(&aview),
1580 .layout = VK_IMAGE_LAYOUT_GENERAL
1581 }
1582 },
1583 .width = iview->extent.width,
1584 .height = iview->extent.height,
1585 .layers = 1
1586 }, &fb);
1587
1588 VkRenderPass pass;
1589 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer->device),
1590 &(VkRenderPassCreateInfo) {
1591 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
1592 .attachmentCount = 1,
1593 .pAttachments = &(VkAttachmentDescription) {
1594 .sType = VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION,
1595 .format = iview->format->vk_format,
1596 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
1597 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
1598 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
1599 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
1600 },
1601 .subpassCount = 1,
1602 .pSubpasses = &(VkSubpassDescription) {
1603 .sType = VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION,
1604 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
1605 .inputCount = 0,
1606 .colorCount = 1,
1607 .pColorAttachments = &(VkAttachmentReference) {
1608 .attachment = 0,
1609 .layout = VK_IMAGE_LAYOUT_GENERAL,
1610 },
1611 .pResolveAttachments = NULL,
1612 .depthStencilAttachment = (VkAttachmentReference) {
1613 .attachment = VK_ATTACHMENT_UNUSED,
1614 .layout = VK_IMAGE_LAYOUT_GENERAL,
1615 },
1616 .preserveCount = 1,
1617 .pPreserveAttachments = &(VkAttachmentReference) {
1618 .attachment = 0,
1619 .layout = VK_IMAGE_LAYOUT_GENERAL,
1620 },
1621 },
1622 .dependencyCount = 0,
1623 }, &pass);
1624
1625 ANV_CALL(CmdBeginRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer),
1626 &(VkRenderPassBeginInfo) {
1627 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
1628 .renderArea = {
1629 .offset = { 0, 0, },
1630 .extent = {
1631 .width = iview->extent.width,
1632 .height = iview->extent.height,
1633 },
1634 },
1635 .renderPass = pass,
1636 .framebuffer = fb,
1637 .clearValueCount = 1,
1638 .pClearValues = NULL,
1639 }, VK_RENDER_PASS_CONTENTS_INLINE);
1640
1641 struct clear_instance_data instance_data = {
1642 .vue_header = {
1643 .RTAIndex = 0,
1644 .ViewportIndex = 0,
1645 .PointWidth = 0.0
1646 },
1647 .color = *pColor,
1648 };
1649
1650 meta_emit_clear(cmd_buffer, 1, &instance_data,
1651 (VkClearDepthStencilValue) {0});
1652
1653 ANV_CALL(CmdEndRenderPass)(anv_cmd_buffer_to_handle(cmd_buffer));
1654 }
1655 }
1656 }
1657
1658 /* Restore API state */
1659 anv_cmd_buffer_restore(cmd_buffer, &saved_state);
1660 }
1661
1662 void anv_CmdClearDepthStencilImage(
1663 VkCmdBuffer cmdBuffer,
1664 VkImage image,
1665 VkImageLayout imageLayout,
1666 const VkClearDepthStencilValue* pDepthStencil,
1667 uint32_t rangeCount,
1668 const VkImageSubresourceRange* pRanges)
1669 {
1670 stub();
1671 }
1672
1673 void anv_CmdClearColorAttachment(
1674 VkCmdBuffer cmdBuffer,
1675 uint32_t colorAttachment,
1676 VkImageLayout imageLayout,
1677 const VkClearColorValue* pColor,
1678 uint32_t rectCount,
1679 const VkRect3D* pRects)
1680 {
1681 stub();
1682 }
1683
1684 void anv_CmdClearDepthStencilAttachment(
1685 VkCmdBuffer cmdBuffer,
1686 VkImageAspectFlags aspectMask,
1687 VkImageLayout imageLayout,
1688 const VkClearDepthStencilValue* pDepthStencil,
1689 uint32_t rectCount,
1690 const VkRect3D* pRects)
1691 {
1692 stub();
1693 }
1694
1695 void anv_CmdResolveImage(
1696 VkCmdBuffer cmdBuffer,
1697 VkImage srcImage,
1698 VkImageLayout srcImageLayout,
1699 VkImage destImage,
1700 VkImageLayout destImageLayout,
1701 uint32_t regionCount,
1702 const VkImageResolve* pRegions)
1703 {
1704 stub();
1705 }
1706
1707 void
1708 anv_device_init_meta(struct anv_device *device)
1709 {
1710 anv_device_init_meta_clear_state(device);
1711 anv_device_init_meta_blit_state(device);
1712
1713 ANV_CALL(CreateDynamicRasterState)(anv_device_to_handle(device),
1714 &(VkDynamicRasterStateCreateInfo) {
1715 .sType = VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO,
1716 },
1717 &device->meta_state.shared.rs_state);
1718
1719 ANV_CALL(CreateDynamicColorBlendState)(anv_device_to_handle(device),
1720 &(VkDynamicColorBlendStateCreateInfo) {
1721 .sType = VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO
1722 },
1723 &device->meta_state.shared.cb_state);
1724
1725 ANV_CALL(CreateDynamicDepthStencilState)(anv_device_to_handle(device),
1726 &(VkDynamicDepthStencilStateCreateInfo) {
1727 .sType = VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO
1728 },
1729 &device->meta_state.shared.ds_state);
1730 }
1731
1732 void
1733 anv_device_finish_meta(struct anv_device *device)
1734 {
1735 /* Clear */
1736 anv_DestroyPipeline(anv_device_to_handle(device),
1737 device->meta_state.clear.pipeline);
1738
1739 /* Blit */
1740 anv_DestroyPipeline(anv_device_to_handle(device),
1741 device->meta_state.blit.pipeline_2d_src);
1742 anv_DestroyPipeline(anv_device_to_handle(device),
1743 device->meta_state.blit.pipeline_3d_src);
1744 anv_DestroyPipelineLayout(anv_device_to_handle(device),
1745 device->meta_state.blit.pipeline_layout);
1746 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device),
1747 device->meta_state.blit.ds_layout);
1748
1749 /* Shared */
1750 anv_DestroyDynamicRasterState(anv_device_to_handle(device),
1751 device->meta_state.shared.rs_state);
1752 anv_DestroyDynamicColorBlendState(anv_device_to_handle(device),
1753 device->meta_state.shared.cb_state);
1754 anv_DestroyDynamicDepthStencilState(anv_device_to_handle(device),
1755 device->meta_state.shared.ds_state);
1756 }