2 * Copyright © 2016 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
24 #include "anv_private.h"
27 lookup_blorp_shader(struct blorp_batch
*batch
,
28 const void *key
, uint32_t key_size
,
29 uint32_t *kernel_out
, void *prog_data_out
)
31 struct blorp_context
*blorp
= batch
->blorp
;
32 struct anv_device
*device
= blorp
->driver_ctx
;
34 /* The default cache must be a real cache */
35 assert(device
->default_pipeline_cache
.cache
);
37 struct anv_shader_bin
*bin
=
38 anv_pipeline_cache_search(&device
->default_pipeline_cache
, key
, key_size
);
42 /* The cache already has a reference and it's not going anywhere so there
43 * is no need to hold a second reference.
45 anv_shader_bin_unref(device
, bin
);
47 *kernel_out
= bin
->kernel
.offset
;
48 *(const struct brw_stage_prog_data
**)prog_data_out
= bin
->prog_data
;
54 upload_blorp_shader(struct blorp_batch
*batch
,
55 const void *key
, uint32_t key_size
,
56 const void *kernel
, uint32_t kernel_size
,
57 const struct brw_stage_prog_data
*prog_data
,
58 uint32_t prog_data_size
,
59 uint32_t *kernel_out
, void *prog_data_out
)
61 struct blorp_context
*blorp
= batch
->blorp
;
62 struct anv_device
*device
= blorp
->driver_ctx
;
64 /* The blorp cache must be a real cache */
65 assert(device
->default_pipeline_cache
.cache
);
67 struct anv_pipeline_bind_map bind_map
= {
72 /* The stage in anv_shader_bin is only useful for pipeline shaders, so just pass
73 * a dummy value here so we don't need to change BLORP API.
75 * TODO: Plumb the stage information to BLORP.
77 gl_shader_stage stage
= MESA_SHADER_NONE
;
78 struct anv_shader_bin
*bin
=
79 anv_pipeline_cache_upload_kernel(&device
->default_pipeline_cache
, stage
,
80 key
, key_size
, kernel
, kernel_size
,
82 prog_data
, prog_data_size
,
83 NULL
, 0, NULL
, &bind_map
);
88 /* The cache already has a reference and it's not going anywhere so there
89 * is no need to hold a second reference.
91 anv_shader_bin_unref(device
, bin
);
93 *kernel_out
= bin
->kernel
.offset
;
94 *(const struct brw_stage_prog_data
**)prog_data_out
= bin
->prog_data
;
100 anv_device_init_blorp(struct anv_device
*device
)
102 blorp_init(&device
->blorp
, device
, &device
->isl_dev
);
103 device
->blorp
.compiler
= device
->physical
->compiler
;
104 device
->blorp
.lookup_shader
= lookup_blorp_shader
;
105 device
->blorp
.upload_shader
= upload_blorp_shader
;
106 switch (device
->info
.gen
) {
108 if (device
->info
.is_haswell
) {
109 device
->blorp
.exec
= gen75_blorp_exec
;
111 device
->blorp
.exec
= gen7_blorp_exec
;
115 device
->blorp
.exec
= gen8_blorp_exec
;
118 device
->blorp
.exec
= gen9_blorp_exec
;
121 device
->blorp
.exec
= gen10_blorp_exec
;
124 device
->blorp
.exec
= gen11_blorp_exec
;
127 device
->blorp
.exec
= gen12_blorp_exec
;
130 unreachable("Unknown hardware generation");
135 anv_device_finish_blorp(struct anv_device
*device
)
137 blorp_finish(&device
->blorp
);
141 get_blorp_surf_for_anv_buffer(struct anv_device
*device
,
142 struct anv_buffer
*buffer
, uint64_t offset
,
143 uint32_t width
, uint32_t height
,
144 uint32_t row_pitch
, enum isl_format format
,
145 struct blorp_surf
*blorp_surf
,
146 struct isl_surf
*isl_surf
)
148 const struct isl_format_layout
*fmtl
=
149 isl_format_get_layout(format
);
152 /* ASTC is the only format which doesn't support linear layouts.
153 * Create an equivalently sized surface with ISL to get around this.
155 if (fmtl
->txc
== ISL_TXC_ASTC
) {
156 /* Use an equivalently sized format */
157 format
= ISL_FORMAT_R32G32B32A32_UINT
;
158 assert(fmtl
->bpb
== isl_format_get_layout(format
)->bpb
);
160 /* Shrink the dimensions for the new format */
161 width
= DIV_ROUND_UP(width
, fmtl
->bw
);
162 height
= DIV_ROUND_UP(height
, fmtl
->bh
);
165 *blorp_surf
= (struct blorp_surf
) {
168 .buffer
= buffer
->address
.bo
,
169 .offset
= buffer
->address
.offset
+ offset
,
170 .mocs
= anv_mocs_for_bo(device
, buffer
->address
.bo
),
174 ok
= isl_surf_init(&device
->isl_dev
, isl_surf
,
175 .dim
= ISL_SURF_DIM_2D
,
183 .row_pitch_B
= row_pitch
,
184 .usage
= ISL_SURF_USAGE_TEXTURE_BIT
|
185 ISL_SURF_USAGE_RENDER_TARGET_BIT
,
186 .tiling_flags
= ISL_TILING_LINEAR_BIT
);
190 /* Pick something high enough that it won't be used in core and low enough it
191 * will never map to an extension.
193 #define ANV_IMAGE_LAYOUT_EXPLICIT_AUX (VkImageLayout)10000000
195 static struct blorp_address
196 anv_to_blorp_address(struct anv_address addr
)
198 return (struct blorp_address
) {
200 .offset
= addr
.offset
,
205 get_blorp_surf_for_anv_image(const struct anv_device
*device
,
206 const struct anv_image
*image
,
207 VkImageAspectFlags aspect
,
208 VkImageUsageFlags usage
,
209 VkImageLayout layout
,
210 enum isl_aux_usage aux_usage
,
211 struct blorp_surf
*blorp_surf
)
213 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
215 if (layout
!= ANV_IMAGE_LAYOUT_EXPLICIT_AUX
) {
217 aux_usage
= anv_layout_to_aux_usage(&device
->info
, image
,
218 aspect
, usage
, layout
);
221 const struct anv_surface
*surface
= &image
->planes
[plane
].surface
;
222 *blorp_surf
= (struct blorp_surf
) {
223 .surf
= &surface
->isl
,
225 .buffer
= image
->planes
[plane
].address
.bo
,
226 .offset
= image
->planes
[plane
].address
.offset
+ surface
->offset
,
227 .mocs
= anv_mocs_for_bo(device
, image
->planes
[plane
].address
.bo
),
231 if (aux_usage
!= ISL_AUX_USAGE_NONE
) {
232 const struct anv_surface
*aux_surface
= &image
->planes
[plane
].aux_surface
;
233 blorp_surf
->aux_surf
= &aux_surface
->isl
,
234 blorp_surf
->aux_addr
= (struct blorp_address
) {
235 .buffer
= image
->planes
[plane
].address
.bo
,
236 .offset
= image
->planes
[plane
].address
.offset
+ aux_surface
->offset
,
237 .mocs
= anv_mocs_for_bo(device
, image
->planes
[plane
].address
.bo
),
239 blorp_surf
->aux_usage
= aux_usage
;
241 /* If we're doing a partial resolve, then we need the indirect clear
242 * color. If we are doing a fast clear and want to store/update the
243 * clear color, we also pass the address to blorp, otherwise it will only
244 * stomp the CCS to a particular value and won't care about format or
247 if (aspect
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
248 const struct anv_address clear_color_addr
=
249 anv_image_get_clear_color_addr(device
, image
, aspect
);
250 blorp_surf
->clear_color_addr
= anv_to_blorp_address(clear_color_addr
);
251 } else if (aspect
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
252 if (device
->info
.gen
>= 10) {
253 /* Vulkan always clears to 1.0. On gen < 10, we set that directly
254 * in the state packet. For gen >= 10, must provide the clear
255 * value in a buffer. We have a single global buffer that stores
258 const struct anv_address clear_color_addr
= (struct anv_address
) {
259 .bo
= device
->hiz_clear_bo
,
261 blorp_surf
->clear_color_addr
=
262 anv_to_blorp_address(clear_color_addr
);
264 blorp_surf
->clear_color
= (union isl_color_value
) {
265 .f32
= { ANV_HZ_FC_VAL
},
273 get_blorp_surf_for_anv_shadow_image(const struct anv_device
*device
,
274 const struct anv_image
*image
,
275 VkImageAspectFlags aspect
,
276 struct blorp_surf
*blorp_surf
)
279 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
280 if (image
->planes
[plane
].shadow_surface
.isl
.size_B
== 0)
283 *blorp_surf
= (struct blorp_surf
) {
284 .surf
= &image
->planes
[plane
].shadow_surface
.isl
,
286 .buffer
= image
->planes
[plane
].address
.bo
,
287 .offset
= image
->planes
[plane
].address
.offset
+
288 image
->planes
[plane
].shadow_surface
.offset
,
289 .mocs
= anv_mocs_for_bo(device
, image
->planes
[plane
].address
.bo
),
296 void anv_CmdCopyImage(
297 VkCommandBuffer commandBuffer
,
299 VkImageLayout srcImageLayout
,
301 VkImageLayout dstImageLayout
,
302 uint32_t regionCount
,
303 const VkImageCopy
* pRegions
)
305 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
306 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
307 ANV_FROM_HANDLE(anv_image
, dst_image
, dstImage
);
309 struct blorp_batch batch
;
310 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
312 for (unsigned r
= 0; r
< regionCount
; r
++) {
313 VkOffset3D srcOffset
=
314 anv_sanitize_image_offset(src_image
->type
, pRegions
[r
].srcOffset
);
315 VkOffset3D dstOffset
=
316 anv_sanitize_image_offset(dst_image
->type
, pRegions
[r
].dstOffset
);
318 anv_sanitize_image_extent(src_image
->type
, pRegions
[r
].extent
);
320 const uint32_t dst_level
= pRegions
[r
].dstSubresource
.mipLevel
;
321 unsigned dst_base_layer
, layer_count
;
322 if (dst_image
->type
== VK_IMAGE_TYPE_3D
) {
323 dst_base_layer
= pRegions
[r
].dstOffset
.z
;
324 layer_count
= pRegions
[r
].extent
.depth
;
326 dst_base_layer
= pRegions
[r
].dstSubresource
.baseArrayLayer
;
328 anv_get_layerCount(dst_image
, &pRegions
[r
].dstSubresource
);
331 const uint32_t src_level
= pRegions
[r
].srcSubresource
.mipLevel
;
332 unsigned src_base_layer
;
333 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
334 src_base_layer
= pRegions
[r
].srcOffset
.z
;
336 src_base_layer
= pRegions
[r
].srcSubresource
.baseArrayLayer
;
337 assert(layer_count
==
338 anv_get_layerCount(src_image
, &pRegions
[r
].srcSubresource
));
341 VkImageAspectFlags src_mask
= pRegions
[r
].srcSubresource
.aspectMask
,
342 dst_mask
= pRegions
[r
].dstSubresource
.aspectMask
;
344 assert(anv_image_aspects_compatible(src_mask
, dst_mask
));
346 if (util_bitcount(src_mask
) > 1) {
348 anv_foreach_image_aspect_bit(aspect_bit
, src_image
, src_mask
) {
349 struct blorp_surf src_surf
, dst_surf
;
350 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
351 src_image
, 1UL << aspect_bit
,
352 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
353 srcImageLayout
, ISL_AUX_USAGE_NONE
,
355 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
356 dst_image
, 1UL << aspect_bit
,
357 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
358 dstImageLayout
, ISL_AUX_USAGE_NONE
,
360 anv_cmd_buffer_mark_image_written(cmd_buffer
, dst_image
,
362 dst_surf
.aux_usage
, dst_level
,
363 dst_base_layer
, layer_count
);
365 for (unsigned i
= 0; i
< layer_count
; i
++) {
366 blorp_copy(&batch
, &src_surf
, src_level
, src_base_layer
+ i
,
367 &dst_surf
, dst_level
, dst_base_layer
+ i
,
368 srcOffset
.x
, srcOffset
.y
,
369 dstOffset
.x
, dstOffset
.y
,
370 extent
.width
, extent
.height
);
373 struct blorp_surf dst_shadow_surf
;
374 if (get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
,
378 for (unsigned i
= 0; i
< layer_count
; i
++) {
379 blorp_copy(&batch
, &src_surf
, src_level
, src_base_layer
+ i
,
380 &dst_shadow_surf
, dst_level
, dst_base_layer
+ i
,
381 srcOffset
.x
, srcOffset
.y
,
382 dstOffset
.x
, dstOffset
.y
,
383 extent
.width
, extent
.height
);
388 struct blorp_surf src_surf
, dst_surf
;
389 get_blorp_surf_for_anv_image(cmd_buffer
->device
, src_image
, src_mask
,
390 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
391 srcImageLayout
, ISL_AUX_USAGE_NONE
,
393 get_blorp_surf_for_anv_image(cmd_buffer
->device
, dst_image
, dst_mask
,
394 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
395 dstImageLayout
, ISL_AUX_USAGE_NONE
,
397 anv_cmd_buffer_mark_image_written(cmd_buffer
, dst_image
, dst_mask
,
398 dst_surf
.aux_usage
, dst_level
,
399 dst_base_layer
, layer_count
);
401 for (unsigned i
= 0; i
< layer_count
; i
++) {
402 blorp_copy(&batch
, &src_surf
, src_level
, src_base_layer
+ i
,
403 &dst_surf
, dst_level
, dst_base_layer
+ i
,
404 srcOffset
.x
, srcOffset
.y
,
405 dstOffset
.x
, dstOffset
.y
,
406 extent
.width
, extent
.height
);
409 struct blorp_surf dst_shadow_surf
;
410 if (get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
,
413 for (unsigned i
= 0; i
< layer_count
; i
++) {
414 blorp_copy(&batch
, &src_surf
, src_level
, src_base_layer
+ i
,
415 &dst_shadow_surf
, dst_level
, dst_base_layer
+ i
,
416 srcOffset
.x
, srcOffset
.y
,
417 dstOffset
.x
, dstOffset
.y
,
418 extent
.width
, extent
.height
);
424 blorp_batch_finish(&batch
);
427 static enum isl_format
428 isl_format_for_size(unsigned size_B
)
430 /* Prefer 32-bit per component formats for CmdFillBuffer */
432 case 1: return ISL_FORMAT_R8_UINT
;
433 case 2: return ISL_FORMAT_R16_UINT
;
434 case 3: return ISL_FORMAT_R8G8B8_UINT
;
435 case 4: return ISL_FORMAT_R32_UINT
;
436 case 6: return ISL_FORMAT_R16G16B16_UINT
;
437 case 8: return ISL_FORMAT_R32G32_UINT
;
438 case 12: return ISL_FORMAT_R32G32B32_UINT
;
439 case 16: return ISL_FORMAT_R32G32B32A32_UINT
;
441 unreachable("Unknown format size");
446 copy_buffer_to_image(struct anv_cmd_buffer
*cmd_buffer
,
447 struct anv_buffer
*anv_buffer
,
448 struct anv_image
*anv_image
,
449 VkImageLayout image_layout
,
450 uint32_t regionCount
,
451 const VkBufferImageCopy
* pRegions
,
452 bool buffer_to_image
)
454 struct blorp_batch batch
;
455 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
458 struct blorp_surf surf
;
461 } image
, buffer
, *src
, *dst
;
464 buffer
.offset
= (VkOffset3D
) { 0, 0, 0 };
466 if (buffer_to_image
) {
474 for (unsigned r
= 0; r
< regionCount
; r
++) {
475 const VkImageAspectFlags aspect
= pRegions
[r
].imageSubresource
.aspectMask
;
477 get_blorp_surf_for_anv_image(cmd_buffer
->device
, anv_image
, aspect
,
479 VK_IMAGE_USAGE_TRANSFER_DST_BIT
:
480 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
481 image_layout
, ISL_AUX_USAGE_NONE
,
484 anv_sanitize_image_offset(anv_image
->type
, pRegions
[r
].imageOffset
);
485 image
.level
= pRegions
[r
].imageSubresource
.mipLevel
;
488 anv_sanitize_image_extent(anv_image
->type
, pRegions
[r
].imageExtent
);
489 if (anv_image
->type
!= VK_IMAGE_TYPE_3D
) {
490 image
.offset
.z
= pRegions
[r
].imageSubresource
.baseArrayLayer
;
492 anv_get_layerCount(anv_image
, &pRegions
[r
].imageSubresource
);
495 const enum isl_format linear_format
=
496 anv_get_isl_format(&cmd_buffer
->device
->info
, anv_image
->vk_format
,
497 aspect
, VK_IMAGE_TILING_LINEAR
);
498 const struct isl_format_layout
*linear_fmtl
=
499 isl_format_get_layout(linear_format
);
501 const uint32_t buffer_row_length
=
502 pRegions
[r
].bufferRowLength
?
503 pRegions
[r
].bufferRowLength
: extent
.width
;
505 const uint32_t buffer_image_height
=
506 pRegions
[r
].bufferImageHeight
?
507 pRegions
[r
].bufferImageHeight
: extent
.height
;
509 const uint32_t buffer_row_pitch
=
510 DIV_ROUND_UP(buffer_row_length
, linear_fmtl
->bw
) *
511 (linear_fmtl
->bpb
/ 8);
513 const uint32_t buffer_layer_stride
=
514 DIV_ROUND_UP(buffer_image_height
, linear_fmtl
->bh
) *
517 /* Some formats have additional restrictions which may cause ISL to
518 * fail to create a surface for us. Some examples include:
520 * 1. ASTC formats are not allowed to be LINEAR and must be tiled
521 * 2. YCbCr formats have to have 2-pixel aligned strides
523 * To avoid these issues, we always bind the buffer as if it's a
524 * "normal" format like RGBA32_UINT. Since we're using blorp_copy,
525 * the format doesn't matter as long as it has the right bpb.
527 const VkExtent2D buffer_extent
= {
528 .width
= DIV_ROUND_UP(extent
.width
, linear_fmtl
->bw
),
529 .height
= DIV_ROUND_UP(extent
.height
, linear_fmtl
->bh
),
531 const enum isl_format buffer_format
=
532 isl_format_for_size(linear_fmtl
->bpb
/ 8);
534 struct isl_surf buffer_isl_surf
;
535 get_blorp_surf_for_anv_buffer(cmd_buffer
->device
,
536 anv_buffer
, pRegions
[r
].bufferOffset
,
537 buffer_extent
.width
, buffer_extent
.height
,
538 buffer_row_pitch
, buffer_format
,
539 &buffer
.surf
, &buffer_isl_surf
);
541 bool dst_has_shadow
= false;
542 struct blorp_surf dst_shadow_surf
;
544 /* In this case, the source is the buffer and, since blorp takes its
545 * copy dimensions in terms of the source format, we have to use the
546 * scaled down version for compressed textures because the source
547 * format is an RGB format.
549 extent
.width
= buffer_extent
.width
;
550 extent
.height
= buffer_extent
.height
;
552 anv_cmd_buffer_mark_image_written(cmd_buffer
, anv_image
,
553 aspect
, dst
->surf
.aux_usage
,
555 dst
->offset
.z
, extent
.depth
);
558 get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
,
563 for (unsigned z
= 0; z
< extent
.depth
; z
++) {
564 blorp_copy(&batch
, &src
->surf
, src
->level
, src
->offset
.z
,
565 &dst
->surf
, dst
->level
, dst
->offset
.z
,
566 src
->offset
.x
, src
->offset
.y
, dst
->offset
.x
, dst
->offset
.y
,
567 extent
.width
, extent
.height
);
569 if (dst_has_shadow
) {
570 blorp_copy(&batch
, &src
->surf
, src
->level
, src
->offset
.z
,
571 &dst_shadow_surf
, dst
->level
, dst
->offset
.z
,
572 src
->offset
.x
, src
->offset
.y
,
573 dst
->offset
.x
, dst
->offset
.y
,
574 extent
.width
, extent
.height
);
578 buffer
.surf
.addr
.offset
+= buffer_layer_stride
;
582 blorp_batch_finish(&batch
);
585 void anv_CmdCopyBufferToImage(
586 VkCommandBuffer commandBuffer
,
589 VkImageLayout dstImageLayout
,
590 uint32_t regionCount
,
591 const VkBufferImageCopy
* pRegions
)
593 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
594 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
595 ANV_FROM_HANDLE(anv_image
, dst_image
, dstImage
);
597 copy_buffer_to_image(cmd_buffer
, src_buffer
, dst_image
, dstImageLayout
,
598 regionCount
, pRegions
, true);
601 void anv_CmdCopyImageToBuffer(
602 VkCommandBuffer commandBuffer
,
604 VkImageLayout srcImageLayout
,
606 uint32_t regionCount
,
607 const VkBufferImageCopy
* pRegions
)
609 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
610 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
611 ANV_FROM_HANDLE(anv_buffer
, dst_buffer
, dstBuffer
);
613 copy_buffer_to_image(cmd_buffer
, dst_buffer
, src_image
, srcImageLayout
,
614 regionCount
, pRegions
, false);
616 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
;
620 flip_coords(unsigned *src0
, unsigned *src1
, unsigned *dst0
, unsigned *dst1
)
624 unsigned tmp
= *src0
;
631 unsigned tmp
= *dst0
;
640 void anv_CmdBlitImage(
641 VkCommandBuffer commandBuffer
,
643 VkImageLayout srcImageLayout
,
645 VkImageLayout dstImageLayout
,
646 uint32_t regionCount
,
647 const VkImageBlit
* pRegions
,
651 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
652 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
653 ANV_FROM_HANDLE(anv_image
, dst_image
, dstImage
);
655 struct blorp_surf src
, dst
;
657 enum blorp_filter blorp_filter
;
659 case VK_FILTER_NEAREST
:
660 blorp_filter
= BLORP_FILTER_NEAREST
;
662 case VK_FILTER_LINEAR
:
663 blorp_filter
= BLORP_FILTER_BILINEAR
;
666 unreachable("Invalid filter");
669 struct blorp_batch batch
;
670 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
672 for (unsigned r
= 0; r
< regionCount
; r
++) {
673 const VkImageSubresourceLayers
*src_res
= &pRegions
[r
].srcSubresource
;
674 const VkImageSubresourceLayers
*dst_res
= &pRegions
[r
].dstSubresource
;
676 assert(anv_image_aspects_compatible(src_res
->aspectMask
,
677 dst_res
->aspectMask
));
680 anv_foreach_image_aspect_bit(aspect_bit
, src_image
, src_res
->aspectMask
) {
681 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
682 src_image
, 1U << aspect_bit
,
683 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
684 srcImageLayout
, ISL_AUX_USAGE_NONE
, &src
);
685 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
686 dst_image
, 1U << aspect_bit
,
687 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
688 dstImageLayout
, ISL_AUX_USAGE_NONE
, &dst
);
690 struct anv_format_plane src_format
=
691 anv_get_format_plane(&cmd_buffer
->device
->info
, src_image
->vk_format
,
692 1U << aspect_bit
, src_image
->tiling
);
693 struct anv_format_plane dst_format
=
694 anv_get_format_plane(&cmd_buffer
->device
->info
, dst_image
->vk_format
,
695 1U << aspect_bit
, dst_image
->tiling
);
697 unsigned dst_start
, dst_end
;
698 if (dst_image
->type
== VK_IMAGE_TYPE_3D
) {
699 assert(dst_res
->baseArrayLayer
== 0);
700 dst_start
= pRegions
[r
].dstOffsets
[0].z
;
701 dst_end
= pRegions
[r
].dstOffsets
[1].z
;
703 dst_start
= dst_res
->baseArrayLayer
;
704 dst_end
= dst_start
+ anv_get_layerCount(dst_image
, dst_res
);
707 unsigned src_start
, src_end
;
708 if (src_image
->type
== VK_IMAGE_TYPE_3D
) {
709 assert(src_res
->baseArrayLayer
== 0);
710 src_start
= pRegions
[r
].srcOffsets
[0].z
;
711 src_end
= pRegions
[r
].srcOffsets
[1].z
;
713 src_start
= src_res
->baseArrayLayer
;
714 src_end
= src_start
+ anv_get_layerCount(src_image
, src_res
);
717 bool flip_z
= flip_coords(&src_start
, &src_end
, &dst_start
, &dst_end
);
718 float src_z_step
= (float)(src_end
+ 1 - src_start
) /
719 (float)(dst_end
+ 1 - dst_start
);
726 unsigned src_x0
= pRegions
[r
].srcOffsets
[0].x
;
727 unsigned src_x1
= pRegions
[r
].srcOffsets
[1].x
;
728 unsigned dst_x0
= pRegions
[r
].dstOffsets
[0].x
;
729 unsigned dst_x1
= pRegions
[r
].dstOffsets
[1].x
;
730 bool flip_x
= flip_coords(&src_x0
, &src_x1
, &dst_x0
, &dst_x1
);
732 unsigned src_y0
= pRegions
[r
].srcOffsets
[0].y
;
733 unsigned src_y1
= pRegions
[r
].srcOffsets
[1].y
;
734 unsigned dst_y0
= pRegions
[r
].dstOffsets
[0].y
;
735 unsigned dst_y1
= pRegions
[r
].dstOffsets
[1].y
;
736 bool flip_y
= flip_coords(&src_y0
, &src_y1
, &dst_y0
, &dst_y1
);
738 const unsigned num_layers
= dst_end
- dst_start
;
739 anv_cmd_buffer_mark_image_written(cmd_buffer
, dst_image
,
743 dst_start
, num_layers
);
745 for (unsigned i
= 0; i
< num_layers
; i
++) {
746 unsigned dst_z
= dst_start
+ i
;
747 unsigned src_z
= src_start
+ i
* src_z_step
;
749 blorp_blit(&batch
, &src
, src_res
->mipLevel
, src_z
,
750 src_format
.isl_format
, src_format
.swizzle
,
751 &dst
, dst_res
->mipLevel
, dst_z
,
752 dst_format
.isl_format
, dst_format
.swizzle
,
753 src_x0
, src_y0
, src_x1
, src_y1
,
754 dst_x0
, dst_y0
, dst_x1
, dst_y1
,
755 blorp_filter
, flip_x
, flip_y
);
760 blorp_batch_finish(&batch
);
764 * Returns the greatest common divisor of a and b that is a power of two.
767 gcd_pow2_u64(uint64_t a
, uint64_t b
)
769 assert(a
> 0 || b
> 0);
771 unsigned a_log2
= ffsll(a
) - 1;
772 unsigned b_log2
= ffsll(b
) - 1;
774 /* If either a or b is 0, then a_log2 or b_log2 till be UINT_MAX in which
775 * case, the MIN2() will take the other one. If both are 0 then we will
776 * hit the assert above.
778 return 1 << MIN2(a_log2
, b_log2
);
781 /* This is maximum possible width/height our HW can handle */
782 #define MAX_SURFACE_DIM (1ull << 14)
784 void anv_CmdCopyBuffer(
785 VkCommandBuffer commandBuffer
,
788 uint32_t regionCount
,
789 const VkBufferCopy
* pRegions
)
791 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
792 ANV_FROM_HANDLE(anv_buffer
, src_buffer
, srcBuffer
);
793 ANV_FROM_HANDLE(anv_buffer
, dst_buffer
, dstBuffer
);
795 struct blorp_batch batch
;
796 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
798 for (unsigned r
= 0; r
< regionCount
; r
++) {
799 struct blorp_address src
= {
800 .buffer
= src_buffer
->address
.bo
,
801 .offset
= src_buffer
->address
.offset
+ pRegions
[r
].srcOffset
,
802 .mocs
= anv_mocs_for_bo(cmd_buffer
->device
, src_buffer
->address
.bo
),
804 struct blorp_address dst
= {
805 .buffer
= dst_buffer
->address
.bo
,
806 .offset
= dst_buffer
->address
.offset
+ pRegions
[r
].dstOffset
,
807 .mocs
= anv_mocs_for_bo(cmd_buffer
->device
, dst_buffer
->address
.bo
),
810 blorp_buffer_copy(&batch
, src
, dst
, pRegions
[r
].size
);
813 blorp_batch_finish(&batch
);
815 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
;
818 void anv_CmdUpdateBuffer(
819 VkCommandBuffer commandBuffer
,
821 VkDeviceSize dstOffset
,
822 VkDeviceSize dataSize
,
825 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
826 ANV_FROM_HANDLE(anv_buffer
, dst_buffer
, dstBuffer
);
828 struct blorp_batch batch
;
829 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
831 /* We can't quite grab a full block because the state stream needs a
832 * little data at the top to build its linked list.
834 const uint32_t max_update_size
=
835 cmd_buffer
->device
->dynamic_state_pool
.block_size
- 64;
837 assert(max_update_size
< MAX_SURFACE_DIM
* 4);
839 /* We're about to read data that was written from the CPU. Flush the
840 * texture cache so we don't get anything stale.
842 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
845 const uint32_t copy_size
= MIN2(dataSize
, max_update_size
);
847 struct anv_state tmp_data
=
848 anv_cmd_buffer_alloc_dynamic_state(cmd_buffer
, copy_size
, 64);
850 memcpy(tmp_data
.map
, pData
, copy_size
);
852 struct blorp_address src
= {
853 .buffer
= cmd_buffer
->device
->dynamic_state_pool
.block_pool
.bo
,
854 .offset
= tmp_data
.offset
,
855 .mocs
= cmd_buffer
->device
->isl_dev
.mocs
.internal
,
857 struct blorp_address dst
= {
858 .buffer
= dst_buffer
->address
.bo
,
859 .offset
= dst_buffer
->address
.offset
+ dstOffset
,
860 .mocs
= anv_mocs_for_bo(cmd_buffer
->device
, dst_buffer
->address
.bo
),
863 blorp_buffer_copy(&batch
, src
, dst
, copy_size
);
865 dataSize
-= copy_size
;
866 dstOffset
+= copy_size
;
867 pData
= (void *)pData
+ copy_size
;
870 blorp_batch_finish(&batch
);
872 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
;
875 void anv_CmdFillBuffer(
876 VkCommandBuffer commandBuffer
,
878 VkDeviceSize dstOffset
,
879 VkDeviceSize fillSize
,
882 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
883 ANV_FROM_HANDLE(anv_buffer
, dst_buffer
, dstBuffer
);
884 struct blorp_surf surf
;
885 struct isl_surf isl_surf
;
887 struct blorp_batch batch
;
888 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
890 fillSize
= anv_buffer_get_range(dst_buffer
, dstOffset
, fillSize
);
892 /* From the Vulkan spec:
894 * "size is the number of bytes to fill, and must be either a multiple
895 * of 4, or VK_WHOLE_SIZE to fill the range from offset to the end of
896 * the buffer. If VK_WHOLE_SIZE is used and the remaining size of the
897 * buffer is not a multiple of 4, then the nearest smaller multiple is
902 /* First, we compute the biggest format that can be used with the
903 * given offsets and size.
906 bs
= gcd_pow2_u64(bs
, dstOffset
);
907 bs
= gcd_pow2_u64(bs
, fillSize
);
908 enum isl_format isl_format
= isl_format_for_size(bs
);
910 union isl_color_value color
= {
911 .u32
= { data
, data
, data
, data
},
914 const uint64_t max_fill_size
= MAX_SURFACE_DIM
* MAX_SURFACE_DIM
* bs
;
915 while (fillSize
>= max_fill_size
) {
916 get_blorp_surf_for_anv_buffer(cmd_buffer
->device
,
917 dst_buffer
, dstOffset
,
918 MAX_SURFACE_DIM
, MAX_SURFACE_DIM
,
919 MAX_SURFACE_DIM
* bs
, isl_format
,
922 blorp_clear(&batch
, &surf
, isl_format
, ISL_SWIZZLE_IDENTITY
,
923 0, 0, 1, 0, 0, MAX_SURFACE_DIM
, MAX_SURFACE_DIM
,
925 fillSize
-= max_fill_size
;
926 dstOffset
+= max_fill_size
;
929 uint64_t height
= fillSize
/ (MAX_SURFACE_DIM
* bs
);
930 assert(height
< MAX_SURFACE_DIM
);
932 const uint64_t rect_fill_size
= height
* MAX_SURFACE_DIM
* bs
;
933 get_blorp_surf_for_anv_buffer(cmd_buffer
->device
,
934 dst_buffer
, dstOffset
,
935 MAX_SURFACE_DIM
, height
,
936 MAX_SURFACE_DIM
* bs
, isl_format
,
939 blorp_clear(&batch
, &surf
, isl_format
, ISL_SWIZZLE_IDENTITY
,
940 0, 0, 1, 0, 0, MAX_SURFACE_DIM
, height
,
942 fillSize
-= rect_fill_size
;
943 dstOffset
+= rect_fill_size
;
947 const uint32_t width
= fillSize
/ bs
;
948 get_blorp_surf_for_anv_buffer(cmd_buffer
->device
,
949 dst_buffer
, dstOffset
,
951 width
* bs
, isl_format
,
954 blorp_clear(&batch
, &surf
, isl_format
, ISL_SWIZZLE_IDENTITY
,
955 0, 0, 1, 0, 0, width
, 1,
959 blorp_batch_finish(&batch
);
961 cmd_buffer
->state
.pending_pipe_bits
|= ANV_PIPE_RENDER_TARGET_BUFFER_WRITES
;
964 void anv_CmdClearColorImage(
965 VkCommandBuffer commandBuffer
,
967 VkImageLayout imageLayout
,
968 const VkClearColorValue
* pColor
,
970 const VkImageSubresourceRange
* pRanges
)
972 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
973 ANV_FROM_HANDLE(anv_image
, image
, _image
);
975 static const bool color_write_disable
[4] = { false, false, false, false };
977 struct blorp_batch batch
;
978 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
981 for (unsigned r
= 0; r
< rangeCount
; r
++) {
982 if (pRanges
[r
].aspectMask
== 0)
985 assert(pRanges
[r
].aspectMask
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
987 struct blorp_surf surf
;
988 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
989 image
, pRanges
[r
].aspectMask
,
990 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
991 imageLayout
, ISL_AUX_USAGE_NONE
, &surf
);
993 struct anv_format_plane src_format
=
994 anv_get_format_plane(&cmd_buffer
->device
->info
, image
->vk_format
,
995 VK_IMAGE_ASPECT_COLOR_BIT
, image
->tiling
);
997 unsigned base_layer
= pRanges
[r
].baseArrayLayer
;
998 unsigned layer_count
= anv_get_layerCount(image
, &pRanges
[r
]);
1000 for (unsigned i
= 0; i
< anv_get_levelCount(image
, &pRanges
[r
]); i
++) {
1001 const unsigned level
= pRanges
[r
].baseMipLevel
+ i
;
1002 const unsigned level_width
= anv_minify(image
->extent
.width
, level
);
1003 const unsigned level_height
= anv_minify(image
->extent
.height
, level
);
1005 if (image
->type
== VK_IMAGE_TYPE_3D
) {
1007 layer_count
= anv_minify(image
->extent
.depth
, level
);
1010 anv_cmd_buffer_mark_image_written(cmd_buffer
, image
,
1011 pRanges
[r
].aspectMask
,
1012 surf
.aux_usage
, level
,
1013 base_layer
, layer_count
);
1015 blorp_clear(&batch
, &surf
,
1016 src_format
.isl_format
, src_format
.swizzle
,
1017 level
, base_layer
, layer_count
,
1018 0, 0, level_width
, level_height
,
1019 vk_to_isl_color(*pColor
), color_write_disable
);
1023 blorp_batch_finish(&batch
);
1026 void anv_CmdClearDepthStencilImage(
1027 VkCommandBuffer commandBuffer
,
1029 VkImageLayout imageLayout
,
1030 const VkClearDepthStencilValue
* pDepthStencil
,
1031 uint32_t rangeCount
,
1032 const VkImageSubresourceRange
* pRanges
)
1034 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1035 ANV_FROM_HANDLE(anv_image
, image
, image_h
);
1037 struct blorp_batch batch
;
1038 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1040 struct blorp_surf depth
, stencil
, stencil_shadow
;
1041 if (image
->aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
1042 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1043 image
, VK_IMAGE_ASPECT_DEPTH_BIT
,
1044 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
1045 imageLayout
, ISL_AUX_USAGE_NONE
, &depth
);
1047 memset(&depth
, 0, sizeof(depth
));
1050 bool has_stencil_shadow
= false;
1051 if (image
->aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
1052 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1053 image
, VK_IMAGE_ASPECT_STENCIL_BIT
,
1054 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
1055 imageLayout
, ISL_AUX_USAGE_NONE
, &stencil
);
1057 has_stencil_shadow
=
1058 get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
, image
,
1059 VK_IMAGE_ASPECT_STENCIL_BIT
,
1062 memset(&stencil
, 0, sizeof(stencil
));
1065 for (unsigned r
= 0; r
< rangeCount
; r
++) {
1066 if (pRanges
[r
].aspectMask
== 0)
1069 bool clear_depth
= pRanges
[r
].aspectMask
& VK_IMAGE_ASPECT_DEPTH_BIT
;
1070 bool clear_stencil
= pRanges
[r
].aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
;
1072 unsigned base_layer
= pRanges
[r
].baseArrayLayer
;
1073 unsigned layer_count
= anv_get_layerCount(image
, &pRanges
[r
]);
1075 for (unsigned i
= 0; i
< anv_get_levelCount(image
, &pRanges
[r
]); i
++) {
1076 const unsigned level
= pRanges
[r
].baseMipLevel
+ i
;
1077 const unsigned level_width
= anv_minify(image
->extent
.width
, level
);
1078 const unsigned level_height
= anv_minify(image
->extent
.height
, level
);
1080 if (image
->type
== VK_IMAGE_TYPE_3D
)
1081 layer_count
= anv_minify(image
->extent
.depth
, level
);
1083 blorp_clear_depth_stencil(&batch
, &depth
, &stencil
,
1084 level
, base_layer
, layer_count
,
1085 0, 0, level_width
, level_height
,
1086 clear_depth
, pDepthStencil
->depth
,
1087 clear_stencil
? 0xff : 0,
1088 pDepthStencil
->stencil
);
1090 if (clear_stencil
&& has_stencil_shadow
) {
1091 union isl_color_value stencil_color
= {
1092 .u32
= { pDepthStencil
->stencil
, },
1094 blorp_clear(&batch
, &stencil_shadow
,
1095 ISL_FORMAT_R8_UINT
, ISL_SWIZZLE_IDENTITY
,
1096 level
, base_layer
, layer_count
,
1097 0, 0, level_width
, level_height
,
1098 stencil_color
, NULL
);
1103 blorp_batch_finish(&batch
);
1107 anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer
*cmd_buffer
,
1108 uint32_t num_entries
,
1109 uint32_t *state_offset
,
1110 struct anv_state
*bt_state
)
1112 *bt_state
= anv_cmd_buffer_alloc_binding_table(cmd_buffer
, num_entries
,
1114 if (bt_state
->map
== NULL
) {
1115 /* We ran out of space. Grab a new binding table block. */
1116 VkResult result
= anv_cmd_buffer_new_binding_table_block(cmd_buffer
);
1117 if (result
!= VK_SUCCESS
)
1120 /* Re-emit state base addresses so we get the new surface state base
1121 * address before we start emitting binding tables etc.
1123 anv_cmd_buffer_emit_state_base_address(cmd_buffer
);
1125 *bt_state
= anv_cmd_buffer_alloc_binding_table(cmd_buffer
, num_entries
,
1127 assert(bt_state
->map
!= NULL
);
1134 binding_table_for_surface_state(struct anv_cmd_buffer
*cmd_buffer
,
1135 struct anv_state surface_state
,
1136 uint32_t *bt_offset
)
1138 uint32_t state_offset
;
1139 struct anv_state bt_state
;
1142 anv_cmd_buffer_alloc_blorp_binding_table(cmd_buffer
, 1, &state_offset
,
1144 if (result
!= VK_SUCCESS
)
1147 uint32_t *bt_map
= bt_state
.map
;
1148 bt_map
[0] = surface_state
.offset
+ state_offset
;
1150 *bt_offset
= bt_state
.offset
;
1155 clear_color_attachment(struct anv_cmd_buffer
*cmd_buffer
,
1156 struct blorp_batch
*batch
,
1157 const VkClearAttachment
*attachment
,
1158 uint32_t rectCount
, const VkClearRect
*pRects
)
1160 const struct anv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
1161 const uint32_t color_att
= attachment
->colorAttachment
;
1162 assert(color_att
< subpass
->color_count
);
1163 const uint32_t att_idx
= subpass
->color_attachments
[color_att
].attachment
;
1165 if (att_idx
== VK_ATTACHMENT_UNUSED
)
1168 struct anv_render_pass_attachment
*pass_att
=
1169 &cmd_buffer
->state
.pass
->attachments
[att_idx
];
1170 struct anv_attachment_state
*att_state
=
1171 &cmd_buffer
->state
.attachments
[att_idx
];
1173 uint32_t binding_table
;
1175 binding_table_for_surface_state(cmd_buffer
, att_state
->color
.state
,
1177 if (result
!= VK_SUCCESS
)
1180 union isl_color_value clear_color
=
1181 vk_to_isl_color(attachment
->clearValue
.color
);
1183 /* If multiview is enabled we ignore baseArrayLayer and layerCount */
1184 if (subpass
->view_mask
) {
1186 for_each_bit(view_idx
, subpass
->view_mask
) {
1187 for (uint32_t r
= 0; r
< rectCount
; ++r
) {
1188 const VkOffset2D offset
= pRects
[r
].rect
.offset
;
1189 const VkExtent2D extent
= pRects
[r
].rect
.extent
;
1190 blorp_clear_attachments(batch
, binding_table
,
1191 ISL_FORMAT_UNSUPPORTED
, pass_att
->samples
,
1194 offset
.x
+ extent
.width
,
1195 offset
.y
+ extent
.height
,
1196 true, clear_color
, false, 0.0f
, 0, 0);
1202 for (uint32_t r
= 0; r
< rectCount
; ++r
) {
1203 const VkOffset2D offset
= pRects
[r
].rect
.offset
;
1204 const VkExtent2D extent
= pRects
[r
].rect
.extent
;
1205 assert(pRects
[r
].layerCount
!= VK_REMAINING_ARRAY_LAYERS
);
1206 blorp_clear_attachments(batch
, binding_table
,
1207 ISL_FORMAT_UNSUPPORTED
, pass_att
->samples
,
1208 pRects
[r
].baseArrayLayer
,
1209 pRects
[r
].layerCount
,
1211 offset
.x
+ extent
.width
, offset
.y
+ extent
.height
,
1212 true, clear_color
, false, 0.0f
, 0, 0);
1217 clear_depth_stencil_attachment(struct anv_cmd_buffer
*cmd_buffer
,
1218 struct blorp_batch
*batch
,
1219 const VkClearAttachment
*attachment
,
1220 uint32_t rectCount
, const VkClearRect
*pRects
)
1222 static const union isl_color_value color_value
= { .u32
= { 0, } };
1223 const struct anv_subpass
*subpass
= cmd_buffer
->state
.subpass
;
1224 if (!subpass
->depth_stencil_attachment
)
1227 const uint32_t att_idx
= subpass
->depth_stencil_attachment
->attachment
;
1228 assert(att_idx
!= VK_ATTACHMENT_UNUSED
);
1229 struct anv_render_pass_attachment
*pass_att
=
1230 &cmd_buffer
->state
.pass
->attachments
[att_idx
];
1232 bool clear_depth
= attachment
->aspectMask
& VK_IMAGE_ASPECT_DEPTH_BIT
;
1233 bool clear_stencil
= attachment
->aspectMask
& VK_IMAGE_ASPECT_STENCIL_BIT
;
1235 enum isl_format depth_format
= ISL_FORMAT_UNSUPPORTED
;
1237 depth_format
= anv_get_isl_format(&cmd_buffer
->device
->info
,
1239 VK_IMAGE_ASPECT_DEPTH_BIT
,
1240 VK_IMAGE_TILING_OPTIMAL
);
1243 uint32_t binding_table
;
1245 binding_table_for_surface_state(cmd_buffer
,
1246 cmd_buffer
->state
.null_surface_state
,
1248 if (result
!= VK_SUCCESS
)
1251 /* If multiview is enabled we ignore baseArrayLayer and layerCount */
1252 if (subpass
->view_mask
) {
1254 for_each_bit(view_idx
, subpass
->view_mask
) {
1255 for (uint32_t r
= 0; r
< rectCount
; ++r
) {
1256 const VkOffset2D offset
= pRects
[r
].rect
.offset
;
1257 const VkExtent2D extent
= pRects
[r
].rect
.extent
;
1258 VkClearDepthStencilValue value
= attachment
->clearValue
.depthStencil
;
1259 blorp_clear_attachments(batch
, binding_table
,
1260 depth_format
, pass_att
->samples
,
1263 offset
.x
+ extent
.width
,
1264 offset
.y
+ extent
.height
,
1266 clear_depth
, value
.depth
,
1267 clear_stencil
? 0xff : 0, value
.stencil
);
1273 for (uint32_t r
= 0; r
< rectCount
; ++r
) {
1274 const VkOffset2D offset
= pRects
[r
].rect
.offset
;
1275 const VkExtent2D extent
= pRects
[r
].rect
.extent
;
1276 VkClearDepthStencilValue value
= attachment
->clearValue
.depthStencil
;
1277 assert(pRects
[r
].layerCount
!= VK_REMAINING_ARRAY_LAYERS
);
1278 blorp_clear_attachments(batch
, binding_table
,
1279 depth_format
, pass_att
->samples
,
1280 pRects
[r
].baseArrayLayer
,
1281 pRects
[r
].layerCount
,
1283 offset
.x
+ extent
.width
, offset
.y
+ extent
.height
,
1285 clear_depth
, value
.depth
,
1286 clear_stencil
? 0xff : 0, value
.stencil
);
1290 void anv_CmdClearAttachments(
1291 VkCommandBuffer commandBuffer
,
1292 uint32_t attachmentCount
,
1293 const VkClearAttachment
* pAttachments
,
1295 const VkClearRect
* pRects
)
1297 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1299 /* Because this gets called within a render pass, we tell blorp not to
1300 * trash our depth and stencil buffers.
1302 struct blorp_batch batch
;
1303 enum blorp_batch_flags flags
= BLORP_BATCH_NO_EMIT_DEPTH_STENCIL
;
1304 if (cmd_buffer
->state
.conditional_render_enabled
) {
1305 anv_cmd_emit_conditional_render_predicate(cmd_buffer
);
1306 flags
|= BLORP_BATCH_PREDICATE_ENABLE
;
1308 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, flags
);
1310 for (uint32_t a
= 0; a
< attachmentCount
; ++a
) {
1311 if (pAttachments
[a
].aspectMask
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
) {
1312 assert(pAttachments
[a
].aspectMask
== VK_IMAGE_ASPECT_COLOR_BIT
);
1313 clear_color_attachment(cmd_buffer
, &batch
,
1317 clear_depth_stencil_attachment(cmd_buffer
, &batch
,
1323 blorp_batch_finish(&batch
);
1326 enum subpass_stage
{
1329 SUBPASS_STAGE_RESOLVE
,
1333 anv_image_msaa_resolve(struct anv_cmd_buffer
*cmd_buffer
,
1334 const struct anv_image
*src_image
,
1335 enum isl_aux_usage src_aux_usage
,
1336 uint32_t src_level
, uint32_t src_base_layer
,
1337 const struct anv_image
*dst_image
,
1338 enum isl_aux_usage dst_aux_usage
,
1339 uint32_t dst_level
, uint32_t dst_base_layer
,
1340 VkImageAspectFlagBits aspect
,
1341 uint32_t src_x
, uint32_t src_y
,
1342 uint32_t dst_x
, uint32_t dst_y
,
1343 uint32_t width
, uint32_t height
,
1344 uint32_t layer_count
,
1345 enum blorp_filter filter
)
1347 struct blorp_batch batch
;
1348 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1350 assert(src_image
->type
== VK_IMAGE_TYPE_2D
);
1351 assert(src_image
->samples
> 1);
1352 assert(dst_image
->type
== VK_IMAGE_TYPE_2D
);
1353 assert(dst_image
->samples
== 1);
1354 assert(src_image
->n_planes
== dst_image
->n_planes
);
1355 assert(!src_image
->format
->can_ycbcr
);
1356 assert(!dst_image
->format
->can_ycbcr
);
1358 struct blorp_surf src_surf
, dst_surf
;
1359 get_blorp_surf_for_anv_image(cmd_buffer
->device
, src_image
, aspect
,
1360 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1361 src_aux_usage
, &src_surf
);
1362 if (src_aux_usage
== ISL_AUX_USAGE_MCS
) {
1363 src_surf
.clear_color_addr
= anv_to_blorp_address(
1364 anv_image_get_clear_color_addr(cmd_buffer
->device
, src_image
,
1365 VK_IMAGE_ASPECT_COLOR_BIT
));
1367 get_blorp_surf_for_anv_image(cmd_buffer
->device
, dst_image
, aspect
,
1368 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1369 dst_aux_usage
, &dst_surf
);
1370 anv_cmd_buffer_mark_image_written(cmd_buffer
, dst_image
,
1371 aspect
, dst_aux_usage
,
1372 dst_level
, dst_base_layer
, layer_count
);
1374 if (filter
== BLORP_FILTER_NONE
) {
1375 /* If no explicit filter is provided, then it's implied by the type of
1378 if ((src_surf
.surf
->usage
& ISL_SURF_USAGE_DEPTH_BIT
) ||
1379 (src_surf
.surf
->usage
& ISL_SURF_USAGE_STENCIL_BIT
) ||
1380 isl_format_has_int_channel(src_surf
.surf
->format
)) {
1381 filter
= BLORP_FILTER_SAMPLE_0
;
1383 filter
= BLORP_FILTER_AVERAGE
;
1387 for (uint32_t l
= 0; l
< layer_count
; l
++) {
1389 &src_surf
, src_level
, src_base_layer
+ l
,
1390 ISL_FORMAT_UNSUPPORTED
, ISL_SWIZZLE_IDENTITY
,
1391 &dst_surf
, dst_level
, dst_base_layer
+ l
,
1392 ISL_FORMAT_UNSUPPORTED
, ISL_SWIZZLE_IDENTITY
,
1393 src_x
, src_y
, src_x
+ width
, src_y
+ height
,
1394 dst_x
, dst_y
, dst_x
+ width
, dst_y
+ height
,
1395 filter
, false, false);
1398 blorp_batch_finish(&batch
);
1401 void anv_CmdResolveImage(
1402 VkCommandBuffer commandBuffer
,
1404 VkImageLayout srcImageLayout
,
1406 VkImageLayout dstImageLayout
,
1407 uint32_t regionCount
,
1408 const VkImageResolve
* pRegions
)
1410 ANV_FROM_HANDLE(anv_cmd_buffer
, cmd_buffer
, commandBuffer
);
1411 ANV_FROM_HANDLE(anv_image
, src_image
, srcImage
);
1412 ANV_FROM_HANDLE(anv_image
, dst_image
, dstImage
);
1414 assert(!src_image
->format
->can_ycbcr
);
1416 for (uint32_t r
= 0; r
< regionCount
; r
++) {
1417 assert(pRegions
[r
].srcSubresource
.aspectMask
==
1418 pRegions
[r
].dstSubresource
.aspectMask
);
1419 assert(anv_get_layerCount(src_image
, &pRegions
[r
].srcSubresource
) ==
1420 anv_get_layerCount(dst_image
, &pRegions
[r
].dstSubresource
));
1422 const uint32_t layer_count
=
1423 anv_get_layerCount(dst_image
, &pRegions
[r
].dstSubresource
);
1425 uint32_t aspect_bit
;
1426 anv_foreach_image_aspect_bit(aspect_bit
, src_image
,
1427 pRegions
[r
].srcSubresource
.aspectMask
) {
1428 enum isl_aux_usage src_aux_usage
=
1429 anv_layout_to_aux_usage(&cmd_buffer
->device
->info
, src_image
,
1431 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
1433 enum isl_aux_usage dst_aux_usage
=
1434 anv_layout_to_aux_usage(&cmd_buffer
->device
->info
, dst_image
,
1436 VK_IMAGE_USAGE_TRANSFER_DST_BIT
,
1439 anv_image_msaa_resolve(cmd_buffer
,
1440 src_image
, src_aux_usage
,
1441 pRegions
[r
].srcSubresource
.mipLevel
,
1442 pRegions
[r
].srcSubresource
.baseArrayLayer
,
1443 dst_image
, dst_aux_usage
,
1444 pRegions
[r
].dstSubresource
.mipLevel
,
1445 pRegions
[r
].dstSubresource
.baseArrayLayer
,
1447 pRegions
[r
].srcOffset
.x
,
1448 pRegions
[r
].srcOffset
.y
,
1449 pRegions
[r
].dstOffset
.x
,
1450 pRegions
[r
].dstOffset
.y
,
1451 pRegions
[r
].extent
.width
,
1452 pRegions
[r
].extent
.height
,
1453 layer_count
, BLORP_FILTER_NONE
);
1459 anv_image_copy_to_shadow(struct anv_cmd_buffer
*cmd_buffer
,
1460 const struct anv_image
*image
,
1461 VkImageAspectFlagBits aspect
,
1462 uint32_t base_level
, uint32_t level_count
,
1463 uint32_t base_layer
, uint32_t layer_count
)
1465 struct blorp_batch batch
;
1466 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1468 /* We don't know who touched the main surface last so flush a bunch of
1469 * caches to ensure we get good data.
1471 cmd_buffer
->state
.pending_pipe_bits
|=
1472 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
|
1473 ANV_PIPE_DATA_CACHE_FLUSH_BIT
|
1474 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
|
1475 ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT
;
1477 struct blorp_surf surf
;
1478 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1480 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
,
1481 VK_IMAGE_LAYOUT_GENERAL
,
1482 ISL_AUX_USAGE_NONE
, &surf
);
1483 assert(surf
.aux_usage
== ISL_AUX_USAGE_NONE
);
1485 struct blorp_surf shadow_surf
;
1486 get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
,
1487 image
, aspect
, &shadow_surf
);
1489 for (uint32_t l
= 0; l
< level_count
; l
++) {
1490 const uint32_t level
= base_level
+ l
;
1492 const VkExtent3D extent
= {
1493 .width
= anv_minify(image
->extent
.width
, level
),
1494 .height
= anv_minify(image
->extent
.height
, level
),
1495 .depth
= anv_minify(image
->extent
.depth
, level
),
1498 if (image
->type
== VK_IMAGE_TYPE_3D
)
1499 layer_count
= extent
.depth
;
1501 for (uint32_t a
= 0; a
< layer_count
; a
++) {
1502 const uint32_t layer
= base_layer
+ a
;
1504 blorp_copy(&batch
, &surf
, level
, layer
,
1505 &shadow_surf
, level
, layer
,
1506 0, 0, 0, 0, extent
.width
, extent
.height
);
1510 /* We just wrote to the buffer with the render cache. Flush it. */
1511 cmd_buffer
->state
.pending_pipe_bits
|=
1512 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
;
1514 blorp_batch_finish(&batch
);
1518 anv_image_clear_color(struct anv_cmd_buffer
*cmd_buffer
,
1519 const struct anv_image
*image
,
1520 VkImageAspectFlagBits aspect
,
1521 enum isl_aux_usage aux_usage
,
1522 enum isl_format format
, struct isl_swizzle swizzle
,
1523 uint32_t level
, uint32_t base_layer
, uint32_t layer_count
,
1524 VkRect2D area
, union isl_color_value clear_color
)
1526 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
1528 /* We don't support planar images with multisampling yet */
1529 assert(image
->n_planes
== 1);
1531 struct blorp_batch batch
;
1532 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1534 struct blorp_surf surf
;
1535 get_blorp_surf_for_anv_image(cmd_buffer
->device
, image
, aspect
,
1536 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1538 anv_cmd_buffer_mark_image_written(cmd_buffer
, image
, aspect
, aux_usage
,
1539 level
, base_layer
, layer_count
);
1541 blorp_clear(&batch
, &surf
, format
, anv_swizzle_for_render(swizzle
),
1542 level
, base_layer
, layer_count
,
1543 area
.offset
.x
, area
.offset
.y
,
1544 area
.offset
.x
+ area
.extent
.width
,
1545 area
.offset
.y
+ area
.extent
.height
,
1548 blorp_batch_finish(&batch
);
1552 anv_image_clear_depth_stencil(struct anv_cmd_buffer
*cmd_buffer
,
1553 const struct anv_image
*image
,
1554 VkImageAspectFlags aspects
,
1555 enum isl_aux_usage depth_aux_usage
,
1557 uint32_t base_layer
, uint32_t layer_count
,
1559 float depth_value
, uint8_t stencil_value
)
1561 assert(image
->aspects
& (VK_IMAGE_ASPECT_DEPTH_BIT
|
1562 VK_IMAGE_ASPECT_STENCIL_BIT
));
1564 struct blorp_batch batch
;
1565 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1567 struct blorp_surf depth
= {};
1568 if (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
1569 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1570 image
, VK_IMAGE_ASPECT_DEPTH_BIT
,
1571 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1572 depth_aux_usage
, &depth
);
1573 depth
.clear_color
.f32
[0] = ANV_HZ_FC_VAL
;
1576 struct blorp_surf stencil
= {};
1577 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
1578 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1579 image
, VK_IMAGE_ASPECT_STENCIL_BIT
,
1580 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1581 ISL_AUX_USAGE_NONE
, &stencil
);
1584 /* Blorp may choose to clear stencil using RGBA32_UINT for better
1585 * performance. If it does this, we need to flush it out of the depth
1586 * cache before rendering to it.
1588 cmd_buffer
->state
.pending_pipe_bits
|=
1589 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1591 blorp_clear_depth_stencil(&batch
, &depth
, &stencil
,
1592 level
, base_layer
, layer_count
,
1593 area
.offset
.x
, area
.offset
.y
,
1594 area
.offset
.x
+ area
.extent
.width
,
1595 area
.offset
.y
+ area
.extent
.height
,
1596 aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
,
1598 (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) ? 0xff : 0,
1601 /* Blorp may choose to clear stencil using RGBA32_UINT for better
1602 * performance. If it does this, we need to flush it out of the render
1603 * cache before someone starts trying to do stencil on it.
1605 cmd_buffer
->state
.pending_pipe_bits
|=
1606 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1608 struct blorp_surf stencil_shadow
;
1609 if ((aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) &&
1610 get_blorp_surf_for_anv_shadow_image(cmd_buffer
->device
, image
,
1611 VK_IMAGE_ASPECT_STENCIL_BIT
,
1613 union isl_color_value stencil_color
= {
1614 .u32
= { stencil_value
},
1616 blorp_clear(&batch
, &stencil_shadow
,
1617 ISL_FORMAT_R8_UINT
, ISL_SWIZZLE_IDENTITY
,
1618 level
, base_layer
, layer_count
,
1619 area
.offset
.x
, area
.offset
.y
,
1620 area
.offset
.x
+ area
.extent
.width
,
1621 area
.offset
.y
+ area
.extent
.height
,
1622 stencil_color
, NULL
);
1625 blorp_batch_finish(&batch
);
1629 anv_image_hiz_op(struct anv_cmd_buffer
*cmd_buffer
,
1630 const struct anv_image
*image
,
1631 VkImageAspectFlagBits aspect
, uint32_t level
,
1632 uint32_t base_layer
, uint32_t layer_count
,
1633 enum isl_aux_op hiz_op
)
1635 assert(aspect
== VK_IMAGE_ASPECT_DEPTH_BIT
);
1636 assert(base_layer
+ layer_count
<= anv_image_aux_layers(image
, aspect
, level
));
1637 assert(anv_image_aspect_to_plane(image
->aspects
,
1638 VK_IMAGE_ASPECT_DEPTH_BIT
) == 0);
1640 struct blorp_batch batch
;
1641 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1643 struct blorp_surf surf
;
1644 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1645 image
, VK_IMAGE_ASPECT_DEPTH_BIT
,
1646 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1647 ISL_AUX_USAGE_HIZ
, &surf
);
1648 surf
.clear_color
.f32
[0] = ANV_HZ_FC_VAL
;
1650 blorp_hiz_op(&batch
, &surf
, level
, base_layer
, layer_count
, hiz_op
);
1652 blorp_batch_finish(&batch
);
1656 anv_image_hiz_clear(struct anv_cmd_buffer
*cmd_buffer
,
1657 const struct anv_image
*image
,
1658 VkImageAspectFlags aspects
,
1660 uint32_t base_layer
, uint32_t layer_count
,
1661 VkRect2D area
, uint8_t stencil_value
)
1663 assert(image
->aspects
& (VK_IMAGE_ASPECT_DEPTH_BIT
|
1664 VK_IMAGE_ASPECT_STENCIL_BIT
));
1666 struct blorp_batch batch
;
1667 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
, 0);
1669 struct blorp_surf depth
= {};
1670 if (aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
) {
1671 assert(base_layer
+ layer_count
<=
1672 anv_image_aux_layers(image
, VK_IMAGE_ASPECT_DEPTH_BIT
, level
));
1673 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1674 image
, VK_IMAGE_ASPECT_DEPTH_BIT
,
1675 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1676 ISL_AUX_USAGE_HIZ
, &depth
);
1677 depth
.clear_color
.f32
[0] = ANV_HZ_FC_VAL
;
1680 struct blorp_surf stencil
= {};
1681 if (aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
) {
1682 get_blorp_surf_for_anv_image(cmd_buffer
->device
,
1683 image
, VK_IMAGE_ASPECT_STENCIL_BIT
,
1684 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1685 ISL_AUX_USAGE_NONE
, &stencil
);
1688 /* From the Sky Lake PRM Volume 7, "Depth Buffer Clear":
1690 * "The following is required when performing a depth buffer clear with
1691 * using the WM_STATE or 3DSTATE_WM:
1693 * * If other rendering operations have preceded this clear, a
1694 * PIPE_CONTROL with depth cache flush enabled, Depth Stall bit
1695 * enabled must be issued before the rectangle primitive used for
1696 * the depth buffer clear operation.
1699 * Even though the PRM only says that this is required if using 3DSTATE_WM
1700 * and a 3DPRIMITIVE, the GPU appears to also need this to avoid occasional
1701 * hangs when doing a clear with WM_HZ_OP.
1703 cmd_buffer
->state
.pending_pipe_bits
|=
1704 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
| ANV_PIPE_DEPTH_STALL_BIT
;
1706 blorp_hiz_clear_depth_stencil(&batch
, &depth
, &stencil
,
1707 level
, base_layer
, layer_count
,
1708 area
.offset
.x
, area
.offset
.y
,
1709 area
.offset
.x
+ area
.extent
.width
,
1710 area
.offset
.y
+ area
.extent
.height
,
1711 aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
,
1713 aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
,
1716 blorp_batch_finish(&batch
);
1718 /* From the SKL PRM, Depth Buffer Clear:
1720 * "Depth Buffer Clear Workaround
1722 * Depth buffer clear pass using any of the methods (WM_STATE,
1723 * 3DSTATE_WM or 3DSTATE_WM_HZ_OP) must be followed by a PIPE_CONTROL
1724 * command with DEPTH_STALL bit and Depth FLUSH bits “set” before
1725 * starting to render. DepthStall and DepthFlush are not needed between
1726 * consecutive depth clear passes nor is it required if the depth-clear
1727 * pass was done with “full_surf_clear” bit set in the
1728 * 3DSTATE_WM_HZ_OP."
1730 * Even though the PRM provides a bunch of conditions under which this is
1731 * supposedly unnecessary, we choose to perform the flush unconditionally
1734 cmd_buffer
->state
.pending_pipe_bits
|=
1735 ANV_PIPE_DEPTH_CACHE_FLUSH_BIT
| ANV_PIPE_DEPTH_STALL_BIT
;
1739 anv_image_mcs_op(struct anv_cmd_buffer
*cmd_buffer
,
1740 const struct anv_image
*image
,
1741 enum isl_format format
,
1742 VkImageAspectFlagBits aspect
,
1743 uint32_t base_layer
, uint32_t layer_count
,
1744 enum isl_aux_op mcs_op
, union isl_color_value
*clear_value
,
1747 assert(image
->aspects
== VK_IMAGE_ASPECT_COLOR_BIT
);
1748 assert(image
->samples
> 1);
1749 assert(base_layer
+ layer_count
<= anv_image_aux_layers(image
, aspect
, 0));
1751 /* Multisampling with multi-planar formats is not supported */
1752 assert(image
->n_planes
== 1);
1754 struct blorp_batch batch
;
1755 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
,
1756 BLORP_BATCH_PREDICATE_ENABLE
* predicate
+
1757 BLORP_BATCH_NO_UPDATE_CLEAR_COLOR
* !clear_value
);
1759 struct blorp_surf surf
;
1760 get_blorp_surf_for_anv_image(cmd_buffer
->device
, image
, aspect
,
1761 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1762 ISL_AUX_USAGE_MCS
, &surf
);
1764 /* Blorp will store the clear color for us if we provide the clear color
1765 * address and we are doing a fast clear. So we save the clear value into
1766 * the blorp surface.
1769 surf
.clear_color
= *clear_value
;
1771 /* From the Sky Lake PRM Vol. 7, "Render Target Fast Clear":
1773 * "After Render target fast clear, pipe-control with color cache
1774 * write-flush must be issued before sending any DRAW commands on
1775 * that render target."
1777 * This comment is a bit cryptic and doesn't really tell you what's going
1778 * or what's really needed. It appears that fast clear ops are not
1779 * properly synchronized with other drawing. This means that we cannot
1780 * have a fast clear operation in the pipe at the same time as other
1781 * regular drawing operations. We need to use a PIPE_CONTROL to ensure
1782 * that the contents of the previous draw hit the render target before we
1783 * resolve and then use a second PIPE_CONTROL after the resolve to ensure
1784 * that it is completed before any additional drawing occurs.
1786 cmd_buffer
->state
.pending_pipe_bits
|=
1787 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1790 case ISL_AUX_OP_FAST_CLEAR
:
1791 blorp_fast_clear(&batch
, &surf
, format
,
1792 0, base_layer
, layer_count
,
1793 0, 0, image
->extent
.width
, image
->extent
.height
);
1795 case ISL_AUX_OP_PARTIAL_RESOLVE
:
1796 blorp_mcs_partial_resolve(&batch
, &surf
, format
,
1797 base_layer
, layer_count
);
1799 case ISL_AUX_OP_FULL_RESOLVE
:
1800 case ISL_AUX_OP_AMBIGUATE
:
1802 unreachable("Unsupported MCS operation");
1805 cmd_buffer
->state
.pending_pipe_bits
|=
1806 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1808 blorp_batch_finish(&batch
);
1812 anv_image_ccs_op(struct anv_cmd_buffer
*cmd_buffer
,
1813 const struct anv_image
*image
,
1814 enum isl_format format
,
1815 VkImageAspectFlagBits aspect
, uint32_t level
,
1816 uint32_t base_layer
, uint32_t layer_count
,
1817 enum isl_aux_op ccs_op
, union isl_color_value
*clear_value
,
1820 assert(image
->aspects
& VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV
);
1821 assert(image
->samples
== 1);
1822 assert(level
< anv_image_aux_levels(image
, aspect
));
1823 /* Multi-LOD YcBcR is not allowed */
1824 assert(image
->n_planes
== 1 || level
== 0);
1825 assert(base_layer
+ layer_count
<=
1826 anv_image_aux_layers(image
, aspect
, level
));
1828 uint32_t plane
= anv_image_aspect_to_plane(image
->aspects
, aspect
);
1829 uint32_t width_div
= image
->format
->planes
[plane
].denominator_scales
[0];
1830 uint32_t height_div
= image
->format
->planes
[plane
].denominator_scales
[1];
1831 uint32_t level_width
= anv_minify(image
->extent
.width
, level
) / width_div
;
1832 uint32_t level_height
= anv_minify(image
->extent
.height
, level
) / height_div
;
1834 struct blorp_batch batch
;
1835 blorp_batch_init(&cmd_buffer
->device
->blorp
, &batch
, cmd_buffer
,
1836 BLORP_BATCH_PREDICATE_ENABLE
* predicate
+
1837 BLORP_BATCH_NO_UPDATE_CLEAR_COLOR
* !clear_value
);
1839 struct blorp_surf surf
;
1840 get_blorp_surf_for_anv_image(cmd_buffer
->device
, image
, aspect
,
1841 0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX
,
1842 image
->planes
[plane
].aux_usage
,
1845 /* Blorp will store the clear color for us if we provide the clear color
1846 * address and we are doing a fast clear. So we save the clear value into
1847 * the blorp surface.
1850 surf
.clear_color
= *clear_value
;
1852 /* From the Sky Lake PRM Vol. 7, "Render Target Fast Clear":
1854 * "After Render target fast clear, pipe-control with color cache
1855 * write-flush must be issued before sending any DRAW commands on
1856 * that render target."
1858 * This comment is a bit cryptic and doesn't really tell you what's going
1859 * or what's really needed. It appears that fast clear ops are not
1860 * properly synchronized with other drawing. This means that we cannot
1861 * have a fast clear operation in the pipe at the same time as other
1862 * regular drawing operations. We need to use a PIPE_CONTROL to ensure
1863 * that the contents of the previous draw hit the render target before we
1864 * resolve and then use a second PIPE_CONTROL after the resolve to ensure
1865 * that it is completed before any additional drawing occurs.
1867 cmd_buffer
->state
.pending_pipe_bits
|=
1868 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1871 case ISL_AUX_OP_FAST_CLEAR
:
1872 blorp_fast_clear(&batch
, &surf
, format
,
1873 level
, base_layer
, layer_count
,
1874 0, 0, level_width
, level_height
);
1876 case ISL_AUX_OP_FULL_RESOLVE
:
1877 case ISL_AUX_OP_PARTIAL_RESOLVE
:
1878 blorp_ccs_resolve(&batch
, &surf
, level
, base_layer
, layer_count
,
1881 case ISL_AUX_OP_AMBIGUATE
:
1882 for (uint32_t a
= 0; a
< layer_count
; a
++) {
1883 const uint32_t layer
= base_layer
+ a
;
1884 blorp_ccs_ambiguate(&batch
, &surf
, level
, layer
);
1888 unreachable("Unsupported CCS operation");
1891 cmd_buffer
->state
.pending_pipe_bits
|=
1892 ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT
| ANV_PIPE_END_OF_PIPE_SYNC_BIT
;
1894 blorp_batch_finish(&batch
);