1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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:
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
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
26 * Rob Clark <robclark@freedesktop.org>
32 #include "pipe/p_context.h"
34 #include "freedreno_draw.h"
36 void fd4_draw_init(struct pipe_context
*pctx
);
38 /* draw packet changed on a4xx, so cannot reuse one from a2xx/a3xx.. */
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
)
44 return (prim_type
<< 0) |
45 (source_select
<< 6) |
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
,
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.
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
71 OUT_RINGP(ring
, DRAW4(primtype
, src_sel
, idx_type
, 0),
74 OUT_RING(ring
, DRAW4(primtype
, src_sel
, idx_type
, vismode
));
76 OUT_RING(ring
, 0x1); /* XXX */
77 OUT_RING(ring
, count
); /* NumIndices */
79 OUT_RING(ring
, 0x0); /* XXX */
80 OUT_RELOC(ring
, idx_bo
, idx_offset
, 0, 0);
81 OUT_RING (ring
, idx_size
);
90 static inline enum pc_di_index_size
91 fd4_size2indextype(unsigned 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
;
98 DBG("unsupported index size: %d", index_size
);
100 return INDEX4_SIZE_32_BIT
;
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
)
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
;
114 assert(!idx
->user_buffer
);
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
;
123 idx_type
= INDEX4_SIZE_32_BIT
;
126 src_sel
= DI_SRC_SEL_AUTO_INDEX
;
129 fd4_draw(ctx
, ring
, ctx
->primtypes
[info
->mode
], vismode
, src_sel
,
130 info
->count
, idx_type
, idx_size
, idx_offset
, idx_bo
);
133 #endif /* FD4_DRAW_H_ */