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"
30 #include "freedreno_blitter.h"
31 #include "freedreno_fence.h"
32 #include "freedreno_resource.h"
34 #include "fd6_blitter.h"
35 #include "fd6_format.h"
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
44 ok_dims(const struct pipe_resource
*r
, const struct pipe_box
*b
, int lvl
)
47 r
->target
== PIPE_TEXTURE_3D
? u_minify(r
->depth0
, lvl
)
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
);
56 ok_format(enum pipe_format pfmt
)
58 enum a6xx_color_fmt fmt
= fd6_pipe2color(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
:
76 if (fd6_ifmt(fmt
) == 0)
82 #define DEBUG_BLIT_FALLBACK 0
83 #define fail_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"); \
100 can_do_blit(const struct pipe_blit_info
*info
)
102 /* I think we can do scaling, but not in z dimension since that would
105 fail_if(info
->dst
.box
.depth
!= info
->src
.box
.depth
);
107 /* Fail if unsupported format: */
108 fail_if(!ok_format(info
->src
.format
));
109 fail_if(!ok_format(info
->dst
.format
));
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
));
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
);
119 fail_if(!ok_dims(info
->src
.resource
, &info
->src
.box
, info
->src
.level
));
121 fail_if(!ok_dims(info
->dst
.resource
, &info
->dst
.box
, info
->dst
.level
));
123 debug_assert(info
->dst
.box
.width
>= 0);
124 debug_assert(info
->dst
.box
.height
>= 0);
125 debug_assert(info
->dst
.box
.depth
>= 0);
127 /* We could probably blit between resources with equal sample count.. */
128 fail_if(info
->dst
.resource
->nr_samples
> 1);
130 /* CP_BLIT supports resolving, but seems to pick one only of the samples
131 * (no blending). This doesn't work for RGBA resolves, so we fall back in
132 * that case. However, GL/GLES spec says:
134 * "If the source formats are integer types or stencil values, a single
135 * sample’s value is selected for each pixel. If the source formats are
136 * floating-point or normalized types, the sample values for each pixel
137 * are resolved in an implementationdependent manner. If the source
138 * formats are depth values, sample values are resolved in an
139 * implementation-dependent manner where the result will be between the
140 * minimum and maximum depth values in the pixel."
142 * so do those with CP_BLIT.
144 * TODO since we re-write z/s blits to RGBA, we'll fail this check in some
145 * cases where we don't need to.
147 fail_if((info
->mask
& PIPE_MASK_RGBA
) &&
148 info
->src
.resource
->nr_samples
> 1);
150 fail_if(info
->window_rectangle_include
);
152 fail_if(util_format_is_srgb(info
->src
.format
));
153 fail_if(util_format_is_srgb(info
->dst
.format
));
155 const struct util_format_description
*src_desc
=
156 util_format_description(info
->src
.format
);
157 const struct util_format_description
*dst_desc
=
158 util_format_description(info
->dst
.format
);
159 const int common_channels
= MIN2(src_desc
->nr_channels
, dst_desc
->nr_channels
);
161 if (info
->mask
& PIPE_MASK_RGBA
) {
162 for (int i
= 0; i
< common_channels
; i
++) {
163 fail_if(memcmp(&src_desc
->channel
[i
],
164 &dst_desc
->channel
[i
],
165 sizeof(src_desc
->channel
[0])));
169 fail_if(info
->alpha_blend
);
175 emit_setup(struct fd_batch
*batch
)
177 struct fd_ringbuffer
*ring
= batch
->draw
;
179 fd6_event_write(batch
, ring
, 0x1d, true);
180 fd6_event_write(batch
, ring
, FACENESS_FLUSH
, true);
181 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
182 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_DEPTH
, false);
186 blit_control(enum a6xx_color_fmt fmt
)
188 unsigned blit_cntl
= 0xf00000;
189 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt
);
190 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_IFMT(fd6_ifmt(fmt
));
194 /* buffers need to be handled specially since x/width can exceed the bounds
195 * supported by hw.. if necessary decompose into (potentially) two 2D blits
198 emit_blit_buffer(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
200 const struct pipe_box
*sbox
= &info
->src
.box
;
201 const struct pipe_box
*dbox
= &info
->dst
.box
;
202 struct fd_resource
*src
, *dst
;
203 unsigned sshift
, dshift
;
205 if (DEBUG_BLIT_FALLBACK
) {
206 fprintf(stderr
, "buffer blit: ");
207 util_dump_blit_info(stderr
, info
);
208 fprintf(stderr
, "\ndst resource: ");
209 util_dump_resource(stderr
, info
->dst
.resource
);
210 fprintf(stderr
, "\nsrc resource: ");
211 util_dump_resource(stderr
, info
->src
.resource
);
212 fprintf(stderr
, "\n");
215 src
= fd_resource(info
->src
.resource
);
216 dst
= fd_resource(info
->dst
.resource
);
218 debug_assert(src
->cpp
== 1);
219 debug_assert(dst
->cpp
== 1);
220 debug_assert(info
->src
.resource
->format
== info
->dst
.resource
->format
);
221 debug_assert((sbox
->y
== 0) && (sbox
->height
== 1));
222 debug_assert((dbox
->y
== 0) && (dbox
->height
== 1));
223 debug_assert((sbox
->z
== 0) && (sbox
->depth
== 1));
224 debug_assert((dbox
->z
== 0) && (dbox
->depth
== 1));
225 debug_assert(sbox
->width
== dbox
->width
);
226 debug_assert(info
->src
.level
== 0);
227 debug_assert(info
->dst
.level
== 0);
230 * Buffers can have dimensions bigger than max width, remap into
231 * multiple 1d blits to fit within max dimension
233 * Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
234 * seems to prevent overfetch related faults. Not quite sure what
237 * Low 6 bits of SRC/DST addresses need to be zero (ie. address
238 * aligned to 64) so we need to shift src/dst x1/x2 to make up the
239 * difference. On top of already splitting up the blit so width
242 * We perhaps could do a bit better, if src and dst are aligned but
243 * in the worst case this means we have to split the copy up into
244 * 16k (0x4000) minus 64 (0x40).
247 sshift
= sbox
->x
& 0x3f;
248 dshift
= dbox
->x
& 0x3f;
250 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
251 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
253 uint32_t blit_cntl
= blit_control(RB6_R8_UNORM
) | 0x20000000;
254 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
255 OUT_RING(ring
, blit_cntl
);
257 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
258 OUT_RING(ring
, blit_cntl
);
260 for (unsigned off
= 0; off
< sbox
->width
; off
+= (0x4000 - 0x40)) {
261 unsigned soff
, doff
, w
, p
;
263 soff
= (sbox
->x
+ off
) & ~0x3f;
264 doff
= (dbox
->x
+ off
) & ~0x3f;
266 w
= MIN2(sbox
->width
- off
, (0x4000 - 0x40));
269 debug_assert((soff
+ w
) <= fd_bo_size(src
->bo
));
270 debug_assert((doff
+ w
) <= fd_bo_size(dst
->bo
));
275 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 10);
276 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
277 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR
) |
278 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX
) |
280 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift
+ w
) |
281 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
282 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
283 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p
));
285 OUT_RING(ring
, 0x00000000);
286 OUT_RING(ring
, 0x00000000);
287 OUT_RING(ring
, 0x00000000);
288 OUT_RING(ring
, 0x00000000);
289 OUT_RING(ring
, 0x00000000);
294 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
295 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
296 A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
297 A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX
));
298 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
299 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(p
));
300 OUT_RING(ring
, 0x00000000);
301 OUT_RING(ring
, 0x00000000);
302 OUT_RING(ring
, 0x00000000);
303 OUT_RING(ring
, 0x00000000);
304 OUT_RING(ring
, 0x00000000);
309 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
310 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sshift
));
311 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sshift
+ w
- 1));
312 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(0));
313 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(0));
315 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
316 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dshift
) | A6XX_GRAS_2D_DST_TL_Y(0));
317 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dshift
+ w
- 1) | A6XX_GRAS_2D_DST_BR_Y(0));
319 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
320 OUT_RING(ring
, 0x3f);
323 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
326 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
327 OUT_RING(ring
, 0xf180);
329 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
330 OUT_RING(ring
, 0x01000000);
332 OUT_PKT7(ring
, CP_BLIT
, 1);
333 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
337 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
343 emit_blit_texture(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
345 const struct pipe_box
*sbox
= &info
->src
.box
;
346 const struct pipe_box
*dbox
= &info
->dst
.box
;
347 struct fd_resource
*src
, *dst
;
348 struct fd_resource_slice
*sslice
, *dslice
;
349 enum a6xx_color_fmt sfmt
, dfmt
;
350 enum a6xx_tile_mode stile
, dtile
;
351 enum a3xx_color_swap sswap
, dswap
;
352 unsigned spitch
, dpitch
;
353 int sx1
, sy1
, sx2
, sy2
;
354 int dx1
, dy1
, dx2
, dy2
;
356 if (DEBUG_BLIT_FALLBACK
) {
357 fprintf(stderr
, "texture blit: ");
358 util_dump_blit_info(stderr
, info
);
359 fprintf(stderr
, "\ndst resource: ");
360 util_dump_resource(stderr
, info
->dst
.resource
);
361 fprintf(stderr
, "\nsrc resource: ");
362 util_dump_resource(stderr
, info
->src
.resource
);
363 fprintf(stderr
, "\n");
366 src
= fd_resource(info
->src
.resource
);
367 dst
= fd_resource(info
->dst
.resource
);
369 sslice
= fd_resource_slice(src
, info
->src
.level
);
370 dslice
= fd_resource_slice(dst
, info
->dst
.level
);
372 sfmt
= fd6_pipe2color(info
->src
.format
);
373 dfmt
= fd6_pipe2color(info
->dst
.format
);
375 int blocksize
= util_format_get_blocksize(info
->src
.format
);
376 int blockwidth
= util_format_get_blockwidth(info
->src
.format
);
377 int blockheight
= util_format_get_blockheight(info
->src
.format
);
380 stile
= fd_resource_level_linear(info
->src
.resource
, info
->src
.level
) ?
381 TILE6_LINEAR
: src
->tile_mode
;
382 dtile
= fd_resource_level_linear(info
->dst
.resource
, info
->dst
.level
) ?
383 TILE6_LINEAR
: dst
->tile_mode
;
385 sswap
= stile
? WZYX
: fd6_pipe2swap(info
->src
.format
);
386 dswap
= dtile
? WZYX
: fd6_pipe2swap(info
->dst
.format
);
388 if (util_format_is_compressed(info
->src
.format
)) {
389 debug_assert(info
->src
.format
== info
->dst
.format
);
390 sfmt
= dfmt
= RB6_R8_UNORM
;
391 nelements
= blocksize
;
393 debug_assert(!util_format_is_compressed(info
->dst
.format
));
397 spitch
= DIV_ROUND_UP(sslice
->pitch
, blockwidth
) * src
->cpp
;
398 dpitch
= DIV_ROUND_UP(dslice
->pitch
, blockwidth
) * dst
->cpp
;
400 sx1
= sbox
->x
/ blockwidth
* nelements
;
401 sy1
= sbox
->y
/ blockheight
;
402 sx2
= DIV_ROUND_UP(sbox
->x
+ sbox
->width
, blockwidth
) * nelements
- 1;
403 sy2
= DIV_ROUND_UP(sbox
->y
+ sbox
->height
, blockheight
) - 1;
405 dx1
= dbox
->x
/ blockwidth
* nelements
;
406 dy1
= dbox
->y
/ blockheight
;
407 dx2
= DIV_ROUND_UP(dbox
->x
+ dbox
->width
, blockwidth
) * nelements
- 1;
408 dy2
= DIV_ROUND_UP(dbox
->y
+ dbox
->height
, blockheight
) - 1;
410 uint32_t width
= DIV_ROUND_UP(u_minify(src
->base
.width0
, info
->src
.level
), blockwidth
) * nelements
;
411 uint32_t height
= DIV_ROUND_UP(u_minify(src
->base
.height0
, info
->src
.level
), blockheight
);
413 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
414 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
416 uint32_t blit_cntl
= blit_control(dfmt
);
419 blit_cntl
|= 0x20000000;
421 if (info
->scissor_enable
) {
422 OUT_PKT4(ring
, REG_A6XX_GRAS_RESOLVE_CNTL_1
, 2);
423 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.minx
) |
424 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.miny
));
425 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.maxx
- 1) |
426 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.maxy
- 1));
427 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SCISSOR
;
430 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
431 OUT_RING(ring
, blit_cntl
);
433 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
434 OUT_RING(ring
, blit_cntl
);
436 for (unsigned i
= 0; i
< info
->dst
.box
.depth
; i
++) {
437 unsigned soff
= fd_resource_offset(src
, info
->src
.level
, sbox
->z
+ i
);
438 unsigned doff
= fd_resource_offset(dst
, info
->dst
.level
, dbox
->z
+ i
);
439 unsigned subwcoff
= fd_resource_ubwc_offset(src
, info
->src
.level
, sbox
->z
+ i
);
440 unsigned dubwcoff
= fd_resource_ubwc_offset(dst
, info
->dst
.level
, dbox
->z
+ i
);
441 bool subwc_enabled
= fd_resource_ubwc_enabled(src
, info
->src
.level
);
442 bool dubwc_enabled
= fd_resource_ubwc_enabled(dst
, info
->dst
.level
);
448 if (info
->filter
== PIPE_TEX_FILTER_LINEAR
)
449 filter
= A6XX_SP_PS_2D_SRC_INFO_FILTER
;
451 enum a3xx_msaa_samples samples
= fd_msaa_samples(src
->base
.nr_samples
);
453 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 10);
454 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt
) |
455 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile
) |
456 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap
) |
457 A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples
) |
458 COND(subwc_enabled
, A6XX_SP_PS_2D_SRC_INFO_FLAGS
) |
460 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width
) |
461 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height
)); /* SP_PS_2D_SRC_SIZE */
462 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
463 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch
));
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);
472 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_FLAGS_LO
, 6);
473 OUT_RELOC(ring
, src
->bo
, subwcoff
, 0, 0);
474 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_FLAGS_PITCH_PITCH(src
->ubwc_pitch
) |
475 A6XX_SP_PS_2D_SRC_FLAGS_PITCH_ARRAY_PITCH(src
->ubwc_size
));
476 OUT_RING(ring
, 0x00000000);
477 OUT_RING(ring
, 0x00000000);
478 OUT_RING(ring
, 0x00000000);
484 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
485 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(dfmt
) |
486 A6XX_RB_2D_DST_INFO_TILE_MODE(dtile
) |
487 A6XX_RB_2D_DST_INFO_COLOR_SWAP(dswap
) |
488 COND(dubwc_enabled
, A6XX_RB_2D_DST_INFO_FLAGS
));
489 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
490 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(dpitch
));
491 OUT_RING(ring
, 0x00000000);
492 OUT_RING(ring
, 0x00000000);
493 OUT_RING(ring
, 0x00000000);
494 OUT_RING(ring
, 0x00000000);
495 OUT_RING(ring
, 0x00000000);
498 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_FLAGS_LO
, 6);
499 OUT_RELOCW(ring
, dst
->bo
, dubwcoff
, 0, 0);
500 OUT_RING(ring
, A6XX_RB_2D_DST_FLAGS_PITCH_PITCH(dst
->ubwc_pitch
) |
501 A6XX_RB_2D_DST_FLAGS_PITCH_ARRAY_PITCH(dst
->ubwc_size
));
502 OUT_RING(ring
, 0x00000000);
503 OUT_RING(ring
, 0x00000000);
504 OUT_RING(ring
, 0x00000000);
510 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
511 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sx1
));
512 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sx2
));
513 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(sy1
));
514 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(sy2
));
516 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
517 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dx1
) | A6XX_GRAS_2D_DST_TL_Y(dy1
));
518 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dx2
) | A6XX_GRAS_2D_DST_BR_Y(dy2
));
520 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
521 OUT_RING(ring
, 0x3f);
524 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
527 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
528 OUT_RING(ring
, A6XX_SP_2D_SRC_FORMAT_COLOR_FORMAT(sfmt
) |
529 COND(util_format_is_pure_sint(info
->src
.format
),
530 A6XX_SP_2D_SRC_FORMAT_SINT
) |
531 COND(util_format_is_pure_uint(info
->src
.format
),
532 A6XX_SP_2D_SRC_FORMAT_UINT
) |
533 COND(util_format_is_snorm(info
->src
.format
),
534 A6XX_SP_2D_SRC_FORMAT_SINT
|
535 A6XX_SP_2D_SRC_FORMAT_NORM
) |
536 COND(util_format_is_unorm(info
->src
.format
),
537 // TODO sometimes blob uses UINT+NORM but dEQP seems unhappy about that
538 // A6XX_SP_2D_SRC_FORMAT_UINT |
539 A6XX_SP_2D_SRC_FORMAT_NORM
) |
542 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
543 OUT_RING(ring
, 0x01000000);
545 OUT_PKT7(ring
, CP_BLIT
, 1);
546 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
550 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
555 static bool handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
);
558 * Re-written z/s blits can still fail for various reasons (for example MSAA).
559 * But we want to do the fallback blit with the re-written pipe_blit_info,
560 * in particular as u_blitter cannot blit stencil. So handle the fallback
561 * ourself and never "fail".
564 do_rewritten_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
566 bool success
= handle_rgba_blit(ctx
, info
);
568 success
= fd_blitter_blit(ctx
, info
);
569 debug_assert(success
); /* fallback should never fail! */
574 * Handle depth/stencil blits either via u_blitter and/or re-writing the
575 * blit into an equivilant format that we can handle
578 handle_zs_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
580 struct pipe_blit_info blit
= *info
;
582 if (DEBUG_BLIT_FALLBACK
) {
583 fprintf(stderr
, "---- handle_zs_blit: ");
584 util_dump_blit_info(stderr
, info
);
585 fprintf(stderr
, "\ndst resource: ");
586 util_dump_resource(stderr
, info
->dst
.resource
);
587 fprintf(stderr
, "\nsrc resource: ");
588 util_dump_resource(stderr
, info
->src
.resource
);
589 fprintf(stderr
, "\n");
592 switch (info
->dst
.format
) {
593 case PIPE_FORMAT_S8_UINT
:
594 debug_assert(info
->mask
== PIPE_MASK_S
);
595 blit
.mask
= PIPE_MASK_R
;
596 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
597 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
598 return do_rewritten_blit(ctx
, &blit
);
600 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
601 if (info
->mask
& PIPE_MASK_Z
) {
602 blit
.mask
= PIPE_MASK_R
;
603 blit
.src
.format
= PIPE_FORMAT_R32_FLOAT
;
604 blit
.dst
.format
= PIPE_FORMAT_R32_FLOAT
;
605 do_rewritten_blit(ctx
, &blit
);
608 if (info
->mask
& PIPE_MASK_S
) {
609 blit
.mask
= PIPE_MASK_R
;
610 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
611 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
612 blit
.src
.resource
= &fd_resource(info
->src
.resource
)->stencil
->base
;
613 blit
.dst
.resource
= &fd_resource(info
->dst
.resource
)->stencil
->base
;
614 do_rewritten_blit(ctx
, &blit
);
619 case PIPE_FORMAT_Z16_UNORM
:
620 blit
.mask
= PIPE_MASK_R
;
621 blit
.src
.format
= PIPE_FORMAT_R16_UNORM
;
622 blit
.dst
.format
= PIPE_FORMAT_R16_UNORM
;
623 return do_rewritten_blit(ctx
, &blit
);
625 case PIPE_FORMAT_Z32_UNORM
:
626 case PIPE_FORMAT_Z32_FLOAT
:
627 debug_assert(info
->mask
== PIPE_MASK_Z
);
628 blit
.mask
= PIPE_MASK_R
;
629 blit
.src
.format
= PIPE_FORMAT_R32_UINT
;
630 blit
.dst
.format
= PIPE_FORMAT_R32_UINT
;
631 return do_rewritten_blit(ctx
, &blit
);
633 case PIPE_FORMAT_Z24X8_UNORM
:
634 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
636 if (info
->mask
& PIPE_MASK_Z
)
637 blit
.mask
|= PIPE_MASK_R
| PIPE_MASK_G
| PIPE_MASK_B
;
638 if (info
->mask
& PIPE_MASK_S
)
639 blit
.mask
|= PIPE_MASK_A
;
640 blit
.src
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
641 blit
.dst
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
642 return fd_blitter_blit(ctx
, &blit
);
650 handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
652 struct fd_batch
*batch
;
654 debug_assert(!(info
->mask
& PIPE_MASK_ZS
));
656 if (!can_do_blit(info
))
659 fd_fence_ref(&ctx
->last_fence
, NULL
);
661 batch
= fd_bc_alloc_batch(&ctx
->screen
->batch_cache
, ctx
, true);
663 fd6_emit_restore(batch
, batch
->draw
);
664 fd6_emit_lrz_flush(batch
->draw
);
666 mtx_lock(&ctx
->screen
->lock
);
668 fd_batch_resource_used(batch
, fd_resource(info
->src
.resource
), false);
669 fd_batch_resource_used(batch
, fd_resource(info
->dst
.resource
), true);
671 mtx_unlock(&ctx
->screen
->lock
);
675 if ((info
->src
.resource
->target
== PIPE_BUFFER
) &&
676 (info
->dst
.resource
->target
== PIPE_BUFFER
)) {
677 assert(fd_resource(info
->src
.resource
)->tile_mode
== TILE6_LINEAR
);
678 assert(fd_resource(info
->dst
.resource
)->tile_mode
== TILE6_LINEAR
);
679 emit_blit_buffer(batch
->draw
, info
);
681 /* I don't *think* we need to handle blits between buffer <-> !buffer */
682 debug_assert(info
->src
.resource
->target
!= PIPE_BUFFER
);
683 debug_assert(info
->dst
.resource
->target
!= PIPE_BUFFER
);
684 emit_blit_texture(batch
->draw
, info
);
687 fd6_event_write(batch
, batch
->draw
, 0x1d, true);
688 fd6_event_write(batch
, batch
->draw
, FACENESS_FLUSH
, true);
689 fd6_event_write(batch
, batch
->draw
, CACHE_FLUSH_TS
, true);
690 fd6_cache_inv(batch
, batch
->draw
);
692 fd_resource(info
->dst
.resource
)->valid
= true;
693 batch
->needs_flush
= true;
695 fd_batch_flush(batch
, false);
696 fd_batch_reference(&batch
, NULL
);
702 fd6_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
704 if (info
->mask
& PIPE_MASK_ZS
)
705 return handle_zs_blit(ctx
, info
);
706 return handle_rgba_blit(ctx
, info
);
710 fd6_blitter_init(struct pipe_context
*pctx
)
712 if (fd_mesa_debug
& FD_DBG_NOBLIT
)
715 fd_context(pctx
)->blit
= fd6_blit
;
719 fd6_tile_mode(const struct pipe_resource
*tmpl
)
721 /* basically just has to be a format we can blit, so uploads/downloads
722 * via linear staging buffer works:
724 if (ok_format(tmpl
->format
))