~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/panfrost/vulkan/panvk_vX_meta_blit.c

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2021 Collabora Ltd.
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 "gen_macros.h"
25
 
 
26
 
#include "pan_blitter.h"
27
 
 
28
 
#include "panvk_private.h"
29
 
 
30
 
static void
31
 
panvk_meta_blit(struct panvk_cmd_buffer *cmdbuf,
32
 
                const struct pan_blit_info *blitinfo)
33
 
{
34
 
   struct panfrost_device *pdev = &cmdbuf->device->physical_device->pdev;
35
 
   struct pan_fb_info *fbinfo = &cmdbuf->state.fb.info;
36
 
   struct pan_blit_context ctx;
37
 
   struct pan_image_view views[2] = {
38
 
      {
39
 
         .format = blitinfo->dst.planes[0].format,
40
 
         .dim = MALI_TEXTURE_DIMENSION_2D,
41
 
         .image = blitinfo->dst.planes[0].image,
42
 
         .nr_samples = blitinfo->dst.planes[0].image->layout.nr_samples,
43
 
         .first_level = blitinfo->dst.level,
44
 
         .last_level = blitinfo->dst.level,
45
 
         .swizzle = { PIPE_SWIZZLE_X, PIPE_SWIZZLE_Y, PIPE_SWIZZLE_Z, PIPE_SWIZZLE_W },
46
 
      },
47
 
   };
48
 
 
49
 
   *fbinfo = (struct pan_fb_info){
50
 
      .width = u_minify(blitinfo->dst.planes[0].image->layout.width, blitinfo->dst.level),
51
 
      .height = u_minify(blitinfo->dst.planes[0].image->layout.height, blitinfo->dst.level),
52
 
      .extent = {
53
 
         .minx = MAX2(MIN2(blitinfo->dst.start.x, blitinfo->dst.end.x), 0),
54
 
         .miny = MAX2(MIN2(blitinfo->dst.start.y, blitinfo->dst.end.y), 0),
55
 
         .maxx = MAX2(blitinfo->dst.start.x, blitinfo->dst.end.x),
56
 
         .maxy = MAX2(blitinfo->dst.start.y, blitinfo->dst.end.y),
57
 
      },
58
 
      .nr_samples = blitinfo->dst.planes[0].image->layout.nr_samples,
59
 
   };
60
 
 
61
 
   fbinfo->extent.maxx = MIN2(fbinfo->extent.maxx, fbinfo->width - 1);
62
 
   fbinfo->extent.maxy = MIN2(fbinfo->extent.maxy, fbinfo->height - 1);
63
 
 
64
 
   /* TODO: don't force preloads of dst resources if unneeded */
65
 
 
66
 
   const struct util_format_description *fdesc =
67
 
      util_format_description(blitinfo->dst.planes[0].image->layout.format);
68
 
 
69
 
   if (util_format_has_depth(fdesc)) {
70
 
      /* We want the image format here, otherwise we might lose one of the
71
 
       * component.
72
 
       */
73
 
      views[0].format = blitinfo->dst.planes[0].image->layout.format;
74
 
      fbinfo->zs.view.zs = &views[0];
75
 
      fbinfo->zs.preload.z = true;
76
 
      fbinfo->zs.preload.s = util_format_has_stencil(fdesc);
77
 
   } else if (util_format_has_stencil(fdesc)) {
78
 
      fbinfo->zs.view.s = &views[0];
79
 
      fbinfo->zs.preload.s = true;
80
 
   } else {
81
 
      fbinfo->rt_count = 1;
82
 
      fbinfo->rts[0].view = &views[0];
83
 
      fbinfo->rts[0].preload = true;
84
 
      cmdbuf->state.fb.crc_valid[0] = false;
85
 
      fbinfo->rts[0].crc_valid = &cmdbuf->state.fb.crc_valid[0];
86
 
   }
87
 
 
88
 
   if (blitinfo->dst.planes[1].format != PIPE_FORMAT_NONE) {
89
 
      /* TODO: don't force preloads of dst resources if unneeded */
90
 
      views[1].format = blitinfo->dst.planes[1].format;
91
 
      views[1].dim = MALI_TEXTURE_DIMENSION_2D;
92
 
      views[1].image = blitinfo->dst.planes[1].image;
93
 
      views[1].nr_samples = blitinfo->dst.planes[1].image->layout.nr_samples;
94
 
      views[1].first_level = blitinfo->dst.level;
95
 
      views[1].last_level = blitinfo->dst.level;
96
 
      views[1].swizzle[0] = PIPE_SWIZZLE_X;
97
 
      views[1].swizzle[1] = PIPE_SWIZZLE_Y;
98
 
      views[1].swizzle[2] = PIPE_SWIZZLE_Z;
99
 
      views[1].swizzle[3] = PIPE_SWIZZLE_W;
100
 
      fbinfo->zs.view.s = &views[1];
101
 
   }
102
 
 
103
 
   panvk_per_arch(cmd_close_batch)(cmdbuf);
104
 
 
105
 
   GENX(pan_blit_ctx_init)(pdev, blitinfo, &cmdbuf->desc_pool.base, &ctx);
106
 
   do {
107
 
      if (ctx.dst.cur_layer < 0)
108
 
         continue;
109
 
 
110
 
      struct panvk_batch *batch = panvk_cmd_open_batch(cmdbuf);
111
 
      mali_ptr tsd, tiler;
112
 
 
113
 
      views[0].first_layer = views[0].last_layer = ctx.dst.cur_layer;
114
 
      views[1].first_layer = views[1].last_layer = views[0].first_layer;
115
 
      batch->blit.src = blitinfo->src.planes[0].image->data.bo;
116
 
      batch->blit.dst = blitinfo->dst.planes[0].image->data.bo;
117
 
      panvk_per_arch(cmd_alloc_tls_desc)(cmdbuf, true);
118
 
      panvk_per_arch(cmd_alloc_fb_desc)(cmdbuf);
119
 
      panvk_per_arch(cmd_prepare_tiler_context)(cmdbuf);
120
 
 
121
 
#if PAN_ARCH >= 6
122
 
      tsd = batch->tls.gpu;
123
 
      tiler = batch->tiler.descs.gpu;
124
 
#else
125
 
      tsd = batch->fb.desc.gpu;
126
 
      tiler = 0;
127
 
#endif
128
 
 
129
 
      struct panfrost_ptr job =
130
 
         GENX(pan_blit)(&ctx, &cmdbuf->desc_pool.base, &batch->scoreboard, tsd, tiler);
131
 
      util_dynarray_append(&batch->jobs, void *, job.cpu);
132
 
      panvk_per_arch(cmd_close_batch)(cmdbuf);
133
 
   } while (pan_blit_next_surface(&ctx));
134
 
}
135
 
 
136
 
