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 "meta-spirv.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 VkShader 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 .pIaState
= &(VkPipelineIaStateCreateInfo
) {
115 .sType
= VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO
,
116 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
117 .primitiveRestartEnable
= false,
119 .pRsState
= &(VkPipelineRsStateCreateInfo
) {
120 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RS_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 .pCbState
= &(VkPipelineCbStateCreateInfo
) {
128 .sType
= VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO
,
129 .attachmentCount
= 1,
130 .pAttachments
= (VkPipelineCbAttachmentState
[]) {
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_DestroyObject(anv_device_to_handle(device
), VK_OBJECT_TYPE_SHADER
, fs
);
147 #define NUM_VB_USED 2
148 struct anv_saved_state
{
149 struct anv_vertex_binding old_vertex_bindings
[NUM_VB_USED
];
150 struct anv_descriptor_set
*old_descriptor_set0
;
151 struct anv_pipeline
*old_pipeline
;
152 VkDynamicColorBlendState cb_state
;
156 anv_cmd_buffer_save(struct anv_cmd_buffer
*cmd_buffer
,
157 struct anv_saved_state
*state
)
159 state
->old_pipeline
= cmd_buffer
->pipeline
;
160 state
->old_descriptor_set0
= cmd_buffer
->descriptors
[0].set
;
161 memcpy(state
->old_vertex_bindings
, cmd_buffer
->vertex_bindings
,
162 sizeof(state
->old_vertex_bindings
));
166 anv_cmd_buffer_restore(struct anv_cmd_buffer
*cmd_buffer
,
167 const struct anv_saved_state
*state
)
169 cmd_buffer
->pipeline
= state
->old_pipeline
;
170 cmd_buffer
->descriptors
[0].set
= state
->old_descriptor_set0
;
171 memcpy(cmd_buffer
->vertex_bindings
, state
->old_vertex_bindings
,
172 sizeof(state
->old_vertex_bindings
));
174 cmd_buffer
->vb_dirty
|= (1 << NUM_VB_USED
) - 1;
175 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
;
176 cmd_buffer
->descriptors_dirty
|= VK_SHADER_STAGE_VERTEX_BIT
;
182 uint32_t ViewportIndex
;
186 struct clear_instance_data
{
187 struct vue_header vue_header
;
188 VkClearColorValue color
;
192 meta_emit_clear(struct anv_cmd_buffer
*cmd_buffer
,
194 struct clear_instance_data
*instance_data
)
196 struct anv_device
*device
= cmd_buffer
->device
;
197 struct anv_framebuffer
*fb
= cmd_buffer
->framebuffer
;
198 struct anv_state state
;
201 const float vertex_data
[] = {
202 /* Rect-list coordinates */
205 fb
->width
, fb
->height
,
207 /* Align to 16 bytes */
211 size
= sizeof(vertex_data
) + num_instances
* sizeof(*instance_data
);
212 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 16);
214 /* Copy in the vertex and instance data */
215 memcpy(state
.map
, vertex_data
, sizeof(vertex_data
));
216 memcpy(state
.map
+ sizeof(vertex_data
), instance_data
,
217 num_instances
* sizeof(*instance_data
));
219 struct anv_buffer vertex_buffer
= {
220 .device
= cmd_buffer
->device
,
222 .bo
= &device
->surface_state_block_pool
.bo
,
223 .offset
= state
.offset
226 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
228 anv_buffer_to_handle(&vertex_buffer
),
229 anv_buffer_to_handle(&vertex_buffer
)
236 if (cmd_buffer
->pipeline
!= anv_pipeline_from_handle(device
->meta_state
.clear
.pipeline
))
237 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
238 VK_PIPELINE_BIND_POINT_GRAPHICS
,
239 device
->meta_state
.clear
.pipeline
);
241 /* We don't need anything here, only set if not already set. */
242 if (cmd_buffer
->rs_state
== NULL
)
243 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer
),
244 device
->meta_state
.shared
.rs_state
);
246 if (cmd_buffer
->vp_state
== NULL
)
247 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer
),
248 cmd_buffer
->framebuffer
->vp_state
);
250 if (cmd_buffer
->ds_state
== NULL
)
251 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer
),
252 device
->meta_state
.shared
.ds_state
);
254 if (cmd_buffer
->cb_state
== NULL
)
255 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
256 device
->meta_state
.shared
.cb_state
);
258 anv_CmdDraw(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 3, 0, num_instances
);
262 anv_cmd_buffer_clear_attachments(struct anv_cmd_buffer
*cmd_buffer
,
263 struct anv_render_pass
*pass
,
264 const VkClearValue
*clear_values
)
266 struct anv_saved_state saved_state
;
268 int num_clear_layers
= 0;
269 for (uint32_t i
= 0; i
< pass
->attachment_count
; i
++) {
270 if (pass
->attachments
[i
].load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
271 if (anv_is_vk_format_depth_or_stencil(pass
->attachments
[i
].format
)) {
272 anv_finishme("Can't clear depth-stencil yet");
279 if (num_clear_layers
== 0)
282 struct clear_instance_data instance_data
[num_clear_layers
];
283 uint32_t color_attachments
[num_clear_layers
];
286 for (uint32_t i
= 0; i
< pass
->attachment_count
; i
++) {
287 if (pass
->attachments
[i
].load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
&&
288 !anv_is_vk_format_depth_or_stencil(pass
->attachments
[i
].format
)) {
289 instance_data
[layer
] = (struct clear_instance_data
) {
295 .color
= clear_values
[i
].color
,
297 color_attachments
[layer
] = i
;
302 anv_cmd_buffer_save(cmd_buffer
, &saved_state
);
304 struct anv_subpass subpass
= {
306 .color_count
= num_clear_layers
,
307 .color_attachments
= color_attachments
,
308 .depth_stencil_attachment
= VK_ATTACHMENT_UNUSED
,
311 anv_cmd_buffer_begin_subpass(cmd_buffer
, &subpass
);
313 meta_emit_clear(cmd_buffer
, num_clear_layers
, instance_data
);
315 /* Restore API state */
316 anv_cmd_buffer_restore(cmd_buffer
, &saved_state
);
320 anv_device_init_meta_blit_state(struct anv_device
*device
)
322 /* We don't use a vertex shader for clearing, but instead build and pass
323 * the VUEs directly to the rasterization backend. However, we do need
324 * to provide GLSL source for the vertex shader so that the compiler
325 * does not dead-code our inputs.
327 VkShaderModule vsm
= GLSL_VK_SHADER_MODULE(device
, VERTEX
,
330 out vec4 v_tex_coord
;
333 v_tex_coord
= vec4(a_tex_coord
, 0, 1);
334 gl_Position
= vec4(a_pos
, 0, 1);
338 VkShaderModule fsm
= GLSL_VK_SHADER_MODULE(device
, FRAGMENT
,
341 layout(set
= 0, binding
= 0) uniform sampler2D u_tex
;
344 f_color
= texture(u_tex
, v_tex_coord
.xy
);
349 anv_CreateShader(anv_device_to_handle(device
),
350 &(VkShaderCreateInfo
) {
351 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
357 anv_CreateShader(anv_device_to_handle(device
),
358 &(VkShaderCreateInfo
) {
359 .sType
= VK_STRUCTURE_TYPE_SHADER_CREATE_INFO
,
364 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
365 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
367 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
371 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
376 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
380 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
385 .format
= VK_FORMAT_R32G32B32A32_UINT
,
392 .format
= VK_FORMAT_R32G32_SFLOAT
,
396 /* Texture Coordinate */
399 .format
= VK_FORMAT_R32G32_SFLOAT
,
405 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
406 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
408 .pBinding
= (VkDescriptorSetLayoutBinding
[]) {
410 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
412 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
413 .pImmutableSamplers
= NULL
417 anv_CreateDescriptorSetLayout(anv_device_to_handle(device
), &ds_layout_info
,
418 &device
->meta_state
.blit
.ds_layout
);
420 anv_CreatePipelineLayout(anv_device_to_handle(device
),
421 &(VkPipelineLayoutCreateInfo
) {
422 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
423 .descriptorSetCount
= 1,
424 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
,
426 &device
->meta_state
.blit
.pipeline_layout
);
428 anv_pipeline_create(anv_device_to_handle(device
),
429 &(VkGraphicsPipelineCreateInfo
) {
430 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
432 .pStages
= (VkPipelineShaderStageCreateInfo
[]) {
434 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
435 .stage
= VK_SHADER_STAGE_VERTEX
,
437 .pSpecializationInfo
= NULL
439 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
440 .stage
= VK_SHADER_STAGE_FRAGMENT
,
442 .pSpecializationInfo
= NULL
445 .pVertexInputState
= &vi_create_info
,
446 .pIaState
= &(VkPipelineIaStateCreateInfo
) {
447 .sType
= VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO
,
448 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
449 .primitiveRestartEnable
= false,
451 .pRsState
= &(VkPipelineRsStateCreateInfo
) {
452 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO
,
453 .depthClipEnable
= true,
454 .rasterizerDiscardEnable
= false,
455 .fillMode
= VK_FILL_MODE_SOLID
,
456 .cullMode
= VK_CULL_MODE_NONE
,
457 .frontFace
= VK_FRONT_FACE_CCW
459 .pCbState
= &(VkPipelineCbStateCreateInfo
) {
460 .sType
= VK_STRUCTURE_TYPE_PIPELINE_CB_STATE_CREATE_INFO
,
461 .attachmentCount
= 1,
462 .pAttachments
= (VkPipelineCbAttachmentState
[]) {
463 { .channelWriteMask
= VK_CHANNEL_A_BIT
|
464 VK_CHANNEL_R_BIT
| VK_CHANNEL_G_BIT
| VK_CHANNEL_B_BIT
},
468 .layout
= device
->meta_state
.blit
.pipeline_layout
,
470 &(struct anv_pipeline_create_info
) {
471 .use_repclear
= false,
472 .disable_viewport
= true,
473 .disable_scissor
= true,
477 &device
->meta_state
.blit
.pipeline
);
479 anv_DestroyObject(anv_device_to_handle(device
), VK_OBJECT_TYPE_SHADER
, vs
);
480 anv_DestroyObject(anv_device_to_handle(device
), VK_OBJECT_TYPE_SHADER
, fs
);
484 meta_prepare_blit(struct anv_cmd_buffer
*cmd_buffer
,
485 struct anv_saved_state
*saved_state
)
487 struct anv_device
*device
= cmd_buffer
->device
;
489 anv_cmd_buffer_save(cmd_buffer
, saved_state
);
491 if (cmd_buffer
->pipeline
!= anv_pipeline_from_handle(device
->meta_state
.blit
.pipeline
))
492 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
493 VK_PIPELINE_BIND_POINT_GRAPHICS
,
494 device
->meta_state
.blit
.pipeline
);
496 /* We don't need anything here, only set if not already set. */
497 if (cmd_buffer
->rs_state
== NULL
)
498 anv_CmdBindDynamicRasterState(anv_cmd_buffer_to_handle(cmd_buffer
),
499 device
->meta_state
.shared
.rs_state
);
500 if (cmd_buffer
->ds_state
== NULL
)
501 anv_CmdBindDynamicDepthStencilState(anv_cmd_buffer_to_handle(cmd_buffer
),
502 device
->meta_state
.shared
.ds_state
);
504 saved_state
->cb_state
= anv_dynamic_cb_state_to_handle(cmd_buffer
->cb_state
);
505 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
506 device
->meta_state
.shared
.cb_state
);
510 VkOffset3D src_offset
;
511 VkExtent3D src_extent
;
512 VkOffset3D dest_offset
;
513 VkExtent3D dest_extent
;
517 meta_emit_blit(struct anv_cmd_buffer
*cmd_buffer
,
518 struct anv_surface_view
*src
,
519 VkOffset3D src_offset
,
520 VkExtent3D src_extent
,
521 struct anv_color_attachment_view
*dest
,
522 VkOffset3D dest_offset
,
523 VkExtent3D dest_extent
)
525 struct anv_device
*device
= cmd_buffer
->device
;
527 struct blit_vb_data
{
532 unsigned vb_size
= sizeof(struct vue_header
) + 3 * sizeof(*vb_data
);
534 struct anv_state vb_state
=
535 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, vb_size
, 16);
536 memset(vb_state
.map
, 0, sizeof(struct vue_header
));
537 vb_data
= vb_state
.map
+ sizeof(struct vue_header
);
539 vb_data
[0] = (struct blit_vb_data
) {
541 dest_offset
.x
+ dest_extent
.width
,
542 dest_offset
.y
+ dest_extent
.height
,
545 (float)(src_offset
.x
+ src_extent
.width
) / (float)src
->extent
.width
,
546 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
550 vb_data
[1] = (struct blit_vb_data
) {
553 dest_offset
.y
+ dest_extent
.height
,
556 (float)src_offset
.x
/ (float)src
->extent
.width
,
557 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
561 vb_data
[2] = (struct blit_vb_data
) {
567 (float)src_offset
.x
/ (float)src
->extent
.width
,
568 (float)src_offset
.y
/ (float)src
->extent
.height
,
572 struct anv_buffer vertex_buffer
= {
575 .bo
= &device
->surface_state_block_pool
.bo
,
576 .offset
= vb_state
.offset
,
579 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
581 anv_buffer_to_handle(&vertex_buffer
),
582 anv_buffer_to_handle(&vertex_buffer
)
586 sizeof(struct vue_header
),
591 anv_AllocDescriptorSets(anv_device_to_handle(device
), 0 /* pool */,
592 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT
,
593 1, &device
->meta_state
.blit
.ds_layout
, &set
, &count
);
594 anv_UpdateDescriptorSets(anv_device_to_handle(device
),
596 (VkWriteDescriptorSet
[]) {
598 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
601 .destArrayElement
= 0,
603 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
604 .pDescriptors
= (VkDescriptorInfo
[]) {
606 .imageView
= (VkImageView
) src
,
607 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
614 anv_CreateFramebuffer(anv_device_to_handle(device
),
615 &(VkFramebufferCreateInfo
) {
616 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
617 .attachmentCount
= 1,
618 .pAttachments
= (VkAttachmentBindInfo
[]) {
620 .view
= anv_attachment_view_to_handle(&dest
->base
),
621 .layout
= VK_IMAGE_LAYOUT_GENERAL
624 .width
= dest
->view
.extent
.width
,
625 .height
= dest
->view
.extent
.height
,
630 anv_CreateRenderPass(anv_device_to_handle(device
),
631 &(VkRenderPassCreateInfo
) {
632 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
633 .attachmentCount
= 1,
634 .pAttachments
= &(VkAttachmentDescription
) {
635 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION
,
636 .format
= dest
->view
.format
,
637 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
638 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
639 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
640 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
643 .pSubpasses
= &(VkSubpassDescription
) {
644 .sType
= VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION
,
645 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
648 .colorAttachments
= &(VkAttachmentReference
) {
650 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
652 .resolveAttachments
= NULL
,
653 .depthStencilAttachment
= (VkAttachmentReference
) {
654 .attachment
= VK_ATTACHMENT_UNUSED
,
655 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
658 .preserveAttachments
= &(VkAttachmentReference
) {
660 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
663 .dependencyCount
= 0,
666 anv_CmdBeginRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
),
667 &(VkRenderPassBeginInfo
) {
668 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
672 .offset
= { dest_offset
.x
, dest_offset
.y
},
673 .extent
= { dest_extent
.width
, dest_extent
.height
},
675 .attachmentCount
= 1,
676 .pAttachmentClearValues
= NULL
,
677 }, VK_RENDER_PASS_CONTENTS_INLINE
);
679 anv_CmdBindDynamicViewportState(anv_cmd_buffer_to_handle(cmd_buffer
),
680 anv_framebuffer_from_handle(fb
)->vp_state
);
682 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer
),
683 VK_PIPELINE_BIND_POINT_GRAPHICS
,
684 device
->meta_state
.blit
.pipeline_layout
, 0, 1,
687 anv_CmdDraw(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 3, 0, 1);
689 anv_CmdEndRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
));
691 /* At the point where we emit the draw call, all data from the
692 * descriptor sets, etc. has been used. We are free to delete it.
694 anv_DestroyObject(anv_device_to_handle(device
),
695 VK_OBJECT_TYPE_DESCRIPTOR_SET
, set
);
696 anv_DestroyObject(anv_device_to_handle(device
),
697 VK_OBJECT_TYPE_FRAMEBUFFER
, fb
);
698 anv_DestroyObject(anv_device_to_handle(device
),
699 VK_OBJECT_TYPE_RENDER_PASS
, pass
);
703 meta_finish_blit(struct anv_cmd_buffer
*cmd_buffer
,
704 const struct anv_saved_state
*saved_state
)
706 anv_cmd_buffer_restore(cmd_buffer
, saved_state
);
707 anv_CmdBindDynamicColorBlendState(anv_cmd_buffer_to_handle(cmd_buffer
),
708 saved_state
->cb_state
);
712 vk_format_for_cpp(int cpp
)
715 case 1: return VK_FORMAT_R8_UINT
;
716 case 2: return VK_FORMAT_R8G8_UINT
;
717 case 3: return VK_FORMAT_R8G8B8_UINT
;
718 case 4: return VK_FORMAT_R8G8B8A8_UINT
;
719 case 6: return VK_FORMAT_R16G16B16_UINT
;
720 case 8: return VK_FORMAT_R16G16B16A16_UINT
;
721 case 12: return VK_FORMAT_R32G32B32_UINT
;
722 case 16: return VK_FORMAT_R32G32B32A32_UINT
;
724 unreachable("Invalid format cpp");
729 do_buffer_copy(struct anv_cmd_buffer
*cmd_buffer
,
730 struct anv_bo
*src
, uint64_t src_offset
,
731 struct anv_bo
*dest
, uint64_t dest_offset
,
732 int width
, int height
, VkFormat copy_format
)
734 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
736 VkImageCreateInfo image_info
= {
737 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
738 .imageType
= VK_IMAGE_TYPE_2D
,
739 .format
= copy_format
,
748 .tiling
= VK_IMAGE_TILING_LINEAR
,
749 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
753 VkImage src_image
, dest_image
;
754 anv_CreateImage(vk_device
, &image_info
, &src_image
);
755 anv_CreateImage(vk_device
, &image_info
, &dest_image
);
757 /* We could use a vk call to bind memory, but that would require
758 * creating a dummy memory object etc. so there's really no point.
760 anv_image_from_handle(src_image
)->bo
= src
;
761 anv_image_from_handle(src_image
)->offset
= src_offset
;
762 anv_image_from_handle(dest_image
)->bo
= dest
;
763 anv_image_from_handle(dest_image
)->offset
= dest_offset
;
765 struct anv_surface_view src_view
;
766 anv_image_view_init(&src_view
, cmd_buffer
->device
,
767 &(VkImageViewCreateInfo
) {
768 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
770 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
771 .format
= copy_format
,
773 VK_CHANNEL_SWIZZLE_R
,
774 VK_CHANNEL_SWIZZLE_G
,
775 VK_CHANNEL_SWIZZLE_B
,
778 .subresourceRange
= {
779 .aspect
= VK_IMAGE_ASPECT_COLOR
,
788 struct anv_color_attachment_view dest_view
;
789 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
790 &(VkAttachmentViewCreateInfo
) {
791 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
793 .format
= copy_format
,
800 meta_emit_blit(cmd_buffer
,
802 (VkOffset3D
) { 0, 0, 0 },
803 (VkExtent3D
) { width
, height
, 1 },
805 (VkOffset3D
) { 0, 0, 0 },
806 (VkExtent3D
) { width
, height
, 1 });
808 anv_DestroyObject(vk_device
, VK_OBJECT_TYPE_IMAGE
, src_image
);
809 anv_DestroyObject(vk_device
, VK_OBJECT_TYPE_IMAGE
, dest_image
);
812 void anv_CmdCopyBuffer(
813 VkCmdBuffer cmdBuffer
,
816 uint32_t regionCount
,
817 const VkBufferCopy
* pRegions
)
819 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
820 struct anv_buffer
*src_buffer
= (struct anv_buffer
*)srcBuffer
;
821 struct anv_buffer
*dest_buffer
= (struct anv_buffer
*)destBuffer
;
822 struct anv_saved_state saved_state
;
824 meta_prepare_blit(cmd_buffer
, &saved_state
);
826 for (unsigned r
= 0; r
< regionCount
; r
++) {
827 uint64_t src_offset
= src_buffer
->offset
+ pRegions
[r
].srcOffset
;
828 uint64_t dest_offset
= dest_buffer
->offset
+ pRegions
[r
].destOffset
;
829 uint64_t copy_size
= pRegions
[r
].copySize
;
831 /* First, we compute the biggest format that can be used with the
832 * given offsets and size.
836 int fs
= ffs(src_offset
) - 1;
838 cpp
= MIN2(cpp
, 1 << fs
);
839 assert(src_offset
% cpp
== 0);
841 fs
= ffs(dest_offset
) - 1;
843 cpp
= MIN2(cpp
, 1 << fs
);
844 assert(dest_offset
% cpp
== 0);
846 fs
= ffs(pRegions
[r
].copySize
) - 1;
848 cpp
= MIN2(cpp
, 1 << fs
);
849 assert(pRegions
[r
].copySize
% cpp
== 0);
851 VkFormat copy_format
= vk_format_for_cpp(cpp
);
853 /* This is maximum possible width/height our HW can handle */
854 uint64_t max_surface_dim
= 1 << 14;
856 /* First, we make a bunch of max-sized copies */
857 uint64_t max_copy_size
= max_surface_dim
* max_surface_dim
* cpp
;
858 while (copy_size
> max_copy_size
) {
859 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
860 dest_buffer
->bo
, dest_offset
,
861 max_surface_dim
, max_surface_dim
, copy_format
);
862 copy_size
-= max_copy_size
;
863 src_offset
+= max_copy_size
;
864 dest_offset
+= max_copy_size
;
867 uint64_t height
= copy_size
/ (max_surface_dim
* cpp
);
868 assert(height
< max_surface_dim
);
870 uint64_t rect_copy_size
= height
* max_surface_dim
* cpp
;
871 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
872 dest_buffer
->bo
, dest_offset
,
873 max_surface_dim
, height
, copy_format
);
874 copy_size
-= rect_copy_size
;
875 src_offset
+= rect_copy_size
;
876 dest_offset
+= rect_copy_size
;
879 if (copy_size
!= 0) {
880 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
881 dest_buffer
->bo
, dest_offset
,
882 copy_size
/ cpp
, 1, copy_format
);
886 meta_finish_blit(cmd_buffer
, &saved_state
);
889 void anv_CmdCopyImage(
890 VkCmdBuffer cmdBuffer
,
892 VkImageLayout srcImageLayout
,
894 VkImageLayout destImageLayout
,
895 uint32_t regionCount
,
896 const VkImageCopy
* pRegions
)
898 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
899 struct anv_image
*src_image
= (struct anv_image
*)srcImage
;
900 struct anv_saved_state saved_state
;
902 meta_prepare_blit(cmd_buffer
, &saved_state
);
904 for (unsigned r
= 0; r
< regionCount
; r
++) {
905 struct anv_surface_view src_view
;
906 anv_image_view_init(&src_view
, cmd_buffer
->device
,
907 &(VkImageViewCreateInfo
) {
908 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
910 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
911 .format
= src_image
->format
,
913 VK_CHANNEL_SWIZZLE_R
,
914 VK_CHANNEL_SWIZZLE_G
,
915 VK_CHANNEL_SWIZZLE_B
,
918 .subresourceRange
= {
919 .aspect
= pRegions
[r
].srcSubresource
.aspect
,
920 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
922 .baseArraySlice
= pRegions
[r
].srcSubresource
.arraySlice
,
928 struct anv_color_attachment_view dest_view
;
929 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
930 &(VkAttachmentViewCreateInfo
) {
931 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
933 .format
= src_image
->format
,
934 .mipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
935 .baseArraySlice
= pRegions
[r
].destSubresource
.arraySlice
,
940 meta_emit_blit(cmd_buffer
,
942 pRegions
[r
].srcOffset
,
945 pRegions
[r
].destOffset
,
949 meta_finish_blit(cmd_buffer
, &saved_state
);
952 void anv_CmdBlitImage(
953 VkCmdBuffer cmdBuffer
,
955 VkImageLayout srcImageLayout
,
957 VkImageLayout destImageLayout
,
958 uint32_t regionCount
,
959 const VkImageBlit
* pRegions
,
963 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
964 struct anv_image
*src_image
= (struct anv_image
*)srcImage
;
965 struct anv_image
*dest_image
= (struct anv_image
*)destImage
;
966 struct anv_saved_state saved_state
;
968 anv_finishme("respect VkTexFilter");
970 meta_prepare_blit(cmd_buffer
, &saved_state
);
972 for (unsigned r
= 0; r
< regionCount
; r
++) {
973 struct anv_surface_view src_view
;
974 anv_image_view_init(&src_view
, cmd_buffer
->device
,
975 &(VkImageViewCreateInfo
) {
976 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
978 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
979 .format
= src_image
->format
,
981 VK_CHANNEL_SWIZZLE_R
,
982 VK_CHANNEL_SWIZZLE_G
,
983 VK_CHANNEL_SWIZZLE_B
,
986 .subresourceRange
= {
987 .aspect
= pRegions
[r
].srcSubresource
.aspect
,
988 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
990 .baseArraySlice
= pRegions
[r
].srcSubresource
.arraySlice
,
996 struct anv_color_attachment_view dest_view
;
997 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
998 &(VkAttachmentViewCreateInfo
) {
999 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1001 .format
= dest_image
->format
,
1002 .mipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
1003 .baseArraySlice
= pRegions
[r
].destSubresource
.arraySlice
,
1008 meta_emit_blit(cmd_buffer
,
1010 pRegions
[r
].srcOffset
,
1011 pRegions
[r
].srcExtent
,
1013 pRegions
[r
].destOffset
,
1014 pRegions
[r
].destExtent
);
1017 meta_finish_blit(cmd_buffer
, &saved_state
);
1020 void anv_CmdCopyBufferToImage(
1021 VkCmdBuffer cmdBuffer
,
1024 VkImageLayout destImageLayout
,
1025 uint32_t regionCount
,
1026 const VkBufferImageCopy
* pRegions
)
1028 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1029 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
1030 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
1031 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1032 struct anv_saved_state saved_state
;
1034 meta_prepare_blit(cmd_buffer
, &saved_state
);
1036 for (unsigned r
= 0; r
< regionCount
; r
++) {
1037 if (pRegions
[r
].bufferRowLength
!= 0)
1038 anv_finishme("bufferRowLength not supported in CopyBufferToImage");
1039 if (pRegions
[r
].bufferImageHeight
!= 0)
1040 anv_finishme("bufferImageHeight not supported in CopyBufferToImage");
1043 anv_CreateImage(vk_device
,
1044 &(VkImageCreateInfo
) {
1045 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
1046 .imageType
= VK_IMAGE_TYPE_2D
,
1047 .format
= dest_image
->format
,
1049 .width
= pRegions
[r
].imageExtent
.width
,
1050 .height
= pRegions
[r
].imageExtent
.height
,
1056 .tiling
= VK_IMAGE_TILING_LINEAR
,
1057 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
1061 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1063 /* We could use a vk call to bind memory, but that would require
1064 * creating a dummy memory object etc. so there's really no point.
1066 src_image
->bo
= src_buffer
->bo
;
1067 src_image
->offset
= src_buffer
->offset
+ pRegions
[r
].bufferOffset
;
1069 struct anv_surface_view src_view
;
1070 anv_image_view_init(&src_view
, cmd_buffer
->device
,
1071 &(VkImageViewCreateInfo
) {
1072 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1073 .image
= anv_image_to_handle(src_image
),
1074 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1075 .format
= dest_image
->format
,
1077 VK_CHANNEL_SWIZZLE_R
,
1078 VK_CHANNEL_SWIZZLE_G
,
1079 VK_CHANNEL_SWIZZLE_B
,
1080 VK_CHANNEL_SWIZZLE_A
1082 .subresourceRange
= {
1083 .aspect
= pRegions
[r
].imageSubresource
.aspect
,
1086 .baseArraySlice
= 0,
1092 struct anv_color_attachment_view dest_view
;
1093 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
1094 &(VkAttachmentViewCreateInfo
) {
1095 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1096 .image
= anv_image_to_handle(dest_image
),
1097 .format
= dest_image
->format
,
1098 .mipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1099 .baseArraySlice
= pRegions
[r
].imageSubresource
.arraySlice
,
1104 meta_emit_blit(cmd_buffer
,
1106 (VkOffset3D
) { 0, 0, 0 },
1107 pRegions
[r
].imageExtent
,
1109 pRegions
[r
].imageOffset
,
1110 pRegions
[r
].imageExtent
);
1112 anv_DestroyObject(vk_device
, VK_OBJECT_TYPE_IMAGE
, srcImage
);
1115 meta_finish_blit(cmd_buffer
, &saved_state
);
1118 void anv_CmdCopyImageToBuffer(
1119 VkCmdBuffer cmdBuffer
,
1121 VkImageLayout srcImageLayout
,
1122 VkBuffer destBuffer
,
1123 uint32_t regionCount
,
1124 const VkBufferImageCopy
* pRegions
)
1126 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1127 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1128 ANV_FROM_HANDLE(anv_buffer
, dest_buffer
, destBuffer
);
1129 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1130 struct anv_saved_state saved_state
;
1132 meta_prepare_blit(cmd_buffer
, &saved_state
);
1134 for (unsigned r
= 0; r
< regionCount
; r
++) {
1135 if (pRegions
[r
].bufferRowLength
!= 0)
1136 anv_finishme("bufferRowLength not supported in CopyBufferToImage");
1137 if (pRegions
[r
].bufferImageHeight
!= 0)
1138 anv_finishme("bufferImageHeight not supported in CopyBufferToImage");
1140 struct anv_surface_view src_view
;
1141 anv_image_view_init(&src_view
, cmd_buffer
->device
,
1142 &(VkImageViewCreateInfo
) {
1143 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1145 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1146 .format
= src_image
->format
,
1148 VK_CHANNEL_SWIZZLE_R
,
1149 VK_CHANNEL_SWIZZLE_G
,
1150 VK_CHANNEL_SWIZZLE_B
,
1151 VK_CHANNEL_SWIZZLE_A
1153 .subresourceRange
= {
1154 .aspect
= pRegions
[r
].imageSubresource
.aspect
,
1155 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1157 .baseArraySlice
= pRegions
[r
].imageSubresource
.arraySlice
,
1164 anv_CreateImage(vk_device
,
1165 &(VkImageCreateInfo
) {
1166 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
1167 .imageType
= VK_IMAGE_TYPE_2D
,
1168 .format
= src_image
->format
,
1170 .width
= pRegions
[r
].imageExtent
.width
,
1171 .height
= pRegions
[r
].imageExtent
.height
,
1177 .tiling
= VK_IMAGE_TILING_LINEAR
,
1178 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
1182 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
1184 /* We could use a vk call to bind memory, but that would require
1185 * creating a dummy memory object etc. so there's really no point.
1187 dest_image
->bo
= dest_buffer
->bo
;
1188 dest_image
->offset
= dest_buffer
->offset
+ pRegions
[r
].bufferOffset
;
1190 struct anv_color_attachment_view dest_view
;
1191 anv_color_attachment_view_init(&dest_view
, cmd_buffer
->device
,
1192 &(VkAttachmentViewCreateInfo
) {
1193 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1195 .format
= src_image
->format
,
1197 .baseArraySlice
= 0,
1202 meta_emit_blit(cmd_buffer
,
1204 pRegions
[r
].imageOffset
,
1205 pRegions
[r
].imageExtent
,
1207 (VkOffset3D
) { 0, 0, 0 },
1208 pRegions
[r
].imageExtent
);
1210 anv_DestroyObject(vk_device
, VK_OBJECT_TYPE_IMAGE
, destImage
);
1213 meta_finish_blit(cmd_buffer
, &saved_state
);
1216 void anv_CmdUpdateBuffer(
1217 VkCmdBuffer cmdBuffer
,
1218 VkBuffer destBuffer
,
1219 VkDeviceSize destOffset
,
1220 VkDeviceSize dataSize
,
1221 const uint32_t* pData
)
1226 void anv_CmdFillBuffer(
1227 VkCmdBuffer cmdBuffer
,
1228 VkBuffer destBuffer
,
1229 VkDeviceSize destOffset
,
1230 VkDeviceSize fillSize
,
1236 void anv_CmdClearColorImage(
1237 VkCmdBuffer cmdBuffer
,
1239 VkImageLayout imageLayout
,
1240 const VkClearColorValue
* pColor
,
1241 uint32_t rangeCount
,
1242 const VkImageSubresourceRange
* pRanges
)
1244 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, cmdBuffer
);
1245 ANV_FROM_HANDLE(anv_image
, image
, _image
);
1246 struct anv_saved_state saved_state
;
1248 anv_cmd_buffer_save(cmd_buffer
, &saved_state
);
1250 for (uint32_t r
= 0; r
< rangeCount
; r
++) {
1251 for (uint32_t l
= 0; l
< pRanges
[r
].mipLevels
; l
++) {
1252 for (uint32_t s
= 0; s
< pRanges
[r
].arraySize
; s
++) {
1253 struct anv_color_attachment_view view
;
1254 anv_color_attachment_view_init(&view
, cmd_buffer
->device
,
1255 &(VkAttachmentViewCreateInfo
) {
1256 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_VIEW_CREATE_INFO
,
1258 .format
= image
->format
,
1259 .mipLevel
= pRanges
[r
].baseMipLevel
+ l
,
1260 .baseArraySlice
= pRanges
[r
].baseArraySlice
+ s
,
1266 anv_CreateFramebuffer(anv_device_to_handle(cmd_buffer
->device
),
1267 &(VkFramebufferCreateInfo
) {
1268 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
1269 .attachmentCount
= 1,
1270 .pAttachments
= (VkAttachmentBindInfo
[]) {
1272 .view
= anv_attachment_view_to_handle(&view
.base
),
1273 .layout
= VK_IMAGE_LAYOUT_GENERAL
1276 .width
= view
.view
.extent
.width
,
1277 .height
= view
.view
.extent
.height
,
1282 anv_CreateRenderPass(anv_device_to_handle(cmd_buffer
->device
),
1283 &(VkRenderPassCreateInfo
) {
1284 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1285 .attachmentCount
= 1,
1286 .pAttachments
= &(VkAttachmentDescription
) {
1287 .sType
= VK_STRUCTURE_TYPE_ATTACHMENT_DESCRIPTION
,
1288 .format
= view
.view
.format
,
1289 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1290 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1291 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1292 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1295 .pSubpasses
= &(VkSubpassDescription
) {
1296 .sType
= VK_STRUCTURE_TYPE_SUBPASS_DESCRIPTION
,
1297 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1300 .colorAttachments
= &(VkAttachmentReference
) {
1302 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1304 .resolveAttachments
= NULL
,
1305 .depthStencilAttachment
= (VkAttachmentReference
) {
1306 .attachment
= VK_ATTACHMENT_UNUSED
,
1307 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1310 .preserveAttachments
= &(VkAttachmentReference
) {
1312 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1315 .dependencyCount
= 0,
1318 anv_CmdBeginRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
),
1319 &(VkRenderPassBeginInfo
) {
1320 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
1322 .offset
= { 0, 0, },
1324 .width
= view
.view
.extent
.width
,
1325 .height
= view
.view
.extent
.height
,
1330 .attachmentCount
= 1,
1331 .pAttachmentClearValues
= NULL
,
1332 }, VK_RENDER_PASS_CONTENTS_INLINE
);
1334 struct clear_instance_data instance_data
= {
1343 meta_emit_clear(cmd_buffer
, 1, &instance_data
);
1345 anv_CmdEndRenderPass(anv_cmd_buffer_to_handle(cmd_buffer
));
1350 /* Restore API state */
1351 anv_cmd_buffer_restore(cmd_buffer
, &saved_state
);
1354 void anv_CmdClearDepthStencilImage(
1355 VkCmdBuffer cmdBuffer
,
1357 VkImageLayout imageLayout
,
1360 uint32_t rangeCount
,
1361 const VkImageSubresourceRange
* pRanges
)
1366 void anv_CmdClearColorAttachment(
1367 VkCmdBuffer cmdBuffer
,
1368 uint32_t colorAttachment
,
1369 VkImageLayout imageLayout
,
1370 const VkClearColorValue
* pColor
,
1372 const VkRect3D
* pRects
)
1377 void anv_CmdClearDepthStencilAttachment(
1378 VkCmdBuffer cmdBuffer
,
1379 VkImageAspectFlags imageAspectMask
,
1380 VkImageLayout imageLayout
,
1384 const VkRect3D
* pRects
)
1389 void anv_CmdResolveImage(
1390 VkCmdBuffer cmdBuffer
,
1392 VkImageLayout srcImageLayout
,
1394 VkImageLayout destImageLayout
,
1395 uint32_t regionCount
,
1396 const VkImageResolve
* pRegions
)
1402 anv_device_init_meta(struct anv_device
*device
)
1404 anv_device_init_meta_clear_state(device
);
1405 anv_device_init_meta_blit_state(device
);
1407 anv_CreateDynamicRasterState(anv_device_to_handle(device
),
1408 &(VkDynamicRasterStateCreateInfo
) {
1409 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
,
1411 &device
->meta_state
.shared
.rs_state
);
1413 anv_CreateDynamicColorBlendState(anv_device_to_handle(device
),
1414 &(VkDynamicColorBlendStateCreateInfo
) {
1415 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_CB_STATE_CREATE_INFO
1417 &device
->meta_state
.shared
.cb_state
);
1419 anv_CreateDynamicDepthStencilState(anv_device_to_handle(device
),
1420 &(VkDynamicDepthStencilStateCreateInfo
) {
1421 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_DS_STATE_CREATE_INFO
1423 &device
->meta_state
.shared
.ds_state
);
1427 anv_device_finish_meta(struct anv_device
*device
)
1430 anv_DestroyObject(anv_device_to_handle(device
), VK_OBJECT_TYPE_PIPELINE
,
1431 device
->meta_state
.clear
.pipeline
);
1434 anv_DestroyObject(anv_device_to_handle(device
), VK_OBJECT_TYPE_PIPELINE
,
1435 device
->meta_state
.blit
.pipeline
);
1436 anv_DestroyObject(anv_device_to_handle(device
),
1437 VK_OBJECT_TYPE_PIPELINE_LAYOUT
,
1438 device
->meta_state
.blit
.pipeline_layout
);
1439 anv_DestroyObject(anv_device_to_handle(device
),
1440 VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT
,
1441 device
->meta_state
.blit
.ds_layout
);
1444 anv_DestroyObject(anv_device_to_handle(device
),
1445 VK_OBJECT_TYPE_DYNAMIC_RS_STATE
,
1446 device
->meta_state
.shared
.rs_state
);
1447 anv_DestroyObject(anv_device_to_handle(device
),
1448 VK_OBJECT_TYPE_DYNAMIC_CB_STATE
,
1449 device
->meta_state
.shared
.cb_state
);
1450 anv_DestroyObject(anv_device_to_handle(device
),
1451 VK_OBJECT_TYPE_DYNAMIC_DS_STATE
,
1452 device
->meta_state
.shared
.ds_state
);