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 #ifndef __cplusplus
43 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)44 fd_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,
45 enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,
46 enum pc_di_src_sel src_sel, uint32_t count, uint8_t instances,
47 enum pc_di_index_size idx_type, uint32_t idx_size, uint32_t idx_offset,
48 struct pipe_resource *idx_buffer)
49 {
50 /* for debug after a lock up, write a unique counter value
51 * to scratch7 for each draw, to make it easier to match up
52 * register dumps to cmdstream. The combination of IB
53 * (scratch6) and DRAW is enough to "triangulate" the
54 * particular draw that caused lockup.
55 */
56 emit_marker(ring, 7);
57
58 if (is_a3xx_p0(batch->ctx->screen)) {
59 /* dummy-draw workaround: */
60 OUT_PKT3(ring, CP_DRAW_INDX, 3);
61 OUT_RING(ring, 0x00000000);
62 OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX, INDEX_SIZE_IGN,
63 USE_VISIBILITY, 0));
64 OUT_RING(ring, 0); /* NumIndices */
65
66 /* ugg, hard-code register offset to avoid pulling in the
67 * a3xx register headers into something #included from a2xx
68 */
69 OUT_PKT0(ring, 0x2206, 1); /* A3XX_HLSQ_CONST_VSPRESV_RANGE_REG */
70 OUT_RING(ring, 0);
71 }
72
73 if (is_a20x(batch->ctx->screen)) {
74 /* a20x has a different draw command for drawing with binning data
75 * note: if we do patching we will have to insert a NOP
76 *
77 * binning data is is 1 byte/vertex (8x8x4 bin position of vertex)
78 * base ptr set by the CP_SET_DRAW_INIT_FLAGS command
79 *
80 * TODO: investigate the faceness_cull_select parameter to see how
81 * it is used with hw binning to use "faceness" bits
82 */
83 uint32_t size = 2;
84 if (vismode)
85 size += 2;
86 if (idx_buffer)
87 size += 2;
88
89 BEGIN_RING(ring, size + 1);
90 if (vismode)
91 util_dynarray_append(&batch->draw_patches, uint32_t *, ring->cur);
92
93 OUT_PKT3(ring, vismode ? CP_DRAW_INDX_BIN : CP_DRAW_INDX, size);
94 OUT_RING(ring, 0x00000000);
95 OUT_RING(ring, DRAW_A20X(primtype, DI_FACE_CULL_NONE, src_sel, idx_type,
96 vismode, vismode, count));
97 if (vismode == USE_VISIBILITY) {
98 OUT_RING(ring, batch->num_vertices);
99 OUT_RING(ring, count);
100 }
101 } else {
102 OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 5 : 3);
103 OUT_RING(ring, 0x00000000); /* viz query info. */
104 if (vismode == USE_VISIBILITY) {
105 /* leave vis mode blank for now, it will be patched up when
106 * we know if we are binning or not
107 */
108 OUT_RINGP(ring, DRAW(primtype, src_sel, idx_type, 0, instances),
109 &batch->draw_patches);
110 } else {
111 OUT_RING(ring, DRAW(primtype, src_sel, idx_type, vismode, instances));
112 }
113 OUT_RING(ring, count); /* NumIndices */
114 }
115
116 if (idx_buffer) {
117 OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);
118 OUT_RING(ring, idx_size);
119 }
120
121 emit_marker(ring, 7);
122
123 fd_reset_wfi(batch);
124 }
125
126 static inline enum pc_di_index_size
size2indextype(unsigned index_size)127 size2indextype(unsigned index_size)
128 {
129 switch (index_size) {
130 case 1:
131 return INDEX_SIZE_8_BIT;
132 case 2:
133 return INDEX_SIZE_16_BIT;
134 case 4:
135 return INDEX_SIZE_32_BIT;
136 }
137 DBG("unsupported index size: %d", index_size);
138 assert(0);
139 return INDEX_SIZE_IGN;
140 }
141
142 /* this is same for a2xx/a3xx, so split into helper: */
143 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)144 fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
145 enum pc_di_primtype primtype, enum pc_di_vis_cull_mode vismode,
146 const struct pipe_draw_info *info,
147 const struct pipe_draw_start_count_bias *draw, unsigned index_offset)
148 {
149 struct pipe_resource *idx_buffer = NULL;
150 enum pc_di_index_size idx_type = INDEX_SIZE_IGN;
151 enum pc_di_src_sel src_sel;
152 uint32_t idx_size, idx_offset;
153
154 if (info->index_size) {
155 assert(!info->has_user_indices);
156
157 idx_buffer = info->index.resource;
158 idx_type = size2indextype(info->index_size);
159 idx_size = info->index_size * draw->count;
160 idx_offset = index_offset + draw->start * info->index_size;
161 src_sel = DI_SRC_SEL_DMA;
162 } else {
163 idx_buffer = NULL;
164 idx_type = INDEX_SIZE_IGN;
165 idx_size = 0;
166 idx_offset = 0;
167 src_sel = DI_SRC_SEL_AUTO_INDEX;
168 }
169
170 fd_draw(batch, ring, primtype, vismode, src_sel, draw->count,
171 info->instance_count - 1, idx_type, idx_size, idx_offset,
172 idx_buffer);
173 }
174 #endif
175
176 static inline void
fd_blend_tracking(struct fd_context * ctx)177 fd_blend_tracking(struct fd_context *ctx)
178 assert_dt
179 {
180 if (ctx->dirty & FD_DIRTY_BLEND) {
181 struct fd_batch *batch = ctx->batch;
182 struct pipe_framebuffer_state *pfb = &batch->framebuffer;
183
184 if (ctx->blend->logicop_enable)
185 batch->gmem_reason |= FD_GMEM_LOGICOP_ENABLED;
186 for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
187 if (ctx->blend->rt[i].blend_enable)
188 batch->gmem_reason |= FD_GMEM_BLEND_ENABLED;
189 }
190 }
191 }
192
193 #endif /* FREEDRENO_DRAW_H_ */
194