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
25 #include "nir/nir_builder.h"
28 VkOffset3D src_offset
;
29 VkExtent3D src_extent
;
30 VkOffset3D dest_offset
;
31 VkExtent3D dest_extent
;
35 build_nir_vertex_shader(void)
39 const struct glsl_type
*vertex_type
= glsl_vec4_type();
41 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_VERTEX
, NULL
);
42 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "meta_blit_vs");
44 nir_variable
*pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
45 vertex_type
, "a_pos");
46 pos_in
->data
.location
= VERT_ATTRIB_GENERIC0
;
47 nir_variable
*pos_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
48 vertex_type
, "gl_Position");
49 pos_out
->data
.location
= VARYING_SLOT_POS
;
50 nir_copy_var(&b
, pos_out
, pos_in
);
52 /* Add one more pass-through attribute. For clear shaders, this is used
53 * to store the color and for blit shaders it's the texture coordinate.
55 const struct glsl_type
*attr_type
= glsl_vec4_type();
56 nir_variable
*attr_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
58 attr_in
->data
.location
= VERT_ATTRIB_GENERIC1
;
59 nir_variable
*attr_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
61 attr_out
->data
.location
= VARYING_SLOT_VAR0
;
62 attr_out
->data
.interpolation
= INTERP_QUALIFIER_SMOOTH
;
63 nir_copy_var(&b
, attr_out
, attr_in
);
69 build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim
)
73 nir_builder_init_simple_shader(&b
, NULL
, MESA_SHADER_FRAGMENT
, NULL
);
74 b
.shader
->info
.name
= ralloc_strdup(b
.shader
, "meta_blit_fs");
76 const struct glsl_type
*color_type
= glsl_vec4_type();
78 nir_variable
*tex_pos_in
= nir_variable_create(b
.shader
, nir_var_shader_in
,
79 glsl_vec4_type(), "v_attr");
80 tex_pos_in
->data
.location
= VARYING_SLOT_VAR0
;
82 /* Swizzle the array index which comes in as Z coordinate into the right
85 unsigned swz
[] = { 0, (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 1), 2 };
86 nir_ssa_def
*const tex_pos
=
87 nir_swizzle(&b
, nir_load_var(&b
, tex_pos_in
), swz
,
88 (tex_dim
== GLSL_SAMPLER_DIM_1D
? 2 : 3), false);
90 const struct glsl_type
*sampler_type
=
91 glsl_sampler_type(tex_dim
, false, tex_dim
!= GLSL_SAMPLER_DIM_3D
,
92 glsl_get_base_type(color_type
));
93 nir_variable
*sampler
= nir_variable_create(b
.shader
, nir_var_uniform
,
94 sampler_type
, "s_tex");
95 sampler
->data
.descriptor_set
= 0;
96 sampler
->data
.binding
= 0;
98 nir_tex_instr
*tex
= nir_tex_instr_create(b
.shader
, 1);
99 tex
->sampler_dim
= tex_dim
;
100 tex
->op
= nir_texop_tex
;
101 tex
->src
[0].src_type
= nir_tex_src_coord
;
102 tex
->src
[0].src
= nir_src_for_ssa(tex_pos
);
103 tex
->dest_type
= nir_type_float
; /* TODO */
104 tex
->is_array
= glsl_sampler_type_is_array(sampler_type
);
105 tex
->coord_components
= tex_pos
->num_components
;
106 tex
->texture
= nir_deref_var_create(tex
, sampler
);
107 tex
->sampler
= nir_deref_var_create(tex
, sampler
);
109 nir_ssa_dest_init(&tex
->instr
, &tex
->dest
, 4, "tex");
110 nir_builder_instr_insert(&b
, &tex
->instr
);
112 nir_variable
*color_out
= nir_variable_create(b
.shader
, nir_var_shader_out
,
113 color_type
, "f_color");
114 color_out
->data
.location
= FRAG_RESULT_DATA0
;
115 nir_store_var(&b
, color_out
, &tex
->dest
.ssa
, 4);
121 meta_prepare_blit(struct anv_cmd_buffer
*cmd_buffer
,
122 struct anv_meta_saved_state
*saved_state
)
124 anv_meta_save(saved_state
, cmd_buffer
,
125 (1 << VK_DYNAMIC_STATE_VIEWPORT
));
128 /* Returns the user-provided VkBufferImageCopy::imageOffset in units of
129 * elements rather than texels. One element equals one texel or one block
130 * if Image is uncompressed or compressed, respectively.
132 static struct VkOffset3D
133 meta_region_offset_el(const struct anv_image
* image
,
134 const struct VkOffset3D
* offset
)
136 const struct isl_format_layout
* isl_layout
= image
->format
->isl_layout
;
137 return (VkOffset3D
) {
138 .x
= offset
->x
/ isl_layout
->bw
,
139 .y
= offset
->y
/ isl_layout
->bh
,
140 .z
= offset
->z
/ isl_layout
->bd
,
144 /* Returns the user-provided VkBufferImageCopy::imageExtent in units of
145 * elements rather than texels. One element equals one texel or one block
146 * if Image is uncompressed or compressed, respectively.
148 static struct VkExtent3D
149 meta_region_extent_el(const VkFormat format
,
150 const struct VkExtent3D
* extent
)
152 const struct isl_format_layout
* isl_layout
=
153 anv_format_for_vk_format(format
)->isl_layout
;
154 return (VkExtent3D
) {
155 .width
= DIV_ROUND_UP(extent
->width
, isl_layout
->bw
),
156 .height
= DIV_ROUND_UP(extent
->height
, isl_layout
->bh
),
157 .depth
= DIV_ROUND_UP(extent
->depth
, isl_layout
->bd
),
162 meta_emit_blit(struct anv_cmd_buffer
*cmd_buffer
,
163 struct anv_image
*src_image
,
164 struct anv_image_view
*src_iview
,
165 VkOffset3D src_offset
,
166 VkExtent3D src_extent
,
167 struct anv_image
*dest_image
,
168 struct anv_image_view
*dest_iview
,
169 VkOffset3D dest_offset
,
170 VkExtent3D dest_extent
,
171 VkFilter blit_filter
)
173 struct anv_device
*device
= cmd_buffer
->device
;
174 VkDescriptorPool dummy_desc_pool
= (VkDescriptorPool
)1;
176 struct blit_vb_data
{
181 assert(src_image
->samples
== dest_image
->samples
);
183 unsigned vb_size
= sizeof(struct anv_vue_header
) + 3 * sizeof(*vb_data
);
185 struct anv_state vb_state
=
186 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, vb_size
, 16);
187 memset(vb_state
.map
, 0, sizeof(struct anv_vue_header
));
188 vb_data
= vb_state
.map
+ sizeof(struct anv_vue_header
);
190 vb_data
[0] = (struct blit_vb_data
) {
192 dest_offset
.x
+ dest_extent
.width
,
193 dest_offset
.y
+ dest_extent
.height
,
196 (float)(src_offset
.x
+ src_extent
.width
) / (float)src_iview
->extent
.width
,
197 (float)(src_offset
.y
+ src_extent
.height
) / (float)src_iview
->extent
.height
,
198 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
202 vb_data
[1] = (struct blit_vb_data
) {
205 dest_offset
.y
+ dest_extent
.height
,
208 (float)src_offset
.x
/ (float)src_iview
->extent
.width
,
209 (float)(src_offset
.y
+ src_extent
.height
) / (float)src_iview
->extent
.height
,
210 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
214 vb_data
[2] = (struct blit_vb_data
) {
220 (float)src_offset
.x
/ (float)src_iview
->extent
.width
,
221 (float)src_offset
.y
/ (float)src_iview
->extent
.height
,
222 (float)src_offset
.z
/ (float)src_iview
->extent
.depth
,
226 anv_state_clflush(vb_state
);
228 struct anv_buffer vertex_buffer
= {
231 .bo
= &device
->dynamic_state_block_pool
.bo
,
232 .offset
= vb_state
.offset
,
235 anv_CmdBindVertexBuffers(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 2,
237 anv_buffer_to_handle(&vertex_buffer
),
238 anv_buffer_to_handle(&vertex_buffer
)
242 sizeof(struct anv_vue_header
),
246 ANV_CALL(CreateSampler
)(anv_device_to_handle(device
),
247 &(VkSamplerCreateInfo
) {
248 .sType
= VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
,
249 .magFilter
= blit_filter
,
250 .minFilter
= blit_filter
,
251 }, &cmd_buffer
->pool
->alloc
, &sampler
);
254 anv_AllocateDescriptorSets(anv_device_to_handle(device
),
255 &(VkDescriptorSetAllocateInfo
) {
256 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO
,
257 .descriptorPool
= dummy_desc_pool
,
258 .descriptorSetCount
= 1,
259 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
261 anv_UpdateDescriptorSets(anv_device_to_handle(device
),
263 (VkWriteDescriptorSet
[]) {
265 .sType
= VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET
,
268 .dstArrayElement
= 0,
269 .descriptorCount
= 1,
270 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
271 .pImageInfo
= (VkDescriptorImageInfo
[]) {
274 .imageView
= anv_image_view_to_handle(src_iview
),
275 .imageLayout
= VK_IMAGE_LAYOUT_GENERAL
,
282 anv_CreateFramebuffer(anv_device_to_handle(device
),
283 &(VkFramebufferCreateInfo
) {
284 .sType
= VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
,
285 .attachmentCount
= 1,
286 .pAttachments
= (VkImageView
[]) {
287 anv_image_view_to_handle(dest_iview
),
289 .width
= dest_iview
->extent
.width
,
290 .height
= dest_iview
->extent
.height
,
292 }, &cmd_buffer
->pool
->alloc
, &fb
);
294 ANV_CALL(CmdBeginRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
),
295 &(VkRenderPassBeginInfo
) {
296 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO
,
297 .renderPass
= device
->meta_state
.blit
.render_pass
,
300 .offset
= { dest_offset
.x
, dest_offset
.y
},
301 .extent
= { dest_extent
.width
, dest_extent
.height
},
303 .clearValueCount
= 0,
304 .pClearValues
= NULL
,
305 }, VK_SUBPASS_CONTENTS_INLINE
);
309 switch (src_image
->type
) {
310 case VK_IMAGE_TYPE_1D
:
311 pipeline
= device
->meta_state
.blit
.pipeline_1d_src
;
313 case VK_IMAGE_TYPE_2D
:
314 pipeline
= device
->meta_state
.blit
.pipeline_2d_src
;
316 case VK_IMAGE_TYPE_3D
:
317 pipeline
= device
->meta_state
.blit
.pipeline_3d_src
;
320 unreachable(!"bad VkImageType");
323 if (cmd_buffer
->state
.pipeline
!= anv_pipeline_from_handle(pipeline
)) {
324 anv_CmdBindPipeline(anv_cmd_buffer_to_handle(cmd_buffer
),
325 VK_PIPELINE_BIND_POINT_GRAPHICS
, pipeline
);
328 anv_CmdSetViewport(anv_cmd_buffer_to_handle(cmd_buffer
), 0, 1,
332 .width
= dest_iview
->extent
.width
,
333 .height
= dest_iview
->extent
.height
,
338 anv_CmdBindDescriptorSets(anv_cmd_buffer_to_handle(cmd_buffer
),
339 VK_PIPELINE_BIND_POINT_GRAPHICS
,
340 device
->meta_state
.blit
.pipeline_layout
, 0, 1,
343 ANV_CALL(CmdDraw
)(anv_cmd_buffer_to_handle(cmd_buffer
), 3, 1, 0, 0);
345 ANV_CALL(CmdEndRenderPass
)(anv_cmd_buffer_to_handle(cmd_buffer
));
347 /* At the point where we emit the draw call, all data from the
348 * descriptor sets, etc. has been used. We are free to delete it.
350 anv_descriptor_set_destroy(device
, anv_descriptor_set_from_handle(set
));
351 anv_DestroySampler(anv_device_to_handle(device
), sampler
,
352 &cmd_buffer
->pool
->alloc
);
353 anv_DestroyFramebuffer(anv_device_to_handle(device
), fb
,
354 &cmd_buffer
->pool
->alloc
);
358 meta_finish_blit(struct anv_cmd_buffer
*cmd_buffer
,
359 const struct anv_meta_saved_state
*saved_state
)
361 anv_meta_restore(saved_state
, cmd_buffer
);
365 vk_format_for_size(int bs
)
367 /* Note: We intentionally use the 4-channel formats whenever we can.
368 * This is so that, when we do a RGB <-> RGBX copy, the two formats will
369 * line up even though one of them is 3/4 the size of the other.
372 case 1: return VK_FORMAT_R8_UINT
;
373 case 2: return VK_FORMAT_R8G8_UINT
;
374 case 3: return VK_FORMAT_R8G8B8_UINT
;
375 case 4: return VK_FORMAT_R8G8B8A8_UINT
;
376 case 6: return VK_FORMAT_R16G16B16_UINT
;
377 case 8: return VK_FORMAT_R16G16B16A16_UINT
;
378 case 12: return VK_FORMAT_R32G32B32_UINT
;
379 case 16: return VK_FORMAT_R32G32B32A32_UINT
;
381 unreachable("Invalid format block size");
386 do_buffer_copy(struct anv_cmd_buffer
*cmd_buffer
,
387 struct anv_bo
*src
, uint64_t src_offset
,
388 struct anv_bo
*dest
, uint64_t dest_offset
,
389 int width
, int height
, VkFormat copy_format
)
391 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
393 VkImageCreateInfo image_info
= {
394 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
395 .imageType
= VK_IMAGE_TYPE_2D
,
396 .format
= copy_format
,
405 .tiling
= VK_IMAGE_TILING_LINEAR
,
411 image_info
.usage
= VK_IMAGE_USAGE_SAMPLED_BIT
;
412 anv_CreateImage(vk_device
, &image_info
,
413 &cmd_buffer
->pool
->alloc
, &src_image
);
416 image_info
.usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
417 anv_CreateImage(vk_device
, &image_info
,
418 &cmd_buffer
->pool
->alloc
, &dest_image
);
420 /* We could use a vk call to bind memory, but that would require
421 * creating a dummy memory object etc. so there's really no point.
423 anv_image_from_handle(src_image
)->bo
= src
;
424 anv_image_from_handle(src_image
)->offset
= src_offset
;
425 anv_image_from_handle(dest_image
)->bo
= dest
;
426 anv_image_from_handle(dest_image
)->offset
= dest_offset
;
428 struct anv_image_view src_iview
;
429 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
430 &(VkImageViewCreateInfo
) {
431 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
433 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
434 .format
= copy_format
,
435 .subresourceRange
= {
436 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
445 struct anv_image_view dest_iview
;
446 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
447 &(VkImageViewCreateInfo
) {
448 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
450 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
451 .format
= copy_format
,
452 .subresourceRange
= {
453 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
462 meta_emit_blit(cmd_buffer
,
463 anv_image_from_handle(src_image
),
465 (VkOffset3D
) { 0, 0, 0 },
466 (VkExtent3D
) { width
, height
, 1 },
467 anv_image_from_handle(dest_image
),
469 (VkOffset3D
) { 0, 0, 0 },
470 (VkExtent3D
) { width
, height
, 1 },
473 anv_DestroyImage(vk_device
, src_image
, &cmd_buffer
->pool
->alloc
);
474 anv_DestroyImage(vk_device
, dest_image
, &cmd_buffer
->pool
->alloc
);
477 void anv_CmdCopyBuffer(
478 VkCommandBuffer commandBuffer
,
481 uint32_t regionCount
,
482 const VkBufferCopy
* pRegions
)
484 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
485 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
486 ANV_FROM_HANDLE(anv_buffer
, dest_buffer
, destBuffer
);
488 struct anv_meta_saved_state saved_state
;
490 meta_prepare_blit(cmd_buffer
, &saved_state
);
492 for (unsigned r
= 0; r
< regionCount
; r
++) {
493 uint64_t src_offset
= src_buffer
->offset
+ pRegions
[r
].srcOffset
;
494 uint64_t dest_offset
= dest_buffer
->offset
+ pRegions
[r
].dstOffset
;
495 uint64_t copy_size
= pRegions
[r
].size
;
497 /* First, we compute the biggest format that can be used with the
498 * given offsets and size.
502 int fs
= ffs(src_offset
) - 1;
504 bs
= MIN2(bs
, 1 << fs
);
505 assert(src_offset
% bs
== 0);
507 fs
= ffs(dest_offset
) - 1;
509 bs
= MIN2(bs
, 1 << fs
);
510 assert(dest_offset
% bs
== 0);
512 fs
= ffs(pRegions
[r
].size
) - 1;
514 bs
= MIN2(bs
, 1 << fs
);
515 assert(pRegions
[r
].size
% bs
== 0);
517 VkFormat copy_format
= vk_format_for_size(bs
);
519 /* This is maximum possible width/height our HW can handle */
520 uint64_t max_surface_dim
= 1 << 14;
522 /* First, we make a bunch of max-sized copies */
523 uint64_t max_copy_size
= max_surface_dim
* max_surface_dim
* bs
;
524 while (copy_size
>= max_copy_size
) {
525 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
526 dest_buffer
->bo
, dest_offset
,
527 max_surface_dim
, max_surface_dim
, copy_format
);
528 copy_size
-= max_copy_size
;
529 src_offset
+= max_copy_size
;
530 dest_offset
+= max_copy_size
;
533 uint64_t height
= copy_size
/ (max_surface_dim
* bs
);
534 assert(height
< max_surface_dim
);
536 uint64_t rect_copy_size
= height
* max_surface_dim
* bs
;
537 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
538 dest_buffer
->bo
, dest_offset
,
539 max_surface_dim
, height
, copy_format
);
540 copy_size
-= rect_copy_size
;
541 src_offset
+= rect_copy_size
;
542 dest_offset
+= rect_copy_size
;
545 if (copy_size
!= 0) {
546 do_buffer_copy(cmd_buffer
, src_buffer
->bo
, src_offset
,
547 dest_buffer
->bo
, dest_offset
,
548 copy_size
/ bs
, 1, copy_format
);
552 meta_finish_blit(cmd_buffer
, &saved_state
);
555 void anv_CmdUpdateBuffer(
556 VkCommandBuffer commandBuffer
,
558 VkDeviceSize dstOffset
,
559 VkDeviceSize dataSize
,
560 const uint32_t* pData
)
562 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
563 ANV_FROM_HANDLE(anv_buffer
, dst_buffer
, dstBuffer
);
564 struct anv_meta_saved_state saved_state
;
566 meta_prepare_blit(cmd_buffer
, &saved_state
);
568 /* We can't quite grab a full block because the state stream needs a
569 * little data at the top to build its linked list.
571 const uint32_t max_update_size
=
572 cmd_buffer
->device
->dynamic_state_block_pool
.block_size
- 64;
574 assert(max_update_size
< (1 << 14) * 4);
577 const uint32_t copy_size
= MIN2(dataSize
, max_update_size
);
579 struct anv_state tmp_data
=
580 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, copy_size
, 64);
582 memcpy(tmp_data
.map
, pData
, copy_size
);
586 if ((copy_size
& 15) == 0 && (dstOffset
& 15) == 0) {
587 format
= VK_FORMAT_R32G32B32A32_UINT
;
589 } else if ((copy_size
& 7) == 0 && (dstOffset
& 7) == 0) {
590 format
= VK_FORMAT_R32G32_UINT
;
593 assert((copy_size
& 3) == 0 && (dstOffset
& 3) == 0);
594 format
= VK_FORMAT_R32_UINT
;
598 do_buffer_copy(cmd_buffer
,
599 &cmd_buffer
->device
->dynamic_state_block_pool
.bo
,
601 dst_buffer
->bo
, dst_buffer
->offset
+ dstOffset
,
602 copy_size
/ bs
, 1, format
);
604 dataSize
-= copy_size
;
605 dstOffset
+= copy_size
;
606 pData
= (void *)pData
+ copy_size
;
611 choose_iview_format(struct anv_image
*image
, VkImageAspectFlagBits aspect
)
613 assert(__builtin_popcount(aspect
) == 1);
615 struct isl_surf
*surf
=
616 &anv_image_get_surface_for_aspect_mask(image
, aspect
)->isl
;
618 /* vkCmdCopyImage behaves like memcpy. Therefore we choose identical UINT
619 * formats for the source and destination image views.
621 * From the Vulkan spec (2015-12-30):
623 * vkCmdCopyImage performs image copies in a similar manner to a host
624 * memcpy. It does not perform general-purpose conversions such as
625 * scaling, resizing, blending, color-space conversion, or format
626 * conversions. Rather, it simply copies raw image data. vkCmdCopyImage
627 * can copy between images with different formats, provided the formats
628 * are compatible as defined below.
630 * [The spec later defines compatibility as having the same number of
633 return vk_format_for_size(isl_format_layouts
[surf
->format
].bs
);
637 choose_buffer_format(VkFormat format
, VkImageAspectFlagBits aspect
)
639 assert(__builtin_popcount(aspect
) == 1);
641 /* vkCmdCopy* commands behave like memcpy. Therefore we choose
642 * compatable UINT formats for the source and destination image views.
644 * For the buffer, we go back to the original image format and get a
645 * the format as if it were linear. This way, for RGB formats, we get
646 * an RGB format here even if the tiled image is RGBA. XXX: This doesn't
647 * work if the buffer is the destination.
649 enum isl_format linear_format
= anv_get_isl_format(format
, aspect
,
650 VK_IMAGE_TILING_LINEAR
,
653 return vk_format_for_size(isl_format_layouts
[linear_format
].bs
);
656 void anv_CmdCopyImage(
657 VkCommandBuffer commandBuffer
,
659 VkImageLayout srcImageLayout
,
661 VkImageLayout destImageLayout
,
662 uint32_t regionCount
,
663 const VkImageCopy
* pRegions
)
665 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
666 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
667 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
668 struct anv_meta_saved_state saved_state
;
670 /* From the Vulkan 1.0 spec:
672 * vkCmdCopyImage can be used to copy image data between multisample
673 * images, but both images must have the same number of samples.
675 assert(src_image
->samples
== dest_image
->samples
);
677 meta_prepare_blit(cmd_buffer
, &saved_state
);
679 for (unsigned r
= 0; r
< regionCount
; r
++) {
680 assert(pRegions
[r
].srcSubresource
.aspectMask
==
681 pRegions
[r
].dstSubresource
.aspectMask
);
683 VkImageAspectFlags aspect
= pRegions
[r
].srcSubresource
.aspectMask
;
685 VkFormat src_format
= choose_iview_format(src_image
, aspect
);
686 VkFormat dst_format
= choose_iview_format(dest_image
, aspect
);
688 struct anv_image_view src_iview
;
689 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
690 &(VkImageViewCreateInfo
) {
691 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
693 .viewType
= anv_meta_get_view_type(src_image
),
694 .format
= src_format
,
695 .subresourceRange
= {
696 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
697 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
699 .baseArrayLayer
= pRegions
[r
].srcSubresource
.baseArrayLayer
,
700 .layerCount
= pRegions
[r
].dstSubresource
.layerCount
,
705 const VkOffset3D dest_offset
= {
706 .x
= pRegions
[r
].dstOffset
.x
,
707 .y
= pRegions
[r
].dstOffset
.y
,
712 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
713 assert(pRegions
[r
].srcSubresource
.layerCount
== 1 &&
714 pRegions
[r
].dstSubresource
.layerCount
== 1);
715 num_slices
= pRegions
[r
].extent
.depth
;
717 assert(pRegions
[r
].srcSubresource
.layerCount
==
718 pRegions
[r
].dstSubresource
.layerCount
);
719 assert(pRegions
[r
].extent
.depth
== 1);
720 num_slices
= pRegions
[r
].dstSubresource
.layerCount
;
723 const uint32_t dest_base_array_slice
=
724 anv_meta_get_iview_layer(dest_image
, &pRegions
[r
].dstSubresource
,
725 &pRegions
[r
].dstOffset
);
727 for (unsigned slice
= 0; slice
< num_slices
; slice
++) {
728 VkOffset3D src_offset
= pRegions
[r
].srcOffset
;
729 src_offset
.z
+= slice
;
731 struct anv_image_view dest_iview
;
732 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
733 &(VkImageViewCreateInfo
) {
734 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
736 .viewType
= anv_meta_get_view_type(dest_image
),
737 .format
= dst_format
,
738 .subresourceRange
= {
739 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
740 .baseMipLevel
= pRegions
[r
].dstSubresource
.mipLevel
,
742 .baseArrayLayer
= dest_base_array_slice
+ slice
,
748 meta_emit_blit(cmd_buffer
,
749 src_image
, &src_iview
,
752 dest_image
, &dest_iview
,
759 meta_finish_blit(cmd_buffer
, &saved_state
);
762 void anv_CmdBlitImage(
763 VkCommandBuffer commandBuffer
,
765 VkImageLayout srcImageLayout
,
767 VkImageLayout destImageLayout
,
768 uint32_t regionCount
,
769 const VkImageBlit
* pRegions
,
773 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
774 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
775 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
776 struct anv_meta_saved_state saved_state
;
778 /* From the Vulkan 1.0 spec:
780 * vkCmdBlitImage must not be used for multisampled source or
781 * destination images. Use vkCmdResolveImage for this purpose.
783 assert(src_image
->samples
== 1);
784 assert(dest_image
->samples
== 1);
786 anv_finishme("respect VkFilter");
788 meta_prepare_blit(cmd_buffer
, &saved_state
);
790 for (unsigned r
= 0; r
< regionCount
; r
++) {
791 struct anv_image_view src_iview
;
792 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
793 &(VkImageViewCreateInfo
) {
794 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
796 .viewType
= anv_meta_get_view_type(src_image
),
797 .format
= src_image
->vk_format
,
798 .subresourceRange
= {
799 .aspectMask
= pRegions
[r
].srcSubresource
.aspectMask
,
800 .baseMipLevel
= pRegions
[r
].srcSubresource
.mipLevel
,
802 .baseArrayLayer
= pRegions
[r
].srcSubresource
.baseArrayLayer
,
808 const VkOffset3D dest_offset
= {
809 .x
= pRegions
[r
].dstOffsets
[0].x
,
810 .y
= pRegions
[r
].dstOffsets
[0].y
,
814 if (pRegions
[r
].dstOffsets
[1].x
< pRegions
[r
].dstOffsets
[0].x
||
815 pRegions
[r
].dstOffsets
[1].y
< pRegions
[r
].dstOffsets
[0].y
||
816 pRegions
[r
].srcOffsets
[1].x
< pRegions
[r
].srcOffsets
[0].x
||
817 pRegions
[r
].srcOffsets
[1].y
< pRegions
[r
].srcOffsets
[0].y
)
818 anv_finishme("FINISHME: Allow flipping in blits");
820 const VkExtent3D dest_extent
= {
821 .width
= pRegions
[r
].dstOffsets
[1].x
- pRegions
[r
].dstOffsets
[0].x
,
822 .height
= pRegions
[r
].dstOffsets
[1].y
- pRegions
[r
].dstOffsets
[0].y
,
825 const VkExtent3D src_extent
= {
826 .width
= pRegions
[r
].srcOffsets
[1].x
- pRegions
[r
].srcOffsets
[0].x
,
827 .height
= pRegions
[r
].srcOffsets
[1].y
- pRegions
[r
].srcOffsets
[0].y
,
830 const uint32_t dest_array_slice
=
831 anv_meta_get_iview_layer(dest_image
, &pRegions
[r
].dstSubresource
,
832 &pRegions
[r
].dstOffsets
[0]);
834 if (pRegions
[r
].srcSubresource
.layerCount
> 1)
835 anv_finishme("FINISHME: copy multiple array layers");
837 if (pRegions
[r
].srcOffsets
[0].z
+ 1 != pRegions
[r
].srcOffsets
[1].z
||
838 pRegions
[r
].dstOffsets
[0].z
+ 1 != pRegions
[r
].dstOffsets
[1].z
)
839 anv_finishme("FINISHME: copy multiple depth layers");
841 struct anv_image_view dest_iview
;
842 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
843 &(VkImageViewCreateInfo
) {
844 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
846 .viewType
= anv_meta_get_view_type(dest_image
),
847 .format
= dest_image
->vk_format
,
848 .subresourceRange
= {
849 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
850 .baseMipLevel
= pRegions
[r
].dstSubresource
.mipLevel
,
852 .baseArrayLayer
= dest_array_slice
,
858 meta_emit_blit(cmd_buffer
,
859 src_image
, &src_iview
,
860 pRegions
[r
].srcOffsets
[0], src_extent
,
861 dest_image
, &dest_iview
,
862 dest_offset
, dest_extent
,
866 meta_finish_blit(cmd_buffer
, &saved_state
);
869 static struct anv_image
*
870 make_image_for_buffer(VkDevice vk_device
, VkBuffer vk_buffer
, VkFormat format
,
871 VkImageUsageFlags usage
,
872 VkImageType image_type
,
873 const VkAllocationCallbacks
*alloc
,
874 const VkBufferImageCopy
*copy
)
876 ANV_FROM_HANDLE(anv_buffer
, buffer
, vk_buffer
);
878 VkExtent3D extent
= copy
->imageExtent
;
879 if (copy
->bufferRowLength
)
880 extent
.width
= copy
->bufferRowLength
;
881 if (copy
->bufferImageHeight
)
882 extent
.height
= copy
->bufferImageHeight
;
884 extent
= meta_region_extent_el(format
, &extent
);
886 VkImageAspectFlags aspect
= copy
->imageSubresource
.aspectMask
;
887 VkFormat buffer_format
= choose_buffer_format(format
, aspect
);
890 VkResult result
= anv_CreateImage(vk_device
,
891 &(VkImageCreateInfo
) {
892 .sType
= VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO
,
893 .imageType
= VK_IMAGE_TYPE_2D
,
894 .format
= buffer_format
,
899 .tiling
= VK_IMAGE_TILING_LINEAR
,
902 }, alloc
, &vk_image
);
903 assert(result
== VK_SUCCESS
);
905 ANV_FROM_HANDLE(anv_image
, image
, vk_image
);
907 /* We could use a vk call to bind memory, but that would require
908 * creating a dummy memory object etc. so there's really no point.
910 image
->bo
= buffer
->bo
;
911 image
->offset
= buffer
->offset
+ copy
->bufferOffset
;
916 void anv_CmdCopyBufferToImage(
917 VkCommandBuffer commandBuffer
,
920 VkImageLayout destImageLayout
,
921 uint32_t regionCount
,
922 const VkBufferImageCopy
* pRegions
)
924 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
925 ANV_FROM_HANDLE(anv_image
, dest_image
, destImage
);
926 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
927 struct anv_meta_saved_state saved_state
;
929 /* The Vulkan 1.0 spec says "dstImage must have a sample count equal to
930 * VK_SAMPLE_COUNT_1_BIT."
932 assert(dest_image
->samples
== 1);
934 meta_prepare_blit(cmd_buffer
, &saved_state
);
936 for (unsigned r
= 0; r
< regionCount
; r
++) {
937 VkImageAspectFlags aspect
= pRegions
[r
].imageSubresource
.aspectMask
;
939 VkFormat image_format
= choose_iview_format(dest_image
, aspect
);
941 struct anv_image
*src_image
=
942 make_image_for_buffer(vk_device
, srcBuffer
, dest_image
->vk_format
,
943 VK_IMAGE_USAGE_SAMPLED_BIT
,
944 dest_image
->type
, &cmd_buffer
->pool
->alloc
,
947 const uint32_t dest_base_array_slice
=
948 anv_meta_get_iview_layer(dest_image
, &pRegions
[r
].imageSubresource
,
949 &pRegions
[r
].imageOffset
);
951 unsigned num_slices_3d
= pRegions
[r
].imageExtent
.depth
;
952 unsigned num_slices_array
= pRegions
[r
].imageSubresource
.layerCount
;
953 unsigned slice_3d
= 0;
954 unsigned slice_array
= 0;
955 while (slice_3d
< num_slices_3d
&& slice_array
< num_slices_array
) {
956 struct anv_image_view src_iview
;
957 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
958 &(VkImageViewCreateInfo
) {
959 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
960 .image
= anv_image_to_handle(src_image
),
961 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
962 .format
= src_image
->vk_format
,
963 .subresourceRange
= {
964 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
976 if (isl_format_is_compressed(dest_image
->format
->isl_format
))
977 isl_surf_get_image_intratile_offset_el(&cmd_buffer
->device
->isl_dev
,
978 &dest_image
->color_surface
.isl
,
979 pRegions
[r
].imageSubresource
.mipLevel
,
980 pRegions
[r
].imageSubresource
.baseArrayLayer
+ slice_array
,
981 pRegions
[r
].imageOffset
.z
+ slice_3d
,
982 &img_o
, &img_x
, &img_y
);
984 VkOffset3D dest_offset_el
= meta_region_offset_el(dest_image
, & pRegions
[r
].imageOffset
);
985 dest_offset_el
.x
+= img_x
;
986 dest_offset_el
.y
+= img_y
;
987 dest_offset_el
.z
= 0;
989 struct anv_image_view dest_iview
;
990 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
991 &(VkImageViewCreateInfo
) {
992 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
993 .image
= anv_image_to_handle(dest_image
),
994 .viewType
= anv_meta_get_view_type(dest_image
),
995 .format
= image_format
,
996 .subresourceRange
= {
997 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
998 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1000 .baseArrayLayer
= dest_base_array_slice
+
1001 slice_array
+ slice_3d
,
1007 const VkExtent3D img_extent_el
= meta_region_extent_el(dest_image
->vk_format
,
1008 &pRegions
[r
].imageExtent
);
1010 meta_emit_blit(cmd_buffer
,
1013 (VkOffset3D
){0, 0, 0},
1021 /* Once we've done the blit, all of the actual information about
1022 * the image is embedded in the command buffer so we can just
1023 * increment the offset directly in the image effectively
1024 * re-binding it to different backing memory.
1026 src_image
->offset
+= src_image
->extent
.width
*
1027 src_image
->extent
.height
*
1028 src_image
->format
->isl_layout
->bs
;
1030 if (dest_image
->type
== VK_IMAGE_TYPE_3D
)
1036 anv_DestroyImage(vk_device
, anv_image_to_handle(src_image
),
1037 &cmd_buffer
->pool
->alloc
);
1040 meta_finish_blit(cmd_buffer
, &saved_state
);
1043 void anv_CmdCopyImageToBuffer(
1044 VkCommandBuffer commandBuffer
,
1046 VkImageLayout srcImageLayout
,
1047 VkBuffer destBuffer
,
1048 uint32_t regionCount
,
1049 const VkBufferImageCopy
* pRegions
)
1051 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1052 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1053 VkDevice vk_device
= anv_device_to_handle(cmd_buffer
->device
);
1054 struct anv_meta_saved_state saved_state
;
1057 /* The Vulkan 1.0 spec says "srcImage must have a sample count equal to
1058 * VK_SAMPLE_COUNT_1_BIT."
1060 assert(src_image
->samples
== 1);
1062 meta_prepare_blit(cmd_buffer
, &saved_state
);
1064 for (unsigned r
= 0; r
< regionCount
; r
++) {
1065 VkImageAspectFlags aspect
= pRegions
[r
].imageSubresource
.aspectMask
;
1067 VkFormat image_format
= choose_iview_format(src_image
, aspect
);
1069 struct anv_image_view src_iview
;
1070 anv_image_view_init(&src_iview
, cmd_buffer
->device
,
1071 &(VkImageViewCreateInfo
) {
1072 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1074 .viewType
= anv_meta_get_view_type(src_image
),
1075 .format
= image_format
,
1076 .subresourceRange
= {
1077 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
1078 .baseMipLevel
= pRegions
[r
].imageSubresource
.mipLevel
,
1080 .baseArrayLayer
= pRegions
[r
].imageSubresource
.baseArrayLayer
,
1081 .layerCount
= pRegions
[r
].imageSubresource
.layerCount
,
1086 struct anv_image
*dest_image
=
1087 make_image_for_buffer(vk_device
, destBuffer
, src_image
->vk_format
,
1088 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
,
1089 src_image
->type
, &cmd_buffer
->pool
->alloc
,
1092 unsigned num_slices
;
1093 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
1094 assert(pRegions
[r
].imageSubresource
.layerCount
== 1);
1095 num_slices
= pRegions
[r
].imageExtent
.depth
;
1097 assert(pRegions
[r
].imageExtent
.depth
== 1);
1098 num_slices
= pRegions
[r
].imageSubresource
.layerCount
;
1101 for (unsigned slice
= 0; slice
< num_slices
; slice
++) {
1102 VkOffset3D src_offset
= pRegions
[r
].imageOffset
;
1103 src_offset
.z
+= slice
;
1105 struct anv_image_view dest_iview
;
1106 anv_image_view_init(&dest_iview
, cmd_buffer
->device
,
1107 &(VkImageViewCreateInfo
) {
1108 .sType
= VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
,
1109 .image
= anv_image_to_handle(dest_image
),
1110 .viewType
= VK_IMAGE_VIEW_TYPE_2D
,
1111 .format
= dest_image
->vk_format
,
1112 .subresourceRange
= {
1113 .aspectMask
= VK_IMAGE_ASPECT_COLOR_BIT
,
1116 .baseArrayLayer
= 0,
1122 meta_emit_blit(cmd_buffer
,
1123 anv_image_from_handle(srcImage
),
1126 pRegions
[r
].imageExtent
,
1129 (VkOffset3D
) { 0, 0, 0 },
1130 pRegions
[r
].imageExtent
,
1133 /* Once we've done the blit, all of the actual information about
1134 * the image is embedded in the command buffer so we can just
1135 * increment the offset directly in the image effectively
1136 * re-binding it to different backing memory.
1138 dest_image
->offset
+= dest_image
->extent
.width
*
1139 dest_image
->extent
.height
*
1140 src_image
->format
->isl_layout
->bs
;
1143 anv_DestroyImage(vk_device
, anv_image_to_handle(dest_image
),
1144 &cmd_buffer
->pool
->alloc
);
1147 meta_finish_blit(cmd_buffer
, &saved_state
);
1151 anv_device_finish_meta_blit_state(struct anv_device
*device
)
1153 anv_DestroyRenderPass(anv_device_to_handle(device
),
1154 device
->meta_state
.blit
.render_pass
,
1155 &device
->meta_state
.alloc
);
1156 anv_DestroyPipeline(anv_device_to_handle(device
),
1157 device
->meta_state
.blit
.pipeline_1d_src
,
1158 &device
->meta_state
.alloc
);
1159 anv_DestroyPipeline(anv_device_to_handle(device
),
1160 device
->meta_state
.blit
.pipeline_2d_src
,
1161 &device
->meta_state
.alloc
);
1162 anv_DestroyPipeline(anv_device_to_handle(device
),
1163 device
->meta_state
.blit
.pipeline_3d_src
,
1164 &device
->meta_state
.alloc
);
1165 anv_DestroyPipelineLayout(anv_device_to_handle(device
),
1166 device
->meta_state
.blit
.pipeline_layout
,
1167 &device
->meta_state
.alloc
);
1168 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device
),
1169 device
->meta_state
.blit
.ds_layout
,
1170 &device
->meta_state
.alloc
);
1174 anv_device_init_meta_blit_state(struct anv_device
*device
)
1178 result
= anv_CreateRenderPass(anv_device_to_handle(device
),
1179 &(VkRenderPassCreateInfo
) {
1180 .sType
= VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO
,
1181 .attachmentCount
= 1,
1182 .pAttachments
= &(VkAttachmentDescription
) {
1183 .format
= VK_FORMAT_UNDEFINED
, /* Our shaders don't care */
1184 .loadOp
= VK_ATTACHMENT_LOAD_OP_LOAD
,
1185 .storeOp
= VK_ATTACHMENT_STORE_OP_STORE
,
1186 .initialLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1187 .finalLayout
= VK_IMAGE_LAYOUT_GENERAL
,
1190 .pSubpasses
= &(VkSubpassDescription
) {
1191 .pipelineBindPoint
= VK_PIPELINE_BIND_POINT_GRAPHICS
,
1192 .inputAttachmentCount
= 0,
1193 .colorAttachmentCount
= 1,
1194 .pColorAttachments
= &(VkAttachmentReference
) {
1196 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1198 .pResolveAttachments
= NULL
,
1199 .pDepthStencilAttachment
= &(VkAttachmentReference
) {
1200 .attachment
= VK_ATTACHMENT_UNUSED
,
1201 .layout
= VK_IMAGE_LAYOUT_GENERAL
,
1203 .preserveAttachmentCount
= 1,
1204 .pPreserveAttachments
= (uint32_t[]) { 0 },
1206 .dependencyCount
= 0,
1207 }, &device
->meta_state
.alloc
, &device
->meta_state
.blit
.render_pass
);
1208 if (result
!= VK_SUCCESS
)
1211 /* We don't use a vertex shader for clearing, but instead build and pass
1212 * the VUEs directly to the rasterization backend. However, we do need
1213 * to provide GLSL source for the vertex shader so that the compiler
1214 * does not dead-code our inputs.
1216 struct anv_shader_module vs
= {
1217 .nir
= build_nir_vertex_shader(),
1220 struct anv_shader_module fs_1d
= {
1221 .nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_1D
),
1224 struct anv_shader_module fs_2d
= {
1225 .nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_2D
),
1228 struct anv_shader_module fs_3d
= {
1229 .nir
= build_nir_copy_fragment_shader(GLSL_SAMPLER_DIM_3D
),
1232 VkPipelineVertexInputStateCreateInfo vi_create_info
= {
1233 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO
,
1234 .vertexBindingDescriptionCount
= 2,
1235 .pVertexBindingDescriptions
= (VkVertexInputBindingDescription
[]) {
1239 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
1243 .stride
= 5 * sizeof(float),
1244 .inputRate
= VK_VERTEX_INPUT_RATE_VERTEX
1247 .vertexAttributeDescriptionCount
= 3,
1248 .pVertexAttributeDescriptions
= (VkVertexInputAttributeDescription
[]) {
1253 .format
= VK_FORMAT_R32G32B32A32_UINT
,
1260 .format
= VK_FORMAT_R32G32_SFLOAT
,
1264 /* Texture Coordinate */
1267 .format
= VK_FORMAT_R32G32B32_SFLOAT
,
1273 VkDescriptorSetLayoutCreateInfo ds_layout_info
= {
1274 .sType
= VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
,
1276 .pBindings
= (VkDescriptorSetLayoutBinding
[]) {
1279 .descriptorType
= VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
,
1280 .descriptorCount
= 1,
1281 .stageFlags
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1282 .pImmutableSamplers
= NULL
1286 result
= anv_CreateDescriptorSetLayout(anv_device_to_handle(device
),
1288 &device
->meta_state
.alloc
,
1289 &device
->meta_state
.blit
.ds_layout
);
1290 if (result
!= VK_SUCCESS
)
1291 goto fail_render_pass
;
1293 result
= anv_CreatePipelineLayout(anv_device_to_handle(device
),
1294 &(VkPipelineLayoutCreateInfo
) {
1295 .sType
= VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO
,
1296 .setLayoutCount
= 1,
1297 .pSetLayouts
= &device
->meta_state
.blit
.ds_layout
,
1299 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_layout
);
1300 if (result
!= VK_SUCCESS
)
1301 goto fail_descriptor_set_layout
;
1303 VkPipelineShaderStageCreateInfo pipeline_shader_stages
[] = {
1305 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1306 .stage
= VK_SHADER_STAGE_VERTEX_BIT
,
1307 .module
= anv_shader_module_to_handle(&vs
),
1309 .pSpecializationInfo
= NULL
1311 .sType
= VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO
,
1312 .stage
= VK_SHADER_STAGE_FRAGMENT_BIT
,
1313 .module
= VK_NULL_HANDLE
, /* TEMPLATE VALUE! FILL ME IN! */
1315 .pSpecializationInfo
= NULL
1319 const VkGraphicsPipelineCreateInfo vk_pipeline_info
= {
1320 .sType
= VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
,
1321 .stageCount
= ARRAY_SIZE(pipeline_shader_stages
),
1322 .pStages
= pipeline_shader_stages
,
1323 .pVertexInputState
= &vi_create_info
,
1324 .pInputAssemblyState
= &(VkPipelineInputAssemblyStateCreateInfo
) {
1325 .sType
= VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO
,
1326 .topology
= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
,
1327 .primitiveRestartEnable
= false,
1329 .pViewportState
= &(VkPipelineViewportStateCreateInfo
) {
1330 .sType
= VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
,
1334 .pRasterizationState
= &(VkPipelineRasterizationStateCreateInfo
) {
1335 .sType
= VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO
,
1336 .rasterizerDiscardEnable
= false,
1337 .polygonMode
= VK_POLYGON_MODE_FILL
,
1338 .cullMode
= VK_CULL_MODE_NONE
,
1339 .frontFace
= VK_FRONT_FACE_COUNTER_CLOCKWISE
1341 .pMultisampleState
= &(VkPipelineMultisampleStateCreateInfo
) {
1342 .sType
= VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO
,
1343 .rasterizationSamples
= 1,
1344 .sampleShadingEnable
= false,
1345 .pSampleMask
= (VkSampleMask
[]) { UINT32_MAX
},
1347 .pColorBlendState
= &(VkPipelineColorBlendStateCreateInfo
) {
1348 .sType
= VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO
,
1349 .attachmentCount
= 1,
1350 .pAttachments
= (VkPipelineColorBlendAttachmentState
[]) {
1352 VK_COLOR_COMPONENT_A_BIT
|
1353 VK_COLOR_COMPONENT_R_BIT
|
1354 VK_COLOR_COMPONENT_G_BIT
|
1355 VK_COLOR_COMPONENT_B_BIT
},
1358 .pDynamicState
= &(VkPipelineDynamicStateCreateInfo
) {
1359 .sType
= VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO
,
1360 .dynamicStateCount
= 9,
1361 .pDynamicStates
= (VkDynamicState
[]) {
1362 VK_DYNAMIC_STATE_VIEWPORT
,
1363 VK_DYNAMIC_STATE_SCISSOR
,
1364 VK_DYNAMIC_STATE_LINE_WIDTH
,
1365 VK_DYNAMIC_STATE_DEPTH_BIAS
,
1366 VK_DYNAMIC_STATE_BLEND_CONSTANTS
,
1367 VK_DYNAMIC_STATE_DEPTH_BOUNDS
,
1368 VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK
,
1369 VK_DYNAMIC_STATE_STENCIL_WRITE_MASK
,
1370 VK_DYNAMIC_STATE_STENCIL_REFERENCE
,
1374 .layout
= device
->meta_state
.blit
.pipeline_layout
,
1375 .renderPass
= device
->meta_state
.blit
.render_pass
,
1379 const struct anv_graphics_pipeline_create_info anv_pipeline_info
= {
1380 .color_attachment_count
= -1,
1381 .use_repclear
= false,
1382 .disable_viewport
= true,
1383 .disable_scissor
= true,
1385 .use_rectlist
= true
1388 pipeline_shader_stages
[1].module
= anv_shader_module_to_handle(&fs_1d
);
1389 result
= anv_graphics_pipeline_create(anv_device_to_handle(device
),
1391 &vk_pipeline_info
, &anv_pipeline_info
,
1392 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_1d_src
);
1393 if (result
!= VK_SUCCESS
)
1394 goto fail_pipeline_layout
;
1396 pipeline_shader_stages
[1].module
= anv_shader_module_to_handle(&fs_2d
);
1397 result
= anv_graphics_pipeline_create(anv_device_to_handle(device
),
1399 &vk_pipeline_info
, &anv_pipeline_info
,
1400 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_2d_src
);
1401 if (result
!= VK_SUCCESS
)
1402 goto fail_pipeline_1d
;
1404 pipeline_shader_stages
[1].module
= anv_shader_module_to_handle(&fs_3d
);
1405 result
= anv_graphics_pipeline_create(anv_device_to_handle(device
),
1407 &vk_pipeline_info
, &anv_pipeline_info
,
1408 &device
->meta_state
.alloc
, &device
->meta_state
.blit
.pipeline_3d_src
);
1409 if (result
!= VK_SUCCESS
)
1410 goto fail_pipeline_2d
;
1412 ralloc_free(vs
.nir
);
1413 ralloc_free(fs_1d
.nir
);
1414 ralloc_free(fs_2d
.nir
);
1415 ralloc_free(fs_3d
.nir
);
1420 anv_DestroyPipeline(anv_device_to_handle(device
),
1421 device
->meta_state
.blit
.pipeline_2d_src
,
1422 &device
->meta_state
.alloc
);
1425 anv_DestroyPipeline(anv_device_to_handle(device
),
1426 device
->meta_state
.blit
.pipeline_1d_src
,
1427 &device
->meta_state
.alloc
);
1429 fail_pipeline_layout
:
1430 anv_DestroyPipelineLayout(anv_device_to_handle(device
),
1431 device
->meta_state
.blit
.pipeline_layout
,
1432 &device
->meta_state
.alloc
);
1433 fail_descriptor_set_layout
:
1434 anv_DestroyDescriptorSetLayout(anv_device_to_handle(device
),
1435 device
->meta_state
.blit
.ds_layout
,
1436 &device
->meta_state
.alloc
);
1438 anv_DestroyRenderPass(anv_device_to_handle(device
),
1439 device
->meta_state
.blit
.render_pass
,
1440 &device
->meta_state
.alloc
);
1442 ralloc_free(vs
.nir
);
1443 ralloc_free(fs_1d
.nir
);
1444 ralloc_free(fs_2d
.nir
);
1445 ralloc_free(fs_3d
.nir
);