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.
29 #include "../../winsys/radeon/drm/radeon_winsys.h"
31 #include "pipe/p_state.h"
32 #include "pipe/p_screen.h"
33 #include "pipe/p_context.h"
34 #include "util/u_math.h"
35 #include "util/u_slab.h"
36 #include "util/u_vbuf.h"
38 #include "r600_public.h"
39 #include "r600_shader.h"
40 #include "r600_resource.h"
42 #define R600_MAX_CONST_BUFFERS 2
43 #define R600_MAX_CONST_BUFFER_SIZE 4096
45 #ifdef PIPE_ARCH_BIG_ENDIAN
46 #define R600_BIG_ENDIAN 1
48 #define R600_BIG_ENDIAN 0
51 enum r600_atom_flags
{
52 /* When set, atoms are added at the beginning of the dirty list
53 * instead of the end. */
57 /* This encapsulates a state or an operation which can emitted into the GPU
58 * command stream. It's not limited to states only, it can be used for anything
59 * that wants to write commands into the CS (e.g. cache flushes). */
61 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
);
64 enum r600_atom_flags flags
;
67 struct list_head head
;
70 /* This is an atom containing GPU commands that never change.
71 * This is supposed to be copied directly into the CS. */
72 struct r600_command_buffer
{
73 struct r600_atom atom
;
78 struct r600_atom_surface_sync
{
79 struct r600_atom atom
;
80 unsigned flush_flags
; /* CP_COHER_CNTL */
83 struct r600_atom_db_misc_state
{
84 struct r600_atom atom
;
85 bool occlusion_query_enabled
;
86 bool flush_depthstencil_enabled
;
89 enum r600_pipe_state_id
{
90 R600_PIPE_STATE_BLEND
= 0,
91 R600_PIPE_STATE_BLEND_COLOR
,
92 R600_PIPE_STATE_CONFIG
,
93 R600_PIPE_STATE_SEAMLESS_CUBEMAP
,
95 R600_PIPE_STATE_SCISSOR
,
96 R600_PIPE_STATE_VIEWPORT
,
97 R600_PIPE_STATE_RASTERIZER
,
99 R600_PIPE_STATE_FRAMEBUFFER
,
101 R600_PIPE_STATE_STENCIL_REF
,
102 R600_PIPE_STATE_PS_SHADER
,
103 R600_PIPE_STATE_VS_SHADER
,
104 R600_PIPE_STATE_CONSTANT
,
105 R600_PIPE_STATE_SAMPLER
,
106 R600_PIPE_STATE_RESOURCE
,
107 R600_PIPE_STATE_POLYGON_OFFSET
,
108 R600_PIPE_STATE_FETCH_SHADER
,
112 struct r600_pipe_fences
{
113 struct r600_resource
*bo
;
116 /* linked list of preallocated blocks */
117 struct list_head blocks
;
118 /* linked list of freed fences */
119 struct list_head pool
;
124 struct pipe_screen screen
;
125 struct radeon_winsys
*ws
;
127 enum chip_class chip_class
;
128 struct radeon_info info
;
129 struct r600_tiling_info tiling_info
;
130 struct util_slab_mempool pool_buffers
;
131 struct r600_pipe_fences fences
;
133 unsigned num_contexts
;
134 bool use_surface_alloc
;
136 /* for thread-safe write accessing to num_contexts */
137 pipe_mutex mutex_num_contexts
;
140 struct r600_pipe_sampler_view
{
141 struct pipe_sampler_view base
;
142 struct r600_pipe_resource_state state
;
145 struct r600_pipe_rasterizer
{
146 struct r600_pipe_state rstate
;
149 unsigned sprite_coord_enable
;
150 unsigned clip_plane_enable
;
151 unsigned pa_sc_line_stipple
;
152 unsigned pa_cl_clip_cntl
;
158 struct r600_pipe_blend
{
159 struct r600_pipe_state rstate
;
160 unsigned cb_target_mask
;
161 unsigned cb_color_control
;
164 struct r600_pipe_dsa
{
165 struct r600_pipe_state rstate
;
172 struct r600_vertex_element
175 struct pipe_vertex_element elements
[PIPE_MAX_ATTRIBS
];
176 struct u_vbuf_elements
*vmgr_elements
;
177 struct r600_resource
*fetch_shader
;
179 struct r600_pipe_state rstate
;
180 /* if offset is to big for fetch instructio we need to alterate
181 * offset of vertex buffer, record here the offset need to add
183 unsigned vbuffer_need_offset
;
184 unsigned vbuffer_offset
[PIPE_MAX_ATTRIBS
];
187 struct r600_pipe_shader
{
188 struct r600_shader shader
;
189 struct r600_pipe_state rstate
;
190 struct r600_resource
*bo
;
191 struct r600_resource
*bo_fetch
;
192 struct r600_vertex_element vertex_elements
;
193 struct tgsi_token
*tokens
;
194 unsigned sprite_coord_enable
;
196 unsigned pa_cl_vs_out_cntl
;
197 struct pipe_stream_output_info so
;
200 struct r600_pipe_sampler_state
{
201 struct r600_pipe_state rstate
;
202 boolean seamless_cube_map
;
205 /* needed for blitter save */
206 #define NUM_TEX_UNITS 16
208 struct r600_textures_info
{
209 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
210 struct r600_pipe_sampler_state
*samplers
[NUM_TEX_UNITS
];
214 bool is_array_sampler
[NUM_TEX_UNITS
];
218 struct pipe_reference reference
;
219 unsigned index
; /* in the shared bo */
220 struct r600_resource
*sleep_bo
;
221 struct list_head head
;
224 #define FENCE_BLOCK_SIZE 16
226 struct r600_fence_block
{
227 struct r600_fence fences
[FENCE_BLOCK_SIZE
];
228 struct list_head head
;
231 #define R600_CONSTANT_ARRAY_SIZE 256
232 #define R600_RESOURCE_ARRAY_SIZE 160
234 struct r600_stencil_ref
241 struct r600_context
{
242 struct pipe_context context
;
243 struct blitter_context
*blitter
;
244 enum radeon_family family
;
245 enum chip_class chip_class
;
246 unsigned r6xx_num_clause_temp_gprs
;
247 void *custom_dsa_flush
;
248 struct r600_screen
*screen
;
249 struct radeon_winsys
*ws
;
250 struct r600_pipe_state
*states
[R600_PIPE_NSTATES
];
251 struct r600_vertex_element
*vertex_elements
;
252 struct r600_pipe_resource_state fs_resource
[PIPE_MAX_ATTRIBS
];
253 struct pipe_framebuffer_state framebuffer
;
254 unsigned cb_target_mask
;
255 unsigned cb_color_control
;
256 unsigned pa_sc_line_stipple
;
257 unsigned pa_cl_clip_cntl
;
258 /* for saving when using blitter */
259 struct pipe_stencil_ref stencil_ref
;
260 struct pipe_viewport_state viewport
;
261 struct pipe_clip_state clip
;
262 struct r600_pipe_shader
*ps_shader
;
263 struct r600_pipe_shader
*vs_shader
;
264 struct r600_pipe_state vs_const_buffer
;
265 struct r600_pipe_resource_state vs_const_buffer_resource
[R600_MAX_CONST_BUFFERS
];
266 struct r600_pipe_state ps_const_buffer
;
267 struct r600_pipe_resource_state ps_const_buffer_resource
[R600_MAX_CONST_BUFFERS
];
268 struct r600_pipe_rasterizer
*rasterizer
;
269 struct r600_pipe_state vgt
;
270 struct r600_pipe_state spi
;
271 struct pipe_query
*current_render_cond
;
272 unsigned current_render_cond_mode
;
273 struct pipe_query
*saved_render_cond
;
274 unsigned saved_render_cond_mode
;
275 /* shader information */
277 unsigned sprite_coord_enable
;
278 boolean export_16bpc
;
280 boolean alpha_ref_dirty
;
282 struct r600_textures_info vs_samplers
;
283 struct r600_textures_info ps_samplers
;
285 struct u_vbuf
*vbuf_mgr
;
286 struct util_slab_mempool pool_transfers
;
287 boolean have_depth_texture
, have_depth_fb
;
289 unsigned default_ps_gprs
, default_vs_gprs
;
291 /* States based on r600_state. */
292 struct list_head dirty_states
;
293 struct r600_command_buffer atom_start_cs
; /* invariant state mostly */
294 struct r600_atom_surface_sync atom_surface_sync
;
295 struct r600_atom atom_r6xx_flush_and_inv
;
296 struct r600_atom_db_misc_state atom_db_misc_state
;
298 /* Below are variables from the old r600_context.
300 struct radeon_winsys_cs
*cs
;
302 struct r600_range
*range
;
304 struct r600_block
**blocks
;
305 struct list_head dirty
;
306 struct list_head resource_dirty
;
307 struct list_head enable_list
;
308 unsigned pm4_dirty_cdwords
;
309 unsigned ctx_pm4_ndwords
;
311 /* The list of active queries. Only one query of each type can be active. */
312 int num_occlusion_queries
;
314 /* Manage queries in two separate groups:
315 * The timer ones and the others (streamout, occlusion).
317 * We do this because we should only suspend non-timer queries for u_blitter,
318 * and later if the non-timer queries are suspended, the context flush should
319 * only suspend and resume the timer queries. */
320 struct list_head active_timer_queries
;
321 unsigned num_cs_dw_timer_queries_suspend
;
322 struct list_head active_nontimer_queries
;
323 unsigned num_cs_dw_nontimer_queries_suspend
;
325 unsigned num_cs_dw_streamout_end
;
327 unsigned backend_mask
;
328 unsigned max_db
; /* for OQ */
330 boolean predicate_drawing
;
331 struct r600_range ps_resources
;
332 struct r600_range vs_resources
;
333 struct r600_range fs_resources
;
334 int num_ps_resources
, num_vs_resources
, num_fs_resources
;
336 unsigned num_so_targets
;
337 struct r600_so_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
338 boolean streamout_start
;
339 unsigned streamout_append_bitmask
;
341 /* There is no scissor enable bit on r6xx, so we must use a workaround.
342 * These track the current scissor state. */
344 struct pipe_scissor_state scissor_state
;
347 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
349 atom
->emit(rctx
, atom
);
351 if (atom
->head
.next
&& atom
->head
.prev
)
352 LIST_DELINIT(&atom
->head
);
355 static INLINE
void r600_atom_dirty(struct r600_context
*rctx
, struct r600_atom
*state
)
358 if (state
->flags
& EMIT_EARLY
) {
359 LIST_ADD(&state
->head
, &rctx
->dirty_states
);
361 LIST_ADDTAIL(&state
->head
, &rctx
->dirty_states
);
367 /* evergreen_state.c */
368 void evergreen_init_state_functions(struct r600_context
*rctx
);
369 void evergreen_init_atom_start_cs(struct r600_context
*rctx
);
370 void evergreen_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
371 void evergreen_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
372 void evergreen_fetch_shader(struct pipe_context
*ctx
, struct r600_vertex_element
*ve
);
373 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
);
374 void evergreen_polygon_offset_update(struct r600_context
*rctx
);
375 void evergreen_pipe_init_buffer_resource(struct r600_context
*rctx
,
376 struct r600_pipe_resource_state
*rstate
);
377 void evergreen_pipe_mod_buffer_resource(struct pipe_context
*ctx
,
378 struct r600_pipe_resource_state
*rstate
,
379 struct r600_resource
*rbuffer
,
380 unsigned offset
, unsigned stride
,
381 enum radeon_bo_usage usage
);
382 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
383 enum pipe_format format
,
384 enum pipe_texture_target target
,
385 unsigned sample_count
,
389 void r600_init_blit_functions(struct r600_context
*rctx
);
390 void r600_blit_uncompress_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
391 void r600_blit_push_depth(struct pipe_context
*ctx
, struct r600_resource_texture
*texture
);
392 void r600_flush_depth_textures(struct r600_context
*rctx
);
395 bool r600_init_resource(struct r600_screen
*rscreen
,
396 struct r600_resource
*res
,
397 unsigned size
, unsigned alignment
,
398 unsigned bind
, unsigned usage
);
399 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
400 const struct pipe_resource
*templ
);
401 struct pipe_resource
*r600_user_buffer_create(struct pipe_screen
*screen
,
402 void *ptr
, unsigned bytes
,
404 void r600_upload_index_buffer(struct r600_context
*rctx
,
405 struct pipe_index_buffer
*ib
, unsigned count
);
409 void r600_flush(struct pipe_context
*ctx
, struct pipe_fence_handle
**fence
,
413 void r600_init_query_functions(struct r600_context
*rctx
);
414 void r600_suspend_nontimer_queries(struct r600_context
*ctx
);
415 void r600_resume_nontimer_queries(struct r600_context
*ctx
);
416 void r600_suspend_timer_queries(struct r600_context
*ctx
);
417 void r600_resume_timer_queries(struct r600_context
*ctx
);
419 /* r600_resource.c */
420 void r600_init_context_resource_functions(struct r600_context
*r600
);
423 int r600_pipe_shader_create(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
424 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
425 int r600_find_vs_semantic_index(struct r600_shader
*vs
,
426 struct r600_shader
*ps
, int id
);
429 void r600_set_scissor_state(struct r600_context
*rctx
,
430 const struct pipe_scissor_state
*state
);
431 void r600_update_sampler_states(struct r600_context
*rctx
);
432 void r600_init_state_functions(struct r600_context
*rctx
);
433 void r600_init_atom_start_cs(struct r600_context
*rctx
);
434 void r600_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
435 void r600_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
436 void r600_fetch_shader(struct pipe_context
*ctx
, struct r600_vertex_element
*ve
);
437 void *r600_create_db_flush_dsa(struct r600_context
*rctx
);
438 void r600_polygon_offset_update(struct r600_context
*rctx
);
439 void r600_pipe_init_buffer_resource(struct r600_context
*rctx
,
440 struct r600_pipe_resource_state
*rstate
);
441 void r600_pipe_mod_buffer_resource(struct r600_pipe_resource_state
*rstate
,
442 struct r600_resource
*rbuffer
,
443 unsigned offset
, unsigned stride
,
444 enum radeon_bo_usage usage
);
445 void r600_adjust_gprs(struct r600_context
*rctx
);
446 boolean
r600_is_format_supported(struct pipe_screen
*screen
,
447 enum pipe_format format
,
448 enum pipe_texture_target target
,
449 unsigned sample_count
,
453 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
454 void r600_init_surface_functions(struct r600_context
*r600
);
455 uint32_t r600_translate_texformat(struct pipe_screen
*screen
, enum pipe_format format
,
456 const unsigned char *swizzle_view
,
457 uint32_t *word4_p
, uint32_t *yuv_format_p
);
458 unsigned r600_texture_get_offset(struct r600_resource_texture
*rtex
,
459 unsigned level
, unsigned layer
);
461 /* r600_translate.c */
462 void r600_translate_index_buffer(struct r600_context
*r600
,
463 struct pipe_index_buffer
*ib
,
466 /* r600_state_common.c */
467 void r600_init_atom(struct r600_atom
*atom
,
468 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
469 unsigned num_dw
, enum r600_atom_flags flags
);
470 void r600_init_common_atoms(struct r600_context
*rctx
);
471 unsigned r600_get_cb_flush_flags(struct r600_context
*rctx
);
472 void r600_texture_barrier(struct pipe_context
*ctx
);
473 void r600_set_index_buffer(struct pipe_context
*ctx
,
474 const struct pipe_index_buffer
*ib
);
475 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
476 const struct pipe_vertex_buffer
*buffers
);
477 void *r600_create_vertex_elements(struct pipe_context
*ctx
,
479 const struct pipe_vertex_element
*elements
);
480 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
);
481 void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
);
482 void r600_set_blend_color(struct pipe_context
*ctx
,
483 const struct pipe_blend_color
*state
);
484 void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
);
485 void r600_set_max_scissor(struct r600_context
*rctx
);
486 void r600_bind_rs_state(struct pipe_context
*ctx
, void *state
);
487 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
);
488 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
489 struct pipe_sampler_view
*state
);
490 void r600_delete_state(struct pipe_context
*ctx
, void *state
);
491 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
);
492 void *r600_create_shader_state(struct pipe_context
*ctx
,
493 const struct pipe_shader_state
*state
);
494 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
);
495 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
);
496 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
);
497 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
);
498 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
499 struct pipe_resource
*buffer
);
500 struct pipe_stream_output_target
*
501 r600_create_so_target(struct pipe_context
*ctx
,
502 struct pipe_resource
*buffer
,
503 unsigned buffer_offset
,
504 unsigned buffer_size
);
505 void r600_so_target_destroy(struct pipe_context
*ctx
,
506 struct pipe_stream_output_target
*target
);
507 void r600_set_so_targets(struct pipe_context
*ctx
,
508 unsigned num_targets
,
509 struct pipe_stream_output_target
**targets
,
510 unsigned append_bitmask
);
511 void r600_set_pipe_stencil_ref(struct pipe_context
*ctx
,
512 const struct pipe_stencil_ref
*state
);
513 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
);
514 uint32_t r600_translate_stencil_op(int s_op
);
515 uint32_t r600_translate_fill(uint32_t func
);
516 unsigned r600_tex_wrap(unsigned wrap
);
517 unsigned r600_tex_filter(unsigned filter
);
518 unsigned r600_tex_mipfilter(unsigned filter
);
519 unsigned r600_tex_compare(unsigned compare
);
522 * Helpers for building command buffers
525 #define PKT3_SET_CONFIG_REG 0x68
526 #define PKT3_SET_CONTEXT_REG 0x69
527 #define PKT3_SET_CTL_CONST 0x6F
528 #define PKT3_SET_LOOP_CONST 0x6C
530 #define R600_CONFIG_REG_OFFSET 0x08000
531 #define R600_CONTEXT_REG_OFFSET 0x28000
532 #define R600_CTL_CONST_OFFSET 0x3CFF0
533 #define R600_LOOP_CONST_OFFSET 0X0003E200
534 #define EG_LOOP_CONST_OFFSET 0x0003A200
536 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
537 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
538 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
539 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
540 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
542 static INLINE
void r600_store_value(struct r600_command_buffer
*cb
, unsigned value
)
544 cb
->buf
[cb
->atom
.num_dw
++] = value
;
547 static INLINE
void r600_store_config_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
549 assert(reg
< R600_CONTEXT_REG_OFFSET
);
550 assert(cb
->atom
.num_dw
+2+num
<= cb
->max_num_dw
);
551 cb
->buf
[cb
->atom
.num_dw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
552 cb
->buf
[cb
->atom
.num_dw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
555 static INLINE
void r600_store_context_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
557 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
558 assert(cb
->atom
.num_dw
+2+num
<= cb
->max_num_dw
);
559 cb
->buf
[cb
->atom
.num_dw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0);
560 cb
->buf
[cb
->atom
.num_dw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
563 static INLINE
void r600_store_ctl_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
565 assert(reg
>= R600_CTL_CONST_OFFSET
);
566 assert(cb
->atom
.num_dw
+2+num
<= cb
->max_num_dw
);
567 cb
->buf
[cb
->atom
.num_dw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
568 cb
->buf
[cb
->atom
.num_dw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
571 static INLINE
void r600_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
573 assert(reg
>= R600_LOOP_CONST_OFFSET
);
574 assert(cb
->atom
.num_dw
+2+num
<= cb
->max_num_dw
);
575 cb
->buf
[cb
->atom
.num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
576 cb
->buf
[cb
->atom
.num_dw
++] = (reg
- R600_LOOP_CONST_OFFSET
) >> 2;
579 static INLINE
void eg_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
581 assert(reg
>= EG_LOOP_CONST_OFFSET
);
582 assert(cb
->atom
.num_dw
+2+num
<= cb
->max_num_dw
);
583 cb
->buf
[cb
->atom
.num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
584 cb
->buf
[cb
->atom
.num_dw
++] = (reg
- EG_LOOP_CONST_OFFSET
) >> 2;
587 static INLINE
void r600_store_config_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
589 r600_store_config_reg_seq(cb
, reg
, 1);
590 r600_store_value(cb
, value
);
593 static INLINE
void r600_store_context_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
595 r600_store_context_reg_seq(cb
, reg
, 1);
596 r600_store_value(cb
, value
);
599 static INLINE
void r600_store_ctl_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
601 r600_store_ctl_const_seq(cb
, reg
, 1);
602 r600_store_value(cb
, value
);
605 static INLINE
void r600_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
607 r600_store_loop_const_seq(cb
, reg
, 1);
608 r600_store_value(cb
, value
);
611 static INLINE
void eg_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
613 eg_store_loop_const_seq(cb
, reg
, 1);
614 r600_store_value(cb
, value
);
617 void r600_init_command_buffer(struct r600_command_buffer
*cb
, unsigned num_dw
, enum r600_atom_flags flags
);
618 void r600_release_command_buffer(struct r600_command_buffer
*cb
);
621 * Helpers for emitting state into a command stream directly.
624 static INLINE
void r600_write_value(struct radeon_winsys_cs
*cs
, unsigned value
)
626 cs
->buf
[cs
->cdw
++] = value
;
629 static INLINE
void r600_write_config_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
631 assert(reg
< R600_CONTEXT_REG_OFFSET
);
632 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
633 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
634 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
637 static INLINE
void r600_write_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
639 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
640 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
641 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0);
642 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
645 static INLINE
void r600_write_ctl_const_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
647 assert(reg
>= R600_CTL_CONST_OFFSET
);
648 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
649 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
650 cs
->buf
[cs
->cdw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
653 static INLINE
void r600_write_config_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
655 r600_write_config_reg_seq(cs
, reg
, 1);
656 r600_write_value(cs
, value
);
659 static INLINE
void r600_write_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
661 r600_write_context_reg_seq(cs
, reg
, 1);
662 r600_write_value(cs
, value
);
665 static INLINE
void r600_write_ctl_const(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
667 r600_write_ctl_const_seq(cs
, reg
, 1);
668 r600_write_value(cs
, value
);
674 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
676 return value
* (1 << frac_bits
);
678 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
680 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
682 if (filter
<= 1) return 0;
683 if (filter
<= 2) return 1;
684 if (filter
<= 4) return 2;
685 if (filter
<= 8) return 3;
689 /* 12.4 fixed-point */
690 static INLINE
unsigned r600_pack_float_12p4(float x
)
693 x
>= 4096 ? 0xffff : x
* 16;