Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a4xx/fd4_draw.h
4574 views
/*1* Copyright (C) 2014 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#ifndef FD4_DRAW_H_27#define FD4_DRAW_H_2829#include "pipe/p_context.h"3031#include "freedreno_draw.h"3233void fd4_draw_init(struct pipe_context *pctx);3435/* draw packet changed on a4xx, so cannot reuse one from a2xx/a3xx.. */3637static inline uint32_t38DRAW4(enum pc_di_primtype prim_type, enum pc_di_src_sel source_select,39enum a4xx_index_size index_size, enum pc_di_vis_cull_mode vis_cull_mode)40{41return CP_DRAW_INDX_OFFSET_0_PRIM_TYPE(prim_type) |42CP_DRAW_INDX_OFFSET_0_SOURCE_SELECT(source_select) |43CP_DRAW_INDX_OFFSET_0_INDEX_SIZE(index_size) |44CP_DRAW_INDX_OFFSET_0_VIS_CULL(vis_cull_mode);45}4647static inline void48fd4_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,49enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,50enum pc_di_src_sel src_sel, uint32_t count, uint32_t instances,51enum a4xx_index_size idx_type, uint32_t max_indices,52uint32_t idx_offset, struct pipe_resource *idx_buffer)53{54/* for debug after a lock up, write a unique counter value55* to scratch7 for each draw, to make it easier to match up56* register dumps to cmdstream. The combination of IB57* (scratch6) and DRAW is enough to "triangulate" the58* particular draw that caused lockup.59*/60emit_marker(ring, 7);6162OUT_PKT3(ring, CP_DRAW_INDX_OFFSET, idx_buffer ? 6 : 3);63if (vismode == USE_VISIBILITY) {64/* leave vis mode blank for now, it will be patched up when65* we know if we are binning or not66*/67OUT_RINGP(ring, DRAW4(primtype, src_sel, idx_type, 0),68&batch->draw_patches);69} else {70OUT_RING(ring, DRAW4(primtype, src_sel, idx_type, vismode));71}72OUT_RING(ring, instances); /* NumInstances */73OUT_RING(ring, count); /* NumIndices */74if (idx_buffer) {75OUT_RING(ring, 0x0); /* XXX */76OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);77OUT_RING(ring, max_indices);78}7980emit_marker(ring, 7);8182fd_reset_wfi(batch);83}8485static inline void86fd4_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,87enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,88const struct pipe_draw_info *info,89const struct pipe_draw_indirect_info *indirect,90const struct pipe_draw_start_count_bias *draw, unsigned index_offset)91{92struct pipe_resource *idx_buffer = NULL;93enum a4xx_index_size idx_type;94enum pc_di_src_sel src_sel;95uint32_t idx_size, idx_offset;9697if (indirect && indirect->buffer) {98struct fd_resource *ind = fd_resource(indirect->buffer);99100emit_marker(ring, 7);101102if (info->index_size) {103struct pipe_resource *idx = info->index.resource;104105OUT_PKT3(ring, CP_DRAW_INDX_INDIRECT, 4);106OUT_RINGP(ring,107DRAW4(primtype, DI_SRC_SEL_DMA,108fd4_size2indextype(info->index_size), 0),109&batch->draw_patches);110OUT_RELOC(ring, fd_resource(idx)->bo, index_offset, 0, 0);111OUT_RING(ring, A4XX_CP_DRAW_INDX_INDIRECT_2_INDX_SIZE(idx->width0 -112index_offset));113OUT_RELOC(ring, ind->bo, indirect->offset, 0, 0);114} else {115OUT_PKT3(ring, CP_DRAW_INDIRECT, 2);116OUT_RINGP(ring, DRAW4(primtype, DI_SRC_SEL_AUTO_INDEX, 0, 0),117&batch->draw_patches);118OUT_RELOC(ring, ind->bo, indirect->offset, 0, 0);119}120121emit_marker(ring, 7);122fd_reset_wfi(batch);123124return;125}126127if (info->index_size) {128assert(!info->has_user_indices);129130idx_buffer = info->index.resource;131idx_type = fd4_size2indextype(info->index_size);132idx_size = info->index_size * draw->count;133idx_offset = index_offset + draw->start * info->index_size;134src_sel = DI_SRC_SEL_DMA;135} else {136idx_buffer = NULL;137idx_type = INDEX4_SIZE_32_BIT;138idx_size = 0;139idx_offset = 0;140src_sel = DI_SRC_SEL_AUTO_INDEX;141}142143fd4_draw(batch, ring, primtype, vismode, src_sel, draw->count,144info->instance_count, idx_type, idx_size, idx_offset, idx_buffer);145}146147#endif /* FD4_DRAW_H_ */148149150