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
30 #include "anv_private.h"
31 #include "anv_meta_spirv_autogen.h"
34 anv_device_init_meta_clear_state(struct anv_device
*device
)
36 /* We don't use a vertex shader for clearing, but instead build and pass
37 * the VUEs directly to the rasterization backend.
39 VkShaderModule fsm
= GLSL_VK_SHADER_MODULE(device
, FRAGMENT
,
49 anv_CreateShader(anv_device_to_handle(device
),
50 &(VkShaderCreateInfo
) {
51 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
56 /* We use instanced rendering to clear multiple render targets. We have two
57 * vertex buffers: the first vertex buffer holds per-vertex data and
58 * provides the vertices for the clear rectangle. The second one holds
59 * per-instance data, which consists of the VUE header (which selects the
60 * layer) and the color (Vulkan supports per-RT clear colors).
62 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
63 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
65 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
69 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
74 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_INSTANCE
78 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
83 .format
= VK_FORMAT_R32G32B32A32_UINT
,
90 .format
= VK_FORMAT_R32G32_SFLOAT
,
97 .format
= VK_FORMAT_R32G32B32A32_SFLOAT
,
103 anv_pipeline_create(anv_device_to_handle(device
),
104 &(VkGraphicsPipelineCreateInfo
) {
105 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
107 .pStages
= &(VkPipelineShaderStageCreateInfo
) {
108 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
109 .stage
= VK_SHADER_STAGE_FRAGMENT
,
111 .pSpecializationInfo
= NULL
,
113 .pVertexInputState
= &vi_create_info
,
114 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
115 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
116 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
117 .primitiveRestartEnable
= false,
119 .pRasterState
= &(VkPipelineRasterStateCreateInfo
) {
120 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO
,
121 .depthClipEnable
= true,
122 .rasterizerDiscardEnable
= false,
123 .fillMode
= VK_FILL_MODE_SOLID
,
124 .cullMode
= VK_CULL_MODE_NONE
,
125 .frontFace
= VK_FRONT_FACE_CCW
127 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
128 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
129 .attachmentCount
= 1,
130 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
131 { .channelWriteMask
= VK_CHANNEL_A_BIT
|
132 VK_CHANNEL_R_BIT
| VK_CHANNEL_G_BIT
| VK_CHANNEL_B_BIT
},
137 &(struct anv_pipeline_create_info
) {
138 .use_repclear
= true,
139 .disable_viewport
= true,
142 &device
->meta_state
.clear
.pipeline
);
144 anv_DestroyShaderModule(anv_device_to_handle(device
), fsm
);
145 anv_DestroyShader(anv_device_to_handle(device
), fs
);
148 #define NUM_VB_USED 2
149 struct anv_saved_state
{
150 struct anv_vertex_binding old_vertex_bindings
[NUM_VB_USED
];
151 struct anv_descriptor_set
*old_descriptor_set0
;
152 struct anv_pipeline
*old_pipeline
;
153 VkDynamicColorBlendState cb_state
;
157 anv_cmd_buffer_save(struct anv_cmd_buffer
*cmd_buffer
,
158 struct anv_saved_state
*state
)
160 state
->old_pipeline
= cmd_buffer
->state
.pipeline
;
161 state
->old_descriptor_set0
= cmd_buffer
->state
.descriptors
[0].set
;
162 memcpy(state
->old_vertex_bindings
, cmd_buffer
->state
.vertex_bindings
,
163 sizeof(state
->old_vertex_bindings
));
167 anv_cmd_buffer_restore(struct anv_cmd_buffer
*cmd_buffer
,
168 const struct anv_saved_state
*state
)
170 cmd_buffer
->state
.pipeline
= state
->old_pipeline
;
171 cmd_buffer
->state
.descriptors
[0].set
= state
->old_descriptor_set0
;
172 memcpy(cmd_buffer
->state
.vertex_bindings
, state
->old_vertex_bindings
,
173 sizeof(state
->old_vertex_bindings
));
175 cmd_buffer
->state
.vb_dirty
|= (1 << NUM_VB_USED
) - 1;
176 cmd_buffer
->state
.dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
177 cmd_buffer
->state
.descriptors_dirty
|= VK_SHADER_STAGE_VERTEX_BIT
;
183 uint32_t ViewportIndex
;
187 struct clear_instance_data
{
188 struct vue_header vue_header
;
189 VkClearColorValue color
;
193 meta_emit_clear(struct anv_cmd_buffer
*cmd_buffer
,
195 struct clear_instance_data
*instance_data
)
197 struct anv_device
*device
= cmd_buffer
->device
;
198 struct anv_framebuffer
*fb
= cmd_buffer
->state
.framebuffer
;
199 struct anv_state state
;
202 const float vertex_data
[] = {
203 /* Rect-list coordinates */
206 fb
->width
, fb
->height
,
208 /* Align to 16 bytes */
212 size
= sizeof(vertex_data
) + num_instances
* sizeof(*instance_data
);
213 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 16);
215 /* Copy in the vertex and instance data */
216 memcpy(state
.map
, vertex_data
, sizeof(vertex_data
));
217 memcpy(state
.map
+ sizeof(vertex_data
), instance_data
,
218 num_instances
* sizeof(*instance_data
));
220 struct anv_buffer vertex_buffer
= {
221 .device
= cmd_buffer
->device
,
223 .bo
= &device
->surface_state_block_pool
.bo
,
224 .offset
= state
.offset
227 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
229 anv_buffer_to_handle(&vertex_buffer
),
230 anv_buffer_to_handle(&vertex_buffer
)
237 if (cmd_buffer
->state
.pipeline
!= anv_pipeline_from_handle(device
->meta_state
.clear
.pipeline
))
238 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
239 VK_PIPELINE_BIND_POINT_GRAPHICS
,
240 device
->meta_state
.clear
.pipeline
);
242 /* We don't need anything here, only set if not already set. */
243 if (cmd_buffer
->state
.rs_state
== NULL
)
244 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer
),
245 device
->meta_state
.shared
.rs_state
);
247 if (cmd_buffer
->state
.vp_state
== NULL
)
248 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer
),
249 cmd_buffer
->state
.framebuffer
->vp_state
);
251 if (cmd_buffer
->state
.ds_state
== NULL
)
252 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer
),
253 device
->meta_state
.shared
.ds_state
);
255 if (cmd_buffer
->state
.cb_state
== NULL
)
256 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
257 device
->meta_state
.shared
.cb_state
);
259 anv_CmdDraw(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 3, 0, num_instances
);
263 anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
264 struct anv_render_pass
*pass
,
265 const VkClearValue
*clear_values
)
267 struct anv_saved_state saved_state
;
269 int num_clear_layers
= 0;
270 for (uint32_t i
= 0; i
< pass
->attachment_count
; i
++) {
271 if (pass
->attachments
[i
].load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
272 if (anv_format_is_depth_or_stencil(pass
->attachments
[i
].format
)) {
273 anv_finishme("Can't clear depth-stencil yet");
280 if (num_clear_layers
== 0)
283 struct clear_instance_data instance_data
[num_clear_layers
];
284 uint32_t color_attachments
[num_clear_layers
];
287 for (uint32_t i
= 0; i
< pass
->attachment_count
; i
++) {
288 if (pass
->attachments
[i
].load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
&&
289 anv_format_is_color(pass
->attachments
[i
].format
)) {
290 instance_data
[layer
] = (struct clear_instance_data
) {
296 .color
= clear_values
[i
].color
,
298 color_attachments
[layer
] = i
;
303 anv_cmd_buffer_save(cmd_buffer
, &saved_state
);
305 struct anv_subpass subpass
= {
307 .color_count
= num_clear_layers
,
308 .color_attachments
= color_attachments
,
309 .depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
,
312 anv_cmd_buffer_begin_subpass(cmd_buffer
, &subpass
);
314 meta_emit_clear(cmd_buffer
, num_clear_layers
, instance_data
);
316 /* Restore API state */
317 anv_cmd_buffer_restore(cmd_buffer
, &saved_state
);
321 anv_device_init_meta_blit_state(struct anv_device
*device
)
323 /* We don't use a vertex shader for clearing, but instead build and pass
324 * the VUEs directly to the rasterization backend. However, we do need
325 * to provide GLSL source for the vertex shader so that the compiler
326 * does not dead-code our inputs.
328 VkShaderModule vsm
= GLSL_VK_SHADER_MODULE(device
, VERTEX
,
331 out vec4 v_tex_coord
;
334 v_tex_coord
= vec4(a_tex_coord
, 0, 1);
335 gl_Position
= vec4(a_pos
, 0, 1);
339 VkShaderModule fsm
= GLSL_VK_SHADER_MODULE(device
, FRAGMENT
,
342 layout(set
= 0, binding
= 0) uniform sampler2D u_tex
;
345 f_color
= texture(u_tex
, v_tex_coord
.xy
);
350 anv_CreateShader(anv_device_to_handle(device
),
351 &(VkShaderCreateInfo
) {
352 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
358 anv_CreateShader(anv_device_to_handle(device
),
359 &(VkShaderCreateInfo
) {
360 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
365 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
366 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
368 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
372 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
377 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
381 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
386 .format
= VK_FORMAT_R32G32B32A32_UINT
,
393 .format
= VK_FORMAT_R32G32_SFLOAT
,
397 /* Texture Coordinate */
400 .format
= VK_FORMAT_R32G32_SFLOAT
,
406 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
407 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
409 .pBinding
= (VkDescriptorSetLayoutBinding
[]) {
411 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
413 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
414 .pImmutableSamplers
= NULL
418 anv_CreateDescriptorSetLayout(anv_device_to_handle(device
), &ds_layout_info
,
419 &device
->meta_state
.blit
.ds_layout
);
421 anv_CreatePipelineLayout(anv_device_to_handle(device
),
422 &(VkPipelineLayoutCreateInfo
) {
423 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
424 .descriptorSetCount
= 1,
425 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
,
427 &device
->meta_state
.blit
.pipeline_layout
);
429 anv_pipeline_create(anv_device_to_handle(device
),
430 &(VkGraphicsPipelineCreateInfo
) {
431 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
433 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
435 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
436 .stage
= VK_SHADER_STAGE_VERTEX
,
438 .pSpecializationInfo
= NULL
440 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
441 .stage
= VK_SHADER_STAGE_FRAGMENT
,
443 .pSpecializationInfo
= NULL
446 .pVertexInputState
= &vi_create_info
,
447 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
448 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
449 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
450 .primitiveRestartEnable
= false,
452 .pRasterState
= &(VkPipelineRasterStateCreateInfo
) {
453 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTER_STATE_CREATE_INFO
,
454 .depthClipEnable
= true,
455 .rasterizerDiscardEnable
= false,
456 .fillMode
= VK_FILL_MODE_SOLID
,
457 .cullMode
= VK_CULL_MODE_NONE
,
458 .frontFace
= VK_FRONT_FACE_CCW
460 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
461 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
462 .attachmentCount
= 1,
463 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
464 { .channelWriteMask
= VK_CHANNEL_A_BIT
|
465 VK_CHANNEL_R_BIT
| VK_CHANNEL_G_BIT
| VK_CHANNEL_B_BIT
},
469 .layout
= device
->meta_state
.blit
.pipeline_layout
,
471 &(struct anv_pipeline_create_info
) {
472 .use_repclear
= false,
473 .disable_viewport
= true,
474 .disable_scissor
= true,
478 &device
->meta_state
.blit
.pipeline
);
480 anv_DestroyShaderModule(anv_device_to_handle(device
), vsm
);
481 anv_DestroyShader(anv_device_to_handle(device
), vs
);
482 anv_DestroyShaderModule(anv_device_to_handle(device
), fsm
);
483 anv_DestroyShader(anv_device_to_handle(device
), fs
);
487 meta_prepare_blit(struct anv_cmd_buffer
*cmd_buffer
,
488 struct anv_saved_state
*saved_state
)
490 struct anv_device
*device
= cmd_buffer
->device
;
492 anv_cmd_buffer_save(cmd_buffer
, saved_state
);
494 if (cmd_buffer
->state
.pipeline
!= anv_pipeline_from_handle(device
->meta_state
.blit
.pipeline
))
495 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
496 VK_PIPELINE_BIND_POINT_GRAPHICS
,
497 device
->meta_state
.blit
.pipeline
);
499 /* We don't need anything here, only set if not already set. */
500 if (cmd_buffer
->state
.rs_state
== NULL
)
501 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer
),
502 device
->meta_state
.shared
.rs_state
);
503 if (cmd_buffer
->state
.ds_state
== NULL
)
504 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer
),
505 device
->meta_state
.shared
.ds_state
);
507 saved_state
->cb_state
= anv_dynamic_cb_state_to_handle(cmd_buffer
->state
.cb_state
);
508 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
509 device
->meta_state
.shared
.cb_state
);
513 VkOffset3D src_offset
;
514 VkExtent3D src_extent
;
515 VkOffset3D dest_offset
;
516 VkExtent3D dest_extent
;
520 meta_emit_blit(struct anv_cmd_buffer
*cmd_buffer
,
521 struct anv_image_view
*src
,
522 VkOffset3D src_offset
,
523 VkExtent3D src_extent
,
524 struct anv_color_attachment_view
*dest
,
525 VkOffset3D dest_offset
,
526 VkExtent3D dest_extent
)
528 struct anv_device
*device
= cmd_buffer
->device
;
529 VkDescriptorPool dummy_desc_pool
= { .handle
= 1 };
531 struct blit_vb_data
{
536 unsigned vb_size
= sizeof(struct vue_header
) + 3 * sizeof(*vb_data
);
538 struct anv_state vb_state
=
539 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, vb_size
, 16);
540 memset(vb_state
.map
, 0, sizeof(struct vue_header
));
541 vb_data
= vb_state
.map
+ sizeof(struct vue_header
);
543 vb_data
[0] = (struct blit_vb_data
) {
545 dest_offset
.x
+ dest_extent
.width
,
546 dest_offset
.y
+ dest_extent
.height
,
549 (float)(src_offset
.x
+ src_extent
.width
) / (float)src
->extent
.width
,
550 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
554 vb_data
[1] = (struct blit_vb_data
) {
557 dest_offset
.y
+ dest_extent
.height
,
560 (float)src_offset
.x
/ (float)src
->extent
.width
,
561 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
565 vb_data
[2] = (struct blit_vb_data
) {
571 (float)src_offset
.x
/ (float)src
->extent
.width
,
572 (float)src_offset
.y
/ (float)src
->extent
.height
,
576 struct anv_buffer vertex_buffer
= {
579 .bo
= &device
->surface_state_block_pool
.bo
,
580 .offset
= vb_state
.offset
,
583 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
585 anv_buffer_to_handle(&vertex_buffer
),
586 anv_buffer_to_handle(&vertex_buffer
)
590 sizeof(struct vue_header
),
595 anv_AllocDescriptorSets(anv_device_to_handle(device
), dummy_desc_pool
,
596 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT
,
597 1, &device
->meta_state
.blit
.ds_layout
, &set
, &count
);
598 anv_UpdateDescriptorSets(anv_device_to_handle(device
),
600 (VkWriteDescriptorSet
[]) {
602 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
605 .destArrayElement
= 0,
607 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
608 .pDescriptors
= (VkDescriptorInfo
[]) {
610 .imageView
= anv_image_view_to_handle(src
),
611 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
618 anv_CreateFramebuffer(anv_device_to_handle(device
),
619 &(VkFramebufferCreateInfo
) {
620 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
621 .attachmentCount
= 1,
622 .pAttachments
= (VkAttachmentBindInfo
[]) {
624 .view
= anv_attachment_view_to_handle(&dest
->base
),
625 .layout
= VK_IMAGE_LAYOUT_GENERAL
628 .width
= dest
->base
.extent
.width
,
629 .height
= dest
->base
.extent
.height
,
634 anv_CreateRenderPass(anv_device_to_handle(device
),
635 &(VkRenderPassCreateInfo
) {
636 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
637 .attachmentCount
= 1,
638 .pAttachments
= &(VkAttachmentDescription
) {
639 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION
,
640 .format
= dest
->view
.format
->vk_format
,
641 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
642 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
643 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
644 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
647 .pSubpasses
= &(VkSubpassDescription
) {
648 .sType
= VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION
,
649 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
652 .colorAttachments
= &(VkAttachmentReference
) {
654 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
656 .resolveAttachments
= NULL
,
657 .depthStencilAttachment
= (VkAttachmentReference
) {
658 .attachment
= VK_ATTACHMENT_UNUSED
,
659 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
662 .preserveAttachments
= &(VkAttachmentReference
) {
664 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
667 .dependencyCount
= 0,
670 anv_CmdBeginRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
),
671 &(VkRenderPassBeginInfo
) {
672 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
676 .offset
= { dest_offset
.x
, dest_offset
.y
},
677 .extent
= { dest_extent
.width
, dest_extent
.height
},
679 .attachmentCount
= 1,
680 .pAttachmentClearValues
= NULL
,
681 }, VK_RENDER_PASS_CONTENTS_INLINE
);
683 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer
),
684 anv_framebuffer_from_handle(fb
)->vp_state
);
686 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer
),
687 VK_PIPELINE_BIND_POINT_GRAPHICS
,
688 device
->meta_state
.blit
.pipeline_layout
, 0, 1,
691 anv_CmdDraw(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 3, 0, 1);
693 anv_CmdEndRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
));
695 /* At the point where we emit the draw call, all data from the
696 * descriptor sets, etc. has been used. We are free to delete it.
698 anv_descriptor_set_destroy(device
, anv_descriptor_set_from_handle(set
));
699 anv_DestroyFramebuffer(anv_device_to_handle(device
), fb
);
700 anv_DestroyRenderPass(anv_device_to_handle(device
), pass
);
704 meta_finish_blit(struct anv_cmd_buffer
*cmd_buffer
,
705 const struct anv_saved_state
*saved_state
)
707 anv_cmd_buffer_restore(cmd_buffer
, saved_state
);
708 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
709 saved_state
->cb_state
);
713 vk_format_for_cpp(int cpp
)
716 case 1: return VK_FORMAT_R8_UINT
;
717 case 2: return VK_FORMAT_R8G8_UINT
;
718 case 3: return VK_FORMAT_R8G8B8_UINT
;
719 case 4: return VK_FORMAT_R8G8B8A8_UINT
;
720 case 6: return VK_FORMAT_R16G16B16_UINT
;
721 case 8: return VK_FORMAT_R16G16B16A16_UINT
;
722 case 12: return VK_FORMAT_R32G32B32_UINT
;
723 case 16: return VK_FORMAT_R32G32B32A32_UINT
;
725 unreachable("Invalid format cpp");
730 do_buffer_copy(struct anv_cmd_buffer
*cmd_buffer
,
731 struct anv_bo
*src
, uint64_t src_offset
,
732 struct anv_bo
*dest
, uint64_t dest_offset
,
733 int width
, int height
, VkFormat copy_format
)
735 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
737 VkImageCreateInfo image_info
= {
738 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
739 .imageType
= VK_IMAGE_TYPE_2D
,
740 .format
= copy_format
,
749 .tiling
= VK_IMAGE_TILING_LINEAR
,
750 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
754 VkImage src_image
, dest_image
;
755 anv_CreateImage(vk_device
, &image_info
, &src_image
);
756 anv_CreateImage(vk_device
, &image_info
, &dest_image
);
758 /* We could use a vk call to bind memory, but that would require
759 * creating a dummy memory object etc. so there's really no point.
761 anv_image_from_handle(src_image
)->bo
= src
;
762 anv_image_from_handle(src_image
)->offset
= src_offset
;
763 anv_image_from_handle(dest_image
)->bo
= dest
;
764 anv_image_from_handle(dest_image
)->offset
= dest_offset
;
766 struct anv_image_view src_view
;
767 anv_image_view_init(&src_view
, cmd_buffer
->device
,
768 &(VkImageViewCreateInfo
) {
769 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
771 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
772 .format
= copy_format
,
774 VK_CHANNEL_SWIZZLE_R
,
775 VK_CHANNEL_SWIZZLE_G
,
776 VK_CHANNEL_SWIZZLE_B
,
779 .subresourceRange
= {
780 .aspect
= VK_IMAGE_ASPECT_COLOR
,
789 struct anv_color_attachment_view dest_view
;
790 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
791 &(VkAttachmentViewCreateInfo
) {
792 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
794 .format
= copy_format
,
801 meta_emit_blit(cmd_buffer
,
803 (VkOffset3D
) { 0, 0, 0 },
804 (VkExtent3D
) { width
, height
, 1 },
806 (VkOffset3D
) { 0, 0, 0 },
807 (VkExtent3D
) { width
, height
, 1 });
809 anv_DestroyImage(vk_device
, src_image
);
810 anv_DestroyImage(vk_device
, dest_image
);
813 void anv_CmdCopyBuffer(
814 VkCmdBuffer cmdBuffer
,
817 uint32_t regionCount
,
818 const VkBufferCopy
* pRegions
)
820 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
821 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
822 ANV_FROM_HANDLE(anv_buffer
, dest_buffer
, destBuffer
);
824 struct anv_saved_state saved_state
;
826 meta_prepare_blit(cmd_buffer
, &saved_state
);
828 for (unsigned r
= 0; r
< regionCount
; r
++) {
829 uint64_t src_offset
= src_buffer
->offset
+ pRegions
[r
].srcOffset
;
830 uint64_t dest_offset
= dest_buffer
->offset
+ pRegions
[r
].destOffset
;
831 uint64_t copy_size
= pRegions
[r
].copySize
;
833 /* First, we compute the biggest format that can be used with the
834 * given offsets and size.
838 int fs
= ffs(src_offset
) - 1;
840 cpp
= MIN2(cpp
, 1 << fs
);
841 assert(src_offset
% cpp
== 0);
843 fs
= ffs(dest_offset
) - 1;
845 cpp
= MIN2(cpp
, 1 << fs
);
846 assert(dest_offset
% cpp
== 0);
848 fs
= ffs(pRegions
[r
].copySize
) - 1;
850 cpp
= MIN2(cpp
, 1 << fs
);
851 assert(pRegions
[r
].copySize
% cpp
== 0);
853 VkFormat copy_format
= vk_format_for_cpp(cpp
);
855 /* This is maximum possible width/height our HW can handle */
856 uint64_t max_surface_dim
= 1 << 14;
858 /* First, we make a bunch of max-sized copies */
859 uint64_t max_copy_size
= max_surface_dim
* max_surface_dim
* cpp
;
860 while (copy_size
> max_copy_size
) {
861 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
862 dest_buffer
->bo
, dest_offset
,
863 max_surface_dim
, max_surface_dim
, copy_format
);
864 copy_size
-= max_copy_size
;
865 src_offset
+= max_copy_size
;
866 dest_offset
+= max_copy_size
;
869 uint64_t height
= copy_size
/ (max_surface_dim
* cpp
);
870 assert(height
< max_surface_dim
);
872 uint64_t rect_copy_size
= height
* max_surface_dim
* cpp
;
873 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
874 dest_buffer
->bo
, dest_offset
,
875 max_surface_dim
, height
, copy_format
);
876 copy_size
-= rect_copy_size
;
877 src_offset
+= rect_copy_size
;
878 dest_offset
+= rect_copy_size
;
881 if (copy_size
!= 0) {
882 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
883 dest_buffer
->bo
, dest_offset
,
884 copy_size
/ cpp
, 1, copy_format
);
888 meta_finish_blit(cmd_buffer
, &saved_state
);
891 void anv_CmdCopyImage(
892 VkCmdBuffer cmdBuffer
,
894 VkImageLayout srcImageLayout
,
896 VkImageLayout destImageLayout
,
897 uint32_t regionCount
,
898 const VkImageCopy
* pRegions
)
900 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
901 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
903 struct anv_saved_state saved_state
;
905 meta_prepare_blit(cmd_buffer
, &saved_state
);
907 for (unsigned r
= 0; r
< regionCount
; r
++) {
908 struct anv_image_view src_view
;
909 anv_image_view_init(&src_view
, cmd_buffer
->device
,
910 &(VkImageViewCreateInfo
) {
911 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
913 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
914 .format
= src_image
->format
->vk_format
,
916 VK_CHANNEL_SWIZZLE_R
,
917 VK_CHANNEL_SWIZZLE_G
,
918 VK_CHANNEL_SWIZZLE_B
,
921 .subresourceRange
= {
922 .aspect
= pRegions
[r
].srcSubresource
.aspect
,
923 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
925 .baseArraySlice
= pRegions
[r
].srcSubresource
.arraySlice
,
931 struct anv_color_attachment_view dest_view
;
932 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
933 &(VkAttachmentViewCreateInfo
) {
934 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
936 .format
= src_image
->format
->vk_format
,
937 .mipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
938 .baseArraySlice
= pRegions
[r
].destSubresource
.arraySlice
,
943 meta_emit_blit(cmd_buffer
,
945 pRegions
[r
].srcOffset
,
948 pRegions
[r
].destOffset
,
952 meta_finish_blit(cmd_buffer
, &saved_state
);
955 void anv_CmdBlitImage(
956 VkCmdBuffer cmdBuffer
,
958 VkImageLayout srcImageLayout
,
960 VkImageLayout destImageLayout
,
961 uint32_t regionCount
,
962 const VkImageBlit
* pRegions
,
966 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
967 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
968 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
970 struct anv_saved_state saved_state
;
972 anv_finishme("respect VkTexFilter");
974 meta_prepare_blit(cmd_buffer
, &saved_state
);
976 for (unsigned r
= 0; r
< regionCount
; r
++) {
977 struct anv_image_view src_view
;
978 anv_image_view_init(&src_view
, cmd_buffer
->device
,
979 &(VkImageViewCreateInfo
) {
980 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
982 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
983 .format
= src_image
->format
->vk_format
,
985 VK_CHANNEL_SWIZZLE_R
,
986 VK_CHANNEL_SWIZZLE_G
,
987 VK_CHANNEL_SWIZZLE_B
,
990 .subresourceRange
= {
991 .aspect
= pRegions
[r
].srcSubresource
.aspect
,
992 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
994 .baseArraySlice
= pRegions
[r
].srcSubresource
.arraySlice
,
1000 struct anv_color_attachment_view dest_view
;
1001 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
1002 &(VkAttachmentViewCreateInfo
) {
1003 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1005 .format
= dest_image
->format
->vk_format
,
1006 .mipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
1007 .baseArraySlice
= pRegions
[r
].destSubresource
.arraySlice
,
1012 meta_emit_blit(cmd_buffer
,
1014 pRegions
[r
].srcOffset
,
1015 pRegions
[r
].srcExtent
,
1017 pRegions
[r
].destOffset
,
1018 pRegions
[r
].destExtent
);
1021 meta_finish_blit(cmd_buffer
, &saved_state
);
1024 void anv_CmdCopyBufferToImage(
1025 VkCmdBuffer cmdBuffer
,
1028 VkImageLayout destImageLayout
,
1029 uint32_t regionCount
,
1030 const VkBufferImageCopy
* pRegions
)
1032 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1033 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
1034 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
1035 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1036 struct anv_saved_state saved_state
;
1038 meta_prepare_blit(cmd_buffer
, &saved_state
);
1040 for (unsigned r
= 0; r
< regionCount
; r
++) {
1041 if (pRegions
[r
].bufferRowLength
!= 0)
1042 anv_finishme("bufferRowLength not supported in CopyBufferToImage");
1043 if (pRegions
[r
].bufferImageHeight
!= 0)
1044 anv_finishme("bufferImageHeight not supported in CopyBufferToImage");
1047 anv_CreateImage(vk_device
,
1048 &(VkImageCreateInfo
) {
1049 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
1050 .imageType
= VK_IMAGE_TYPE_2D
,
1051 .format
= dest_image
->format
->vk_format
,
1053 .width
= pRegions
[r
].imageExtent
.width
,
1054 .height
= pRegions
[r
].imageExtent
.height
,
1060 .tiling
= VK_IMAGE_TILING_LINEAR
,
1061 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
1065 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1067 /* We could use a vk call to bind memory, but that would require
1068 * creating a dummy memory object etc. so there's really no point.
1070 src_image
->bo
= src_buffer
->bo
;
1071 src_image
->offset
= src_buffer
->offset
+ pRegions
[r
].bufferOffset
;
1073 struct anv_image_view src_view
;
1074 anv_image_view_init(&src_view
, cmd_buffer
->device
,
1075 &(VkImageViewCreateInfo
) {
1076 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1077 .image
= anv_image_to_handle(src_image
),
1078 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1079 .format
= dest_image
->format
->vk_format
,
1081 VK_CHANNEL_SWIZZLE_R
,
1082 VK_CHANNEL_SWIZZLE_G
,
1083 VK_CHANNEL_SWIZZLE_B
,
1084 VK_CHANNEL_SWIZZLE_A
1086 .subresourceRange
= {
1087 .aspect
= pRegions
[r
].imageSubresource
.aspect
,
1090 .baseArraySlice
= 0,
1096 struct anv_color_attachment_view dest_view
;
1097 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
1098 &(VkAttachmentViewCreateInfo
) {
1099 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1100 .image
= anv_image_to_handle(dest_image
),
1101 .format
= dest_image
->format
->vk_format
,
1102 .mipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1103 .baseArraySlice
= pRegions
[r
].imageSubresource
.arraySlice
,
1108 meta_emit_blit(cmd_buffer
,
1110 (VkOffset3D
) { 0, 0, 0 },
1111 pRegions
[r
].imageExtent
,
1113 pRegions
[r
].imageOffset
,
1114 pRegions
[r
].imageExtent
);
1116 anv_DestroyImage(vk_device
, srcImage
);
1119 meta_finish_blit(cmd_buffer
, &saved_state
);
1122 void anv_CmdCopyImageToBuffer(
1123 VkCmdBuffer cmdBuffer
,
1125 VkImageLayout srcImageLayout
,
1126 VkBuffer destBuffer
,
1127 uint32_t regionCount
,
1128 const VkBufferImageCopy
* pRegions
)
1130 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1131 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1132 ANV_FROM_HANDLE(anv_buffer
, dest_buffer
, destBuffer
);
1133 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1134 struct anv_saved_state saved_state
;
1136 meta_prepare_blit(cmd_buffer
, &saved_state
);
1138 for (unsigned r
= 0; r
< regionCount
; r
++) {
1139 if (pRegions
[r
].bufferRowLength
!= 0)
1140 anv_finishme("bufferRowLength not supported in CopyBufferToImage");
1141 if (pRegions
[r
].bufferImageHeight
!= 0)
1142 anv_finishme("bufferImageHeight not supported in CopyBufferToImage");
1144 struct anv_image_view src_view
;
1145 anv_image_view_init(&src_view
, cmd_buffer
->device
,
1146 &(VkImageViewCreateInfo
) {
1147 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1149 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1150 .format
= src_image
->format
->vk_format
,
1152 VK_CHANNEL_SWIZZLE_R
,
1153 VK_CHANNEL_SWIZZLE_G
,
1154 VK_CHANNEL_SWIZZLE_B
,
1155 VK_CHANNEL_SWIZZLE_A
1157 .subresourceRange
= {
1158 .aspect
= pRegions
[r
].imageSubresource
.aspect
,
1159 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1161 .baseArraySlice
= pRegions
[r
].imageSubresource
.arraySlice
,
1168 anv_CreateImage(vk_device
,
1169 &(VkImageCreateInfo
) {
1170 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
1171 .imageType
= VK_IMAGE_TYPE_2D
,
1172 .format
= src_image
->format
->vk_format
,
1174 .width
= pRegions
[r
].imageExtent
.width
,
1175 .height
= pRegions
[r
].imageExtent
.height
,
1181 .tiling
= VK_IMAGE_TILING_LINEAR
,
1182 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
1186 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
1188 /* We could use a vk call to bind memory, but that would require
1189 * creating a dummy memory object etc. so there's really no point.
1191 dest_image
->bo
= dest_buffer
->bo
;
1192 dest_image
->offset
= dest_buffer
->offset
+ pRegions
[r
].bufferOffset
;
1194 struct anv_color_attachment_view dest_view
;
1195 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
1196 &(VkAttachmentViewCreateInfo
) {
1197 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1199 .format
= src_image
->format
->vk_format
,
1201 .baseArraySlice
= 0,
1206 meta_emit_blit(cmd_buffer
,
1208 pRegions
[r
].imageOffset
,
1209 pRegions
[r
].imageExtent
,
1211 (VkOffset3D
) { 0, 0, 0 },
1212 pRegions
[r
].imageExtent
);
1214 anv_DestroyImage(vk_device
, destImage
);
1217 meta_finish_blit(cmd_buffer
, &saved_state
);
1220 void anv_CmdUpdateBuffer(
1221 VkCmdBuffer cmdBuffer
,
1222 VkBuffer destBuffer
,
1223 VkDeviceSize destOffset
,
1224 VkDeviceSize dataSize
,
1225 const uint32_t* pData
)
1230 void anv_CmdFillBuffer(
1231 VkCmdBuffer cmdBuffer
,
1232 VkBuffer destBuffer
,
1233 VkDeviceSize destOffset
,
1234 VkDeviceSize fillSize
,
1240 void anv_CmdClearColorImage(
1241 VkCmdBuffer cmdBuffer
,
1243 VkImageLayout imageLayout
,
1244 const VkClearColorValue
* pColor
,
1245 uint32_t rangeCount
,
1246 const VkImageSubresourceRange
* pRanges
)
1248 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1249 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1250 struct anv_saved_state saved_state
;
1252 anv_cmd_buffer_save(cmd_buffer
, &saved_state
);
1254 for (uint32_t r
= 0; r
< rangeCount
; r
++) {
1255 for (uint32_t l
= 0; l
< pRanges
[r
].mipLevels
; l
++) {
1256 for (uint32_t s
= 0; s
< pRanges
[r
].arraySize
; s
++) {
1257 struct anv_color_attachment_view view
;
1258 anv_color_attachment_view_init(&view
, cmd_buffer
->device
,
1259 &(VkAttachmentViewCreateInfo
) {
1260 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1262 .format
= image
->format
->vk_format
,
1263 .mipLevel
= pRanges
[r
].baseMipLevel
+ l
,
1264 .baseArraySlice
= pRanges
[r
].baseArraySlice
+ s
,
1270 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer
->device
),
1271 &(VkFramebufferCreateInfo
) {
1272 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
1273 .attachmentCount
= 1,
1274 .pAttachments
= (VkAttachmentBindInfo
[]) {
1276 .view
= anv_attachment_view_to_handle(&view
.base
),
1277 .layout
= VK_IMAGE_LAYOUT_GENERAL
1280 .width
= view
.base
.extent
.width
,
1281 .height
= view
.base
.extent
.height
,
1286 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer
->device
),
1287 &(VkRenderPassCreateInfo
) {
1288 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1289 .attachmentCount
= 1,
1290 .pAttachments
= &(VkAttachmentDescription
) {
1291 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION
,
1292 .format
= view
.view
.format
->vk_format
,
1293 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1294 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1295 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1296 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1299 .pSubpasses
= &(VkSubpassDescription
) {
1300 .sType
= VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION
,
1301 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1304 .colorAttachments
= &(VkAttachmentReference
) {
1306 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1308 .resolveAttachments
= NULL
,
1309 .depthStencilAttachment
= (VkAttachmentReference
) {
1310 .attachment
= VK_ATTACHMENT_UNUSED
,
1311 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1314 .preserveAttachments
= &(VkAttachmentReference
) {
1316 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1319 .dependencyCount
= 0,
1322 anv_CmdBeginRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
),
1323 &(VkRenderPassBeginInfo
) {
1324 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
1326 .offset
= { 0, 0, },
1328 .width
= view
.base
.extent
.width
,
1329 .height
= view
.base
.extent
.height
,
1334 .attachmentCount
= 1,
1335 .pAttachmentClearValues
= NULL
,
1336 }, VK_RENDER_PASS_CONTENTS_INLINE
);
1338 struct clear_instance_data instance_data
= {
1347 meta_emit_clear(cmd_buffer
, 1, &instance_data
);
1349 anv_CmdEndRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
));
1354 /* Restore API state */
1355 anv_cmd_buffer_restore(cmd_buffer
, &saved_state
);
1358 void anv_CmdClearDepthStencilImage(
1359 VkCmdBuffer cmdBuffer
,
1361 VkImageLayout imageLayout
,
1364 uint32_t rangeCount
,
1365 const VkImageSubresourceRange
* pRanges
)
1370 void anv_CmdClearColorAttachment(
1371 VkCmdBuffer cmdBuffer
,
1372 uint32_t colorAttachment
,
1373 VkImageLayout imageLayout
,
1374 const VkClearColorValue
* pColor
,
1376 const VkRect3D
* pRects
)
1381 void anv_CmdClearDepthStencilAttachment(
1382 VkCmdBuffer cmdBuffer
,
1383 VkImageAspectFlags imageAspectMask
,
1384 VkImageLayout imageLayout
,
1388 const VkRect3D
* pRects
)
1393 void anv_CmdResolveImage(
1394 VkCmdBuffer cmdBuffer
,
1396 VkImageLayout srcImageLayout
,
1398 VkImageLayout destImageLayout
,
1399 uint32_t regionCount
,
1400 const VkImageResolve
* pRegions
)
1406 anv_device_init_meta(struct anv_device
*device
)
1408 anv_device_init_meta_clear_state(device
);
1409 anv_device_init_meta_blit_state(device
);
1411 anv_CreateDynamicRasterState(anv_device_to_handle(device
),
1412 &(VkDynamicRasterStateCreateInfo
) {
1413 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_RASTER_STATE_CREATE_INFO
,
1415 &device
->meta_state
.shared
.rs_state
);
1417 anv_CreateDynamicColorBlendState(anv_device_to_handle(device
),
1418 &(VkDynamicColorBlendStateCreateInfo
) {
1419 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_COLOR_BLEND_STATE_CREATE_INFO
1421 &device
->meta_state
.shared
.cb_state
);
1423 anv_CreateDynamicDepthStencilState(anv_device_to_handle(device
),
1424 &(VkDynamicDepthStencilStateCreateInfo
) {
1425 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_DEPTH_STENCIL_STATE_CREATE_INFO
1427 &device
->meta_state
.shared
.ds_state
);
1431 anv_device_finish_meta(struct anv_device
*device
)
1434 anv_DestroyPipeline(anv_device_to_handle(device
),
1435 device
->meta_state
.clear
.pipeline
);
1438 anv_DestroyPipeline(anv_device_to_handle(device
),
1439 device
->meta_state
.blit
.pipeline
);
1440 anv_DestroyPipelineLayout(anv_device_to_handle(device
),
1441 device
->meta_state
.blit
.pipeline_layout
);
1442 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device
),
1443 device
->meta_state
.blit
.ds_layout
);
1446 anv_DestroyDynamicRasterState(anv_device_to_handle(device
),
1447 device
->meta_state
.shared
.rs_state
);
1448 anv_DestroyDynamicColorBlendState(anv_device_to_handle(device
),
1449 device
->meta_state
.shared
.cb_state
);
1450 anv_DestroyDynamicDepthStencilState(anv_device_to_handle(device
),
1451 device
->meta_state
.shared
.ds_state
);