fd6_draw.c 15.8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
 * Copyright © 2018 Google, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Authors:
 *    Rob Clark <robclark@freedesktop.org>
 */

#include "pipe/p_state.h"
#include "util/u_string.h"
#include "util/u_memory.h"
#include "util/u_prim.h"

#include "freedreno_state.h"
#include "freedreno_resource.h"

#include "fd6_draw.h"
#include "fd6_context.h"
#include "fd6_emit.h"
#include "fd6_program.h"
#include "fd6_format.h"
41
#include "fd6_vsc.h"
42
43
#include "fd6_zsa.h"

44
45
#include "fd6_pack.h"

46
static void
47
draw_emit_indirect(struct fd_ringbuffer *ring,
48
				   struct CP_DRAW_INDX_OFFSET_0 *draw0,
49
				   const struct pipe_draw_info *info,
50
                   const struct pipe_draw_indirect_info *indirect,
51
52
				   unsigned index_offset)
{
53
	struct fd_resource *ind = fd_resource(indirect->buffer);
54
55
56

	if (info->index_size) {
		struct pipe_resource *idx = info->index.resource;
57
		unsigned max_indices = (idx->width0 - index_offset) / info->index_size;
58

59
60
61
62
		OUT_PKT(ring, CP_DRAW_INDX_INDIRECT,
				pack_CP_DRAW_INDX_OFFSET_0(*draw0),
				A5XX_CP_DRAW_INDX_INDIRECT_INDX_BASE(
						fd_resource(idx)->bo, index_offset),
63
				A5XX_CP_DRAW_INDX_INDIRECT_3(.max_indices = max_indices),
64
				A5XX_CP_DRAW_INDX_INDIRECT_INDIRECT(
65
						ind->bo, indirect->offset)
66
			);
67
	} else {
68
69
70
		OUT_PKT(ring, CP_DRAW_INDIRECT,
				pack_CP_DRAW_INDX_OFFSET_0(*draw0),
				A5XX_CP_DRAW_INDIRECT_INDIRECT(
71
						ind->bo, indirect->offset)
72
			);
73
74
75
76
	}
}

static void
77
draw_emit(struct fd_ringbuffer *ring,
78
		  struct CP_DRAW_INDX_OFFSET_0 *draw0,
79
		  const struct pipe_draw_info *info,
80
                  const struct pipe_draw_start_count *draw,
81
		  unsigned index_offset)
82
83
84
85
{
	if (info->index_size) {
		assert(!info->has_user_indices);

86
		struct pipe_resource *idx_buffer = info->index.resource;
87
		unsigned max_indices = (idx_buffer->width0 - index_offset) / info->index_size;
88

89
90
91
		OUT_PKT(ring, CP_DRAW_INDX_OFFSET,
				pack_CP_DRAW_INDX_OFFSET_0(*draw0),
				CP_DRAW_INDX_OFFSET_1(.num_instances = info->instance_count),
92
93
				CP_DRAW_INDX_OFFSET_2(.num_indices = draw->count),
				CP_DRAW_INDX_OFFSET_3(.first_indx = draw->start),
94
				A5XX_CP_DRAW_INDX_OFFSET_INDX_BASE(
95
						fd_resource(idx_buffer)->bo, index_offset),
96
				A5XX_CP_DRAW_INDX_OFFSET_6(.max_indices = max_indices)
97
			);
98
	} else {
99
100
101
		OUT_PKT(ring, CP_DRAW_INDX_OFFSET,
				pack_CP_DRAW_INDX_OFFSET_0(*draw0),
				CP_DRAW_INDX_OFFSET_1(.num_instances = info->instance_count),
102
				CP_DRAW_INDX_OFFSET_2(.num_indices = draw->count)
103
			);
104
	}
105
}
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

/* fixup dirty shader state in case some "unrelated" (from the state-
 * tracker's perspective) state change causes us to switch to a
 * different variant.
 */
static void
fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
{
	struct fd6_context *fd6_ctx = fd6_context(ctx);
	struct ir3_shader_key *last_key = &fd6_ctx->last_key;

	if (!ir3_shader_key_equal(last_key, key)) {
		if (ir3_shader_key_changes_fs(last_key, key)) {
			ctx->dirty_shader[PIPE_SHADER_FRAGMENT] |= FD_DIRTY_SHADER_PROG;
			ctx->dirty |= FD_DIRTY_PROG;
		}

		if (ir3_shader_key_changes_vs(last_key, key)) {
			ctx->dirty_shader[PIPE_SHADER_VERTEX] |= FD_DIRTY_SHADER_PROG;
			ctx->dirty |= FD_DIRTY_PROG;
		}

		fd6_ctx->last_key = *key;
	}
}

