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)
102 enum radeon_family
r600_get_family(struct radeon
*rw
);
103 enum chip_class
r600_get_family_class(struct radeon
*radeon
);
107 struct radeon_ws_bo
*radeon_ws_bo(struct radeon
*radeon
,
108 unsigned size
, unsigned alignment
, unsigned usage
);
109 struct radeon_ws_bo
*radeon_ws_bo_handle(struct radeon
*radeon
,
111 void *radeon_ws_bo_map(struct radeon
*radeon
, struct radeon_ws_bo
*bo
, unsigned usage
, void *ctx
);
112 void radeon_ws_bo_unmap(struct radeon
*radeon
, struct radeon_ws_bo
*bo
);
113 void radeon_ws_bo_reference(struct radeon
*radeon
, struct radeon_ws_bo
**dst
,
114 struct radeon_ws_bo
*src
);
116 /* R600/R700 STATES */
117 #define R600_GROUP_MAX 16
118 #define R600_BLOCK_MAX_BO 32
119 #define R600_BLOCK_MAX_REG 128
121 struct r600_pipe_reg
{
125 struct radeon_ws_bo
*bo
;
128 struct r600_pipe_state
{
131 struct r600_pipe_reg regs
[R600_BLOCK_MAX_REG
];
134 static inline void r600_pipe_state_add_reg(struct r600_pipe_state
*state
,
135 u32 offset
, u32 value
, u32 mask
,
136 struct radeon_ws_bo
*bo
)
138 state
->regs
[state
->nregs
].offset
= offset
;
139 state
->regs
[state
->nregs
].value
= value
;
140 state
->regs
[state
->nregs
].mask
= mask
;
141 state
->regs
[state
->nregs
].bo
= bo
;
143 assert(state
->nregs
< R600_BLOCK_MAX_REG
);
146 #define R600_BLOCK_STATUS_ENABLED (1 << 0)
147 #define R600_BLOCK_STATUS_DIRTY (1 << 1)
149 struct r600_block_reloc
{
150 struct radeon_ws_bo
*bo
;
152 unsigned bo_pm4_index
[R600_BLOCK_MAX_BO
];
157 unsigned start_offset
;
158 unsigned pm4_ndwords
;
162 u32 pm4
[R600_BLOCK_MAX_REG
];
163 unsigned pm4_bo_index
[R600_BLOCK_MAX_REG
];
164 struct r600_block_reloc reloc
[R600_BLOCK_MAX_BO
];
168 unsigned start_offset
;
170 struct r600_block
**blocks
;
179 uint32_t read_domain
;
180 uint32_t write_domain
;
190 /* The kind of query. Currently only OQ is supported. */
192 /* How many results have been written, in dwords. It's incremented
193 * after end_query and flush. */
194 unsigned num_results
;
195 /* if we've flushed the query */
197 /* The buffer where query results are stored. */
198 struct radeon_ws_bo
*buffer
;
199 unsigned buffer_size
;
200 /* linked list of queries */
201 struct list_head list
;
204 #define R600_QUERY_STATE_STARTED (1 << 0)
205 #define R600_QUERY_STATE_ENDED (1 << 1)
206 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
209 struct r600_context
{
210 struct radeon
*radeon
;
213 struct r600_range range
[256];
215 struct r600_block
**blocks
;
216 unsigned pm4_ndwords
;
217 unsigned pm4_cdwords
;
218 unsigned pm4_dirty_cdwords
;
219 unsigned ctx_pm4_ndwords
;
222 struct r600_reloc
*reloc
;
223 struct radeon_bo
**bo
;
225 struct list_head query_list
;
226 unsigned num_query_running
;
231 u32 vgt_num_instances
;
233 u32 vgt_draw_initiator
;
234 u32 indices_bo_offset
;
235 struct radeon_ws_bo
*indices
;
238 int r600_context_init(struct r600_context
*ctx
, struct radeon
*radeon
);
239 void r600_context_fini(struct r600_context
*ctx
);
240 void r600_context_pipe_state_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
);
241 void r600_context_pipe_state_set_ps_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
242 void r600_context_pipe_state_set_vs_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
243 void r600_context_pipe_state_set_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
244 void r600_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
245 void r600_context_flush(struct r600_context
*ctx
);
246 void r600_context_dump_bof(struct r600_context
*ctx
, const char *file
);
247 void r600_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
249 struct r600_query
*r600_context_query_create(struct r600_context
*ctx
, unsigned query_type
);
250 void r600_context_query_destroy(struct r600_context
*ctx
, struct r600_query
*query
);
251 boolean
r600_context_query_result(struct r600_context
*ctx
,
252 struct r600_query
*query
,
253 boolean wait
, void *vresult
);
254 void r600_query_begin(struct r600_context
*ctx
, struct r600_query
*query
);
255 void r600_query_end(struct r600_context
*ctx
, struct r600_query
*query
);
256 void r600_context_queries_suspend(struct r600_context
*ctx
);
257 void r600_context_queries_resume(struct r600_context
*ctx
);
259 int evergreen_context_init(struct r600_context
*ctx
, struct radeon
*radeon
);
260 void evergreen_context_draw(struct r600_context
*ctx
, const struct r600_draw
*draw
);
261 void evergreen_ps_resource_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
262 void evergreen_vs_resource_set(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
264 void evergreen_context_pipe_state_set_ps_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
265 void evergreen_context_pipe_state_set_vs_resource(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned rid
);
266 void evergreen_context_pipe_state_set_ps_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);
267 void evergreen_context_pipe_state_set_vs_sampler(struct r600_context
*ctx
, struct r600_pipe_state
*state
, unsigned id
);