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 /* 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);
131 fail_if(info
->window_rectangle_include
);
133 fail_if(util_format_is_srgb(info
->src
.format
));
134 fail_if(util_format_is_srgb(info
->dst
.format
));
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
);
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])));
150 fail_if(info
->alpha_blend
);
156 emit_setup(struct fd_ringbuffer
*ring
)
158 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
159 OUT_RING(ring
, PC_CCU_INVALIDATE_COLOR
);
161 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
162 OUT_RING(ring
, LRZ_FLUSH
);
164 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
169 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
170 OUT_RING(ring
, 0x10000000);
174 blit_control(enum a6xx_color_fmt fmt
)
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
));
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
186 emit_blit_buffer(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
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
;
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");
203 src
= fd_resource(info
->src
.resource
);
204 dst
= fd_resource(info
->dst
.resource
);
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);
218 * Buffers can have dimensions bigger than max width, remap into
219 * multiple 1d blits to fit within max dimension
221 * Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
222 * seems to prevent overfetch related faults. Not quite sure what
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
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).
235 sshift
= sbox
->x
& 0x3f;
236 dshift
= dbox
->x
& 0x3f;
238 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
239 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
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
);
245 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
246 OUT_RING(ring
, blit_cntl
);
248 for (unsigned off
= 0; off
< sbox
->width
; off
+= (0x4000 - 0x40)) {
249 unsigned soff
, doff
, w
, p
;
251 soff
= (sbox
->x
+ off
) & ~0x3f;
252 doff
= (dbox
->x
+ off
) & ~0x3f;
254 w
= MIN2(sbox
->width
- off
, (0x4000 - 0x40));
257 debug_assert((soff
+ w
) <= fd_bo_size(src
->bo
));
258 debug_assert((doff
+ w
) <= fd_bo_size(dst
->bo
));
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
));
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);
278 OUT_RING(ring
, 0x00000000);
279 OUT_RING(ring
, 0x00000000);
280 OUT_RING(ring
, 0x00000000);
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);
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));
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));
310 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
311 OUT_RING(ring
, 0x3f);
314 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
317 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
318 OUT_RING(ring
, 0xf180);
320 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
321 OUT_RING(ring
, 0x01000000);
323 OUT_PKT7(ring
, CP_BLIT
, 1);
324 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
328 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
334 emit_blit_texture(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
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
;
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");
357 src
= fd_resource(info
->src
.resource
);
358 dst
= fd_resource(info
->dst
.resource
);
360 sslice
= fd_resource_slice(src
, info
->src
.level
);
361 dslice
= fd_resource_slice(dst
, info
->dst
.level
);
363 sfmt
= fd6_pipe2color(info
->src
.format
);
364 dfmt
= fd6_pipe2color(info
->dst
.format
);
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
);
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
;
376 sswap
= stile
? WZYX
: fd6_pipe2swap(info
->src
.format
);
377 dswap
= dtile
? WZYX
: fd6_pipe2swap(info
->dst
.format
);
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
;
384 debug_assert(!util_format_is_compressed(info
->dst
.format
));
388 spitch
= DIV_ROUND_UP(sslice
->pitch
, blockwidth
) * src
->cpp
;
389 dpitch
= DIV_ROUND_UP(dslice
->pitch
, blockwidth
) * dst
->cpp
;
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;
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;
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
);
404 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
405 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
407 uint32_t blit_cntl
= blit_control(dfmt
);
410 blit_cntl
|= 0x20000000;
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
;
421 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
422 OUT_RING(ring
, blit_cntl
);
424 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
425 OUT_RING(ring
, blit_cntl
);
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
);
435 if (info
->filter
== PIPE_TEX_FILTER_LINEAR
)
436 filter
= A6XX_SP_PS_2D_SRC_INFO_FILTER
;
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);
452 OUT_RING(ring
, 0x00000000);
453 OUT_RING(ring
, 0x00000000);
454 OUT_RING(ring
, 0x00000000);
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);
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
));
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
));
484 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
485 OUT_RING(ring
, 0x3f);
488 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
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
) |
506 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
507 OUT_RING(ring
, 0x01000000);
509 OUT_PKT7(ring
, CP_BLIT
, 1);
510 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
514 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
520 rewrite_zs_blit(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
522 struct pipe_blit_info separate
= *info
;
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");
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
);
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
);
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
);
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
);
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
);
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
);
592 rewrite_combined_zs_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
594 struct pipe_blit_info separate
= *info
;
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");
606 switch (info
->mask
) {
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
;
612 fd_blitter_blit(ctx
, &separate
);
616 separate
.mask
= PIPE_MASK_A
;
617 separate
.src
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
618 separate
.dst
.format
= PIPE_FORMAT_R8G8B8A8_UNORM
;
620 fd_blitter_blit(ctx
, &separate
);
629 fd6_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
631 struct fd_batch
*batch
;
633 if (info
->dst
.format
== PIPE_FORMAT_Z24_UNORM_S8_UINT
&&
634 info
->mask
!= PIPE_MASK_ZS
) {
635 rewrite_combined_zs_blit(ctx
, info
);
639 if (!can_do_blit(info
))
642 fd_fence_ref(ctx
->base
.screen
, &ctx
->last_fence
, NULL
);
644 batch
= fd_bc_alloc_batch(&ctx
->screen
->batch_cache
, ctx
, true);
646 fd6_emit_restore(batch
, batch
->draw
);
647 fd6_emit_lrz_flush(batch
->draw
);
649 mtx_lock(&ctx
->screen
->lock
);
651 fd_batch_resource_used(batch
, fd_resource(info
->src
.resource
), false);
652 fd_batch_resource_used(batch
, fd_resource(info
->dst
.resource
), true);
654 mtx_unlock(&ctx
->screen
->lock
);
656 emit_setup(batch
->draw
);
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
);
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
);
668 if (info
->mask
& (PIPE_MASK_ZS
)) {
669 rewrite_zs_blit(batch
->draw
, info
);
671 emit_blit_texture(batch
->draw
, info
);
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);
679 fd_resource(info
->dst
.resource
)->valid
= true;
680 batch
->needs_flush
= true;
682 fd_batch_flush(batch
, false, false);
683 fd_batch_reference(&batch
, NULL
);
689 fd6_blitter_init(struct pipe_context
*pctx
)
691 if (fd_mesa_debug
& FD_DBG_NOBLIT
)
694 fd_context(pctx
)->blit
= fd6_blit
;
698 fd6_tile_mode(const struct pipe_resource
*tmpl
)
700 /* basically just has to be a format we can blit, so uploads/downloads
701 * via linear staging buffer works:
703 if (ok_format(tmpl
->format
))