132
133
134
135
136
137
138
139
140
141
142
static void
fixup_draw_state(struct fd_context *ctx, struct fd6_emit *emit)
{
	if (ctx->last.dirty ||
			(ctx->last.primitive_restart != emit->primitive_restart)) {
		/* rasterizer state is effected by primitive-restart: */
		ctx->dirty |= FD_DIRTY_RASTERIZER;
		ctx->last.primitive_restart = emit->primitive_restart;
	}
}

143
144
static bool
fd6_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
145
             const struct pipe_draw_indirect_info *indirect,
146
             const struct pipe_draw_start_count *draw,
147
148
149
             unsigned index_offset)
{
	struct fd6_context *fd6_ctx = fd6_context(ctx);
150
	struct ir3_shader *gs = ctx->prog.gs;
151
	struct fd6_emit emit = {
Rob Clark's avatar
Rob Clark committed
152
		.ctx = ctx,
153
154
		.vtx  = &ctx->vtx,
		.info = info,
155
                .indirect = indirect,
156
                .draw = draw,
157
		.key = {
158
			.vs = ctx->prog.vs,
159
			.gs = ctx->prog.gs,
160
			.fs = ctx->prog.fs,
Rob Clark's avatar
Rob Clark committed
161
162
163
164
165
166
			.key = {
				.color_two_side = ctx->rasterizer->light_twoside,
				.vclamp_color = ctx->rasterizer->clamp_vertex_color,
				.fclamp_color = ctx->rasterizer->clamp_fragment_color,
				.rasterflat = ctx->rasterizer->flatshade,
				.ucp_enables = ctx->rasterizer->clip_plane_enable,
167
				.has_per_samp = (fd6_ctx->fsaturate || fd6_ctx->vsaturate),
Rob Clark's avatar
Rob Clark committed
168
169
170
171
172
173
				.vsaturate_s = fd6_ctx->vsaturate_s,
				.vsaturate_t = fd6_ctx->vsaturate_t,
				.vsaturate_r = fd6_ctx->vsaturate_r,
				.fsaturate_s = fd6_ctx->fsaturate_s,
				.fsaturate_t = fd6_ctx->fsaturate_t,
				.fsaturate_r = fd6_ctx->fsaturate_r,
174
				.layer_zero = !gs || !(gs->nir->info.outputs_written & VARYING_BIT_LAYER),
Rob Clark's avatar
Rob Clark committed
175
176
				.vsamples = ctx->tex[PIPE_SHADER_VERTEX].samples,
				.fsamples = ctx->tex[PIPE_SHADER_FRAGMENT].samples,
177
178
179
				.sample_shading = (ctx->min_samples > 1),
				.msaa = (ctx->framebuffer.samples > 1),
			},
180
181
182
		},
		.rasterflat = ctx->rasterizer->flatshade,
		.sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
183
184
		.sprite_origin_upper_left =
			ctx->rasterizer->sprite_coord_mode == PIPE_SPRITE_COORD_UPPER_LEFT,
185
		.fb_inverted = ctx->viewport.scale[1] < 0,
186
		.primitive_restart = info->primitive_restart && info->index_size,
187
188
	};

189
190
191
	if (!(ctx->prog.vs && ctx->prog.fs))
		return false;

192
	if (info->mode == PIPE_PRIM_PATCHES) {
193
194
195
		emit.key.hs = ctx->prog.hs;
		emit.key.ds = ctx->prog.ds;

196
197
198
		if (!(ctx->prog.hs && ctx->prog.ds))
			return false;

199
		shader_info *ds_info = &emit.key.ds->nir->info;
200
		emit.key.key.tessellation = ir3_tess_mode(ds_info->tess.primitive_mode);
201
202
	}

203
204
205
	if (emit.key.gs)
		emit.key.key.has_gs = true;

206
	if (!(emit.key.hs || emit.key.ds || emit.key.gs || (indirect && indirect->buffer)))
207
		fd6_vsc_update_sizes(ctx->batch, info, draw);
208

Rob Clark's avatar
Rob Clark committed
209
	fixup_shader_state(ctx, &emit.key.key);
210

211
	if (!(ctx->dirty & FD_DIRTY_PROG)) {
Rob Clark's avatar
Rob Clark committed
212
213
214
215
216
		emit.prog = fd6_ctx->prog;
	} else {
		fd6_ctx->prog = fd6_emit_get_prog(&emit);
	}

217
218
	/* bail if compile failed: */
	if (!fd6_ctx->prog)
219
		return false;
220

221
222
	fixup_draw_state(ctx, &emit);

223
	emit.dirty = ctx->dirty;      /* *after* fixup_shader_state() */
224
	emit.bs = fd6_emit_get_prog(&emit)->bs;
Rob Clark's avatar
Rob Clark committed
225
	emit.vs = fd6_emit_get_prog(&emit)->vs;
226
227
228
	emit.hs = fd6_emit_get_prog(&emit)->hs;
	emit.ds = fd6_emit_get_prog(&emit)->ds;
	emit.gs = fd6_emit_get_prog(&emit)->gs;
Rob Clark's avatar
Rob Clark committed
229
230
	emit.fs = fd6_emit_get_prog(&emit)->fs;

231
232
233
234
235
	ctx->stats.vs_regs += ir3_shader_halfregs(emit.vs);
	ctx->stats.hs_regs += COND(emit.hs, ir3_shader_halfregs(emit.hs));
	ctx->stats.ds_regs += COND(emit.ds, ir3_shader_halfregs(emit.ds));
	ctx->stats.gs_regs += COND(emit.gs, ir3_shader_halfregs(emit.gs));
	ctx->stats.fs_regs += ir3_shader_halfregs(emit.fs);
236

Rob Clark's avatar
Rob Clark committed
237
238
	struct fd_ringbuffer *ring = ctx->batch->draw;

239
240
241
242
243
244
245
246
247
248
249
250
251
	struct CP_DRAW_INDX_OFFSET_0 draw0 = {
			.prim_type = ctx->primtypes[info->mode],
			.vis_cull  = USE_VISIBILITY,
			.gs_enable = !!emit.key.gs,
	};

	if (info->index_size) {
		draw0.source_select = DI_SRC_SEL_DMA;
		draw0.index_size = fd4_size2indextype(info->index_size);
	} else {
		draw0.source_select = DI_SRC_SEL_AUTO_INDEX;
	}

252
253
254
255
256
257
	if (info->mode == PIPE_PRIM_PATCHES) {
		shader_info *ds_info = &emit.ds->shader->nir->info;
		uint32_t factor_stride;

		switch (ds_info->tess.primitive_mode) {
		case GL_ISOLINES:
258
			draw0.patch_type = TESS_ISOLINES;
259
260
261
			factor_stride = 12;
			break;
		case GL_TRIANGLES:
262
			draw0.patch_type = TESS_TRIANGLES;
263
264
265
			factor_stride = 20;
			break;
		case GL_QUADS:
266
			draw0.patch_type = TESS_QUADS;
267
268
269
270
271
272
			factor_stride = 28;
			break;
		default:
			unreachable("bad tessmode");
		}

273
274
		draw0.prim_type = DI_PT_PATCHES0 + info->vertices_per_patch;
		draw0.tess_enable = true;
275
276
277

		ctx->batch->tessellation = true;
		ctx->batch->tessparam_size = MAX2(ctx->batch->tessparam_size,
278
				emit.hs->output_size * 4 * draw->count);
279
		ctx->batch->tessfactor_size = MAX2(ctx->batch->tessfactor_size,
280
				factor_stride * draw->count);
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

		if (!ctx->batch->tess_addrs_constobj) {
			/* Reserve space for the bo address - we'll write them later in
			 * setup_tess_buffers().  We need 2 bo address, but indirect
			 * constant upload needs at least 4 vec4s.
			 */
			unsigned size = 4 * 16;

			ctx->batch->tess_addrs_constobj = fd_submit_new_ringbuffer(
				ctx->batch->submit, size, FD_RINGBUFFER_STREAMING);

			ctx->batch->tess_addrs_constobj->cur += size;
		}
	}

296
	uint32_t index_start = info->index_size ? info->index_bias : draw->start;
297
298
299
300
301
	if (ctx->last.dirty || (ctx->last.index_start != index_start)) {
		OUT_PKT4(ring, REG_A6XX_VFD_INDEX_OFFSET, 1);
		OUT_RING(ring, index_start); /* VFD_INDEX_OFFSET */
		ctx->last.index_start = index_start;
	}
302

303
304
305
306
307
	if (ctx->last.dirty || (ctx->last.instance_start != info->start_instance)) {
		OUT_PKT4(ring, REG_A6XX_VFD_INSTANCE_START_OFFSET, 1);
		OUT_RING(ring, info->start_instance); /* VFD_INSTANCE_START_OFFSET */
		ctx->last.instance_start = info->start_instance;
	}
Rob Clark's avatar
Rob Clark committed
308

309
310
311
312
313
314
315
316
	uint32_t restart_index = info->primitive_restart ? info->restart_index : 0xffffffff;
	if (ctx->last.dirty || (ctx->last.restart_index != restart_index)) {
		OUT_PKT4(ring, REG_A6XX_PC_RESTART_INDEX, 1);
		OUT_RING(ring, restart_index); /* PC_RESTART_INDEX */
		ctx->last.restart_index = restart_index;
	}

	fd6_emit_state(ring, &emit);
Rob Clark's avatar
Rob Clark committed
317
318
319
320
321
322
323
324
325

	/* for debug after a lock up, write a unique counter value
	 * to scratch7 for each draw, to make it easier to match up
	 * register dumps to cmdstream.  The combination of IB
	 * (scratch6) and DRAW is enough to "triangulate" the
	 * particular draw that caused lockup.
	 */
	emit_marker6(ring, 7);

326
327
	if (indirect && indirect->buffer) {
		draw_emit_indirect(ring, &draw0, info, indirect, index_offset);
Rob Clark's avatar
Rob Clark committed
328
	} else {
329
		draw_emit(ring, &draw0, info, draw, index_offset);
Rob Clark's avatar
Rob Clark committed
330
331
332
333
	}

	emit_marker6(ring, 7);
	fd_reset_wfi(ctx->batch);
334
335
336
337
338
339

	if (emit.streamout_mask) {
		struct fd_ringbuffer *ring = ctx->batch->draw;

		for (unsigned i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
			if (emit.streamout_mask & (1 << i)) {
340
				fd6_event_write(ctx->batch, ring, FLUSH_SO_0 + i, false);
341
342
343
344
345
346
347
348
349
350
351
352
353
			}
		}
	}

	fd_context_all_clean(ctx);

	return true;
}

