turnip: implement CmdClearColorImage/CmdClearDepthStencilImage
[mesa.git] / src / freedreno / vulkan / tu_meta_clear.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "tu_private.h"
25 #include "tu_blit.h"
26
27 static void
28 clear_image(struct tu_cmd_buffer *cmdbuf,
29 struct tu_image *image,
30 uint32_t clear_value[4],
31 const VkImageSubresourceRange *range)
32 {
33 uint32_t level_count = tu_get_levelCount(image, range);
34 uint32_t layer_count = tu_get_layerCount(image, range);
35
36 if (image->type == VK_IMAGE_TYPE_3D) {
37 assert(layer_count == 1);
38 assert(range->baseArrayLayer == 0);
39 }
40
41 for (unsigned j = 0; j < level_count; j++) {
42 if (image->type == VK_IMAGE_TYPE_3D)
43 layer_count = u_minify(image->extent.depth, range->baseMipLevel + j);
44
45 tu_blit(cmdbuf, &(struct tu_blit) {
46 .dst = tu_blit_surf_whole(image, range->baseMipLevel + j, range->baseArrayLayer),
47 .src = tu_blit_surf_whole(image, range->baseMipLevel + j, range->baseArrayLayer),
48 .layers = layer_count,
49 .clear_value = {clear_value[0], clear_value[1], clear_value[2], clear_value[3]},
50 .type = TU_BLIT_CLEAR,
51 });
52 }
53 }
54
55 void
56 tu_CmdClearColorImage(VkCommandBuffer commandBuffer,
57 VkImage image_h,
58 VkImageLayout imageLayout,
59 const VkClearColorValue *pColor,
60 uint32_t rangeCount,
61 const VkImageSubresourceRange *pRanges)
62 {
63 TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, commandBuffer);
64 TU_FROM_HANDLE(tu_image, image, image_h);
65 uint32_t clear_value[4] = {};
66
67 tu_2d_clear_color(pColor, image->vk_format, clear_value);
68
69 tu_bo_list_add(&cmdbuf->bo_list, image->bo, MSM_SUBMIT_BO_WRITE);
70
71 for (unsigned i = 0; i < rangeCount; i++)
72 clear_image(cmdbuf, image, clear_value, pRanges + i);
73 }
74
75 void
76 tu_CmdClearDepthStencilImage(VkCommandBuffer commandBuffer,
77 VkImage image_h,
78 VkImageLayout imageLayout,
79 const VkClearDepthStencilValue *pDepthStencil,
80 uint32_t rangeCount,
81 const VkImageSubresourceRange *pRanges)
82 {
83 TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, commandBuffer);
84 TU_FROM_HANDLE(tu_image, image, image_h);
85 uint32_t clear_value[4] = {};
86
87 tu_2d_clear_zs(pDepthStencil, image->vk_format, clear_value);
88
89 tu_bo_list_add(&cmdbuf->bo_list, image->bo, MSM_SUBMIT_BO_WRITE);
90
91 for (unsigned i = 0; i < rangeCount; i++)
92 clear_image(cmdbuf, image, clear_value, pRanges + i);
93 }
94
95 void
96 tu_CmdClearAttachments(VkCommandBuffer commandBuffer,
97 uint32_t attachmentCount,
98 const VkClearAttachment *pAttachments,
99 uint32_t rectCount,
100 const VkClearRect *pRects)
101 {
102 tu_finishme("CmdClearAttachments");
103 }