void
137
 
panvk_per_arch(CmdBlitImage2)(VkCommandBuffer commandBuffer,
138
 
                              const VkBlitImageInfo2 *pBlitImageInfo)
139
 
{
140
 
   VK_FROM_HANDLE(panvk_cmd_buffer, cmdbuf, commandBuffer);
141
 
   VK_FROM_HANDLE(panvk_image, src, pBlitImageInfo->srcImage);
142
 
   VK_FROM_HANDLE(panvk_image, dst, pBlitImageInfo->dstImage);
143
 
 
144
 
   for (unsigned i = 0; i < pBlitImageInfo->regionCount; i++) {
145
 
      const VkImageBlit2 *region = &pBlitImageInfo->pRegions[i];
146
 
      struct pan_blit_info info = {
147
 
         .src = {
148
 
            .planes[0].image = &src->pimage,
149
 
            .planes[0].format = src->pimage.layout.format,
150
 
            .level = region->srcSubresource.mipLevel,
151
 
            .start = {
152
 
               region->srcOffsets[0].x,
153
 
               region->srcOffsets[0].y,
154
 
               region->srcOffsets[0].z,
155
 
               region->srcSubresource.baseArrayLayer,
156
 
            },
157
 
            .end = {
158
 
               region->srcOffsets[1].x,
159
 
               region->srcOffsets[1].y,
160
 
               region->srcOffsets[1].z,
161
 
               region->srcSubresource.baseArrayLayer + region->srcSubresource.layerCount - 1,
162
 
            },
163
 
         },
164
 
         .dst = {
165
 
            .planes[0].image = &dst->pimage,
166
 
            .planes[0].format = dst->pimage.layout.format,
167
 
            .level = region->dstSubresource.mipLevel,
168
 
            .start = {
169
 
               region->dstOffsets[0].x,
170
 
               region->dstOffsets[0].y,
171
 
               region->dstOffsets[0].z,
172
 
               region->dstSubresource.baseArrayLayer,
173
 
            },
174
 
            .end = {
175
 
               region->dstOffsets[1].x,
176
 
               region->dstOffsets[1].y,
177
 
               region->dstOffsets[1].z,
178
 
               region->dstSubresource.baseArrayLayer + region->dstSubresource.layerCount - 1,
179
 
            },
180
 
         },
181
 
         .nearest = pBlitImageInfo->filter == VK_FILTER_NEAREST,
182
 
      };
183
 
 
184
 
      if (region->srcSubresource.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT)
185
 
         info.src.planes[0].format = util_format_stencil_only(info.src.planes[0].format);
186
 
      else if (region->srcSubresource.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT)
187
 
         info.src.planes[0].format = util_format_get_depth_only(info.src.planes[0].format);
188
 
 
189
 
      if (region->dstSubresource.aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT)
190
 
         info.dst.planes[0].format = util_format_stencil_only(info.dst.planes[0].format);
191
 
      else if (region->dstSubresource.aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT)
192
 
         info.dst.planes[0].format = util_format_get_depth_only(info.dst.planes[0].format);
193
 
 
194
 
      panvk_meta_blit(cmdbuf, &info);
195
 
   }
196
 
}
197
 
 
198
 
