2 * Copyright © 2015 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
31 #include "anv_meta_clear.h"
32 #include "anv_private.h"
33 #include "anv_nir_builder.h"
35 struct anv_render_pass anv_meta_dummy_renderpass
= {0};
38 build_nir_vertex_shader(bool attr_flat
)
42 const struct glsl_type
*vertex_type
= glsl_vec4_type();
44 nir_builder_init_simple_shader(&b
, MESA_SHADER_VERTEX
);
46 nir_variable
*pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
47 vertex_type
, "a_pos");
48 pos_in
->data
.location
= VERT_ATTRIB_GENERIC0
;
49 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
50 vertex_type
, "gl_Position");
51 pos_in
->data
.location
= VARYING_SLOT_POS
;
52 nir_copy_var(&b
, pos_out
, pos_in
);
54 /* Add one more pass-through attribute. For clear shaders, this is used
55 * to store the color and for blit shaders it's the texture coordinate.
57 const struct glsl_type
*attr_type
= glsl_vec4_type();
58 nir_variable
*attr_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
60 attr_in
->data
.location
= VERT_ATTRIB_GENERIC1
;
61 nir_variable
*attr_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
63 attr_out
->data
.location
= VARYING_SLOT_VAR0
;
64 attr_out
->data
.interpolation
= attr_flat
? INTERP_QUALIFIER_FLAT
:
65 INTERP_QUALIFIER_SMOOTH
;
66 nir_copy_var(&b
, attr_out
, attr_in
);
72 build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim
)
76 nir_builder_init_simple_shader(&b
, MESA_SHADER_FRAGMENT
);
78 const struct glsl_type
*color_type
= glsl_vec4_type();
80 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
81 glsl_vec4_type(), "v_attr");
82 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
84 const struct glsl_type
*sampler_type
=
85 glsl_sampler_type(tex_dim
, false, false, glsl_get_base_type(color_type
));
86 nir_variable
*sampler
= nir_variable_create(b
.shader
, nir_var_uniform
,
87 sampler_type
, "s_tex");
88 sampler
->data
.descriptor_set
= 0;
89 sampler
->data
.binding
= 0;
91 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 1);
92 tex
->sampler_dim
= tex_dim
;
93 tex
->op
= nir_texop_tex
;
94 tex
->src
[0].src_type
= nir_tex_src_coord
;
95 tex
->src
[0].src
= nir_src_for_ssa(nir_load_var(&b
, tex_pos_in
));
96 tex
->dest_type
= nir_type_float
; /* TODO */
98 if (tex_dim
== GLSL_SAMPLER_DIM_2D
)
100 tex
->coord_components
= 3;
102 tex
->sampler
= nir_deref_var_create(tex
, sampler
);
104 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, "tex");
105 nir_builder_instr_insert(&b
, &tex
->instr
);
107 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
108 color_type
, "f_color");
109 color_out
->data
.location
= FRAG_RESULT_DATA0
;
110 nir_store_var(&b
, color_out
, &tex
->dest
.ssa
);
116 anv_meta_save(struct anv_meta_saved_state
*state
,
117 const struct anv_cmd_buffer
*cmd_buffer
,
118 uint32_t dynamic_mask
)
120 state
->old_pipeline
= cmd_buffer
->state
.pipeline
;
121 state
->old_descriptor_set0
= cmd_buffer
->state
.descriptors
[0];
122 memcpy(state
->old_vertex_bindings
, cmd_buffer
->state
.vertex_bindings
,
123 sizeof(state
->old_vertex_bindings
));
125 state
->dynamic_mask
= dynamic_mask
;
126 anv_dynamic_state_copy(&state
->dynamic
, &cmd_buffer
->state
.dynamic
,
131 anv_meta_restore(const struct anv_meta_saved_state
*state
,
132 struct anv_cmd_buffer
*cmd_buffer
)
134 cmd_buffer
->state
.pipeline
= state
->old_pipeline
;
135 cmd_buffer
->state
.descriptors
[0] = state
->old_descriptor_set0
;
136 memcpy(cmd_buffer
->state
.vertex_bindings
, state
->old_vertex_bindings
,
137 sizeof(state
->old_vertex_bindings
));
139 cmd_buffer
->state
.vb_dirty
|= (1 << ANV_META_VERTEX_BINDING_COUNT
) - 1;
140 cmd_buffer
->state
.dirty
|= ANV_CMD_DIRTY_PIPELINE
;
141 cmd_buffer
->state
.descriptors_dirty
|= VK_SHADER_STAGE_VERTEX_BIT
;
143 anv_dynamic_state_copy(&cmd_buffer
->state
.dynamic
, &state
->dynamic
,
144 state
->dynamic_mask
);
145 cmd_buffer
->state
.dirty
|= state
->dynamic_mask
;
148 static VkImageViewType
149 meta_blit_get_src_image_view_type(const struct anv_image
*src_image
)
151 switch (src_image
->type
) {
152 case VK_IMAGE_TYPE_1D
:
153 return VK_IMAGE_VIEW_TYPE_1D
;
154 case VK_IMAGE_TYPE_2D
:
155 return VK_IMAGE_VIEW_TYPE_2D
;
156 case VK_IMAGE_TYPE_3D
:
157 return VK_IMAGE_VIEW_TYPE_3D
;
159 assert(!"bad VkImageType");
165 meta_blit_get_dest_view_base_array_slice(const struct anv_image
*dest_image
,
166 const VkImageSubresourceCopy
*dest_subresource
,
167 const VkOffset3D
*dest_offset
)
169 switch (dest_image
->type
) {
170 case VK_IMAGE_TYPE_1D
:
171 case VK_IMAGE_TYPE_2D
:
172 return dest_subresource
->arrayLayer
;
173 case VK_IMAGE_TYPE_3D
:
174 /* HACK: Vulkan does not allow attaching a 3D image to a framebuffer,
175 * but meta does it anyway. When doing so, we translate the
176 * destination's z offset into an array offset.
178 return dest_offset
->z
;
180 assert(!"bad VkImageType");
186 anv_device_init_meta_blit_state(struct anv_device
*device
)
188 anv_CreateRenderPass(anv_device_to_handle(device
),
189 &(VkRenderPassCreateInfo
) {
190 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
191 .attachmentCount
= 1,
192 .pAttachments
= &(VkAttachmentDescription
) {
193 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION
,
194 .format
= VK_FORMAT_UNDEFINED
, /* Our shaders don't care */
195 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
196 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
197 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
198 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
201 .pSubpasses
= &(VkSubpassDescription
) {
202 .sType
= VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION
,
203 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
206 .pColorAttachments
= &(VkAttachmentReference
) {
208 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
210 .pResolveAttachments
= NULL
,
211 .depthStencilAttachment
= (VkAttachmentReference
) {
212 .attachment
= VK_ATTACHMENT_UNUSED
,
213 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
216 .pPreserveAttachments
= &(VkAttachmentReference
) {
218 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
221 .dependencyCount
= 0,
222 }, &device
->meta_state
.blit
.render_pass
);
224 /* We don't use a vertex shader for clearing, but instead build and pass
225 * the VUEs directly to the rasterization backend. However, we do need
226 * to provide GLSL source for the vertex shader so that the compiler
227 * does not dead-code our inputs.
229 struct anv_shader_module vsm
= {
230 .nir
= build_nir_vertex_shader(false),
233 struct anv_shader_module fsm_2d
= {
234 .nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_2D
),
237 struct anv_shader_module fsm_3d
= {
238 .nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_3D
),
242 anv_CreateShader(anv_device_to_handle(device
),
243 &(VkShaderCreateInfo
) {
244 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
245 .module
= anv_shader_module_to_handle(&vsm
),
250 anv_CreateShader(anv_device_to_handle(device
),
251 &(VkShaderCreateInfo
) {
252 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
253 .module
= anv_shader_module_to_handle(&fsm_2d
),
258 anv_CreateShader(anv_device_to_handle(device
),
259 &(VkShaderCreateInfo
) {
260 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
261 .module
= anv_shader_module_to_handle(&fsm_3d
),
265 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
266 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
268 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
272 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
276 .strideInBytes
= 5 * sizeof(float),
277 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
281 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
286 .format
= VK_FORMAT_R32G32B32A32_UINT
,
293 .format
= VK_FORMAT_R32G32_SFLOAT
,
297 /* Texture Coordinate */
300 .format
= VK_FORMAT_R32G32B32_SFLOAT
,
306 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
307 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
309 .pBinding
= (VkDescriptorSetLayoutBinding
[]) {
311 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
313 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
314 .pImmutableSamplers
= NULL
318 anv_CreateDescriptorSetLayout(anv_device_to_handle(device
), &ds_layout_info
,
319 &device
->meta_state
.blit
.ds_layout
);
321 anv_CreatePipelineLayout(anv_device_to_handle(device
),
322 &(VkPipelineLayoutCreateInfo
) {
323 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
324 .descriptorSetCount
= 1,
325 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
,
327 &device
->meta_state
.blit
.pipeline_layout
);
329 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
331 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
332 .stage
= VK_SHADER_STAGE_VERTEX
,
334 .pSpecializationInfo
= NULL
336 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
337 .stage
= VK_SHADER_STAGE_FRAGMENT
,
338 .shader
= {0}, /* TEMPLATE VALUE! FILL ME IN! */
339 .pSpecializationInfo
= NULL
343 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
344 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
345 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
346 .pStages
= pipeline_shader_stages
,
347 .pVertexInputState
= &vi_create_info
,
348 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
349 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
350 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
351 .primitiveRestartEnable
= false,
353 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
354 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
358 .pRasterState
= &(VkPipelineRasterStateCreateInfo
) {
359 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO
,
360 .depthClipEnable
= true,
361 .rasterizerDiscardEnable
= false,
362 .fillMode
= VK_FILL_MODE_SOLID
,
363 .cullMode
= VK_CULL_MODE_NONE
,
364 .frontFace
= VK_FRONT_FACE_CCW
366 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
367 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
369 .sampleShadingEnable
= false,
370 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
372 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
373 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
374 .attachmentCount
= 1,
375 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
376 { .channelWriteMask
= VK_CHANNEL_A_BIT
|
377 VK_CHANNEL_R_BIT
| VK_CHANNEL_G_BIT
| VK_CHANNEL_B_BIT
},
380 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
381 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
382 .dynamicStateCount
= 9,
383 .pDynamicStates
= (VkDynamicState
[]) {
384 VK_DYNAMIC_STATE_VIEWPORT
,
385 VK_DYNAMIC_STATE_SCISSOR
,
386 VK_DYNAMIC_STATE_LINE_WIDTH
,
387 VK_DYNAMIC_STATE_DEPTH_BIAS
,
388 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
389 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
390 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
391 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
392 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
396 .layout
= device
->meta_state
.blit
.pipeline_layout
,
397 .renderPass
= device
->meta_state
.blit
.render_pass
,
401 const struct anv_graphics_pipeline_create_info anv_pipeline_info
= {
402 .use_repclear
= false,
403 .disable_viewport
= true,
404 .disable_scissor
= true,
409 pipeline_shader_stages
[1].shader
= fs_2d
;
410 anv_graphics_pipeline_create(anv_device_to_handle(device
),
411 &vk_pipeline_info
, &anv_pipeline_info
,
412 &device
->meta_state
.blit
.pipeline_2d_src
);
414 pipeline_shader_stages
[1].shader
= fs_3d
;
415 anv_graphics_pipeline_create(anv_device_to_handle(device
),
416 &vk_pipeline_info
, &anv_pipeline_info
,
417 &device
->meta_state
.blit
.pipeline_3d_src
);
419 anv_DestroyShader(anv_device_to_handle(device
), vs
);
420 anv_DestroyShader(anv_device_to_handle(device
), fs_2d
);
421 anv_DestroyShader(anv_device_to_handle(device
), fs_3d
);
422 ralloc_free(vsm
.nir
);
423 ralloc_free(fsm_2d
.nir
);
424 ralloc_free(fsm_3d
.nir
);
428 meta_prepare_blit(struct anv_cmd_buffer
*cmd_buffer
,
429 struct anv_meta_saved_state
*saved_state
)
431 anv_meta_save(saved_state
, cmd_buffer
,
432 (1 << VK_DYNAMIC_STATE_VIEWPORT
));
436 VkOffset3D src_offset
;
437 VkExtent3D src_extent
;
438 VkOffset3D dest_offset
;
439 VkExtent3D dest_extent
;
443 meta_emit_blit(struct anv_cmd_buffer
*cmd_buffer
,
444 struct anv_image
*src_image
,
445 struct anv_image_view
*src_iview
,
446 VkOffset3D src_offset
,
447 VkExtent3D src_extent
,
448 struct anv_image
*dest_image
,
449 struct anv_image_view
*dest_iview
,
450 VkOffset3D dest_offset
,
451 VkExtent3D dest_extent
,
452 VkTexFilter blit_filter
)
454 struct anv_device
*device
= cmd_buffer
->device
;
455 VkDescriptorPool dummy_desc_pool
= { .handle
= 1 };
457 struct blit_vb_data
{
462 unsigned vb_size
= sizeof(struct anv_vue_header
) + 3 * sizeof(*vb_data
);
464 struct anv_state vb_state
=
465 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, vb_size
, 16);
466 memset(vb_state
.map
, 0, sizeof(struct anv_vue_header
));
467 vb_data
= vb_state
.map
+ sizeof(struct anv_vue_header
);
469 vb_data
[0] = (struct blit_vb_data
) {
471 dest_offset
.x
+ dest_extent
.width
,
472 dest_offset
.y
+ dest_extent
.height
,
475 (float)(src_offset
.x
+ src_extent
.width
) / (float)src_iview
->extent
.width
,
476 (float)(src_offset
.y
+ src_extent
.height
) / (float)src_iview
->extent
.height
,
477 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
481 vb_data
[1] = (struct blit_vb_data
) {
484 dest_offset
.y
+ dest_extent
.height
,
487 (float)src_offset
.x
/ (float)src_iview
->extent
.width
,
488 (float)(src_offset
.y
+ src_extent
.height
) / (float)src_iview
->extent
.height
,
489 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
493 vb_data
[2] = (struct blit_vb_data
) {
499 (float)src_offset
.x
/ (float)src_iview
->extent
.width
,
500 (float)src_offset
.y
/ (float)src_iview
->extent
.height
,
501 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
505 struct anv_buffer vertex_buffer
= {
508 .bo
= &device
->dynamic_state_block_pool
.bo
,
509 .offset
= vb_state
.offset
,
512 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
514 anv_buffer_to_handle(&vertex_buffer
),
515 anv_buffer_to_handle(&vertex_buffer
)
519 sizeof(struct anv_vue_header
),
523 ANV_CALL(CreateSampler
)(anv_device_to_handle(device
),
524 &(VkSamplerCreateInfo
) {
525 .sType
= VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
,
526 .magFilter
= blit_filter
,
527 .minFilter
= blit_filter
,
531 anv_AllocDescriptorSets(anv_device_to_handle(device
), dummy_desc_pool
,
532 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT
,
533 1, &device
->meta_state
.blit
.ds_layout
, &set
);
534 anv_UpdateDescriptorSets(anv_device_to_handle(device
),
536 (VkWriteDescriptorSet
[]) {
538 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
541 .destArrayElement
= 0,
543 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
544 .pDescriptors
= (VkDescriptorInfo
[]) {
546 .imageView
= anv_image_view_to_handle(src_iview
),
547 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
555 anv_CreateFramebuffer(anv_device_to_handle(device
),
556 &(VkFramebufferCreateInfo
) {
557 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
558 .attachmentCount
= 1,
559 .pAttachments
= (VkImageView
[]) {
560 anv_image_view_to_handle(dest_iview
),
562 .width
= dest_iview
->extent
.width
,
563 .height
= dest_iview
->extent
.height
,
567 ANV_CALL(CmdBeginRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
),
568 &(VkRenderPassBeginInfo
) {
569 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
570 .renderPass
= device
->meta_state
.blit
.render_pass
,
573 .offset
= { dest_offset
.x
, dest_offset
.y
},
574 .extent
= { dest_extent
.width
, dest_extent
.height
},
576 .clearValueCount
= 0,
577 .pClearValues
= NULL
,
578 }, VK_RENDER_PASS_CONTENTS_INLINE
);
582 switch (src_image
->type
) {
583 case VK_IMAGE_TYPE_1D
:
584 anv_finishme("VK_IMAGE_TYPE_1D");
585 pipeline
= device
->meta_state
.blit
.pipeline_2d_src
;
587 case VK_IMAGE_TYPE_2D
:
588 pipeline
= device
->meta_state
.blit
.pipeline_2d_src
;
590 case VK_IMAGE_TYPE_3D
:
591 pipeline
= device
->meta_state
.blit
.pipeline_3d_src
;
594 unreachable(!"bad VkImageType");
597 if (cmd_buffer
->state
.pipeline
!= anv_pipeline_from_handle(pipeline
)) {
598 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
599 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
602 anv_CmdSetViewport(anv_cmd_buffer_to_handle(cmd_buffer
), 1,
606 .width
= dest_iview
->extent
.width
,
607 .height
= dest_iview
->extent
.height
,
612 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer
),
613 VK_PIPELINE_BIND_POINT_GRAPHICS
,
614 device
->meta_state
.blit
.pipeline_layout
, 0, 1,
617 ANV_CALL(CmdDraw
)(anv_cmd_buffer_to_handle(cmd_buffer
), 3, 1, 0, 0);
619 ANV_CALL(CmdEndRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
));
621 /* At the point where we emit the draw call, all data from the
622 * descriptor sets, etc. has been used. We are free to delete it.
624 anv_descriptor_set_destroy(device
, anv_descriptor_set_from_handle(set
));
625 anv_DestroySampler(anv_device_to_handle(device
), sampler
);
626 anv_DestroyFramebuffer(anv_device_to_handle(device
), fb
);
630 meta_finish_blit(struct anv_cmd_buffer
*cmd_buffer
,
631 const struct anv_meta_saved_state
*saved_state
)
633 anv_meta_restore(saved_state
, cmd_buffer
);
637 vk_format_for_size(int bs
)
640 case 1: return VK_FORMAT_R8_UINT
;
641 case 2: return VK_FORMAT_R8G8_UINT
;
642 case 3: return VK_FORMAT_R8G8B8_UINT
;
643 case 4: return VK_FORMAT_R8G8B8A8_UINT
;
644 case 6: return VK_FORMAT_R16G16B16_UINT
;
645 case 8: return VK_FORMAT_R16G16B16A16_UINT
;
646 case 12: return VK_FORMAT_R32G32B32_UINT
;
647 case 16: return VK_FORMAT_R32G32B32A32_UINT
;
649 unreachable("Invalid format block size");
654 do_buffer_copy(struct anv_cmd_buffer
*cmd_buffer
,
655 struct anv_bo
*src
, uint64_t src_offset
,
656 struct anv_bo
*dest
, uint64_t dest_offset
,
657 int width
, int height
, VkFormat copy_format
)
659 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
661 VkImageCreateInfo image_info
= {
662 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
663 .imageType
= VK_IMAGE_TYPE_2D
,
664 .format
= copy_format
,
673 .tiling
= VK_IMAGE_TILING_LINEAR
,
679 image_info
.usage
= VK_IMAGE_USAGE_SAMPLED_BIT
;
680 anv_CreateImage(vk_device
, &image_info
, &src_image
);
683 image_info
.usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
684 anv_CreateImage(vk_device
, &image_info
, &dest_image
);
686 /* We could use a vk call to bind memory, but that would require
687 * creating a dummy memory object etc. so there's really no point.
689 anv_image_from_handle(src_image
)->bo
= src
;
690 anv_image_from_handle(src_image
)->offset
= src_offset
;
691 anv_image_from_handle(dest_image
)->bo
= dest
;
692 anv_image_from_handle(dest_image
)->offset
= dest_offset
;
694 struct anv_image_view src_iview
;
695 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
696 &(VkImageViewCreateInfo
) {
697 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
699 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
700 .format
= copy_format
,
702 VK_CHANNEL_SWIZZLE_R
,
703 VK_CHANNEL_SWIZZLE_G
,
704 VK_CHANNEL_SWIZZLE_B
,
707 .subresourceRange
= {
708 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
717 struct anv_image_view dest_iview
;
718 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
719 &(VkImageViewCreateInfo
) {
720 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
722 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
723 .format
= copy_format
,
725 .r
= VK_CHANNEL_SWIZZLE_R
,
726 .g
= VK_CHANNEL_SWIZZLE_G
,
727 .b
= VK_CHANNEL_SWIZZLE_B
,
728 .a
= VK_CHANNEL_SWIZZLE_A
,
730 .subresourceRange
= {
731 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
740 meta_emit_blit(cmd_buffer
,
741 anv_image_from_handle(src_image
),
743 (VkOffset3D
) { 0, 0, 0 },
744 (VkExtent3D
) { width
, height
, 1 },
745 anv_image_from_handle(dest_image
),
747 (VkOffset3D
) { 0, 0, 0 },
748 (VkExtent3D
) { width
, height
, 1 },
749 VK_TEX_FILTER_NEAREST
);
751 anv_DestroyImage(vk_device
, src_image
);
752 anv_DestroyImage(vk_device
, dest_image
);
755 void anv_CmdCopyBuffer(
756 VkCmdBuffer cmdBuffer
,
759 uint32_t regionCount
,
760 const VkBufferCopy
* pRegions
)
762 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
763 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
764 ANV_FROM_HANDLE(anv_buffer
, dest_buffer
, destBuffer
);
766 struct anv_meta_saved_state saved_state
;
768 meta_prepare_blit(cmd_buffer
, &saved_state
);
770 for (unsigned r
= 0; r
< regionCount
; r
++) {
771 uint64_t src_offset
= src_buffer
->offset
+ pRegions
[r
].srcOffset
;
772 uint64_t dest_offset
= dest_buffer
->offset
+ pRegions
[r
].destOffset
;
773 uint64_t copy_size
= pRegions
[r
].copySize
;
775 /* First, we compute the biggest format that can be used with the
776 * given offsets and size.
780 int fs
= ffs(src_offset
) - 1;
782 bs
= MIN2(bs
, 1 << fs
);
783 assert(src_offset
% bs
== 0);
785 fs
= ffs(dest_offset
) - 1;
787 bs
= MIN2(bs
, 1 << fs
);
788 assert(dest_offset
% bs
== 0);
790 fs
= ffs(pRegions
[r
].copySize
) - 1;
792 bs
= MIN2(bs
, 1 << fs
);
793 assert(pRegions
[r
].copySize
% bs
== 0);
795 VkFormat copy_format
= vk_format_for_size(bs
);
797 /* This is maximum possible width/height our HW can handle */
798 uint64_t max_surface_dim
= 1 << 14;
800 /* First, we make a bunch of max-sized copies */
801 uint64_t max_copy_size
= max_surface_dim
* max_surface_dim
* bs
;
802 while (copy_size
> max_copy_size
) {
803 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
804 dest_buffer
->bo
, dest_offset
,
805 max_surface_dim
, max_surface_dim
, copy_format
);
806 copy_size
-= max_copy_size
;
807 src_offset
+= max_copy_size
;
808 dest_offset
+= max_copy_size
;
811 uint64_t height
= copy_size
/ (max_surface_dim
* bs
);
812 assert(height
< max_surface_dim
);
814 uint64_t rect_copy_size
= height
* max_surface_dim
* bs
;
815 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
816 dest_buffer
->bo
, dest_offset
,
817 max_surface_dim
, height
, copy_format
);
818 copy_size
-= rect_copy_size
;
819 src_offset
+= rect_copy_size
;
820 dest_offset
+= rect_copy_size
;
823 if (copy_size
!= 0) {
824 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
825 dest_buffer
->bo
, dest_offset
,
826 copy_size
/ bs
, 1, copy_format
);
830 meta_finish_blit(cmd_buffer
, &saved_state
);
833 void anv_CmdCopyImage(
834 VkCmdBuffer cmdBuffer
,
836 VkImageLayout srcImageLayout
,
838 VkImageLayout destImageLayout
,
839 uint32_t regionCount
,
840 const VkImageCopy
* pRegions
)
842 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
843 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
844 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
846 const VkImageViewType src_iview_type
=
847 meta_blit_get_src_image_view_type(src_image
);
849 struct anv_meta_saved_state saved_state
;
851 meta_prepare_blit(cmd_buffer
, &saved_state
);
853 for (unsigned r
= 0; r
< regionCount
; r
++) {
854 struct anv_image_view src_iview
;
855 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
856 &(VkImageViewCreateInfo
) {
857 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
859 .viewType
= src_iview_type
,
860 .format
= src_image
->format
->vk_format
,
862 VK_CHANNEL_SWIZZLE_R
,
863 VK_CHANNEL_SWIZZLE_G
,
864 VK_CHANNEL_SWIZZLE_B
,
867 .subresourceRange
= {
868 .aspectMask
= 1 << pRegions
[r
].srcSubresource
.aspect
,
869 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
871 .baseArrayLayer
= pRegions
[r
].srcSubresource
.arrayLayer
,
872 .arraySize
= pRegions
[r
].destSubresource
.arraySize
,
877 const VkOffset3D dest_offset
= {
878 .x
= pRegions
[r
].destOffset
.x
,
879 .y
= pRegions
[r
].destOffset
.y
,
884 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
885 assert(pRegions
[r
].srcSubresource
.arraySize
== 1 &&
886 pRegions
[r
].destSubresource
.arraySize
== 1);
887 num_slices
= pRegions
[r
].extent
.depth
;
889 assert(pRegions
[r
].srcSubresource
.arraySize
==
890 pRegions
[r
].destSubresource
.arraySize
);
891 assert(pRegions
[r
].extent
.depth
== 1);
892 num_slices
= pRegions
[r
].destSubresource
.arraySize
;
895 const uint32_t dest_base_array_slice
=
896 meta_blit_get_dest_view_base_array_slice(dest_image
,
897 &pRegions
[r
].destSubresource
,
898 &pRegions
[r
].destOffset
);
900 for (unsigned slice
= 0; slice
< num_slices
; slice
++) {
901 VkOffset3D src_offset
= pRegions
[r
].srcOffset
;
902 src_offset
.z
+= slice
;
904 struct anv_image_view dest_iview
;
905 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
906 &(VkImageViewCreateInfo
) {
907 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
909 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
910 .format
= dest_image
->format
->vk_format
,
912 VK_CHANNEL_SWIZZLE_R
,
913 VK_CHANNEL_SWIZZLE_G
,
914 VK_CHANNEL_SWIZZLE_B
,
917 .subresourceRange
= {
918 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
919 .baseMipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
921 .baseArrayLayer
= dest_base_array_slice
+ slice
,
927 meta_emit_blit(cmd_buffer
,
928 src_image
, &src_iview
,
931 dest_image
, &dest_iview
,
934 VK_TEX_FILTER_NEAREST
);
938 meta_finish_blit(cmd_buffer
, &saved_state
);
941 void anv_CmdBlitImage(
942 VkCmdBuffer cmdBuffer
,
944 VkImageLayout srcImageLayout
,
946 VkImageLayout destImageLayout
,
947 uint32_t regionCount
,
948 const VkImageBlit
* pRegions
,
952 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
953 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
954 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
956 const VkImageViewType src_iview_type
=
957 meta_blit_get_src_image_view_type(src_image
);
959 struct anv_meta_saved_state saved_state
;
961 anv_finishme("respect VkTexFilter");
963 meta_prepare_blit(cmd_buffer
, &saved_state
);
965 for (unsigned r
= 0; r
< regionCount
; r
++) {
966 struct anv_image_view src_iview
;
967 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
968 &(VkImageViewCreateInfo
) {
969 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
971 .viewType
= src_iview_type
,
972 .format
= src_image
->format
->vk_format
,
974 VK_CHANNEL_SWIZZLE_R
,
975 VK_CHANNEL_SWIZZLE_G
,
976 VK_CHANNEL_SWIZZLE_B
,
979 .subresourceRange
= {
980 .aspectMask
= 1 << pRegions
[r
].srcSubresource
.aspect
,
981 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
983 .baseArrayLayer
= pRegions
[r
].srcSubresource
.arrayLayer
,
989 const VkOffset3D dest_offset
= {
990 .x
= pRegions
[r
].destOffset
.x
,
991 .y
= pRegions
[r
].destOffset
.y
,
995 const uint32_t dest_array_slice
=
996 meta_blit_get_dest_view_base_array_slice(dest_image
,
997 &pRegions
[r
].destSubresource
,
998 &pRegions
[r
].destOffset
);
1000 if (pRegions
[r
].srcSubresource
.arraySize
> 1)
1001 anv_finishme("FINISHME: copy multiple array layers");
1003 if (pRegions
[r
].destExtent
.depth
> 1)
1004 anv_finishme("FINISHME: copy multiple depth layers");
1006 struct anv_image_view dest_iview
;
1007 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
1008 &(VkImageViewCreateInfo
) {
1009 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1011 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1012 .format
= dest_image
->format
->vk_format
,
1014 VK_CHANNEL_SWIZZLE_R
,
1015 VK_CHANNEL_SWIZZLE_G
,
1016 VK_CHANNEL_SWIZZLE_B
,
1017 VK_CHANNEL_SWIZZLE_A
1019 .subresourceRange
= {
1020 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
1021 .baseMipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
1023 .baseArrayLayer
= dest_array_slice
,
1029 meta_emit_blit(cmd_buffer
,
1030 src_image
, &src_iview
,
1031 pRegions
[r
].srcOffset
,
1032 pRegions
[r
].srcExtent
,
1033 dest_image
, &dest_iview
,
1035 pRegions
[r
].destExtent
,
1039 meta_finish_blit(cmd_buffer
, &saved_state
);
1042 static struct anv_image
*
1043 make_image_for_buffer(VkDevice vk_device
, VkBuffer vk_buffer
, VkFormat format
,
1044 VkImageUsageFlags usage
,
1045 VkImageType image_type
,
1046 const VkBufferImageCopy
*copy
)
1048 ANV_FROM_HANDLE(anv_buffer
, buffer
, vk_buffer
);
1050 VkExtent3D extent
= copy
->imageExtent
;
1051 if (copy
->bufferRowLength
)
1052 extent
.width
= copy
->bufferRowLength
;
1053 if (copy
->bufferImageHeight
)
1054 extent
.height
= copy
->bufferImageHeight
;
1058 VkResult result
= anv_CreateImage(vk_device
,
1059 &(VkImageCreateInfo
) {
1060 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
1061 .imageType
= VK_IMAGE_TYPE_2D
,
1067 .tiling
= VK_IMAGE_TILING_LINEAR
,
1071 assert(result
== VK_SUCCESS
);
1073 ANV_FROM_HANDLE(anv_image
, image
, vk_image
);
1075 /* We could use a vk call to bind memory, but that would require
1076 * creating a dummy memory object etc. so there's really no point.
1078 image
->bo
= buffer
->bo
;
1079 image
->offset
= buffer
->offset
+ copy
->bufferOffset
;
1084 void anv_CmdCopyBufferToImage(
1085 VkCmdBuffer cmdBuffer
,
1088 VkImageLayout destImageLayout
,
1089 uint32_t regionCount
,
1090 const VkBufferImageCopy
* pRegions
)
1092 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1093 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
1094 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1095 const VkFormat orig_format
= dest_image
->format
->vk_format
;
1096 struct anv_meta_saved_state saved_state
;
1098 meta_prepare_blit(cmd_buffer
, &saved_state
);
1100 for (unsigned r
= 0; r
< regionCount
; r
++) {
1101 VkFormat proxy_format
= orig_format
;
1102 VkImageAspect proxy_aspect
= pRegions
[r
].imageSubresource
.aspect
;
1104 if (orig_format
== VK_FORMAT_S8_UINT
) {
1105 proxy_format
= VK_FORMAT_R8_UINT
;
1106 proxy_aspect
= VK_IMAGE_ASPECT_COLOR
;
1109 struct anv_image
*src_image
=
1110 make_image_for_buffer(vk_device
, srcBuffer
, proxy_format
,
1111 VK_IMAGE_USAGE_SAMPLED_BIT
,
1112 dest_image
->type
, &pRegions
[r
]);
1114 const uint32_t dest_base_array_slice
=
1115 meta_blit_get_dest_view_base_array_slice(dest_image
,
1116 &pRegions
[r
].imageSubresource
,
1117 &pRegions
[r
].imageOffset
);
1119 unsigned num_slices
;
1120 if (dest_image
->type
== VK_IMAGE_TYPE_3D
) {
1121 assert(pRegions
[r
].imageSubresource
.arraySize
== 1);
1122 num_slices
= pRegions
[r
].imageExtent
.depth
;
1124 assert(pRegions
[r
].imageExtent
.depth
== 1);
1125 num_slices
= pRegions
[r
].imageSubresource
.arraySize
;
1128 for (unsigned slice
= 0; slice
< num_slices
; slice
++) {
1129 struct anv_image_view src_iview
;
1130 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
1131 &(VkImageViewCreateInfo
) {
1132 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1133 .image
= anv_image_to_handle(src_image
),
1134 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1135 .format
= proxy_format
,
1137 VK_CHANNEL_SWIZZLE_R
,
1138 VK_CHANNEL_SWIZZLE_G
,
1139 VK_CHANNEL_SWIZZLE_B
,
1140 VK_CHANNEL_SWIZZLE_A
1142 .subresourceRange
= {
1143 .aspectMask
= 1 << proxy_aspect
,
1146 .baseArrayLayer
= 0,
1152 struct anv_image_view dest_iview
;
1153 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
1154 &(VkImageViewCreateInfo
) {
1155 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1156 .image
= anv_image_to_handle(dest_image
),
1157 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1158 .format
= proxy_format
,
1160 VK_CHANNEL_SWIZZLE_R
,
1161 VK_CHANNEL_SWIZZLE_G
,
1162 VK_CHANNEL_SWIZZLE_B
,
1163 VK_CHANNEL_SWIZZLE_A
1165 .subresourceRange
= {
1166 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
1167 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1169 .baseArrayLayer
= dest_base_array_slice
+ slice
,
1175 VkOffset3D src_offset
= { 0, 0, slice
};
1177 const VkOffset3D dest_offset
= {
1178 .x
= pRegions
[r
].imageOffset
.x
,
1179 .y
= pRegions
[r
].imageOffset
.y
,
1183 meta_emit_blit(cmd_buffer
,
1187 pRegions
[r
].imageExtent
,
1191 pRegions
[r
].imageExtent
,
1192 VK_TEX_FILTER_NEAREST
);
1194 /* Once we've done the blit, all of the actual information about
1195 * the image is embedded in the command buffer so we can just
1196 * increment the offset directly in the image effectively
1197 * re-binding it to different backing memory.
1199 /* XXX: Insert a real CPP */
1200 src_image
->offset
+= src_image
->extent
.width
*
1201 src_image
->extent
.height
* 4;
1204 anv_DestroyImage(vk_device
, anv_image_to_handle(src_image
));
1207 meta_finish_blit(cmd_buffer
, &saved_state
);
1210 void anv_CmdCopyImageToBuffer(
1211 VkCmdBuffer cmdBuffer
,
1213 VkImageLayout srcImageLayout
,
1214 VkBuffer destBuffer
,
1215 uint32_t regionCount
,
1216 const VkBufferImageCopy
* pRegions
)
1218 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1219 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1220 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1221 struct anv_meta_saved_state saved_state
;
1223 const VkImageViewType src_iview_type
=
1224 meta_blit_get_src_image_view_type(src_image
);
1226 meta_prepare_blit(cmd_buffer
, &saved_state
);
1228 for (unsigned r
= 0; r
< regionCount
; r
++) {
1229 struct anv_image_view src_iview
;
1230 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
1231 &(VkImageViewCreateInfo
) {
1232 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1234 .viewType
= src_iview_type
,
1235 .format
= src_image
->format
->vk_format
,
1237 VK_CHANNEL_SWIZZLE_R
,
1238 VK_CHANNEL_SWIZZLE_G
,
1239 VK_CHANNEL_SWIZZLE_B
,
1240 VK_CHANNEL_SWIZZLE_A
1242 .subresourceRange
= {
1243 .aspectMask
= 1 << pRegions
[r
].imageSubresource
.aspect
,
1244 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1246 .baseArrayLayer
= pRegions
[r
].imageSubresource
.arrayLayer
,
1247 .arraySize
= pRegions
[r
].imageSubresource
.arraySize
,
1252 VkFormat dest_format
= src_image
->format
->vk_format
;
1253 if (dest_format
== VK_FORMAT_S8_UINT
) {
1254 dest_format
= VK_FORMAT_R8_UINT
;
1257 struct anv_image
*dest_image
=
1258 make_image_for_buffer(vk_device
, destBuffer
, dest_format
,
1259 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
1260 src_image
->type
, &pRegions
[r
]);
1262 unsigned num_slices
;
1263 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
1264 assert(pRegions
[r
].imageSubresource
.arraySize
== 1);
1265 num_slices
= pRegions
[r
].imageExtent
.depth
;
1267 assert(pRegions
[r
].imageExtent
.depth
== 1);
1268 num_slices
= pRegions
[r
].imageSubresource
.arraySize
;
1271 for (unsigned slice
= 0; slice
< num_slices
; slice
++) {
1272 VkOffset3D src_offset
= pRegions
[r
].imageOffset
;
1273 src_offset
.z
+= slice
;
1275 struct anv_image_view dest_iview
;
1276 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
1277 &(VkImageViewCreateInfo
) {
1278 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1279 .image
= anv_image_to_handle(dest_image
),
1280 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1281 .format
= dest_format
,
1283 VK_CHANNEL_SWIZZLE_R
,
1284 VK_CHANNEL_SWIZZLE_G
,
1285 VK_CHANNEL_SWIZZLE_B
,
1286 VK_CHANNEL_SWIZZLE_A
1288 .subresourceRange
= {
1289 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
1292 .baseArrayLayer
= 0,
1298 meta_emit_blit(cmd_buffer
,
1299 anv_image_from_handle(srcImage
),
1302 pRegions
[r
].imageExtent
,
1305 (VkOffset3D
) { 0, 0, 0 },
1306 pRegions
[r
].imageExtent
,
1307 VK_TEX_FILTER_NEAREST
);
1309 /* Once we've done the blit, all of the actual information about
1310 * the image is embedded in the command buffer so we can just
1311 * increment the offset directly in the image effectively
1312 * re-binding it to different backing memory.
1314 /* XXX: Insert a real CPP */
1315 dest_image
->offset
+= dest_image
->extent
.width
*
1316 dest_image
->extent
.height
* 4;
1319 anv_DestroyImage(vk_device
, anv_image_to_handle(dest_image
));
1322 meta_finish_blit(cmd_buffer
, &saved_state
);
1325 void anv_CmdUpdateBuffer(
1326 VkCmdBuffer cmdBuffer
,
1327 VkBuffer destBuffer
,
1328 VkDeviceSize destOffset
,
1329 VkDeviceSize dataSize
,
1330 const uint32_t* pData
)
1335 void anv_CmdFillBuffer(
1336 VkCmdBuffer cmdBuffer
,
1337 VkBuffer destBuffer
,
1338 VkDeviceSize destOffset
,
1339 VkDeviceSize fillSize
,
1345 void anv_CmdResolveImage(
1346 VkCmdBuffer cmdBuffer
,
1348 VkImageLayout srcImageLayout
,
1350 VkImageLayout destImageLayout
,
1351 uint32_t regionCount
,
1352 const VkImageResolve
* pRegions
)
1358 anv_device_init_meta(struct anv_device
*device
)
1360 anv_device_init_meta_clear_state(device
);
1361 anv_device_init_meta_blit_state(device
);
1365 anv_device_finish_meta(struct anv_device
*device
)
1367 anv_device_finish_meta_clear_state(device
);
1370 anv_DestroyRenderPass(anv_device_to_handle(device
),
1371 device
->meta_state
.blit
.render_pass
);
1372 anv_DestroyPipeline(anv_device_to_handle(device
),
1373 device
->meta_state
.blit
.pipeline_2d_src
);
1374 anv_DestroyPipeline(anv_device_to_handle(device
),
1375 device
->meta_state
.blit
.pipeline_3d_src
);
1376 anv_DestroyPipelineLayout(anv_device_to_handle(device
),
1377 device
->meta_state
.blit
.pipeline_layout
);
1378 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device
),
1379 device
->meta_state
.blit
.ds_layout
);