Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
4574 views
1
/*
2
* Copyright (C) 2017 Rob Clark <[email protected]>
3
* Copyright © 2018 Google, Inc.
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, 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:
11
*
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
14
* 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 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
22
* SOFTWARE.
23
*
24
* Authors:
25
* Rob Clark <[email protected]>
26
*/
27
28
#include "util/format_srgb.h"
29
#include "util/half_float.h"
30
#include "util/u_dump.h"
31
32
#include "freedreno_blitter.h"
33
#include "freedreno_fence.h"
34
#include "freedreno_resource.h"
35
#include "freedreno_tracepoints.h"
36
37
#include "fd6_blitter.h"
38
#include "fd6_emit.h"
39
#include "fd6_format.h"
40
#include "fd6_resource.h"
41
42
static inline enum a6xx_2d_ifmt
43
fd6_ifmt(enum a6xx_format fmt)
44
{
45
switch (fmt) {
46
case FMT6_A8_UNORM:
47
case FMT6_8_UNORM:
48
case FMT6_8_SNORM:
49
case FMT6_8_8_UNORM:
50
case FMT6_8_8_SNORM:
51
case FMT6_8_8_8_8_UNORM:
52
case FMT6_8_8_8_X8_UNORM:
53
case FMT6_8_8_8_8_SNORM:
54
case FMT6_4_4_4_4_UNORM:
55
case FMT6_5_5_5_1_UNORM:
56
case FMT6_5_6_5_UNORM:
57
return R2D_UNORM8;
58
59
case FMT6_32_UINT:
60
case FMT6_32_SINT:
61
case FMT6_32_32_UINT:
62
case FMT6_32_32_SINT:
63
case FMT6_32_32_32_32_UINT:
64
case FMT6_32_32_32_32_SINT:
65
return R2D_INT32;
66
67
case FMT6_16_UINT:
68
case FMT6_16_SINT:
69
case FMT6_16_16_UINT:
70
case FMT6_16_16_SINT:
71
case FMT6_16_16_16_16_UINT:
72
case FMT6_16_16_16_16_SINT:
73
case FMT6_10_10_10_2_UINT:
74
return R2D_INT16;
75
76
case FMT6_8_UINT:
77
case FMT6_8_SINT:
78
case FMT6_8_8_UINT:
79
case FMT6_8_8_SINT:
80
case FMT6_8_8_8_8_UINT:
81
case FMT6_8_8_8_8_SINT:
82
case FMT6_Z24_UNORM_S8_UINT:
83
case FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8:
84
return R2D_INT8;
85
86
case FMT6_16_UNORM:
87
case FMT6_16_SNORM:
88
case FMT6_16_16_UNORM:
89
case FMT6_16_16_SNORM:
90
case FMT6_16_16_16_16_UNORM:
91
case FMT6_16_16_16_16_SNORM:
92
case FMT6_32_FLOAT:
93
case FMT6_32_32_FLOAT:
94
case FMT6_32_32_32_32_FLOAT:
95
return R2D_FLOAT32;
96
97
case FMT6_16_FLOAT:
98
case FMT6_16_16_FLOAT:
99
case FMT6_16_16_16_16_FLOAT:
100
case FMT6_11_11_10_FLOAT:
101
case FMT6_10_10_10_2_UNORM_DEST:
102
return R2D_FLOAT16;
103
104
default:
105
unreachable("bad format");
106
return 0;
107
}
108
}
109
110
/* Make sure none of the requested dimensions extend beyond the size of the
111
* resource. Not entirely sure why this happens, but sometimes it does, and
112
* w/ 2d blt doesn't have wrap modes like a sampler, so force those cases
113
* back to u_blitter
114
*/
115
static bool
116
ok_dims(const struct pipe_resource *r, const struct pipe_box *b, int lvl)
117
{
118
int last_layer =
119
r->target == PIPE_TEXTURE_3D ? u_minify(r->depth0, lvl) : r->array_size;
120
121
return (b->x >= 0) && (b->x + b->width <= u_minify(r->width0, lvl)) &&
122
(b->y >= 0) && (b->y + b->height <= u_minify(r->height0, lvl)) &&
123
(b->z >= 0) && (b->z + b->depth <= last_layer);
124
}
125
126
static bool
127
ok_format(enum pipe_format pfmt)
128
{
129
enum a6xx_format fmt = fd6_pipe2color(pfmt);
130
131
if (util_format_is_compressed(pfmt))
132
return true;
133
134
switch (pfmt) {
135
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
136
case PIPE_FORMAT_Z24X8_UNORM:
137
case PIPE_FORMAT_Z16_UNORM:
138
case PIPE_FORMAT_Z32_UNORM:
139
case PIPE_FORMAT_Z32_FLOAT:
140
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
141
case PIPE_FORMAT_S8_UINT:
142
return true;
143
default:
144
break;
145
}
146
147
if (fmt == FMT6_NONE)
148
return false;
149
150
return true;
151
}
152
153
#define DEBUG_BLIT 0
154
#define DEBUG_BLIT_FALLBACK 0
155
156
#define fail_if(cond) \
157
do { \
158
if (cond) { \
159
if (DEBUG_BLIT_FALLBACK) { \
160
fprintf(stderr, "falling back: %s for blit:\n", #cond); \
161
dump_blit_info(info); \
162
} \
163
return false; \
164
} \
165
} while (0)
166
167
static bool
168
is_ubwc(struct pipe_resource *prsc, unsigned level)
169
{
170
return fd_resource_ubwc_enabled(fd_resource(prsc), level);
171
}
172
173
static void
174
dump_blit_info(const struct pipe_blit_info *info)
175
{
176
util_dump_blit_info(stderr, info);
177
fprintf(stderr, "\ndst resource: ");
178
util_dump_resource(stderr, info->dst.resource);
179
if (is_ubwc(info->dst.resource, info->dst.level))
180
fprintf(stderr, " (ubwc)");
181
fprintf(stderr, "\nsrc resource: ");
182
util_dump_resource(stderr, info->src.resource);
183
if (is_ubwc(info->src.resource, info->src.level))
184
fprintf(stderr, " (ubwc)");
185
fprintf(stderr, "\n");
186
}
187
188
static bool
189
can_do_blit(const struct pipe_blit_info *info)
190
{
191
/* I think we can do scaling, but not in z dimension since that would
192
* require blending..
193
*/
194
fail_if(info->dst.box.depth != info->src.box.depth);
195
196
/* Fail if unsupported format: */
197
fail_if(!ok_format(info->src.format));
198
fail_if(!ok_format(info->dst.format));
199
200
debug_assert(!util_format_is_compressed(info->src.format));
201
debug_assert(!util_format_is_compressed(info->dst.format));
202
203
fail_if(!ok_dims(info->src.resource, &info->src.box, info->src.level));
204
205
fail_if(!ok_dims(info->dst.resource, &info->dst.box, info->dst.level));
206
207
debug_assert(info->dst.box.width >= 0);
208
debug_assert(info->dst.box.height >= 0);
209
debug_assert(info->dst.box.depth >= 0);
210
211
fail_if(info->dst.resource->nr_samples > 1);
212
213
fail_if(info->window_rectangle_include);
214
215
const struct util_format_description *src_desc =
216
util_format_description(info->src.format);
217
const struct util_format_description *dst_desc =
218
util_format_description(info->dst.format);
219
const int common_channels =
220
MIN2(src_desc->nr_channels, dst_desc->nr_channels);
221
222
if (info->mask & PIPE_MASK_RGBA) {
223
for (int i = 0; i < common_channels; i++) {
224
fail_if(memcmp(&src_desc->channel[i], &dst_desc->channel[i],
225
sizeof(src_desc->channel[0])));
226
}
227
}
228
229
fail_if(info->alpha_blend);
230
231
return true;
232
}
233
234
static void
235
emit_setup(struct fd_batch *batch)
236
{
237
struct fd_ringbuffer *ring = batch->draw;
238
struct fd_screen *screen = batch->ctx->screen;
239
240
fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
241
fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);
242
fd6_event_write(batch, ring, PC_CCU_INVALIDATE_COLOR, false);
243
fd6_event_write(batch, ring, PC_CCU_INVALIDATE_DEPTH, false);
244
245
/* normal BLIT_OP_SCALE operation needs bypass RB_CCU_CNTL */
246
OUT_WFI5(ring);
247
OUT_PKT4(ring, REG_A6XX_RB_CCU_CNTL, 1);
248
OUT_RING(ring, A6XX_RB_CCU_CNTL_COLOR_OFFSET(screen->ccu_offset_bypass));
249
}
250
251
static void
252
emit_blit_setup(struct fd_ringbuffer *ring, enum pipe_format pfmt,
253
bool scissor_enable, union pipe_color_union *color)
254
{
255
enum a6xx_format fmt = fd6_pipe2color(pfmt);
256
bool is_srgb = util_format_is_srgb(pfmt);
257
enum a6xx_2d_ifmt ifmt = fd6_ifmt(fmt);
258
259
if (is_srgb) {
260
assert(ifmt == R2D_UNORM8);
261
ifmt = R2D_UNORM8_SRGB;
262
}
263
264
uint32_t blit_cntl = A6XX_RB_2D_BLIT_CNTL_MASK(0xf) |
265
A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt) |
266
A6XX_RB_2D_BLIT_CNTL_IFMT(ifmt) |
267
COND(color, A6XX_RB_2D_BLIT_CNTL_SOLID_COLOR) |
268
COND(scissor_enable, A6XX_RB_2D_BLIT_CNTL_SCISSOR);
269
270
OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);
271
OUT_RING(ring, blit_cntl);
272
273
OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);
274
OUT_RING(ring, blit_cntl);
275
276
if (fmt == FMT6_10_10_10_2_UNORM_DEST)
277
fmt = FMT6_16_16_16_16_FLOAT;
278
279
/* This register is probably badly named... it seems that it's
280
* controlling the internal/accumulator format or something like
281
* that. It's certainly not tied to only the src format.
282
*/
283
OUT_PKT4(ring, REG_A6XX_SP_2D_DST_FORMAT, 1);
284
OUT_RING(
285
ring,
286
A6XX_SP_2D_DST_FORMAT_COLOR_FORMAT(fmt) |
287
COND(util_format_is_pure_sint(pfmt), A6XX_SP_2D_DST_FORMAT_SINT) |
288
COND(util_format_is_pure_uint(pfmt), A6XX_SP_2D_DST_FORMAT_UINT) |
289
COND(is_srgb, A6XX_SP_2D_DST_FORMAT_SRGB) |
290
A6XX_SP_2D_DST_FORMAT_MASK(0xf));
291
292
OUT_PKT4(ring, REG_A6XX_RB_2D_UNKNOWN_8C01, 1);
293
OUT_RING(ring, 0);
294
}
295
296
/* buffers need to be handled specially since x/width can exceed the bounds
297
* supported by hw.. if necessary decompose into (potentially) two 2D blits
298
*/
299
static void
300
emit_blit_buffer(struct fd_context *ctx, struct fd_ringbuffer *ring,
301
const struct pipe_blit_info *info)
302
{
303
const struct pipe_box *sbox = &info->src.box;
304
const struct pipe_box *dbox = &info->dst.box;
305
struct fd_resource *src, *dst;
306
unsigned sshift, dshift;
307
308
if (DEBUG_BLIT) {
309
fprintf(stderr, "buffer blit: ");
310
dump_blit_info(info);
311
}
312
313
src = fd_resource(info->src.resource);
314
dst = fd_resource(info->dst.resource);
315
316
debug_assert(src->layout.cpp == 1);
317
debug_assert(dst->layout.cpp == 1);
318
debug_assert(info->src.resource->format == info->dst.resource->format);
319
debug_assert((sbox->y == 0) && (sbox->height == 1));
320
debug_assert((dbox->y == 0) && (dbox->height == 1));
321
debug_assert((sbox->z == 0) && (sbox->depth == 1));
322
debug_assert((dbox->z == 0) && (dbox->depth == 1));
323
debug_assert(sbox->width == dbox->width);
324
debug_assert(info->src.level == 0);
325
debug_assert(info->dst.level == 0);
326
327
/*
328
* Buffers can have dimensions bigger than max width, remap into
329
* multiple 1d blits to fit within max dimension
330
*
331
* Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which
332
* seems to prevent overfetch related faults. Not quite sure what
333
* the deal is there.
334
*
335
* Low 6 bits of SRC/DST addresses need to be zero (ie. address
336
* aligned to 64) so we need to shift src/dst x1/x2 to make up the
337
* difference. On top of already splitting up the blit so width
338
* isn't > 16k.
339
*
340
* We perhaps could do a bit better, if src and dst are aligned but
341
* in the worst case this means we have to split the copy up into
342
* 16k (0x4000) minus 64 (0x40).
343
*/
344
345
sshift = sbox->x & 0x3f;
346
dshift = dbox->x & 0x3f;
347
348
emit_blit_setup(ring, PIPE_FORMAT_R8_UNORM, false, NULL);
349
350
for (unsigned off = 0; off < sbox->width; off += (0x4000 - 0x40)) {
351
unsigned soff, doff, w, p;
352
353
soff = (sbox->x + off) & ~0x3f;
354
doff = (dbox->x + off) & ~0x3f;
355
356
w = MIN2(sbox->width - off, (0x4000 - 0x40));
357
p = align(w, 64);
358
359
debug_assert((soff + w) <= fd_bo_size(src->bo));
360
debug_assert((doff + w) <= fd_bo_size(dst->bo));
361
362
/*
363
* Emit source:
364
*/
365
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);
366
OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(FMT6_8_UNORM) |
367
A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR) |
368
A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX) | 0x500000);
369
OUT_RING(ring,
370
A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift + w) |
371
A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */
372
OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */
373
OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p));
374
375
OUT_RING(ring, 0x00000000);
376
OUT_RING(ring, 0x00000000);
377
OUT_RING(ring, 0x00000000);
378
OUT_RING(ring, 0x00000000);
379
OUT_RING(ring, 0x00000000);
380
381
/*
382
* Emit destination:
383
*/
384
OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
385
OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_8_UNORM) |
386
A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |
387
A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));
388
OUT_RELOC(ring, dst->bo, doff, 0, 0); /* RB_2D_DST_LO/HI */
389
OUT_RING(ring, A6XX_RB_2D_DST_PITCH(p));
390
OUT_RING(ring, 0x00000000);
391
OUT_RING(ring, 0x00000000);
392
OUT_RING(ring, 0x00000000);
393
OUT_RING(ring, 0x00000000);
394
OUT_RING(ring, 0x00000000);
395
396
/*
397
* Blit command:
398
*/
399
OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
400
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(sshift));
401
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(sshift + w - 1));
402
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));
403
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(0));
404
405
OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
406
OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dshift) | A6XX_GRAS_2D_DST_TL_Y(0));
407
OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dshift + w - 1) |
408
A6XX_GRAS_2D_DST_BR_Y(0));
409
410
OUT_PKT7(ring, CP_EVENT_WRITE, 1);
411
OUT_RING(ring, 0x3f);
412
OUT_WFI5(ring);
413
414
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
415
OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);
416
417
OUT_PKT7(ring, CP_BLIT, 1);
418
OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
419
420
OUT_WFI5(ring);
421
422
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
423
OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */
424
}
425
}
426
427
static void
428
fd6_clear_ubwc(struct fd_batch *batch, struct fd_resource *rsc) assert_dt
429
{
430
struct fd_ringbuffer *ring = fd_batch_get_prologue(batch);
431
union pipe_color_union color = {};
432
433
emit_blit_setup(ring, PIPE_FORMAT_R8_UNORM, false, &color);
434
435
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);
436
OUT_RING(ring, 0x00000000);
437
OUT_RING(ring, 0x00000000);
438
OUT_RING(ring, 0x00000000);
439
OUT_RING(ring, 0x00000000);
440
OUT_RING(ring, 0x00000000);
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);
446
OUT_RING(ring, 0x00000000);
447
OUT_RING(ring, 0x00000000);
448
OUT_RING(ring, 0x00000000);
449
450
OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);
451
OUT_RING(ring, 0x00000000);
452
OUT_RING(ring, 0x00000000);
453
OUT_RING(ring, 0x00000000);
454
OUT_RING(ring, 0x00000000);
455
456
OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
457
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(0));
458
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(0));
459
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));
460
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(0));
461
462
unsigned size = rsc->layout.slices[0].offset;
463
unsigned offset = 0;
464
465
/* We could be more clever here and realize that we could use a
466
* larger width if the size is aligned to something more than a
467
* single page.. or even use a format larger than r8 in those
468
* cases. But for normal sized textures and even up to 16k x 16k
469
* at <= 4byte/pixel, we'll only go thru the loop once
470
*/
471
const unsigned w = 0x1000;
472
473
/* ubwc size should always be page aligned: */
474
assert((size % w) == 0);
475
476
while (size > 0) {
477
const unsigned h = MIN2(0x4000, size / w);
478
/* width is already aligned to a suitable pitch: */
479
const unsigned p = w;
480
481
/*
482
* Emit destination:
483
*/
484
OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
485
OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_8_UNORM) |
486
A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |
487
A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));
488
OUT_RELOC(ring, rsc->bo, offset, 0, 0); /* RB_2D_DST_LO/HI */
489
OUT_RING(ring, A6XX_RB_2D_DST_PITCH(p));
490
OUT_RING(ring, 0x00000000);
491
OUT_RING(ring, 0x00000000);
492
OUT_RING(ring, 0x00000000);
493
OUT_RING(ring, 0x00000000);
494
OUT_RING(ring, 0x00000000);
495
496
/*
497
* Blit command:
498
*/
499
500
OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
501
OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));
502
OUT_RING(ring,
503
A6XX_GRAS_2D_DST_BR_X(w - 1) | A6XX_GRAS_2D_DST_BR_Y(h - 1));
504
505
OUT_PKT7(ring, CP_EVENT_WRITE, 1);
506
OUT_RING(ring, 0x3f);
507
OUT_WFI5(ring);
508
509
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
510
OUT_RING(ring, batch->ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);
511
512
OUT_PKT7(ring, CP_BLIT, 1);
513
OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
514
515
OUT_WFI5(ring);
516
517
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
518
OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */
519
520
offset += w * h;
521
size -= w * h;
522
}
523
524
fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
525
fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);
526
fd6_event_write(batch, ring, CACHE_FLUSH_TS, true);
527
fd6_cache_inv(batch, ring);
528
}
529
530
static void
531
emit_blit_dst(struct fd_ringbuffer *ring, struct pipe_resource *prsc,
532
enum pipe_format pfmt, unsigned level, unsigned layer)
533
{
534
struct fd_resource *dst = fd_resource(prsc);
535
enum a6xx_format fmt = fd6_pipe2color(pfmt);
536
enum a6xx_tile_mode tile = fd_resource_tile_mode(prsc, level);
537
enum a3xx_color_swap swap = fd6_resource_swap(dst, pfmt);
538
uint32_t pitch = fd_resource_pitch(dst, level);
539
bool ubwc_enabled = fd_resource_ubwc_enabled(dst, level);
540
unsigned off = fd_resource_offset(dst, level, layer);
541
542
if (fmt == FMT6_Z24_UNORM_S8_UINT)
543
fmt = FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8;
544
545
OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
546
OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(fmt) |
547
A6XX_RB_2D_DST_INFO_TILE_MODE(tile) |
548
A6XX_RB_2D_DST_INFO_COLOR_SWAP(swap) |
549
COND(util_format_is_srgb(pfmt), A6XX_RB_2D_DST_INFO_SRGB) |
550
COND(ubwc_enabled, A6XX_RB_2D_DST_INFO_FLAGS));
551
OUT_RELOC(ring, dst->bo, off, 0, 0); /* RB_2D_DST_LO/HI */
552
OUT_RING(ring, A6XX_RB_2D_DST_PITCH(pitch));
553
OUT_RING(ring, 0x00000000);
554
OUT_RING(ring, 0x00000000);
555
OUT_RING(ring, 0x00000000);
556
OUT_RING(ring, 0x00000000);
557
OUT_RING(ring, 0x00000000);
558
559
if (ubwc_enabled) {
560
OUT_PKT4(ring, REG_A6XX_RB_2D_DST_FLAGS, 6);
561
fd6_emit_flag_reference(ring, dst, level, layer);
562
OUT_RING(ring, 0x00000000);
563
OUT_RING(ring, 0x00000000);
564
OUT_RING(ring, 0x00000000);
565
}
566
}
567
568
static void
569
emit_blit_src(struct fd_ringbuffer *ring, const struct pipe_blit_info *info,
570
unsigned layer, unsigned nr_samples)
571
{
572
struct fd_resource *src = fd_resource(info->src.resource);
573
enum a6xx_format sfmt = fd6_pipe2color(info->src.format);
574
enum a6xx_tile_mode stile =
575
fd_resource_tile_mode(info->src.resource, info->src.level);
576
enum a3xx_color_swap sswap = fd6_resource_swap(src, info->src.format);
577
uint32_t pitch = fd_resource_pitch(src, info->src.level);
578
bool subwc_enabled = fd_resource_ubwc_enabled(src, info->src.level);
579
unsigned soff = fd_resource_offset(src, info->src.level, layer);
580
uint32_t width = u_minify(src->b.b.width0, info->src.level) * nr_samples;
581
uint32_t height = u_minify(src->b.b.height0, info->src.level);
582
uint32_t filter = 0;
583
584
if (info->filter == PIPE_TEX_FILTER_LINEAR)
585
filter = A6XX_SP_PS_2D_SRC_INFO_FILTER;
586
587
enum a3xx_msaa_samples samples = fd_msaa_samples(src->b.b.nr_samples);
588
589
if (sfmt == FMT6_10_10_10_2_UNORM_DEST)
590
sfmt = FMT6_10_10_10_2_UNORM;
591
592
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);
593
OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt) |
594
A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile) |
595
A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap) |
596
A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples) |
597
COND(samples > MSAA_ONE && (info->mask & PIPE_MASK_RGBA),
598
A6XX_SP_PS_2D_SRC_INFO_SAMPLES_AVERAGE) |
599
COND(subwc_enabled, A6XX_SP_PS_2D_SRC_INFO_FLAGS) |
600
COND(util_format_is_srgb(info->src.format),
601
A6XX_SP_PS_2D_SRC_INFO_SRGB) |
602
0x500000 | filter);
603
OUT_RING(ring,
604
A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width) |
605
A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height)); /* SP_PS_2D_SRC_SIZE */
606
OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */
607
OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(pitch));
608
609
OUT_RING(ring, 0x00000000);
610
OUT_RING(ring, 0x00000000);
611
OUT_RING(ring, 0x00000000);
612
OUT_RING(ring, 0x00000000);
613
OUT_RING(ring, 0x00000000);
614
615
if (subwc_enabled) {
616
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_FLAGS, 6);
617
fd6_emit_flag_reference(ring, src, info->src.level, layer);
618
OUT_RING(ring, 0x00000000);
619
OUT_RING(ring, 0x00000000);
620
OUT_RING(ring, 0x00000000);
621
}
622
}
623
624
static void
625
emit_blit_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,
626
const struct pipe_blit_info *info)
627
{
628
const struct pipe_box *sbox = &info->src.box;
629
const struct pipe_box *dbox = &info->dst.box;
630
struct fd_resource *dst;
631
int sx1, sy1, sx2, sy2;
632
int dx1, dy1, dx2, dy2;
633
634
if (DEBUG_BLIT) {
635
fprintf(stderr, "texture blit: ");
636
dump_blit_info(info);
637
}
638
639
dst = fd_resource(info->dst.resource);
640
641
uint32_t nr_samples = fd_resource_nr_samples(&dst->b.b);
642
643
sx1 = sbox->x * nr_samples;
644
sy1 = sbox->y;
645
sx2 = (sbox->x + sbox->width) * nr_samples - 1;
646
sy2 = sbox->y + sbox->height - 1;
647
648
OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
649
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(sx1));
650
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(sx2));
651
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(sy1));
652
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(sy2));
653
654
dx1 = dbox->x * nr_samples;
655
dy1 = dbox->y;
656
dx2 = (dbox->x + dbox->width) * nr_samples - 1;
657
dy2 = dbox->y + dbox->height - 1;
658
659
OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
660
OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dx1) | A6XX_GRAS_2D_DST_TL_Y(dy1));
661
OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dx2) | A6XX_GRAS_2D_DST_BR_Y(dy2));
662
663
if (info->scissor_enable) {
664
OUT_PKT4(ring, REG_A6XX_GRAS_2D_RESOLVE_CNTL_1, 2);
665
OUT_RING(ring, A6XX_GRAS_2D_RESOLVE_CNTL_1_X(info->scissor.minx) |
666
A6XX_GRAS_2D_RESOLVE_CNTL_1_Y(info->scissor.miny));
667
OUT_RING(ring, A6XX_GRAS_2D_RESOLVE_CNTL_1_X(info->scissor.maxx - 1) |
668
A6XX_GRAS_2D_RESOLVE_CNTL_1_Y(info->scissor.maxy - 1));
669
}
670
671
emit_blit_setup(ring, info->dst.format, info->scissor_enable, NULL);
672
673
for (unsigned i = 0; i < info->dst.box.depth; i++) {
674
675
emit_blit_src(ring, info, sbox->z + i, nr_samples);
676
emit_blit_dst(ring, info->dst.resource, info->dst.format, info->dst.level,
677
dbox->z + i);
678
679
/*
680
* Blit command:
681
*/
682
OUT_PKT7(ring, CP_EVENT_WRITE, 1);
683
OUT_RING(ring, 0x3f);
684
OUT_WFI5(ring);
685
686
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
687
OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);
688
689
OUT_PKT7(ring, CP_BLIT, 1);
690
OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
691
692
OUT_WFI5(ring);
693
694
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
695
OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */
696
}
697
}
698
699
static void
700
emit_clear_color(struct fd_ringbuffer *ring, enum pipe_format pfmt,
701
union pipe_color_union *color)
702
{
703
switch (pfmt) {
704
case PIPE_FORMAT_Z24X8_UNORM:
705
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
706
case PIPE_FORMAT_X24S8_UINT: {
707
uint32_t depth_unorm24 = color->f[0] * ((1u << 24) - 1);
708
uint8_t stencil = color->ui[1];
709
color->ui[0] = depth_unorm24 & 0xff;
710
color->ui[1] = (depth_unorm24 >> 8) & 0xff;
711
color->ui[2] = (depth_unorm24 >> 16) & 0xff;
712
color->ui[3] = stencil;
713
break;
714
}
715
default:
716
break;
717
}
718
719
OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);
720
switch (fd6_ifmt(fd6_pipe2color(pfmt))) {
721
case R2D_UNORM8:
722
case R2D_UNORM8_SRGB:
723
/* The r2d ifmt is badly named, it also covers the signed case: */
724
if (util_format_is_snorm(pfmt)) {
725
OUT_RING(ring, float_to_byte_tex(color->f[0]));
726
OUT_RING(ring, float_to_byte_tex(color->f[1]));
727
OUT_RING(ring, float_to_byte_tex(color->f[2]));
728
OUT_RING(ring, float_to_byte_tex(color->f[3]));
729
} else {
730
OUT_RING(ring, float_to_ubyte(color->f[0]));
731
OUT_RING(ring, float_to_ubyte(color->f[1]));
732
OUT_RING(ring, float_to_ubyte(color->f[2]));
733
OUT_RING(ring, float_to_ubyte(color->f[3]));
734
}
735
break;
736
case R2D_FLOAT16:
737
OUT_RING(ring, _mesa_float_to_half(color->f[0]));
738
OUT_RING(ring, _mesa_float_to_half(color->f[1]));
739
OUT_RING(ring, _mesa_float_to_half(color->f[2]));
740
OUT_RING(ring, _mesa_float_to_half(color->f[3]));
741
break;
742
case R2D_FLOAT32:
743
case R2D_INT32:
744
case R2D_INT16:
745
case R2D_INT8:
746
default:
747
OUT_RING(ring, color->ui[0]);
748
OUT_RING(ring, color->ui[1]);
749
OUT_RING(ring, color->ui[2]);
750
OUT_RING(ring, color->ui[3]);
751
break;
752
}
753
}
754
755
/**
756
* Handle conversion of clear color
757
*/
758
static union pipe_color_union
759
convert_color(enum pipe_format format, union pipe_color_union *pcolor)
760
{
761
union pipe_color_union color = *pcolor;
762
763
/* For solid-fill blits, the hw isn't going to convert from
764
* linear to srgb for us:
765
*/
766
if (util_format_is_srgb(format)) {
767
for (int i = 0; i < 3; i++)
768
color.f[i] = util_format_linear_to_srgb_float(color.f[i]);
769
}
770
771
if (util_format_is_snorm(format)) {
772
for (int i = 0; i < 3; i++)
773
color.f[i] = CLAMP(color.f[i], -1.0f, 1.0f);
774
}
775
776
/* Note that float_to_ubyte() already clamps, for the unorm case */
777
778
return color;
779
}
780
781
void
782
fd6_clear_surface(struct fd_context *ctx, struct fd_ringbuffer *ring,
783
struct pipe_surface *psurf, uint32_t width, uint32_t height,
784
union pipe_color_union *color)
785
{
786
if (DEBUG_BLIT) {
787
fprintf(stderr, "surface clear:\ndst resource: ");
788
util_dump_resource(stderr, psurf->texture);
789
fprintf(stderr, "\n");
790
}
791
792
uint32_t nr_samples = fd_resource_nr_samples(psurf->texture);
793
OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
794
OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));
795
OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(width * nr_samples - 1) |
796
A6XX_GRAS_2D_DST_BR_Y(height - 1));
797
798
union pipe_color_union clear_color = convert_color(psurf->format, color);
799
800
emit_clear_color(ring, psurf->format, &clear_color);
801
emit_blit_setup(ring, psurf->format, false, &clear_color);
802
803
for (unsigned i = psurf->u.tex.first_layer; i <= psurf->u.tex.last_layer;
804
i++) {
805
emit_blit_dst(ring, psurf->texture, psurf->format, psurf->u.tex.level, i);
806
807
/*
808
* Blit command:
809
*/
810
OUT_PKT7(ring, CP_EVENT_WRITE, 1);
811
OUT_RING(ring, 0x3f);
812
OUT_WFI5(ring);
813
814
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
815
OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);
816
817
OUT_PKT7(ring, CP_BLIT, 1);
818
OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
819
820
OUT_WFI5(ring);
821
822
OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
823
OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */
824
}
825
}
826
827
void
828
fd6_resolve_tile(struct fd_batch *batch, struct fd_ringbuffer *ring,
829
uint32_t base, struct pipe_surface *psurf)
830
{
831
const struct fd_gmem_stateobj *gmem = batch->gmem_state;
832
uint64_t gmem_base = batch->ctx->screen->gmem_base + base;
833
uint32_t gmem_pitch = gmem->bin_w * batch->framebuffer.samples *
834
util_format_get_blocksize(psurf->format);
835
836
OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
837
OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));
838
OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(psurf->width - 1) |
839
A6XX_GRAS_2D_DST_BR_Y(psurf->height - 1));
840
841
OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);
842
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(0));
843
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(psurf->width - 1));
844
OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));
845
OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(psurf->height - 1));
846
847
/* Enable scissor bit, which will take into account the window scissor
848
* which is set per-tile
849
*/
850
emit_blit_setup(ring, psurf->format, true, NULL);
851
852
/* We shouldn't be using GMEM in the layered rendering case: */
853
assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer);
854
855
emit_blit_dst(ring, psurf->texture, psurf->format, psurf->u.tex.level,
856
psurf->u.tex.first_layer);
857
858
enum a6xx_format sfmt = fd6_pipe2color(psurf->format);
859
enum a3xx_msaa_samples samples = fd_msaa_samples(batch->framebuffer.samples);
860
861
OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);
862
OUT_RING(ring,
863
A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt) |
864
A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_2) |
865
A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples) |
866
COND(samples > MSAA_ONE, A6XX_SP_PS_2D_SRC_INFO_SAMPLES_AVERAGE) |
867
COND(util_format_is_srgb(psurf->format), A6XX_SP_PS_2D_SRC_INFO_SRGB) |
868
A6XX_SP_PS_2D_SRC_INFO_UNK20 | A6XX_SP_PS_2D_SRC_INFO_UNK22);
869
OUT_RING(ring, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(psurf->width) |
870
A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(psurf->height));
871
OUT_RING(ring, gmem_base); /* SP_PS_2D_SRC_LO */
872
OUT_RING(ring, gmem_base >> 32); /* SP_PS_2D_SRC_HI */
873
OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(gmem_pitch));
874
OUT_RING(ring, 0x00000000);
875
OUT_RING(ring, 0x00000000);
876
OUT_RING(ring, 0x00000000);
877
OUT_RING(ring, 0x00000000);
878
OUT_RING(ring, 0x00000000);
879
880
/* sync GMEM writes with CACHE. */
881
fd6_cache_inv(batch, ring);
882
883
/* Wait for CACHE_INVALIDATE to land */
884
fd_wfi(batch, ring);
885
886
OUT_PKT7(ring, CP_BLIT, 1);
887
OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
888
889
OUT_WFI5(ring);
890
891
/* CP_BLIT writes to the CCU, unlike CP_EVENT_WRITE::BLIT which writes to
892
* sysmem, and we generally assume that GMEM renderpasses leave their
893
* results in sysmem, so we need to flush manually here.
894
*/
895
fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
896
}
897
898
static bool
899
handle_rgba_blit(struct fd_context *ctx,
900
const struct pipe_blit_info *info) assert_dt
901
{
902
struct fd_batch *batch;
903
904
debug_assert(!(info->mask & PIPE_MASK_ZS));
905
906
if (!can_do_blit(info))
907
return false;
908
909
struct fd_resource *src = fd_resource(info->src.resource);
910
struct fd_resource *dst = fd_resource(info->dst.resource);
911
912
fd6_validate_format(ctx, src, info->src.format);
913
fd6_validate_format(ctx, dst, info->dst.format);
914
915
batch = fd_bc_alloc_batch(ctx, true);
916
917
fd_screen_lock(ctx->screen);
918
919
fd_batch_resource_read(batch, src);
920
fd_batch_resource_write(batch, dst);
921
922
fd_screen_unlock(ctx->screen);
923
924
ASSERTED bool ret = fd_batch_lock_submit(batch);
925
assert(ret);
926
927
/* Marking the batch as needing flush must come after the batch
928
* dependency tracking (resource_read()/resource_write()), as that
929
* can trigger a flush
930
*/
931
fd_batch_needs_flush(batch);
932
933
fd_batch_update_queries(batch);
934
935
emit_setup(batch);
936
937
DBG_BLIT(info, batch);
938
939
trace_start_blit(&batch->trace, info->src.resource->target,
940
info->dst.resource->target);
941
942
if ((info->src.resource->target == PIPE_BUFFER) &&
943
(info->dst.resource->target == PIPE_BUFFER)) {
944
assert(src->layout.tile_mode == TILE6_LINEAR);
945
assert(dst->layout.tile_mode == TILE6_LINEAR);
946
emit_blit_buffer(ctx, batch->draw, info);
947
} else {
948
/* I don't *think* we need to handle blits between buffer <-> !buffer */
949
debug_assert(info->src.resource->target != PIPE_BUFFER);
950
debug_assert(info->dst.resource->target != PIPE_BUFFER);
951
emit_blit_texture(ctx, batch->draw, info);
952
}
953
954
trace_end_blit(&batch->trace);
955
956
fd6_event_write(batch, batch->draw, PC_CCU_FLUSH_COLOR_TS, true);
957
fd6_event_write(batch, batch->draw, PC_CCU_FLUSH_DEPTH_TS, true);
958
fd6_event_write(batch, batch->draw, CACHE_FLUSH_TS, true);
959
fd6_cache_inv(batch, batch->draw);
960
961
fd_batch_unlock_submit(batch);
962
963
fd_batch_flush(batch);
964
fd_batch_reference(&batch, NULL);
965
966
/* Acc query state will have been dirtied by our fd_batch_update_queries, so
967
* the ctx->batch may need to turn its queries back on.
968
*/
969
ctx->update_active_queries = true;
970
971
return true;
972
}
973
974
/**
975
* Re-written z/s blits can still fail for various reasons (for example MSAA).
976
* But we want to do the fallback blit with the re-written pipe_blit_info,
977
* in particular as u_blitter cannot blit stencil. So handle the fallback
978
* ourself and never "fail".
979
*/
980
static bool
981
do_rewritten_blit(struct fd_context *ctx,
982
const struct pipe_blit_info *info) assert_dt
983
{
984
bool success = handle_rgba_blit(ctx, info);
985
if (!success)
986
success = fd_blitter_blit(ctx, info);
987
debug_assert(success); /* fallback should never fail! */
988
return success;
989
}
990
991
/**
992
* Handle depth/stencil blits either via u_blitter and/or re-writing the
993
* blit into an equivilant format that we can handle
994
*/
995
static bool
996
handle_zs_blit(struct fd_context *ctx,
997
const struct pipe_blit_info *info) assert_dt
998
{
999
struct pipe_blit_info blit = *info;
1000
1001
if (DEBUG_BLIT) {
1002
fprintf(stderr, "---- handle_zs_blit: ");
1003
dump_blit_info(info);
1004
}
1005
1006
if (info->src.format != info->dst.format)
1007
return false;
1008
1009
struct fd_resource *src = fd_resource(info->src.resource);
1010
struct fd_resource *dst = fd_resource(info->dst.resource);
1011
1012
switch (info->dst.format) {
1013
case PIPE_FORMAT_S8_UINT:
1014
debug_assert(info->mask == PIPE_MASK_S);
1015
blit.mask = PIPE_MASK_R;
1016
blit.src.format = PIPE_FORMAT_R8_UINT;
1017
blit.dst.format = PIPE_FORMAT_R8_UINT;
1018
return do_rewritten_blit(ctx, &blit);
1019
1020
case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
1021
if (info->mask & PIPE_MASK_Z) {
1022
blit.mask = PIPE_MASK_R;
1023
blit.src.format = PIPE_FORMAT_R32_FLOAT;
1024
blit.dst.format = PIPE_FORMAT_R32_FLOAT;
1025
do_rewritten_blit(ctx, &blit);
1026
}
1027
1028
if (info->mask & PIPE_MASK_S) {
1029
blit.mask = PIPE_MASK_R;
1030
blit.src.format = PIPE_FORMAT_R8_UINT;
1031
blit.dst.format = PIPE_FORMAT_R8_UINT;
1032
blit.src.resource = &src->stencil->b.b;
1033
blit.dst.resource = &dst->stencil->b.b;
1034
do_rewritten_blit(ctx, &blit);
1035
}
1036
1037
return true;
1038
1039
case PIPE_FORMAT_Z16_UNORM:
1040
blit.mask = PIPE_MASK_R;
1041
blit.src.format = PIPE_FORMAT_R16_UNORM;
1042
blit.dst.format = PIPE_FORMAT_R16_UNORM;
1043
return do_rewritten_blit(ctx, &blit);
1044
1045
case PIPE_FORMAT_Z32_UNORM:
1046
case PIPE_FORMAT_Z32_FLOAT:
1047
debug_assert(info->mask == PIPE_MASK_Z);
1048
blit.mask = PIPE_MASK_R;
1049
blit.src.format = PIPE_FORMAT_R32_UINT;
1050
blit.dst.format = PIPE_FORMAT_R32_UINT;
1051
return do_rewritten_blit(ctx, &blit);
1052
1053
case PIPE_FORMAT_Z24X8_UNORM:
1054
case PIPE_FORMAT_Z24_UNORM_S8_UINT:
1055
blit.mask = 0;
1056
if (info->mask & PIPE_MASK_Z)
1057
blit.mask |= PIPE_MASK_R | PIPE_MASK_G | PIPE_MASK_B;
1058
if (info->mask & PIPE_MASK_S)
1059
blit.mask |= PIPE_MASK_A;
1060
blit.src.format = PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8;
1061
blit.dst.format = PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8;
1062
/* non-UBWC Z24_UNORM_S8_UINT_AS_R8G8B8A8 is broken on a630, fall back to
1063
* 8888_unorm.
1064
*/
1065
if (!ctx->screen->info->a6xx.has_z24uint_s8uint) {
1066
if (!src->layout.ubwc)
1067
blit.src.format = PIPE_FORMAT_RGBA8888_UNORM;
1068
if (!dst->layout.ubwc)
1069
blit.dst.format = PIPE_FORMAT_RGBA8888_UNORM;
1070
}
1071
return fd_blitter_blit(ctx, &blit);
1072
1073
default:
1074
return false;
1075
}
1076
}
1077
1078
static bool
1079
handle_compressed_blit(struct fd_context *ctx,
1080
const struct pipe_blit_info *info) assert_dt
1081
{
1082
struct pipe_blit_info blit = *info;
1083
1084
if (DEBUG_BLIT) {
1085
fprintf(stderr, "---- handle_compressed_blit: ");
1086
dump_blit_info(info);
1087
}
1088
1089
if (info->src.format != info->dst.format)
1090
return fd_blitter_blit(ctx, info);
1091
1092
if (util_format_get_blocksize(info->src.format) == 8) {
1093
blit.src.format = blit.dst.format = PIPE_FORMAT_R16G16B16A16_UINT;
1094
} else {
1095
debug_assert(util_format_get_blocksize(info->src.format) == 16);
1096
blit.src.format = blit.dst.format = PIPE_FORMAT_R32G32B32A32_UINT;
1097
}
1098
1099
int bw = util_format_get_blockwidth(info->src.format);
1100
int bh = util_format_get_blockheight(info->src.format);
1101
1102
/* NOTE: x/y *must* be aligned to block boundary (ie. in
1103
* glCompressedTexSubImage2D()) but width/height may not
1104
* be:
1105
*/
1106
1107
debug_assert((blit.src.box.x % bw) == 0);
1108
debug_assert((blit.src.box.y % bh) == 0);
1109
1110
blit.src.box.x /= bw;
1111
blit.src.box.y /= bh;
1112
blit.src.box.width = DIV_ROUND_UP(blit.src.box.width, bw);
1113
blit.src.box.height = DIV_ROUND_UP(blit.src.box.height, bh);
1114
1115
debug_assert((blit.dst.box.x % bw) == 0);
1116
debug_assert((blit.dst.box.y % bh) == 0);
1117
1118
blit.dst.box.x /= bw;
1119
blit.dst.box.y /= bh;
1120
blit.dst.box.width = DIV_ROUND_UP(blit.dst.box.width, bw);
1121
blit.dst.box.height = DIV_ROUND_UP(blit.dst.box.height, bh);
1122
1123
return do_rewritten_blit(ctx, &blit);
1124
}
1125
1126
static enum pipe_format
1127
snorm_copy_format(enum pipe_format format)
1128
{
1129
switch (format) {
1130
case PIPE_FORMAT_R8_SNORM: return PIPE_FORMAT_R8_UNORM;
1131
case PIPE_FORMAT_R16_SNORM: return PIPE_FORMAT_R16_UNORM;
1132
case PIPE_FORMAT_A16_SNORM: return PIPE_FORMAT_A16_UNORM;
1133
case PIPE_FORMAT_L16_SNORM: return PIPE_FORMAT_L16_UNORM;
1134
case PIPE_FORMAT_I16_SNORM: return PIPE_FORMAT_I16_UNORM;
1135
case PIPE_FORMAT_R8G8_SNORM: return PIPE_FORMAT_R8G8_UNORM;
1136
case PIPE_FORMAT_R8G8B8_SNORM: return PIPE_FORMAT_R8G8B8_UNORM;
1137
case PIPE_FORMAT_R32_SNORM: return PIPE_FORMAT_R32_UNORM;
1138
case PIPE_FORMAT_R16G16_SNORM: return PIPE_FORMAT_R16G16_UNORM;
1139
case PIPE_FORMAT_L16A16_SNORM: return PIPE_FORMAT_L16A16_UNORM;
1140
case PIPE_FORMAT_R8G8B8A8_SNORM: return PIPE_FORMAT_R8G8B8A8_UNORM;
1141
case PIPE_FORMAT_R10G10B10A2_SNORM: return PIPE_FORMAT_R10G10B10A2_UNORM;
1142
case PIPE_FORMAT_B10G10R10A2_SNORM: return PIPE_FORMAT_B10G10R10A2_UNORM;
1143
case PIPE_FORMAT_R16G16B16_SNORM: return PIPE_FORMAT_R16G16B16_UNORM;
1144
case PIPE_FORMAT_R16G16B16A16_SNORM: return PIPE_FORMAT_R16G16B16A16_UNORM;
1145
case PIPE_FORMAT_R16G16B16X16_SNORM: return PIPE_FORMAT_R16G16B16X16_UNORM;
1146
case PIPE_FORMAT_R32G32_SNORM: return PIPE_FORMAT_R32G32_UNORM;
1147
case PIPE_FORMAT_R32G32B32_SNORM: return PIPE_FORMAT_R32G32B32_UNORM;
1148
case PIPE_FORMAT_R32G32B32A32_SNORM: return PIPE_FORMAT_R32G32B32A32_UNORM;
1149
default:
1150
unreachable("unhandled snorm format");
1151
return format;
1152
}
1153
}
1154
1155
/**
1156
* For SNORM formats, copy them as the equivalent UNORM format. If we treat
1157
* them as snorm then the 0x80 (-1.0 snorm8) value will get clamped to 0x81
1158
* (also -1.0), when we're supposed to be memcpying the bits. See
1159
* https://gitlab.khronos.org/Tracker/vk-gl-cts/-/issues/2917 for discussion.
1160
*/
1161
static bool
1162
handle_snorm_copy_blit(struct fd_context *ctx,
1163
const struct pipe_blit_info *info)
1164
assert_dt
1165
{
1166
struct pipe_blit_info blit = *info;
1167
1168
blit.src.format = blit.dst.format = snorm_copy_format(info->src.format);
1169
1170
return do_rewritten_blit(ctx, &blit);
1171
}
1172
1173
static bool
1174
fd6_blit(struct fd_context *ctx, const struct pipe_blit_info *info) assert_dt
1175
{
1176
if (info->mask & PIPE_MASK_ZS)
1177
return handle_zs_blit(ctx, info);
1178
1179
if (util_format_is_compressed(info->src.format) ||
1180
util_format_is_compressed(info->dst.format))
1181
return handle_compressed_blit(ctx, info);
1182
1183
if ((info->src.format == info->dst.format) &&
1184
util_format_is_snorm(info->src.format))
1185
return handle_snorm_copy_blit(ctx, info);
1186
1187
return handle_rgba_blit(ctx, info);
1188
}
1189
1190
void
1191
fd6_blitter_init(struct pipe_context *pctx) disable_thread_safety_analysis
1192
{
1193
struct fd_context *ctx = fd_context(pctx);
1194
1195
ctx->clear_ubwc = fd6_clear_ubwc;
1196
ctx->validate_format = fd6_validate_format;
1197
1198
if (FD_DBG(NOBLIT))
1199
return;
1200
1201
ctx->blit = fd6_blit;
1202
}
1203
1204
unsigned
1205
fd6_tile_mode(const struct pipe_resource *tmpl)
1206
{
1207
/* if the mipmap level 0 is still too small to be tiled, then don't
1208
* bother pretending:
1209
*/
1210
if (fd_resource_level_linear(tmpl, 0))
1211
return TILE6_LINEAR;
1212
1213
/* basically just has to be a format we can blit, so uploads/downloads
1214
* via linear staging buffer works:
1215
*/
1216
if (ok_format(tmpl->format))
1217
return TILE6_3;
1218
1219
return TILE6_LINEAR;
1220
}
1221
1222