1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2012-2013 Rob Clark <robclark@freedesktop.org> 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "pipe/p_state.h" 28bf215546Sopenharmony_ci#include "util/u_memory.h" 29bf215546Sopenharmony_ci#include "util/u_prim.h" 30bf215546Sopenharmony_ci#include "util/u_string.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "freedreno_resource.h" 33bf215546Sopenharmony_ci#include "freedreno_state.h" 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#include "fd2_context.h" 36bf215546Sopenharmony_ci#include "fd2_draw.h" 37bf215546Sopenharmony_ci#include "fd2_emit.h" 38bf215546Sopenharmony_ci#include "fd2_program.h" 39bf215546Sopenharmony_ci#include "fd2_util.h" 40bf215546Sopenharmony_ci#include "fd2_zsa.h" 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistatic void 43bf215546Sopenharmony_ciemit_cacheflush(struct fd_ringbuffer *ring) 44bf215546Sopenharmony_ci{ 45bf215546Sopenharmony_ci unsigned i; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci for (i = 0; i < 12; i++) { 48bf215546Sopenharmony_ci OUT_PKT3(ring, CP_EVENT_WRITE, 1); 49bf215546Sopenharmony_ci OUT_RING(ring, CACHE_FLUSH); 50bf215546Sopenharmony_ci } 51bf215546Sopenharmony_ci} 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_cistatic void 54bf215546Sopenharmony_ciemit_vertexbufs(struct fd_context *ctx) assert_dt 55bf215546Sopenharmony_ci{ 56bf215546Sopenharmony_ci struct fd_vertex_stateobj *vtx = ctx->vtx.vtx; 57bf215546Sopenharmony_ci struct fd_vertexbuf_stateobj *vertexbuf = &ctx->vtx.vertexbuf; 58bf215546Sopenharmony_ci struct fd2_vertex_buf bufs[PIPE_MAX_ATTRIBS]; 59bf215546Sopenharmony_ci unsigned i; 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci if (!vtx->num_elements) 62bf215546Sopenharmony_ci return; 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci for (i = 0; i < vtx->num_elements; i++) { 65bf215546Sopenharmony_ci struct pipe_vertex_element *elem = &vtx->pipe[i]; 66bf215546Sopenharmony_ci struct pipe_vertex_buffer *vb = &vertexbuf->vb[elem->vertex_buffer_index]; 67bf215546Sopenharmony_ci bufs[i].offset = vb->buffer_offset; 68bf215546Sopenharmony_ci bufs[i].size = fd_bo_size(fd_resource(vb->buffer.resource)->bo); 69bf215546Sopenharmony_ci bufs[i].prsc = vb->buffer.resource; 70bf215546Sopenharmony_ci } 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci // NOTE I believe the 0x78 (or 0x9c in solid_vp) relates to the 73bf215546Sopenharmony_ci // CONST(20,0) (or CONST(26,0) in soliv_vp) 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci fd2_emit_vertex_bufs(ctx->batch->draw, 0x78, bufs, vtx->num_elements); 76bf215546Sopenharmony_ci fd2_emit_vertex_bufs(ctx->batch->binning, 0x78, bufs, vtx->num_elements); 77bf215546Sopenharmony_ci} 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_cistatic void 80bf215546Sopenharmony_cidraw_impl(struct fd_context *ctx, const struct pipe_draw_info *info, 81bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw, struct fd_ringbuffer *ring, 82bf215546Sopenharmony_ci unsigned index_offset, bool binning) assert_dt 83bf215546Sopenharmony_ci{ 84bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 85bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_INDX_OFFSET)); 86bf215546Sopenharmony_ci OUT_RING(ring, info->index_size ? 0 : draw->start); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci OUT_PKT0(ring, REG_A2XX_TC_CNTL_STATUS, 1); 89bf215546Sopenharmony_ci OUT_RING(ring, A2XX_TC_CNTL_STATUS_L2_INVALIDATE); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci if (is_a20x(ctx->screen)) { 92bf215546Sopenharmony_ci /* wait for DMA to finish and 93bf215546Sopenharmony_ci * dummy draw one triangle with indexes 0,0,0. 94bf215546Sopenharmony_ci * with PRE_FETCH_CULL_ENABLE | GRP_CULL_ENABLE. 95bf215546Sopenharmony_ci * 96bf215546Sopenharmony_ci * this workaround is for a HW bug related to DMA alignment: 97bf215546Sopenharmony_ci * it is necessary for indexed draws and possibly also 98bf215546Sopenharmony_ci * draws that read binning data 99bf215546Sopenharmony_ci */ 100bf215546Sopenharmony_ci OUT_PKT3(ring, CP_WAIT_REG_EQ, 4); 101bf215546Sopenharmony_ci OUT_RING(ring, 0x000005d0); /* RBBM_STATUS */ 102bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 103bf215546Sopenharmony_ci OUT_RING(ring, 0x00001000); /* bit: 12: VGT_BUSY_NO_DMA */ 104bf215546Sopenharmony_ci OUT_RING(ring, 0x00000001); 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci OUT_PKT3(ring, CP_DRAW_INDX_BIN, 6); 107bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 108bf215546Sopenharmony_ci OUT_RING(ring, 0x0003c004); 109bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 110bf215546Sopenharmony_ci OUT_RING(ring, 0x00000003); 111bf215546Sopenharmony_ci OUT_RELOC(ring, fd_resource(fd2_context(ctx)->solid_vertexbuf)->bo, 64, 0, 112bf215546Sopenharmony_ci 0); 113bf215546Sopenharmony_ci OUT_RING(ring, 0x00000006); 114bf215546Sopenharmony_ci } else { 115bf215546Sopenharmony_ci OUT_WFI(ring); 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 118bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_MAX_VTX_INDX)); 119bf215546Sopenharmony_ci OUT_RING(ring, info->index_bounds_valid ? info->max_index 120bf215546Sopenharmony_ci : ~0); /* VGT_MAX_VTX_INDX */ 121bf215546Sopenharmony_ci OUT_RING(ring, info->index_bounds_valid ? info->min_index 122bf215546Sopenharmony_ci : 0); /* VGT_MIN_VTX_INDX */ 123bf215546Sopenharmony_ci } 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci /* binning shader will take offset from C64 */ 126bf215546Sopenharmony_ci if (binning && is_a20x(ctx->screen)) { 127bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 5); 128bf215546Sopenharmony_ci OUT_RING(ring, 0x00000180); 129bf215546Sopenharmony_ci OUT_RING(ring, fui(ctx->batch->num_vertices)); 130bf215546Sopenharmony_ci OUT_RING(ring, fui(0.0f)); 131bf215546Sopenharmony_ci OUT_RING(ring, fui(0.0f)); 132bf215546Sopenharmony_ci OUT_RING(ring, fui(0.0f)); 133bf215546Sopenharmony_ci } 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci enum pc_di_vis_cull_mode vismode = USE_VISIBILITY; 136bf215546Sopenharmony_ci if (binning || info->mode == PIPE_PRIM_POINTS) 137bf215546Sopenharmony_ci vismode = IGNORE_VISIBILITY; 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci fd_draw_emit(ctx->batch, ring, ctx->screen->primtypes[info->mode], 140bf215546Sopenharmony_ci vismode, info, draw, index_offset); 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci if (is_a20x(ctx->screen)) { 143bf215546Sopenharmony_ci /* not sure why this is required, but it fixes some hangs */ 144bf215546Sopenharmony_ci OUT_WFI(ring); 145bf215546Sopenharmony_ci } else { 146bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 147bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_UNKNOWN_2010)); 148bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 149bf215546Sopenharmony_ci } 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_ci emit_cacheflush(ring); 152bf215546Sopenharmony_ci} 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_cistatic bool 155bf215546Sopenharmony_cifd2_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *pinfo, 156bf215546Sopenharmony_ci unsigned drawid_offset, 157bf215546Sopenharmony_ci const struct pipe_draw_indirect_info *indirect, 158bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *pdraw, 159bf215546Sopenharmony_ci unsigned index_offset) assert_dt 160bf215546Sopenharmony_ci{ 161bf215546Sopenharmony_ci if (!ctx->prog.fs || !ctx->prog.vs) 162bf215546Sopenharmony_ci return false; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci if (pinfo->mode != PIPE_PRIM_MAX && !indirect && !pinfo->primitive_restart && 165bf215546Sopenharmony_ci !u_trim_pipe_prim(pinfo->mode, (unsigned *)&pdraw->count)) 166bf215546Sopenharmony_ci return false; 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_ci if (ctx->dirty & FD_DIRTY_VTXBUF) 169bf215546Sopenharmony_ci emit_vertexbufs(ctx); 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci if (fd_binning_enabled) 172bf215546Sopenharmony_ci fd2_emit_state_binning(ctx, ctx->dirty); 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci fd2_emit_state(ctx, ctx->dirty); 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci /* a2xx can draw only 65535 vertices at once 177bf215546Sopenharmony_ci * on a22x the field in the draw command is 32bits but seems limited too 178bf215546Sopenharmony_ci * using a limit of 32k because it fixes an unexplained hang 179bf215546Sopenharmony_ci * 32766 works for all primitives (multiple of 2 and 3) 180bf215546Sopenharmony_ci */ 181bf215546Sopenharmony_ci if (pdraw->count > 32766) { 182bf215546Sopenharmony_ci /* clang-format off */ 183bf215546Sopenharmony_ci static const uint16_t step_tbl[PIPE_PRIM_MAX] = { 184bf215546Sopenharmony_ci [0 ... PIPE_PRIM_MAX - 1] = 32766, 185bf215546Sopenharmony_ci [PIPE_PRIM_LINE_STRIP] = 32765, 186bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_STRIP] = 32764, 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_ci /* needs more work */ 189bf215546Sopenharmony_ci [PIPE_PRIM_TRIANGLE_FAN] = 0, 190bf215546Sopenharmony_ci [PIPE_PRIM_LINE_LOOP] = 0, 191bf215546Sopenharmony_ci }; 192bf215546Sopenharmony_ci /* clang-format on */ 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci struct pipe_draw_start_count_bias draw = *pdraw; 195bf215546Sopenharmony_ci unsigned count = draw.count; 196bf215546Sopenharmony_ci unsigned step = step_tbl[pinfo->mode]; 197bf215546Sopenharmony_ci unsigned num_vertices = ctx->batch->num_vertices; 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci if (!step) 200bf215546Sopenharmony_ci return false; 201bf215546Sopenharmony_ci 202bf215546Sopenharmony_ci for (; count + step > 32766; count -= step) { 203bf215546Sopenharmony_ci draw.count = MIN2(count, 32766); 204bf215546Sopenharmony_ci draw_impl(ctx, pinfo, &draw, ctx->batch->draw, index_offset, false); 205bf215546Sopenharmony_ci draw_impl(ctx, pinfo, &draw, ctx->batch->binning, index_offset, true); 206bf215546Sopenharmony_ci draw.start += step; 207bf215546Sopenharmony_ci ctx->batch->num_vertices += step; 208bf215546Sopenharmony_ci } 209bf215546Sopenharmony_ci /* changing this value is a hack, restore it */ 210bf215546Sopenharmony_ci ctx->batch->num_vertices = num_vertices; 211bf215546Sopenharmony_ci } else { 212bf215546Sopenharmony_ci draw_impl(ctx, pinfo, pdraw, ctx->batch->draw, index_offset, false); 213bf215546Sopenharmony_ci draw_impl(ctx, pinfo, pdraw, ctx->batch->binning, index_offset, true); 214bf215546Sopenharmony_ci } 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci fd_context_all_clean(ctx); 217bf215546Sopenharmony_ci 218bf215546Sopenharmony_ci return true; 219bf215546Sopenharmony_ci} 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_cistatic void 222bf215546Sopenharmony_ciclear_state(struct fd_batch *batch, struct fd_ringbuffer *ring, 223bf215546Sopenharmony_ci unsigned buffers, bool fast_clear) assert_dt 224bf215546Sopenharmony_ci{ 225bf215546Sopenharmony_ci struct fd_context *ctx = batch->ctx; 226bf215546Sopenharmony_ci struct fd2_context *fd2_ctx = fd2_context(ctx); 227bf215546Sopenharmony_ci uint32_t reg; 228bf215546Sopenharmony_ci 229bf215546Sopenharmony_ci fd2_emit_vertex_bufs(ring, 0x9c, 230bf215546Sopenharmony_ci (struct fd2_vertex_buf[]){ 231bf215546Sopenharmony_ci {.prsc = fd2_ctx->solid_vertexbuf, .size = 36}, 232bf215546Sopenharmony_ci }, 233bf215546Sopenharmony_ci 1); 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 236bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_INDX_OFFSET)); 237bf215546Sopenharmony_ci OUT_RING(ring, 0); 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci fd2_program_emit(ctx, ring, &ctx->solid_prog); 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci OUT_PKT0(ring, REG_A2XX_TC_CNTL_STATUS, 1); 242bf215546Sopenharmony_ci OUT_RING(ring, A2XX_TC_CNTL_STATUS_L2_INVALIDATE); 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci if (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) { 245bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 246bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTHCONTROL)); 247bf215546Sopenharmony_ci reg = 0; 248bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_DEPTH) { 249bf215546Sopenharmony_ci reg |= A2XX_RB_DEPTHCONTROL_ZFUNC(FUNC_ALWAYS) | 250bf215546Sopenharmony_ci A2XX_RB_DEPTHCONTROL_Z_ENABLE | 251bf215546Sopenharmony_ci A2XX_RB_DEPTHCONTROL_Z_WRITE_ENABLE | 252bf215546Sopenharmony_ci A2XX_RB_DEPTHCONTROL_EARLY_Z_ENABLE; 253bf215546Sopenharmony_ci } 254bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_STENCIL) { 255bf215546Sopenharmony_ci reg |= A2XX_RB_DEPTHCONTROL_STENCILFUNC(FUNC_ALWAYS) | 256bf215546Sopenharmony_ci A2XX_RB_DEPTHCONTROL_STENCIL_ENABLE | 257bf215546Sopenharmony_ci A2XX_RB_DEPTHCONTROL_STENCILZPASS(STENCIL_REPLACE); 258bf215546Sopenharmony_ci } 259bf215546Sopenharmony_ci OUT_RING(ring, reg); 260bf215546Sopenharmony_ci } 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 263bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_COLORCONTROL)); 264bf215546Sopenharmony_ci OUT_RING(ring, A2XX_RB_COLORCONTROL_ALPHA_FUNC(FUNC_ALWAYS) | 265bf215546Sopenharmony_ci A2XX_RB_COLORCONTROL_BLEND_DISABLE | 266bf215546Sopenharmony_ci A2XX_RB_COLORCONTROL_ROP_CODE(12) | 267bf215546Sopenharmony_ci A2XX_RB_COLORCONTROL_DITHER_MODE(DITHER_DISABLE) | 268bf215546Sopenharmony_ci A2XX_RB_COLORCONTROL_DITHER_TYPE(DITHER_PIXEL)); 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 271bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_CLIP_CNTL)); 272bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* PA_CL_CLIP_CNTL */ 273bf215546Sopenharmony_ci OUT_RING( 274bf215546Sopenharmony_ci ring, 275bf215546Sopenharmony_ci A2XX_PA_SU_SC_MODE_CNTL_PROVOKING_VTX_LAST | /* PA_SU_SC_MODE_CNTL */ 276bf215546Sopenharmony_ci A2XX_PA_SU_SC_MODE_CNTL_FRONT_PTYPE(PC_DRAW_TRIANGLES) | 277bf215546Sopenharmony_ci A2XX_PA_SU_SC_MODE_CNTL_BACK_PTYPE(PC_DRAW_TRIANGLES) | 278bf215546Sopenharmony_ci (fast_clear ? A2XX_PA_SU_SC_MODE_CNTL_MSAA_ENABLE : 0)); 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci if (fast_clear) { 281bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 282bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_CONFIG)); 283bf215546Sopenharmony_ci OUT_RING(ring, A2XX_PA_SC_AA_CONFIG_MSAA_NUM_SAMPLES(3)); 284bf215546Sopenharmony_ci } 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 287bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_MASK)); 288bf215546Sopenharmony_ci OUT_RING(ring, 0x0000ffff); 289bf215546Sopenharmony_ci 290bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 291bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_COLOR_MASK)); 292bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_COLOR) { 293bf215546Sopenharmony_ci OUT_RING(ring, A2XX_RB_COLOR_MASK_WRITE_RED | 294bf215546Sopenharmony_ci A2XX_RB_COLOR_MASK_WRITE_GREEN | 295bf215546Sopenharmony_ci A2XX_RB_COLOR_MASK_WRITE_BLUE | 296bf215546Sopenharmony_ci A2XX_RB_COLOR_MASK_WRITE_ALPHA); 297bf215546Sopenharmony_ci } else { 298bf215546Sopenharmony_ci OUT_RING(ring, 0x0); 299bf215546Sopenharmony_ci } 300bf215546Sopenharmony_ci 301bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 302bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_BLEND_CONTROL)); 303bf215546Sopenharmony_ci OUT_RING(ring, 0); 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci if (is_a20x(batch->ctx->screen)) 306bf215546Sopenharmony_ci return; 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 309bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_MAX_VTX_INDX)); 310bf215546Sopenharmony_ci OUT_RING(ring, 3); /* VGT_MAX_VTX_INDX */ 311bf215546Sopenharmony_ci OUT_RING(ring, 0); /* VGT_MIN_VTX_INDX */ 312bf215546Sopenharmony_ci 313bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 314bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF)); 315bf215546Sopenharmony_ci OUT_RING(ring, 316bf215546Sopenharmony_ci 0xff000000 | A2XX_RB_STENCILREFMASK_BF_STENCILWRITEMASK(0xff)); 317bf215546Sopenharmony_ci OUT_RING(ring, 0xff000000 | A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff)); 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 320bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_A220_RB_LRZ_VSC_CONTROL)); 321bf215546Sopenharmony_ci OUT_RING(ring, 0x00000084); 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 324bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL)); 325bf215546Sopenharmony_ci OUT_RING(ring, 0x0000028f); 326bf215546Sopenharmony_ci} 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_cistatic void 329bf215546Sopenharmony_ciclear_state_restore(struct fd_context *ctx, struct fd_ringbuffer *ring) 330bf215546Sopenharmony_ci{ 331bf215546Sopenharmony_ci if (is_a20x(ctx->screen)) 332bf215546Sopenharmony_ci return; 333bf215546Sopenharmony_ci 334bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 335bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_CONTROL)); 336bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 339bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_A220_RB_LRZ_VSC_CONTROL)); 340bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 343bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_VGT_VERTEX_REUSE_BLOCK_CNTL)); 344bf215546Sopenharmony_ci OUT_RING(ring, 0x0000003b); 345bf215546Sopenharmony_ci} 346bf215546Sopenharmony_ci 347bf215546Sopenharmony_cistatic void 348bf215546Sopenharmony_ciclear_fast(struct fd_batch *batch, struct fd_ringbuffer *ring, 349bf215546Sopenharmony_ci uint32_t color_clear, uint32_t depth_clear, unsigned patch_type) 350bf215546Sopenharmony_ci{ 351bf215546Sopenharmony_ci BEGIN_RING(ring, 8); /* preallocate next 2 packets (for patching) */ 352bf215546Sopenharmony_ci 353bf215546Sopenharmony_ci /* zero values are patched in */ 354bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 355bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_SCREEN_SCISSOR_BR)); 356bf215546Sopenharmony_ci OUT_RINGP(ring, patch_type, &batch->gmem_patches); 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 4); 359bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_SURFACE_INFO)); 360bf215546Sopenharmony_ci OUT_RING(ring, 0x8000 | 32); 361bf215546Sopenharmony_ci OUT_RING(ring, 0); 362bf215546Sopenharmony_ci OUT_RING(ring, 0); 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ci /* set fill values */ 365bf215546Sopenharmony_ci if (!is_a20x(batch->ctx->screen)) { 366bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 367bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_CLEAR_COLOR)); 368bf215546Sopenharmony_ci OUT_RING(ring, color_clear); 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 371bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_CONTROL)); 372bf215546Sopenharmony_ci OUT_RING(ring, A2XX_RB_COPY_CONTROL_DEPTH_CLEAR_ENABLE | 373bf215546Sopenharmony_ci A2XX_RB_COPY_CONTROL_CLEAR_MASK(0xf)); 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 376bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTH_CLEAR)); 377bf215546Sopenharmony_ci OUT_RING(ring, depth_clear); 378bf215546Sopenharmony_ci } else { 379bf215546Sopenharmony_ci const float sc = 1.0f / 255.0f; 380bf215546Sopenharmony_ci 381bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 5); 382bf215546Sopenharmony_ci OUT_RING(ring, 0x00000480); 383bf215546Sopenharmony_ci OUT_RING(ring, fui((float)(color_clear >> 0 & 0xff) * sc)); 384bf215546Sopenharmony_ci OUT_RING(ring, fui((float)(color_clear >> 8 & 0xff) * sc)); 385bf215546Sopenharmony_ci OUT_RING(ring, fui((float)(color_clear >> 16 & 0xff) * sc)); 386bf215546Sopenharmony_ci OUT_RING(ring, fui((float)(color_clear >> 24 & 0xff) * sc)); 387bf215546Sopenharmony_ci 388bf215546Sopenharmony_ci // XXX if using float the rounding error breaks it.. 389bf215546Sopenharmony_ci float depth = ((double)(depth_clear >> 8)) * (1.0 / (double)0xffffff); 390bf215546Sopenharmony_ci assert((unsigned)(((double)depth * (double)0xffffff)) == 391bf215546Sopenharmony_ci (depth_clear >> 8)); 392bf215546Sopenharmony_ci 393bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 394bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_ZSCALE)); 395bf215546Sopenharmony_ci OUT_RING(ring, fui(0.0f)); 396bf215546Sopenharmony_ci OUT_RING(ring, fui(depth)); 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 399bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF)); 400bf215546Sopenharmony_ci OUT_RING(ring, 401bf215546Sopenharmony_ci 0xff000000 | 402bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_BF_STENCILREF(depth_clear & 0xff) | 403bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_BF_STENCILWRITEMASK(0xff)); 404bf215546Sopenharmony_ci OUT_RING(ring, 0xff000000 | 405bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_STENCILREF(depth_clear & 0xff) | 406bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff)); 407bf215546Sopenharmony_ci } 408bf215546Sopenharmony_ci 409bf215546Sopenharmony_ci fd_draw(batch, ring, DI_PT_RECTLIST, IGNORE_VISIBILITY, 410bf215546Sopenharmony_ci DI_SRC_SEL_AUTO_INDEX, 3, 0, INDEX_SIZE_IGN, 0, 0, NULL); 411bf215546Sopenharmony_ci} 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_cistatic bool 414bf215546Sopenharmony_cifd2_clear_fast(struct fd_context *ctx, unsigned buffers, 415bf215546Sopenharmony_ci const union pipe_color_union *color, double depth, 416bf215546Sopenharmony_ci unsigned stencil) assert_dt 417bf215546Sopenharmony_ci{ 418bf215546Sopenharmony_ci /* using 4x MSAA allows clearing ~2x faster 419bf215546Sopenharmony_ci * then we can use higher bpp clearing to clear lower bpp 420bf215546Sopenharmony_ci * 1 "pixel" can clear 64 bits (rgba8+depth24+stencil8) 421bf215546Sopenharmony_ci * note: its possible to clear with 32_32_32_32 format but its not faster 422bf215546Sopenharmony_ci * note: fast clear doesn't work with sysmem rendering 423bf215546Sopenharmony_ci * (sysmem rendering is disabled when clear is used) 424bf215546Sopenharmony_ci * 425bf215546Sopenharmony_ci * we only have 16-bit / 32-bit color formats 426bf215546Sopenharmony_ci * and 16-bit / 32-bit depth formats 427bf215546Sopenharmony_ci * so there are only a few possible combinations 428bf215546Sopenharmony_ci * 429bf215546Sopenharmony_ci * if the bpp of the color/depth doesn't match 430bf215546Sopenharmony_ci * we clear with depth/color individually 431bf215546Sopenharmony_ci */ 432bf215546Sopenharmony_ci struct fd2_context *fd2_ctx = fd2_context(ctx); 433bf215546Sopenharmony_ci struct fd_batch *batch = ctx->batch; 434bf215546Sopenharmony_ci struct fd_ringbuffer *ring = batch->draw; 435bf215546Sopenharmony_ci struct pipe_framebuffer_state *pfb = &batch->framebuffer; 436bf215546Sopenharmony_ci uint32_t color_clear = 0, depth_clear = 0; 437bf215546Sopenharmony_ci enum pipe_format format = pipe_surface_format(pfb->cbufs[0]); 438bf215546Sopenharmony_ci int depth_size = -1; /* -1: no clear, 0: clear 16-bit, 1: clear 32-bit */ 439bf215546Sopenharmony_ci int color_size = -1; 440bf215546Sopenharmony_ci 441bf215546Sopenharmony_ci /* TODO: need to test performance on a22x */ 442bf215546Sopenharmony_ci if (!is_a20x(ctx->screen)) 443bf215546Sopenharmony_ci return false; 444bf215546Sopenharmony_ci 445bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_COLOR) 446bf215546Sopenharmony_ci color_size = util_format_get_blocksizebits(format) == 32; 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci if (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) { 449bf215546Sopenharmony_ci /* no fast clear when clearing only one component of depth+stencil buffer */ 450bf215546Sopenharmony_ci if (!(buffers & PIPE_CLEAR_DEPTH)) 451bf215546Sopenharmony_ci return false; 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci if ((pfb->zsbuf->format == PIPE_FORMAT_Z24_UNORM_S8_UINT || 454bf215546Sopenharmony_ci pfb->zsbuf->format == PIPE_FORMAT_S8_UINT_Z24_UNORM) && 455bf215546Sopenharmony_ci !(buffers & PIPE_CLEAR_STENCIL)) 456bf215546Sopenharmony_ci return false; 457bf215546Sopenharmony_ci 458bf215546Sopenharmony_ci depth_size = fd_pipe2depth(pfb->zsbuf->format) == DEPTHX_24_8; 459bf215546Sopenharmony_ci } 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci assert(color_size >= 0 || depth_size >= 0); 462bf215546Sopenharmony_ci 463bf215546Sopenharmony_ci if (color_size == 0) { 464bf215546Sopenharmony_ci color_clear = pack_rgba(format, color->f); 465bf215546Sopenharmony_ci color_clear = (color_clear << 16) | (color_clear & 0xffff); 466bf215546Sopenharmony_ci } else if (color_size == 1) { 467bf215546Sopenharmony_ci color_clear = pack_rgba(format, color->f); 468bf215546Sopenharmony_ci } 469bf215546Sopenharmony_ci 470bf215546Sopenharmony_ci if (depth_size == 0) { 471bf215546Sopenharmony_ci depth_clear = (uint32_t)(0xffff * depth); 472bf215546Sopenharmony_ci depth_clear |= depth_clear << 16; 473bf215546Sopenharmony_ci } else if (depth_size == 1) { 474bf215546Sopenharmony_ci depth_clear = (((uint32_t)(0xffffff * depth)) << 8); 475bf215546Sopenharmony_ci depth_clear |= (stencil & 0xff); 476bf215546Sopenharmony_ci } 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_ci /* disable "window" scissor.. */ 479bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 480bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_SCISSOR_TL)); 481bf215546Sopenharmony_ci OUT_RING(ring, xy2d(0, 0)); 482bf215546Sopenharmony_ci OUT_RING(ring, xy2d(0x7fff, 0x7fff)); 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_ci /* make sure we fill all "pixels" (in SCREEN_SCISSOR) */ 485bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 5); 486bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_XSCALE)); 487bf215546Sopenharmony_ci OUT_RING(ring, fui(4096.0f)); 488bf215546Sopenharmony_ci OUT_RING(ring, fui(4096.0f)); 489bf215546Sopenharmony_ci OUT_RING(ring, fui(4096.0f)); 490bf215546Sopenharmony_ci OUT_RING(ring, fui(4096.0f)); 491bf215546Sopenharmony_ci 492bf215546Sopenharmony_ci clear_state(batch, ring, ~0u, true); 493bf215546Sopenharmony_ci 494bf215546Sopenharmony_ci if (color_size >= 0 && depth_size != color_size) 495bf215546Sopenharmony_ci clear_fast(batch, ring, color_clear, color_clear, 496bf215546Sopenharmony_ci GMEM_PATCH_FASTCLEAR_COLOR); 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_ci if (depth_size >= 0 && depth_size != color_size) 499bf215546Sopenharmony_ci clear_fast(batch, ring, depth_clear, depth_clear, 500bf215546Sopenharmony_ci GMEM_PATCH_FASTCLEAR_DEPTH); 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_ci if (depth_size == color_size) 503bf215546Sopenharmony_ci clear_fast(batch, ring, color_clear, depth_clear, 504bf215546Sopenharmony_ci GMEM_PATCH_FASTCLEAR_COLOR_DEPTH); 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_ci clear_state_restore(ctx, ring); 507bf215546Sopenharmony_ci 508bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 509bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_AA_CONFIG)); 510bf215546Sopenharmony_ci OUT_RING(ring, 0); 511bf215546Sopenharmony_ci 512bf215546Sopenharmony_ci /* can't patch in SCREEN_SCISSOR_BR as it can be different for each tile. 513bf215546Sopenharmony_ci * MEM_WRITE the value in tile_renderprep, and use CP_LOAD_CONSTANT_CONTEXT 514bf215546Sopenharmony_ci * the value is read from byte offset 60 in the given bo 515bf215546Sopenharmony_ci */ 516bf215546Sopenharmony_ci OUT_PKT3(ring, CP_LOAD_CONSTANT_CONTEXT, 3); 517bf215546Sopenharmony_ci OUT_RELOC(ring, fd_resource(fd2_ctx->solid_vertexbuf)->bo, 0, 0, 0); 518bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_SCREEN_SCISSOR_BR)); 519bf215546Sopenharmony_ci OUT_RING(ring, 1); 520bf215546Sopenharmony_ci 521bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 4); 522bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_SURFACE_INFO)); 523bf215546Sopenharmony_ci OUT_RINGP(ring, GMEM_PATCH_RESTORE_INFO, &batch->gmem_patches); 524bf215546Sopenharmony_ci OUT_RING(ring, 0); 525bf215546Sopenharmony_ci OUT_RING(ring, 0); 526bf215546Sopenharmony_ci return true; 527bf215546Sopenharmony_ci} 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_cistatic bool 530bf215546Sopenharmony_cifd2_clear(struct fd_context *ctx, unsigned buffers, 531bf215546Sopenharmony_ci const union pipe_color_union *color, double depth, 532bf215546Sopenharmony_ci unsigned stencil) assert_dt 533bf215546Sopenharmony_ci{ 534bf215546Sopenharmony_ci struct fd_ringbuffer *ring = ctx->batch->draw; 535bf215546Sopenharmony_ci struct pipe_framebuffer_state *fb = &ctx->batch->framebuffer; 536bf215546Sopenharmony_ci 537bf215546Sopenharmony_ci if (fd2_clear_fast(ctx, buffers, color, depth, stencil)) 538bf215546Sopenharmony_ci goto dirty; 539bf215546Sopenharmony_ci 540bf215546Sopenharmony_ci /* set clear value */ 541bf215546Sopenharmony_ci if (is_a20x(ctx->screen)) { 542bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_COLOR) { 543bf215546Sopenharmony_ci /* C0 used by fragment shader */ 544bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 5); 545bf215546Sopenharmony_ci OUT_RING(ring, 0x00000480); 546bf215546Sopenharmony_ci OUT_RING(ring, color->ui[0]); 547bf215546Sopenharmony_ci OUT_RING(ring, color->ui[1]); 548bf215546Sopenharmony_ci OUT_RING(ring, color->ui[2]); 549bf215546Sopenharmony_ci OUT_RING(ring, color->ui[3]); 550bf215546Sopenharmony_ci } 551bf215546Sopenharmony_ci 552bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_DEPTH) { 553bf215546Sopenharmony_ci /* use viewport to set depth value */ 554bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 555bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_ZSCALE)); 556bf215546Sopenharmony_ci OUT_RING(ring, fui(0.0f)); 557bf215546Sopenharmony_ci OUT_RING(ring, fui(depth)); 558bf215546Sopenharmony_ci } 559bf215546Sopenharmony_ci 560bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_STENCIL) { 561bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 562bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_STENCILREFMASK_BF)); 563bf215546Sopenharmony_ci OUT_RING(ring, 0xff000000 | 564bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_BF_STENCILREF(stencil) | 565bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_BF_STENCILWRITEMASK(0xff)); 566bf215546Sopenharmony_ci OUT_RING(ring, 0xff000000 | 567bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_STENCILREF(stencil) | 568bf215546Sopenharmony_ci A2XX_RB_STENCILREFMASK_STENCILWRITEMASK(0xff)); 569bf215546Sopenharmony_ci } 570bf215546Sopenharmony_ci } else { 571bf215546Sopenharmony_ci if (buffers & PIPE_CLEAR_COLOR) { 572bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 573bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_CLEAR_COLOR)); 574bf215546Sopenharmony_ci OUT_RING(ring, pack_rgba(PIPE_FORMAT_R8G8B8A8_UNORM, color->f)); 575bf215546Sopenharmony_ci } 576bf215546Sopenharmony_ci 577bf215546Sopenharmony_ci if (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) { 578bf215546Sopenharmony_ci uint32_t clear_mask, depth_clear; 579bf215546Sopenharmony_ci switch (fd_pipe2depth(fb->zsbuf->format)) { 580bf215546Sopenharmony_ci case DEPTHX_24_8: 581bf215546Sopenharmony_ci clear_mask = ((buffers & PIPE_CLEAR_DEPTH) ? 0xe : 0) | 582bf215546Sopenharmony_ci ((buffers & PIPE_CLEAR_STENCIL) ? 0x1 : 0); 583bf215546Sopenharmony_ci depth_clear = 584bf215546Sopenharmony_ci (((uint32_t)(0xffffff * depth)) << 8) | (stencil & 0xff); 585bf215546Sopenharmony_ci break; 586bf215546Sopenharmony_ci case DEPTHX_16: 587bf215546Sopenharmony_ci clear_mask = 0xf; 588bf215546Sopenharmony_ci depth_clear = (uint32_t)(0xffffffff * depth); 589bf215546Sopenharmony_ci break; 590bf215546Sopenharmony_ci default: 591bf215546Sopenharmony_ci unreachable("invalid depth"); 592bf215546Sopenharmony_ci break; 593bf215546Sopenharmony_ci } 594bf215546Sopenharmony_ci 595bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 596bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_COPY_CONTROL)); 597bf215546Sopenharmony_ci OUT_RING(ring, A2XX_RB_COPY_CONTROL_DEPTH_CLEAR_ENABLE | 598bf215546Sopenharmony_ci A2XX_RB_COPY_CONTROL_CLEAR_MASK(clear_mask)); 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 2); 601bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_RB_DEPTH_CLEAR)); 602bf215546Sopenharmony_ci OUT_RING(ring, depth_clear); 603bf215546Sopenharmony_ci } 604bf215546Sopenharmony_ci } 605bf215546Sopenharmony_ci 606bf215546Sopenharmony_ci /* scissor state */ 607bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 3); 608bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_SC_WINDOW_SCISSOR_TL)); 609bf215546Sopenharmony_ci OUT_RING(ring, xy2d(0, 0)); 610bf215546Sopenharmony_ci OUT_RING(ring, xy2d(fb->width, fb->height)); 611bf215546Sopenharmony_ci 612bf215546Sopenharmony_ci /* viewport state */ 613bf215546Sopenharmony_ci OUT_PKT3(ring, CP_SET_CONSTANT, 5); 614bf215546Sopenharmony_ci OUT_RING(ring, CP_REG(REG_A2XX_PA_CL_VPORT_XSCALE)); 615bf215546Sopenharmony_ci OUT_RING(ring, fui((float)fb->width / 2.0f)); 616bf215546Sopenharmony_ci OUT_RING(ring, fui((float)fb->width / 2.0f)); 617bf215546Sopenharmony_ci OUT_RING(ring, fui((float)fb->height / 2.0f)); 618bf215546Sopenharmony_ci OUT_RING(ring, fui((float)fb->height / 2.0f)); 619bf215546Sopenharmony_ci 620bf215546Sopenharmony_ci /* common state */ 621bf215546Sopenharmony_ci clear_state(ctx->batch, ring, buffers, false); 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci fd_draw(ctx->batch, ring, DI_PT_RECTLIST, IGNORE_VISIBILITY, 624bf215546Sopenharmony_ci DI_SRC_SEL_AUTO_INDEX, 3, 0, INDEX_SIZE_IGN, 0, 0, NULL); 625bf215546Sopenharmony_ci 626bf215546Sopenharmony_ci clear_state_restore(ctx, ring); 627bf215546Sopenharmony_ci 628bf215546Sopenharmony_cidirty: 629bf215546Sopenharmony_ci ctx->dirty |= FD_DIRTY_ZSA | FD_DIRTY_VIEWPORT | FD_DIRTY_RASTERIZER | 630bf215546Sopenharmony_ci FD_DIRTY_SAMPLE_MASK | FD_DIRTY_PROG | FD_DIRTY_CONST | 631bf215546Sopenharmony_ci FD_DIRTY_BLEND | FD_DIRTY_FRAMEBUFFER | FD_DIRTY_SCISSOR; 632bf215546Sopenharmony_ci 633bf215546Sopenharmony_ci ctx->dirty_shader[PIPE_SHADER_VERTEX] |= FD_DIRTY_SHADER_PROG; 634bf215546Sopenharmony_ci ctx->dirty_shader[PIPE_SHADER_FRAGMENT] |= 635bf215546Sopenharmony_ci FD_DIRTY_SHADER_PROG | FD_DIRTY_SHADER_CONST; 636bf215546Sopenharmony_ci 637bf215546Sopenharmony_ci return true; 638bf215546Sopenharmony_ci} 639bf215546Sopenharmony_ci 640bf215546Sopenharmony_civoid 641bf215546Sopenharmony_cifd2_draw_init(struct pipe_context *pctx) disable_thread_safety_analysis 642bf215546Sopenharmony_ci{ 643bf215546Sopenharmony_ci struct fd_context *ctx = fd_context(pctx); 644bf215546Sopenharmony_ci ctx->draw_vbo = fd2_draw_vbo; 645bf215546Sopenharmony_ci ctx->clear = fd2_clear; 646bf215546Sopenharmony_ci} 647