blob: 1f504294bda804b4102a660a80b99a0e308882a7 [file] [log] [blame]
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +00001/*
2 * Copyright 2018-2019 Alyssa Rosenzweig
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 */
24
25#include "pan_context.h"
26#include "pan_util.h"
27#include "pan_format.h"
28
29#include "util/u_format.h"
30
Alyssa Rosenzweig5cfb4242019-06-25 08:51:48 -070031static void
32panfrost_invert_swizzle(const unsigned char *in, unsigned char *out)
33{
34 /* First, default to all zeroes to prevent uninitialized junk */
35
36 for (unsigned c = 0; c < 4; ++c)
37 out[c] = PIPE_SWIZZLE_0;
38
39 /* Now "do" what the swizzle says */
40
41 for (unsigned c = 0; c < 4; ++c) {
42 unsigned char i = in[c];
43
44 /* Who cares? */
45 if (i < PIPE_SWIZZLE_X || i > PIPE_SWIZZLE_W)
46 continue;
47
48 /* Invert */
49 unsigned idx = i - PIPE_SWIZZLE_X;
50 out[idx] = PIPE_SWIZZLE_X + c;
51 }
52}
53
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +000054static struct mali_rt_format
55panfrost_mfbd_format(struct pipe_surface *surf)
56{
57 /* Explode details on the format */
58
59 const struct util_format_description *desc =
Alyssa Rosenzweig5cfb4242019-06-25 08:51:48 -070060 util_format_description(surf->format);
61
62 /* The swizzle for rendering is inverted from texturing */
63
64 unsigned char swizzle[4];
65 panfrost_invert_swizzle(desc->swizzle, swizzle);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +000066
Alyssa Rosenzweig4b137da2019-06-17 16:19:33 -070067 /* Fill in accordingly, defaulting to 8-bit UNORM */
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +000068
69 struct mali_rt_format fmt = {
70 .unk1 = 0x4000000,
71 .unk2 = 0x1,
72 .nr_channels = MALI_POSITIVE(desc->nr_channels),
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -070073 .unk3 = 0x4,
74 .flags = 0x8,
Alyssa Rosenzweig5cfb4242019-06-25 08:51:48 -070075 .swizzle = panfrost_translate_swizzle_4(swizzle),
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -070076 .no_preload = true
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +000077 };
78
Alyssa Rosenzweig4b137da2019-06-17 16:19:33 -070079 if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
80 fmt.flags |= MALI_MFBD_FORMAT_SRGB;
81
Alyssa Rosenzweigced132d2019-07-05 06:26:48 -070082 /* sRGB handled as a dedicated flag */
83 enum pipe_format linearized = util_format_linear(surf->format);
84
85 /* If RGB, we're good to go */
86 if (util_format_is_unorm8(desc))
87 return fmt;
88
Alyssa Rosenzweig31f5a432019-05-02 02:27:04 +000089 /* Set flags for alternative formats */
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -070090
Alyssa Rosenzweigced132d2019-07-05 06:26:48 -070091 switch (linearized) {
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -070092 case PIPE_FORMAT_B5G6R5_UNORM:
93 fmt.unk1 = 0x14000000;
94 fmt.nr_channels = MALI_POSITIVE(2);
95 fmt.unk3 |= 0x1;
96 break;
Alyssa Rosenzweig31f5a432019-05-02 02:27:04 +000097
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -070098 case PIPE_FORMAT_A4B4G4R4_UNORM:
99 case PIPE_FORMAT_B4G4R4A4_UNORM:
100 fmt.unk1 = 0x10000000;
101 fmt.unk3 = 0x5;
102 fmt.nr_channels = MALI_POSITIVE(1);
103 break;
Alyssa Rosenzweig21c863a2019-07-01 09:44:40 -0700104
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700105 case PIPE_FORMAT_R10G10B10A2_UNORM:
106 case PIPE_FORMAT_B10G10R10A2_UNORM:
107 case PIPE_FORMAT_R10G10B10X2_UNORM:
108 case PIPE_FORMAT_B10G10R10X2_UNORM:
109 fmt.unk1 = 0x08000000;
110 fmt.unk3 = 0x6;
111 fmt.nr_channels = MALI_POSITIVE(1);
112 break;
Alyssa Rosenzweig21c863a2019-07-01 09:44:40 -0700113
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700114 /* Generic 8-bit */
115 case PIPE_FORMAT_R8_UINT:
116 case PIPE_FORMAT_R8_SINT:
117 fmt.unk1 = 0x80000000;
118 fmt.unk3 = 0x0;
119 fmt.nr_channels = MALI_POSITIVE(1);
120 break;
Alyssa Rosenzweigc0c709a2019-07-05 15:59:22 -0700121
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700122 /* Generic 32-bit */
123 case PIPE_FORMAT_R11G11B10_FLOAT:
124 case PIPE_FORMAT_R8G8B8A8_UINT:
125 case PIPE_FORMAT_R8G8B8A8_SINT:
126 case PIPE_FORMAT_R16G16_FLOAT:
127 case PIPE_FORMAT_R16G16_UINT:
128 case PIPE_FORMAT_R16G16_SINT:
129 case PIPE_FORMAT_R32_FLOAT:
130 case PIPE_FORMAT_R32_UINT:
131 case PIPE_FORMAT_R32_SINT:
132 case PIPE_FORMAT_R10G10B10A2_UINT:
133 fmt.unk1 = 0x88000000;
134 fmt.unk3 = 0x0;
135 fmt.nr_channels = MALI_POSITIVE(4);
136 break;
Alyssa Rosenzweig21c863a2019-07-01 09:44:40 -0700137
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700138 /* Generic 16-bit */
139 case PIPE_FORMAT_R8G8_UINT:
140 case PIPE_FORMAT_R8G8_SINT:
141 case PIPE_FORMAT_R16_FLOAT:
142 case PIPE_FORMAT_R16_UINT:
143 case PIPE_FORMAT_R16_SINT:
144 case PIPE_FORMAT_B5G5R5A1_UNORM:
145 fmt.unk1 = 0x84000000;
146 fmt.unk3 = 0x0;
147 fmt.nr_channels = MALI_POSITIVE(2);
148 break;
Alyssa Rosenzweig21c863a2019-07-01 09:44:40 -0700149
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700150 /* Generic 64-bit */
151 case PIPE_FORMAT_R32G32_FLOAT:
152 case PIPE_FORMAT_R32G32_SINT:
153 case PIPE_FORMAT_R32G32_UINT:
154 case PIPE_FORMAT_R16G16B16A16_FLOAT:
155 case PIPE_FORMAT_R16G16B16A16_SINT:
156 case PIPE_FORMAT_R16G16B16A16_UINT:
157 fmt.unk1 = 0x8c000000;
158 fmt.unk3 = 0x1;
159 fmt.nr_channels = MALI_POSITIVE(2);
160 break;
Alyssa Rosenzweigc2ee9372019-07-03 12:34:32 -0700161
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700162 /* Generic 128-bit */
163 case PIPE_FORMAT_R32G32B32A32_FLOAT:
164 case PIPE_FORMAT_R32G32B32A32_SINT:
165 case PIPE_FORMAT_R32G32B32A32_UINT:
166 fmt.unk1 = 0x90000000;
167 fmt.unk3 = 0x1;
168 fmt.nr_channels = MALI_POSITIVE(4);
169 break;
Alyssa Rosenzweigced132d2019-07-05 06:26:48 -0700170
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700171 default:
172 unreachable("Invalid format rendering");
Alyssa Rosenzweig31f5a432019-05-02 02:27:04 +0000173 }
174
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000175 return fmt;
176}
177
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000178
179static void
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000180panfrost_mfbd_clear(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700181 struct panfrost_job *job,
182 struct bifrost_framebuffer *fb,
183 struct bifrost_fb_extra *fbx,
184 struct bifrost_render_target *rts,
185 unsigned rt_count)
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000186{
Alyssa Rosenzweig8e4e4672019-07-01 11:49:06 -0700187 for (unsigned i = 0; i < rt_count; ++i) {
188 if (!(job->clear & (PIPE_CLEAR_COLOR0 << i)))
189 continue;
190
191 rts[i].clear_color_1 = job->clear_color[i][0];
192 rts[i].clear_color_2 = job->clear_color[i][1];
193 rts[i].clear_color_3 = job->clear_color[i][2];
194 rts[i].clear_color_4 = job->clear_color[i][3];
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000195 }
196
197 if (job->clear & PIPE_CLEAR_DEPTH) {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000198 fb->clear_depth = job->clear_depth;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000199 }
200
201 if (job->clear & PIPE_CLEAR_STENCIL) {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000202 fb->clear_stencil = job->clear_stencil;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000203 }
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000204}
205
206static void
207panfrost_mfbd_set_cbuf(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700208 struct bifrost_render_target *rt,
209 struct pipe_surface *surf)
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000210{
211 struct panfrost_resource *rsrc = pan_resource(surf->texture);
Alyssa Rosenzweigd4aed002019-06-12 15:23:19 -0700212
213 unsigned level = surf->u.tex.level;
Alyssa Rosenzweig65bc56b2019-06-21 17:23:49 -0700214 unsigned first_layer = surf->u.tex.first_layer;
Alyssa Rosenzweig64b7bd32019-06-21 17:39:02 -0700215 assert(surf->u.tex.last_layer == first_layer);
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200216 int stride = rsrc->slices[level].stride;
Alyssa Rosenzweig65bc56b2019-06-21 17:23:49 -0700217
218 mali_ptr base = panfrost_get_texture_address(rsrc, level, first_layer);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000219
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000220 rt->format = panfrost_mfbd_format(surf);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000221
222 /* Now, we set the layout specific pieces */
223
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200224 if (rsrc->layout == PAN_LINEAR) {
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700225 rt->format.block = MALI_MFBD_BLOCK_LINEAR;
Alyssa Rosenzweig65bc56b2019-06-21 17:23:49 -0700226 rt->framebuffer = base;
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000227 rt->framebuffer_stride = stride / 16;
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200228 } else if (rsrc->layout == PAN_TILED) {
Alyssa Rosenzweig01e1eec2019-06-17 15:56:48 -0700229 rt->format.block = MALI_MFBD_BLOCK_TILED;
Alyssa Rosenzweig65bc56b2019-06-21 17:23:49 -0700230 rt->framebuffer = base;
Alyssa Rosenzweig01e1eec2019-06-17 15:56:48 -0700231 rt->framebuffer_stride = stride;
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200232 } else if (rsrc->layout == PAN_AFBC) {
Alyssa Rosenzweigd5079512019-06-17 15:53:09 -0700233 rt->format.block = MALI_MFBD_BLOCK_AFBC;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000234
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200235 unsigned header_size = rsrc->slices[level].header_size;
Alyssa Rosenzweig3609b502019-06-21 14:54:44 -0700236
237 rt->framebuffer = base + header_size;
238 rt->afbc.metadata = base;
239 rt->afbc.stride = 0;
240 rt->afbc.unk = 0x30009;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000241
Alyssa Rosenzweigd6099492019-07-15 15:35:30 -0700242 /* TODO: The blob sets this to something nonzero, but it's not
243 * clear what/how to calculate/if it matters */
244 rt->framebuffer_stride = 0;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000245 } else {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000246 fprintf(stderr, "Invalid render layout (cbuf)");
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000247 assert(0);
248 }
249}
250
Alyssa Rosenzweig1aaf68d2019-07-15 07:10:31 -0700251/* Is a format encoded like Z24S8 and therefore compatible for render? */
252
253static bool
254panfrost_is_z24s8_variant(enum pipe_format fmt)
255{
256 switch (fmt) {
257 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
258 case PIPE_FORMAT_Z24X8_UNORM:
259 return true;
260 default:
261 return false;
262 }
263}
264
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000265static void
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000266panfrost_mfbd_set_zsbuf(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700267 struct bifrost_framebuffer *fb,
268 struct bifrost_fb_extra *fbx,
269 struct pipe_surface *surf)
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000270{
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000271 struct panfrost_resource *rsrc = pan_resource(surf->texture);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000272
Alyssa Rosenzweigd4aed002019-06-12 15:23:19 -0700273 unsigned level = surf->u.tex.level;
274 assert(surf->u.tex.first_layer == 0);
275
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200276 unsigned offset = rsrc->slices[level].offset;
Alyssa Rosenzweigd4aed002019-06-12 15:23:19 -0700277
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200278 if (rsrc->layout == PAN_AFBC) {
Alyssa Rosenzweig507e2972019-07-10 14:50:48 -0700279 /* The only Z/S format we can compress is Z24S8 or variants
280 * thereof (handled by the state tracker) */
Alyssa Rosenzweig1aaf68d2019-07-15 07:10:31 -0700281 assert(panfrost_is_z24s8_variant(surf->format));
Alyssa Rosenzweig507e2972019-07-10 14:50:48 -0700282
Alyssa Rosenzweig3609b502019-06-21 14:54:44 -0700283 mali_ptr base = rsrc->bo->gpu + offset;
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200284 unsigned header_size = rsrc->slices[level].header_size;
Alyssa Rosenzweig3609b502019-06-21 14:54:44 -0700285
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700286 fb->mfbd_flags |= MALI_MFBD_EXTRA;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000287
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000288 fbx->flags =
289 MALI_EXTRA_PRESENT |
290 MALI_EXTRA_AFBC |
291 MALI_EXTRA_AFBC_ZS |
292 MALI_EXTRA_ZS |
293 0x1; /* unknown */
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000294
Alyssa Rosenzweig3609b502019-06-21 14:54:44 -0700295 fbx->ds_afbc.depth_stencil = base + header_size;
296 fbx->ds_afbc.depth_stencil_afbc_metadata = base;
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000297 fbx->ds_afbc.depth_stencil_afbc_stride = 0;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000298
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000299 fbx->ds_afbc.zero1 = 0x10009;
300 fbx->ds_afbc.padding = 0x1000;
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200301 } else if (rsrc->layout == PAN_LINEAR) {
Alyssa Rosenzweig507e2972019-07-10 14:50:48 -0700302 /* TODO: Z32F(S8) support, which is always linear */
303
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200304 int stride = rsrc->slices[level].stride;
Alyssa Rosenzweigd4aed002019-06-12 15:23:19 -0700305
Alyssa Rosenzweig1aaf68d2019-07-15 07:10:31 -0700306 fb->mfbd_flags |= MALI_MFBD_EXTRA;
307 fbx->flags |= MALI_EXTRA_PRESENT | MALI_EXTRA_ZS;
Alyssa Rosenzweig9bf60242019-03-12 22:49:33 +0000308
Alyssa Rosenzweigd4aed002019-06-12 15:23:19 -0700309 fbx->ds_linear.depth = rsrc->bo->gpu + offset;
310 fbx->ds_linear.depth_stride = stride;
Alyssa Rosenzweig1aaf68d2019-07-15 07:10:31 -0700311
312 if (panfrost_is_z24s8_variant(surf->format)) {
313 fbx->flags |= 0x1;
314 } else if (surf->format == PIPE_FORMAT_Z32_UNORM) {
315 /* default flags (0 in bottom place) */
Alyssa Rosenzweig676b9332019-07-17 15:49:42 -0700316 } else if (surf->format == PIPE_FORMAT_Z32_FLOAT) {
317 fbx->flags |= 0xA;
318 fb->mfbd_flags ^= 0x100;
319 fb->mfbd_flags |= 0x200;
320 } else if (surf->format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
321 fbx->flags |= 0x1000A;
322 fb->mfbd_flags ^= 0x100;
323 fb->mfbd_flags |= 0x201;
324
325 struct panfrost_resource *stencil = rsrc->separate_stencil;
326 struct panfrost_slice stencil_slice = stencil->slices[level];
327
328 fbx->ds_linear.stencil = stencil->bo->gpu + stencil_slice.offset;
329 fbx->ds_linear.stencil_stride = stencil_slice.stride;
Alyssa Rosenzweig1aaf68d2019-07-15 07:10:31 -0700330 }
331
Alyssa Rosenzweig9bf60242019-03-12 22:49:33 +0000332 } else {
333 assert(0);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000334 }
335}
336
337/* Helper for sequential uploads used for MFBD */
338
339#define UPLOAD(dest, offset, src, max) { \
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000340 size_t sz = sizeof(*src); \
341 memcpy(dest.cpu + offset, src, sz); \
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000342 assert((offset + sz) <= max); \
343 offset += sz; \
344}
345
346static mali_ptr
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000347panfrost_mfbd_upload(
Alyssa Rosenzweiga2d0ea92019-07-10 10:10:31 -0700348 struct panfrost_context *ctx,
349 struct bifrost_framebuffer *fb,
350 struct bifrost_fb_extra *fbx,
351 struct bifrost_render_target *rts,
352 unsigned cbufs)
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000353{
354 off_t offset = 0;
355
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000356 /* There may be extra data stuck in the middle */
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700357 bool has_extra = fb->mfbd_flags & MALI_MFBD_EXTRA;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000358
359 /* Compute total size for transfer */
360
361 size_t total_sz =
362 sizeof(struct bifrost_framebuffer) +
363 (has_extra ? sizeof(struct bifrost_fb_extra) : 0) +
364 sizeof(struct bifrost_render_target) * cbufs;
365
366 struct panfrost_transfer m_f_trans =
367 panfrost_allocate_transient(ctx, total_sz);
368
369 /* Do the transfer */
370
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000371 UPLOAD(m_f_trans, offset, fb, total_sz);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000372
373 if (has_extra)
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000374 UPLOAD(m_f_trans, offset, fbx, total_sz);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000375
376 for (unsigned c = 0; c < cbufs; ++c) {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000377 UPLOAD(m_f_trans, offset, &rts[c], total_sz);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000378 }
379
Alyssa Rosenzweig79e474f2019-03-13 00:53:18 +0000380 /* Return pointer suitable for the fragment section */
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000381 return m_f_trans.gpu | MALI_MFBD | (has_extra ? 2 : 0);
382}
383
384#undef UPLOAD
385
386/* Creates an MFBD for the FRAGMENT section of the bound framebuffer */
387
388mali_ptr
Alyssa Rosenzweigf9ecca22019-06-14 11:23:24 -0700389panfrost_mfbd_fragment(struct panfrost_context *ctx, bool has_draws)
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000390{
391 struct panfrost_job *job = panfrost_get_job_for_fbo(ctx);
392
Alyssa Rosenzweigf9ecca22019-06-14 11:23:24 -0700393 struct bifrost_framebuffer fb = panfrost_emit_mfbd(ctx, has_draws);
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000394 struct bifrost_fb_extra fbx = {};
395 struct bifrost_render_target rts[4] = {};
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000396
Alyssa Rosenzweig0395b582019-07-18 12:43:39 -0700397 /* We always upload at least one dummy GL_NONE render target */
398
399 unsigned rt_descriptors =
400 MAX2(ctx->pipe_framebuffer.nr_cbufs, 1);
401
402 fb.rt_count_1 = MALI_POSITIVE(rt_descriptors);
403 fb.rt_count_2 = rt_descriptors;
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700404 fb.mfbd_flags = 0x100;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000405
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000406 /* TODO: MRT clear */
Alyssa Rosenzweig8e4e4672019-07-01 11:49:06 -0700407 panfrost_mfbd_clear(job, &fb, &fbx, rts, fb.rt_count_2);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000408
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700409
410 /* Upload either the render target or a dummy GL_NONE target */
411
412 for (int cb = 0; cb < rt_descriptors; ++cb) {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000413 struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[cb];
Alyssa Rosenzweig227c3952019-07-18 10:59:59 -0700414
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700415 if (surf) {
416 panfrost_mfbd_set_cbuf(&rts[cb], surf);
Alyssa Rosenzweig227c3952019-07-18 10:59:59 -0700417
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700418 /* What is this? Looks like some extension of the bpp
419 * field. Maybe it establishes how much internal
420 * tilebuffer space is reserved? */
Alyssa Rosenzweig7647e562019-07-02 09:54:23 -0700421
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700422 unsigned bpp = util_format_get_blocksize(surf->format);
423 fb.rt_count_2 = MAX2(fb.rt_count_2, ALIGN_POT(bpp, 4) / 4);
424 } else {
425 struct mali_rt_format null_rt = {
426 .unk1 = 0x4000000,
Alyssa Rosenzweigb78e04c2019-08-14 16:01:38 -0700427 .no_preload = true
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700428 };
Alyssa Rosenzweig7647e562019-07-02 09:54:23 -0700429
Alyssa Rosenzweigf475b792019-07-18 11:09:19 -0700430 rts[cb].format = null_rt;
431 rts[cb].framebuffer = 0;
432 rts[cb].framebuffer_stride = 0;
433 }
Alyssa Rosenzweig0395b582019-07-18 12:43:39 -0700434
435 /* TODO: Break out the field */
436 rts[cb].format.unk1 |= (cb * 0x400);
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000437 }
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000438
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000439 if (ctx->pipe_framebuffer.zsbuf) {
440 panfrost_mfbd_set_zsbuf(&fb, &fbx, ctx->pipe_framebuffer.zsbuf);
441 }
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000442
Alyssa Rosenzweig8c268902019-03-12 23:16:37 +0000443 /* When scanning out, the depth buffer is immediately invalidated, so
444 * we don't need to waste bandwidth writing it out. This can improve
445 * performance substantially (Z32_UNORM 1080p @ 60fps is 475 MB/s of
446 * memory bandwidth!).
447 *
448 * The exception is ReadPixels, but this is not supported on GLES so we
449 * can safely ignore it. */
450
451 if (panfrost_is_scanout(ctx)) {
452 job->requirements &= ~PAN_REQ_DEPTH_WRITE;
453 }
454
455 /* Actualize the requirements */
456
457 if (job->requirements & PAN_REQ_MSAA) {
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000458 rts[0].format.flags |= MALI_MFBD_FORMAT_MSAA;
459
460 /* XXX */
461 fb.unk1 |= (1 << 4) | (1 << 1);
462 fb.rt_count_2 = 4;
463 }
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000464
Alyssa Rosenzweig8c268902019-03-12 23:16:37 +0000465 if (job->requirements & PAN_REQ_DEPTH_WRITE)
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700466 fb.mfbd_flags |= MALI_MFBD_DEPTH_WRITE;
Alyssa Rosenzweig8c268902019-03-12 23:16:37 +0000467
Alyssa Rosenzweig3e6c6bb2019-06-24 07:08:52 -0700468 /* Checksumming only works with a single render target */
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000469
Alyssa Rosenzweig3e6c6bb2019-06-24 07:08:52 -0700470 if (ctx->pipe_framebuffer.nr_cbufs == 1) {
471 struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[0];
472 struct panfrost_resource *rsrc = pan_resource(surf->texture);
473 struct panfrost_bo *bo = rsrc->bo;
474
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200475 if (rsrc->checksummed) {
Alyssa Rosenzweig3e6c6bb2019-06-24 07:08:52 -0700476 unsigned level = surf->u.tex.level;
Boris Brezillonaa5bc352019-07-02 11:37:40 +0200477 struct panfrost_slice *slice = &rsrc->slices[level];
Alyssa Rosenzweig3e6c6bb2019-06-24 07:08:52 -0700478
Alyssa Rosenzweigac689462019-06-14 11:14:01 -0700479 fb.mfbd_flags |= MALI_MFBD_EXTRA;
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000480 fbx.flags |= MALI_EXTRA_PRESENT;
Alyssa Rosenzweig3e6c6bb2019-06-24 07:08:52 -0700481 fbx.checksum_stride = slice->checksum_stride;
482 fbx.checksum = bo->gpu + slice->checksum_offset;
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000483 }
484 }
485
Alyssa Rosenzweigc119c282019-03-12 22:41:11 +0000486 /* We always upload at least one (dummy) cbuf */
487 unsigned cbufs = MAX2(ctx->pipe_framebuffer.nr_cbufs, 1);
488
489 return panfrost_mfbd_upload(ctx, &fb, &fbx, rts, cbufs);
Alyssa Rosenzweig9dd84db2019-03-12 03:32:17 +0000490}