2 * Copyright (C) 2017 Rob Clark <robclark@freedesktop.org>
3 * Copyright © 2018 Google, Inc.
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:
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
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
25 * Rob Clark <robclark@freedesktop.org>
28 #include "util/u_dump.h"
29 #include "util/half_float.h"
31 #include "freedreno_blitter.h"
32 #include "freedreno_fence.h"
33 #include "freedreno_resource.h"
35 #include "fd6_blitter.h"
36 #include "fd6_format.h"
38 #include "fd6_resource.h"
41 /* Make sure none of the requested dimensions extend beyond the size of the
42 * resource. Not entirely sure why this happens, but sometimes it does, and
43 * w/ 2d blt doesn't have wrap modes like a sampler, so force those cases
47 ok_dims(const struct pipe_resource
*r
, const struct pipe_box
*b
, int lvl
)
50 r
->target
== PIPE_TEXTURE_3D
? u_minify(r
->depth0
, lvl
)
53 return (b
->x
>= 0) && (b
->x
+ b
->width
<= u_minify(r
->width0
, lvl
)) &&
54 (b
->y
>= 0) && (b
->y
+ b
->height
<= u_minify(r
->height0
, lvl
)) &&
55 (b
->z
>= 0) && (b
->z
+ b
->depth
<= last_layer
);
59 ok_format(enum pipe_format pfmt
)
61 enum a6xx_color_fmt fmt
= fd6_pipe2color(pfmt
);
64 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
65 case PIPE_FORMAT_Z24X8_UNORM
:
66 case PIPE_FORMAT_Z16_UNORM
:
67 case PIPE_FORMAT_Z32_UNORM
:
68 case PIPE_FORMAT_Z32_FLOAT
:
69 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
70 case PIPE_FORMAT_S8_UINT
:
79 if (fd6_ifmt(fmt
) == 0)
86 #define DEBUG_BLIT_FALLBACK 0
88 #define fail_if(cond) \
91 if (DEBUG_BLIT_FALLBACK) { \
92 fprintf(stderr, "falling back: %s for blit:\n", #cond); \
93 util_dump_blit_info(stderr, info); \
94 fprintf(stderr, "\nsrc: "); \
95 util_dump_resource(stderr, info->src.resource); \
96 fprintf(stderr, "\ndst: "); \
97 util_dump_resource(stderr, info->dst.resource); \
98 fprintf(stderr, "\n"); \
105 can_do_blit(const struct pipe_blit_info
*info
)
107 /* I think we can do scaling, but not in z dimension since that would
110 fail_if(info
->dst
.box
.depth
!= info
->src
.box
.depth
);
112 /* Fail if unsupported format: */
113 fail_if(!ok_format(info
->src
.format
));
114 fail_if(!ok_format(info
->dst
.format
));
116 /* We can blit if both or neither formats are compressed formats... */
117 fail_if(util_format_is_compressed(info
->src
.format
) !=
118 util_format_is_compressed(info
->src
.format
));
120 /* ... but only if they're the same compression format. */
121 fail_if(util_format_is_compressed(info
->src
.format
) &&
122 info
->src
.format
!= info
->dst
.format
);
124 fail_if(!ok_dims(info
->src
.resource
, &info
->src
.box
, info
->src
.level
));
126 fail_if(!ok_dims(info
->dst
.resource
, &info
->dst
.box
, info
->dst
.level
));
128 debug_assert(info
->dst
.box
.width
>= 0);
129 debug_assert(info
->dst
.box
.height
>= 0);
130 debug_assert(info
->dst
.box
.depth
>= 0);
132 /* We could probably blit between resources with equal sample count.. */
133 fail_if(info
->dst
.resource
->nr_samples
> 1);
135 /* CP_BLIT supports resolving, but seems to pick one only of the samples
136 * (no blending). This doesn't work for RGBA resolves, so we fall back in
137 * that case. However, GL/GLES spec says:
139 * "If the source formats are integer types or stencil values, a single
140 * sample’s value is selected for each pixel. If the source formats are
141 * floating-point or normalized types, the sample values for each pixel
142 * are resolved in an implementationdependent manner. If the source
143 * formats are depth values, sample values are resolved in an
144 * implementation-dependent manner where the result will be between the
145 * minimum and maximum depth values in the pixel."
147 * so do those with CP_BLIT.
149 * TODO since we re-write z/s blits to RGBA, we'll fail this check in some
150 * cases where we don't need to.
152 fail_if((info
->mask
& PIPE_MASK_RGBA
) &&
153 info
->src
.resource
->nr_samples
> 1);
155 fail_if(info
->window_rectangle_include
);
157 fail_if(util_format_is_srgb(info
->src
.format
));
158 fail_if(util_format_is_srgb(info
->dst
.format
));
160 const struct util_format_description
*src_desc
=
161 util_format_description(info
->src
.format
);
162 const struct util_format_description
*dst_desc
=
163 util_format_description(info
->dst
.format
);
164 const int common_channels
= MIN2(src_desc
->nr_channels
, dst_desc
->nr_channels
);
166 if (info
->mask
& PIPE_MASK_RGBA
) {
167 for (int i
= 0; i
< common_channels
; i
++) {
168 fail_if(memcmp(&src_desc
->channel
[i
],
169 &dst_desc
->channel
[i
],
170 sizeof(src_desc
->channel
[0])));
174 fail_if(info
->alpha_blend
);
180 emit_setup(struct fd_batch
*batch
)
182 struct fd_ringbuffer
*ring
= batch
->draw
;
184 fd6_event_write(batch
, ring
, 0x1d, true);
185 fd6_event_write(batch
, ring
, FACENESS_FLUSH
, true);
186 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
187 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_DEPTH
, false);
191 blit_control(enum a6xx_color_fmt fmt
)
193 unsigned blit_cntl
= 0xf00000;
194 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt
);
195 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_IFMT(fd6_ifmt(fmt
));
199 /* buffers need to be handled specially since x/width can exceed the bounds
200 * supported by hw.. if necessary decompose into (potentially) two 2D blits
203 emit_blit_buffer(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
204 const struct pipe_blit_info
*info
)
206 const struct pipe_box
*sbox
= &info
->src
.box
;
207 const struct pipe_box
*dbox
= &info
->dst
.box
;
208 struct fd_resource
*src
, *dst
;
209 unsigned sshift
, dshift
;
212 fprintf(stderr
, "buffer blit: ");
213 util_dump_blit_info(stderr
, info
);
214 fprintf(stderr
, "\ndst resource: ");
215 util_dump_resource(stderr
, info
->dst
.resource
);
216 fprintf(stderr
, "\nsrc resource: ");
217 util_dump_resource(stderr
, info
->src
.resource
);
218 fprintf(stderr
, "\n");
221 src
= fd_resource(info
->src
.resource
);
222 dst
= fd_resource(info
->dst
.resource
);
224 debug_assert(src
->layout
.cpp
== 1);
225 debug_assert(dst
->layout
.cpp
== 1);
226 debug_assert(info
->src
.resource
->format
== info
->dst
.resource
->format
);
227 debug_assert((sbox
->y
== 0) && (sbox
->height
== 1));
228 debug_assert((dbox
->y
== 0) && (dbox
->height
== 1));
229 debug_assert((sbox
->z
== 0) && (sbox
->depth
== 1));
230 debug_assert((dbox
->z
== 0) && (dbox
->depth
== 1));
231 debug_assert(sbox
->width
== dbox
->width
);
232 debug_assert(info
->src
.level
== 0);
233 debug_assert(info
->dst
.level
== 0);
236 * Buffers can have dimensions bigger than max width, remap into
237 * multiple 1d blits to fit within max dimension
239 * Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
240 * seems to prevent overfetch related faults. Not quite sure what
243 * Low 6 bits of SRC/DST addresses need to be zero (ie. address
244 * aligned to 64) so we need to shift src/dst x1/x2 to make up the
245 * difference. On top of already splitting up the blit so width
248 * We perhaps could do a bit better, if src and dst are aligned but
249 * in the worst case this means we have to split the copy up into
250 * 16k (0x4000) minus 64 (0x40).
253 sshift
= sbox
->x
& 0x3f;
254 dshift
= dbox
->x
& 0x3f;
256 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
257 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
259 uint32_t blit_cntl
= blit_control(RB6_R8_UNORM
) | 0x20000000;
260 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
261 OUT_RING(ring
, blit_cntl
);
263 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
264 OUT_RING(ring
, blit_cntl
);
266 for (unsigned off
= 0; off
< sbox
->width
; off
+= (0x4000 - 0x40)) {
267 unsigned soff
, doff
, w
, p
;
269 soff
= (sbox
->x
+ off
) & ~0x3f;
270 doff
= (dbox
->x
+ off
) & ~0x3f;
272 w
= MIN2(sbox
->width
- off
, (0x4000 - 0x40));
275 debug_assert((soff
+ w
) <= fd_bo_size(src
->bo
));
276 debug_assert((doff
+ w
) <= fd_bo_size(dst
->bo
));
281 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 10);
282 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
283 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR
) |
284 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX
) |
286 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift
+ w
) |
287 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
288 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
289 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_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);
300 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
301 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
302 A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
303 A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX
));
304 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
305 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(p
));
306 OUT_RING(ring
, 0x00000000);
307 OUT_RING(ring
, 0x00000000);
308 OUT_RING(ring
, 0x00000000);
309 OUT_RING(ring
, 0x00000000);
310 OUT_RING(ring
, 0x00000000);
315 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
316 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sshift
));
317 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sshift
+ w
- 1));
318 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(0));
319 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(0));
321 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
322 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dshift
) | A6XX_GRAS_2D_DST_TL_Y(0));
323 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dshift
+ w
- 1) | A6XX_GRAS_2D_DST_BR_Y(0));
325 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
326 OUT_RING(ring
, 0x3f);
329 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
332 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
333 OUT_RING(ring
, 0xf180);
335 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
336 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_UNKNOWN_8E04_blit
);
338 OUT_PKT7(ring
, CP_BLIT
, 1);
339 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
343 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
344 OUT_RING(ring
, 0); /* RB_UNKNOWN_8E04 */
349 emit_blit_or_clear_texture(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
350 const struct pipe_blit_info
*info
, union pipe_color_union
*color
)
352 const struct pipe_box
*sbox
= &info
->src
.box
;
353 const struct pipe_box
*dbox
= &info
->dst
.box
;
354 struct fd_resource
*src
, *dst
;
355 struct fdl_slice
*sslice
, *dslice
;
356 enum a6xx_color_fmt sfmt
, dfmt
;
357 enum a6xx_tile_mode stile
, dtile
;
358 enum a3xx_color_swap sswap
, dswap
;
359 unsigned spitch
, dpitch
;
360 int sx1
, sy1
, sx2
, sy2
;
361 int dx1
, dy1
, dx2
, dy2
;
364 fprintf(stderr
, "texture blit: ");
365 util_dump_blit_info(stderr
, info
);
366 fprintf(stderr
, "\ndst resource: ");
367 util_dump_resource(stderr
, info
->dst
.resource
);
368 fprintf(stderr
, "\nsrc resource: ");
369 util_dump_resource(stderr
, info
->src
.resource
);
370 fprintf(stderr
, "\n");
373 src
= fd_resource(info
->src
.resource
);
374 dst
= fd_resource(info
->dst
.resource
);
376 sslice
= fd_resource_slice(src
, info
->src
.level
);
377 dslice
= fd_resource_slice(dst
, info
->dst
.level
);
379 sfmt
= fd6_pipe2color(info
->src
.format
);
380 dfmt
= fd6_pipe2color(info
->dst
.format
);
382 int blocksize
= util_format_get_blocksize(info
->src
.format
);
383 int blockwidth
= util_format_get_blockwidth(info
->src
.format
);
384 int blockheight
= util_format_get_blockheight(info
->src
.format
);
387 stile
= fd_resource_tile_mode(info
->src
.resource
, info
->src
.level
);
388 dtile
= fd_resource_tile_mode(info
->dst
.resource
, info
->dst
.level
);
390 /* Linear levels of a tiled resource are always WZYX, so look at
391 * rsc->tile_mode to determine the swap.
393 sswap
= fd6_resource_swap(src
, info
->src
.format
);
394 dswap
= fd6_resource_swap(dst
, info
->dst
.format
);
396 if (util_format_is_compressed(info
->src
.format
)) {
397 debug_assert(info
->src
.format
== info
->dst
.format
);
398 sfmt
= dfmt
= RB6_R8_UNORM
;
399 nelements
= blocksize
;
401 debug_assert(!util_format_is_compressed(info
->dst
.format
));
402 nelements
= (dst
->base
.nr_samples
? dst
->base
.nr_samples
: 1);
405 spitch
= DIV_ROUND_UP(sslice
->pitch
, blockwidth
) * src
->layout
.cpp
;
406 dpitch
= DIV_ROUND_UP(dslice
->pitch
, blockwidth
) * dst
->layout
.cpp
;
408 sx1
= sbox
->x
/ blockwidth
* nelements
;
409 sy1
= sbox
->y
/ blockheight
;
410 sx2
= DIV_ROUND_UP(sbox
->x
+ sbox
->width
, blockwidth
) * nelements
- 1;
411 sy2
= DIV_ROUND_UP(sbox
->y
+ sbox
->height
, blockheight
) - 1;
413 dx1
= dbox
->x
/ blockwidth
* nelements
;
414 dy1
= dbox
->y
/ blockheight
;
415 dx2
= DIV_ROUND_UP(dbox
->x
+ dbox
->width
, blockwidth
) * nelements
- 1;
416 dy2
= DIV_ROUND_UP(dbox
->y
+ dbox
->height
, blockheight
) - 1;
418 uint32_t width
= DIV_ROUND_UP(u_minify(src
->base
.width0
, info
->src
.level
), blockwidth
) * nelements
;
419 uint32_t height
= DIV_ROUND_UP(u_minify(src
->base
.height0
, info
->src
.level
), blockheight
);
421 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
422 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
424 uint32_t blit_cntl
= blit_control(dfmt
);
427 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SOLID_COLOR
;
429 switch (info
->dst
.format
) {
430 case PIPE_FORMAT_Z24X8_UNORM
:
431 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
432 case PIPE_FORMAT_X24S8_UINT
: {
433 uint32_t depth_unorm24
= color
->f
[0] * ((1u << 24) - 1);
434 uint8_t stencil
= color
->ui
[1];
435 color
->ui
[0] = depth_unorm24
& 0xff;
436 color
->ui
[1] = (depth_unorm24
>> 8) & 0xff;
437 color
->ui
[2] = (depth_unorm24
>> 16) & 0xff;
438 color
->ui
[3] = stencil
;
440 dfmt
= RB6_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
443 case PIPE_FORMAT_B5G6R5_UNORM
:
444 case PIPE_FORMAT_B5G5R5A1_UNORM
:
445 case PIPE_FORMAT_B5G5R5X1_UNORM
:
446 case PIPE_FORMAT_B4G4R4A4_UNORM
:
447 color
->ui
[0] = float_to_ubyte(color
->f
[0]);
448 color
->ui
[1] = float_to_ubyte(color
->f
[1]);
449 color
->ui
[2] = float_to_ubyte(color
->f
[2]);
450 color
->ui
[3] = float_to_ubyte(color
->f
[3]);
456 OUT_PKT4(ring
, REG_A6XX_RB_2D_SRC_SOLID_C0
, 4);
458 switch (fd6_ifmt(dfmt
)) {
460 case R2D_UNORM8_SRGB
:
461 OUT_RING(ring
, float_to_ubyte(color
->f
[0]));
462 OUT_RING(ring
, float_to_ubyte(color
->f
[1]));
463 OUT_RING(ring
, float_to_ubyte(color
->f
[2]));
464 OUT_RING(ring
, float_to_ubyte(color
->f
[3]));
467 OUT_RING(ring
, _mesa_float_to_half(color
->f
[0]));
468 OUT_RING(ring
, _mesa_float_to_half(color
->f
[1]));
469 OUT_RING(ring
, _mesa_float_to_half(color
->f
[2]));
470 OUT_RING(ring
, _mesa_float_to_half(color
->f
[3]));
471 sfmt
= RB6_R16G16B16A16_FLOAT
;
480 OUT_RING(ring
, color
->ui
[0]);
481 OUT_RING(ring
, color
->ui
[1]);
482 OUT_RING(ring
, color
->ui
[2]);
483 OUT_RING(ring
, color
->ui
[3]);
489 blit_cntl
|= 0x20000000;
491 if (info
->scissor_enable
) {
492 OUT_PKT4(ring
, REG_A6XX_GRAS_RESOLVE_CNTL_1
, 2);
493 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.minx
) |
494 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.miny
));
495 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.maxx
- 1) |
496 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.maxy
- 1));
497 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SCISSOR
;
500 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
501 OUT_RING(ring
, blit_cntl
);
503 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
504 OUT_RING(ring
, blit_cntl
);
506 for (unsigned i
= 0; i
< info
->dst
.box
.depth
; i
++) {
507 unsigned soff
= fd_resource_offset(src
, info
->src
.level
, sbox
->z
+ i
);
508 unsigned doff
= fd_resource_offset(dst
, info
->dst
.level
, dbox
->z
+ i
);
509 bool subwc_enabled
= fd_resource_ubwc_enabled(src
, info
->src
.level
);
510 bool dubwc_enabled
= fd_resource_ubwc_enabled(dst
, info
->dst
.level
);
516 if (info
->filter
== PIPE_TEX_FILTER_LINEAR
)
517 filter
= A6XX_SP_PS_2D_SRC_INFO_FILTER
;
519 enum a3xx_msaa_samples samples
= fd_msaa_samples(src
->base
.nr_samples
);
521 if (sfmt
== RB6_R10G10B10A2_UNORM
)
522 sfmt
= RB6_R10G10B10A2_FLOAT16
;
524 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 10);
525 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt
) |
526 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile
) |
527 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap
) |
528 A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples
) |
529 COND(subwc_enabled
, A6XX_SP_PS_2D_SRC_INFO_FLAGS
) |
531 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width
) |
532 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height
)); /* SP_PS_2D_SRC_SIZE */
533 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
534 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch
));
536 OUT_RING(ring
, 0x00000000);
537 OUT_RING(ring
, 0x00000000);
538 OUT_RING(ring
, 0x00000000);
539 OUT_RING(ring
, 0x00000000);
540 OUT_RING(ring
, 0x00000000);
543 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_FLAGS_LO
, 6);
544 fd6_emit_flag_reference(ring
, src
, info
->src
.level
, sbox
->z
+ i
);
545 OUT_RING(ring
, 0x00000000);
546 OUT_RING(ring
, 0x00000000);
547 OUT_RING(ring
, 0x00000000);
553 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
554 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(dfmt
) |
555 A6XX_RB_2D_DST_INFO_TILE_MODE(dtile
) |
556 A6XX_RB_2D_DST_INFO_COLOR_SWAP(dswap
) |
557 COND(dubwc_enabled
, A6XX_RB_2D_DST_INFO_FLAGS
));
558 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
559 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(dpitch
));
560 OUT_RING(ring
, 0x00000000);
561 OUT_RING(ring
, 0x00000000);
562 OUT_RING(ring
, 0x00000000);
563 OUT_RING(ring
, 0x00000000);
564 OUT_RING(ring
, 0x00000000);
567 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_FLAGS_LO
, 6);
568 fd6_emit_flag_reference(ring
, dst
, info
->dst
.level
, dbox
->z
+ i
);
569 OUT_RING(ring
, 0x00000000);
570 OUT_RING(ring
, 0x00000000);
571 OUT_RING(ring
, 0x00000000);
577 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
578 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sx1
));
579 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sx2
));
580 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(sy1
));
581 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(sy2
));
583 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
584 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dx1
) | A6XX_GRAS_2D_DST_TL_Y(dy1
));
585 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dx2
) | A6XX_GRAS_2D_DST_BR_Y(dy2
));
587 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
588 OUT_RING(ring
, 0x3f);
591 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
594 if (dfmt
== RB6_R10G10B10A2_UNORM
)
595 sfmt
= RB6_R16G16B16A16_FLOAT
;
597 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
598 OUT_RING(ring
, A6XX_SP_2D_SRC_FORMAT_COLOR_FORMAT(sfmt
) |
599 COND(util_format_is_pure_sint(info
->src
.format
),
600 A6XX_SP_2D_SRC_FORMAT_SINT
) |
601 COND(util_format_is_pure_uint(info
->src
.format
),
602 A6XX_SP_2D_SRC_FORMAT_UINT
) |
603 COND(util_format_is_snorm(info
->src
.format
),
604 A6XX_SP_2D_SRC_FORMAT_SINT
|
605 A6XX_SP_2D_SRC_FORMAT_NORM
) |
606 COND(util_format_is_unorm(info
->src
.format
),
607 // TODO sometimes blob uses UINT+NORM but dEQP seems unhappy about that
608 // A6XX_SP_2D_SRC_FORMAT_UINT |
609 A6XX_SP_2D_SRC_FORMAT_NORM
) |
612 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
613 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_UNKNOWN_8E04_blit
);
615 OUT_PKT7(ring
, CP_BLIT
, 1);
616 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
620 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
621 OUT_RING(ring
, 0); /* RB_UNKNOWN_8E04 */
626 fd6_clear_surface(struct fd_context
*ctx
,
627 struct fd_ringbuffer
*ring
, struct pipe_surface
*psurf
,
628 uint32_t width
, uint32_t height
, union pipe_color_union
*color
)
630 struct pipe_blit_info info
= {};
632 info
.dst
.resource
= psurf
->texture
;
633 info
.dst
.level
= psurf
->u
.tex
.level
;
636 info
.dst
.box
.z
= psurf
->u
.tex
.first_layer
;
637 info
.dst
.box
.width
= width
;
638 info
.dst
.box
.height
= height
;
639 info
.dst
.box
.depth
= psurf
->u
.tex
.last_layer
+ 1 - psurf
->u
.tex
.first_layer
;
640 info
.dst
.format
= psurf
->format
;
642 info
.mask
= util_format_get_mask(psurf
->format
);
643 info
.filter
= PIPE_TEX_FILTER_NEAREST
;
644 info
.scissor_enable
= 0;
646 emit_blit_or_clear_texture(ctx
, ring
, &info
, color
);
649 static bool handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
);
652 * Re-written z/s blits can still fail for various reasons (for example MSAA).
653 * But we want to do the fallback blit with the re-written pipe_blit_info,
654 * in particular as u_blitter cannot blit stencil. So handle the fallback
655 * ourself and never "fail".
658 do_rewritten_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
660 bool success
= handle_rgba_blit(ctx
, info
);
662 success
= fd_blitter_blit(ctx
, info
);
663 debug_assert(success
); /* fallback should never fail! */
668 * Handle depth/stencil blits either via u_blitter and/or re-writing the
669 * blit into an equivilant format that we can handle
672 handle_zs_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
674 struct pipe_blit_info blit
= *info
;
677 fprintf(stderr
, "---- handle_zs_blit: ");
678 util_dump_blit_info(stderr
, info
);
679 fprintf(stderr
, "\ndst resource: ");
680 util_dump_resource(stderr
, info
->dst
.resource
);
681 fprintf(stderr
, "\nsrc resource: ");
682 util_dump_resource(stderr
, info
->src
.resource
);
683 fprintf(stderr
, "\n");
686 switch (info
->dst
.format
) {
687 case PIPE_FORMAT_S8_UINT
:
688 debug_assert(info
->mask
== PIPE_MASK_S
);
689 blit
.mask
= PIPE_MASK_R
;
690 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
691 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
692 return do_rewritten_blit(ctx
, &blit
);
694 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
695 if (info
->mask
& PIPE_MASK_Z
) {
696 blit
.mask
= PIPE_MASK_R
;
697 blit
.src
.format
= PIPE_FORMAT_R32_FLOAT
;
698 blit
.dst
.format
= PIPE_FORMAT_R32_FLOAT
;
699 do_rewritten_blit(ctx
, &blit
);
702 if (info
->mask
& PIPE_MASK_S
) {
703 blit
.mask
= PIPE_MASK_R
;
704 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
705 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
706 blit
.src
.resource
= &fd_resource(info
->src
.resource
)->stencil
->base
;
707 blit
.dst
.resource
= &fd_resource(info
->dst
.resource
)->stencil
->base
;
708 do_rewritten_blit(ctx
, &blit
);
713 case PIPE_FORMAT_Z16_UNORM
:
714 blit
.mask
= PIPE_MASK_R
;
715 blit
.src
.format
= PIPE_FORMAT_R16_UNORM
;
716 blit
.dst
.format
= PIPE_FORMAT_R16_UNORM
;
717 return do_rewritten_blit(ctx
, &blit
);
719 case PIPE_FORMAT_Z32_UNORM
:
720 case PIPE_FORMAT_Z32_FLOAT
:
721 debug_assert(info
->mask
== PIPE_MASK_Z
);
722 blit
.mask
= PIPE_MASK_R
;
723 blit
.src
.format
= PIPE_FORMAT_R32_UINT
;
724 blit
.dst
.format
= PIPE_FORMAT_R32_UINT
;
725 return do_rewritten_blit(ctx
, &blit
);
727 case PIPE_FORMAT_Z24X8_UNORM
:
728 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
730 if (info
->mask
& PIPE_MASK_Z
)
731 blit
.mask
|= PIPE_MASK_R
| PIPE_MASK_G
| PIPE_MASK_B
;
732 if (info
->mask
& PIPE_MASK_S
)
733 blit
.mask
|= PIPE_MASK_A
;
734 blit
.src
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
735 blit
.dst
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
736 return fd_blitter_blit(ctx
, &blit
);
744 handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
746 struct fd_batch
*batch
;
748 debug_assert(!(info
->mask
& PIPE_MASK_ZS
));
750 if (!can_do_blit(info
))
753 fd_fence_ref(&ctx
->last_fence
, NULL
);
755 batch
= fd_bc_alloc_batch(&ctx
->screen
->batch_cache
, ctx
, true);
757 fd6_emit_restore(batch
, batch
->draw
);
758 fd6_emit_lrz_flush(batch
->draw
);
760 mtx_lock(&ctx
->screen
->lock
);
762 fd_batch_resource_used(batch
, fd_resource(info
->src
.resource
), false);
763 fd_batch_resource_used(batch
, fd_resource(info
->dst
.resource
), true);
765 mtx_unlock(&ctx
->screen
->lock
);
769 if ((info
->src
.resource
->target
== PIPE_BUFFER
) &&
770 (info
->dst
.resource
->target
== PIPE_BUFFER
)) {
771 assert(fd_resource(info
->src
.resource
)->layout
.tile_mode
== TILE6_LINEAR
);
772 assert(fd_resource(info
->dst
.resource
)->layout
.tile_mode
== TILE6_LINEAR
);
773 emit_blit_buffer(ctx
, batch
->draw
, info
);
775 /* I don't *think* we need to handle blits between buffer <-> !buffer */
776 debug_assert(info
->src
.resource
->target
!= PIPE_BUFFER
);
777 debug_assert(info
->dst
.resource
->target
!= PIPE_BUFFER
);
778 emit_blit_or_clear_texture(ctx
, batch
->draw
, info
, NULL
);
781 fd6_event_write(batch
, batch
->draw
, 0x1d, true);
782 fd6_event_write(batch
, batch
->draw
, FACENESS_FLUSH
, true);
783 fd6_event_write(batch
, batch
->draw
, CACHE_FLUSH_TS
, true);
784 fd6_cache_inv(batch
, batch
->draw
);
786 fd_resource(info
->dst
.resource
)->valid
= true;
787 batch
->needs_flush
= true;
789 fd_batch_flush(batch
, false);
790 fd_batch_reference(&batch
, NULL
);
796 fd6_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
798 if (info
->mask
& PIPE_MASK_ZS
)
799 return handle_zs_blit(ctx
, info
);
800 return handle_rgba_blit(ctx
, info
);
804 fd6_blitter_init(struct pipe_context
*pctx
)
806 if (fd_mesa_debug
& FD_DBG_NOBLIT
)
809 fd_context(pctx
)->blit
= fd6_blit
;
813 fd6_tile_mode(const struct pipe_resource
*tmpl
)
815 /* if the mipmap level 0 is still too small to be tiled, then don't
818 if (fd_resource_level_linear(tmpl
, 0))
821 /* basically just has to be a format we can blit, so uploads/downloads
822 * via linear staging buffer works:
824 if (ok_format(tmpl
->format
))