freedreno/a6xx: Copy stencil as R8_UINT
[mesa.git] / src / gallium / drivers / freedreno / a6xx / fd6_blitter.c
1 /*
2 * Copyright (C) 2017 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 * Authors:
25 * Rob Clark <robclark@freedesktop.org>
26 */
27
28 #include "util/u_dump.h"
29
30 #include "freedreno_blitter.h"
31 #include "freedreno_fence.h"
32 #include "freedreno_resource.h"
33
34 #include "fd6_blitter.h"
35 #include "fd6_format.h"
36 #include "fd6_emit.h"
37
38 /* Make sure none of the requested dimensions extend beyond the size of the
39 * resource. Not entirely sure why this happens, but sometimes it does, and
40 * w/ 2d blt doesn't have wrap modes like a sampler, so force those cases
41 * back to u_blitter
42 */
43 static bool
44 ok_dims(const struct pipe_resource *r, const struct pipe_box *b, int lvl)
45 {
46 int last_layer =
47 r->target == PIPE_TEXTURE_3D ? u_minify(r->depth0, lvl)
48 : r->array_size;
49
50 return (b->x >= 0) && (b->x + b->width <= u_minify(r->width0, lvl)) &&
51 (b->y >= 0) && (b->y + b->height <= u_minify(r->height0, lvl)) &&
52 (b->z >= 0) && (b->z + b->depth <= last_layer);
53 }
54
55 static bool
56 ok_format(enum pipe_format pfmt)
57 {
58 enum a6xx_color_fmt fmt = fd6_pipe2color(pfmt);
59
60 switch (pfmt) {
61 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
62 case PIPE_FORMAT_Z24X8_UNORM:
63 case PIPE_FORMAT_Z16_UNORM:
64 case PIPE_FORMAT_Z32_UNORM:
65 case PIPE_FORMAT_Z32_FLOAT:
66 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
67 case PIPE_FORMAT_S8_UINT:
68 return true;
69 default:
70 break;
71 }
72
73 if (fmt == ~0)
74 return false;
75
76 if (fd6_ifmt(fmt) == 0)
77 return false;
78
79 return true;
80 }
81
82 #define DEBUG_BLIT_FALLBACK 0
83 #define fail_if(cond) \
84 do { \
85 if (cond) { \
86 if (DEBUG_BLIT_FALLBACK) { \
87 fprintf(stderr, "falling back: %s for blit:\n", #cond); \
88 util_dump_blit_info(stderr, info); \
89 fprintf(stderr, "\nsrc: "); \
90 util_dump_resource(stderr, info->src.resource); \
91 fprintf(stderr, "\ndst: "); \
92 util_dump_resource(stderr, info->dst.resource); \
93 fprintf(stderr, "\n"); \
94 } \
95 return false; \
96 } \
97 } while (0)
98
99 static bool
100 can_do_blit(const struct pipe_blit_info *info)
101 {
102 /* I think we can do scaling, but not in z dimension since that would
103 * require blending..
104 */
105 fail_if(info->dst.box.depth != info->src.box.depth);
106
107 /* Fail if unsupported format: */
108 fail_if(!ok_format(info->src.format));
109 fail_if(!ok_format(info->dst.format));
110
111 /* We can blit if both or neither formats are compressed formats... */
112 fail_if(util_format_is_compressed(info->src.format) !=
113 util_format_is_compressed(info->src.format));
114
115 /* ... but only if they're the same compression format. */
116 fail_if(util_format_is_compressed(info->src.format) &&
117 info->src.format != info->dst.format);
118
119 fail_if(!ok_dims(info->src.resource, &info->src.box, info->src.level));
120
121 fail_if(!ok_dims(info->dst.resource, &info->dst.box, info->dst.level));
122
123 debug_assert(info->dst.box.width >= 0);
124 debug_assert(info->dst.box.height >= 0);
125 debug_assert(info->dst.box.depth >= 0);
126
127 /* non-multisampled could either have nr_samples == 0 or == 1 */
128 fail_if(info->dst.resource->nr_samples > 1);
129 fail_if(info->src.resource->nr_samples > 1);
130
131 fail_if(info->window_rectangle_include);
132
133 fail_if(util_format_is_srgb(info->src.format));
134 fail_if(util_format_is_srgb(info->dst.format));
135
136 const struct util_format_description *src_desc =
137 util_format_description(info->src.format);
138 const struct util_format_description *dst_desc =
139 util_format_description(info->dst.format);
140 const int common_channels = MIN2(src_desc->nr_channels, dst_desc->nr_channels);
141
142 if (info->mask & PIPE_MASK_RGBA) {
143 for (int i = 0; i < common_channels; i++) {
144 fail_if(memcmp(&src_desc->channel[i],
145 &dst_desc->channel[i],
146 sizeof(src_desc->channel[0])));
147 }
148 }
149
150 fail_if(info->alpha_blend);
151
152 return true;
153 }
154
155 static void
156 emit_setup(struct fd_ringbuffer *ring)
157 {
158 OUT_PKT7(ring, CP_EVENT_WRITE, 1);
159 OUT_RING(ring, PC_CCU_INVALIDATE_COLOR);
160
161 OUT_PKT7(ring, CP_EVENT_WRITE, 1);
162 OUT_RING(ring, LRZ_FLUSH);
163
164 OUT_PKT7(ring, CP_SKIP_IB2_ENABLE_GLOBAL, 1);
165 OUT_RING(ring, 0x0);
166
167 OUT_WFI5(ring);
168
169 OUT_PKT4(ring, REG_A6XX_RB_CCU_CNTL, 1);
170 OUT_RING(ring, 0x10000000);
171 }
172
173 static uint32_t
174 blit_control(enum a6xx_color_fmt fmt)
175 {
176 unsigned blit_cntl = 0xf00000;
177 blit_cntl |= A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt);
178 blit_cntl |= A6XX_RB_2D_BLIT_CNTL_IFMT(fd6_ifmt(fmt));
179 return blit_cntl;
180 }
181
182 /* buffers need to be handled specially since x/width can exceed the bounds
183 * supported by hw.. if necessary decompose into (potentially) two 2D blits
184 */
185 static void
186 emit_blit_buffer(struct fd_ringbuffer *ring, const struct pipe_blit_info *info)
187 {
188 const struct pipe_box *sbox = &info->src.box;
189 const struct pipe_box *dbox = &info->dst.box;
190 struct fd_resource *src, *dst;
191 unsigned sshift, dshift;
192
193 if (DEBUG_BLIT_FALLBACK) {
194 fprintf(stderr, "buffer blit: ");
195 util_dump_blit_info(stderr, info);
196 fprintf(stderr, "\ndst resource: ");
197 util_dump_resource(stderr, info->dst.resource);
198 fprintf(stderr, "\nsrc resource: ");
199 util_dump_resource(stderr, info->src.resource);
200 fprintf(stderr, "\n");
201 }
202
203 src = fd_resource(info->src.resource);
204 dst = fd_resource(info->dst.resource);
205
206 debug_assert(src->cpp == 1);
207 debug_assert(dst->cpp == 1);
208 debug_assert(info->src.resource->format == info->dst.resource->format);
209 debug_assert((sbox->y == 0) && (sbox->height == 1));
210 debug_assert((dbox->y == 0) && (dbox->height == 1));
211 debug_assert((sbox->z == 0) && (sbox->depth == 1));
212 debug_assert((dbox->z == 0) && (dbox->depth == 1));
213 debug_assert(sbox->width == dbox->width);
214 debug_assert(info->src.level == 0);
215 debug_assert(info->dst.level == 0);
216
217 /*
218 * Buffers can have dimensions bigger than max width, remap into
219 * multiple 1d blits to fit within max dimension
220 *
221 * Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
222 * seems to prevent overfetch related faults. Not quite sure what
223 * the deal is there.
224 *
225 * Low 6 bits of SRC/DST addresses need to be zero (ie. address
226 * aligned to 64) so we need to shift src/dst x1/x2 to make up the
227 * difference. On top of already splitting up the blit so width
228 * isn't > 16k.
229 *
230 * We perhaps could do a bit better, if src and dst are aligned but
231 * in the worst case this means we have to split the copy up into
232 * 16k (0x4000) minus 64 (0x40).
233 */
234
235 sshift = sbox->x & 0x3f;
236 dshift = dbox->x & 0x3f;
237
238 OUT_PKT7(ring, CP_SET_MARKER, 1);
239 OUT_RING(ring, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
240
241 uint32_t blit_cntl = blit_control(RB6_R8_UNORM) | 0x20000000;
242 OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);
243 OUT_RING(ring, blit_cntl);
244
245 OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);
246 OUT_RING(ring, blit_cntl);
247
248 for (unsigned off = 0; off < sbox->width; off += (0x4000 - 0x40)) {
249 unsigned soff, doff, w, p;
250
251 soff = (sbox->x + off) & ~0x3f;
252 doff = (dbox->x + off) & ~0x3f;
253
254 w = MIN2(sbox->width - off, (0x4000 - 0x40));
255 p = align(w, 64);
256
257 debug_assert((soff + w) <= fd_bo_size(src->bo));
258 debug_assert((doff + w) <= fd_bo_size(dst->bo));
259
260 /*
261 * Emit source:
262 */
263 OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);
264 OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(RB6_R8_UNORM) |
265 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR) |
266 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX) | 0x500000);
267 OUT_RING(ring, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift + w) |
268 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
269 OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */
270 OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p));
271
272 OUT_RING(ring, 0x00000000);
273 OUT_RING(ring, 0x00000000);
274 OUT_RING(ring, 0x00000000);
275 OUT_RING(ring, 0x00000000);
276 OUT_RING(ring, 0x00000000);
277
278 OUT_RING(ring, 0x00000000);
279 OUT_RING(ring, 0x00000000);
280 OUT_RING(ring, 0x00000000);
281
282 /*
283 * Emit destination:
284 */
285 OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
286 OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(RB6_R8_UNORM) |
287 A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |
288 A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));
289 OUT_RELOC(ring, dst->bo, doff, 0, 0); /* RB_2D_DST_LO/HI */
290 OUT_RING(ring, A6XX_RB_2D_DST_SIZE_PITCH(p));
291 OUT_RING(ring, 0x00000000);
292 OUT_RING(ring, 0x00000000);
293 OUT_RING(ring, 0x00000000);
294 OUT_RING(ring, 0x00000000);
295 OUT_RING(ring, 0x00000000);
296
297 /*
298 * Blit command:
299 */
300 OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
301 OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X_X(sshift));
302 OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X_X(sshift + w - 1));
303 OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y_Y(0));
304 OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y_Y(0));
305
306 OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
307 OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dshift) | A6XX_GRAS_2D_DST_TL_Y(0));
308 OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dshift + w - 1) | A6XX_GRAS_2D_DST_BR_Y(0));
309
310 OUT_PKT7(ring, CP_EVENT_WRITE, 1);
311 OUT_RING(ring, 0x3f);
312 OUT_WFI5(ring);
313
314 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8C01, 1);
315 OUT_RING(ring, 0);
316
317 OUT_PKT4(ring, REG_A6XX_SP_2D_SRC_FORMAT, 1);
318 OUT_RING(ring, 0xf180);
319
320 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
321 OUT_RING(ring, 0x01000000);
322
323 OUT_PKT7(ring, CP_BLIT, 1);
324 OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
325
326 OUT_WFI5(ring);
327
328 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
329 OUT_RING(ring, 0);
330 }
331 }
332
333 static void
334 emit_blit_texture(struct fd_ringbuffer *ring, const struct pipe_blit_info *info)
335 {
336 const struct pipe_box *sbox = &info->src.box;
337 const struct pipe_box *dbox = &info->dst.box;
338 struct fd_resource *src, *dst;
339 struct fd_resource_slice *sslice, *dslice;
340 enum a6xx_color_fmt sfmt, dfmt;
341 enum a6xx_tile_mode stile, dtile;
342 enum a3xx_color_swap sswap, dswap;
343 unsigned spitch, dpitch;
344 int sx1, sy1, sx2, sy2;
345 int dx1, dy1, dx2, dy2;
346
347 if (DEBUG_BLIT_FALLBACK) {
348 fprintf(stderr, "texture blit: ");
349 util_dump_blit_info(stderr, info);
350 fprintf(stderr, "\ndst resource: ");
351 util_dump_resource(stderr, info->dst.resource);
352 fprintf(stderr, "\nsrc resource: ");
353 util_dump_resource(stderr, info->src.resource);
354 fprintf(stderr, "\n");
355 }
356
357 src = fd_resource(info->src.resource);
358 dst = fd_resource(info->dst.resource);
359
360 sslice = fd_resource_slice(src, info->src.level);
361 dslice = fd_resource_slice(dst, info->dst.level);
362
363 sfmt = fd6_pipe2color(info->src.format);
364 dfmt = fd6_pipe2color(info->dst.format);
365
366 int blocksize = util_format_get_blocksize(info->src.format);
367 int blockwidth = util_format_get_blockwidth(info->src.format);
368 int blockheight = util_format_get_blockheight(info->src.format);
369 int nelements;
370
371 stile = fd_resource_level_linear(info->src.resource, info->src.level) ?
372 TILE6_LINEAR : src->tile_mode;
373 dtile = fd_resource_level_linear(info->dst.resource, info->dst.level) ?
374 TILE6_LINEAR : dst->tile_mode;
375
376 sswap = stile ? WZYX : fd6_pipe2swap(info->src.format);
377 dswap = dtile ? WZYX : fd6_pipe2swap(info->dst.format);
378
379 if (util_format_is_compressed(info->src.format)) {
380 debug_assert(info->src.format == info->dst.format);
381 sfmt = dfmt = RB6_R8_UNORM;
382 nelements = blocksize;
383 } else {
384 debug_assert(!util_format_is_compressed(info->dst.format));
385 nelements = 1;
386 }
387
388 spitch = DIV_ROUND_UP(sslice->pitch, blockwidth) * src->cpp;
389 dpitch = DIV_ROUND_UP(dslice->pitch, blockwidth) * dst->cpp;
390
391 sx1 = sbox->x / blockwidth * nelements;
392 sy1 = sbox->y / blockheight;
393 sx2 = DIV_ROUND_UP(sbox->x + sbox->width, blockwidth) * nelements - 1;
394 sy2 = DIV_ROUND_UP(sbox->y + sbox->height, blockheight) - 1;
395
396 dx1 = dbox->x / blockwidth * nelements;
397 dy1 = dbox->y / blockheight;
398 dx2 = DIV_ROUND_UP(dbox->x + dbox->width, blockwidth) * nelements - 1;
399 dy2 = DIV_ROUND_UP(dbox->y + dbox->height, blockheight) - 1;
400
401 uint32_t width = DIV_ROUND_UP(u_minify(src->base.width0, info->src.level), blockwidth) * nelements;
402 uint32_t height = DIV_ROUND_UP(u_minify(src->base.height0, info->src.level), blockheight);
403
404 OUT_PKT7(ring, CP_SET_MARKER, 1);
405 OUT_RING(ring, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
406
407 uint32_t blit_cntl = blit_control(dfmt);
408
409 if (dtile != stile)
410 blit_cntl |= 0x20000000;
411
412 if (info->scissor_enable) {
413 OUT_PKT4(ring, REG_A6XX_GRAS_RESOLVE_CNTL_1, 2);
414 OUT_RING(ring, A6XX_GRAS_RESOLVE_CNTL_1_X(info->scissor.minx) |
415 A6XX_GRAS_RESOLVE_CNTL_1_Y(info->scissor.miny));
416 OUT_RING(ring, A6XX_GRAS_RESOLVE_CNTL_1_X(info->scissor.maxx - 1) |
417 A6XX_GRAS_RESOLVE_CNTL_1_Y(info->scissor.maxy - 1));
418 blit_cntl |= A6XX_RB_2D_BLIT_CNTL_SCISSOR;
419 }
420
421 OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);
422 OUT_RING(ring, blit_cntl);
423
424 OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);
425 OUT_RING(ring, blit_cntl);
426
427 for (unsigned i = 0; i < info->dst.box.depth; i++) {
428 unsigned soff = fd_resource_offset(src, info->src.level, sbox->z + i);
429 unsigned doff = fd_resource_offset(dst, info->dst.level, dbox->z + i);
430
431 /*
432 * Emit source:
433 */
434 uint32_t filter = 0;
435 if (info->filter == PIPE_TEX_FILTER_LINEAR)
436 filter = A6XX_SP_PS_2D_SRC_INFO_FILTER;
437
438 OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);
439 OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt) |
440 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile) |
441 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap) | 0x500000 | filter);
442 OUT_RING(ring, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width) |
443 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height)); /* SP_PS_2D_SRC_SIZE */
444 OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */
445 OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch));
446 OUT_RING(ring, 0x00000000);
447 OUT_RING(ring, 0x00000000);
448 OUT_RING(ring, 0x00000000);
449 OUT_RING(ring, 0x00000000);
450 OUT_RING(ring, 0x00000000);
451
452 OUT_RING(ring, 0x00000000);
453 OUT_RING(ring, 0x00000000);
454 OUT_RING(ring, 0x00000000);
455
456 /*
457 * Emit destination:
458 */
459 OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
460 OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(dfmt) |
461 A6XX_RB_2D_DST_INFO_TILE_MODE(dtile) |
462 A6XX_RB_2D_DST_INFO_COLOR_SWAP(dswap));
463 OUT_RELOCW(ring, dst->bo, doff, 0, 0); /* RB_2D_DST_LO/HI */
464 OUT_RING(ring, A6XX_RB_2D_DST_SIZE_PITCH(dpitch));
465 OUT_RING(ring, 0x00000000);
466 OUT_RING(ring, 0x00000000);
467 OUT_RING(ring, 0x00000000);
468 OUT_RING(ring, 0x00000000);
469 OUT_RING(ring, 0x00000000);
470
471 /*
472 * Blit command:
473 */
474 OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
475 OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X_X(sx1));
476 OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X_X(sx2));
477 OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y_Y(sy1));
478 OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y_Y(sy2));
479
480 OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
481 OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dx1) | A6XX_GRAS_2D_DST_TL_Y(dy1));
482 OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dx2) | A6XX_GRAS_2D_DST_BR_Y(dy2));
483
484 OUT_PKT7(ring, CP_EVENT_WRITE, 1);
485 OUT_RING(ring, 0x3f);
486 OUT_WFI5(ring);
487
488 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8C01, 1);
489 OUT_RING(ring, 0);
490
491 OUT_PKT4(ring, REG_A6XX_SP_2D_SRC_FORMAT, 1);
492 OUT_RING(ring, A6XX_SP_2D_SRC_FORMAT_COLOR_FORMAT(sfmt) |
493 COND(util_format_is_pure_sint(info->src.format),
494 A6XX_SP_2D_SRC_FORMAT_SINT) |
495 COND(util_format_is_pure_uint(info->src.format),
496 A6XX_SP_2D_SRC_FORMAT_UINT) |
497 COND(util_format_is_snorm(info->src.format),
498 A6XX_SP_2D_SRC_FORMAT_SINT |
499 A6XX_SP_2D_SRC_FORMAT_NORM) |
500 COND(util_format_is_unorm(info->src.format),
501 // TODO sometimes blob uses UINT+NORM but dEQP seems unhappy about that
502 // A6XX_SP_2D_SRC_FORMAT_UINT |
503 A6XX_SP_2D_SRC_FORMAT_NORM) |
504 0xf000);
505
506 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
507 OUT_RING(ring, 0x01000000);
508
509 OUT_PKT7(ring, CP_BLIT, 1);
510 OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
511
512 OUT_WFI5(ring);
513
514 OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
515 OUT_RING(ring, 0);
516 }
517 }
518
519 static void
520 rewrite_zs_blit(struct fd_ringbuffer *ring, const struct pipe_blit_info *info)
521 {
522 struct pipe_blit_info separate = *info;
523
524 if (DEBUG_BLIT_FALLBACK) {
525 fprintf(stderr, "---- rewrite_separate_zs_blit: ");
526 util_dump_blit_info(stderr, info);
527 fprintf(stderr, "\ndst resource: ");
528 util_dump_resource(stderr, info->dst.resource);
529 fprintf(stderr, "\nsrc resource: ");
530 util_dump_resource(stderr, info->src.resource);
531 fprintf(stderr, "\n\n");
532 }
533
534 switch (info->src.format) {
535 case PIPE_FORMAT_S8_UINT:
536 debug_assert(info->mask == PIPE_MASK_S);
537 separate.mask = PIPE_MASK_R;
538 separate.src.format = PIPE_FORMAT_R8_UINT;
539 separate.dst.format = PIPE_FORMAT_R8_UINT;
540 emit_blit_texture(ring, &separate);
541 break;
542
543 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
544 if (info->mask & PIPE_MASK_Z) {
545 separate.mask = PIPE_MASK_R;
546 separate.src.format = PIPE_FORMAT_R32_FLOAT;
547 separate.dst.format = PIPE_FORMAT_R32_FLOAT;
548 emit_blit_texture(ring, &separate);
549 }
550 if (info->mask & PIPE_MASK_S) {
551 separate.mask = PIPE_MASK_R;
552 separate.src.format = PIPE_FORMAT_R8_UINT;
553 separate.dst.format = PIPE_FORMAT_R8_UINT;
554 separate.src.resource = &fd_resource(info->src.resource)->stencil->base;
555 separate.dst.resource = &fd_resource(info->dst.resource)->stencil->base;
556 emit_blit_texture(ring, &separate);
557 }
558 break;
559
560 case PIPE_FORMAT_Z16_UNORM:
561 separate.mask = PIPE_MASK_R;
562 separate.src.format = PIPE_FORMAT_R16_UNORM;
563 separate.dst.format = PIPE_FORMAT_R16_UNORM;
564 emit_blit_texture(ring, &separate);
565 break;
566
567 case PIPE_FORMAT_Z32_UNORM:
568 case PIPE_FORMAT_Z32_FLOAT:
569 debug_assert(info->mask == PIPE_MASK_Z);
570 separate.mask = PIPE_MASK_R;
571 separate.src.format = PIPE_FORMAT_R32_UINT;
572 separate.dst.format = PIPE_FORMAT_R32_UINT;
573 emit_blit_texture(ring, &separate);
574 break;
575
576 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
577 debug_assert(info->mask == PIPE_MASK_ZS);
578 case PIPE_FORMAT_Z24X8_UNORM:
579 case PIPE_FORMAT_X8Z24_UNORM:
580 separate.mask = PIPE_MASK_R;
581 separate.src.format = PIPE_FORMAT_R32_UINT;
582 separate.dst.format = PIPE_FORMAT_R32_UINT;
583 emit_blit_texture(ring, &separate);
584 break;
585
586 default:
587 unreachable("");
588 }
589 }
590
591 static void
592 rewrite_combined_zs_blit(struct fd_context *ctx, const struct pipe_blit_info *info)
593 {
594 struct pipe_blit_info separate = *info;
595
596 if (DEBUG_BLIT_FALLBACK) {
597 fprintf(stderr, "---- rewrite_combined_zs_blit: ");
598 util_dump_blit_info(stderr, info);
599 fprintf(stderr, "\ndst resource: ");
600 util_dump_resource(stderr, info->dst.resource);
601 fprintf(stderr, "\nsrc resource: ");
602 util_dump_resource(stderr, info->src.resource);
603 fprintf(stderr, "\n");
604 }
605
606 switch (info->mask) {
607 case PIPE_MASK_Z:
608 separate.mask = PIPE_MASK_R | PIPE_MASK_G | PIPE_MASK_B;
609 separate.src.format = PIPE_FORMAT_R8G8B8A8_UNORM;
610 separate.dst.format = PIPE_FORMAT_R8G8B8A8_UNORM;
611
612 fd_blitter_blit(ctx, &separate);
613 break;
614
615 case PIPE_MASK_S:
616 separate.mask = PIPE_MASK_A;
617 separate.src.format = PIPE_FORMAT_R8G8B8A8_UNORM;
618 separate.dst.format = PIPE_FORMAT_R8G8B8A8_UNORM;
619
620 fd_blitter_blit(ctx, &separate);
621 break;
622
623 default:
624 unreachable("");
625 }
626 }
627
628 static bool
629 fd6_blit(struct fd_context *ctx, const struct pipe_blit_info *info)
630 {
631 struct fd_batch *batch;
632
633 if (info->dst.format == PIPE_FORMAT_Z24_UNORM_S8_UINT &&
634 info->mask != PIPE_MASK_ZS) {
635 rewrite_combined_zs_blit(ctx, info);
636 return true;
637 }
638
639 if (!can_do_blit(info))
640 return false;
641
642 fd_fence_ref(ctx->base.screen, &ctx->last_fence, NULL);
643
644 batch = fd_bc_alloc_batch(&ctx->screen->batch_cache, ctx, true);
645
646 fd6_emit_restore(batch, batch->draw);
647 fd6_emit_lrz_flush(batch->draw);
648
649 mtx_lock(&ctx->screen->lock);
650
651 fd_batch_resource_used(batch, fd_resource(info->src.resource), false);
652 fd_batch_resource_used(batch, fd_resource(info->dst.resource), true);
653
654 mtx_unlock(&ctx->screen->lock);
655
656 emit_setup(batch->draw);
657
658 if ((info->src.resource->target == PIPE_BUFFER) &&
659 (info->dst.resource->target == PIPE_BUFFER)) {
660 assert(fd_resource(info->src.resource)->tile_mode == TILE6_LINEAR);
661 assert(fd_resource(info->dst.resource)->tile_mode == TILE6_LINEAR);
662 emit_blit_buffer(batch->draw, info);
663 } else {
664 /* I don't *think* we need to handle blits between buffer <-> !buffer */
665 debug_assert(info->src.resource->target != PIPE_BUFFER);
666 debug_assert(info->dst.resource->target != PIPE_BUFFER);
667
668 if (info->mask & (PIPE_MASK_ZS)) {
669 rewrite_zs_blit(batch->draw, info);
670 } else {
671 emit_blit_texture(batch->draw, info);
672 }
673 }
674
675 fd6_event_write(batch, batch->draw, 0x1d, true);
676 fd6_event_write(batch, batch->draw, FACENESS_FLUSH, true);
677 fd6_event_write(batch, batch->draw, CACHE_FLUSH_TS, true);
678
679 fd_resource(info->dst.resource)->valid = true;
680 batch->needs_flush = true;
681
682 fd_batch_flush(batch, false, false);
683 fd_batch_reference(&batch, NULL);
684
685 return true;
686 }
687
688 void
689 fd6_blitter_init(struct pipe_context *pctx)
690 {
691 if (fd_mesa_debug & FD_DBG_NOBLIT)
692 return;
693
694 fd_context(pctx)->blit = fd6_blit;
695 }
696
697 unsigned
698 fd6_tile_mode(const struct pipe_resource *tmpl)
699 {
700 /* basically just has to be a format we can blit, so uploads/downloads
701 * via linear staging buffer works:
702 */
703 if (ok_format(tmpl->format))
704 return TILE6_3;
705
706 return TILE6_LINEAR;
707 }