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