etnaviv: drop not used config_out function param
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_blt.c
1 /*
2 * Copyright (c) 2017 Etnaviv Project
3 * Copyright (C) 2017 Zodiac Inflight Innovations
4 *
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, sub license,
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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 NON-INFRINGEMENT. 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
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Wladimir J. van der Laan <laanwj@gmail.com>
26 */
27 #include "etnaviv_blt.h"
28
29 #include "etnaviv_emit.h"
30 #include "etnaviv_clear_blit.h"
31 #include "etnaviv_context.h"
32 #include "etnaviv_emit.h"
33 #include "etnaviv_format.h"
34 #include "etnaviv_resource.h"
35 #include "etnaviv_surface.h"
36 #include "etnaviv_translate.h"
37
38 #include "util/u_math.h"
39 #include "pipe/p_defines.h"
40 #include "pipe/p_state.h"
41 #include "util/u_blitter.h"
42 #include "util/u_inlines.h"
43 #include "util/u_memory.h"
44 #include "util/u_surface.h"
45
46 #include "hw/common_3d.xml.h"
47 #include "hw/state_blt.xml.h"
48 #include "hw/common.xml.h"
49
50 #include <assert.h>
51
52 static uint32_t
53 etna_compatible_blt_format(enum pipe_format fmt)
54 {
55 /* YUYV and UYVY are blocksize 4, but 2 bytes per pixel */
56 if (fmt == PIPE_FORMAT_YUYV || fmt == PIPE_FORMAT_UYVY)
57 return BLT_FORMAT_R8G8;
58
59 switch (util_format_get_blocksize(fmt)) {
60 case 1: return BLT_FORMAT_R8;
61 case 2: return BLT_FORMAT_R8G8;
62 case 4: return BLT_FORMAT_A8R8G8B8;
63 case 8: return BLT_FORMAT_A16R16G16B16;
64 default: return ETNA_NO_MATCH;
65 }
66 }
67
68 static inline uint32_t
69 blt_compute_stride_bits(const struct blt_imginfo *img)
70 {
71 return VIVS_BLT_DEST_STRIDE_TILING(img->tiling == ETNA_LAYOUT_LINEAR ? 0 : 3) | /* 1/3? */
72 VIVS_BLT_DEST_STRIDE_FORMAT(img->format) |
73 VIVS_BLT_DEST_STRIDE_STRIDE(img->stride);
74 }
75
76 static inline uint32_t
77 blt_compute_img_config_bits(const struct blt_imginfo *img, bool for_dest)
78 {
79 uint32_t tiling_bits = 0;
80 if (img->tiling == ETNA_LAYOUT_SUPER_TILED) {
81 tiling_bits |= for_dest ? BLT_IMAGE_CONFIG_TO_SUPER_TILED : BLT_IMAGE_CONFIG_FROM_SUPER_TILED;
82 }
83
84 return BLT_IMAGE_CONFIG_TS_MODE(img->ts_mode) |
85 COND(img->use_ts, BLT_IMAGE_CONFIG_TS) |
86 COND(img->use_ts && img->ts_compress_fmt >= 0, BLT_IMAGE_CONFIG_COMPRESSION) |
87 BLT_IMAGE_CONFIG_COMPRESSION_FORMAT(img->ts_compress_fmt) |
88 COND(for_dest, BLT_IMAGE_CONFIG_UNK22) |
89 BLT_IMAGE_CONFIG_SWIZ_R(0) | /* not used? */
90 BLT_IMAGE_CONFIG_SWIZ_G(1) |
91 BLT_IMAGE_CONFIG_SWIZ_B(2) |
92 BLT_IMAGE_CONFIG_SWIZ_A(3) |
93 tiling_bits;
94 }
95
96 static inline uint32_t
97 blt_compute_swizzle_bits(const struct blt_imginfo *img, bool for_dest)
98 {
99 uint32_t swiz = VIVS_BLT_SWIZZLE_SRC_R(img->swizzle[0]) |
100 VIVS_BLT_SWIZZLE_SRC_G(img->swizzle[1]) |
101 VIVS_BLT_SWIZZLE_SRC_B(img->swizzle[2]) |
102 VIVS_BLT_SWIZZLE_SRC_A(img->swizzle[3]);
103 return for_dest ? (swiz << 12) : swiz;
104 }
105
106 /* Clear (part of) an image */
107 static void
108 emit_blt_clearimage(struct etna_cmd_stream *stream, const struct blt_clear_op *op)
109 {
110 etna_cmd_stream_reserve(stream, 64*2); /* Make sure BLT op doesn't get broken up */
111
112 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000001);
113 assert(op->dest.bpp);
114 etna_set_state(stream, VIVS_BLT_CONFIG, VIVS_BLT_CONFIG_CLEAR_BPP(op->dest.bpp-1));
115 /* NB: blob sets format to 1 in dest/src config for clear, and the swizzle to RRRR.
116 * does this matter? It seems to just be ignored. But if we run into issues with BLT
117 * behaving stragely, it's something to look at.
118 */
119 etna_set_state(stream, VIVS_BLT_DEST_STRIDE, blt_compute_stride_bits(&op->dest));
120 etna_set_state(stream, VIVS_BLT_DEST_CONFIG, blt_compute_img_config_bits(&op->dest, true));
121 etna_set_state_reloc(stream, VIVS_BLT_DEST_ADDR, &op->dest.addr);
122 etna_set_state(stream, VIVS_BLT_SRC_STRIDE, blt_compute_stride_bits(&op->dest));
123 etna_set_state(stream, VIVS_BLT_SRC_CONFIG, blt_compute_img_config_bits(&op->dest, false));
124 etna_set_state_reloc(stream, VIVS_BLT_SRC_ADDR, &op->dest.addr);
125 etna_set_state(stream, VIVS_BLT_DEST_POS, VIVS_BLT_DEST_POS_X(op->rect_x) | VIVS_BLT_DEST_POS_Y(op->rect_y));
126 etna_set_state(stream, VIVS_BLT_IMAGE_SIZE, VIVS_BLT_IMAGE_SIZE_WIDTH(op->rect_w) | VIVS_BLT_IMAGE_SIZE_HEIGHT(op->rect_h));
127 etna_set_state(stream, VIVS_BLT_CLEAR_COLOR0, op->clear_value[0]);
128 etna_set_state(stream, VIVS_BLT_CLEAR_COLOR1, op->clear_value[1]);
129 etna_set_state(stream, VIVS_BLT_CLEAR_BITS0, op->clear_bits[0]);
130 etna_set_state(stream, VIVS_BLT_CLEAR_BITS1, op->clear_bits[1]);
131 if (op->dest.use_ts) {
132 etna_set_state_reloc(stream, VIVS_BLT_DEST_TS, &op->dest.ts_addr);
133 etna_set_state_reloc(stream, VIVS_BLT_SRC_TS, &op->dest.ts_addr);
134 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE0, op->dest.ts_clear_value[0]);
135 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE1, op->dest.ts_clear_value[1]);
136 etna_set_state(stream, VIVS_BLT_SRC_TS_CLEAR_VALUE0, op->dest.ts_clear_value[0]);
137 etna_set_state(stream, VIVS_BLT_SRC_TS_CLEAR_VALUE1, op->dest.ts_clear_value[1]);
138 }
139 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
140 etna_set_state(stream, VIVS_BLT_COMMAND, VIVS_BLT_COMMAND_COMMAND_CLEAR_IMAGE);
141 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
142 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000000);
143 }
144
145 /* Copy (a subset of) an image to another image. */
146 static void
147 emit_blt_copyimage(struct etna_cmd_stream *stream, const struct blt_imgcopy_op *op)
148 {
149 etna_cmd_stream_reserve(stream, 64*2); /* Never allow BLT sequences to be broken up */
150
151 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000001);
152 etna_set_state(stream, VIVS_BLT_CONFIG,
153 VIVS_BLT_CONFIG_SRC_ENDIAN(op->src.endian_mode) |
154 VIVS_BLT_CONFIG_DEST_ENDIAN(op->dest.endian_mode));
155 etna_set_state(stream, VIVS_BLT_SRC_STRIDE, blt_compute_stride_bits(&op->src));
156 etna_set_state(stream, VIVS_BLT_SRC_CONFIG, blt_compute_img_config_bits(&op->src, false));
157 etna_set_state(stream, VIVS_BLT_SWIZZLE,
158 blt_compute_swizzle_bits(&op->src, false) |
159 blt_compute_swizzle_bits(&op->dest, true));
160 etna_set_state(stream, VIVS_BLT_UNK140A0, 0x00040004);
161 etna_set_state(stream, VIVS_BLT_UNK1409C, 0x00400040);
162 if (op->src.use_ts) {
163 etna_set_state_reloc(stream, VIVS_BLT_SRC_TS, &op->src.ts_addr);
164 etna_set_state(stream, VIVS_BLT_SRC_TS_CLEAR_VALUE0, op->src.ts_clear_value[0]);
165 etna_set_state(stream, VIVS_BLT_SRC_TS_CLEAR_VALUE1, op->src.ts_clear_value[1]);
166 }
167 etna_set_state_reloc(stream, VIVS_BLT_SRC_ADDR, &op->src.addr);
168 etna_set_state(stream, VIVS_BLT_DEST_STRIDE, blt_compute_stride_bits(&op->dest));
169 etna_set_state(stream, VIVS_BLT_DEST_CONFIG,
170 blt_compute_img_config_bits(&op->dest, true) |
171 COND(op->flip_y, BLT_IMAGE_CONFIG_FLIP_Y));
172 assert(!op->dest.use_ts); /* Dest TS path doesn't work for copies? */
173 if (op->dest.use_ts) {
174 etna_set_state_reloc(stream, VIVS_BLT_DEST_TS, &op->dest.ts_addr);
175 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE0, op->dest.ts_clear_value[0]);
176 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE1, op->dest.ts_clear_value[1]);
177 }
178 etna_set_state_reloc(stream, VIVS_BLT_DEST_ADDR, &op->dest.addr);
179 etna_set_state(stream, VIVS_BLT_SRC_POS, VIVS_BLT_DEST_POS_X(op->src_x) | VIVS_BLT_DEST_POS_Y(op->src_y));
180 etna_set_state(stream, VIVS_BLT_DEST_POS, VIVS_BLT_DEST_POS_X(op->dest_x) | VIVS_BLT_DEST_POS_Y(op->dest_y));
181 etna_set_state(stream, VIVS_BLT_IMAGE_SIZE, VIVS_BLT_IMAGE_SIZE_WIDTH(op->rect_w) | VIVS_BLT_IMAGE_SIZE_HEIGHT(op->rect_h));
182 etna_set_state(stream, VIVS_BLT_UNK14058, 0xffffffff);
183 etna_set_state(stream, VIVS_BLT_UNK1405C, 0xffffffff);
184 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
185 etna_set_state(stream, VIVS_BLT_COMMAND, VIVS_BLT_COMMAND_COMMAND_COPY_IMAGE);
186 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
187 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000000);
188 }
189
190 /* Emit in-place resolve using BLT. */
191 static void
192 emit_blt_inplace(struct etna_cmd_stream *stream, const struct blt_inplace_op *op)
193 {
194 assert(op->bpp > 0 && util_is_power_of_two_nonzero(op->bpp));
195 etna_cmd_stream_reserve(stream, 64*2); /* Never allow BLT sequences to be broken up */
196 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000001);
197 etna_set_state(stream, VIVS_BLT_CONFIG,
198 VIVS_BLT_CONFIG_INPLACE_TS_MODE(op->ts_mode) |
199 VIVS_BLT_CONFIG_INPLACE_BOTH |
200 (util_logbase2(op->bpp) << VIVS_BLT_CONFIG_INPLACE_BPP__SHIFT));
201 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE0, op->ts_clear_value[0]);
202 etna_set_state(stream, VIVS_BLT_DEST_TS_CLEAR_VALUE1, op->ts_clear_value[1]);
203 etna_set_state_reloc(stream, VIVS_BLT_DEST_ADDR, &op->addr);
204 etna_set_state_reloc(stream, VIVS_BLT_DEST_TS, &op->ts_addr);
205 etna_set_state(stream, 0x14068, op->num_tiles);
206 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
207 etna_set_state(stream, VIVS_BLT_COMMAND, 0x00000004);
208 etna_set_state(stream, VIVS_BLT_SET_COMMAND, 0x00000003);
209 etna_set_state(stream, VIVS_BLT_ENABLE, 0x00000000);
210 }
211
212 static void
213 etna_blit_clear_color_blt(struct pipe_context *pctx, struct pipe_surface *dst,
214 const union pipe_color_union *color)
215 {
216 struct etna_context *ctx = etna_context(pctx);
217 struct etna_surface *surf = etna_surface(dst);
218 uint32_t new_clear_value = etna_clear_blit_pack_rgba(surf->base.format, color->f);
219
220 struct etna_resource *res = etna_resource(surf->base.texture);
221 struct blt_clear_op clr = {};
222 clr.dest.addr.bo = res->bo;
223 clr.dest.addr.offset = surf->surf.offset;
224 clr.dest.addr.flags = ETNA_RELOC_WRITE;
225 clr.dest.bpp = util_format_get_blocksize(surf->base.format);
226 clr.dest.stride = surf->surf.stride;
227 clr.dest.tiling = res->layout;
228
229 if (surf->surf.ts_size) {
230 clr.dest.use_ts = 1;
231 clr.dest.ts_addr.bo = res->ts_bo;
232 clr.dest.ts_addr.offset = 0;
233 clr.dest.ts_addr.flags = ETNA_RELOC_WRITE;
234 clr.dest.ts_clear_value[0] = new_clear_value;
235 clr.dest.ts_clear_value[1] = new_clear_value;
236 clr.dest.ts_mode = surf->level->ts_mode;
237 clr.dest.ts_compress_fmt = surf->level->ts_compress_fmt;
238 }
239
240 clr.clear_value[0] = new_clear_value;
241 clr.clear_value[1] = new_clear_value;
242 clr.clear_bits[0] = 0xffffffff; /* TODO: Might want to clear only specific channels? */
243 clr.clear_bits[1] = 0xffffffff;
244 clr.rect_x = 0; /* What about scissors? */
245 clr.rect_y = 0;
246 clr.rect_w = surf->surf.width;
247 clr.rect_h = surf->surf.height;
248
249 emit_blt_clearimage(ctx->stream, &clr);
250
251 /* This made the TS valid */
252 if (surf->surf.ts_size) {
253 ctx->framebuffer.TS_COLOR_CLEAR_VALUE = new_clear_value;
254 surf->level->ts_valid = true;
255 ctx->dirty |= ETNA_DIRTY_TS | ETNA_DIRTY_DERIVE_TS;
256 }
257
258 surf->level->clear_value = new_clear_value;
259 resource_written(ctx, surf->base.texture);
260 etna_resource(surf->base.texture)->seqno++;
261 }
262
263 static void
264 etna_blit_clear_zs_blt(struct pipe_context *pctx, struct pipe_surface *dst,
265 unsigned buffers, double depth, unsigned stencil)
266 {
267 struct etna_context *ctx = etna_context(pctx);
268 struct etna_surface *surf = etna_surface(dst);
269 uint32_t new_clear_value = translate_clear_depth_stencil(surf->base.format, depth, stencil);
270 uint32_t new_clear_bits = 0, clear_bits_depth, clear_bits_stencil;
271
272 /* Get the channels to clear */
273 switch (surf->base.format) {
274 case PIPE_FORMAT_Z16_UNORM:
275 case PIPE_FORMAT_X8Z24_UNORM:
276 clear_bits_depth = 0xffffffff;
277 clear_bits_stencil = 0x00000000;
278 break;
279 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
280 clear_bits_depth = 0xffffff00;
281 clear_bits_stencil = 0x000000ff;
282 break;
283 default:
284 clear_bits_depth = clear_bits_stencil = 0xffffffff;
285 break;
286 }
287
288 if (buffers & PIPE_CLEAR_DEPTH)
289 new_clear_bits |= clear_bits_depth;
290 if (buffers & PIPE_CLEAR_STENCIL)
291 new_clear_bits |= clear_bits_stencil;
292
293 /* TODO unduplicate this */
294 struct etna_resource *res = etna_resource(surf->base.texture);
295 struct blt_clear_op clr = {};
296 clr.dest.addr.bo = res->bo;
297 clr.dest.addr.offset = surf->surf.offset;
298 clr.dest.addr.flags = ETNA_RELOC_WRITE;
299 clr.dest.bpp = util_format_get_blocksize(surf->base.format);
300 clr.dest.stride = surf->surf.stride;
301 clr.dest.tiling = res->layout;
302
303 if (surf->surf.ts_size) {
304 clr.dest.use_ts = 1;
305 clr.dest.ts_addr.bo = res->ts_bo;
306 clr.dest.ts_addr.offset = 0;
307 clr.dest.ts_addr.flags = ETNA_RELOC_WRITE;
308 clr.dest.ts_clear_value[0] = new_clear_value;
309 clr.dest.ts_clear_value[1] = new_clear_value;
310 clr.dest.ts_mode = surf->level->ts_mode;
311 clr.dest.ts_compress_fmt = surf->level->ts_compress_fmt;
312 }
313
314 clr.clear_value[0] = new_clear_value;
315 clr.clear_value[1] = new_clear_value;
316 clr.clear_bits[0] = new_clear_bits;
317 clr.clear_bits[1] = new_clear_bits;
318 clr.rect_x = 0; /* What about scissors? */
319 clr.rect_y = 0;
320 clr.rect_w = surf->surf.width;
321 clr.rect_h = surf->surf.height;
322
323 emit_blt_clearimage(ctx->stream, &clr);
324
325 /* This made the TS valid */
326 if (surf->surf.ts_size) {
327 ctx->framebuffer.TS_DEPTH_CLEAR_VALUE = new_clear_value;
328 surf->level->ts_valid = true;
329 ctx->dirty |= ETNA_DIRTY_TS | ETNA_DIRTY_DERIVE_TS;
330 }
331
332 surf->level->clear_value = new_clear_value;
333 resource_written(ctx, surf->base.texture);
334 etna_resource(surf->base.texture)->seqno++;
335 }
336
337 static void
338 etna_clear_blt(struct pipe_context *pctx, unsigned buffers,
339 const union pipe_color_union *color, double depth, unsigned stencil)
340 {
341 struct etna_context *ctx = etna_context(pctx);
342 mtx_lock(&ctx->lock);
343
344 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000c23);
345 etna_set_state(ctx->stream, VIVS_TS_FLUSH_CACHE, VIVS_TS_FLUSH_CACHE_FLUSH);
346
347 if (buffers & PIPE_CLEAR_COLOR) {
348 for (int idx = 0; idx < ctx->framebuffer_s.nr_cbufs; ++idx) {
349 etna_blit_clear_color_blt(pctx, ctx->framebuffer_s.cbufs[idx],
350 &color[idx]);
351 }
352 }
353
354 if ((buffers & PIPE_CLEAR_DEPTHSTENCIL) && ctx->framebuffer_s.zsbuf != NULL)
355 etna_blit_clear_zs_blt(pctx, ctx->framebuffer_s.zsbuf, buffers, depth, stencil);
356
357 etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_BLT);
358
359 if ((buffers & PIPE_CLEAR_COLOR) && (buffers & PIPE_CLEAR_DEPTH))
360 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000c23);
361 else
362 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000002);
363 mtx_unlock(&ctx->lock);
364 }
365
366 static bool
367 etna_try_blt_blit(struct pipe_context *pctx,
368 const struct pipe_blit_info *blit_info)
369 {
370 struct etna_context *ctx = etna_context(pctx);
371 struct etna_resource *src = etna_resource(blit_info->src.resource);
372 struct etna_resource *dst = etna_resource(blit_info->dst.resource);
373 int msaa_xscale = 1, msaa_yscale = 1;
374
375 /* Ensure that the level is valid */
376 assert(blit_info->src.level <= src->base.last_level);
377 assert(blit_info->dst.level <= dst->base.last_level);
378
379 if (!translate_samples_to_xyscale(src->base.nr_samples, &msaa_xscale, &msaa_yscale))
380 return false;
381
382 /* The width/height are in pixels; they do not change as a result of
383 * multi-sampling. So, when blitting from a 4x multisampled surface
384 * to a non-multisampled surface, the width and height will be
385 * identical. As we do not support scaling, reject different sizes.
386 * TODO: could handle 2x downsample here with emit_blt_genmipmaps */
387 if (blit_info->dst.box.width != blit_info->src.box.width ||
388 blit_info->dst.box.height != abs(blit_info->src.box.height)) { /* allow y flip for glTexImage2D */
389 DBG("scaling requested: source %dx%d destination %dx%d",
390 blit_info->src.box.width, blit_info->src.box.height,
391 blit_info->dst.box.width, blit_info->dst.box.height);
392 return false;
393 }
394
395 /* No masks - not sure if BLT can copy individual channels */
396 unsigned mask = util_format_get_mask(blit_info->dst.format);
397 if ((blit_info->mask & mask) != mask) {
398 DBG("sub-mask requested: 0x%02x vs format mask 0x%02x", blit_info->mask, mask);
399 return false;
400 }
401
402 /* Only support same format (used tiling/detiling) blits for now.
403 * TODO: figure out which different-format blits are possible and test them
404 * - need to use correct swizzle
405 * - set sRGB bits correctly
406 * - avoid trying to convert between float/int formats?
407 */
408 if (blit_info->src.format != blit_info->dst.format)
409 return false;
410
411 uint32_t format = etna_compatible_blt_format(blit_info->dst.format);
412 if (format == ETNA_NO_MATCH)
413 return false;
414
415 if (blit_info->scissor_enable ||
416 blit_info->dst.box.depth != blit_info->src.box.depth ||
417 blit_info->dst.box.depth != 1) {
418 return false;
419 }
420
421 struct etna_resource_level *src_lev = &src->levels[blit_info->src.level];
422 struct etna_resource_level *dst_lev = &dst->levels[blit_info->dst.level];
423
424 /* if we asked for in-place resolve, return immediately if ts isn't valid
425 * do this check separately because it applies when compression is used, but
426 * we can't use inplace resolve path with compression
427 */
428 if (src == dst) {
429 assert(!memcmp(&blit_info->src, &blit_info->dst, sizeof(blit_info->src)));
430 if (!src_lev->ts_size || !src_lev->ts_valid) /* No TS, no worries */
431 return true;
432 }
433
434 mtx_lock(&ctx->lock);
435 /* Kick off BLT here */
436 if (src == dst && src_lev->ts_compress_fmt < 0) {
437 /* Resolve-in-place */
438 struct blt_inplace_op op = {};
439
440 op.addr.bo = src->bo;
441 op.addr.offset = src_lev->offset + blit_info->src.box.z * src_lev->layer_stride;
442 op.addr.flags = ETNA_RELOC_READ | ETNA_RELOC_WRITE;
443 op.ts_addr.bo = src->ts_bo;
444 op.ts_addr.offset = src_lev->ts_offset + blit_info->src.box.z * src_lev->ts_layer_stride;
445 op.ts_addr.flags = ETNA_RELOC_READ;
446 op.ts_clear_value[0] = src_lev->clear_value;
447 op.ts_clear_value[1] = src_lev->clear_value;
448 op.ts_mode = src_lev->ts_mode;
449 op.num_tiles = DIV_ROUND_UP(src_lev->size, src_lev->ts_mode ? 256 : 128);
450 op.bpp = util_format_get_blocksize(src->base.format);
451
452 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000c23);
453 etna_set_state(ctx->stream, VIVS_TS_FLUSH_CACHE, 0x00000001);
454 emit_blt_inplace(ctx->stream, &op);
455 } else {
456 /* Copy op */
457 struct blt_imgcopy_op op = {};
458
459 op.src.addr.bo = src->bo;
460 op.src.addr.offset = src_lev->offset + blit_info->src.box.z * src_lev->layer_stride;
461 op.src.addr.flags = ETNA_RELOC_READ;
462 op.src.format = format;
463 op.src.stride = src_lev->stride;
464 op.src.tiling = src->layout;
465 for (unsigned x=0; x<4; ++x)
466 op.src.swizzle[x] = x;
467
468 if (src_lev->ts_size && src_lev->ts_valid) {
469 op.src.use_ts = 1;
470 op.src.ts_addr.bo = src->ts_bo;
471 op.src.ts_addr.offset = src_lev->ts_offset + blit_info->src.box.z * src_lev->ts_layer_stride;
472 op.src.ts_addr.flags = ETNA_RELOC_READ;
473 op.src.ts_clear_value[0] = src_lev->clear_value;
474 op.src.ts_clear_value[1] = src_lev->clear_value;
475 op.src.ts_mode = src_lev->ts_mode;
476 op.src.ts_compress_fmt = src_lev->ts_compress_fmt;
477 }
478
479 op.dest.addr.bo = dst->bo;
480 op.dest.addr.offset = dst_lev->offset + blit_info->dst.box.z * dst_lev->layer_stride;
481 op.dest.addr.flags = ETNA_RELOC_WRITE;
482 op.dest.format = format;
483 op.dest.stride = dst_lev->stride;
484 op.dest.tiling = dst->layout;
485 for (unsigned x=0; x<4; ++x)
486 op.dest.swizzle[x] = x;
487
488 op.dest_x = blit_info->dst.box.x;
489 op.dest_y = blit_info->dst.box.y;
490 op.src_x = blit_info->src.box.x;
491 op.src_y = blit_info->src.box.y;
492 op.rect_w = blit_info->dst.box.width;
493 op.rect_h = blit_info->dst.box.height;
494
495 if (blit_info->src.box.height < 0) { /* flipped? fix up base y */
496 op.flip_y = 1;
497 op.src_y += blit_info->src.box.height;
498 }
499
500 assert(op.src_x < src_lev->padded_width);
501 assert(op.src_y < src_lev->padded_height);
502 assert((op.src_x + op.rect_w) <= src_lev->padded_width);
503 assert((op.src_y + op.rect_h) <= src_lev->padded_height);
504 assert(op.dest_x < dst_lev->padded_width);
505 assert(op.dest_y < dst_lev->padded_height);
506 assert((op.dest_x + op.rect_w) <= dst_lev->padded_width);
507 assert((op.dest_y + op.rect_h) <= dst_lev->padded_height);
508
509 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000c23);
510 etna_set_state(ctx->stream, VIVS_TS_FLUSH_CACHE, 0x00000001);
511 emit_blt_copyimage(ctx->stream, &op);
512 }
513
514 /* Make FE wait for BLT, in case we want to do something with the image next.
515 * This probably shouldn't be here, and depend on what is done with the resource.
516 */
517 etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_BLT);
518 etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, 0x00000c23);
519
520 resource_read(ctx, &src->base);
521 resource_written(ctx, &dst->base);
522
523 dst->seqno++;
524 dst_lev->ts_valid = false;
525 mtx_unlock(&ctx->lock);
526
527 return true;
528 }
529
530 static void
531 etna_blit_blt(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
532 {
533 struct etna_context *ctx = etna_context(pctx);
534 struct pipe_blit_info info = *blit_info;
535
536 if (info.src.resource->nr_samples > 1 &&
537 info.dst.resource->nr_samples <= 1 &&
538 !util_format_is_depth_or_stencil(info.src.resource->format) &&
539 !util_format_is_pure_integer(info.src.resource->format)) {
540 DBG("color resolve unimplemented");
541 return;
542 }
543
544 if (etna_try_blt_blit(pctx, blit_info))
545 return;
546
547 if (util_try_blit_via_copy_region(pctx, blit_info))
548 return;
549
550 if (info.mask & PIPE_MASK_S) {
551 DBG("cannot blit stencil, skipping");
552 info.mask &= ~PIPE_MASK_S;
553 }
554
555 if (!util_blitter_is_blit_supported(ctx->blitter, &info)) {
556 DBG("blit unsupported %s -> %s",
557 util_format_short_name(info.src.resource->format),
558 util_format_short_name(info.dst.resource->format));
559 return;
560 }
561
562 etna_blit_save_state(ctx);
563 util_blitter_blit(ctx->blitter, &info);
564 }
565
566 void
567 etna_clear_blit_blt_init(struct pipe_context *pctx)
568 {
569 DBG("etnaviv: Using BLT blit engine");
570 pctx->clear = etna_clear_blt;
571 pctx->blit = etna_blit_blt;
572 }