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
);
62 if (fd6_ifmt(fmt
) == 0)
68 #define DEBUG_BLIT_FALLBACK 0
69 #define fail_if(cond) \
72 if (DEBUG_BLIT_FALLBACK) { \
73 fprintf(stderr, "falling back: %s for blit:\n", #cond); \
74 util_dump_blit_info(stderr, info); \
75 fprintf(stderr, "\nsrc: "); \
76 util_dump_resource(stderr, info->src.resource); \
77 fprintf(stderr, "\ndst: "); \
78 util_dump_resource(stderr, info->dst.resource); \
79 fprintf(stderr, "\n"); \
86 can_do_blit(const struct pipe_blit_info
*info
)
88 /* I think we can do scaling, but not in z dimension since that would
91 fail_if(info
->dst
.box
.depth
!= info
->src
.box
.depth
);
93 /* We can blit if both or neither formats are compressed formats... */
94 fail_if(util_format_is_compressed(info
->src
.format
) !=
95 util_format_is_compressed(info
->src
.format
));
97 /* Fail if unsupported format: */
98 fail_if(!ok_format(info
->src
.format
));
99 fail_if(!ok_format(info
->dst
.format
));
101 /* ... but only if they're the same compression format. */
102 fail_if(util_format_is_compressed(info
->src
.format
) &&
103 info
->src
.format
!= info
->dst
.format
);
105 /* hw ignores {SRC,DST}_INFO.COLOR_SWAP if {SRC,DST}_INFO.TILE_MODE
106 * is set (not linear). We can kind of get around that when tiling/
107 * untiling by setting both src and dst COLOR_SWAP=WZYX, but that
108 * means the formats must match:
110 fail_if((fd_resource(info
->dst
.resource
)->tile_mode
||
111 fd_resource(info
->src
.resource
)->tile_mode
) &&
112 info
->dst
.format
!= info
->src
.format
);
114 /* src box can be inverted, which we don't support.. dst box cannot: */
115 fail_if((info
->src
.box
.width
< 0) || (info
->src
.box
.height
< 0));
117 fail_if(!ok_dims(info
->src
.resource
, &info
->src
.box
, info
->src
.level
));
119 fail_if(!ok_dims(info
->dst
.resource
, &info
->dst
.box
, info
->dst
.level
));
121 debug_assert(info
->dst
.box
.width
>= 0);
122 debug_assert(info
->dst
.box
.height
>= 0);
123 debug_assert(info
->dst
.box
.depth
>= 0);
125 fail_if(info
->dst
.resource
->nr_samples
+ info
->src
.resource
->nr_samples
> 2);
127 fail_if(info
->window_rectangle_include
);
129 fail_if(info
->render_condition_enable
);
131 fail_if(info
->alpha_blend
);
133 fail_if(info
->mask
!= util_format_get_mask(info
->src
.format
));
135 fail_if(info
->mask
!= util_format_get_mask(info
->dst
.format
));
141 emit_setup(struct fd_ringbuffer
*ring
)
143 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
144 OUT_RING(ring
, PC_CCU_INVALIDATE_COLOR
);
146 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
147 OUT_RING(ring
, LRZ_FLUSH
);
149 OUT_PKT7(ring
, CP_SKIP_IB2_ENABLE_GLOBAL
, 1);
154 OUT_PKT4(ring
, REG_A6XX_RB_CCU_CNTL
, 1);
155 OUT_RING(ring
, 0x10000000);
159 blit_control(enum a6xx_color_fmt fmt
)
161 unsigned blit_cntl
= 0xf00000;
162 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt
);
163 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_IFMT(fd6_ifmt(fmt
));
167 /* buffers need to be handled specially since x/width can exceed the bounds
168 * supported by hw.. if necessary decompose into (potentially) two 2D blits
171 emit_blit_buffer(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
173 const struct pipe_box
*sbox
= &info
->src
.box
;
174 const struct pipe_box
*dbox
= &info
->dst
.box
;
175 struct fd_resource
*src
, *dst
;
176 unsigned sshift
, dshift
;
178 if (DEBUG_BLIT_FALLBACK
) {
179 fprintf(stderr
, "buffer blit: ");
180 util_dump_blit_info(stderr
, info
);
181 fprintf(stderr
, "\ndst resource: ");
182 util_dump_resource(stderr
, info
->dst
.resource
);
183 fprintf(stderr
, "\nsrc resource: ");
184 util_dump_resource(stderr
, info
->src
.resource
);
185 fprintf(stderr
, "\n");
188 src
= fd_resource(info
->src
.resource
);
189 dst
= fd_resource(info
->dst
.resource
);
191 debug_assert(src
->cpp
== 1);
192 debug_assert(dst
->cpp
== 1);
193 debug_assert(info
->src
.resource
->format
== info
->dst
.resource
->format
);
194 debug_assert((sbox
->y
== 0) && (sbox
->height
== 1));
195 debug_assert((dbox
->y
== 0) && (dbox
->height
== 1));
196 debug_assert((sbox
->z
== 0) && (sbox
->depth
== 1));
197 debug_assert((dbox
->z
== 0) && (dbox
->depth
== 1));
198 debug_assert(sbox
->width
== dbox
->width
);
199 debug_assert(info
->src
.level
== 0);
200 debug_assert(info
->dst
.level
== 0);
203 * Buffers can have dimensions bigger than max width, remap into
204 * multiple 1d blits to fit within max dimension
206 * Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
207 * seems to prevent overfetch related faults. Not quite sure what
210 * Low 6 bits of SRC/DST addresses need to be zero (ie. address
211 * aligned to 64) so we need to shift src/dst x1/x2 to make up the
212 * difference. On top of already splitting up the blit so width
215 * We perhaps could do a bit better, if src and dst are aligned but
216 * in the worst case this means we have to split the copy up into
217 * 16k (0x4000) minus 64 (0x40).
220 sshift
= sbox
->x
& 0x3f;
221 dshift
= dbox
->x
& 0x3f;
223 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
224 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
226 uint32_t blit_cntl
= blit_control(RB6_R8_UNORM
) | 0x20000000;
227 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
228 OUT_RING(ring
, blit_cntl
);
230 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
231 OUT_RING(ring
, blit_cntl
);
233 for (unsigned off
= 0; off
< sbox
->width
; off
+= (0x4000 - 0x40)) {
234 unsigned soff
, doff
, w
, p
;
236 soff
= (sbox
->x
+ off
) & ~0x3f;
237 doff
= (dbox
->x
+ off
) & ~0x3f;
239 w
= MIN2(sbox
->width
- off
, (0x4000 - 0x40));
242 debug_assert((soff
+ w
) <= fd_bo_size(src
->bo
));
243 debug_assert((doff
+ w
) <= fd_bo_size(dst
->bo
));
248 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 13);
249 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
250 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR
) |
251 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX
) | 0x500000);
252 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift
+ w
) |
253 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
254 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
255 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p
));
257 OUT_RING(ring
, 0x00000000);
258 OUT_RING(ring
, 0x00000000);
259 OUT_RING(ring
, 0x00000000);
260 OUT_RING(ring
, 0x00000000);
261 OUT_RING(ring
, 0x00000000);
263 OUT_RING(ring
, 0x00000000);
264 OUT_RING(ring
, 0x00000000);
265 OUT_RING(ring
, 0x00000000);
270 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
271 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
272 A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
273 A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX
));
274 OUT_RELOC(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
275 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(p
));
276 OUT_RING(ring
, 0x00000000);
277 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_GRAS_2D_SRC_TL_X
, 4);
286 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sshift
));
287 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sshift
+ w
- 1));
288 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(0));
289 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(0));
291 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
292 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dshift
) | A6XX_GRAS_2D_DST_TL_Y(0));
293 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dshift
+ w
- 1) | A6XX_GRAS_2D_DST_BR_Y(0));
295 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
296 OUT_RING(ring
, 0x3f);
299 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
302 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
303 OUT_RING(ring
, 0xf180);
305 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
306 OUT_RING(ring
, 0x01000000);
308 OUT_PKT7(ring
, CP_BLIT
, 1);
309 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
313 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
319 emit_blit_texture(struct fd_ringbuffer
*ring
, const struct pipe_blit_info
*info
)
321 const struct pipe_box
*sbox
= &info
->src
.box
;
322 const struct pipe_box
*dbox
= &info
->dst
.box
;
323 struct fd_resource
*src
, *dst
;
324 struct fd_resource_slice
*sslice
, *dslice
;
325 enum a6xx_color_fmt sfmt
, dfmt
;
326 enum a6xx_tile_mode stile
, dtile
;
327 enum a3xx_color_swap sswap
, dswap
;
328 unsigned spitch
, dpitch
;
329 unsigned sx1
, sy1
, sx2
, sy2
;
330 unsigned dx1
, dy1
, dx2
, dy2
;
332 if (DEBUG_BLIT_FALLBACK
) {
333 fprintf(stderr
, "texture blit: ");
334 util_dump_blit_info(stderr
, info
);
335 fprintf(stderr
, "\ndst resource: ");
336 util_dump_resource(stderr
, info
->dst
.resource
);
337 fprintf(stderr
, "\nsrc resource: ");
338 util_dump_resource(stderr
, info
->src
.resource
);
339 fprintf(stderr
, "\n");
342 src
= fd_resource(info
->src
.resource
);
343 dst
= fd_resource(info
->dst
.resource
);
345 sslice
= fd_resource_slice(src
, info
->src
.level
);
346 dslice
= fd_resource_slice(dst
, info
->dst
.level
);
348 sfmt
= fd6_pipe2color(info
->src
.format
);
349 dfmt
= fd6_pipe2color(info
->dst
.format
);
351 int blocksize
= util_format_get_blocksize(info
->src
.format
);
352 int blockwidth
= util_format_get_blockwidth(info
->src
.format
);
353 int blockheight
= util_format_get_blockheight(info
->src
.format
);
356 stile
= fd_resource_level_linear(info
->src
.resource
, info
->src
.level
) ?
357 TILE6_LINEAR
: src
->tile_mode
;
358 dtile
= fd_resource_level_linear(info
->dst
.resource
, info
->dst
.level
) ?
359 TILE6_LINEAR
: dst
->tile_mode
;
361 sswap
= fd6_pipe2swap(info
->src
.format
);
362 dswap
= fd6_pipe2swap(info
->dst
.format
);
364 if (util_format_is_compressed(info
->src
.format
)) {
365 debug_assert(info
->src
.format
== info
->dst
.format
);
366 sfmt
= dfmt
= RB6_R8_UNORM
;
367 nelements
= blocksize
;
369 debug_assert(!util_format_is_compressed(info
->dst
.format
));
373 spitch
= DIV_ROUND_UP(sslice
->pitch
, blockwidth
) * src
->cpp
;
374 dpitch
= DIV_ROUND_UP(dslice
->pitch
, blockwidth
) * dst
->cpp
;
376 sx1
= sbox
->x
/ blockwidth
* nelements
;
377 sy1
= sbox
->y
/ blockheight
;
378 sx2
= DIV_ROUND_UP(sbox
->x
+ sbox
->width
, blockwidth
) * nelements
- 1;
379 sy2
= DIV_ROUND_UP(sbox
->y
+ sbox
->height
, blockheight
) - 1;
381 dx1
= dbox
->x
/ blockwidth
* nelements
;
382 dy1
= dbox
->y
/ blockheight
;
383 dx2
= DIV_ROUND_UP(dbox
->x
+ dbox
->width
, blockwidth
) * nelements
- 1;
384 dy2
= DIV_ROUND_UP(dbox
->y
+ dbox
->height
, blockheight
) - 1;
386 uint32_t width
= DIV_ROUND_UP(u_minify(src
->base
.width0
, info
->src
.level
), blockwidth
) * nelements
;
387 uint32_t height
= DIV_ROUND_UP(u_minify(src
->base
.height0
, info
->src
.level
), blockheight
);
389 /* if dtile, then dswap ignored by hw, and likewise if stile then sswap
390 * ignored by hw.. but in this case we have already rejected the blit
391 * if src and dst formats differ, so juse use WZYX for both src and
392 * dst swap mode (so we don't change component order)
394 if (stile
|| dtile
) {
395 debug_assert(info
->src
.format
== info
->dst
.format
);
396 sswap
= dswap
= WZYX
;
399 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
400 OUT_RING(ring
, A2XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
402 uint32_t blit_cntl
= blit_control(dfmt
);
405 blit_cntl
|= 0x20000000;
407 if (info
->scissor_enable
) {
408 OUT_PKT4(ring
, REG_A6XX_GRAS_RESOLVE_CNTL_1
, 2);
409 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.minx
) |
410 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.miny
));
411 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.maxx
- 1) |
412 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.maxy
- 1));
413 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SCISSOR
;
416 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
417 OUT_RING(ring
, blit_cntl
);
419 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
420 OUT_RING(ring
, blit_cntl
);
422 for (unsigned i
= 0; i
< info
->dst
.box
.depth
; i
++) {
423 unsigned soff
= fd_resource_offset(src
, info
->src
.level
, sbox
->z
+ i
);
424 unsigned doff
= fd_resource_offset(dst
, info
->dst
.level
, dbox
->z
+ i
);
430 if (info
->filter
== PIPE_TEX_FILTER_LINEAR
)
431 filter
= A6XX_SP_PS_2D_SRC_INFO_FILTER
;
433 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 13);
434 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt
) |
435 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile
) |
436 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap
) | 0x500000 | filter
);
437 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width
) |
438 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height
)); /* SP_PS_2D_SRC_SIZE */
439 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
440 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch
));
441 OUT_RING(ring
, 0x00000000);
442 OUT_RING(ring
, 0x00000000);
443 OUT_RING(ring
, 0x00000000);
444 OUT_RING(ring
, 0x00000000);
445 OUT_RING(ring
, 0x00000000);
447 OUT_RING(ring
, 0x00000000);
448 OUT_RING(ring
, 0x00000000);
449 OUT_RING(ring
, 0x00000000);
454 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
455 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(dfmt
) |
456 A6XX_RB_2D_DST_INFO_TILE_MODE(dtile
) |
457 A6XX_RB_2D_DST_INFO_COLOR_SWAP(dswap
));
458 OUT_RELOC(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
459 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(dpitch
));
460 OUT_RING(ring
, 0x00000000);
461 OUT_RING(ring
, 0x00000000);
462 OUT_RING(ring
, 0x00000000);
463 OUT_RING(ring
, 0x00000000);
464 OUT_RING(ring
, 0x00000000);
469 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
470 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sx1
));
471 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sx2
));
472 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(sy1
));
473 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(sy2
));
475 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
476 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dx1
) | A6XX_GRAS_2D_DST_TL_Y(dy1
));
477 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dx2
) | A6XX_GRAS_2D_DST_BR_Y(dy2
));
479 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
480 OUT_RING(ring
, 0x3f);
483 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
486 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
487 OUT_RING(ring
, A6XX_SP_2D_SRC_FORMAT_COLOR_FORMAT(sfmt
) |
488 COND(util_format_is_pure_sint(info
->src
.format
),
489 A6XX_SP_2D_SRC_FORMAT_SINT
) |
490 COND(util_format_is_pure_uint(info
->src
.format
),
491 A6XX_SP_2D_SRC_FORMAT_UINT
) |
492 COND(util_format_is_snorm(info
->src
.format
),
493 A6XX_SP_2D_SRC_FORMAT_SINT
|
494 A6XX_SP_2D_SRC_FORMAT_NORM
) |
495 COND(util_format_is_unorm(info
->src
.format
),
496 // TODO sometimes blob uses UINT+NORM but dEQP seems unhappy about that
497 // A6XX_SP_2D_SRC_FORMAT_UINT |
498 A6XX_SP_2D_SRC_FORMAT_NORM
) |
501 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
502 OUT_RING(ring
, 0x01000000);
504 OUT_PKT7(ring
, CP_BLIT
, 1);
505 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
509 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
515 emit_blit(struct pipe_context
*pctx
, const struct pipe_blit_info
*info
)
517 struct fd_context
*ctx
= fd_context(pctx
);
518 struct fd_batch
*batch
;
520 fd_fence_ref(pctx
->screen
, &ctx
->last_fence
, NULL
);
522 batch
= fd_bc_alloc_batch(&ctx
->screen
->batch_cache
, ctx
, true);
524 fd6_emit_restore(batch
, batch
->draw
);
525 fd6_emit_lrz_flush(batch
->draw
);
527 mtx_lock(&ctx
->screen
->lock
);
529 fd_batch_resource_used(batch
, fd_resource(info
->src
.resource
), false);
530 fd_batch_resource_used(batch
, fd_resource(info
->dst
.resource
), true);
532 mtx_unlock(&ctx
->screen
->lock
);
534 emit_setup(batch
->draw
);
536 if ((info
->src
.resource
->target
== PIPE_BUFFER
) &&
537 (info
->dst
.resource
->target
== PIPE_BUFFER
)) {
538 assert(fd_resource(info
->src
.resource
)->tile_mode
== TILE6_LINEAR
);
539 assert(fd_resource(info
->dst
.resource
)->tile_mode
== TILE6_LINEAR
);
540 emit_blit_buffer(batch
->draw
, info
);
542 /* I don't *think* we need to handle blits between buffer <-> !buffer */
543 debug_assert(info
->src
.resource
->target
!= PIPE_BUFFER
);
544 debug_assert(info
->dst
.resource
->target
!= PIPE_BUFFER
);
545 emit_blit_texture(batch
->draw
, info
);
548 fd6_event_write(batch
, batch
->draw
, 0x1d, true);
549 fd6_event_write(batch
, batch
->draw
, FACENESS_FLUSH
, true);
550 fd6_event_write(batch
, batch
->draw
, CACHE_FLUSH_TS
, true);
552 fd_resource(info
->dst
.resource
)->valid
= true;
553 batch
->needs_flush
= true;
555 fd_batch_flush(batch
, false, false);
556 fd_batch_reference(&batch
, NULL
);
560 fd6_blit(struct pipe_context
*pctx
, const struct pipe_blit_info
*info
)
562 struct fd_context
*ctx
= fd_context(pctx
);
564 if (!can_do_blit(info
)) {
565 fd_blitter_blit(ctx
, info
);
569 emit_blit(pctx
, info
);
573 fd6_resource_copy_region(struct pipe_context
*pctx
,
574 struct pipe_resource
*dst
,
576 unsigned dstx
, unsigned dsty
, unsigned dstz
,
577 struct pipe_resource
*src
,
579 const struct pipe_box
*src_box
)
581 struct pipe_blit_info info
;
583 debug_assert(src
->format
== dst
->format
);
585 memset(&info
, 0, sizeof info
);
586 info
.dst
.resource
= dst
;
587 info
.dst
.level
= dst_level
;
588 info
.dst
.box
.x
= dstx
;
589 info
.dst
.box
.y
= dsty
;
590 info
.dst
.box
.z
= dstz
;
591 info
.dst
.box
.width
= src_box
->width
;
592 info
.dst
.box
.height
= src_box
->height
;
593 assert(info
.dst
.box
.width
>= 0);
594 assert(info
.dst
.box
.height
>= 0);
595 info
.dst
.box
.depth
= 1;
596 info
.dst
.format
= dst
->format
;
597 info
.src
.resource
= src
;
598 info
.src
.level
= src_level
;
599 info
.src
.box
= *src_box
;
600 info
.src
.format
= src
->format
;
601 info
.mask
= util_format_get_mask(src
->format
);
602 info
.filter
= PIPE_TEX_FILTER_NEAREST
;
603 info
.scissor_enable
= 0;
605 if (!can_do_blit(&info
)) {
606 fd_resource_copy_region(pctx
,
607 dst
, dst_level
, dstx
, dsty
, dstz
,
608 src
, src_level
, src_box
);
612 emit_blit(pctx
, &info
);
616 fd6_blitter_init(struct pipe_context
*pctx
)
618 if (fd_mesa_debug
& FD_DBG_NOBLIT
)
621 pctx
->resource_copy_region
= fd6_resource_copy_region
;
622 pctx
->blit
= fd6_blit
;
626 fd6_tile_mode(const struct pipe_resource
*tmpl
)
628 /* basically just has to be a format we can blit, so uploads/downloads
629 * via linear staging buffer works: