2 * Copyright © 2016 Intel Corporation
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:
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
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
28 #include "anv_private.h"
29 #include "nir/nir_builder.h"
32 * Vertex attributes used by all pipelines.
35 struct anv_vue_header vue_header;
36 float position[2]; /**< 3DPRIM_RECTLIST */
37 float tex_position[2];
41 meta_resolve_save(struct anv_meta_saved_state *saved_state,
42 struct anv_cmd_buffer *cmd_buffer)
44 anv_meta_save(saved_state, cmd_buffer, 0);
48 meta_resolve_restore(struct anv_meta_saved_state *saved_state,
49 struct anv_cmd_buffer *cmd_buffer)
51 anv_meta_restore(saved_state, cmd_buffer);
55 get_pipeline_h(struct anv_device *device, uint32_t samples)
57 uint32_t i = ffs(samples) - 2; /* log2(samples) - 1 */
60 assert(i < ARRAY_SIZE(device->meta_state.resolve.pipelines));
62 return &device->meta_state.resolve.pipelines[i];
68 const struct glsl_type *vec4 = glsl_vec4_type();
71 nir_variable *a_position;
72 nir_variable *v_position;
73 nir_variable *a_tex_position;
74 nir_variable *v_tex_position;
76 nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_VERTEX, NULL);
77 b.shader->info.name = ralloc_strdup(b.shader, "meta_resolve_vs");
79 a_position = nir_variable_create(b.shader, nir_var_shader_in, vec4,
81 a_position->data.location = VERT_ATTRIB_GENERIC0;
83 v_position = nir_variable_create(b.shader, nir_var_shader_out, vec4,
85 v_position->data.location = VARYING_SLOT_POS;
87 a_tex_position = nir_variable_create(b.shader, nir_var_shader_in, vec4,
89 a_tex_position->data.location = VERT_ATTRIB_GENERIC1;
91 v_tex_position = nir_variable_create(b.shader, nir_var_shader_out, vec4,
93 v_tex_position->data.location = VARYING_SLOT_VAR0;
95 nir_copy_var(&b, v_position, a_position);
96 nir_copy_var(&b, v_tex_position, a_tex_position);
102 build_nir_fs(uint32_t num_samples)
104 const struct glsl_type *vec4 = glsl_vec4_type();
106 const struct glsl_type *sampler2DMS =
107 glsl_sampler_type(GLSL_SAMPLER_DIM_MS,
113 nir_variable *u_tex; /* uniform sampler */
114 nir_variable *v_position; /* vec4, varying fragment position */
115 nir_variable *v_tex_position; /* vec4, varying texture coordinate */
116 nir_variable *f_color; /* vec4, fragment output color */
117 nir_ssa_def *accum; /* vec4, accumulation of sample values */
119 nir_builder_init_simple_shader(&b, NULL, MESA_SHADER_FRAGMENT, NULL);
120 b.shader->info.name = ralloc_asprintf(b.shader,
121 "meta_resolve_fs_samples%02d",
124 u_tex = nir_variable_create(b.shader, nir_var_uniform, sampler2DMS,
126 u_tex->data.descriptor_set = 0;
127 u_tex->data.binding = 0;
129 v_position = nir_variable_create(b.shader, nir_var_shader_in, vec4,
131 v_position->data.location = VARYING_SLOT_POS;
132 v_position->data.origin_upper_left = true;
134 v_tex_position = nir_variable_create(b.shader, nir_var_shader_in, vec4,
136 v_tex_position->data.location = VARYING_SLOT_VAR0;
138 f_color = nir_variable_create(b.shader, nir_var_shader_out, vec4,
140 f_color->data.location = FRAG_RESULT_DATA0;
142 accum = nir_imm_vec4(&b, 0, 0, 0, 0);
144 nir_ssa_def *tex_position_ivec =
145 nir_f2i(&b, nir_load_var(&b, v_tex_position));
147 for (uint32_t i = 0; i < num_samples; ++i) {
150 tex = nir_tex_instr_create(b.shader, /*num_srcs*/ 2);
151 tex->texture = nir_deref_var_create(tex, u_tex);
152 tex->sampler = nir_deref_var_create(tex, u_tex);
153 tex->sampler_dim = GLSL_SAMPLER_DIM_MS;
154 tex->op = nir_texop_txf_ms;
155 tex->src[0].src = nir_src_for_ssa(tex_position_ivec);
156 tex->src[0].src_type = nir_tex_src_coord;
157 tex->src[1].src = nir_src_for_ssa(nir_imm_int(&b, i));
158 tex->src[1].src_type = nir_tex_src_ms_index;
159 tex->dest_type = nir_type_float;
160 tex->is_array = false;
161 tex->coord_components = 3;
162 nir_ssa_dest_init(&tex->instr, &tex->dest, 4, 32, "tex");
163 nir_builder_instr_insert(&b, &tex->instr);
165 accum = nir_fadd(&b, accum, &tex->dest.ssa);
168 accum = nir_fdiv(&b, accum, nir_imm_float(&b, num_samples));
169 nir_store_var(&b, f_color, accum, /*writemask*/ 4);
175 create_pass(struct anv_device *device)
178 VkDevice device_h = anv_device_to_handle(device);
179 const VkAllocationCallbacks *alloc = &device->meta_state.alloc;
181 result = anv_CreateRenderPass(device_h,
182 &(VkRenderPassCreateInfo) {
183 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
184 .attachmentCount = 1,
185 .pAttachments = &(VkAttachmentDescription) {
186 .format = VK_FORMAT_UNDEFINED, /* Our shaders don't care */
188 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
189 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
190 .initialLayout = VK_IMAGE_LAYOUT_GENERAL,
191 .finalLayout = VK_IMAGE_LAYOUT_GENERAL,
194 .pSubpasses = &(VkSubpassDescription) {
195 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
196 .inputAttachmentCount = 0,
197 .colorAttachmentCount = 1,
198 .pColorAttachments = &(VkAttachmentReference) {
200 .layout = VK_IMAGE_LAYOUT_GENERAL,
202 .pResolveAttachments = NULL,
203 .pDepthStencilAttachment = &(VkAttachmentReference) {
204 .attachment = VK_ATTACHMENT_UNUSED,
206 .preserveAttachmentCount = 0,
207 .pPreserveAttachments = NULL,
209 .dependencyCount = 0,
212 &device->meta_state.resolve.pass);
218 create_pipeline(struct anv_device *device,
219 uint32_t num_samples,
220 VkShaderModule vs_module_h)
223 VkDevice device_h = anv_device_to_handle(device);
225 struct anv_shader_module fs_module = {
226 .nir = build_nir_fs(num_samples),
229 if (!fs_module.nir) {
230 /* XXX: Need more accurate error */
231 result = VK_ERROR_OUT_OF_HOST_MEMORY;
235 result = anv_graphics_pipeline_create(device_h,
237 &(VkGraphicsPipelineCreateInfo) {
238 .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
240 .pStages = (VkPipelineShaderStageCreateInfo[]) {
242 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
243 .stage = VK_SHADER_STAGE_VERTEX_BIT,
244 .module = vs_module_h,
248 .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
249 .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
250 .module = anv_shader_module_to_handle(&fs_module),
254 .pVertexInputState = &(VkPipelineVertexInputStateCreateInfo) {
255 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
256 .vertexBindingDescriptionCount = 1,
257 .pVertexBindingDescriptions = (VkVertexInputBindingDescription[]) {
260 .stride = sizeof(struct vertex_attrs),
261 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
264 .vertexAttributeDescriptionCount = 3,
265 .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[]) {
270 .format = VK_FORMAT_R32G32B32A32_UINT,
271 .offset = offsetof(struct vertex_attrs, vue_header),
277 .format = VK_FORMAT_R32G32_SFLOAT,
278 .offset = offsetof(struct vertex_attrs, position),
281 /* Texture Coordinate */
284 .format = VK_FORMAT_R32G32_SFLOAT,
285 .offset = offsetof(struct vertex_attrs, tex_position),
289 .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
290 .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
291 .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
292 .primitiveRestartEnable = false,
294 .pViewportState = &(VkPipelineViewportStateCreateInfo) {
295 .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
299 .pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
300 .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
301 .depthClampEnable = false,
302 .rasterizerDiscardEnable = false,
303 .polygonMode = VK_POLYGON_MODE_FILL,
304 .cullMode = VK_CULL_MODE_NONE,
305 .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE,
307 .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
308 .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
309 .rasterizationSamples = 1,
310 .sampleShadingEnable = false,
311 .pSampleMask = (VkSampleMask[]) { 0x1 },
312 .alphaToCoverageEnable = false,
313 .alphaToOneEnable = false,
315 .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
316 .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
317 .logicOpEnable = false,
318 .attachmentCount = 1,
319 .pAttachments = (VkPipelineColorBlendAttachmentState []) {
321 .colorWriteMask = VK_COLOR_COMPONENT_R_BIT |
322 VK_COLOR_COMPONENT_G_BIT |
323 VK_COLOR_COMPONENT_B_BIT |
324 VK_COLOR_COMPONENT_A_BIT,
328 .pDynamicState = &(VkPipelineDynamicStateCreateInfo) {
329 .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
330 .dynamicStateCount = 2,
331 .pDynamicStates = (VkDynamicState[]) {
332 VK_DYNAMIC_STATE_VIEWPORT,
333 VK_DYNAMIC_STATE_SCISSOR,
336 .layout = device->meta_state.resolve.pipeline_layout,
337 .renderPass = device->meta_state.resolve.pass,
340 &(struct anv_graphics_pipeline_create_info) {
341 .color_attachment_count = -1,
342 .use_repclear = false,
346 &device->meta_state.alloc,
347 get_pipeline_h(device, num_samples));
348 if (result != VK_SUCCESS)
354 ralloc_free(fs_module.nir);
359 anv_device_finish_meta_resolve_state(struct anv_device *device)
361 struct anv_meta_state *state = &device->meta_state;
362 VkDevice device_h = anv_device_to_handle(device);
363 VkRenderPass pass_h = device->meta_state.resolve.pass;
364 VkPipelineLayout pipeline_layout_h = device->meta_state.resolve.pipeline_layout;
365 VkDescriptorSetLayout ds_layout_h = device->meta_state.resolve.ds_layout;
366 const VkAllocationCallbacks *alloc = &device->meta_state.alloc;
369 ANV_CALL(DestroyRenderPass)(device_h, pass_h,
370 &device->meta_state.alloc);
372 if (pipeline_layout_h)
373 ANV_CALL(DestroyPipelineLayout)(device_h, pipeline_layout_h, alloc);
376 ANV_CALL(DestroyDescriptorSetLayout)(device_h, ds_layout_h, alloc);
378 for (uint32_t i = 0; i < ARRAY_SIZE(state->resolve.pipelines); ++i) {
379 VkPipeline pipeline_h = state->resolve.pipelines[i];
382 ANV_CALL(DestroyPipeline)(device_h, pipeline_h, alloc);
388 anv_device_init_meta_resolve_state(struct anv_device *device)
390 VkResult res = VK_SUCCESS;
391 VkDevice device_h = anv_device_to_handle(device);
392 const VkAllocationCallbacks *alloc = &device->meta_state.alloc;
394 const isl_sample_count_mask_t sample_count_mask =
395 isl_device_get_sample_counts(&device->isl_dev);
397 zero(device->meta_state.resolve);
399 struct anv_shader_module vs_module = { .nir = build_nir_vs() };
400 if (!vs_module.nir) {
401 /* XXX: Need more accurate error */
402 res = VK_ERROR_OUT_OF_HOST_MEMORY;
406 VkShaderModule vs_module_h = anv_shader_module_to_handle(&vs_module);
408 res = anv_CreateDescriptorSetLayout(device_h,
409 &(VkDescriptorSetLayoutCreateInfo) {
410 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
412 .pBindings = (VkDescriptorSetLayoutBinding[]) {
415 .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
416 .descriptorCount = 1,
417 .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
422 &device->meta_state.resolve.ds_layout);
423 if (res != VK_SUCCESS)
426 res = anv_CreatePipelineLayout(device_h,
427 &(VkPipelineLayoutCreateInfo) {
428 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
430 .pSetLayouts = (VkDescriptorSetLayout[]) {
431 device->meta_state.resolve.ds_layout,
435 &device->meta_state.resolve.pipeline_layout);
436 if (res != VK_SUCCESS)
439 res = create_pass(device);
440 if (res != VK_SUCCESS)
444 i < ARRAY_SIZE(device->meta_state.resolve.pipelines); ++i) {
446 uint32_t sample_count = 1 << (1 + i);
447 if (!(sample_count_mask & sample_count))
450 res = create_pipeline(device, sample_count, vs_module_h);
451 if (res != VK_SUCCESS)
458 anv_device_finish_meta_resolve_state(device);
461 ralloc_free(vs_module.nir);
467 emit_resolve(struct anv_cmd_buffer *cmd_buffer,
468 struct anv_image_view *src_iview,
469 const VkOffset2D *src_offset,
470 struct anv_image_view *dest_iview,
471 const VkOffset2D *dest_offset,
472 const VkExtent2D *resolve_extent)
474 struct anv_device *device = cmd_buffer->device;
475 VkDevice device_h = anv_device_to_handle(device);
476 VkCommandBuffer cmd_buffer_h = anv_cmd_buffer_to_handle(cmd_buffer);
477 const struct anv_image *src_image = src_iview->image;
479 const struct vertex_attrs vertex_data[3] = {
483 dest_offset->x + resolve_extent->width,
484 dest_offset->y + resolve_extent->height,
487 src_offset->x + resolve_extent->width,
488 src_offset->y + resolve_extent->height,
495 dest_offset->y + resolve_extent->height,
499 src_offset->y + resolve_extent->height,
515 struct anv_state vertex_mem =
516 anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data,
517 sizeof(vertex_data), 16);
519 struct anv_buffer vertex_buffer = {
521 .size = sizeof(vertex_data),
522 .bo = &cmd_buffer->dynamic_state_stream.block_pool->bo,
523 .offset = vertex_mem.offset,
526 VkBuffer vertex_buffer_h = anv_buffer_to_handle(&vertex_buffer);
528 anv_CmdBindVertexBuffers(cmd_buffer_h,
531 (VkBuffer[]) { vertex_buffer_h },
532 (VkDeviceSize[]) { 0 });
535 ANV_CALL(CreateSampler)(device_h,
536 &(VkSamplerCreateInfo) {
537 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
538 .magFilter = VK_FILTER_NEAREST,
539 .minFilter = VK_FILTER_NEAREST,
540 .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST,
541 .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
542 .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
543 .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
545 .anisotropyEnable = false,
546 .compareEnable = false,
549 .unnormalizedCoordinates = false,
551 &cmd_buffer->pool->alloc,
554 VkDescriptorPool desc_pool;
555 anv_CreateDescriptorPool(anv_device_to_handle(device),
556 &(const VkDescriptorPoolCreateInfo) {
557 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
562 .pPoolSizes = (VkDescriptorPoolSize[]) {
564 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
568 }, &cmd_buffer->pool->alloc, &desc_pool);
570 VkDescriptorSet desc_set_h;
571 anv_AllocateDescriptorSets(device_h,
572 &(VkDescriptorSetAllocateInfo) {
573 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
574 .descriptorPool = desc_pool,
575 .descriptorSetCount = 1,
576 .pSetLayouts = (VkDescriptorSetLayout[]) {
577 device->meta_state.resolve.ds_layout,
582 anv_UpdateDescriptorSets(device_h,
584 (VkWriteDescriptorSet[]) {
586 .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
587 .dstSet = desc_set_h,
589 .dstArrayElement = 0,
590 .descriptorCount = 1,
591 .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
592 .pImageInfo = (VkDescriptorImageInfo[]) {
594 .sampler = sampler_h,
595 .imageView = anv_image_view_to_handle(src_iview),
596 .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
604 VkPipeline pipeline_h = *get_pipeline_h(device, src_image->samples);
605 ANV_FROM_HANDLE(anv_pipeline, pipeline, pipeline_h);
607 if (cmd_buffer->state.pipeline != pipeline) {
608 anv_CmdBindPipeline(cmd_buffer_h, VK_PIPELINE_BIND_POINT_GRAPHICS,
612 anv_CmdBindDescriptorSets(cmd_buffer_h,
613 VK_PIPELINE_BIND_POINT_GRAPHICS,
614 device->meta_state.resolve.pipeline_layout,
617 (VkDescriptorSet[]) {
623 ANV_CALL(CmdDraw)(cmd_buffer_h, 3, 1, 0, 0);
625 /* All objects below are consumed by the draw call. We may safely destroy
628 anv_DestroyDescriptorPool(anv_device_to_handle(device),
629 desc_pool, &cmd_buffer->pool->alloc);
630 anv_DestroySampler(device_h, sampler_h,
631 &cmd_buffer->pool->alloc);
634 void anv_CmdResolveImage(
635 VkCommandBuffer cmd_buffer_h,
637 VkImageLayout src_image_layout,
638 VkImage dest_image_h,
639 VkImageLayout dest_image_layout,
640 uint32_t region_count,
641 const VkImageResolve* regions)
643 ANV_FROM_HANDLE(anv_cmd_buffer, cmd_buffer, cmd_buffer_h);
644 ANV_FROM_HANDLE(anv_image, src_image, src_image_h);
645 ANV_FROM_HANDLE(anv_image, dest_image, dest_image_h);
646 struct anv_device *device = cmd_buffer->device;
647 struct anv_meta_saved_state state;
648 VkDevice device_h = anv_device_to_handle(device);
650 meta_resolve_save(&state, cmd_buffer);
652 assert(src_image->samples > 1);
653 assert(dest_image->samples == 1);
655 if (src_image->samples >= 16) {
656 /* See commit aa3f9aaf31e9056a255f9e0472ebdfdaa60abe54 for the
657 * glBlitFramebuffer workaround for samples >= 16.
659 anv_finishme("vkCmdResolveImage: need interpolation workaround when "
663 if (src_image->array_size > 1)
664 anv_finishme("vkCmdResolveImage: multisample array images");
666 for (uint32_t r = 0; r < region_count; ++r) {
667 const VkImageResolve *region = ®ions[r];
669 /* From the Vulkan 1.0 spec:
671 * - The aspectMask member of srcSubresource and dstSubresource must
672 * only contain VK_IMAGE_ASPECT_COLOR_BIT
674 * - The layerCount member of srcSubresource and dstSubresource must
677 assert(region->srcSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
678 assert(region->dstSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
679 assert(region->srcSubresource.layerCount ==
680 region->dstSubresource.layerCount);
682 const uint32_t src_base_layer =
683 anv_meta_get_iview_layer(src_image, ®ion->srcSubresource,
686 const uint32_t dest_base_layer =
687 anv_meta_get_iview_layer(dest_image, ®ion->dstSubresource,
691 * From Vulkan 1.0.6 spec: 18.6 Resolving Multisample Images
693 * extent is the size in texels of the source image to resolve in width,
694 * height and depth. 1D images use only x and width. 2D images use x, y,
695 * width and height. 3D images use x, y, z, width, height and depth.
697 * srcOffset and dstOffset select the initial x, y, and z offsets in
698 * texels of the sub-regions of the source and destination image data.
699 * extent is the size in texels of the source image to resolve in width,
700 * height and depth. 1D images use only x and width. 2D images use x, y,
701 * width and height. 3D images use x, y, z, width, height and depth.
703 const struct VkExtent3D extent =
704 anv_sanitize_image_extent(src_image->type, region->extent);
705 const struct VkOffset3D srcOffset =
706 anv_sanitize_image_offset(src_image->type, region->srcOffset);
707 const struct VkOffset3D dstOffset =
708 anv_sanitize_image_offset(dest_image->type, region->dstOffset);
711 for (uint32_t layer = 0; layer < region->srcSubresource.layerCount;
714 struct anv_image_view src_iview;
715 anv_image_view_init(&src_iview, cmd_buffer->device,
716 &(VkImageViewCreateInfo) {
717 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
718 .image = src_image_h,
719 .viewType = anv_meta_get_view_type(src_image),
720 .format = src_image->vk_format,
721 .subresourceRange = {
722 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
723 .baseMipLevel = region->srcSubresource.mipLevel,
725 .baseArrayLayer = src_base_layer + layer,
729 cmd_buffer, VK_IMAGE_USAGE_SAMPLED_BIT);
731 struct anv_image_view dest_iview;
732 anv_image_view_init(&dest_iview, cmd_buffer->device,
733 &(VkImageViewCreateInfo) {
734 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
735 .image = dest_image_h,
736 .viewType = anv_meta_get_view_type(dest_image),
737 .format = dest_image->vk_format,
738 .subresourceRange = {
739 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
740 .baseMipLevel = region->dstSubresource.mipLevel,
742 .baseArrayLayer = dest_base_layer + layer,
746 cmd_buffer, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT);
749 anv_CreateFramebuffer(device_h,
750 &(VkFramebufferCreateInfo) {
751 .sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
752 .attachmentCount = 1,
753 .pAttachments = (VkImageView[]) {
754 anv_image_view_to_handle(&dest_iview),
756 .width = anv_minify(dest_image->extent.width,
757 region->dstSubresource.mipLevel),
758 .height = anv_minify(dest_image->extent.height,
759 region->dstSubresource.mipLevel),
762 &cmd_buffer->pool->alloc,
765 ANV_CALL(CmdBeginRenderPass)(cmd_buffer_h,
766 &(VkRenderPassBeginInfo) {
767 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
768 .renderPass = device->meta_state.resolve.pass,
780 .clearValueCount = 0,
781 .pClearValues = NULL,
783 VK_SUBPASS_CONTENTS_INLINE);
785 emit_resolve(cmd_buffer,
797 .width = extent.width,
798 .height = extent.height,
801 ANV_CALL(CmdEndRenderPass)(cmd_buffer_h);
803 anv_DestroyFramebuffer(device_h, fb_h,
804 &cmd_buffer->pool->alloc);
808 meta_resolve_restore(&state, cmd_buffer);
812 * Emit any needed resolves for the current subpass.
815 anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer)
817 struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
818 struct anv_subpass *subpass = cmd_buffer->state.subpass;
819 struct anv_meta_saved_state saved_state;
821 /* FINISHME(perf): Skip clears for resolve attachments.
823 * From the Vulkan 1.0 spec:
825 * If the first use of an attachment in a render pass is as a resolve
826 * attachment, then the loadOp is effectively ignored as the resolve is
827 * guaranteed to overwrite all pixels in the render area.
830 if (!subpass->has_resolve)
833 meta_resolve_save(&saved_state, cmd_buffer);
835 for (uint32_t i = 0; i < subpass->color_count; ++i) {
836 uint32_t src_att = subpass->color_attachments[i];
837 uint32_t dest_att = subpass->resolve_attachments[i];
839 if (dest_att == VK_ATTACHMENT_UNUSED)
842 struct anv_image_view *src_iview = fb->attachments[src_att];
843 struct anv_image_view *dest_iview = fb->attachments[dest_att];
845 struct anv_subpass resolve_subpass = {
847 .color_attachments = (uint32_t[]) { dest_att },
848 .depth_stencil_attachment = VK_ATTACHMENT_UNUSED,
851 anv_cmd_buffer_set_subpass(cmd_buffer, &resolve_subpass);
853 /* Subpass resolves must respect the render area. We can ignore the
854 * render area here because vkCmdBeginRenderPass set the render area
855 * with 3DSTATE_DRAWING_RECTANGLE.
857 * XXX(chadv): Does the hardware really respect
858 * 3DSTATE_DRAWING_RECTANGLE when draing a 3DPRIM_RECTLIST?
860 emit_resolve(cmd_buffer,
862 &(VkOffset2D) { 0, 0 },
864 &(VkOffset2D) { 0, 0 },
865 &(VkExtent2D) { fb->width, fb->height });
868 cmd_buffer->state.subpass = subpass;
869 meta_resolve_restore(&saved_state, cmd_buffer);