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 "glsl/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
,
45 (1 << VK_DYNAMIC_STATE_VIEWPORT
) |
46 (1 << VK_DYNAMIC_STATE_SCISSOR
));
48 cmd_buffer
->state
.dynamic
.viewport
.count
= 0;
49 cmd_buffer
->state
.dynamic
.scissor
.count
= 0;
53 meta_resolve_restore(struct anv_meta_saved_state
*saved_state
,
54 struct anv_cmd_buffer
*cmd_buffer
)
56 anv_meta_restore(saved_state
, cmd_buffer
);
60 get_pipeline_h(struct anv_device
*device
, uint32_t samples
)
62 uint32_t i
= ffs(samples
) - 2; /* log2(samples) - 1 */
65 assert(i
< ARRAY_SIZE(device
->meta_state
.resolve
.pipelines
));
67 return &device
->meta_state
.resolve
.pipelines
[i
];
73 const struct glsl_type
*vec4
= glsl_vec4_type();
76 nir_variable
*a_position
;
77 nir_variable
*v_position
;
78 nir_variable
*a_tex_position
;
79 nir_variable
*v_tex_position
;
81 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
82 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "meta_resolve_vs");
84 a_position
= nir_variable_create(b
.shader
, nir_var_shader_in
, vec4
,
86 a_position
->data
.location
= VERT_ATTRIB_GENERIC0
;
88 v_position
= nir_variable_create(b
.shader
, nir_var_shader_out
, vec4
,
90 v_position
->data
.location
= VARYING_SLOT_POS
;
92 a_tex_position
= nir_variable_create(b
.shader
, nir_var_shader_in
, vec4
,
94 a_tex_position
->data
.location
= VERT_ATTRIB_GENERIC1
;
96 v_tex_position
= nir_variable_create(b
.shader
, nir_var_shader_out
, vec4
,
98 v_tex_position
->data
.location
= VARYING_SLOT_VAR0
;
100 nir_copy_var(&b
, v_position
, a_position
);
101 nir_copy_var(&b
, v_tex_position
, a_tex_position
);
107 build_nir_fs(uint32_t num_samples
)
109 const struct glsl_type
*vec4
= glsl_vec4_type();
111 const struct glsl_type
*sampler2DMS
=
112 glsl_sampler_type(GLSL_SAMPLER_DIM_MS
,
118 nir_variable
*u_tex
; /* uniform sampler */
119 nir_variable
*v_position
; /* vec4, varying fragment position */
120 nir_variable
*v_tex_position
; /* vec4, varying texture coordinate */
121 nir_variable
*f_color
; /* vec4, fragment output color */
122 nir_ssa_def
*accum
; /* vec4, accumulation of sample values */
124 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
125 b
.shader
->info
.name
= ralloc_asprintf(b
.shader
,
126 "meta_resolve_fs_samples%02d",
129 u_tex
= nir_variable_create(b
.shader
, nir_var_uniform
, sampler2DMS
,
131 u_tex
->data
.descriptor_set
= 0;
132 u_tex
->data
.binding
= 0;
134 v_position
= nir_variable_create(b
.shader
, nir_var_shader_in
, vec4
,
136 v_position
->data
.location
= VARYING_SLOT_POS
;
138 v_tex_position
= nir_variable_create(b
.shader
, nir_var_shader_in
, vec4
,
140 v_tex_position
->data
.location
= VARYING_SLOT_VAR0
;
142 f_color
= nir_variable_create(b
.shader
, nir_var_shader_out
, vec4
,
144 f_color
->data
.location
= FRAG_RESULT_DATA0
;
146 accum
= nir_imm_vec4(&b
, 0, 0, 0, 0);
148 nir_ssa_def
*tex_position_ivec
=
149 nir_f2i(&b
, nir_load_var(&b
, v_tex_position
));
151 for (uint32_t i
= 0; i
< num_samples
; ++i
) {
154 tex
= nir_tex_instr_create(b
.shader
, /*num_srcs*/ 2);
155 tex
->sampler
= nir_deref_var_create(tex
, u_tex
);
156 tex
->sampler_dim
= GLSL_SAMPLER_DIM_MS
;
157 tex
->op
= nir_texop_txf_ms
;
158 tex
->src
[0].src
= nir_src_for_ssa(tex_position_ivec
);
159 tex
->src
[0].src_type
= nir_tex_src_coord
;
160 tex
->src
[1].src
= nir_src_for_ssa(nir_imm_int(&b
, i
));
161 tex
->src
[1].src_type
= nir_tex_src_ms_index
;
162 tex
->dest_type
= nir_type_float
;
163 tex
->is_array
= false;
164 tex
->coord_components
= 3;
165 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, /*num_components*/ 4, "tex");
166 nir_builder_instr_insert(&b
, &tex
->instr
);
168 accum
= nir_fadd(&b
, accum
, &tex
->dest
.ssa
);
171 accum
= nir_fdiv(&b
, accum
, nir_imm_float(&b
, num_samples
));
172 nir_store_var(&b
, f_color
, accum
, /*writemask*/ 4);
178 create_pass(struct anv_device
*device
)
181 VkDevice device_h
= anv_device_to_handle(device
);
182 const VkAllocationCallbacks
*alloc
= &device
->meta_state
.alloc
;
184 result
= anv_CreateRenderPass(device_h
,
185 &(VkRenderPassCreateInfo
) {
186 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
187 .attachmentCount
= 1,
188 .pAttachments
= &(VkAttachmentDescription
) {
189 .format
= VK_FORMAT_UNDEFINED
, /* Our shaders don't care */
191 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
192 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
193 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
194 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
197 .pSubpasses
= &(VkSubpassDescription
) {
198 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
199 .inputAttachmentCount
= 0,
200 .colorAttachmentCount
= 1,
201 .pColorAttachments
= &(VkAttachmentReference
) {
203 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
205 .pResolveAttachments
= NULL
,
206 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
207 .attachment
= VK_ATTACHMENT_UNUSED
,
209 .preserveAttachmentCount
= 0,
210 .pPreserveAttachments
= NULL
,
212 .dependencyCount
= 0,
215 &device
->meta_state
.resolve
.pass
);
221 create_pipeline(struct anv_device
*device
,
222 uint32_t num_samples
,
223 VkShaderModule vs_module_h
)
226 VkDevice device_h
= anv_device_to_handle(device
);
228 struct anv_shader_module fs_module
= {
229 .nir
= build_nir_fs(num_samples
),
232 if (!fs_module
.nir
) {
233 /* XXX: Need more accurate error */
234 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
238 result
= anv_graphics_pipeline_create(device_h
,
240 &(VkGraphicsPipelineCreateInfo
) {
241 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
243 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
245 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
246 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
247 .module
= vs_module_h
,
251 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
252 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
253 .module
= anv_shader_module_to_handle(&fs_module
),
257 .pVertexInputState
= &(VkPipelineVertexInputStateCreateInfo
) {
258 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
259 .vertexBindingDescriptionCount
= 1,
260 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
263 .stride
= sizeof(struct vertex_attrs
),
264 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
267 .vertexAttributeDescriptionCount
= 3,
268 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
273 .format
= VK_FORMAT_R32G32B32A32_UINT
,
274 .offset
= offsetof(struct vertex_attrs
, vue_header
),
280 .format
= VK_FORMAT_R32G32_SFLOAT
,
281 .offset
= offsetof(struct vertex_attrs
, position
),
284 /* Texture Coordinate */
287 .format
= VK_FORMAT_R32G32_SFLOAT
,
288 .offset
= offsetof(struct vertex_attrs
, tex_position
),
292 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
293 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
294 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
295 .primitiveRestartEnable
= false,
297 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
298 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
302 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
303 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
304 .depthClampEnable
= false,
305 .rasterizerDiscardEnable
= false,
306 .polygonMode
= VK_POLYGON_MODE_FILL
,
307 .cullMode
= VK_CULL_MODE_NONE
,
308 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
,
310 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
311 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
312 .rasterizationSamples
= 1,
313 .sampleShadingEnable
= false,
314 .pSampleMask
= (VkSampleMask
[]) { 0x1 },
315 .alphaToCoverageEnable
= false,
316 .alphaToOneEnable
= false,
318 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
319 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
320 .logicOpEnable
= false,
321 .attachmentCount
= 1,
322 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
324 .colorWriteMask
= VK_COLOR_COMPONENT_R_BIT
|
325 VK_COLOR_COMPONENT_G_BIT
|
326 VK_COLOR_COMPONENT_B_BIT
|
327 VK_COLOR_COMPONENT_A_BIT
,
331 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
332 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
333 .dynamicStateCount
= 2,
334 .pDynamicStates
= (VkDynamicState
[]) {
335 VK_DYNAMIC_STATE_VIEWPORT
,
336 VK_DYNAMIC_STATE_SCISSOR
,
339 .layout
= device
->meta_state
.resolve
.pipeline_layout
,
340 .renderPass
= device
->meta_state
.resolve
.pass
,
343 &(struct anv_graphics_pipeline_create_info
) {
344 .color_attachment_count
= -1,
345 .use_repclear
= false,
346 .disable_viewport
= true,
347 .disable_scissor
= true,
351 &device
->meta_state
.alloc
,
352 get_pipeline_h(device
, num_samples
));
353 if (result
!= VK_SUCCESS
)
359 ralloc_free(fs_module
.nir
);
364 anv_device_finish_meta_resolve_state(struct anv_device
*device
)
366 struct anv_meta_state
*state
= &device
->meta_state
;
367 VkDevice device_h
= anv_device_to_handle(device
);
368 VkRenderPass pass_h
= device
->meta_state
.resolve
.pass
;
369 VkPipelineLayout pipeline_layout_h
= device
->meta_state
.resolve
.pipeline_layout
;
370 VkDescriptorSetLayout ds_layout_h
= device
->meta_state
.resolve
.ds_layout
;
371 const VkAllocationCallbacks
*alloc
= &device
->meta_state
.alloc
;
374 ANV_CALL(DestroyRenderPass
)(device_h
, pass_h
,
375 &device
->meta_state
.alloc
);
377 if (pipeline_layout_h
)
378 ANV_CALL(DestroyPipelineLayout
)(device_h
, pipeline_layout_h
, alloc
);
381 ANV_CALL(DestroyDescriptorSetLayout
)(device_h
, ds_layout_h
, alloc
);
383 for (uint32_t i
= 0; i
< ARRAY_SIZE(state
->resolve
.pipelines
); ++i
) {
384 VkPipeline pipeline_h
= state
->resolve
.pipelines
[i
];
387 ANV_CALL(DestroyPipeline
)(device_h
, pipeline_h
, alloc
);
393 anv_device_init_meta_resolve_state(struct anv_device
*device
)
395 VkResult res
= VK_SUCCESS
;
396 VkDevice device_h
= anv_device_to_handle(device
);
397 const VkAllocationCallbacks
*alloc
= &device
->meta_state
.alloc
;
399 const isl_sample_count_mask_t sample_count_mask
=
400 isl_device_get_sample_counts(&device
->isl_dev
);
402 zero(device
->meta_state
.resolve
);
404 struct anv_shader_module vs_module
= { .nir
= build_nir_vs() };
405 if (!vs_module
.nir
) {
406 /* XXX: Need more accurate error */
407 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
411 VkShaderModule vs_module_h
= anv_shader_module_to_handle(&vs_module
);
413 res
= anv_CreateDescriptorSetLayout(device_h
,
414 &(VkDescriptorSetLayoutCreateInfo
) {
415 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
417 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
420 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
421 .descriptorCount
= 1,
422 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
427 &device
->meta_state
.resolve
.ds_layout
);
428 if (res
!= VK_SUCCESS
)
431 res
= anv_CreatePipelineLayout(device_h
,
432 &(VkPipelineLayoutCreateInfo
) {
433 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
435 .pSetLayouts
= (VkDescriptorSetLayout
[]) {
436 device
->meta_state
.resolve
.ds_layout
,
440 &device
->meta_state
.resolve
.pipeline_layout
);
441 if (res
!= VK_SUCCESS
)
444 res
= create_pass(device
);
445 if (res
!= VK_SUCCESS
)
449 i
< ARRAY_SIZE(device
->meta_state
.resolve
.pipelines
); ++i
) {
451 uint32_t sample_count
= 1 << (1 + i
);
452 if (!(sample_count_mask
& sample_count
))
455 res
= create_pipeline(device
, sample_count
, vs_module_h
);
456 if (res
!= VK_SUCCESS
)
463 anv_device_finish_meta_resolve_state(device
);
466 ralloc_free(vs_module
.nir
);
472 emit_resolve(struct anv_cmd_buffer
*cmd_buffer
,
473 struct anv_image_view
*src_iview
,
474 const VkOffset2D
*src_offset
,
475 struct anv_image_view
*dest_iview
,
476 const VkOffset2D
*dest_offset
,
477 const VkExtent2D
*resolve_extent
)
479 struct anv_device
*device
= cmd_buffer
->device
;
480 VkDevice device_h
= anv_device_to_handle(device
);
481 VkCommandBuffer cmd_buffer_h
= anv_cmd_buffer_to_handle(cmd_buffer
);
482 const struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
483 const struct anv_image
*src_image
= src_iview
->image
;
484 VkDescriptorPool dummy_desc_pool_h
= (VkDescriptorPool
) 1;
486 const struct vertex_attrs vertex_data
[3] = {
490 dest_offset
->x
+ resolve_extent
->width
,
491 dest_offset
->y
+ resolve_extent
->height
,
494 src_offset
->x
+ resolve_extent
->width
,
495 src_offset
->y
+ resolve_extent
->height
,
502 dest_offset
->y
+ resolve_extent
->height
,
506 src_offset
->y
+ resolve_extent
->height
,
522 struct anv_state vertex_mem
=
523 anv_cmd_buffer_emit_dynamic(cmd_buffer
, vertex_data
,
524 sizeof(vertex_data
), 16);
526 struct anv_buffer vertex_buffer
= {
528 .size
= sizeof(vertex_data
),
529 .bo
= &cmd_buffer
->dynamic_state_stream
.block_pool
->bo
,
530 .offset
= vertex_mem
.offset
,
533 VkBuffer vertex_buffer_h
= anv_buffer_to_handle(&vertex_buffer
);
535 anv_CmdBindVertexBuffers(cmd_buffer_h
,
538 (VkBuffer
[]) { vertex_buffer_h
},
539 (VkDeviceSize
[]) { 0 });
542 ANV_CALL(CreateSampler
)(device_h
,
543 &(VkSamplerCreateInfo
) {
544 .sType
= VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
,
545 .magFilter
= VK_FILTER_NEAREST
,
546 .minFilter
= VK_FILTER_NEAREST
,
547 .mipmapMode
= VK_SAMPLER_MIPMAP_MODE_NEAREST
,
548 .addressModeU
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
549 .addressModeV
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
550 .addressModeW
= VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
,
552 .anisotropyEnable
= false,
553 .compareEnable
= false,
556 .unnormalizedCoordinates
= false,
558 &cmd_buffer
->pool
->alloc
,
561 VkDescriptorSet desc_set_h
;
562 anv_AllocateDescriptorSets(device_h
,
563 &(VkDescriptorSetAllocateInfo
) {
564 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO
,
565 .descriptorPool
= dummy_desc_pool_h
,
566 .descriptorSetCount
= 1,
567 .pSetLayouts
= (VkDescriptorSetLayout
[]) {
568 device
->meta_state
.blit
.ds_layout
,
573 ANV_FROM_HANDLE(anv_descriptor_set
, desc_set
, desc_set_h
);
575 anv_UpdateDescriptorSets(device_h
,
577 (VkWriteDescriptorSet
[]) {
579 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
580 .dstSet
= desc_set_h
,
582 .dstArrayElement
= 0,
583 .descriptorCount
= 1,
584 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
585 .pImageInfo
= (VkDescriptorImageInfo
[]) {
587 .sampler
= sampler_h
,
588 .imageView
= anv_image_view_to_handle(src_iview
),
589 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
597 ANV_CALL(CmdSetViewport
)(cmd_buffer_h
,
605 .height
= fb
->height
,
611 ANV_CALL(CmdSetScissor
)(cmd_buffer_h
,
617 .extent
= (VkExtent2D
) { fb
->width
, fb
->height
},
621 VkPipeline pipeline_h
= *get_pipeline_h(device
, src_image
->samples
);
622 ANV_FROM_HANDLE(anv_pipeline
, pipeline
, pipeline_h
);
624 if (cmd_buffer
->state
.pipeline
!= pipeline
) {
625 anv_CmdBindPipeline(cmd_buffer_h
, VK_PIPELINE_BIND_POINT_GRAPHICS
,
629 anv_CmdBindDescriptorSets(cmd_buffer_h
,
630 VK_PIPELINE_BIND_POINT_GRAPHICS
,
631 device
->meta_state
.resolve
.pipeline_layout
,
634 (VkDescriptorSet
[]) {
640 ANV_CALL(CmdDraw
)(cmd_buffer_h
, 3, 1, 0, 0);
642 /* All objects below are consumed by the draw call. We may safely destroy
645 anv_descriptor_set_destroy(device
, desc_set
);
646 anv_DestroySampler(device_h
, sampler_h
,
647 &cmd_buffer
->pool
->alloc
);
650 void anv_CmdResolveImage(
651 VkCommandBuffer cmd_buffer_h
,
653 VkImageLayout src_image_layout
,
654 VkImage dest_image_h
,
655 VkImageLayout dest_image_layout
,
656 uint32_t region_count
,
657 const VkImageResolve
* regions
)
659 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmd_buffer_h
);
660 ANV_FROM_HANDLE(anv_image
, src_image
, src_image_h
);
661 ANV_FROM_HANDLE(anv_image
, dest_image
, dest_image_h
);
662 struct anv_device
*device
= cmd_buffer
->device
;
663 struct anv_meta_saved_state state
;
664 VkDevice device_h
= anv_device_to_handle(device
);
666 meta_resolve_save(&state
, cmd_buffer
);
668 assert(src_image
->samples
> 1);
669 assert(dest_image
->samples
== 1);
671 if (src_image
->samples
>= 16) {
672 /* See commit aa3f9aaf31e9056a255f9e0472ebdfdaa60abe54 for the
673 * glBlitFramebuffer workaround for samples >= 16.
675 anv_finishme("vkCmdResolveImage: need interpolation workaround when "
679 if (src_image
->array_size
> 1)
680 anv_finishme("vkCmdResolveImage: multisample array images");
682 for (uint32_t r
= 0; r
< region_count
; ++r
) {
683 const VkImageResolve
*region
= ®ions
[r
];
685 /* From the Vulkan 1.0 spec:
687 * - The aspectMask member of srcSubresource and dstSubresource must
688 * only contain VK_IMAGE_ASPECT_COLOR_BIT
690 * - The layerCount member of srcSubresource and dstSubresource must
693 assert(region
->srcSubresource
.aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
694 assert(region
->dstSubresource
.aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
695 assert(region
->srcSubresource
.layerCount
==
696 region
->dstSubresource
.layerCount
);
698 const uint32_t src_base_layer
=
699 anv_meta_get_iview_layer(src_image
, ®ion
->srcSubresource
,
702 const uint32_t dest_base_layer
=
703 anv_meta_get_iview_layer(dest_image
, ®ion
->dstSubresource
,
706 for (uint32_t layer
= 0; layer
< region
->srcSubresource
.layerCount
;
709 struct anv_image_view src_iview
;
710 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
711 &(VkImageViewCreateInfo
) {
712 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
713 .image
= src_image_h
,
714 .viewType
= anv_meta_get_view_type(src_image
),
715 .format
= src_image
->format
->vk_format
,
716 .subresourceRange
= {
717 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
718 .baseMipLevel
= region
->srcSubresource
.mipLevel
,
720 .baseArrayLayer
= src_base_layer
+ layer
,
726 struct anv_image_view dest_iview
;
727 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
728 &(VkImageViewCreateInfo
) {
729 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
730 .image
= dest_image_h
,
731 .viewType
= anv_meta_get_view_type(dest_image
),
732 .format
= dest_image
->format
->vk_format
,
733 .subresourceRange
= {
734 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
735 .baseMipLevel
= region
->dstSubresource
.mipLevel
,
737 .baseArrayLayer
= dest_base_layer
+ layer
,
744 anv_CreateFramebuffer(device_h
,
745 &(VkFramebufferCreateInfo
) {
746 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
747 .attachmentCount
= 1,
748 .pAttachments
= (VkImageView
[]) {
749 anv_image_view_to_handle(&dest_iview
),
751 .width
= anv_minify(dest_image
->extent
.width
,
752 region
->dstSubresource
.mipLevel
),
753 .height
= anv_minify(dest_image
->extent
.height
,
754 region
->dstSubresource
.mipLevel
),
757 &cmd_buffer
->pool
->alloc
,
760 ANV_CALL(CmdBeginRenderPass
)(cmd_buffer_h
,
761 &(VkRenderPassBeginInfo
) {
762 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
763 .renderPass
= device
->meta_state
.resolve
.pass
,
771 region
->extent
.width
,
772 region
->extent
.height
,
775 .clearValueCount
= 0,
776 .pClearValues
= NULL
,
778 VK_SUBPASS_CONTENTS_INLINE
);
780 emit_resolve(cmd_buffer
,
783 .x
= region
->srcOffset
.x
,
784 .y
= region
->srcOffset
.y
,
788 .x
= region
->dstOffset
.x
,
789 .y
= region
->dstOffset
.y
,
792 .width
= region
->extent
.width
,
793 .height
= region
->extent
.height
,
796 ANV_CALL(CmdEndRenderPass
)(cmd_buffer_h
);
798 anv_DestroyFramebuffer(device_h
, fb_h
,
799 &cmd_buffer
->pool
->alloc
);
803 meta_resolve_restore(&state
, cmd_buffer
);