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:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
111 struct r600_tiling_info
{
112 unsigned num_channels
;
114 unsigned group_bytes
;
117 enum radeon_family
r600_get_family(struct radeon
*rw
);
118 enum chip_class
r600_get_family_class(struct radeon
*radeon
);
119 struct r600_tiling_info
*r600_get_tiling_info(struct radeon
*radeon
);
120 unsigned r600_get_clock_crystal_freq(struct radeon
*radeon
);
121 unsigned r600_get_minor_version(struct radeon
*radeon
);
122 unsigned r600_get_num_backends(struct radeon
*radeon
);
126 struct r600_bo
*r600_bo(struct radeon
*radeon
,
127 unsigned size
, unsigned alignment
,
128 unsigned binding
, unsigned usage
);
129 struct r600_bo
*r600_bo_handle(struct radeon
*radeon
,
130 unsigned handle
, unsigned *array_mode
);
131 void *r600_bo_map(struct radeon
*radeon
, struct r600_bo
*bo
, unsigned usage
, void *ctx
);
132 void r600_bo_unmap(struct radeon
*radeon
, struct r600_bo
*bo
);
133 void r600_bo_reference(struct radeon
*radeon
, struct r600_bo
**dst
,
134 struct r600_bo
*src
);
135 boolean
r600_bo_get_winsys_handle(struct radeon
*radeon
, struct r600_bo
*pb_bo
,
136 unsigned stride
, struct winsys_handle
*whandle
);
137 static INLINE
unsigned r600_bo_offset(struct r600_bo
*bo
)
143 /* R600/R700 STATES */
144 #define R600_GROUP_MAX 16
145 #define R600_BLOCK_MAX_BO 32
146 #define R600_BLOCK_MAX_REG 128
148 /* each range covers 9 bits of dword space = 512 dwords = 2k bytes */
149 /* there is a block entry for each register so 512 blocks */
150 /* we have no registers to read/write below 0x8000 (0x2000 in dw space) */
151 /* we use some fake offsets at 0x40000 to do evergreen sampler borders so take 0x42000 as a max bound*/
152 #define RANGE_OFFSET_START 0x8000
154 #define NUM_RANGES (0x42000 - RANGE_OFFSET_START) / (4 << HASH_SHIFT) /* 128 << 9 = 64k */
156 #define CTX_RANGE_ID(offset) ((((offset - RANGE_OFFSET_START) >> 2) >> HASH_SHIFT) & 255)
157 #define CTX_BLOCK_ID(offset) (((offset - RANGE_OFFSET_START) >> 2) & ((1 << HASH_SHIFT) - 1))
159 struct r600_pipe_reg
{
162 struct r600_block
*block
;
167 struct r600_pipe_state
{
170 struct r600_pipe_reg regs
[R600_BLOCK_MAX_REG
];
173 struct r600_pipe_resource_state
{
176 struct r600_bo
*bo
[2];
179 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
180 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
182 struct r600_block_reloc
{
184 unsigned flush_flags
;
186 unsigned bo_pm4_index
;
190 struct list_head list
;
193 unsigned start_offset
;
194 unsigned pm4_ndwords
;
195 unsigned pm4_flush_ndwords
;
200 u32 pm4
[R600_BLOCK_MAX_REG
];
201 unsigned pm4_bo_index
[R600_BLOCK_MAX_REG
];
202 struct r600_block_reloc reloc
[R600_BLOCK_MAX_BO
];
206 struct r600_block
**blocks
;
215 uint32_t read_domain
;
216 uint32_t write_domain
;
226 /* The kind of query. Currently only OQ is supported. */
228 /* How many results have been written, in dwords. It's incremented
229 * after end_query and flush. */
230 unsigned num_results
;
231 /* if we've flushed the query */
233 /* The buffer where query results are stored. */
234 struct r600_bo
*buffer
;
235 unsigned buffer_size
;
236 /* linked list of queries */
237 struct list_head list
;
240 #define R600_QUERY_STATE_STARTED (1 << 0)
241 #define R600_QUERY_STATE_ENDED (1 << 1)
242 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
244 #define R600_CONTEXT_DRAW_PENDING (1 << 0)
245 #define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1)
246 #define R600_CONTEXT_CHECK_EVENT_FLUSH (1 << 2)
248 struct r600_context
{
249 struct radeon
*radeon
;
250 struct r600_range
*range
;
252 struct r600_block
**blocks
;
253 struct list_head dirty
;
254 unsigned pm4_ndwords
;
255 unsigned pm4_cdwords
;
256 unsigned pm4_dirty_cdwords
;
257 unsigned ctx_pm4_ndwords
;
260 struct r600_reloc
*reloc
;
261 struct radeon_bo
**bo
;
263 struct list_head query_list
;
264 unsigned num_query_running
;
265 struct list_head fenced_bo
;
266 unsigned max_db
; /* for OQ */
267 unsigned num_dest_buffers
;
269 boolean predicate_drawing
;
270 struct r600_range ps_resources
;
271 struct r600_range vs_resources
;
272 struct r600_range fs_resources
;
273 int num_ps_resources
, num_vs_resources
, num_fs_resources
;
278 u32 vgt_num_instances
;
280 u32 vgt_draw_initiator
;
281 u32 indices_bo_offset
;
282 struct r600_bo
*indices
;
285 int r600_context_init(struct r600_context
*ctx
, struct radeon
*radeon
);
286 void r600_context_fini(struct r600_context
*ctx
);
287 void r600_context_pipe_state_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
);
288 void r600_context_pipe_state_set_ps_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
289 void r600_context_pipe_state_set_vs_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
290 void r600_context_pipe_state_set_fs_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
291 void r600_context_pipe_state_set_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
292 void r600_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
293 void r600_context_flush(struct r600_context
*ctx
);
294 void r600_context_dump_bof(struct r600_context
*ctx
, const char *file
);
295 void r600_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
297 struct r600_query
*r600_context_query_create(struct r600_context
*ctx
, unsigned query_type
);
298 void r600_context_query_destroy(struct r600_context
*ctx
, struct r600_query
*query
);
299 boolean
r600_context_query_result(struct r600_context
*ctx
,
300 struct r600_query
*query
,
301 boolean wait
, void *vresult
);
302 void r600_query_begin(struct r600_context
*ctx
, struct r600_query
*query
);
303 void r600_query_end(struct r600_context
*ctx
, struct r600_query
*query
);
304 void r600_context_queries_suspend(struct r600_context
*ctx
);
305 void r600_context_queries_resume(struct r600_context
*ctx
);
306 void r600_query_predication(struct r600_context
*ctx
, struct r600_query
*query
, int operation
,
308 void r600_context_emit_fence(struct r600_context
*ctx
, struct r600_bo
*fence
,
309 unsigned offset
, unsigned value
);
310 void r600_context_flush_all(struct r600_context
*ctx
, unsigned flush_flags
);
311 void r600_context_flush_dest_caches(struct r600_context
*ctx
);
313 int evergreen_context_init(struct r600_context
*ctx
, struct radeon
*radeon
);
314 void evergreen_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
315 void evergreen_context_flush_dest_caches(struct r600_context
*ctx
);
316 void evergreen_context_pipe_state_set_ps_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
317 void evergreen_context_pipe_state_set_vs_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
318 void evergreen_context_pipe_state_set_fs_resource(struct r600_context
*ctx
, struct r600_pipe_resource_state
*state
, unsigned rid
);
319 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
320 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
322 struct radeon
*radeon_decref(struct radeon
*radeon
);
324 void _r600_pipe_state_add_reg(struct r600_context
*ctx
,
325 struct r600_pipe_state
*state
,
326 u32 offset
, u32 value
, u32 mask
,
327 u32 range_id
, u32 block_id
,
330 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state
*state
,
331 u32 offset
, u32 value
, u32 mask
,
333 #define r600_pipe_state_add_reg(state, offset, value, mask, bo) _r600_pipe_state_add_reg(&rctx->ctx, state, offset, value, mask, CTX_RANGE_ID(offset), CTX_BLOCK_ID(offset), bo)
335 static inline void r600_pipe_state_mod_reg(struct r600_pipe_state
*state
,
338 state
->regs
[state
->nregs
].value
= value
;
342 static inline void r600_pipe_state_mod_reg_bo(struct r600_pipe_state
*state
,
343 u32 value
, struct r600_bo
*bo
)
345 state
->regs
[state
->nregs
].value
= value
;
346 state
->regs
[state
->nregs
].bo
= bo
;