2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
32 #include <util/u_double_list.h>
33 #include <pipe/p_compiler.h>
35 #define RADEON_CTX_MAX_PM4 (64 * 1024 / 4)
37 #define R600_ERR(fmt, args...) \
38 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
104 struct r600_tiling_info {
105 unsigned num_channels;
107 unsigned group_bytes;
110 enum radeon_family r600_get_family(struct radeon *rw);
111 enum chip_class r600_get_family_class(struct radeon *radeon);
112 struct r600_tiling_info *r600_get_tiling_info(struct radeon *radeon);
116 struct r600_bo *r600_bo(struct radeon *radeon,
117 unsigned size, unsigned alignment,
118 unsigned binding, unsigned usage);
119 struct r600_bo *r600_bo_handle(struct radeon *radeon,
120 unsigned handle, unsigned *array_mode);
121 void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx);
122 void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo);
123 void r600_bo_reference(struct radeon *radeon, struct r600_bo **dst,
124 struct r600_bo *src);
125 boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *pb_bo,
126 unsigned stride, struct winsys_handle *whandle);
127 static INLINE unsigned r600_bo_offset(struct r600_bo *bo)
133 /* R600/R700 STATES */
134 #define R600_GROUP_MAX 16
135 #define R600_BLOCK_MAX_BO 32
136 #define R600_BLOCK_MAX_REG 128
138 struct r600_pipe_reg {
145 struct r600_pipe_state {
148 struct r600_pipe_reg regs[R600_BLOCK_MAX_REG];
151 static inline void r600_pipe_state_add_reg(struct r600_pipe_state *state,
152 u32 offset, u32 value, u32 mask,
155 state->regs[state->nregs].offset = offset;
156 state->regs[state->nregs].value = value;
157 state->regs[state->nregs].mask = mask;
158 state->regs[state->nregs].bo = bo;
160 assert(state->nregs < R600_BLOCK_MAX_REG);
163 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
164 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
166 struct r600_block_reloc {
168 unsigned flush_flags;
170 unsigned bo_pm4_index;
174 struct list_head list;
176 unsigned start_offset;
177 unsigned pm4_ndwords;
178 unsigned pm4_flush_ndwords;
182 u32 pm4[R600_BLOCK_MAX_REG];
183 unsigned pm4_bo_index[R600_BLOCK_MAX_REG];
184 struct r600_block_reloc reloc[R600_BLOCK_MAX_BO];
188 unsigned start_offset;
190 struct r600_block **blocks;
199 uint32_t read_domain;
200 uint32_t write_domain;
210 /* The kind of query. Currently only OQ is supported. */
212 /* How many results have been written, in dwords. It's incremented
213 * after end_query and flush. */
214 unsigned num_results;
215 /* if we've flushed the query */
217 /* The buffer where query results are stored. */
218 struct r600_bo *buffer;
219 unsigned buffer_size;
220 /* linked list of queries */
221 struct list_head list;
224 #define R600_QUERY_STATE_STARTED (1 << 0)
225 #define R600_QUERY_STATE_ENDED (1 << 1)
226 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
229 struct r600_context {
230 struct radeon *radeon;
233 struct r600_range range[256];
235 struct r600_block **blocks;
236 struct list_head dirty;
237 unsigned pm4_ndwords;
238 unsigned pm4_cdwords;
239 unsigned pm4_dirty_cdwords;
240 unsigned ctx_pm4_ndwords;
243 struct r600_reloc *reloc;
244 struct radeon_bo **bo;
246 struct list_head query_list;
247 unsigned num_query_running;
249 struct list_head fenced_bo;
251 struct r600_bo *fence_bo;
256 u32 vgt_num_instances;
258 u32 vgt_draw_initiator;
259 u32 indices_bo_offset;
260 struct r600_bo *indices;
263 int r600_context_init(struct r600_context *ctx, struct radeon *radeon);
264 void r600_context_fini(struct r600_context *ctx);
265 void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state);
266 void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
267 void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
268 void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
269 void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
270 void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
271 void r600_context_flush(struct r600_context *ctx);
272 void r600_context_dump_bof(struct r600_context *ctx, const char *file);
273 void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
275 struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type);
276 void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query);
277 boolean r600_context_query_result(struct r600_context *ctx,
278 struct r600_query *query,
279 boolean wait, void *vresult);
280 void r600_query_begin(struct r600_context *ctx, struct r600_query *query);
281 void r600_query_end(struct r600_context *ctx, struct r600_query *query);
282 void r600_context_queries_suspend(struct r600_context *ctx);
283 void r600_context_queries_resume(struct r600_context *ctx);
285 int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon);
286 void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw);
287 void evergreen_ps_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
288 void evergreen_vs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
289 void evergreen_fs_resource_set(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
291 void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
292 void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
293 void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid);
294 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);
295 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id);