turnip: don't set SP_FS_CTRL_REG0_VARYING if only fragcoord is used
[mesa.git] / src / freedreno / vulkan / tu_meta_blit.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
26 #include "tu_blit.h"
27
28 static void
29 tu_blit_image(struct tu_cmd_buffer *cmdbuf,
30 struct tu_image *src_image,
31 struct tu_image *dst_image,
32 const VkImageBlit *info,
33 VkFilter filter)
34 {
35 static const enum a6xx_rotation rotate[2][2] = {
36 {ROTATE_0, ROTATE_HFLIP},
37 {ROTATE_VFLIP, ROTATE_180},
38 };
39 bool mirror_x = (info->srcOffsets[1].x < info->srcOffsets[0].x) !=
40 (info->dstOffsets[1].x < info->dstOffsets[0].x);
41 bool mirror_y = (info->srcOffsets[1].y < info->srcOffsets[0].y) !=
42 (info->dstOffsets[1].y < info->dstOffsets[0].y);
43 bool mirror_z = (info->srcOffsets[1].z < info->srcOffsets[0].z) !=
44 (info->dstOffsets[1].z < info->dstOffsets[0].z);
45
46 if (mirror_z) {
47 tu_finishme("blit z mirror\n");
48 return;
49 }
50
51 if (info->srcOffsets[1].z - info->srcOffsets[0].z !=
52 info->dstOffsets[1].z - info->dstOffsets[0].z) {
53 tu_finishme("blit z filter\n");
54 return;
55 }
56 assert(info->dstSubresource.layerCount == info->srcSubresource.layerCount);
57
58 struct tu_blit blt = {
59 .dst = tu_blit_surf(dst_image, info->dstSubresource, info->dstOffsets),
60 .src = tu_blit_surf(src_image, info->srcSubresource, info->srcOffsets),
61 .layers = MAX2(info->srcOffsets[1].z - info->srcOffsets[0].z,
62 info->dstSubresource.layerCount),
63 .filter = filter == VK_FILTER_LINEAR,
64 .rotation = rotate[mirror_y][mirror_x],
65 };
66
67 tu_blit(cmdbuf, &blt);
68 }
69
70 void
71 tu_CmdBlitImage(VkCommandBuffer commandBuffer,
72 VkImage srcImage,
73 VkImageLayout srcImageLayout,
74 VkImage destImage,
75 VkImageLayout destImageLayout,
76 uint32_t regionCount,
77 const VkImageBlit *pRegions,
78 VkFilter filter)
79
80 {
81 TU_FROM_HANDLE(tu_cmd_buffer, cmdbuf, commandBuffer);
82 TU_FROM_HANDLE(tu_image, src_image, srcImage);
83 TU_FROM_HANDLE(tu_image, dst_image, destImage);
84
85 tu_bo_list_add(&cmdbuf->bo_list, src_image->bo, MSM_SUBMIT_BO_READ);
86 tu_bo_list_add(&cmdbuf->bo_list, dst_image->bo, MSM_SUBMIT_BO_WRITE);
87
88 for (uint32_t i = 0; i < regionCount; ++i) {
89 tu_blit_image(cmdbuf, src_image, dst_image, pRegions + i, filter);
90 }
91 }