• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 Rob Clark <robclark@freedesktop.org>
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 <robclark@freedesktop.org>
26  */
27 
28 #include "pipe/p_state.h"
29 #include "util/u_memory.h"
30 #include "util/u_prim.h"
31 #include "util/u_string.h"
32 
33 #include "freedreno_resource.h"
34 #include "freedreno_state.h"
35 
36 #include "fd6_context.h"
37 #include "fd6_draw.h"
38 #include "fd6_emit.h"
39 #include "fd6_format.h"
40 #include "fd6_program.h"
41 #include "fd6_vsc.h"
42 #include "fd6_zsa.h"
43 
44 #include "fd6_pack.h"
45 
46 static void
draw_emit_xfb(struct fd_ringbuffer * ring,struct CP_DRAW_INDX_OFFSET_0 * draw0,const struct pipe_draw_info * info,const struct pipe_draw_indirect_info * indirect)47 draw_emit_xfb(struct fd_ringbuffer *ring, struct CP_DRAW_INDX_OFFSET_0 *draw0,
48               const struct pipe_draw_info *info,
49               const struct pipe_draw_indirect_info *indirect)
50 {
51    struct fd_stream_output_target *target =
52       fd_stream_output_target(indirect->count_from_stream_output);
53    struct fd_resource *offset = fd_resource(target->offset_buf);
54 
55    /* All known firmware versions do not wait for WFI's with CP_DRAW_AUTO.
56     * Plus, for the common case where the counter buffer is written by
57     * vkCmdEndTransformFeedback, we need to wait for the CP_WAIT_MEM_WRITES to
58     * complete which means we need a WAIT_FOR_ME anyway.
59     */
60    OUT_PKT7(ring, CP_WAIT_FOR_ME, 0);
61 
62    OUT_PKT7(ring, CP_DRAW_AUTO, 6);
63    OUT_RING(ring, pack_CP_DRAW_INDX_OFFSET_0(*draw0).value);
64    OUT_RING(ring, info->instance_count);
65    OUT_RELOC(ring, offset->bo, 0, 0, 0);
66    OUT_RING(
67       ring,
68       0); /* byte counter offset subtraced from the value read from above */
69    OUT_RING(ring, target->stride);
70 }
71 
72 static void
draw_emit_indirect(struct fd_ringbuffer * ring,struct CP_DRAW_INDX_OFFSET_0 * draw0,const struct pipe_draw_info * info,const struct pipe_draw_indirect_info * indirect,unsigned index_offset)73 draw_emit_indirect(struct fd_ringbuffer *ring,
74                    struct CP_DRAW_INDX_OFFSET_0 *draw0,
75                    const struct pipe_draw_info *info,
76                    const struct pipe_draw_indirect_info *indirect,
77                    unsigned index_offset)
78 {
79    struct fd_resource *ind = fd_resource(indirect->buffer);
80 
81    if (info->index_size) {
82       struct pipe_resource *idx = info->index.resource;
83       unsigned max_indices = (idx->width0 - index_offset) / info->index_size;
84 
85       OUT_PKT(ring, CP_DRAW_INDX_INDIRECT, pack_CP_DRAW_INDX_OFFSET_0(*draw0),
86               A5XX_CP_DRAW_INDX_INDIRECT_INDX_BASE(fd_resource(idx)->bo,
87                                                    index_offset),
88               A5XX_CP_DRAW_INDX_INDIRECT_3(.max_indices = max_indices),
89               A5XX_CP_DRAW_INDX_INDIRECT_INDIRECT(ind->bo, indirect->offset));
90    } else {
91       OUT_PKT(ring, CP_DRAW_INDIRECT, pack_CP_DRAW_INDX_OFFSET_0(*draw0),
92               A5XX_CP_DRAW_INDIRECT_INDIRECT(ind->bo, indirect->offset));
93    }
94 }
95 
96 static void
draw_emit(struct fd_ringbuffer * ring,struct CP_DRAW_INDX_OFFSET_0 * draw0,const struct pipe_draw_info * info,const struct pipe_draw_start_count_bias * draw,unsigned index_offset)97 draw_emit(struct fd_ringbuffer *ring, struct CP_DRAW_INDX_OFFSET_0 *draw0,
98           const struct pipe_draw_info *info,
99           const struct pipe_draw_start_count_bias *draw, unsigned index_offset)
100 {
101    if (info->index_size) {
102       assert(!info->has_user_indices);
103 
104       struct pipe_resource *idx_buffer = info->index.resource;
105       unsigned max_indices =
106          (idx_buffer->width0 - index_offset) / info->index_size;
107 
108       OUT_PKT(ring, CP_DRAW_INDX_OFFSET, pack_CP_DRAW_INDX_OFFSET_0(*draw0),
109               CP_DRAW_INDX_OFFSET_1(.num_instances = info->instance_count),
110               CP_DRAW_INDX_OFFSET_2(.num_indices = draw->count),
111               CP_DRAW_INDX_OFFSET_3(.first_indx = draw->start),
112               A5XX_CP_DRAW_INDX_OFFSET_INDX_BASE(fd_resource(idx_buffer)->bo,
113                                                  index_offset),
114               A5XX_CP_DRAW_INDX_OFFSET_6(.max_indices = max_indices));
115    } else {
116       OUT_PKT(ring, CP_DRAW_INDX_OFFSET, pack_CP_DRAW_INDX_OFFSET_0(*draw0),
117               CP_DRAW_INDX_OFFSET_1(.num_instances = info->instance_count),
118               CP_DRAW_INDX_OFFSET_2(.num_indices = draw->count));
119    }
120 }
121 
122 static void
fixup_draw_state(struct fd_context * ctx,struct fd6_emit * emit)123 fixup_draw_state(struct fd_context *ctx, struct fd6_emit *emit) assert_dt
124 {
125    if (ctx->last.dirty ||
126        (ctx->last.primitive_restart != emit->primitive_restart)) {
127       /* rasterizer state is effected by primitive-restart: */
128       fd_context_dirty(ctx, FD_DIRTY_RASTERIZER);
129       ctx->last.primitive_restart = emit->primitive_restart;
130    }
131 }
132 
133 static bool
fd6_draw_vbo(struct fd_context * ctx,const struct pipe_draw_info * info,unsigned drawid_offset,const struct pipe_draw_indirect_info * indirect,const struct pipe_draw_start_count_bias * draw,unsigned index_offset)134 fd6_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
135              unsigned drawid_offset,
136              const struct pipe_draw_indirect_info *indirect,
137              const struct pipe_draw_start_count_bias *draw,
138              unsigned index_offset) assert_dt
139 {
140    struct fd6_context *fd6_ctx = fd6_context(ctx);
141    struct shader_info *gs_info = ir3_get_shader_info(ctx->prog.gs);
142    struct fd6_emit emit = {
143       .ctx = ctx,
144       .vtx = &ctx->vtx,
145       .info = info,
146       .drawid_offset = drawid_offset,
147       .indirect = indirect,
148       .draw = draw,
149       .key = {
150          .vs = ctx->prog.vs,
151          .gs = ctx->prog.gs,
152          .fs = ctx->prog.fs,
153          .key = {
154             .rasterflat = ctx->rasterizer->flatshade,
155             .layer_zero = !gs_info || !(gs_info->outputs_written & VARYING_BIT_LAYER),
156             .sample_shading = (ctx->min_samples > 1),
157             .msaa = (ctx->framebuffer.samples > 1),
158          },
159       },
160       .rasterflat = ctx->rasterizer->flatshade,
161       .sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
162       .sprite_coord_mode = ctx->rasterizer->sprite_coord_mode,
163       .primitive_restart = info->primitive_restart && info->index_size,
164       .patch_vertices = ctx->patch_vertices,
165    };
166 
167    if (!(ctx->prog.vs && ctx->prog.fs))
168       return false;
169 
170    if (info->mode == PIPE_PRIM_PATCHES) {
171       emit.key.hs = ctx->prog.hs;
172       emit.key.ds = ctx->prog.ds;
173 
174       if (!(ctx->prog.hs && ctx->prog.ds))
175          return false;
176 
177       struct shader_info *ds_info = ir3_get_shader_info(emit.key.ds);
178       emit.key.key.tessellation = ir3_tess_mode(ds_info->tess.primitive_mode);
179       ctx->gen_dirty |= BIT(FD6_GROUP_PRIMITIVE_PARAMS);
180 
181       struct shader_info *fs_info = ir3_get_shader_info(emit.key.fs);
182       emit.key.key.tcs_store_primid =
183          BITSET_TEST(ds_info->system_values_read, SYSTEM_VALUE_PRIMITIVE_ID) ||
184          (gs_info && BITSET_TEST(gs_info->system_values_read, SYSTEM_VALUE_PRIMITIVE_ID)) ||
185          (fs_info && (fs_info->inputs_read & (1ull << VARYING_SLOT_PRIMITIVE_ID)));
186    }
187 
188    if (emit.key.gs) {
189       emit.key.key.has_gs = true;
190       ctx->gen_dirty |= BIT(FD6_GROUP_PRIMITIVE_PARAMS);
191    }
192 
193    if (!(emit.key.hs || emit.key.ds || emit.key.gs || indirect))
194       fd6_vsc_update_sizes(ctx->batch, info, draw);
195 
196    ir3_fixup_shader_state(&ctx->base, &emit.key.key);
197 
198    if (!(ctx->dirty & FD_DIRTY_PROG)) {
199       emit.prog = fd6_ctx->prog;
200    } else {
201       fd6_ctx->prog = fd6_emit_get_prog(&emit);
202    }
203 
204    /* bail if compile failed: */
205    if (!fd6_ctx->prog)
206       return false;
207 
208    fixup_draw_state(ctx, &emit);
209 
210    /* *after* fixup_shader_state(): */
211    emit.dirty = ctx->dirty;
212    emit.dirty_groups = ctx->gen_dirty;
213 
214    emit.bs = fd6_emit_get_prog(&emit)->bs;
215    emit.vs = fd6_emit_get_prog(&emit)->vs;
216    emit.hs = fd6_emit_get_prog(&emit)->hs;
217    emit.ds = fd6_emit_get_prog(&emit)->ds;
218    emit.gs = fd6_emit_get_prog(&emit)->gs;
219    emit.fs = fd6_emit_get_prog(&emit)->fs;
220 
221    if (emit.vs->need_driver_params || fd6_ctx->has_dp_state)
222       emit.dirty_groups |= BIT(FD6_GROUP_VS_DRIVER_PARAMS);
223 
224    /* If we are doing xfb, we need to emit the xfb state on every draw: */
225    if (emit.prog->stream_output)
226       emit.dirty_groups |= BIT(FD6_GROUP_SO);
227 
228    if (unlikely(ctx->stats_users > 0)) {
229       ctx->stats.vs_regs += ir3_shader_halfregs(emit.vs);
230       ctx->stats.hs_regs += COND(emit.hs, ir3_shader_halfregs(emit.hs));
231       ctx->stats.ds_regs += COND(emit.ds, ir3_shader_halfregs(emit.ds));
232       ctx->stats.gs_regs += COND(emit.gs, ir3_shader_halfregs(emit.gs));
233       ctx->stats.fs_regs += ir3_shader_halfregs(emit.fs);
234    }
235 
236    struct fd_ringbuffer *ring = ctx->batch->draw;
237 
238    struct CP_DRAW_INDX_OFFSET_0 draw0 = {
239       .prim_type = ctx->screen->primtypes[info->mode],
240       .vis_cull = USE_VISIBILITY,
241       .gs_enable = !!emit.key.gs,
242    };
243 
244    if (indirect && indirect->count_from_stream_output) {
245       draw0.source_select = DI_SRC_SEL_AUTO_XFB;
246    } else if (info->index_size) {
247       draw0.source_select = DI_SRC_SEL_DMA;
248       draw0.index_size = fd4_size2indextype(info->index_size);
249    } else {
250       draw0.source_select = DI_SRC_SEL_AUTO_INDEX;
251    }
252 
253    if (info->mode == PIPE_PRIM_PATCHES) {
254       shader_info *ds_info = &emit.ds->shader->nir->info;
255       uint32_t factor_stride;
256 
257       switch (ds_info->tess.primitive_mode) {
258       case GL_ISOLINES:
259          draw0.patch_type = TESS_ISOLINES;
260          factor_stride = 12;
261          break;
262       case GL_TRIANGLES:
263          draw0.patch_type = TESS_TRIANGLES;
264          factor_stride = 20;
265          break;
266       case GL_QUADS:
267          draw0.patch_type = TESS_QUADS;
268          factor_stride = 28;
269          break;
270       default:
271          unreachable("bad tessmode");
272       }
273 
274       draw0.prim_type = DI_PT_PATCHES0 + ctx->patch_vertices;
275       draw0.tess_enable = true;
276 
277       const unsigned max_count = 2048;
278       unsigned count;
279 
280       /**
281        * We can cap tessparam/tessfactor buffer sizes at the sub-draw
282        * limit.  But in the indirect-draw case we must assume the worst.
283        */
284       if (indirect && indirect->buffer) {
285          count = ALIGN_NPOT(max_count, ctx->patch_vertices);
286       } else {
287          count = MIN2(max_count, draw->count);
288          count = ALIGN_NPOT(count, ctx->patch_vertices);
289       }
290 
291       OUT_PKT7(ring, CP_SET_SUBDRAW_SIZE, 1);
292       OUT_RING(ring, count);
293 
294       ctx->batch->tessellation = true;
295       ctx->batch->tessparam_size =
296          MAX2(ctx->batch->tessparam_size, emit.hs->output_size * 4 * count);
297       ctx->batch->tessfactor_size =
298          MAX2(ctx->batch->tessfactor_size, factor_stride * count);
299 
300       if (!ctx->batch->tess_addrs_constobj) {
301          /* Reserve space for the bo address - we'll write them later in
302           * setup_tess_buffers().  We need 2 bo address, but indirect
303           * constant upload needs at least 4 vec4s.
304           */
305          unsigned size = 4 * 16;
306 
307          ctx->batch->tess_addrs_constobj = fd_submit_new_ringbuffer(
308             ctx->batch->submit, size, FD_RINGBUFFER_STREAMING);
309 
310          ctx->batch->tess_addrs_constobj->cur += size;
311       }
312    }
313 
314 	uint32_t index_start = info->index_size ? draw->index_bias : draw->start;
315    if (ctx->last.dirty || (ctx->last.index_start != index_start)) {
316       OUT_PKT4(ring, REG_A6XX_VFD_INDEX_OFFSET, 1);
317       OUT_RING(ring, index_start); /* VFD_INDEX_OFFSET */
318       ctx->last.index_start = index_start;
319    }
320 
321    if (ctx->last.dirty || (ctx->last.instance_start != info->start_instance)) {
322       OUT_PKT4(ring, REG_A6XX_VFD_INSTANCE_START_OFFSET, 1);
323       OUT_RING(ring, info->start_instance); /* VFD_INSTANCE_START_OFFSET */
324       ctx->last.instance_start = info->start_instance;
325    }
326 
327    uint32_t restart_index =
328       info->primitive_restart ? info->restart_index : 0xffffffff;
329    if (ctx->last.dirty || (ctx->last.restart_index != restart_index)) {
330       OUT_PKT4(ring, REG_A6XX_PC_RESTART_INDEX, 1);
331       OUT_RING(ring, restart_index); /* PC_RESTART_INDEX */
332       ctx->last.restart_index = restart_index;
333    }
334 
335    // TODO move fd6_emit_streamout.. I think..
336    if (emit.dirty_groups)
337       fd6_emit_state(ring, &emit);
338 
339    /* for debug after a lock up, write a unique counter value
340     * to scratch7 for each draw, to make it easier to match up
341     * register dumps to cmdstream.  The combination of IB
342     * (scratch6) and DRAW is enough to "triangulate" the
343     * particular draw that caused lockup.
344     */
345    emit_marker6(ring, 7);
346 
347    if (indirect) {
348       if (indirect->count_from_stream_output) {
349          draw_emit_xfb(ring, &draw0, info, indirect);
350       } else {
351          draw_emit_indirect(ring, &draw0, info, indirect, index_offset);
352       }
353    } else {
354       draw_emit(ring, &draw0, info, draw, index_offset);
355    }
356 
357    emit_marker6(ring, 7);
358    fd_reset_wfi(ctx->batch);
359 
360    if (emit.streamout_mask) {
361       struct fd_ringbuffer *ring = ctx->batch->draw;
362 
363       for (unsigned i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
364          if (emit.streamout_mask & (1 << i)) {
365             fd6_event_write(ctx->batch, ring, FLUSH_SO_0 + i, false);
366          }
367       }
368    }
369 
370    fd_context_all_clean(ctx);
371 
372    return true;
373 }
374 
375 static void
fd6_clear_lrz(struct fd_batch * batch,struct fd_resource * zsbuf,double depth)376 fd6_clear_lrz(struct fd_batch *batch, struct fd_resource *zsbuf, double depth) assert_dt
377 {
378    struct fd_ringbuffer *ring;
379    struct fd_screen *screen = batch->ctx->screen;
380 
381    ring = fd_batch_get_prologue(batch);
382 
383    emit_marker6(ring, 7);
384    OUT_PKT7(ring, CP_SET_MARKER, 1);
385    OUT_RING(ring, A6XX_CP_SET_MARKER_0_MODE(RM6_BYPASS));
386    emit_marker6(ring, 7);
387 
388    OUT_WFI5(ring);
389 
390    OUT_REG(ring, A6XX_RB_CCU_CNTL(.color_offset = screen->ccu_offset_bypass));
391 
392    OUT_REG(ring,
393            A6XX_HLSQ_INVALIDATE_CMD(.vs_state = true, .hs_state = true,
394                                     .ds_state = true, .gs_state = true,
395                                     .fs_state = true, .cs_state = true,
396                                     .gfx_ibo = true, .cs_ibo = true,
397                                     .gfx_shared_const = true,
398                                     .gfx_bindless = 0x1f, .cs_bindless = 0x1f));
399 
400    emit_marker6(ring, 7);
401    OUT_PKT7(ring, CP_SET_MARKER, 1);
402    OUT_RING(ring, A6XX_CP_SET_MARKER_0_MODE(RM6_BLIT2DSCALE));
403    emit_marker6(ring, 7);
404 
405    OUT_PKT4(ring, REG_A6XX_RB_2D_UNKNOWN_8C01, 1);
406    OUT_RING(ring, 0x0);
407 
408    OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);
409    OUT_RING(ring, 0x00000000);
410    OUT_RING(ring, 0x00000000);
411    OUT_RING(ring, 0x00000000);
412    OUT_RING(ring, 0x00000000);
413    OUT_RING(ring, 0x00000000);
414    OUT_RING(ring, 0x00000000);
415    OUT_RING(ring, 0x00000000);
416    OUT_RING(ring, 0x00000000);
417    OUT_RING(ring, 0x00000000);
418    OUT_RING(ring, 0x00000000);
419    OUT_RING(ring, 0x00000000);
420    OUT_RING(ring, 0x00000000);
421    OUT_RING(ring, 0x00000000);
422 
423    OUT_PKT4(ring, REG_A6XX_SP_2D_DST_FORMAT, 1);
424    OUT_RING(ring, 0x0000f410);
425 
426    OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);
427    OUT_RING(ring,
428             A6XX_GRAS_2D_BLIT_CNTL_COLOR_FORMAT(FMT6_16_UNORM) | 0x4f00080);
429 
430    OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);
431    OUT_RING(ring, A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(FMT6_16_UNORM) | 0x4f00080);
432 
433    fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
434    fd6_event_write(batch, ring, PC_CCU_INVALIDATE_COLOR, false);
435    fd_wfi(batch, ring);
436 
437    OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);
438    OUT_RING(ring, fui(depth));
439    OUT_RING(ring, 0x00000000);
440    OUT_RING(ring, 0x00000000);
441    OUT_RING(ring, 0x00000000);
442 
443    OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);
444    OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_16_UNORM) |
445                      A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |
446                      A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));
447    OUT_RELOC(ring, zsbuf->lrz, 0, 0, 0);
448    OUT_RING(ring, A6XX_RB_2D_DST_PITCH(zsbuf->lrz_pitch * 2).value);
449    OUT_RING(ring, 0x00000000);
450    OUT_RING(ring, 0x00000000);
451    OUT_RING(ring, 0x00000000);
452    OUT_RING(ring, 0x00000000);
453    OUT_RING(ring, 0x00000000);
454 
455    OUT_REG(ring, A6XX_GRAS_2D_SRC_TL_X(0), A6XX_GRAS_2D_SRC_BR_X(0),
456            A6XX_GRAS_2D_SRC_TL_Y(0), A6XX_GRAS_2D_SRC_BR_Y(0));
457 
458    OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);
459    OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));
460    OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(zsbuf->lrz_width - 1) |
461                      A6XX_GRAS_2D_DST_BR_Y(zsbuf->lrz_height - 1));
462 
463    fd6_event_write(batch, ring, 0x3f, false);
464 
465    OUT_WFI5(ring);
466 
467    OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
468    OUT_RING(ring, screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);
469 
470    OUT_PKT7(ring, CP_BLIT, 1);
471    OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));
472 
473    OUT_WFI5(ring);
474 
475    OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);
476    OUT_RING(ring, 0x0); /* RB_UNKNOWN_8E04 */
477 
478    fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);
479    fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);
480    fd6_event_write(batch, ring, CACHE_FLUSH_TS, true);
481    fd_wfi(batch, ring);
482 
483    fd6_cache_inv(batch, ring);
484 }
485 
486 static bool
is_z32(enum pipe_format format)487 is_z32(enum pipe_format format)
488 {
489    switch (format) {
490    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
491    case PIPE_FORMAT_Z32_UNORM:
492    case PIPE_FORMAT_Z32_FLOAT:
493       return true;
494    default:
495       return false;
496    }
497 }
498 
499 static bool
fd6_clear(struct fd_context * ctx,unsigned buffers,const union pipe_color_union * color,double depth,unsigned stencil)500 fd6_clear(struct fd_context *ctx, unsigned buffers,
501           const union pipe_color_union *color, double depth,
502           unsigned stencil) assert_dt
503 {
504    struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
505    const bool has_depth = pfb->zsbuf;
506    unsigned color_buffers = buffers >> 2;
507 
508    /* we need to do multisample clear on 3d pipe, so fallback to u_blitter: */
509    if (pfb->samples > 1)
510       return false;
511 
512    /* If we're clearing after draws, fallback to 3D pipe clears.  We could
513     * use blitter clears in the draw batch but then we'd have to patch up the
514     * gmem offsets. This doesn't seem like a useful thing to optimize for
515     * however.*/
516    if (ctx->batch->num_draws > 0)
517       return false;
518 
519    u_foreach_bit (i, color_buffers)
520       ctx->batch->clear_color[i] = *color;
521    if (buffers & PIPE_CLEAR_DEPTH)
522       ctx->batch->clear_depth = depth;
523    if (buffers & PIPE_CLEAR_STENCIL)
524       ctx->batch->clear_stencil = stencil;
525 
526    ctx->batch->fast_cleared |= buffers;
527 
528    if (has_depth && (buffers & PIPE_CLEAR_DEPTH)) {
529       struct fd_resource *zsbuf = fd_resource(pfb->zsbuf->texture);
530       if (zsbuf->lrz && !is_z32(pfb->zsbuf->format)) {
531          zsbuf->lrz_valid = true;
532          zsbuf->lrz_direction = FD_LRZ_UNKNOWN;
533          fd6_clear_lrz(ctx->batch, zsbuf, depth);
534       }
535    }
536 
537    return true;
538 }
539 
540 void
fd6_draw_init(struct pipe_context * pctx)541 fd6_draw_init(struct pipe_context *pctx) disable_thread_safety_analysis
542 {
543    struct fd_context *ctx = fd_context(pctx);
544    ctx->draw_vbo = fd6_draw_vbo;
545    ctx->clear = fd6_clear;
546 }
547