static void
fd6_clear_lrz(struct fd_batch *batch, struct fd_resource *zsbuf, double depth)
{
	struct fd_ringbuffer *ring;
354
	struct fd_screen *screen = batch->ctx->screen;
355

356
	ring = fd_batch_get_prologue(batch);
357

Rob Clark's avatar
Rob Clark committed
358
359
	emit_marker6(ring, 7);
	OUT_PKT7(ring, CP_SET_MARKER, 1);
360
	OUT_RING(ring, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS));
Rob Clark's avatar
Rob Clark committed
361
	emit_marker6(ring, 7);
362

363
364
	OUT_WFI5(ring);

365
	OUT_REG(ring, A6XX_RB_CCU_CNTL(.offset = screen->info.a6xx.ccu_offset_bypass));
366

367
368
369
370
371
372
373
374
375
376
377
378
379
	OUT_REG(ring, A6XX_HLSQ_INVALIDATE_CMD(
			.vs_state = true,
			.hs_state = true,
			.ds_state = true,
			.gs_state = true,
			.fs_state = true,
			.cs_state = true,
			.gfx_ibo = true,
			.cs_ibo = true,
			.gfx_shared_const = true,
			.gfx_bindless = 0x1f,
			.cs_bindless = 0x1f
		));
380

Rob Clark's avatar
Rob Clark committed
381
382
	emit_marker6(ring, 7);
	OUT_PKT7(ring, CP_SET_MARKER, 1);
383
	OUT_RING(ring, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
Rob Clark's avatar
Rob Clark committed
384
	emit_marker6(ring, 7);
385

386
	OUT_PKT4(ring, REG_A6XX_RB_2D_UNKNOWN_8C01, 1);
Rob Clark's avatar
Rob Clark committed
387
	OUT_RING(ring, 0x0);
388

Rob Clark's avatar
Rob Clark committed
389
390
391
392
393
394
395
396
397
398
399
400
	OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
401
402
403
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);

404
	OUT_PKT4(ring, REG_A6XX_SP_2D_DST_FORMAT, 1);
Rob Clark's avatar
Rob Clark committed
405
	OUT_RING(ring, 0x0000f410);
406

Rob Clark's avatar
Rob Clark committed
407
	OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);
408
	OUT_RING(ring, A6XX_GRAS_2D_BLIT_CNTL_COLOR_FORMAT(FMT6_16_UNORM) |
Rob Clark's avatar
Rob Clark committed
409
			0x4f00080);
410

Rob Clark's avatar
Rob Clark committed
411
	OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);
412
	OUT_RING(ring, A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(FMT6_16_UNORM) |
Rob Clark's avatar
Rob Clark committed
413
			0x4f00080);
414

415
	fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
Rob Clark's avatar
Rob Clark committed
416
	fd6_event_write(batch, ring, PC_CCU_INVALIDATE_COLOR, false);
417

Rob Clark's avatar
Rob Clark committed
418
419
420
421
422
	OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);
	OUT_RING(ring, fui(depth));
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
423

Rob Clark's avatar
Rob Clark committed
424
	OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
425
	OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_16_UNORM) |
Rob Clark's avatar
Rob Clark committed
426
427
			A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |
			A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));
428
	OUT_RELOC(ring, zsbuf->lrz, 0, 0, 0);
429
	OUT_RING(ring, A6XX_RB_2D_DST_PITCH(zsbuf->lrz_pitch * 2).value);
Rob Clark's avatar
Rob Clark committed
430
431
432
433
434
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
	OUT_RING(ring, 0x00000000);
435

436
437
438
439
440
	OUT_REG(ring,
			A6XX_GRAS_2D_SRC_TL_X(0),
			A6XX_GRAS_2D_SRC_BR_X(0),
			A6XX_GRAS_2D_SRC_TL_Y(0),
			A6XX_GRAS_2D_SRC_BR_Y(0));
441

Rob Clark's avatar
Rob Clark committed
442
443
444
445
446
	OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
	OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) |
			A6XX_GRAS_2D_DST_TL_Y(0));
	OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(zsbuf->lrz_width - 1) |
			A6XX_GRAS_2D_DST_BR_Y(zsbuf->lrz_height - 1));
447

Rob Clark's avatar
Rob Clark committed
448
	fd6_event_write(batch, ring, 0x3f, false);
449

Rob Clark's avatar
Rob Clark committed
450
	OUT_WFI5(ring);
451

Rob Clark's avatar
Rob Clark committed
452
	OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
453
	OUT_RING(ring, screen->info.a6xx.magic.RB_UNKNOWN_8E04_blit);
454

Rob Clark's avatar
Rob Clark committed
455
456
	OUT_PKT7(ring, CP_BLIT, 1);
	OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
457

Rob Clark's avatar
Rob Clark committed
458
	OUT_WFI5(ring);
459

Rob Clark's avatar
Rob Clark committed
460
	OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
461
	OUT_RING(ring, 0x0);               /* RB_UNKNOWN_8E04 */
462

463
464
	fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
	fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);
Rob Clark's avatar
Rob Clark committed
465
	fd6_event_write(batch, ring, CACHE_FLUSH_TS, true);
466

Rob Clark's avatar
Rob Clark committed
467
	fd6_cache_inv(batch, ring);
468
469
}

470
471
472
473
474
475
476
477
478
479
480
481
static bool is_z32(enum pipe_format format)
{
	switch (format) {
	case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
	case PIPE_FORMAT_Z32_UNORM:
	case PIPE_FORMAT_Z32_FLOAT:
		return true;
	default:
		return false;
	}
}

482
483
484
485
486
static bool
fd6_clear(struct fd_context *ctx, unsigned buffers,
		const union pipe_color_union *color, double depth, unsigned stencil)
{
	struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
487
	const bool has_depth = pfb->zsbuf;
488
489
	unsigned color_buffers = buffers >> 2;

Rob Clark's avatar
Rob Clark committed
490
491
492
493
	/* we need to do multisample clear on 3d pipe, so fallback to u_blitter: */
	if (pfb->samples > 1)
		return false;

494
495
496
497
498
499
	/* If we're clearing after draws, fallback to 3D pipe clears.  We could
	 * use blitter clears in the draw batch but then we'd have to patch up the
	 * gmem offsets. This doesn't seem like a useful thing to optimize for
	 * however.*/
	if (ctx->batch->num_draws > 0)
		return false;
500

501
502
503
504
505
506
	foreach_bit(i, color_buffers)
		ctx->batch->clear_color[i] = *color;
	if (buffers & PIPE_CLEAR_DEPTH)
		ctx->batch->clear_depth = depth;
	if (buffers & PIPE_CLEAR_STENCIL)
		ctx->batch->clear_stencil = stencil;
507

508
	ctx->batch->fast_cleared |= buffers;
509
510
511

	if (has_depth && (buffers & PIPE_CLEAR_DEPTH)) {
		struct fd_resource *zsbuf = fd_resource(pfb->zsbuf->texture);
512
		if (zsbuf->lrz && !is_z32(pfb->zsbuf->format)) {
513
			zsbuf->lrz_valid = true;
514
			zsbuf->lrz_direction = FD_LRZ_UNKNOWN;
515
			fd6_clear_lrz(ctx->batch, zsbuf, depth);
516
517
518
519
520
521
522
523
524
525
526
527
528
		}
	}

	return true;
}

void
fd6_draw_init(struct pipe_context *pctx)
{
	struct fd_context *ctx = fd_context(pctx);
	ctx->draw_vbo = fd6_draw_vbo;
	ctx->clear = fd6_clear;
}