1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (C) 2016 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#ifndef FD5_EMIT_H 28bf215546Sopenharmony_ci#define FD5_EMIT_H 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "pipe/p_context.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "fd5_context.h" 33bf215546Sopenharmony_ci#include "fd5_format.h" 34bf215546Sopenharmony_ci#include "fd5_program.h" 35bf215546Sopenharmony_ci#include "fd5_screen.h" 36bf215546Sopenharmony_ci#include "freedreno_batch.h" 37bf215546Sopenharmony_ci#include "freedreno_context.h" 38bf215546Sopenharmony_ci#include "ir3_gallium.h" 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_cistruct fd_ringbuffer; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci/* grouped together emit-state for prog/vertex/state emit: */ 43bf215546Sopenharmony_cistruct fd5_emit { 44bf215546Sopenharmony_ci struct util_debug_callback *debug; 45bf215546Sopenharmony_ci const struct fd_vertex_state *vtx; 46bf215546Sopenharmony_ci const struct fd5_program_state *prog; 47bf215546Sopenharmony_ci const struct pipe_draw_info *info; 48bf215546Sopenharmony_ci unsigned drawid_offset; 49bf215546Sopenharmony_ci const struct pipe_draw_indirect_info *indirect; 50bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw; 51bf215546Sopenharmony_ci bool binning_pass; 52bf215546Sopenharmony_ci struct ir3_cache_key key; 53bf215546Sopenharmony_ci enum fd_dirty_3d_state dirty; 54bf215546Sopenharmony_ci 55bf215546Sopenharmony_ci uint32_t sprite_coord_enable; /* bitmask */ 56bf215546Sopenharmony_ci bool sprite_coord_mode; 57bf215546Sopenharmony_ci bool rasterflat; 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci /* in binning pass, we don't have real frag shader, so we 60bf215546Sopenharmony_ci * don't know if real draw disqualifies lrz write. So just 61bf215546Sopenharmony_ci * figure that out up-front and stash it in the emit. 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_ci bool no_lrz_write; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci /* cached to avoid repeated lookups of same variants: */ 66bf215546Sopenharmony_ci const struct ir3_shader_variant *vs, *fs; 67bf215546Sopenharmony_ci /* TODO: other shader stages.. */ 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci unsigned streamout_mask; 70bf215546Sopenharmony_ci}; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_cistatic inline enum a5xx_color_fmt 73bf215546Sopenharmony_cifd5_emit_format(struct pipe_surface *surf) 74bf215546Sopenharmony_ci{ 75bf215546Sopenharmony_ci if (!surf) 76bf215546Sopenharmony_ci return 0; 77bf215546Sopenharmony_ci return fd5_pipe2color(surf->format); 78bf215546Sopenharmony_ci} 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistatic inline const struct ir3_shader_variant * 81bf215546Sopenharmony_cifd5_emit_get_vp(struct fd5_emit *emit) 82bf215546Sopenharmony_ci{ 83bf215546Sopenharmony_ci if (!emit->vs) { 84bf215546Sopenharmony_ci /* We use nonbinning VS during binning when TFB is enabled because that 85bf215546Sopenharmony_ci * is what has all the outputs that might be involved in TFB. 86bf215546Sopenharmony_ci */ 87bf215546Sopenharmony_ci if (emit->binning_pass && 88bf215546Sopenharmony_ci !emit->prog->vs->stream_output.num_outputs) 89bf215546Sopenharmony_ci emit->vs = emit->prog->bs; 90bf215546Sopenharmony_ci else 91bf215546Sopenharmony_ci emit->vs = emit->prog->vs; 92bf215546Sopenharmony_ci } 93bf215546Sopenharmony_ci return emit->vs; 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_cistatic inline const struct ir3_shader_variant * 97bf215546Sopenharmony_cifd5_emit_get_fp(struct fd5_emit *emit) 98bf215546Sopenharmony_ci{ 99bf215546Sopenharmony_ci if (!emit->fs) { 100bf215546Sopenharmony_ci if (emit->binning_pass) { 101bf215546Sopenharmony_ci /* use dummy stateobj to simplify binning vs non-binning: */ 102bf215546Sopenharmony_ci static const struct ir3_shader_variant binning_fs = {}; 103bf215546Sopenharmony_ci emit->fs = &binning_fs; 104bf215546Sopenharmony_ci } else { 105bf215546Sopenharmony_ci emit->fs = emit->prog->fs; 106bf215546Sopenharmony_ci } 107bf215546Sopenharmony_ci } 108bf215546Sopenharmony_ci return emit->fs; 109bf215546Sopenharmony_ci} 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_cistatic inline void 112bf215546Sopenharmony_cifd5_cache_flush(struct fd_batch *batch, struct fd_ringbuffer *ring) assert_dt 113bf215546Sopenharmony_ci{ 114bf215546Sopenharmony_ci fd_reset_wfi(batch); 115bf215546Sopenharmony_ci OUT_PKT4(ring, REG_A5XX_UCHE_CACHE_INVALIDATE_MIN_LO, 5); 116bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* UCHE_CACHE_INVALIDATE_MIN_LO */ 117bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* UCHE_CACHE_INVALIDATE_MIN_HI */ 118bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* UCHE_CACHE_INVALIDATE_MAX_LO */ 119bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* UCHE_CACHE_INVALIDATE_MAX_HI */ 120bf215546Sopenharmony_ci OUT_RING(ring, 0x00000012); /* UCHE_CACHE_INVALIDATE */ 121bf215546Sopenharmony_ci fd_wfi(batch, ring); 122bf215546Sopenharmony_ci} 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_cistatic inline void 125bf215546Sopenharmony_cifd5_set_render_mode(struct fd_context *ctx, struct fd_ringbuffer *ring, 126bf215546Sopenharmony_ci enum render_mode_cmd mode) 127bf215546Sopenharmony_ci{ 128bf215546Sopenharmony_ci /* TODO add preemption support, gmem bypass, etc */ 129bf215546Sopenharmony_ci emit_marker5(ring, 7); 130bf215546Sopenharmony_ci OUT_PKT7(ring, CP_SET_RENDER_MODE, 5); 131bf215546Sopenharmony_ci OUT_RING(ring, CP_SET_RENDER_MODE_0_MODE(mode)); 132bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* ADDR_LO */ 133bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); /* ADDR_HI */ 134bf215546Sopenharmony_ci OUT_RING(ring, COND(mode == GMEM, CP_SET_RENDER_MODE_3_GMEM_ENABLE) | 135bf215546Sopenharmony_ci COND(mode == BINNING, CP_SET_RENDER_MODE_3_VSC_ENABLE)); 136bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 137bf215546Sopenharmony_ci emit_marker5(ring, 7); 138bf215546Sopenharmony_ci} 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_cistatic inline void 141bf215546Sopenharmony_cifd5_event_write(struct fd_batch *batch, struct fd_ringbuffer *ring, 142bf215546Sopenharmony_ci enum vgt_event_type evt, bool timestamp) 143bf215546Sopenharmony_ci{ 144bf215546Sopenharmony_ci OUT_PKT7(ring, CP_EVENT_WRITE, timestamp ? 4 : 1); 145bf215546Sopenharmony_ci OUT_RING(ring, CP_EVENT_WRITE_0_EVENT(evt)); 146bf215546Sopenharmony_ci if (timestamp) { 147bf215546Sopenharmony_ci OUT_RELOC(ring, fd5_context(batch->ctx)->blit_mem, 0, 0, 148bf215546Sopenharmony_ci 0); /* ADDR_LO/HI */ 149bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000); 150bf215546Sopenharmony_ci } 151bf215546Sopenharmony_ci} 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_cistatic inline void 154bf215546Sopenharmony_cifd5_emit_blit(struct fd_batch *batch, struct fd_ringbuffer *ring) 155bf215546Sopenharmony_ci{ 156bf215546Sopenharmony_ci emit_marker5(ring, 7); 157bf215546Sopenharmony_ci fd5_event_write(batch, ring, BLIT, true); 158bf215546Sopenharmony_ci emit_marker5(ring, 7); 159bf215546Sopenharmony_ci} 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_cistatic inline void 162bf215546Sopenharmony_cifd5_emit_render_cntl(struct fd_context *ctx, bool blit, bool binning) assert_dt 163bf215546Sopenharmony_ci{ 164bf215546Sopenharmony_ci struct fd_ringbuffer *ring = 165bf215546Sopenharmony_ci binning ? ctx->batch->binning : ctx->batch->draw; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci /* TODO eventually this partially depends on the pfb state, ie. 168bf215546Sopenharmony_ci * which of the cbuf(s)/zsbuf has an UBWC flag buffer.. that part 169bf215546Sopenharmony_ci * we could probably cache and just regenerate if framebuffer 170bf215546Sopenharmony_ci * state is dirty (or something like that).. 171bf215546Sopenharmony_ci * 172bf215546Sopenharmony_ci * Other bits seem to depend on query state, like if samples-passed 173bf215546Sopenharmony_ci * query is active. 174bf215546Sopenharmony_ci */ 175bf215546Sopenharmony_ci bool samples_passed = (fd5_context(ctx)->samples_passed_queries > 0); 176bf215546Sopenharmony_ci OUT_PKT4(ring, REG_A5XX_RB_RENDER_CNTL, 1); 177bf215546Sopenharmony_ci OUT_RING(ring, 0x00000000 | /* RB_RENDER_CNTL */ 178bf215546Sopenharmony_ci COND(binning, A5XX_RB_RENDER_CNTL_BINNING_PASS) | 179bf215546Sopenharmony_ci COND(binning, A5XX_RB_RENDER_CNTL_DISABLE_COLOR_PIPE) | 180bf215546Sopenharmony_ci COND(samples_passed, A5XX_RB_RENDER_CNTL_SAMPLES_PASSED) | 181bf215546Sopenharmony_ci COND(!blit, 0x8)); 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci OUT_PKT4(ring, REG_A5XX_GRAS_SC_CNTL, 1); 184bf215546Sopenharmony_ci OUT_RING(ring, 0x00000008 | /* GRAS_SC_CNTL */ 185bf215546Sopenharmony_ci COND(binning, A5XX_GRAS_SC_CNTL_BINNING_PASS) | 186bf215546Sopenharmony_ci COND(samples_passed, A5XX_GRAS_SC_CNTL_SAMPLES_PASSED)); 187bf215546Sopenharmony_ci} 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_cistatic inline void 190bf215546Sopenharmony_cifd5_emit_lrz_flush(struct fd_batch *batch, struct fd_ringbuffer *ring) 191bf215546Sopenharmony_ci{ 192bf215546Sopenharmony_ci /* TODO I think the extra writes to GRAS_LRZ_CNTL are probably 193bf215546Sopenharmony_ci * a workaround and not needed on all a5xx. 194bf215546Sopenharmony_ci */ 195bf215546Sopenharmony_ci OUT_PKT4(ring, REG_A5XX_GRAS_LRZ_CNTL, 1); 196bf215546Sopenharmony_ci OUT_RING(ring, A5XX_GRAS_LRZ_CNTL_ENABLE); 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci fd5_event_write(batch, ring, LRZ_FLUSH, false); 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci OUT_PKT4(ring, REG_A5XX_GRAS_LRZ_CNTL, 1); 201bf215546Sopenharmony_ci OUT_RING(ring, 0x0); 202bf215546Sopenharmony_ci} 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_civoid fd5_emit_vertex_bufs(struct fd_ringbuffer *ring, 205bf215546Sopenharmony_ci struct fd5_emit *emit) assert_dt; 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_civoid fd5_emit_state(struct fd_context *ctx, struct fd_ringbuffer *ring, 208bf215546Sopenharmony_ci struct fd5_emit *emit) assert_dt; 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_civoid fd5_emit_cs_state(struct fd_context *ctx, struct fd_ringbuffer *ring, 211bf215546Sopenharmony_ci struct ir3_shader_variant *cp) assert_dt; 212bf215546Sopenharmony_civoid fd5_emit_cs_consts(const struct ir3_shader_variant *v, 213bf215546Sopenharmony_ci struct fd_ringbuffer *ring, struct fd_context *ctx, 214bf215546Sopenharmony_ci const struct pipe_grid_info *info) assert_dt; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_civoid fd5_emit_restore(struct fd_batch *batch, 217bf215546Sopenharmony_ci struct fd_ringbuffer *ring) assert_dt; 218bf215546Sopenharmony_ci 219bf215546Sopenharmony_civoid fd5_emit_init_screen(struct pipe_screen *pscreen); 220bf215546Sopenharmony_civoid fd5_emit_init(struct pipe_context *pctx); 221bf215546Sopenharmony_ci 222bf215546Sopenharmony_cistatic inline void 223bf215546Sopenharmony_cifd5_emit_ib(struct fd_ringbuffer *ring, struct fd_ringbuffer *target) 224bf215546Sopenharmony_ci{ 225bf215546Sopenharmony_ci /* for debug after a lock up, write a unique counter value 226bf215546Sopenharmony_ci * to scratch6 for each IB, to make it easier to match up 227bf215546Sopenharmony_ci * register dumps to cmdstream. The combination of IB and 228bf215546Sopenharmony_ci * DRAW (scratch7) is enough to "triangulate" the particular 229bf215546Sopenharmony_ci * draw that caused lockup. 230bf215546Sopenharmony_ci */ 231bf215546Sopenharmony_ci emit_marker5(ring, 6); 232bf215546Sopenharmony_ci __OUT_IB5(ring, target); 233bf215546Sopenharmony_ci emit_marker5(ring, 6); 234bf215546Sopenharmony_ci} 235bf215546Sopenharmony_ci 236bf215546Sopenharmony_ci#endif /* FD5_EMIT_H */ 237