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 fail_if(info
->dst
.resource
->nr_samples
> 1);
134 fail_if(info
->window_rectangle_include
);
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_batch
*batch
)
158 struct fd_ringbuffer
*ring
= batch
->draw
;
160 fd6_event_write(batch
, ring
, 0x1d, true);
161 fd6_event_write(batch
, ring
, FACENESS_FLUSH
, true);
162 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_COLOR
, false);
163 fd6_event_write(batch
, ring
, PC_CCU_INVALIDATE_DEPTH
, false);
167 blit_control(enum a6xx_color_fmt fmt
, bool is_srgb
)
169 enum a6xx_2d_ifmt ifmt
= fd6_ifmt(fmt
);
172 assert(ifmt
== R2D_UNORM8
);
173 ifmt
= R2D_UNORM8_SRGB
;
176 return A6XX_RB_2D_BLIT_CNTL_MASK(0xf) |
177 A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt
) |
178 A6XX_RB_2D_BLIT_CNTL_IFMT(ifmt
);
181 /* buffers need to be handled specially since x/width can exceed the bounds
182 * supported by hw.. if necessary decompose into (potentially) two 2D blits
185 emit_blit_buffer(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
186 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
;
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
->layout
.cpp
== 1);
207 debug_assert(dst
->layout
.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
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
241 uint32_t blit_cntl
= blit_control(RB6_R8_UNORM
, false) | 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
, 10);
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
) |
268 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift
+ w
) |
269 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
270 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
271 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p
));
273 OUT_RING(ring
, 0x00000000);
274 OUT_RING(ring
, 0x00000000);
275 OUT_RING(ring
, 0x00000000);
276 OUT_RING(ring
, 0x00000000);
277 OUT_RING(ring
, 0x00000000);
282 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
283 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(RB6_R8_UNORM
) |
284 A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR
) |
285 A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX
));
286 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
287 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(p
));
288 OUT_RING(ring
, 0x00000000);
289 OUT_RING(ring
, 0x00000000);
290 OUT_RING(ring
, 0x00000000);
291 OUT_RING(ring
, 0x00000000);
292 OUT_RING(ring
, 0x00000000);
297 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
298 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sshift
));
299 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sshift
+ w
- 1));
300 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(0));
301 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(0));
303 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
304 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dshift
) | A6XX_GRAS_2D_DST_TL_Y(0));
305 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dshift
+ w
- 1) | A6XX_GRAS_2D_DST_BR_Y(0));
307 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
308 OUT_RING(ring
, 0x3f);
311 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
314 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
315 OUT_RING(ring
, 0xf180);
317 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
318 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_UNKNOWN_8E04_blit
);
320 OUT_PKT7(ring
, CP_BLIT
, 1);
321 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
325 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
326 OUT_RING(ring
, 0); /* RB_UNKNOWN_8E04 */
331 emit_blit_or_clear_texture(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
332 const struct pipe_blit_info
*info
, union pipe_color_union
*color
)
334 const struct pipe_box
*sbox
= &info
->src
.box
;
335 const struct pipe_box
*dbox
= &info
->dst
.box
;
336 struct fd_resource
*src
, *dst
;
337 struct fdl_slice
*sslice
, *dslice
;
338 enum a6xx_color_fmt sfmt
, dfmt
;
339 enum a6xx_tile_mode stile
, dtile
;
340 enum a3xx_color_swap sswap
, dswap
;
341 unsigned spitch
, dpitch
;
342 int sx1
, sy1
, sx2
, sy2
;
343 int dx1
, dy1
, dx2
, dy2
;
346 fprintf(stderr
, "texture blit: ");
347 util_dump_blit_info(stderr
, info
);
348 fprintf(stderr
, "\ndst resource: ");
349 util_dump_resource(stderr
, info
->dst
.resource
);
350 fprintf(stderr
, "\nsrc resource: ");
351 util_dump_resource(stderr
, info
->src
.resource
);
352 fprintf(stderr
, "\n");
355 src
= fd_resource(info
->src
.resource
);
356 dst
= fd_resource(info
->dst
.resource
);
358 sslice
= fd_resource_slice(src
, info
->src
.level
);
359 dslice
= fd_resource_slice(dst
, info
->dst
.level
);
361 sfmt
= fd6_pipe2color(info
->src
.format
);
362 dfmt
= fd6_pipe2color(info
->dst
.format
);
364 int blocksize
= util_format_get_blocksize(info
->src
.format
);
365 int blockwidth
= util_format_get_blockwidth(info
->src
.format
);
366 int blockheight
= util_format_get_blockheight(info
->src
.format
);
369 stile
= fd_resource_tile_mode(info
->src
.resource
, info
->src
.level
);
370 dtile
= fd_resource_tile_mode(info
->dst
.resource
, info
->dst
.level
);
372 /* Linear levels of a tiled resource are always WZYX, so look at
373 * rsc->tile_mode to determine the swap.
375 sswap
= fd6_resource_swap(src
, info
->src
.format
);
376 dswap
= fd6_resource_swap(dst
, info
->dst
.format
);
378 if (util_format_is_compressed(info
->src
.format
)) {
379 debug_assert(info
->src
.format
== info
->dst
.format
);
380 sfmt
= dfmt
= RB6_R8_UNORM
;
381 nelements
= blocksize
;
383 debug_assert(!util_format_is_compressed(info
->dst
.format
));
384 nelements
= (dst
->base
.nr_samples
? dst
->base
.nr_samples
: 1);
387 spitch
= DIV_ROUND_UP(sslice
->pitch
, blockwidth
) * src
->layout
.cpp
;
388 dpitch
= DIV_ROUND_UP(dslice
->pitch
, blockwidth
) * dst
->layout
.cpp
;
390 sx1
= sbox
->x
/ blockwidth
* nelements
;
391 sy1
= sbox
->y
/ blockheight
;
392 sx2
= DIV_ROUND_UP(sbox
->x
+ sbox
->width
, blockwidth
) * nelements
- 1;
393 sy2
= DIV_ROUND_UP(sbox
->y
+ sbox
->height
, blockheight
) - 1;
395 dx1
= dbox
->x
/ blockwidth
* nelements
;
396 dy1
= dbox
->y
/ blockheight
;
397 dx2
= DIV_ROUND_UP(dbox
->x
+ dbox
->width
, blockwidth
) * nelements
- 1;
398 dy2
= DIV_ROUND_UP(dbox
->y
+ dbox
->height
, blockheight
) - 1;
400 uint32_t width
= DIV_ROUND_UP(u_minify(src
->base
.width0
, info
->src
.level
), blockwidth
) * nelements
;
401 uint32_t height
= DIV_ROUND_UP(u_minify(src
->base
.height0
, info
->src
.level
), blockheight
);
403 OUT_PKT7(ring
, CP_SET_MARKER
, 1);
404 OUT_RING(ring
, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE
));
406 uint32_t blit_cntl
= blit_control(dfmt
, util_format_is_srgb(info
->dst
.format
));
409 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SOLID_COLOR
;
411 switch (info
->dst
.format
) {
412 case PIPE_FORMAT_Z24X8_UNORM
:
413 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
414 case PIPE_FORMAT_X24S8_UINT
: {
415 uint32_t depth_unorm24
= color
->f
[0] * ((1u << 24) - 1);
416 uint8_t stencil
= color
->ui
[1];
417 color
->ui
[0] = depth_unorm24
& 0xff;
418 color
->ui
[1] = (depth_unorm24
>> 8) & 0xff;
419 color
->ui
[2] = (depth_unorm24
>> 16) & 0xff;
420 color
->ui
[3] = stencil
;
422 dfmt
= RB6_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
425 case PIPE_FORMAT_B5G6R5_UNORM
:
426 case PIPE_FORMAT_B5G5R5A1_UNORM
:
427 case PIPE_FORMAT_B5G5R5X1_UNORM
:
428 case PIPE_FORMAT_B4G4R4A4_UNORM
:
429 color
->ui
[0] = float_to_ubyte(color
->f
[0]);
430 color
->ui
[1] = float_to_ubyte(color
->f
[1]);
431 color
->ui
[2] = float_to_ubyte(color
->f
[2]);
432 color
->ui
[3] = float_to_ubyte(color
->f
[3]);
438 OUT_PKT4(ring
, REG_A6XX_RB_2D_SRC_SOLID_C0
, 4);
440 switch (fd6_ifmt(dfmt
)) {
442 case R2D_UNORM8_SRGB
:
443 OUT_RING(ring
, float_to_ubyte(color
->f
[0]));
444 OUT_RING(ring
, float_to_ubyte(color
->f
[1]));
445 OUT_RING(ring
, float_to_ubyte(color
->f
[2]));
446 OUT_RING(ring
, float_to_ubyte(color
->f
[3]));
449 OUT_RING(ring
, _mesa_float_to_half(color
->f
[0]));
450 OUT_RING(ring
, _mesa_float_to_half(color
->f
[1]));
451 OUT_RING(ring
, _mesa_float_to_half(color
->f
[2]));
452 OUT_RING(ring
, _mesa_float_to_half(color
->f
[3]));
453 sfmt
= RB6_R16G16B16A16_FLOAT
;
462 OUT_RING(ring
, color
->ui
[0]);
463 OUT_RING(ring
, color
->ui
[1]);
464 OUT_RING(ring
, color
->ui
[2]);
465 OUT_RING(ring
, color
->ui
[3]);
471 blit_cntl
|= 0x20000000;
473 if (info
->scissor_enable
) {
474 OUT_PKT4(ring
, REG_A6XX_GRAS_RESOLVE_CNTL_1
, 2);
475 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.minx
) |
476 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.miny
));
477 OUT_RING(ring
, A6XX_GRAS_RESOLVE_CNTL_1_X(info
->scissor
.maxx
- 1) |
478 A6XX_GRAS_RESOLVE_CNTL_1_Y(info
->scissor
.maxy
- 1));
479 blit_cntl
|= A6XX_RB_2D_BLIT_CNTL_SCISSOR
;
482 OUT_PKT4(ring
, REG_A6XX_RB_2D_BLIT_CNTL
, 1);
483 OUT_RING(ring
, blit_cntl
);
485 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_BLIT_CNTL
, 1);
486 OUT_RING(ring
, blit_cntl
);
488 for (unsigned i
= 0; i
< info
->dst
.box
.depth
; i
++) {
489 unsigned soff
= fd_resource_offset(src
, info
->src
.level
, sbox
->z
+ i
);
490 unsigned doff
= fd_resource_offset(dst
, info
->dst
.level
, dbox
->z
+ i
);
491 bool subwc_enabled
= fd_resource_ubwc_enabled(src
, info
->src
.level
);
492 bool dubwc_enabled
= fd_resource_ubwc_enabled(dst
, info
->dst
.level
);
498 if (info
->filter
== PIPE_TEX_FILTER_LINEAR
)
499 filter
= A6XX_SP_PS_2D_SRC_INFO_FILTER
;
501 enum a3xx_msaa_samples samples
= fd_msaa_samples(src
->base
.nr_samples
);
503 if (sfmt
== RB6_R10G10B10A2_UNORM
)
504 sfmt
= RB6_R10G10B10A2_FLOAT16
;
506 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_INFO
, 10);
507 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt
) |
508 A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile
) |
509 A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap
) |
510 A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples
) |
511 COND(samples
> MSAA_ONE
&& (info
->mask
& PIPE_MASK_RGBA
),
512 A6XX_SP_PS_2D_SRC_INFO_SAMPLES_AVERAGE
) |
513 COND(subwc_enabled
, A6XX_SP_PS_2D_SRC_INFO_FLAGS
) |
514 COND(util_format_is_srgb(info
->src
.format
), A6XX_SP_PS_2D_SRC_INFO_SRGB
) |
516 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width
) |
517 A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height
)); /* SP_PS_2D_SRC_SIZE */
518 OUT_RELOC(ring
, src
->bo
, soff
, 0, 0); /* SP_PS_2D_SRC_LO/HI */
519 OUT_RING(ring
, A6XX_SP_PS_2D_SRC_PITCH_PITCH(spitch
));
521 OUT_RING(ring
, 0x00000000);
522 OUT_RING(ring
, 0x00000000);
523 OUT_RING(ring
, 0x00000000);
524 OUT_RING(ring
, 0x00000000);
525 OUT_RING(ring
, 0x00000000);
528 OUT_PKT4(ring
, REG_A6XX_SP_PS_2D_SRC_FLAGS_LO
, 6);
529 fd6_emit_flag_reference(ring
, src
, info
->src
.level
, sbox
->z
+ i
);
530 OUT_RING(ring
, 0x00000000);
531 OUT_RING(ring
, 0x00000000);
532 OUT_RING(ring
, 0x00000000);
538 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_INFO
, 9);
539 OUT_RING(ring
, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(dfmt
) |
540 A6XX_RB_2D_DST_INFO_TILE_MODE(dtile
) |
541 A6XX_RB_2D_DST_INFO_COLOR_SWAP(dswap
) |
542 COND(util_format_is_srgb(info
->dst
.format
), A6XX_RB_2D_DST_INFO_SRGB
) |
543 COND(dubwc_enabled
, A6XX_RB_2D_DST_INFO_FLAGS
));
544 OUT_RELOCW(ring
, dst
->bo
, doff
, 0, 0); /* RB_2D_DST_LO/HI */
545 OUT_RING(ring
, A6XX_RB_2D_DST_SIZE_PITCH(dpitch
));
546 OUT_RING(ring
, 0x00000000);
547 OUT_RING(ring
, 0x00000000);
548 OUT_RING(ring
, 0x00000000);
549 OUT_RING(ring
, 0x00000000);
550 OUT_RING(ring
, 0x00000000);
553 OUT_PKT4(ring
, REG_A6XX_RB_2D_DST_FLAGS_LO
, 6);
554 fd6_emit_flag_reference(ring
, dst
, info
->dst
.level
, dbox
->z
+ i
);
555 OUT_RING(ring
, 0x00000000);
556 OUT_RING(ring
, 0x00000000);
557 OUT_RING(ring
, 0x00000000);
563 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_SRC_TL_X
, 4);
564 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_X_X(sx1
));
565 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_X_X(sx2
));
566 OUT_RING(ring
, A6XX_GRAS_2D_SRC_TL_Y_Y(sy1
));
567 OUT_RING(ring
, A6XX_GRAS_2D_SRC_BR_Y_Y(sy2
));
569 OUT_PKT4(ring
, REG_A6XX_GRAS_2D_DST_TL
, 2);
570 OUT_RING(ring
, A6XX_GRAS_2D_DST_TL_X(dx1
) | A6XX_GRAS_2D_DST_TL_Y(dy1
));
571 OUT_RING(ring
, A6XX_GRAS_2D_DST_BR_X(dx2
) | A6XX_GRAS_2D_DST_BR_Y(dy2
));
573 OUT_PKT7(ring
, CP_EVENT_WRITE
, 1);
574 OUT_RING(ring
, 0x3f);
577 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8C01
, 1);
580 if (dfmt
== RB6_R10G10B10A2_UNORM
)
581 sfmt
= RB6_R16G16B16A16_FLOAT
;
583 /* This register is probably badly named... it seems that it's
584 * controlling the internal/accumulator format or something like
585 * that. It's certainly not tied to only the src format.
587 OUT_PKT4(ring
, REG_A6XX_SP_2D_SRC_FORMAT
, 1);
588 OUT_RING(ring
, A6XX_SP_2D_SRC_FORMAT_COLOR_FORMAT(sfmt
) |
589 COND(util_format_is_pure_sint(info
->src
.format
),
590 A6XX_SP_2D_SRC_FORMAT_SINT
) |
591 COND(util_format_is_pure_uint(info
->src
.format
),
592 A6XX_SP_2D_SRC_FORMAT_UINT
) |
593 COND(util_format_is_snorm(info
->src
.format
),
594 A6XX_SP_2D_SRC_FORMAT_SINT
|
595 A6XX_SP_2D_SRC_FORMAT_NORM
) |
596 COND(util_format_is_unorm(info
->src
.format
),
597 // TODO sometimes blob uses UINT+NORM but dEQP seems unhappy about that
598 // A6XX_SP_2D_SRC_FORMAT_UINT |
599 A6XX_SP_2D_SRC_FORMAT_NORM
) |
600 COND(util_format_is_srgb(info
->dst
.format
), A6XX_SP_2D_SRC_FORMAT_SRGB
) |
601 A6XX_SP_2D_SRC_FORMAT_MASK(0xf));
603 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
604 OUT_RING(ring
, fd6_context(ctx
)->magic
.RB_UNKNOWN_8E04_blit
);
606 OUT_PKT7(ring
, CP_BLIT
, 1);
607 OUT_RING(ring
, CP_BLIT_0_OP(BLIT_OP_SCALE
));
611 OUT_PKT4(ring
, REG_A6XX_RB_UNKNOWN_8E04
, 1);
612 OUT_RING(ring
, 0); /* RB_UNKNOWN_8E04 */
617 fd6_clear_surface(struct fd_context
*ctx
,
618 struct fd_ringbuffer
*ring
, struct pipe_surface
*psurf
,
619 uint32_t width
, uint32_t height
, union pipe_color_union
*color
)
621 struct pipe_blit_info info
= {};
623 info
.dst
.resource
= psurf
->texture
;
624 info
.dst
.level
= psurf
->u
.tex
.level
;
627 info
.dst
.box
.z
= psurf
->u
.tex
.first_layer
;
628 info
.dst
.box
.width
= width
;
629 info
.dst
.box
.height
= height
;
630 info
.dst
.box
.depth
= psurf
->u
.tex
.last_layer
+ 1 - psurf
->u
.tex
.first_layer
;
631 info
.dst
.format
= psurf
->format
;
633 info
.mask
= util_format_get_mask(psurf
->format
);
634 info
.filter
= PIPE_TEX_FILTER_NEAREST
;
635 info
.scissor_enable
= 0;
637 emit_blit_or_clear_texture(ctx
, ring
, &info
, color
);
640 static bool handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
);
643 * Re-written z/s blits can still fail for various reasons (for example MSAA).
644 * But we want to do the fallback blit with the re-written pipe_blit_info,
645 * in particular as u_blitter cannot blit stencil. So handle the fallback
646 * ourself and never "fail".
649 do_rewritten_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
651 bool success
= handle_rgba_blit(ctx
, info
);
653 success
= fd_blitter_blit(ctx
, info
);
654 debug_assert(success
); /* fallback should never fail! */
659 * Handle depth/stencil blits either via u_blitter and/or re-writing the
660 * blit into an equivilant format that we can handle
663 handle_zs_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
665 struct pipe_blit_info blit
= *info
;
668 fprintf(stderr
, "---- handle_zs_blit: ");
669 util_dump_blit_info(stderr
, info
);
670 fprintf(stderr
, "\ndst resource: ");
671 util_dump_resource(stderr
, info
->dst
.resource
);
672 fprintf(stderr
, "\nsrc resource: ");
673 util_dump_resource(stderr
, info
->src
.resource
);
674 fprintf(stderr
, "\n");
677 switch (info
->dst
.format
) {
678 case PIPE_FORMAT_S8_UINT
:
679 debug_assert(info
->mask
== PIPE_MASK_S
);
680 blit
.mask
= PIPE_MASK_R
;
681 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
682 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
683 return do_rewritten_blit(ctx
, &blit
);
685 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
686 if (info
->mask
& PIPE_MASK_Z
) {
687 blit
.mask
= PIPE_MASK_R
;
688 blit
.src
.format
= PIPE_FORMAT_R32_FLOAT
;
689 blit
.dst
.format
= PIPE_FORMAT_R32_FLOAT
;
690 do_rewritten_blit(ctx
, &blit
);
693 if (info
->mask
& PIPE_MASK_S
) {
694 blit
.mask
= PIPE_MASK_R
;
695 blit
.src
.format
= PIPE_FORMAT_R8_UINT
;
696 blit
.dst
.format
= PIPE_FORMAT_R8_UINT
;
697 blit
.src
.resource
= &fd_resource(info
->src
.resource
)->stencil
->base
;
698 blit
.dst
.resource
= &fd_resource(info
->dst
.resource
)->stencil
->base
;
699 do_rewritten_blit(ctx
, &blit
);
704 case PIPE_FORMAT_Z16_UNORM
:
705 blit
.mask
= PIPE_MASK_R
;
706 blit
.src
.format
= PIPE_FORMAT_R16_UNORM
;
707 blit
.dst
.format
= PIPE_FORMAT_R16_UNORM
;
708 return do_rewritten_blit(ctx
, &blit
);
710 case PIPE_FORMAT_Z32_UNORM
:
711 case PIPE_FORMAT_Z32_FLOAT
:
712 debug_assert(info
->mask
== PIPE_MASK_Z
);
713 blit
.mask
= PIPE_MASK_R
;
714 blit
.src
.format
= PIPE_FORMAT_R32_UINT
;
715 blit
.dst
.format
= PIPE_FORMAT_R32_UINT
;
716 return do_rewritten_blit(ctx
, &blit
);
718 case PIPE_FORMAT_Z24X8_UNORM
:
719 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
721 if (info
->mask
& PIPE_MASK_Z
)
722 blit
.mask
|= PIPE_MASK_R
| PIPE_MASK_G
| PIPE_MASK_B
;
723 if (info
->mask
& PIPE_MASK_S
)
724 blit
.mask
|= PIPE_MASK_A
;
725 blit
.src
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
726 blit
.dst
.format
= PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8
;
727 return fd_blitter_blit(ctx
, &blit
);
735 handle_rgba_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
737 struct fd_batch
*batch
;
739 debug_assert(!(info
->mask
& PIPE_MASK_ZS
));
741 if (!can_do_blit(info
))
744 fd_fence_ref(&ctx
->last_fence
, NULL
);
746 batch
= fd_bc_alloc_batch(&ctx
->screen
->batch_cache
, ctx
, true);
748 fd6_emit_restore(batch
, batch
->draw
);
749 fd6_emit_lrz_flush(batch
->draw
);
751 mtx_lock(&ctx
->screen
->lock
);
753 fd_batch_resource_used(batch
, fd_resource(info
->src
.resource
), false);
754 fd_batch_resource_used(batch
, fd_resource(info
->dst
.resource
), true);
756 mtx_unlock(&ctx
->screen
->lock
);
760 if ((info
->src
.resource
->target
== PIPE_BUFFER
) &&
761 (info
->dst
.resource
->target
== PIPE_BUFFER
)) {
762 assert(fd_resource(info
->src
.resource
)->layout
.tile_mode
== TILE6_LINEAR
);
763 assert(fd_resource(info
->dst
.resource
)->layout
.tile_mode
== TILE6_LINEAR
);
764 emit_blit_buffer(ctx
, batch
->draw
, info
);
766 /* I don't *think* we need to handle blits between buffer <-> !buffer */
767 debug_assert(info
->src
.resource
->target
!= PIPE_BUFFER
);
768 debug_assert(info
->dst
.resource
->target
!= PIPE_BUFFER
);
769 emit_blit_or_clear_texture(ctx
, batch
->draw
, info
, NULL
);
772 fd6_event_write(batch
, batch
->draw
, 0x1d, true);
773 fd6_event_write(batch
, batch
->draw
, FACENESS_FLUSH
, true);
774 fd6_event_write(batch
, batch
->draw
, CACHE_FLUSH_TS
, true);
775 fd6_cache_inv(batch
, batch
->draw
);
777 fd_resource(info
->dst
.resource
)->valid
= true;
778 batch
->needs_flush
= true;
780 fd_batch_flush(batch
, false);
781 fd_batch_reference(&batch
, NULL
);
787 fd6_blit(struct fd_context
*ctx
, const struct pipe_blit_info
*info
)
789 if (info
->mask
& PIPE_MASK_ZS
)
790 return handle_zs_blit(ctx
, info
);
791 return handle_rgba_blit(ctx
, info
);
795 fd6_blitter_init(struct pipe_context
*pctx
)
797 if (fd_mesa_debug
& FD_DBG_NOBLIT
)
800 fd_context(pctx
)->blit
= fd6_blit
;
804 fd6_tile_mode(const struct pipe_resource
*tmpl
)
806 /* if the mipmap level 0 is still too small to be tiled, then don't
809 if (fd_resource_level_linear(tmpl
, 0))
812 /* basically just has to be a format we can blit, so uploads/downloads
813 * via linear staging buffer works:
815 if (ok_format(tmpl
->format
))