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_DRAW_H_ 28bf215546Sopenharmony_ci#define FD5_DRAW_H_ 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "pipe/p_context.h" 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "freedreno_draw.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "fd5_context.h" 35bf215546Sopenharmony_ci#include "fd5_screen.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci/* some bits in common w/ a4xx: */ 38bf215546Sopenharmony_ci#include "a4xx/fd4_draw.h" 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_civoid fd5_draw_init(struct pipe_context *pctx); 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_cistatic inline void 43bf215546Sopenharmony_cifd5_draw(struct fd_batch *batch, struct fd_ringbuffer *ring, 44bf215546Sopenharmony_ci enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode, 45bf215546Sopenharmony_ci enum pc_di_src_sel src_sel, uint32_t count, uint32_t instances, 46bf215546Sopenharmony_ci enum a4xx_index_size idx_type, uint32_t max_indices, 47bf215546Sopenharmony_ci uint32_t idx_offset, struct pipe_resource *idx_buffer) 48bf215546Sopenharmony_ci{ 49bf215546Sopenharmony_ci /* for debug after a lock up, write a unique counter value 50bf215546Sopenharmony_ci * to scratch7 for each draw, to make it easier to match up 51bf215546Sopenharmony_ci * register dumps to cmdstream. The combination of IB 52bf215546Sopenharmony_ci * (scratch6) and DRAW is enough to "triangulate" the 53bf215546Sopenharmony_ci * particular draw that caused lockup. 54bf215546Sopenharmony_ci */ 55bf215546Sopenharmony_ci emit_marker5(ring, 7); 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci OUT_PKT7(ring, CP_DRAW_INDX_OFFSET, idx_buffer ? 7 : 3); 58bf215546Sopenharmony_ci if (vismode == USE_VISIBILITY) { 59bf215546Sopenharmony_ci /* leave vis mode blank for now, it will be patched up when 60bf215546Sopenharmony_ci * we know if we are binning or not 61bf215546Sopenharmony_ci */ 62bf215546Sopenharmony_ci OUT_RINGP(ring, DRAW4(primtype, src_sel, idx_type, 0), 63bf215546Sopenharmony_ci &batch->draw_patches); 64bf215546Sopenharmony_ci } else { 65bf215546Sopenharmony_ci OUT_RING(ring, DRAW4(primtype, src_sel, idx_type, vismode)); 66bf215546Sopenharmony_ci } 67bf215546Sopenharmony_ci OUT_RING(ring, instances); /* NumInstances */ 68bf215546Sopenharmony_ci OUT_RING(ring, count); /* NumIndices */ 69bf215546Sopenharmony_ci if (idx_buffer) { 70bf215546Sopenharmony_ci OUT_RING(ring, 0x0); /* XXX */ 71bf215546Sopenharmony_ci OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0); 72bf215546Sopenharmony_ci OUT_RING(ring, max_indices); 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci emit_marker5(ring, 7); 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci fd_reset_wfi(batch); 78bf215546Sopenharmony_ci} 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_cistatic inline void 81bf215546Sopenharmony_cifd5_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring, 82bf215546Sopenharmony_ci enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode, 83bf215546Sopenharmony_ci const struct pipe_draw_info *info, 84bf215546Sopenharmony_ci const struct pipe_draw_indirect_info *indirect, 85bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw, unsigned index_offset) 86bf215546Sopenharmony_ci{ 87bf215546Sopenharmony_ci struct pipe_resource *idx_buffer = NULL; 88bf215546Sopenharmony_ci enum a4xx_index_size idx_type; 89bf215546Sopenharmony_ci enum pc_di_src_sel src_sel; 90bf215546Sopenharmony_ci uint32_t max_indices, idx_offset; 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ci if (indirect && indirect->buffer) { 93bf215546Sopenharmony_ci struct fd_resource *ind = fd_resource(indirect->buffer); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci emit_marker5(ring, 7); 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci if (info->index_size) { 98bf215546Sopenharmony_ci struct pipe_resource *idx = info->index.resource; 99bf215546Sopenharmony_ci max_indices = idx->width0 / info->index_size; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci OUT_PKT7(ring, CP_DRAW_INDX_INDIRECT, 6); 102bf215546Sopenharmony_ci OUT_RINGP(ring, 103bf215546Sopenharmony_ci DRAW4(primtype, DI_SRC_SEL_DMA, 104bf215546Sopenharmony_ci fd4_size2indextype(info->index_size), 0), 105bf215546Sopenharmony_ci &batch->draw_patches); 106bf215546Sopenharmony_ci OUT_RELOC(ring, fd_resource(idx)->bo, index_offset, 0, 0); 107bf215546Sopenharmony_ci OUT_RING(ring, A5XX_CP_DRAW_INDX_INDIRECT_3_MAX_INDICES(max_indices)); 108bf215546Sopenharmony_ci OUT_RELOC(ring, ind->bo, indirect->offset, 0, 0); 109bf215546Sopenharmony_ci } else { 110bf215546Sopenharmony_ci OUT_PKT7(ring, CP_DRAW_INDIRECT, 3); 111bf215546Sopenharmony_ci OUT_RINGP(ring, DRAW4(primtype, DI_SRC_SEL_AUTO_INDEX, 0, 0), 112bf215546Sopenharmony_ci &batch->draw_patches); 113bf215546Sopenharmony_ci OUT_RELOC(ring, ind->bo, indirect->offset, 0, 0); 114bf215546Sopenharmony_ci } 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci emit_marker5(ring, 7); 117bf215546Sopenharmony_ci fd_reset_wfi(batch); 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci return; 120bf215546Sopenharmony_ci } 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_ci if (info->index_size) { 123bf215546Sopenharmony_ci assert(!info->has_user_indices); 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci idx_buffer = info->index.resource; 126bf215546Sopenharmony_ci idx_type = fd4_size2indextype(info->index_size); 127bf215546Sopenharmony_ci max_indices = idx_buffer->width0 / info->index_size; 128bf215546Sopenharmony_ci idx_offset = index_offset + draw->start * info->index_size; 129bf215546Sopenharmony_ci src_sel = DI_SRC_SEL_DMA; 130bf215546Sopenharmony_ci } else { 131bf215546Sopenharmony_ci idx_buffer = NULL; 132bf215546Sopenharmony_ci idx_type = INDEX4_SIZE_32_BIT; 133bf215546Sopenharmony_ci max_indices = 0; 134bf215546Sopenharmony_ci idx_offset = 0; 135bf215546Sopenharmony_ci src_sel = DI_SRC_SEL_AUTO_INDEX; 136bf215546Sopenharmony_ci } 137bf215546Sopenharmony_ci 138bf215546Sopenharmony_ci fd5_draw(batch, ring, primtype, vismode, src_sel, draw->count, 139bf215546Sopenharmony_ci info->instance_count, idx_type, max_indices, idx_offset, 140bf215546Sopenharmony_ci idx_buffer); 141bf215546Sopenharmony_ci} 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ci#endif /* FD5_DRAW_H_ */ 144