Path: blob/21.2-virgl/src/gallium/drivers/freedreno/freedreno_draw.h
4570 views
/*1* Copyright (C) 2012 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 FREEDRENO_DRAW_H_27#define FREEDRENO_DRAW_H_2829#include "pipe/p_context.h"30#include "pipe/p_state.h"3132#include "freedreno_context.h"33#include "freedreno_resource.h"34#include "freedreno_screen.h"35#include "freedreno_util.h"3637struct fd_ringbuffer;3839void fd_draw_init(struct pipe_context *pctx);4041static inline void42fd_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,43enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,44enum pc_di_src_sel src_sel, uint32_t count, uint8_t instances,45enum pc_di_index_size idx_type, uint32_t idx_size, uint32_t idx_offset,46struct pipe_resource *idx_buffer)47{48/* for debug after a lock up, write a unique counter value49* to scratch7 for each draw, to make it easier to match up50* register dumps to cmdstream. The combination of IB51* (scratch6) and DRAW is enough to "triangulate" the52* particular draw that caused lockup.53*/54emit_marker(ring, 7);5556if (is_a3xx_p0(batch->ctx->screen)) {57/* dummy-draw workaround: */58OUT_PKT3(ring, CP_DRAW_INDX, 3);59OUT_RING(ring, 0x00000000);60OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX, INDEX_SIZE_IGN,61USE_VISIBILITY, 0));62OUT_RING(ring, 0); /* NumIndices */6364/* ugg, hard-code register offset to avoid pulling in the65* a3xx register headers into something #included from a2xx66*/67OUT_PKT0(ring, 0x2206, 1); /* A3XX_HLSQ_CONST_VSPRESV_RANGE_REG */68OUT_RING(ring, 0);69}7071if (is_a20x(batch->ctx->screen)) {72/* a20x has a different draw command for drawing with binning data73* note: if we do patching we will have to insert a NOP74*75* binning data is is 1 byte/vertex (8x8x4 bin position of vertex)76* base ptr set by the CP_SET_DRAW_INIT_FLAGS command77*78* TODO: investigate the faceness_cull_select parameter to see how79* it is used with hw binning to use "faceness" bits80*/81uint32_t size = 2;82if (vismode)83size += 2;84if (idx_buffer)85size += 2;8687BEGIN_RING(ring, size + 1);88if (vismode)89util_dynarray_append(&batch->draw_patches, uint32_t *, ring->cur);9091OUT_PKT3(ring, vismode ? CP_DRAW_INDX_BIN : CP_DRAW_INDX, size);92OUT_RING(ring, 0x00000000);93OUT_RING(ring, DRAW_A20X(primtype, DI_FACE_CULL_NONE, src_sel, idx_type,94vismode, vismode, count));95if (vismode == USE_VISIBILITY) {96OUT_RING(ring, batch->num_vertices);97OUT_RING(ring, count);98}99} else {100OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 5 : 3);101OUT_RING(ring, 0x00000000); /* viz query info. */102if (vismode == USE_VISIBILITY) {103/* leave vis mode blank for now, it will be patched up when104* we know if we are binning or not105*/106OUT_RINGP(ring, DRAW(primtype, src_sel, idx_type, 0, instances),107&batch->draw_patches);108} else {109OUT_RING(ring, DRAW(primtype, src_sel, idx_type, vismode, instances));110}111OUT_RING(ring, count); /* NumIndices */112}113114if (idx_buffer) {115OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);116OUT_RING(ring, idx_size);117}118119emit_marker(ring, 7);120121fd_reset_wfi(batch);122}123124static inline enum pc_di_index_size125size2indextype(unsigned index_size)126{127switch (index_size) {128case 1:129return INDEX_SIZE_8_BIT;130case 2:131return INDEX_SIZE_16_BIT;132case 4:133return INDEX_SIZE_32_BIT;134}135DBG("unsupported index size: %d", index_size);136assert(0);137return INDEX_SIZE_IGN;138}139140/* this is same for a2xx/a3xx, so split into helper: */141static inline void142fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,143enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,144const struct pipe_draw_info *info,145const struct pipe_draw_start_count_bias *draw, unsigned index_offset)146{147struct pipe_resource *idx_buffer = NULL;148enum pc_di_index_size idx_type = INDEX_SIZE_IGN;149enum pc_di_src_sel src_sel;150uint32_t idx_size, idx_offset;151152if (info->index_size) {153assert(!info->has_user_indices);154155idx_buffer = info->index.resource;156idx_type = size2indextype(info->index_size);157idx_size = info->index_size * draw->count;158idx_offset = index_offset + draw->start * info->index_size;159src_sel = DI_SRC_SEL_DMA;160} else {161idx_buffer = NULL;162idx_type = INDEX_SIZE_IGN;163idx_size = 0;164idx_offset = 0;165src_sel = DI_SRC_SEL_AUTO_INDEX;166}167168fd_draw(batch, ring, primtype, vismode, src_sel, draw->count,169info->instance_count - 1, idx_type, idx_size, idx_offset,170idx_buffer);171}172173#endif /* FREEDRENO_DRAW_H_ */174175176