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 "glsl_helpers.h"
34 anv_device_init_meta_clear_state(struct anv_device
*device
)
36 VkPipelineIaStateCreateInfo ia_create_info
= {
37 .sType
= VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO
,
38 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
39 .disableVertexReuse
= false,
40 .primitiveRestartEnable
= false,
41 .primitiveRestartIndex
= 0
44 /* We don't use a vertex shader for clearing, but instead build and pass
45 * the VUEs directly to the rasterization backend.
47 VkShader fs
= GLSL_VK_SHADER(device
, FRAGMENT
,
56 VkPipelineShaderStageCreateInfo fs_create_info
= {
57 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
58 .pNext
= &ia_create_info
,
60 .stage
= VK_SHADER_STAGE_FRAGMENT
,
62 .linkConstBufferCount
= 0,
63 .pLinkConstBufferInfo
= NULL
,
64 .pSpecializationInfo
= NULL
68 /* We use instanced rendering to clear multiple render targets. We have two
69 * vertex buffers: the first vertex buffer holds per-vertex data and
70 * provides the vertices for the clear rectangle. The second one holds
71 * per-instance data, which consists of the VUE header (which selects the
72 * layer) and the color (Vulkan supports per-RT clear colors).
74 VkPipelineVertexInputCreateInfo vi_create_info
= {
75 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO
,
76 .pNext
= &fs_create_info
,
78 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
82 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
87 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_INSTANCE
91 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
96 .format
= VK_FORMAT_R32G32B32A32_UINT
,
103 .format
= VK_FORMAT_R32G32_SFLOAT
,
110 .format
= VK_FORMAT_R32G32B32A32_SFLOAT
,
116 VkPipelineRsStateCreateInfo rs_create_info
= {
117 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO
,
118 .pNext
= &vi_create_info
,
119 .depthClipEnable
= true,
120 .rasterizerDiscardEnable
= false,
121 .fillMode
= VK_FILL_MODE_SOLID
,
122 .cullMode
= VK_CULL_MODE_NONE
,
123 .frontFace
= VK_FRONT_FACE_CCW
126 anv_pipeline_create((VkDevice
) device
,
127 &(VkGraphicsPipelineCreateInfo
) {
128 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
129 .pNext
= &rs_create_info
,
133 &(struct anv_pipeline_create_info
) {
134 .use_repclear
= true,
135 .disable_viewport
= true,
138 &device
->clear_state
.pipeline
);
140 anv_DestroyObject((VkDevice
) device
, VK_OBJECT_TYPE_SHADER
, fs
);
142 anv_CreateDynamicRasterState((VkDevice
) device
,
143 &(VkDynamicRsStateCreateInfo
) {
144 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
,
146 &device
->clear_state
.rs_state
);
149 #define NUM_VB_USED 2
150 struct anv_saved_state
{
151 struct anv_bindings bindings
;
152 struct anv_bindings
*old_bindings
;
153 struct anv_pipeline
*old_pipeline
;
157 anv_cmd_buffer_save(struct anv_cmd_buffer
*cmd_buffer
,
158 struct anv_saved_state
*state
)
160 state
->old_bindings
= cmd_buffer
->bindings
;
161 cmd_buffer
->bindings
= &state
->bindings
;
162 state
->old_pipeline
= cmd_buffer
->pipeline
;
164 /* Initialize render targets for the meta bindings. */
165 anv_cmd_buffer_fill_render_targets(cmd_buffer
);
169 anv_cmd_buffer_restore(struct anv_cmd_buffer
*cmd_buffer
,
170 const struct anv_saved_state
*state
)
172 cmd_buffer
->bindings
= state
->old_bindings
;
173 cmd_buffer
->pipeline
= state
->old_pipeline
;
175 cmd_buffer
->vb_dirty
|= (1 << NUM_VB_USED
) - 1;
176 cmd_buffer
->dirty
|= ANV_CMD_BUFFER_PIPELINE_DIRTY
|
177 ANV_CMD_BUFFER_DESCRIPTOR_SET_DIRTY
;
183 uint32_t ViewportIndex
;
188 anv_cmd_buffer_clear(struct anv_cmd_buffer
*cmd_buffer
,
189 struct anv_render_pass
*pass
)
191 struct anv_device
*device
= cmd_buffer
->device
;
192 struct anv_framebuffer
*fb
= cmd_buffer
->framebuffer
;
193 struct anv_saved_state saved_state
;
194 struct anv_state state
;
197 struct instance_data
{
198 struct vue_header vue_header
;
202 if (pass
->num_clear_layers
== 0)
205 const float vertex_data
[] = {
206 /* Rect-list coordinates */
209 fb
->width
, fb
->height
,
211 /* Align to 16 bytes */
215 size
= sizeof(vertex_data
) + pass
->num_clear_layers
* sizeof(instance_data
[0]);
216 state
= anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, size
, 16);
218 memcpy(state
.map
, vertex_data
, sizeof(vertex_data
));
219 instance_data
= state
.map
+ sizeof(vertex_data
);
221 for (uint32_t i
= 0; i
< pass
->num_layers
; i
++) {
222 if (pass
->layers
[i
].color_load_op
== VK_ATTACHMENT_LOAD_OP_CLEAR
) {
223 *instance_data
++ = (struct instance_data
) {
230 pass
->layers
[i
].clear_color
.color
.floatColor
[0],
231 pass
->layers
[i
].clear_color
.color
.floatColor
[1],
232 pass
->layers
[i
].clear_color
.color
.floatColor
[2],
233 pass
->layers
[i
].clear_color
.color
.floatColor
[3],
239 struct anv_buffer vertex_buffer
= {
240 .device
= cmd_buffer
->device
,
242 .bo
= &device
->surface_state_block_pool
.bo
,
243 .offset
= state
.offset
246 anv_cmd_buffer_save(cmd_buffer
, &saved_state
);
248 anv_CmdBindVertexBuffers((VkCmdBuffer
) cmd_buffer
, 0, 2,
250 (VkBuffer
) &vertex_buffer
,
251 (VkBuffer
) &vertex_buffer
258 if ((VkPipeline
) cmd_buffer
->pipeline
!= device
->clear_state
.pipeline
)
259 anv_CmdBindPipeline((VkCmdBuffer
) cmd_buffer
,
260 VK_PIPELINE_BIND_POINT_GRAPHICS
, device
->clear_state
.pipeline
);
262 /* We don't need anything here, only set if not already set. */
263 if (cmd_buffer
->rs_state
== NULL
)
264 anv_CmdBindDynamicStateObject((VkCmdBuffer
) cmd_buffer
,
265 VK_STATE_BIND_POINT_RASTER
,
266 device
->clear_state
.rs_state
);
268 if (cmd_buffer
->vp_state
== NULL
)
269 anv_CmdBindDynamicStateObject((VkCmdBuffer
) cmd_buffer
,
270 VK_STATE_BIND_POINT_VIEWPORT
,
271 cmd_buffer
->framebuffer
->vp_state
);
273 anv_CmdDraw((VkCmdBuffer
) cmd_buffer
, 0, 3, 0, pass
->num_clear_layers
);
275 /* Restore API state */
276 anv_cmd_buffer_restore(cmd_buffer
, &saved_state
);
281 anv_device_init_meta_blit_state(struct anv_device
*device
)
283 VkPipelineIaStateCreateInfo ia_create_info
= {
284 .sType
= VK_STRUCTURE_TYPE_PIPELINE_IA_STATE_CREATE_INFO
,
285 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
286 .disableVertexReuse
= false,
287 .primitiveRestartEnable
= false,
288 .primitiveRestartIndex
= 0
291 /* We don't use a vertex shader for clearing, but instead build and pass
292 * the VUEs directly to the rasterization backend. However, we do need
293 * to provide GLSL source for the vertex shader so that the compiler
294 * does not dead-code our inputs.
296 VkShader vs
= GLSL_VK_SHADER(device
, VERTEX
,
299 out vec4 v_tex_coord
;
302 v_tex_coord
= vec4(a_tex_coord
, 0, 1);
303 gl_Position
= vec4(a_pos
, 0, 1);
307 VkShader fs
= GLSL_VK_SHADER(device
, FRAGMENT
,
310 layout(set
= 0, index
= 0) uniform sampler2D u_tex
;
313 f_color
= texture2D(u_tex
, v_tex_coord
.xy
);
317 VkPipelineShaderStageCreateInfo vs_create_info
= {
318 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
319 .pNext
= &ia_create_info
,
321 .stage
= VK_SHADER_STAGE_VERTEX
,
323 .linkConstBufferCount
= 0,
324 .pLinkConstBufferInfo
= NULL
,
325 .pSpecializationInfo
= NULL
329 VkPipelineShaderStageCreateInfo fs_create_info
= {
330 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
331 .pNext
= &vs_create_info
,
333 .stage
= VK_SHADER_STAGE_FRAGMENT
,
335 .linkConstBufferCount
= 0,
336 .pLinkConstBufferInfo
= NULL
,
337 .pSpecializationInfo
= NULL
341 VkPipelineVertexInputCreateInfo vi_create_info
= {
342 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_CREATE_INFO
,
343 .pNext
= &fs_create_info
,
345 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
349 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
354 .stepRate
= VK_VERTEX_INPUT_STEP_RATE_VERTEX
358 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
363 .format
= VK_FORMAT_R32G32B32A32_UINT
,
370 .format
= VK_FORMAT_R32G32_SFLOAT
,
374 /* Texture Coordinate */
377 .format
= VK_FORMAT_R32G32_SFLOAT
,
383 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
384 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
386 .pBinding
= (VkDescriptorSetLayoutBinding
[]) {
388 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
390 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
391 .pImmutableSamplers
= NULL
395 anv_CreateDescriptorSetLayout((VkDevice
) device
, &ds_layout_info
,
396 &device
->blit_state
.ds_layout
);
398 VkPipelineLayoutCreateInfo pipeline_layout_info
= {
399 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
400 .descriptorSetCount
= 1,
401 .pSetLayouts
= &device
->blit_state
.ds_layout
,
404 VkPipelineLayout pipeline_layout
;
405 anv_CreatePipelineLayout((VkDevice
) device
, &pipeline_layout_info
,
408 VkPipelineRsStateCreateInfo rs_create_info
= {
409 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RS_STATE_CREATE_INFO
,
410 .pNext
= &vi_create_info
,
411 .depthClipEnable
= true,
412 .rasterizerDiscardEnable
= false,
413 .fillMode
= VK_FILL_MODE_SOLID
,
414 .cullMode
= VK_CULL_MODE_NONE
,
415 .frontFace
= VK_FRONT_FACE_CCW
418 VkGraphicsPipelineCreateInfo pipeline_info
= {
419 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
420 .pNext
= &rs_create_info
,
422 .layout
= pipeline_layout
,
425 anv_pipeline_create((VkDevice
) device
, &pipeline_info
,
426 &(struct anv_pipeline_create_info
) {
427 .use_repclear
= false,
428 .disable_viewport
= true,
429 .disable_scissor
= true,
433 &device
->blit_state
.pipeline
);
435 anv_DestroyObject((VkDevice
) device
, VK_OBJECT_TYPE_SHADER
, vs
);
436 anv_DestroyObject((VkDevice
) device
, VK_OBJECT_TYPE_SHADER
, fs
);
438 anv_CreateDynamicRasterState((VkDevice
) device
,
439 &(VkDynamicRsStateCreateInfo
) {
440 .sType
= VK_STRUCTURE_TYPE_DYNAMIC_RS_STATE_CREATE_INFO
,
442 &device
->blit_state
.rs_state
);
446 meta_prepare_blit(struct anv_cmd_buffer
*cmd_buffer
,
447 struct anv_saved_state
*saved_state
)
449 struct anv_device
*device
= cmd_buffer
->device
;
451 anv_cmd_buffer_save(cmd_buffer
, saved_state
);
453 if ((VkPipeline
) cmd_buffer
->pipeline
!= device
->blit_state
.pipeline
)
454 anv_CmdBindPipeline((VkCmdBuffer
) cmd_buffer
,
455 VK_PIPELINE_BIND_POINT_GRAPHICS
,
456 device
->blit_state
.pipeline
);
458 /* We don't need anything here, only set if not already set. */
459 if (cmd_buffer
->rs_state
== NULL
)
460 anv_CmdBindDynamicStateObject((VkCmdBuffer
) cmd_buffer
,
461 VK_STATE_BIND_POINT_RASTER
,
462 device
->blit_state
.rs_state
);
466 VkOffset3D src_offset
;
467 VkExtent3D src_extent
;
468 VkOffset3D dest_offset
;
469 VkExtent3D dest_extent
;
473 meta_emit_blit(struct anv_cmd_buffer
*cmd_buffer
,
474 struct anv_surface_view
*src
,
475 VkOffset3D src_offset
,
476 VkExtent3D src_extent
,
477 struct anv_surface_view
*dest
,
478 VkOffset3D dest_offset
,
479 VkExtent3D dest_extent
)
481 struct anv_device
*device
= cmd_buffer
->device
;
483 struct blit_vb_data
{
488 unsigned vb_size
= sizeof(struct vue_header
) + 3 * sizeof(*vb_data
);
490 struct anv_state vb_state
=
491 anv_state_stream_alloc(&cmd_buffer
->surface_state_stream
, vb_size
, 16);
492 memset(vb_state
.map
, 0, sizeof(struct vue_header
));
493 vb_data
= vb_state
.map
+ sizeof(struct vue_header
);
495 vb_data
[0] = (struct blit_vb_data
) {
497 dest_offset
.x
+ dest_extent
.width
,
498 dest_offset
.y
+ dest_extent
.height
,
501 (float)(src_offset
.x
+ src_extent
.width
) / (float)src
->extent
.width
,
502 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
506 vb_data
[1] = (struct blit_vb_data
) {
509 dest_offset
.y
+ dest_extent
.height
,
512 (float)src_offset
.x
/ (float)src
->extent
.width
,
513 (float)(src_offset
.y
+ src_extent
.height
) / (float)src
->extent
.height
,
517 vb_data
[2] = (struct blit_vb_data
) {
523 (float)src_offset
.x
/ (float)src
->extent
.width
,
524 (float)src_offset
.y
/ (float)src
->extent
.height
,
528 struct anv_buffer vertex_buffer
= {
531 .bo
= &device
->surface_state_block_pool
.bo
,
532 .offset
= vb_state
.offset
,
535 anv_CmdBindVertexBuffers((VkCmdBuffer
) cmd_buffer
, 0, 2,
537 (VkBuffer
) &vertex_buffer
,
538 (VkBuffer
) &vertex_buffer
542 sizeof(struct vue_header
),
547 anv_AllocDescriptorSets((VkDevice
) device
, 0 /* pool */,
548 VK_DESCRIPTOR_SET_USAGE_ONE_SHOT
,
549 1, &device
->blit_state
.ds_layout
, &set
, &count
);
550 anv_UpdateDescriptors((VkDevice
) device
, set
, 1,
553 .sType
= VK_STRUCTURE_TYPE_UPDATE_IMAGES
,
554 .descriptorType
= VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
,
557 .pImageViews
= (VkImageViewAttachInfo
[]) {
559 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_ATTACH_INFO
,
560 .view
= (VkImageView
) src
,
561 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
567 VkFramebufferCreateInfo fb_info
= {
568 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
569 .colorAttachmentCount
= 1,
570 .pColorAttachments
= (VkColorAttachmentBindInfo
[]) {
572 .view
= (VkColorAttachmentView
) dest
,
573 .layout
= VK_IMAGE_LAYOUT_GENERAL
576 .pDepthStencilAttachment
= NULL
,
578 .width
= dest
->extent
.width
,
579 .height
= dest
->extent
.height
,
583 struct anv_framebuffer
*fb
;
584 anv_CreateFramebuffer((VkDevice
) device
, &fb_info
, (VkFramebuffer
*)&fb
);
586 VkRenderPassCreateInfo pass_info
= {
587 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
588 .renderArea
= { { 0, 0 }, { dest
->extent
.width
, dest
->extent
.height
} },
589 .colorAttachmentCount
= 1,
593 .pColorFormats
= (VkFormat
[]) { dest
->format
},
594 .pColorLayouts
= (VkImageLayout
[]) { VK_IMAGE_LAYOUT_GENERAL
},
595 .pColorLoadOps
= (VkAttachmentLoadOp
[]) { VK_ATTACHMENT_LOAD_OP_LOAD
},
596 .pColorStoreOps
= (VkAttachmentStoreOp
[]) { VK_ATTACHMENT_STORE_OP_STORE
},
597 .pColorLoadClearValues
= (VkClearColor
[]) {
598 { .color
= { .floatColor
= { 1.0, 0.0, 0.0, 1.0 } }, .useRawValue
= false }
600 .depthStencilFormat
= VK_FORMAT_UNDEFINED
,
604 anv_CreateRenderPass((VkDevice
)device
, &pass_info
, &pass
);
606 anv_CmdBeginRenderPass((VkCmdBuffer
) cmd_buffer
,
607 &(VkRenderPassBegin
) {
609 .framebuffer
= (VkFramebuffer
) fb
,
612 anv_CmdBindDynamicStateObject((VkCmdBuffer
) cmd_buffer
,
613 VK_STATE_BIND_POINT_VIEWPORT
, fb
->vp_state
);
615 anv_CmdBindDescriptorSets((VkCmdBuffer
) cmd_buffer
,
616 VK_PIPELINE_BIND_POINT_GRAPHICS
, 0, 1,
619 anv_CmdDraw((VkCmdBuffer
) cmd_buffer
, 0, 3, 0, 1);
621 anv_CmdEndRenderPass((VkCmdBuffer
) cmd_buffer
, pass
);
625 meta_finish_blit(struct anv_cmd_buffer
*cmd_buffer
,
626 const struct anv_saved_state
*saved_state
)
628 anv_cmd_buffer_restore(cmd_buffer
, saved_state
);
631 void anv_CmdCopyBuffer(
632 VkCmdBuffer cmdBuffer
,
635 uint32_t regionCount
,
636 const VkBufferCopy
* pRegions
)
641 void anv_CmdCopyImage(
642 VkCmdBuffer cmdBuffer
,
644 VkImageLayout srcImageLayout
,
646 VkImageLayout destImageLayout
,
647 uint32_t regionCount
,
648 const VkImageCopy
* pRegions
)
650 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
651 VkDevice vk_device
= (VkDevice
) cmd_buffer
->device
;
652 struct anv_image
*src_image
= (struct anv_image
*)srcImage
;
653 struct anv_saved_state saved_state
;
655 meta_prepare_blit(cmd_buffer
, &saved_state
);
657 for (unsigned r
= 0; r
< regionCount
; r
++) {
658 VkImageViewCreateInfo src_view_info
= {
659 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
661 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
662 .format
= src_image
->format
,
664 VK_CHANNEL_SWIZZLE_R
,
665 VK_CHANNEL_SWIZZLE_G
,
666 VK_CHANNEL_SWIZZLE_B
,
669 .subresourceRange
= {
670 .aspect
= pRegions
[r
].srcSubresource
.aspect
,
671 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
673 .baseArraySlice
= pRegions
[r
].srcSubresource
.arraySlice
,
679 VkImageView src_view
;
680 vkCreateImageView(vk_device
, &src_view_info
, &src_view
);
682 VkColorAttachmentViewCreateInfo dest_view_info
= {
683 .sType
= VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO
,
685 .format
= src_image
->format
,
686 .mipLevel
= pRegions
[r
].destSubresource
.mipLevel
,
687 .baseArraySlice
= pRegions
[r
].destSubresource
.arraySlice
,
691 VkColorAttachmentView dest_view
;
692 vkCreateColorAttachmentView(vk_device
, &dest_view_info
, &dest_view
);
694 meta_emit_blit(cmd_buffer
,
695 (struct anv_surface_view
*)src_view
,
696 pRegions
[r
].srcOffset
,
698 (struct anv_surface_view
*)dest_view
,
699 pRegions
[r
].destOffset
,
703 meta_finish_blit(cmd_buffer
, &saved_state
);
706 void anv_CmdBlitImage(
707 VkCmdBuffer cmdBuffer
,
709 VkImageLayout srcImageLayout
,
711 VkImageLayout destImageLayout
,
712 uint32_t regionCount
,
713 const VkImageBlit
* pRegions
)
718 void anv_CmdCopyBufferToImage(
719 VkCmdBuffer cmdBuffer
,
722 VkImageLayout destImageLayout
,
723 uint32_t regionCount
,
724 const VkBufferImageCopy
* pRegions
)
729 void anv_CmdCopyImageToBuffer(
730 VkCmdBuffer cmdBuffer
,
732 VkImageLayout srcImageLayout
,
734 uint32_t regionCount
,
735 const VkBufferImageCopy
* pRegions
)
737 struct anv_cmd_buffer
*cmd_buffer
= (struct anv_cmd_buffer
*)cmdBuffer
;
738 VkDevice vk_device
= (VkDevice
) cmd_buffer
->device
;
739 struct anv_image
*src_image
= (struct anv_image
*)srcImage
;
740 struct anv_buffer
*dest_buffer
= (struct anv_buffer
*)destBuffer
;
741 struct anv_saved_state saved_state
;
743 meta_prepare_blit(cmd_buffer
, &saved_state
);
745 for (unsigned r
= 0; r
< regionCount
; r
++) {
746 VkImageViewCreateInfo src_view_info
= {
747 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
749 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
750 .format
= src_image
->format
,
752 VK_CHANNEL_SWIZZLE_R
,
753 VK_CHANNEL_SWIZZLE_G
,
754 VK_CHANNEL_SWIZZLE_B
,
757 .subresourceRange
= {
758 .aspect
= pRegions
[r
].imageSubresource
.aspect
,
759 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
761 .baseArraySlice
= pRegions
[r
].imageSubresource
.arraySlice
,
767 VkImageView src_view
;
768 anv_CreateImageView(vk_device
, &src_view_info
, &src_view
);
770 VkImageCreateInfo dest_image_info
= {
771 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
772 .imageType
= VK_IMAGE_TYPE_2D
,
773 .format
= src_image
->format
,
775 .width
= pRegions
[r
].imageExtent
.width
,
776 .height
= pRegions
[r
].imageExtent
.height
,
782 .tiling
= VK_IMAGE_TILING_LINEAR
,
783 .usage
= VK_IMAGE_USAGE_SAMPLED_BIT
,
787 struct anv_image
*dest_image
;
788 anv_CreateImage(vk_device
, &dest_image_info
, (VkImage
*)&dest_image
);
790 /* We could use a vk call to bind memory, but that would require
791 * creating a dummy memory object etc. so there's really no point.
793 dest_image
->bo
= dest_buffer
->bo
;
794 dest_image
->offset
= dest_buffer
->offset
+ pRegions
[r
].bufferOffset
;
796 VkColorAttachmentViewCreateInfo dest_view_info
= {
797 .sType
= VK_STRUCTURE_TYPE_COLOR_ATTACHMENT_VIEW_CREATE_INFO
,
798 .image
= (VkImage
)dest_image
,
799 .format
= src_image
->format
,
805 VkColorAttachmentView dest_view
;
806 anv_CreateColorAttachmentView(vk_device
, &dest_view_info
, &dest_view
);
808 meta_emit_blit(cmd_buffer
,
809 (struct anv_surface_view
*)src_view
,
810 pRegions
[r
].imageOffset
,
811 pRegions
[r
].imageExtent
,
812 (struct anv_surface_view
*)dest_view
,
813 (VkOffset3D
) { 0, 0, 0 },
814 pRegions
[r
].imageExtent
);
817 meta_finish_blit(cmd_buffer
, &saved_state
);
820 void anv_CmdCloneImageData(
821 VkCmdBuffer cmdBuffer
,
823 VkImageLayout srcImageLayout
,
825 VkImageLayout destImageLayout
)
830 void anv_CmdUpdateBuffer(
831 VkCmdBuffer cmdBuffer
,
833 VkDeviceSize destOffset
,
834 VkDeviceSize dataSize
,
835 const uint32_t* pData
)
840 void anv_CmdFillBuffer(
841 VkCmdBuffer cmdBuffer
,
843 VkDeviceSize destOffset
,
844 VkDeviceSize fillSize
,
850 void anv_CmdClearColorImage(
851 VkCmdBuffer cmdBuffer
,
853 VkImageLayout imageLayout
,
854 const VkClearColor
* color
,
856 const VkImageSubresourceRange
* pRanges
)
861 void anv_CmdClearDepthStencil(
862 VkCmdBuffer cmdBuffer
,
864 VkImageLayout imageLayout
,
868 const VkImageSubresourceRange
* pRanges
)
873 void anv_CmdResolveImage(
874 VkCmdBuffer cmdBuffer
,
876 VkImageLayout srcImageLayout
,
878 VkImageLayout destImageLayout
,
879 uint32_t regionCount
,
880 const VkImageResolve
* pRegions
)
886 anv_device_init_meta(struct anv_device
*device
)
888 anv_device_init_meta_clear_state(device
);
889 anv_device_init_meta_blit_state(device
);