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 "util/u_blitter.h"
30 #include "util/u_slab.h"
32 #include "r600_llvm.h"
33 #include "r600_public.h"
34 #include "r600_resource.h"
35 #include "evergreen_compute.h"
37 #define R600_NUM_ATOMS 36
39 #define R600_MAX_CONST_BUFFERS 2
40 #define R600_MAX_CONST_BUFFER_SIZE 4096
42 #ifdef PIPE_ARCH_BIG_ENDIAN
43 #define R600_BIG_ENDIAN 1
45 #define R600_BIG_ENDIAN 0
48 struct r600_shader_key
;
50 /* This encapsulates a state or an operation which can emitted into the GPU
51 * command stream. It's not limited to states only, it can be used for anything
52 * that wants to write commands into the CS (e.g. cache flushes). */
54 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
);
60 /* This is an atom containing GPU commands that never change.
61 * This is supposed to be copied directly into the CS. */
62 struct r600_command_buffer
{
69 struct r600_db_misc_state
{
70 struct r600_atom atom
;
71 bool occlusion_query_enabled
;
72 bool flush_depthstencil_through_cb
;
73 bool copy_depth
, copy_stencil
;
76 unsigned db_shader_control
;
79 struct r600_cb_misc_state
{
80 struct r600_atom atom
;
81 unsigned cb_color_control
; /* this comes from blend state */
82 unsigned blend_colormask
; /* 8*4 bits for 8 RGBA colorbuffers */
84 unsigned nr_ps_color_outputs
;
89 struct r600_clip_misc_state
{
90 struct r600_atom atom
;
91 unsigned pa_cl_clip_cntl
; /* from rasterizer */
92 unsigned pa_cl_vs_out_cntl
; /* from vertex shader */
93 unsigned clip_plane_enable
; /* from rasterizer */
94 unsigned clip_dist_write
; /* from vertex shader */
97 struct r600_alphatest_state
{
98 struct r600_atom atom
;
99 unsigned sx_alpha_test_control
; /* this comes from dsa state */
100 unsigned sx_alpha_ref
; /* this comes from dsa state */
102 bool cb0_export_16bpc
; /* from set_framebuffer_state */
105 struct r600_vgt_state
{
106 struct r600_atom atom
;
107 uint32_t vgt_multi_prim_ib_reset_en
;
108 uint32_t vgt_multi_prim_ib_reset_indx
;
111 struct r600_vgt2_state
{
112 struct r600_atom atom
;
113 uint32_t vgt_indx_offset
;
116 struct r600_blend_color
{
117 struct r600_atom atom
;
118 struct pipe_blend_color state
;
121 struct r600_clip_state
{
122 struct r600_atom atom
;
123 struct pipe_clip_state state
;
126 struct r600_cs_shader_state
{
127 struct r600_atom atom
;
128 unsigned kernel_index
;
129 struct r600_pipe_compute
*shader
;
132 struct r600_framebuffer
{
133 struct r600_atom atom
;
134 struct pipe_framebuffer_state state
;
135 unsigned compressed_cb_mask
;
139 bool is_msaa_resolve
;
142 struct r600_sample_mask
{
143 struct r600_atom atom
;
144 uint16_t sample_mask
; /* there are only 8 bits on EG, 16 bits on Cayman */
147 struct r600_config_state
{
148 struct r600_atom atom
;
149 unsigned sq_gpr_resource_mgmt_1
;
152 struct r600_stencil_ref
159 struct r600_stencil_ref_state
{
160 struct r600_atom atom
;
161 struct r600_stencil_ref state
;
162 struct pipe_stencil_ref pipe_state
;
165 struct r600_viewport_state
{
166 struct r600_atom atom
;
167 struct pipe_viewport_state state
;
170 struct compute_memory_pool
;
171 void compute_memory_pool_delete(struct compute_memory_pool
* pool
);
172 struct compute_memory_pool
* compute_memory_pool_new(
173 struct r600_screen
*rscreen
);
175 struct r600_pipe_fences
{
176 struct r600_resource
*bo
;
179 /* linked list of preallocated blocks */
180 struct list_head blocks
;
181 /* linked list of freed fences */
182 struct list_head pool
;
187 struct pipe_screen screen
;
188 struct radeon_winsys
*ws
;
190 enum chip_class chip_class
;
191 struct radeon_info info
;
193 struct r600_tiling_info tiling_info
;
194 struct r600_pipe_fences fences
;
196 /*for compute global memory binding, we allocate stuff here, instead of
198 * XXX: Not sure if this is the best place for global_pool. Also,
199 * it's not thread safe, so it won't work with multiple contexts. */
200 struct compute_memory_pool
*global_pool
;
203 struct r600_pipe_sampler_view
{
204 struct pipe_sampler_view base
;
205 struct r600_resource
*tex_resource
;
206 uint32_t tex_resource_words
[8];
209 struct r600_rasterizer_state
{
210 struct r600_command_buffer buffer
;
213 unsigned sprite_coord_enable
;
214 unsigned clip_plane_enable
;
215 unsigned pa_sc_line_stipple
;
216 unsigned pa_cl_clip_cntl
;
221 bool multisample_enable
;
224 struct r600_poly_offset_state
{
225 struct r600_atom atom
;
226 enum pipe_format zs_format
;
231 struct r600_blend_state
{
232 struct r600_command_buffer buffer
;
233 struct r600_command_buffer buffer_no_blend
;
234 unsigned cb_target_mask
;
235 unsigned cb_color_control
;
236 unsigned cb_color_control_no_blend
;
241 struct r600_dsa_state
{
242 struct r600_command_buffer buffer
;
246 unsigned sx_alpha_test_control
;
249 struct r600_pipe_shader
;
251 struct r600_pipe_shader_selector
{
252 struct r600_pipe_shader
*current
;
254 struct tgsi_token
*tokens
;
255 struct pipe_stream_output_info so
;
257 unsigned num_shaders
;
259 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
262 unsigned nr_ps_max_color_exports
;
265 struct r600_pipe_sampler_state
{
266 uint32_t tex_sampler_words
[3];
267 union pipe_color_union border_color
;
268 bool border_color_use
;
269 bool seamless_cube_map
;
272 /* needed for blitter save */
273 #define NUM_TEX_UNITS 16
275 struct r600_seamless_cube_map
{
276 struct r600_atom atom
;
280 struct r600_samplerview_state
{
281 struct r600_atom atom
;
282 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
283 uint32_t enabled_mask
;
285 uint32_t compressed_depthtex_mask
; /* which textures are depth */
286 uint32_t compressed_colortex_mask
;
289 struct r600_sampler_states
{
290 struct r600_atom atom
;
291 struct r600_pipe_sampler_state
*states
[NUM_TEX_UNITS
];
292 uint32_t enabled_mask
;
294 uint32_t has_bordercolor_mask
; /* which states contain the border color */
297 struct r600_textures_info
{
298 struct r600_samplerview_state views
;
299 struct r600_sampler_states states
;
300 bool is_array_sampler
[NUM_TEX_UNITS
];
304 struct pipe_reference reference
;
305 unsigned index
; /* in the shared bo */
306 struct r600_resource
*sleep_bo
;
307 struct list_head head
;
310 #define FENCE_BLOCK_SIZE 16
312 struct r600_fence_block
{
313 struct r600_fence fences
[FENCE_BLOCK_SIZE
];
314 struct list_head head
;
317 #define R600_CONSTANT_ARRAY_SIZE 256
318 #define R600_RESOURCE_ARRAY_SIZE 160
320 struct r600_constbuf_state
322 struct r600_atom atom
;
323 struct pipe_constant_buffer cb
[PIPE_MAX_CONSTANT_BUFFERS
];
324 uint32_t enabled_mask
;
328 struct r600_vertexbuf_state
330 struct r600_atom atom
;
331 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
332 uint32_t enabled_mask
; /* non-NULL buffers */
336 /* CSO (constant state object, in other words, immutable state). */
337 struct r600_cso_state
339 struct r600_atom atom
;
340 void *cso
; /* e.g. r600_blend_state */
341 struct r600_command_buffer
*cb
;
344 struct r600_scissor_state
346 struct r600_atom atom
;
347 struct pipe_scissor_state scissor
;
348 bool enable
; /* r6xx only */
351 struct r600_context
{
352 struct pipe_context context
;
353 struct r600_screen
*screen
;
354 struct radeon_winsys
*ws
;
355 struct radeon_winsys_cs
*cs
;
356 struct blitter_context
*blitter
;
357 struct u_upload_mgr
*uploader
;
358 struct util_slab_mempool pool_transfers
;
361 enum radeon_family family
;
362 enum chip_class chip_class
;
363 boolean has_vertex_cache
;
364 boolean keep_tiling_flags
;
365 unsigned default_ps_gprs
, default_vs_gprs
;
366 unsigned r6xx_num_clause_temp_gprs
;
367 unsigned backend_mask
;
368 unsigned max_db
; /* for OQ */
370 /* Miscellaneous state objects. */
371 void *custom_dsa_flush
;
372 void *custom_blend_resolve
;
373 void *custom_blend_decompress
;
374 /* With rasterizer discard, there doesn't have to be a pixel shader.
375 * In that case, we bind this one: */
376 void *dummy_pixel_shader
;
377 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
378 * bug where valid CMASK and FMASK are required to be present to avoid
379 * a hardlock in certain operations but aren't actually used
380 * for anything useful. */
381 struct r600_resource
*dummy_fmask
;
382 struct r600_resource
*dummy_cmask
;
384 /* State binding slots are here. */
385 struct r600_atom
*atoms
[R600_NUM_ATOMS
];
386 /* States for CS initialization. */
387 struct r600_command_buffer start_cs_cmd
; /* invariant state mostly */
388 /** Compute specific registers initializations. The start_cs_cmd atom
389 * must be emitted before start_compute_cs_cmd. */
390 struct r600_command_buffer start_compute_cs_cmd
;
391 /* Register states. */
392 struct r600_alphatest_state alphatest_state
;
393 struct r600_cso_state blend_state
;
394 struct r600_blend_color blend_color
;
395 struct r600_cb_misc_state cb_misc_state
;
396 struct r600_clip_misc_state clip_misc_state
;
397 struct r600_clip_state clip_state
;
398 struct r600_db_misc_state db_misc_state
;
399 struct r600_cso_state dsa_state
;
400 struct r600_framebuffer framebuffer
;
401 struct r600_poly_offset_state poly_offset_state
;
402 struct r600_cso_state rasterizer_state
;
403 struct r600_sample_mask sample_mask
;
404 struct r600_scissor_state scissor
;
405 struct r600_seamless_cube_map seamless_cube_map
;
406 struct r600_config_state config_state
;
407 struct r600_stencil_ref_state stencil_ref
;
408 struct r600_vgt_state vgt_state
;
409 struct r600_vgt2_state vgt2_state
;
410 struct r600_viewport_state viewport
;
411 /* Shaders and shader resources. */
412 struct r600_cso_state vertex_fetch_shader
;
413 struct r600_cs_shader_state cs_shader_state
;
414 struct r600_constbuf_state constbuf_state
[PIPE_SHADER_TYPES
];
415 struct r600_textures_info samplers
[PIPE_SHADER_TYPES
];
416 /** Vertex buffers for fetch shaders */
417 struct r600_vertexbuf_state vertex_buffer_state
;
418 /** Vertex buffers for compute shaders */
419 struct r600_vertexbuf_state cs_vertex_buffer_state
;
421 /* Additional context states. */
423 unsigned compute_cb_target_mask
;
424 struct r600_pipe_shader_selector
*ps_shader
;
425 struct r600_pipe_shader_selector
*vs_shader
;
426 struct r600_rasterizer_state
*rasterizer
;
428 bool force_blend_disable
;
429 boolean dual_src_blend
;
432 struct pipe_index_buffer index_buffer
;
434 /* Last draw state (-1 = unset). */
435 int last_primitive_type
; /* Last primitive type used in draw_vbo. */
436 int last_start_instance
;
439 /* The list of active queries. Only one query of each type can be active. */
440 int num_occlusion_queries
;
441 /* Manage queries in two separate groups:
442 * The timer ones and the others (streamout, occlusion).
444 * We do this because we should only suspend non-timer queries for u_blitter,
445 * and later if the non-timer queries are suspended, the context flush should
446 * only suspend and resume the timer queries. */
447 struct list_head active_timer_queries
;
448 unsigned num_cs_dw_timer_queries_suspend
;
449 struct list_head active_nontimer_queries
;
450 unsigned num_cs_dw_nontimer_queries_suspend
;
451 /* Flags if queries have been suspended. */
452 bool timer_queries_suspended
;
453 bool nontimer_queries_suspended
;
455 /* Render condition. */
456 struct pipe_query
*current_render_cond
;
457 unsigned current_render_cond_mode
;
458 boolean predicate_drawing
;
460 /* Streamout state. */
461 unsigned num_cs_dw_streamout_end
;
462 unsigned num_so_targets
;
463 struct r600_so_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
464 boolean streamout_start
;
465 unsigned streamout_append_bitmask
;
466 bool streamout_suspended
;
468 /* Deprecated state management. */
469 struct r600_range
*range
;
471 struct r600_block
**blocks
;
472 struct list_head dirty
;
473 struct list_head enable_list
;
474 unsigned pm4_dirty_cdwords
;
477 static INLINE
void r600_emit_command_buffer(struct radeon_winsys_cs
*cs
,
478 struct r600_command_buffer
*cb
)
480 assert(cs
->cdw
+ cb
->num_dw
<= RADEON_MAX_CMDBUF_DWORDS
);
481 memcpy(cs
->buf
+ cs
->cdw
, cb
->buf
, 4 * cb
->num_dw
);
482 cs
->cdw
+= cb
->num_dw
;
485 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
487 atom
->emit(rctx
, atom
);
491 static INLINE
void r600_set_cso_state(struct r600_cso_state
*state
, void *cso
)
494 state
->atom
.dirty
= cso
!= NULL
;
497 static INLINE
void r600_set_cso_state_with_cb(struct r600_cso_state
*state
, void *cso
,
498 struct r600_command_buffer
*cb
)
501 state
->atom
.num_dw
= cb
->num_dw
;
502 r600_set_cso_state(state
, cso
);
505 /* evergreen_state.c */
506 struct pipe_sampler_view
*
507 evergreen_create_sampler_view_custom(struct pipe_context
*ctx
,
508 struct pipe_resource
*texture
,
509 const struct pipe_sampler_view
*state
,
510 unsigned width0
, unsigned height0
);
511 void evergreen_init_common_regs(struct r600_command_buffer
*cb
,
512 enum chip_class ctx_chip_class
,
513 enum radeon_family ctx_family
,
516 void evergreen_init_state_functions(struct r600_context
*rctx
);
517 void evergreen_init_atom_start_cs(struct r600_context
*rctx
);
518 void evergreen_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
519 void evergreen_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
520 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
);
521 void *evergreen_create_resolve_blend(struct r600_context
*rctx
);
522 void *evergreen_create_decompress_blend(struct r600_context
*rctx
);
523 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
524 enum pipe_format format
,
525 enum pipe_texture_target target
,
526 unsigned sample_count
,
528 void evergreen_init_color_surface(struct r600_context
*rctx
,
529 struct r600_surface
*surf
);
530 void evergreen_init_color_surface_rat(struct r600_context
*rctx
,
531 struct r600_surface
*surf
);
532 void evergreen_update_db_shader_control(struct r600_context
* rctx
);
535 void r600_copy_buffer(struct pipe_context
*ctx
, struct
536 pipe_resource
*dst
, unsigned dstx
,
537 struct pipe_resource
*src
, const struct pipe_box
*src_box
);
538 void r600_init_blit_functions(struct r600_context
*rctx
);
539 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
540 struct r600_texture
*texture
,
541 struct r600_texture
*staging
,
542 unsigned first_level
, unsigned last_level
,
543 unsigned first_layer
, unsigned last_layer
,
544 unsigned first_sample
, unsigned last_sample
);
545 void r600_decompress_depth_textures(struct r600_context
*rctx
,
546 struct r600_samplerview_state
*textures
);
547 void r600_decompress_color_textures(struct r600_context
*rctx
,
548 struct r600_samplerview_state
*textures
);
551 bool r600_init_resource(struct r600_screen
*rscreen
,
552 struct r600_resource
*res
,
553 unsigned size
, unsigned alignment
,
554 unsigned bind
, unsigned usage
);
555 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
556 const struct pipe_resource
*templ
,
560 void r600_flush(struct pipe_context
*ctx
, struct pipe_fence_handle
**fence
,
564 void r600_init_query_functions(struct r600_context
*rctx
);
565 void r600_suspend_nontimer_queries(struct r600_context
*ctx
);
566 void r600_resume_nontimer_queries(struct r600_context
*ctx
);
567 void r600_suspend_timer_queries(struct r600_context
*ctx
);
568 void r600_resume_timer_queries(struct r600_context
*ctx
);
570 /* r600_resource.c */
571 void r600_init_context_resource_functions(struct r600_context
*r600
);
574 int r600_pipe_shader_create(struct pipe_context
*ctx
,
575 struct r600_pipe_shader
*shader
,
576 struct r600_shader_key key
);
578 int r600_compute_shader_create(struct pipe_context
* ctx
,
579 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
);
581 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
584 struct pipe_sampler_view
*
585 r600_create_sampler_view_custom(struct pipe_context
*ctx
,
586 struct pipe_resource
*texture
,
587 const struct pipe_sampler_view
*state
,
588 unsigned width_first_level
, unsigned height_first_level
);
589 void r600_init_state_functions(struct r600_context
*rctx
);
590 void r600_init_atom_start_cs(struct r600_context
*rctx
);
591 void r600_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
592 void r600_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
593 void *r600_create_db_flush_dsa(struct r600_context
*rctx
);
594 void *r600_create_resolve_blend(struct r600_context
*rctx
);
595 void *r700_create_resolve_blend(struct r600_context
*rctx
);
596 void *r600_create_decompress_blend(struct r600_context
*rctx
);
597 void r600_adjust_gprs(struct r600_context
*rctx
);
598 boolean
r600_is_format_supported(struct pipe_screen
*screen
,
599 enum pipe_format format
,
600 enum pipe_texture_target target
,
601 unsigned sample_count
,
603 void r600_update_db_shader_control(struct r600_context
* rctx
);
606 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
607 void r600_init_surface_functions(struct r600_context
*r600
);
608 uint32_t r600_translate_texformat(struct pipe_screen
*screen
, enum pipe_format format
,
609 const unsigned char *swizzle_view
,
610 uint32_t *word4_p
, uint32_t *yuv_format_p
);
611 unsigned r600_texture_get_offset(struct r600_texture
*rtex
,
612 unsigned level
, unsigned layer
);
613 struct pipe_surface
*r600_create_surface_custom(struct pipe_context
*pipe
,
614 struct pipe_resource
*texture
,
615 const struct pipe_surface
*templ
,
616 unsigned width
, unsigned height
);
618 /* r600_state_common.c */
619 void r600_init_common_state_functions(struct r600_context
*rctx
);
620 void r600_emit_cso_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
621 void r600_emit_alphatest_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
622 void r600_emit_blend_color(struct r600_context
*rctx
, struct r600_atom
*atom
);
623 void r600_emit_vgt_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
624 void r600_emit_vgt2_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
625 void r600_emit_clip_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
626 void r600_emit_stencil_ref(struct r600_context
*rctx
, struct r600_atom
*atom
);
627 void r600_emit_viewport_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
628 void r600_init_atom(struct r600_context
*rctx
, struct r600_atom
*atom
, unsigned id
,
629 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
631 void r600_vertex_buffers_dirty(struct r600_context
*rctx
);
632 void r600_sampler_views_dirty(struct r600_context
*rctx
,
633 struct r600_samplerview_state
*state
);
634 void r600_sampler_states_dirty(struct r600_context
*rctx
,
635 struct r600_sampler_states
*state
);
636 void r600_constant_buffers_dirty(struct r600_context
*rctx
, struct r600_constbuf_state
*state
);
637 void r600_draw_rectangle(struct blitter_context
*blitter
,
638 int x1
, int y1
, int x2
, int y2
, float depth
,
639 enum blitter_attrib_type type
, const union pipe_color_union
*attrib
);
640 uint32_t r600_translate_stencil_op(int s_op
);
641 uint32_t r600_translate_fill(uint32_t func
);
642 unsigned r600_tex_wrap(unsigned wrap
);
643 unsigned r600_tex_filter(unsigned filter
);
644 unsigned r600_tex_mipfilter(unsigned filter
);
645 unsigned r600_tex_compare(unsigned compare
);
648 * Helpers for building command buffers
651 #define PKT3_SET_CONFIG_REG 0x68
652 #define PKT3_SET_CONTEXT_REG 0x69
653 #define PKT3_SET_CTL_CONST 0x6F
654 #define PKT3_SET_LOOP_CONST 0x6C
656 #define R600_CONFIG_REG_OFFSET 0x08000
657 #define R600_CONTEXT_REG_OFFSET 0x28000
658 #define R600_CTL_CONST_OFFSET 0x3CFF0
659 #define R600_LOOP_CONST_OFFSET 0X0003E200
660 #define EG_LOOP_CONST_OFFSET 0x0003A200
662 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
663 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
664 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
665 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
666 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
668 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
670 /*Evergreen Compute packet3*/
671 #define PKT3C(op, count, predicate) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count) | PKT3_PREDICATE(predicate) | RADEON_CP_PACKET3_COMPUTE_MODE)
673 static INLINE
void r600_store_value(struct r600_command_buffer
*cb
, unsigned value
)
675 cb
->buf
[cb
->num_dw
++] = value
;
678 static INLINE
void r600_store_config_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
680 assert(reg
< R600_CONTEXT_REG_OFFSET
);
681 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
682 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
683 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
687 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
690 static INLINE
void r600_store_context_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
692 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
693 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
694 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0) | cb
->pkt_flags
;
695 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
699 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
702 static INLINE
void r600_store_ctl_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
704 assert(reg
>= R600_CTL_CONST_OFFSET
);
705 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
706 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0) | cb
->pkt_flags
;
707 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
710 static INLINE
void r600_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
712 assert(reg
>= R600_LOOP_CONST_OFFSET
);
713 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
714 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
715 cb
->buf
[cb
->num_dw
++] = (reg
- R600_LOOP_CONST_OFFSET
) >> 2;
719 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
722 static INLINE
void eg_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
724 assert(reg
>= EG_LOOP_CONST_OFFSET
);
725 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
726 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0) | cb
->pkt_flags
;
727 cb
->buf
[cb
->num_dw
++] = (reg
- EG_LOOP_CONST_OFFSET
) >> 2;
730 static INLINE
void r600_store_config_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
732 r600_store_config_reg_seq(cb
, reg
, 1);
733 r600_store_value(cb
, value
);
736 static INLINE
void r600_store_context_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
738 r600_store_context_reg_seq(cb
, reg
, 1);
739 r600_store_value(cb
, value
);
742 static INLINE
void r600_store_ctl_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
744 r600_store_ctl_const_seq(cb
, reg
, 1);
745 r600_store_value(cb
, value
);
748 static INLINE
void r600_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
750 r600_store_loop_const_seq(cb
, reg
, 1);
751 r600_store_value(cb
, value
);
754 static INLINE
void eg_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
756 eg_store_loop_const_seq(cb
, reg
, 1);
757 r600_store_value(cb
, value
);
760 void r600_init_command_buffer(struct r600_command_buffer
*cb
, unsigned num_dw
);
761 void r600_release_command_buffer(struct r600_command_buffer
*cb
);
764 * Helpers for emitting state into a command stream directly.
767 static INLINE
unsigned r600_context_bo_reloc(struct r600_context
*ctx
, struct r600_resource
*rbo
,
768 enum radeon_bo_usage usage
)
771 return ctx
->ws
->cs_add_reloc(ctx
->cs
, rbo
->cs_buf
, usage
, rbo
->domains
) * 4;
774 static INLINE
void r600_write_value(struct radeon_winsys_cs
*cs
, unsigned value
)
776 cs
->buf
[cs
->cdw
++] = value
;
779 static INLINE
void r600_write_array(struct radeon_winsys_cs
*cs
, unsigned num
, unsigned *ptr
)
781 assert(cs
->cdw
+num
<= RADEON_MAX_CMDBUF_DWORDS
);
782 memcpy(&cs
->buf
[cs
->cdw
], ptr
, num
* sizeof(ptr
[0]));
786 static INLINE
void r600_write_config_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
788 assert(reg
< R600_CONTEXT_REG_OFFSET
);
789 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
790 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
791 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
794 static INLINE
void r600_write_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
796 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
797 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
798 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0);
799 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
802 static INLINE
void r600_write_compute_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
804 r600_write_context_reg_seq(cs
, reg
, num
);
805 /* Set the compute bit on the packet header */
806 cs
->buf
[cs
->cdw
- 2] |= RADEON_CP_PACKET3_COMPUTE_MODE
;
809 static INLINE
void r600_write_ctl_const_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
811 assert(reg
>= R600_CTL_CONST_OFFSET
);
812 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
813 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
814 cs
->buf
[cs
->cdw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
817 static INLINE
void r600_write_config_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
819 r600_write_config_reg_seq(cs
, reg
, 1);
820 r600_write_value(cs
, value
);
823 static INLINE
void r600_write_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
825 r600_write_context_reg_seq(cs
, reg
, 1);
826 r600_write_value(cs
, value
);
829 static INLINE
void r600_write_compute_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
831 r600_write_compute_context_reg_seq(cs
, reg
, 1);
832 r600_write_value(cs
, value
);
835 static INLINE
void r600_write_ctl_const(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
837 r600_write_ctl_const_seq(cs
, reg
, 1);
838 r600_write_value(cs
, value
);
844 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
846 return value
* (1 << frac_bits
);
848 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
850 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
852 if (filter
<= 1) return 0;
853 if (filter
<= 2) return 1;
854 if (filter
<= 4) return 2;
855 if (filter
<= 8) return 3;
859 /* 12.4 fixed-point */
860 static INLINE
unsigned r600_pack_float_12p4(float x
)
863 x
>= 4096 ? 0xffff : x
* 16;
866 static INLINE
uint64_t r600_resource_va(struct pipe_screen
*screen
, struct pipe_resource
*resource
)
868 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
869 struct r600_resource
*rresource
= (struct r600_resource
*)resource
;
871 return rscreen
->ws
->buffer_get_virtual_address(rresource
->cs_buf
);