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.
31 #include <util/u_double_list.h>
32 #include <pipe/p_compiler.h>
34 #define RADEON_CTX_MAX_PM4 (64 * 1024 / 4)
36 #define R600_ERR(fmt, args...) \
37 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
101 enum radeon_family
r600_get_family(struct radeon
*rw
);
102 enum chip_class
r600_get_family_class(struct radeon
*radeon
);
106 struct radeon_ws_bo
*radeon_ws_bo(struct radeon
*radeon
,
107 unsigned size
, unsigned alignment
, unsigned usage
);
108 struct radeon_ws_bo
*radeon_ws_bo_handle(struct radeon
*radeon
,
110 void *radeon_ws_bo_map(struct radeon
*radeon
, struct radeon_ws_bo
*bo
, unsigned usage
, void *ctx
);
111 void radeon_ws_bo_unmap(struct radeon
*radeon
, struct radeon_ws_bo
*bo
);
112 void radeon_ws_bo_reference(struct radeon
*radeon
, struct radeon_ws_bo
**dst
,
113 struct radeon_ws_bo
*src
);
115 /* R600/R700 STATES */
116 #define R600_GROUP_MAX 16
117 #define R600_BLOCK_MAX_BO 32
118 #define R600_BLOCK_MAX_REG 128
121 R600_GROUP_CONFIG
= 0,
123 R600_GROUP_ALU_CONST
,
126 R600_GROUP_CTL_CONST
,
127 R600_GROUP_LOOP_CONST
,
128 R600_GROUP_BOOL_CONST
,
132 enum evergreen_group_id
{
133 EVERGREEN_GROUP_CONFIG
= 0,
134 EVERGREEN_GROUP_CONTEXT
,
135 EVERGREEN_GROUP_RESOURCE
,
136 EVERGREEN_GROUP_SAMPLER
,
137 EVERGREEN_GROUP_CTL_CONST
,
138 EVERGREEN_GROUP_LOOP_CONST
,
139 EVERGREEN_GROUP_BOOL_CONST
,
140 EVERGREEN_GROUP_SAMPLER_BORDER
,
144 struct r600_pipe_reg
{
149 struct radeon_ws_bo
*bo
;
152 struct r600_pipe_state
{
155 struct r600_pipe_reg regs
[R600_BLOCK_MAX_REG
];
158 static inline void r600_pipe_state_add_reg(struct r600_pipe_state
*state
,
159 unsigned group_id
, u32 offset
,
161 struct radeon_ws_bo
*bo
)
163 state
->regs
[state
->nregs
].group_id
= group_id
;
164 state
->regs
[state
->nregs
].offset
= offset
;
165 state
->regs
[state
->nregs
].value
= value
;
166 state
->regs
[state
->nregs
].mask
= mask
;
167 state
->regs
[state
->nregs
].bo
= bo
;
169 assert(state
->nregs
< R600_BLOCK_MAX_REG
);
172 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
173 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
175 struct r600_block_reloc
{
176 struct radeon_ws_bo
*bo
;
178 unsigned bo_pm4_index
[R600_BLOCK_MAX_BO
];
181 struct r600_group_block
{
183 unsigned start_offset
;
184 unsigned pm4_ndwords
;
188 u32 pm4
[R600_BLOCK_MAX_REG
];
189 unsigned pm4_bo_index
[R600_BLOCK_MAX_REG
];
190 struct r600_block_reloc reloc
[R600_BLOCK_MAX_BO
];
194 unsigned start_offset
;
197 struct r600_group_block
*blocks
;
198 unsigned *offset_block_id
;
207 uint32_t read_domain
;
208 uint32_t write_domain
;
218 /* The kind of query. Currently only OQ is supported. */
220 /* How many results have been written, in dwords. It's incremented
221 * after end_query and flush. */
222 unsigned num_results
;
223 /* if we've flushed the query */
225 /* The buffer where query results are stored. */
226 struct radeon_ws_bo
*buffer
;
227 unsigned buffer_size
;
228 /* linked list of queries */
229 struct list_head list
;
232 #define R600_QUERY_STATE_STARTED (1 << 0)
233 #define R600_QUERY_STATE_ENDED (1 << 1)
234 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
237 struct r600_context
{
238 struct radeon
*radeon
;
240 struct r600_group groups
[R600_GROUP_MAX
];
241 unsigned pm4_ndwords
;
242 unsigned pm4_cdwords
;
243 unsigned pm4_dirty_cdwords
;
244 unsigned ctx_pm4_ndwords
;
247 struct r600_reloc
*reloc
;
248 struct radeon_bo
**bo
;
250 struct list_head query_list
;
251 unsigned num_query_running
;
256 u32 vgt_num_instances
;
258 u32 vgt_draw_initiator
;
259 u32 indices_bo_offset
;
260 struct radeon_ws_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_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
269 void r600_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
270 void r600_context_flush(struct r600_context
*ctx
);
271 void r600_context_dump_bof(struct r600_context
*ctx
, const char *file
);
272 void r600_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
274 struct r600_query
*r600_context_query_create(struct r600_context
*ctx
, unsigned query_type
);
275 void r600_context_query_destroy(struct r600_context
*ctx
, struct r600_query
*query
);
276 boolean
r600_context_query_result(struct r600_context
*ctx
,
277 struct r600_query
*query
,
278 boolean wait
, void *vresult
);
279 void r600_query_begin(struct r600_context
*ctx
, struct r600_query
*query
);
280 void r600_query_end(struct r600_context
*ctx
, struct r600_query
*query
);
281 void r600_context_queries_suspend(struct r600_context
*ctx
);
282 void r600_context_queries_resume(struct r600_context
*ctx
);
284 int evergreen_context_init(struct r600_context
*ctx
, struct radeon
*radeon
);
285 void evergreen_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
286 void evergreen_ps_resource_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
287 void evergreen_vs_resource_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
289 void evergreen_context_pipe_state_set_ps_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
290 void evergreen_context_pipe_state_set_vs_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
291 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
292 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);