dd2516aa98597543326fecbeb502c23d3d9acb8d
[mesa.git] / src / gallium / drivers / freedreno / a4xx / fd4_draw.h
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2
3 /*
4 * Copyright (C) 2014 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 FD4_DRAW_H_
30 #define FD4_DRAW_H_
31
32 #include "pipe/p_context.h"
33
34 #include "freedreno_draw.h"
35
36 void fd4_draw_init(struct pipe_context *pctx);
37
38 /* draw packet changed on a4xx, so cannot reuse one from a2xx/a3xx.. */
39
40 static inline uint32_t DRAW4(enum pc_di_primtype prim_type,
41 enum pc_di_src_sel source_select, enum a4xx_index_size index_size,
42 enum pc_di_vis_cull_mode vis_cull_mode)
43 {
44 return (prim_type << 0) |
45 (source_select << 6) |
46 (index_size << 10);
47 }
48
49 static inline void
50 fd4_draw(struct fd_context *ctx, struct fd_ringbuffer *ring,
51 enum pc_di_primtype primtype,
52 enum pc_di_vis_cull_mode vismode,
53 enum pc_di_src_sel src_sel, uint32_t count,
54 enum a4xx_index_size idx_type,
55 uint32_t idx_size, uint32_t idx_offset,
56 struct fd_bo *idx_bo)
57 {
58 /* for debug after a lock up, write a unique counter value
59 * to scratch7 for each draw, to make it easier to match up
60 * register dumps to cmdstream. The combination of IB
61 * (scratch6) and DRAW is enough to "triangulate" the
62 * particular draw that caused lockup.
63 */
64 emit_marker(ring, 7);
65
66 OUT_PKT3(ring, CP_DRAW_INDX_OFFSET, idx_bo ? 6 : 3);
67 if (vismode == USE_VISIBILITY) {
68 /* leave vis mode blank for now, it will be patched up when
69 * we know if we are binning or not
70 */
71 OUT_RINGP(ring, DRAW4(primtype, src_sel, idx_type, 0),
72 &ctx->draw_patches);
73 } else {
74 OUT_RING(ring, DRAW4(primtype, src_sel, idx_type, vismode));
75 }
76 OUT_RING(ring, 0x1); /* XXX */
77 OUT_RING(ring, count); /* NumIndices */
78 if (idx_bo) {
79 OUT_RING(ring, 0x0); /* XXX */
80 OUT_RELOC(ring, idx_bo, idx_offset, 0, 0);
81 OUT_RING (ring, idx_size);
82 }
83
84 emit_marker(ring, 7);
85
86 fd_reset_wfi(ctx);
87 }
88
89
90 static inline enum pc_di_index_size
91 fd4_size2indextype(unsigned index_size)
92 {
93 switch (index_size) {
94 case 1: return INDEX4_SIZE_8_BIT;
95 case 2: return INDEX4_SIZE_16_BIT;
96 case 4: return INDEX4_SIZE_32_BIT;
97 }
98 DBG("unsupported index size: %d", index_size);
99 assert(0);
100 return INDEX4_SIZE_32_BIT;
101 }
102 static inline void
103 fd4_draw_emit(struct fd_context *ctx, struct fd_ringbuffer *ring,
104 enum pc_di_vis_cull_mode vismode,
105 const struct pipe_draw_info *info)
106 {
107 struct pipe_index_buffer *idx = &ctx->indexbuf;
108 struct fd_bo *idx_bo = NULL;
109 enum a4xx_index_size idx_type;
110 enum pc_di_src_sel src_sel;
111 uint32_t idx_size, idx_offset;
112
113 if (info->indexed) {
114 assert(!idx->user_buffer);
115
116 idx_bo = fd_resource(idx->buffer)->bo;
117 idx_type = fd4_size2indextype(idx->index_size);
118 idx_size = idx->index_size * info->count;
119 idx_offset = idx->offset + (info->start * idx->index_size);
120 src_sel = DI_SRC_SEL_DMA;
121 } else {
122 idx_bo = NULL;
123 idx_type = INDEX4_SIZE_32_BIT;
124 idx_size = 0;
125 idx_offset = 0;
126 src_sel = DI_SRC_SEL_AUTO_INDEX;
127 }
128
129 fd4_draw(ctx, ring, ctx->primtypes[info->mode], vismode, src_sel,
130 info->count, idx_type, idx_size, idx_offset, idx_bo);
131 }
132
133 #endif /* FD4_DRAW_H_ */