r600g: don't use r600_context_reg on r6xx-r7xx
[mesa.git] / src / gallium / drivers / r600 / r600.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef R600_H
27 #define R600_H
28
29 #include "../../winsys/radeon/drm/radeon_winsys.h"
30 #include "util/u_double_list.h"
31 #include "util/u_vbuf.h"
32
33 #define R600_ERR(fmt, args...) \
34 fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
35
36 typedef uint64_t u64;
37 typedef uint32_t u32;
38 typedef uint16_t u16;
39 typedef uint8_t u8;
40
41 struct winsys_handle;
42
43 enum radeon_family {
44 CHIP_UNKNOWN,
45 CHIP_R600,
46 CHIP_RV610,
47 CHIP_RV630,
48 CHIP_RV670,
49 CHIP_RV620,
50 CHIP_RV635,
51 CHIP_RS780,
52 CHIP_RS880,
53 CHIP_RV770,
54 CHIP_RV730,
55 CHIP_RV710,
56 CHIP_RV740,
57 CHIP_CEDAR,
58 CHIP_REDWOOD,
59 CHIP_JUNIPER,
60 CHIP_CYPRESS,
61 CHIP_HEMLOCK,
62 CHIP_PALM,
63 CHIP_SUMO,
64 CHIP_SUMO2,
65 CHIP_BARTS,
66 CHIP_TURKS,
67 CHIP_CAICOS,
68 CHIP_CAYMAN,
69 CHIP_LAST,
70 };
71
72 enum chip_class {
73 R600,
74 R700,
75 EVERGREEN,
76 CAYMAN,
77 };
78
79 struct r600_tiling_info {
80 unsigned num_channels;
81 unsigned num_banks;
82 unsigned group_bytes;
83 };
84
85 struct r600_resource {
86 struct u_vbuf_resource b;
87
88 /* Winsys objects. */
89 struct pb_buffer *buf;
90 struct radeon_winsys_cs_handle *cs_buf;
91
92 /* Resource state. */
93 unsigned domains;
94 };
95
96 /* R600/R700 STATES */
97 #define R600_GROUP_MAX 16
98 #define R600_BLOCK_MAX_BO 32
99 #define R600_BLOCK_MAX_REG 128
100
101 /* each range covers 9 bits of dword space = 512 dwords = 2k bytes */
102 /* there is a block entry for each register so 512 blocks */
103 /* we have no registers to read/write below 0x8000 (0x2000 in dw space) */
104 /* we use some fake offsets at 0x40000 to do evergreen sampler borders so take 0x42000 as a max bound*/
105 #define RANGE_OFFSET_START 0x8000
106 #define HASH_SHIFT 9
107 #define NUM_RANGES (0x42000 - RANGE_OFFSET_START) / (4 << HASH_SHIFT) /* 128 << 9 = 64k */
108
109 #define CTX_RANGE_ID(offset) ((((offset - RANGE_OFFSET_START) >> 2) >> HASH_SHIFT) & 255)
110 #define CTX_BLOCK_ID(offset) (((offset - RANGE_OFFSET_START) >> 2) & ((1 << HASH_SHIFT) - 1))
111
112 struct r600_pipe_reg {
113 u32 value;
114 struct r600_block *block;
115 struct r600_resource *bo;
116 enum radeon_bo_usage bo_usage;
117 u32 id;
118 };
119
120 struct r600_pipe_state {
121 unsigned id;
122 unsigned nregs;
123 struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
124 };
125
126 struct r600_pipe_resource_state {
127 unsigned id;
128 u32 val[8];
129 struct r600_resource *bo[2];
130 enum radeon_bo_usage bo_usage[2];
131 };
132
133 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
134 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
135 #define R600_BLOCK_STATUS_RESOURCE_DIRTY (1 << 2)
136
137 #define R600_BLOCK_STATUS_RESOURCE_VERTEX (1 << 3)
138
139 struct r600_block_reloc {
140 struct r600_resource *bo;
141 enum radeon_bo_usage bo_usage;
142 unsigned flush_flags;
143 unsigned flush_mask;
144 unsigned bo_pm4_index;
145 };
146
147 struct r600_block {
148 struct list_head list;
149 struct list_head enable_list;
150 unsigned status;
151 unsigned flags;
152 unsigned start_offset;
153 unsigned pm4_ndwords;
154 unsigned pm4_flush_ndwords;
155 unsigned nbo;
156 u16 nreg;
157 u16 nreg_dirty;
158 u32 *reg;
159 u32 pm4[R600_BLOCK_MAX_REG];
160 unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
161 struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
162 };
163
164 struct r600_range {
165 struct r600_block **blocks;
166 };
167
168 struct r600_query {
169 union {
170 uint64_t u64;
171 boolean b;
172 struct pipe_query_data_so_statistics so;
173 } result;
174 /* The kind of query */
175 unsigned type;
176 /* Offset of the first result for current query */
177 unsigned results_start;
178 /* Offset of the next free result after current query data */
179 unsigned results_end;
180 /* Size of the result in memory for both begin_query and end_query,
181 * this can be one or two numbers, or it could even be a size of a structure. */
182 unsigned result_size;
183 /* The buffer where query results are stored. It's used as a ring,
184 * data blocks for current query are stored sequentially from
185 * results_start to results_end, with wrapping on the buffer end */
186 struct r600_resource *buffer;
187 /* The number of dwords for begin_query or end_query. */
188 unsigned num_cs_dw;
189 /* linked list of queries */
190 struct list_head list;
191 };
192
193 struct r600_so_target {
194 struct pipe_stream_output_target b;
195
196 /* The buffer where BUFFER_FILLED_SIZE is stored. */
197 struct r600_resource *filled_size;
198 unsigned stride_in_dw;
199 unsigned so_index;
200 };
201
202 #define R600_CONTEXT_DRAW_PENDING (1 << 0)
203 #define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1)
204 #define R600_CONTEXT_CHECK_EVENT_FLUSH (1 << 2)
205
206 struct r600_context {
207 struct r600_screen *screen;
208 struct radeon_winsys *ws;
209 struct radeon_winsys_cs *cs;
210 struct pipe_context *pipe;
211
212 void (*flush)(void *pipe, unsigned flags);
213
214 struct r600_range *range;
215 unsigned nblocks;
216 struct r600_block **blocks;
217 struct list_head dirty;
218 struct list_head resource_dirty;
219 struct list_head enable_list;
220 unsigned pm4_dirty_cdwords;
221 unsigned ctx_pm4_ndwords;
222 unsigned init_dwords;
223
224 unsigned creloc;
225 struct r600_resource **bo;
226
227 u32 *pm4;
228 unsigned pm4_cdwords;
229
230 /* The list of active queries. Only one query of each type can be active. */
231 struct list_head active_query_list;
232 unsigned num_cs_dw_queries_suspend;
233 unsigned num_cs_dw_streamout_end;
234
235 unsigned backend_mask;
236 unsigned max_db; /* for OQ */
237 unsigned num_dest_buffers;
238 unsigned flags;
239 boolean predicate_drawing;
240 struct r600_range ps_resources;
241 struct r600_range vs_resources;
242 struct r600_range fs_resources;
243 int num_ps_resources, num_vs_resources, num_fs_resources;
244 boolean have_depth_texture, have_depth_fb;
245
246 unsigned num_so_targets;
247 struct r600_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
248 boolean streamout_start;
249 unsigned streamout_append_bitmask;
250 unsigned *vs_so_stride_in_dw;
251 };
252
253 struct r600_draw {
254 u32 vgt_num_indices;
255 u32 vgt_num_instances;
256 u32 vgt_index_type;
257 u32 vgt_draw_initiator;
258 u32 indices_bo_offset;
259 unsigned db_render_override;
260 unsigned db_render_control;
261 struct r600_resource *indices;
262 };
263
264 void r600_get_backend_mask(struct r600_context *ctx);
265 int r600_context_init(struct r600_context *ctx, struct r600_screen *screen);
266 void r600_context_fini(struct r600_context *ctx);
267 void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
268 void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
269 void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
270 void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
271 void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
272 void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
273 void r600_context_flush(struct r600_context *ctx, unsigned flags);
274 void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
275
276 struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type);
277 void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query);
278 boolean r600_context_query_result(struct r600_context *ctx,
279 struct r600_query *query,
280 boolean wait, void *vresult);
281 void r600_query_begin(struct r600_context *ctx, struct r600_query *query);
282 void r600_query_end(struct r600_context *ctx, struct r600_query *query);
283 void r600_context_queries_suspend(struct r600_context *ctx);
284 void r600_context_queries_resume(struct r600_context *ctx);
285 void r600_query_predication(struct r600_context *ctx, struct r600_query *query, int operation,
286 int flag_wait);
287 void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence,
288 unsigned offset, unsigned value);
289 void r600_context_flush_all(struct r600_context *ctx, unsigned flush_flags);
290 void r600_context_flush_dest_caches(struct r600_context *ctx);
291
292 void r600_context_streamout_begin(struct r600_context *ctx);
293 void r600_context_streamout_end(struct r600_context *ctx);
294 void r600_context_draw_opaque_count(struct r600_context *ctx, struct r600_so_target *t);
295
296 int evergreen_context_init(struct r600_context *ctx, struct r600_screen *screen);
297 void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
298 void evergreen_context_flush_dest_caches(struct r600_context *ctx);
299 void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
300 void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
301 void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_resource_state *state, unsigned rid);
302 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
303 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
304
305 void _r600_pipe_state_add_reg(struct r600_context *ctx,
306 struct r600_pipe_state *state,
307 u32 offset, u32 value,
308 u32 range_id, u32 block_id,
309 struct r600_resource *bo,
310 enum radeon_bo_usage usage);
311
312 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state *state,
313 u32 offset, u32 value,
314 struct r600_resource *bo,
315 enum radeon_bo_usage usage);
316
317 #define r600_pipe_state_add_reg(state, offset, value, bo, usage) _r600_pipe_state_add_reg(&rctx->ctx, state, offset, value, CTX_RANGE_ID(offset), CTX_BLOCK_ID(offset), bo, usage)
318
319 static inline void r600_pipe_state_mod_reg(struct r600_pipe_state *state,
320 u32 value)
321 {
322 state->regs[state->nregs].value = value;
323 state->nregs++;
324 }
325
326 static inline void r600_pipe_state_mod_reg_bo(struct r600_pipe_state *state,
327 u32 value, struct r600_resource *bo,
328 enum radeon_bo_usage usage)
329 {
330 state->regs[state->nregs].value = value;
331 state->regs[state->nregs].bo = bo;
332 state->regs[state->nregs].bo_usage = usage;
333 state->nregs++;
334 }
335
336 #endif