freedreno/a6xx: use program cache
[mesa.git] / src / gallium / drivers / freedreno / freedreno_draw.h
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_state.h"
31 #include "pipe/p_context.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
43 fd_draw(struct fd_batch *batch, struct fd_ringbuffer *ring,
44 enum pc_di_primtype primtype,
45 enum pc_di_vis_cull_mode vismode,
46 enum pc_di_src_sel src_sel, uint32_t count,
47 uint8_t instances,
48 enum pc_di_index_size idx_type,
49 uint32_t idx_size, uint32_t idx_offset,
50 struct pipe_resource *idx_buffer)
51 {
52 /* for debug after a lock up, write a unique counter value
53 * to scratch7 for each draw, to make it easier to match up
54 * register dumps to cmdstream. The combination of IB
55 * (scratch6) and DRAW is enough to "triangulate" the
56 * particular draw that caused lockup.
57 */
58 emit_marker(ring, 7);
59
60 if (is_a3xx_p0(batch->ctx->screen)) {
61 /* dummy-draw workaround: */
62 OUT_PKT3(ring, CP_DRAW_INDX, 3);
63 OUT_RING(ring, 0x00000000);
64 OUT_RING(ring, DRAW(1, DI_SRC_SEL_AUTO_INDEX,
65 INDEX_SIZE_IGN, USE_VISIBILITY, 0));
66 OUT_RING(ring, 0); /* NumIndices */
67
68 /* ugg, hard-code register offset to avoid pulling in the
69 * a3xx register headers into something #included from a2xx
70 */
71 OUT_PKT0(ring, 0x2206, 1); /* A3XX_HLSQ_CONST_VSPRESV_RANGE_REG */
72 OUT_RING(ring, 0);
73 }
74
75 if (is_a20x(batch->ctx->screen)) {
76 OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 4 : 2);
77 OUT_RING(ring, 0x00000000);
78 OUT_RING(ring, DRAW_A20X(primtype, src_sel, idx_type, vismode, count));
79 } else {
80 OUT_PKT3(ring, CP_DRAW_INDX, idx_buffer ? 5 : 3);
81 OUT_RING(ring, 0x00000000); /* viz query info. */
82 if (vismode == USE_VISIBILITY) {
83 /* leave vis mode blank for now, it will be patched up when
84 * we know if we are binning or not
85 */
86 OUT_RINGP(ring, DRAW(primtype, src_sel, idx_type, 0, instances),
87 &batch->draw_patches);
88 } else {
89 OUT_RING(ring, DRAW(primtype, src_sel, idx_type, vismode, instances));
90 }
91 OUT_RING(ring, count); /* NumIndices */
92 }
93
94 if (idx_buffer) {
95 OUT_RELOC(ring, fd_resource(idx_buffer)->bo, idx_offset, 0, 0);
96 OUT_RING (ring, idx_size);
97 }
98
99 emit_marker(ring, 7);
100
101 fd_reset_wfi(batch);
102 }
103
104
105 static inline enum pc_di_index_size
106 size2indextype(unsigned index_size)
107 {
108 switch (index_size) {
109 case 1: return INDEX_SIZE_8_BIT;
110 case 2: return INDEX_SIZE_16_BIT;
111 case 4: return INDEX_SIZE_32_BIT;
112 }
113 DBG("unsupported index size: %d", index_size);
114 assert(0);
115 return INDEX_SIZE_IGN;
116 }
117
118 /* this is same for a2xx/a3xx, so split into helper: */
119 static inline void
120 fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
121 enum pc_di_primtype primtype,
122 enum pc_di_vis_cull_mode vismode,
123 const struct pipe_draw_info *info,
124 unsigned index_offset)
125 {
126 struct pipe_resource *idx_buffer = NULL;
127 enum pc_di_index_size idx_type = INDEX_SIZE_IGN;
128 enum pc_di_src_sel src_sel;
129 uint32_t idx_size, idx_offset;
130
131 if (info->index_size) {
132 assert(!info->has_user_indices);
133
134 idx_buffer = info->index.resource;
135 idx_type = size2indextype(info->index_size);
136 idx_size = info->index_size * info->count;
137 idx_offset = index_offset + info->start * info->index_size;
138 src_sel = DI_SRC_SEL_DMA;
139 } else {
140 idx_buffer = NULL;
141 idx_type = INDEX_SIZE_IGN;
142 idx_size = 0;
143 idx_offset = 0;
144 src_sel = DI_SRC_SEL_AUTO_INDEX;
145 }
146
147 fd_draw(batch, ring, primtype, vismode, src_sel,
148 info->count, info->instance_count - 1,
149 idx_type, idx_size, idx_offset, idx_buffer);
150 }
151
152 #endif /* FREEDRENO_DRAW_H_ */