void
199
 
panvk_per_arch(CmdResolveImage2)(VkCommandBuffer commandBuffer,
200
 
                                 const VkResolveImageInfo2* pResolveImageInfo)
201
 
{
202
 
   panvk_stub();
203
 
}
204
 
 
205
 
void
206
 
panvk_per_arch(meta_blit_init)(struct panvk_physical_device *dev)
207
 
{
208
 
   panvk_pool_init(&dev->meta.blitter.bin_pool, &dev->pdev, NULL,
209
 
                   PAN_BO_EXECUTE, 16 * 1024,
210
 
                   "panvk_meta blitter binary pool", false);
211
 
   panvk_pool_init(&dev->meta.blitter.desc_pool, &dev->pdev, NULL,
212
 
                   0, 16 * 1024, "panvk_meta blitter descriptor pool",
213
 
                   false);
214
 
   pan_blend_shaders_init(&dev->pdev);
215
 
   GENX(pan_blitter_init)(&dev->pdev, &dev->meta.blitter.bin_pool.base,
216
 
                          &dev->meta.blitter.desc_pool.base);
217
 
}
218
 
 
219
 
void
220
 
panvk_per_arch(meta_blit_cleanup)(struct panvk_physical_device *dev)
221
 
{
222
 
   GENX(pan_blitter_cleanup)(&dev->pdev);
223
 
   pan_blend_shaders_cleanup(&dev->pdev);
224
 
   panvk_pool_cleanup(&dev->meta.blitter.desc_pool);
225
 
   panvk_pool_cleanup(&dev->meta.blitter.bin_pool);
226
 
}