• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  *    Rob Clark <robclark@freedesktop.org>
25  */
26 
27 #ifndef FREEDRENO_DRAW_H_
28 #define FREEDRENO_DRAW_H_
29 
30 #include "pipe/p_context.h"
31 #include "pipe/p_state.h"
32 
33 #include "freedreno_context.h"
34 #include "freedreno_resource.h"
35 #include "freedreno_screen.h"
36 #include "freedreno_util.h"
37 
38 struct fd_ringbuffer;
39 
40 void fd_draw_init(struct pipe_context *pctx);
41 
42 static inline void
fd_draw(struct fd_batch * batch,struct fd_ringbuffer * ring,enum pc_di_primtype primtype,enum pc_di_vis_cull_mode vismode,enum pc_di_src_sel src_sel,uint32_t count,uint8_t instances,enum pc_di_index_size idx_type,uint32_t idx_size,uint32_t idx_offset,struct pipe_resource * idx_buffer)43 fd_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,
44         enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,
45         enum pc_di_src_sel src_sel, uint32_t count, uint8_t instances,
46         enum pc_di_index_size idx_type, uint32_t idx_size, uint32_t idx_offset,
47         struct pipe_resource *idx_buffer)
48 {
49    /* for debug after a lock up, write a unique counter value
50     * to scratch7 for each draw, to make it easier to match up
51     * register dumps to cmdstream.  The combination of IB
52     * (scratch6) and DRAW is enough to "triangulate" the
53     * particular draw that caused lockup.
54     */
55    emit_marker(ring, 7);
56 
57    if (is_a3xx_p0(batch->ctx->screen)) {
58       /* dummy-draw workaround: */
59       OUT_PKT3(ring, CP_DRAW_INDX, 3);
60       OUT_RING(ring, 0x00000000);
61       OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX, INDEX_SIZE_IGN,
62                           USE_VISIBILITY, 0));
63       OUT_RING(ring, 0); /* NumIndices */
64 
65       /* ugg, hard-code register offset to avoid pulling in the
66        * a3xx register headers into something #included from a2xx
67        */
68       OUT_PKT0(ring, 0x2206, 1); /* A3XX_HLSQ_CONST_VSPRESV_RANGE_REG */
69       OUT_RING(ring, 0);
70    }
71 
72    if (is_a20x(batch->ctx->screen)) {
73       /* a20x has a different draw command for drawing with binning data
74        * note: if we do patching we will have to insert a NOP
75        *
76        * binning data is is 1 byte/vertex (8x8x4 bin position of vertex)
77        * base ptr set by the CP_SET_DRAW_INIT_FLAGS command
78        *
79        * TODO: investigate the faceness_cull_select parameter to see how
80        * it is used with hw binning to use "faceness" bits
81        */
82       uint32_t size = 2;
83       if (vismode)
84          size += 2;
85       if (idx_buffer)
86          size += 2;
87 
88       BEGIN_RING(ring, size + 1);
89       if (vismode)
90          util_dynarray_append(&batch->draw_patches, uint32_t *, ring->cur);
91 
92       OUT_PKT3(ring, vismode ? CP_DRAW_INDX_BIN : CP_DRAW_INDX, size);
93       OUT_RING(ring, 0x00000000);
94       OUT_RING(ring, DRAW_A20X(primtype, DI_FACE_CULL_NONE, src_sel, idx_type,
95                                vismode, vismode, count));
96       if (vismode == USE_VISIBILITY) {
97          OUT_RING(ring, batch->num_vertices);
98          OUT_RING(ring, count);
99       }
100    } else {
101       OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 5 : 3);
102       OUT_RING(ring, 0x00000000); /* viz query info. */
103       if (vismode == USE_VISIBILITY) {
104          /* leave vis mode blank for now, it will be patched up when
105           * we know if we are binning or not
106           */
107          OUT_RINGP(ring, DRAW(primtype, src_sel, idx_type, 0, instances),
108                    &batch->draw_patches);
109       } else {
110          OUT_RING(ring, DRAW(primtype, src_sel, idx_type, vismode, instances));
111       }
112       OUT_RING(ring, count); /* NumIndices */
113    }
114 
115    if (idx_buffer) {
116       OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);
117       OUT_RING(ring, idx_size);
118    }
119 
120    emit_marker(ring, 7);
121 
122    fd_reset_wfi(batch);
123 }
124 
125 static inline enum pc_di_index_size
size2indextype(unsigned index_size)126 size2indextype(unsigned index_size)
127 {
128    switch (index_size) {
129    case 1:
130       return INDEX_SIZE_8_BIT;
131    case 2:
132       return INDEX_SIZE_16_BIT;
133    case 4:
134       return INDEX_SIZE_32_BIT;
135    }
136    DBG("unsupported index size: %d", index_size);
137    assert(0);
138    return INDEX_SIZE_IGN;
139 }
140 
141 /* this is same for a2xx/a3xx, so split into helper: */
142 static inline void
fd_draw_emit(struct fd_batch * batch,struct fd_ringbuffer * ring,enum pc_di_primtype primtype,enum pc_di_vis_cull_mode vismode,const struct pipe_draw_info * info,const struct pipe_draw_start_count_bias * draw,unsigned index_offset)143 fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
144              enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,
145              const struct pipe_draw_info *info,
146              const struct pipe_draw_start_count_bias *draw, unsigned index_offset)
147 {
148    struct pipe_resource *idx_buffer = NULL;
149    enum pc_di_index_size idx_type = INDEX_SIZE_IGN;
150    enum pc_di_src_sel src_sel;
151    uint32_t idx_size, idx_offset;
152 
153    if (info->index_size) {
154       assert(!info->has_user_indices);
155 
156       idx_buffer = info->index.resource;
157       idx_type = size2indextype(info->index_size);
158       idx_size = info->index_size * draw->count;
159       idx_offset = index_offset + draw->start * info->index_size;
160       src_sel = DI_SRC_SEL_DMA;
161    } else {
162       idx_buffer = NULL;
163       idx_type = INDEX_SIZE_IGN;
164       idx_size = 0;
165       idx_offset = 0;
166       src_sel = DI_SRC_SEL_AUTO_INDEX;
167    }
168 
169    fd_draw(batch, ring, primtype, vismode, src_sel, draw->count,
170            info->instance_count - 1, idx_type, idx_size, idx_offset,
171            idx_buffer);
172 }
173 
174 #endif /* FREEDRENO_DRAW_H_ */
175