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 "../radeon/r600_pipe_common.h"
30 #include "../radeon/r600_cs.h"
32 #include "r600_llvm.h"
33 #include "r600_public.h"
35 #include "util/u_blitter.h"
36 #include "util/u_suballoc.h"
37 #include "util/u_double_list.h"
38 #include "util/u_transfer.h"
40 #define R600_NUM_ATOMS 73
42 /* the number of CS dwords for flushing and drawing */
43 #define R600_MAX_FLUSH_CS_DWORDS 16
44 #define R600_MAX_DRAW_CS_DWORDS 37
45 #define R600_TRACE_CS_DWORDS 7
47 #define R600_MAX_USER_CONST_BUFFERS 13
48 #define R600_MAX_DRIVER_CONST_BUFFERS 4
49 #define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
51 /* start driver buffers after user buffers */
52 #define R600_UCP_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
53 #define R600_TXQ_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
54 #define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
55 #define R600_GS_RING_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 3)
57 #define R600_MAX_CONST_BUFFER_SIZE 4096
59 #ifdef PIPE_ARCH_BIG_ENDIAN
60 #define R600_BIG_ENDIAN 1
62 #define R600_BIG_ENDIAN 0
67 struct r600_shader_key
;
69 /* This is an atom containing GPU commands that never change.
70 * This is supposed to be copied directly into the CS. */
71 struct r600_command_buffer
{
78 struct r600_db_state
{
79 struct r600_atom atom
;
80 struct r600_surface
*rsurf
;
83 struct r600_db_misc_state
{
84 struct r600_atom atom
;
85 bool occlusion_query_enabled
;
86 bool flush_depthstencil_through_cb
;
87 bool flush_depthstencil_in_place
;
88 bool copy_depth
, copy_stencil
;
91 unsigned db_shader_control
;
95 struct r600_cb_misc_state
{
96 struct r600_atom atom
;
97 unsigned cb_color_control
; /* this comes from blend state */
98 unsigned blend_colormask
; /* 8*4 bits for 8 RGBA colorbuffers */
100 unsigned nr_ps_color_outputs
;
105 struct r600_clip_misc_state
{
106 struct r600_atom atom
;
107 unsigned pa_cl_clip_cntl
; /* from rasterizer */
108 unsigned pa_cl_vs_out_cntl
; /* from vertex shader */
109 unsigned clip_plane_enable
; /* from rasterizer */
110 unsigned clip_dist_write
; /* from vertex shader */
111 boolean clip_disable
; /* from vertex shader */
114 struct r600_alphatest_state
{
115 struct r600_atom atom
;
116 unsigned sx_alpha_test_control
; /* this comes from dsa state */
117 unsigned sx_alpha_ref
; /* this comes from dsa state */
119 bool cb0_export_16bpc
; /* from set_framebuffer_state */
122 struct r600_vgt_state
{
123 struct r600_atom atom
;
124 uint32_t vgt_multi_prim_ib_reset_en
;
125 uint32_t vgt_multi_prim_ib_reset_indx
;
126 uint32_t vgt_indx_offset
;
129 struct r600_blend_color
{
130 struct r600_atom atom
;
131 struct pipe_blend_color state
;
134 struct r600_clip_state
{
135 struct r600_atom atom
;
136 struct pipe_clip_state state
;
139 struct r600_cs_shader_state
{
140 struct r600_atom atom
;
141 unsigned kernel_index
;
142 struct r600_pipe_compute
*shader
;
145 struct r600_framebuffer
{
146 struct r600_atom atom
;
147 struct pipe_framebuffer_state state
;
148 unsigned compressed_cb_mask
;
152 bool is_msaa_resolve
;
155 struct r600_sample_mask
{
156 struct r600_atom atom
;
157 uint16_t sample_mask
; /* there are only 8 bits on EG, 16 bits on Cayman */
160 struct r600_config_state
{
161 struct r600_atom atom
;
162 unsigned sq_gpr_resource_mgmt_1
;
163 unsigned sq_gpr_resource_mgmt_2
;
166 struct r600_stencil_ref
173 struct r600_stencil_ref_state
{
174 struct r600_atom atom
;
175 struct r600_stencil_ref state
;
176 struct pipe_stencil_ref pipe_state
;
179 struct r600_viewport_state
{
180 struct r600_atom atom
;
181 struct pipe_viewport_state state
;
185 struct r600_shader_stages_state
{
186 struct r600_atom atom
;
187 unsigned geom_enable
;
190 struct r600_gs_rings_state
{
191 struct r600_atom atom
;
193 struct pipe_constant_buffer esgs_ring
;
194 struct pipe_constant_buffer gsvs_ring
;
197 /* This must start from 16. */
199 #define DBG_LLVM (1 << 17)
200 #define DBG_NO_CP_DMA (1 << 18)
202 #define DBG_NO_SB (1 << 21)
203 #define DBG_SB_CS (1 << 22)
204 #define DBG_SB_DRY_RUN (1 << 23)
205 #define DBG_SB_STAT (1 << 24)
206 #define DBG_SB_DUMP (1 << 25)
207 #define DBG_SB_NO_FALLBACK (1 << 26)
208 #define DBG_SB_DISASM (1 << 27)
209 #define DBG_SB_SAFEMATH (1 << 28)
212 struct r600_common_screen b
;
214 bool has_compressed_msaa_texturing
;
216 /*for compute global memory binding, we allocate stuff here, instead of
218 * XXX: Not sure if this is the best place for global_pool. Also,
219 * it's not thread safe, so it won't work with multiple contexts. */
220 struct compute_memory_pool
*global_pool
;
223 struct r600_pipe_sampler_view
{
224 struct pipe_sampler_view base
;
225 struct r600_resource
*tex_resource
;
226 uint32_t tex_resource_words
[8];
227 bool skip_mip_address_reloc
;
230 struct r600_rasterizer_state
{
231 struct r600_command_buffer buffer
;
234 unsigned sprite_coord_enable
;
235 unsigned clip_plane_enable
;
236 unsigned pa_sc_line_stipple
;
237 unsigned pa_cl_clip_cntl
;
238 unsigned pa_su_sc_mode_cntl
;
243 bool multisample_enable
;
246 struct r600_poly_offset_state
{
247 struct r600_atom atom
;
248 enum pipe_format zs_format
;
253 struct r600_blend_state
{
254 struct r600_command_buffer buffer
;
255 struct r600_command_buffer buffer_no_blend
;
256 unsigned cb_target_mask
;
257 unsigned cb_color_control
;
258 unsigned cb_color_control_no_blend
;
263 struct r600_dsa_state
{
264 struct r600_command_buffer buffer
;
269 unsigned sx_alpha_test_control
;
272 struct r600_pipe_shader
;
274 struct r600_pipe_shader_selector
{
275 struct r600_pipe_shader
*current
;
277 struct tgsi_token
*tokens
;
278 struct pipe_stream_output_info so
;
280 unsigned num_shaders
;
282 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
285 unsigned nr_ps_max_color_exports
;
288 struct r600_pipe_sampler_state
{
289 uint32_t tex_sampler_words
[3];
290 union pipe_color_union border_color
;
291 bool border_color_use
;
292 bool seamless_cube_map
;
295 /* needed for blitter save */
296 #define NUM_TEX_UNITS 16
298 struct r600_seamless_cube_map
{
299 struct r600_atom atom
;
303 struct r600_samplerview_state
{
304 struct r600_atom atom
;
305 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
306 uint32_t enabled_mask
;
308 uint32_t compressed_depthtex_mask
; /* which textures are depth */
309 uint32_t compressed_colortex_mask
;
310 boolean dirty_txq_constants
;
311 boolean dirty_buffer_constants
;
314 struct r600_sampler_states
{
315 struct r600_atom atom
;
316 struct r600_pipe_sampler_state
*states
[NUM_TEX_UNITS
];
317 uint32_t enabled_mask
;
319 uint32_t has_bordercolor_mask
; /* which states contain the border color */
322 struct r600_textures_info
{
323 struct r600_samplerview_state views
;
324 struct r600_sampler_states states
;
325 bool is_array_sampler
[NUM_TEX_UNITS
];
327 /* cube array txq workaround */
328 uint32_t *txq_constants
;
329 /* buffer related workarounds */
330 uint32_t *buffer_constants
;
333 struct r600_constbuf_state
335 struct r600_atom atom
;
336 struct pipe_constant_buffer cb
[PIPE_MAX_CONSTANT_BUFFERS
];
337 uint32_t enabled_mask
;
341 struct r600_vertexbuf_state
343 struct r600_atom atom
;
344 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
345 uint32_t enabled_mask
; /* non-NULL buffers */
349 /* CSO (constant state object, in other words, immutable state). */
350 struct r600_cso_state
352 struct r600_atom atom
;
353 void *cso
; /* e.g. r600_blend_state */
354 struct r600_command_buffer
*cb
;
357 struct r600_scissor_state
359 struct r600_atom atom
;
360 struct pipe_scissor_state scissor
;
361 bool enable
; /* r6xx only */
365 struct r600_fetch_shader
{
366 struct r600_resource
*buffer
;
370 struct r600_shader_state
{
371 struct r600_atom atom
;
372 struct r600_pipe_shader
*shader
;
375 struct r600_context
{
376 struct r600_common_context b
;
377 struct r600_screen
*screen
;
378 struct blitter_context
*blitter
;
379 struct u_suballocator
*allocator_fetch_shader
;
382 boolean has_vertex_cache
;
383 boolean keep_tiling_flags
;
384 unsigned default_ps_gprs
, default_vs_gprs
;
385 unsigned r6xx_num_clause_temp_gprs
;
387 /* Miscellaneous state objects. */
388 void *custom_dsa_flush
;
389 void *custom_blend_resolve
;
390 void *custom_blend_decompress
;
391 void *custom_blend_fastclear
;
392 /* With rasterizer discard, there doesn't have to be a pixel shader.
393 * In that case, we bind this one: */
394 void *dummy_pixel_shader
;
395 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
396 * bug where valid CMASK and FMASK are required to be present to avoid
397 * a hardlock in certain operations but aren't actually used
398 * for anything useful. */
399 struct r600_resource
*dummy_fmask
;
400 struct r600_resource
*dummy_cmask
;
402 /* State binding slots are here. */
403 struct r600_atom
*atoms
[R600_NUM_ATOMS
];
404 /* States for CS initialization. */
405 struct r600_command_buffer start_cs_cmd
; /* invariant state mostly */
406 /** Compute specific registers initializations. The start_cs_cmd atom
407 * must be emitted before start_compute_cs_cmd. */
408 struct r600_command_buffer start_compute_cs_cmd
;
409 /* Register states. */
410 struct r600_alphatest_state alphatest_state
;
411 struct r600_cso_state blend_state
;
412 struct r600_blend_color blend_color
;
413 struct r600_cb_misc_state cb_misc_state
;
414 struct r600_clip_misc_state clip_misc_state
;
415 struct r600_clip_state clip_state
;
416 struct r600_db_misc_state db_misc_state
;
417 struct r600_db_state db_state
;
418 struct r600_cso_state dsa_state
;
419 struct r600_framebuffer framebuffer
;
420 struct r600_poly_offset_state poly_offset_state
;
421 struct r600_cso_state rasterizer_state
;
422 struct r600_sample_mask sample_mask
;
423 struct r600_scissor_state scissor
[16];
424 struct r600_seamless_cube_map seamless_cube_map
;
425 struct r600_config_state config_state
;
426 struct r600_stencil_ref_state stencil_ref
;
427 struct r600_vgt_state vgt_state
;
428 struct r600_viewport_state viewport
[16];
429 /* Shaders and shader resources. */
430 struct r600_cso_state vertex_fetch_shader
;
431 struct r600_shader_state vertex_shader
;
432 struct r600_shader_state pixel_shader
;
433 struct r600_shader_state geometry_shader
;
434 struct r600_shader_state export_shader
;
435 struct r600_cs_shader_state cs_shader_state
;
436 struct r600_shader_stages_state shader_stages
;
437 struct r600_gs_rings_state gs_rings
;
438 struct r600_constbuf_state constbuf_state
[PIPE_SHADER_TYPES
];
439 struct r600_textures_info samplers
[PIPE_SHADER_TYPES
];
440 /** Vertex buffers for fetch shaders */
441 struct r600_vertexbuf_state vertex_buffer_state
;
442 /** Vertex buffers for compute shaders */
443 struct r600_vertexbuf_state cs_vertex_buffer_state
;
445 /* Additional context states. */
446 unsigned compute_cb_target_mask
;
447 struct r600_pipe_shader_selector
*ps_shader
;
448 struct r600_pipe_shader_selector
*vs_shader
;
449 struct r600_pipe_shader_selector
*gs_shader
;
450 struct r600_rasterizer_state
*rasterizer
;
452 bool force_blend_disable
;
453 boolean dual_src_blend
;
457 struct pipe_index_buffer index_buffer
;
459 /* Last draw state (-1 = unset). */
460 int last_primitive_type
; /* Last primitive type used in draw_vbo. */
461 int last_start_instance
;
464 struct r600_isa
*isa
;
467 static INLINE
void r600_emit_command_buffer(struct radeon_winsys_cs
*cs
,
468 struct r600_command_buffer
*cb
)
470 assert(cs
->cdw
+ cb
->num_dw
<= RADEON_MAX_CMDBUF_DWORDS
);
471 memcpy(cs
->buf
+ cs
->cdw
, cb
->buf
, 4 * cb
->num_dw
);
472 cs
->cdw
+= cb
->num_dw
;
475 void r600_trace_emit(struct r600_context
*rctx
);
477 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
479 atom
->emit(&rctx
->b
, atom
);
481 if (rctx
->screen
->b
.trace_bo
) {
482 r600_trace_emit(rctx
);
486 static INLINE
void r600_set_cso_state(struct r600_cso_state
*state
, void *cso
)
489 state
->atom
.dirty
= cso
!= NULL
;
492 static INLINE
void r600_set_cso_state_with_cb(struct r600_cso_state
*state
, void *cso
,
493 struct r600_command_buffer
*cb
)
496 state
->atom
.num_dw
= cb
? cb
->num_dw
: 0;
497 r600_set_cso_state(state
, cso
);
500 /* compute_memory_pool.c */
501 struct compute_memory_pool
;
502 void compute_memory_pool_delete(struct compute_memory_pool
* pool
);
503 struct compute_memory_pool
* compute_memory_pool_new(
504 struct r600_screen
*rscreen
);
506 /* evergreen_compute.c */
507 void evergreen_set_cs_sampler_view(struct pipe_context
*ctx_
,
508 unsigned start_slot
, unsigned count
,
509 struct pipe_sampler_view
**views
);
511 /* evergreen_state.c */
512 struct pipe_sampler_view
*
513 evergreen_create_sampler_view_custom(struct pipe_context
*ctx
,
514 struct pipe_resource
*texture
,
515 const struct pipe_sampler_view
*state
,
516 unsigned width0
, unsigned height0
,
517 unsigned force_level
);
518 void evergreen_init_common_regs(struct r600_command_buffer
*cb
,
519 enum chip_class ctx_chip_class
,
520 enum radeon_family ctx_family
,
522 void cayman_init_common_regs(struct r600_command_buffer
*cb
,
523 enum chip_class ctx_chip_class
,
524 enum radeon_family ctx_family
,
527 void evergreen_init_state_functions(struct r600_context
*rctx
);
528 void evergreen_init_atom_start_cs(struct r600_context
*rctx
);
529 void evergreen_update_ps_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
530 void evergreen_update_es_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
531 void evergreen_update_gs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
532 void evergreen_update_vs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
533 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
);
534 void *evergreen_create_resolve_blend(struct r600_context
*rctx
);
535 void *evergreen_create_decompress_blend(struct r600_context
*rctx
);
536 void *evergreen_create_fastclear_blend(struct r600_context
*rctx
);
537 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
538 enum pipe_format format
,
539 enum pipe_texture_target target
,
540 unsigned sample_count
,
542 void evergreen_init_color_surface(struct r600_context
*rctx
,
543 struct r600_surface
*surf
);
544 void evergreen_init_color_surface_rat(struct r600_context
*rctx
,
545 struct r600_surface
*surf
);
546 void evergreen_update_db_shader_control(struct r600_context
* rctx
);
549 void r600_init_blit_functions(struct r600_context
*rctx
);
550 void r600_decompress_depth_textures(struct r600_context
*rctx
,
551 struct r600_samplerview_state
*textures
);
552 void r600_decompress_color_textures(struct r600_context
*rctx
,
553 struct r600_samplerview_state
*textures
);
556 int r600_pipe_shader_create(struct pipe_context
*ctx
,
557 struct r600_pipe_shader
*shader
,
558 struct r600_shader_key key
);
560 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
563 struct pipe_sampler_view
*
564 r600_create_sampler_view_custom(struct pipe_context
*ctx
,
565 struct pipe_resource
*texture
,
566 const struct pipe_sampler_view
*state
,
567 unsigned width_first_level
, unsigned height_first_level
);
568 void r600_init_state_functions(struct r600_context
*rctx
);
569 void r600_init_atom_start_cs(struct r600_context
*rctx
);
570 void r600_update_ps_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
571 void r600_update_es_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
572 void r600_update_gs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
573 void r600_update_vs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
574 void *r600_create_db_flush_dsa(struct r600_context
*rctx
);
575 void *r600_create_resolve_blend(struct r600_context
*rctx
);
576 void *r700_create_resolve_blend(struct r600_context
*rctx
);
577 void *r600_create_decompress_blend(struct r600_context
*rctx
);
578 bool r600_adjust_gprs(struct r600_context
*rctx
);
579 boolean
r600_is_format_supported(struct pipe_screen
*screen
,
580 enum pipe_format format
,
581 enum pipe_texture_target target
,
582 unsigned sample_count
,
584 void r600_update_db_shader_control(struct r600_context
* rctx
);
586 /* r600_hw_context.c */
587 void r600_context_gfx_flush(void *context
, unsigned flags
,
588 struct pipe_fence_handle
**fence
);
589 void r600_begin_new_cs(struct r600_context
*ctx
);
590 void r600_flush_emit(struct r600_context
*ctx
);
591 void r600_need_cs_space(struct r600_context
*ctx
, unsigned num_dw
, boolean count_draw_in
);
592 void r600_cp_dma_copy_buffer(struct r600_context
*rctx
,
593 struct pipe_resource
*dst
, uint64_t dst_offset
,
594 struct pipe_resource
*src
, uint64_t src_offset
,
596 void evergreen_cp_dma_clear_buffer(struct r600_context
*rctx
,
597 struct pipe_resource
*dst
, uint64_t offset
,
598 unsigned size
, uint32_t clear_value
);
599 void r600_dma_copy_buffer(struct r600_context
*rctx
,
600 struct pipe_resource
*dst
,
601 struct pipe_resource
*src
,
607 * evergreen_hw_context.c
609 void evergreen_dma_copy_buffer(struct r600_context
*rctx
,
610 struct pipe_resource
*dst
,
611 struct pipe_resource
*src
,
616 /* r600_state_common.c */
617 void r600_init_common_state_functions(struct r600_context
*rctx
);
618 void r600_emit_cso_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
619 void r600_emit_alphatest_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
620 void r600_emit_blend_color(struct r600_context
*rctx
, struct r600_atom
*atom
);
621 void r600_emit_vgt_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
622 void r600_emit_clip_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
623 void r600_emit_stencil_ref(struct r600_context
*rctx
, struct r600_atom
*atom
);
624 void r600_emit_viewport_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
625 void r600_emit_shader(struct r600_context
*rctx
, struct r600_atom
*a
);
626 void r600_init_atom(struct r600_context
*rctx
, struct r600_atom
*atom
, unsigned id
,
627 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
629 void r600_vertex_buffers_dirty(struct r600_context
*rctx
);
630 void r600_sampler_views_dirty(struct r600_context
*rctx
,
631 struct r600_samplerview_state
*state
);
632 void r600_sampler_states_dirty(struct r600_context
*rctx
,
633 struct r600_sampler_states
*state
);
634 void r600_constant_buffers_dirty(struct r600_context
*rctx
, struct r600_constbuf_state
*state
);
635 void r600_draw_rectangle(struct blitter_context
*blitter
,
636 int x1
, int y1
, int x2
, int y2
, float depth
,
637 enum blitter_attrib_type type
, const union pipe_color_union
*attrib
);
638 uint32_t r600_translate_stencil_op(int s_op
);
639 uint32_t r600_translate_fill(uint32_t func
);
640 unsigned r600_tex_wrap(unsigned wrap
);
641 unsigned r600_tex_filter(unsigned filter
);
642 unsigned r600_tex_mipfilter(unsigned filter
);
643 unsigned r600_tex_compare(unsigned compare
);
644 bool sampler_state_needs_border_color(const struct pipe_sampler_state
*state
);
645 struct pipe_surface
*r600_create_surface_custom(struct pipe_context
*pipe
,
646 struct pipe_resource
*texture
,
647 const struct pipe_surface
*templ
,
648 unsigned width
, unsigned height
);
649 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format
,
650 const unsigned char *swizzle_view
,
652 uint32_t r600_translate_texformat(struct pipe_screen
*screen
, enum pipe_format format
,
653 const unsigned char *swizzle_view
,
654 uint32_t *word4_p
, uint32_t *yuv_format_p
);
655 uint32_t r600_translate_colorformat(enum chip_class chip
, enum pipe_format format
);
656 uint32_t r600_colorformat_endian_swap(uint32_t colorformat
);
659 struct pipe_video_codec
*r600_uvd_create_decoder(struct pipe_context
*context
,
660 const struct pipe_video_codec
*decoder
);
662 struct pipe_video_buffer
*r600_video_buffer_create(struct pipe_context
*pipe
,
663 const struct pipe_video_buffer
*tmpl
);
666 * Helpers for building command buffers
669 #define PKT3_SET_CONFIG_REG 0x68
670 #define PKT3_SET_CONTEXT_REG 0x69
671 #define PKT3_SET_CTL_CONST 0x6F
672 #define PKT3_SET_LOOP_CONST 0x6C
674 #define R600_CONFIG_REG_OFFSET 0x08000
675 #define R600_CONTEXT_REG_OFFSET 0x28000
676 #define R600_CTL_CONST_OFFSET 0x3CFF0
677 #define R600_LOOP_CONST_OFFSET 0X0003E200
678 #define EG_LOOP_CONST_OFFSET 0x0003A200
680 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
681 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
682 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
683 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
684 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
686 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
688 /*Evergreen Compute packet3*/
689 #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)
691 static INLINE
void r600_store_value(struct r600_command_buffer
*cb
, unsigned value
)
693 cb
->buf
[cb
->num_dw
++] = value
;
696 static INLINE
void r600_store_array(struct r600_command_buffer
*cb
, unsigned num
, unsigned *ptr
)
698 assert(cb
->num_dw
+num
<= cb
->max_num_dw
);
699 memcpy(&cb
->buf
[cb
->num_dw
], ptr
, num
* sizeof(ptr
[0]));
703 static INLINE
void r600_store_config_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
705 assert(reg
< R600_CONTEXT_REG_OFFSET
);
706 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
707 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
708 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
712 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
715 static INLINE
void r600_store_context_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
717 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
718 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
719 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0) | cb
->pkt_flags
;
720 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
724 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
727 static INLINE
void r600_store_ctl_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
729 assert(reg
>= R600_CTL_CONST_OFFSET
);
730 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
731 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0) | cb
->pkt_flags
;
732 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
735 static INLINE
void r600_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
737 assert(reg
>= R600_LOOP_CONST_OFFSET
);
738 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
739 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
740 cb
->buf
[cb
->num_dw
++] = (reg
- R600_LOOP_CONST_OFFSET
) >> 2;
744 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
747 static INLINE
void eg_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
749 assert(reg
>= EG_LOOP_CONST_OFFSET
);
750 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
751 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0) | cb
->pkt_flags
;
752 cb
->buf
[cb
->num_dw
++] = (reg
- EG_LOOP_CONST_OFFSET
) >> 2;
755 static INLINE
void r600_store_config_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
757 r600_store_config_reg_seq(cb
, reg
, 1);
758 r600_store_value(cb
, value
);
761 static INLINE
void r600_store_context_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
763 r600_store_context_reg_seq(cb
, reg
, 1);
764 r600_store_value(cb
, value
);
767 static INLINE
void r600_store_ctl_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
769 r600_store_ctl_const_seq(cb
, reg
, 1);
770 r600_store_value(cb
, value
);
773 static INLINE
void r600_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
775 r600_store_loop_const_seq(cb
, reg
, 1);
776 r600_store_value(cb
, value
);
779 static INLINE
void eg_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
781 eg_store_loop_const_seq(cb
, reg
, 1);
782 r600_store_value(cb
, value
);
785 void r600_init_command_buffer(struct r600_command_buffer
*cb
, unsigned num_dw
);
786 void r600_release_command_buffer(struct r600_command_buffer
*cb
);
788 static INLINE
void r600_write_compute_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
790 r600_write_context_reg_seq(cs
, reg
, num
);
791 /* Set the compute bit on the packet header */
792 cs
->buf
[cs
->cdw
- 2] |= RADEON_CP_PACKET3_COMPUTE_MODE
;
795 static INLINE
void r600_write_ctl_const_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
797 assert(reg
>= R600_CTL_CONST_OFFSET
);
798 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
799 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
800 cs
->buf
[cs
->cdw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
803 static INLINE
void r600_write_compute_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
805 r600_write_compute_context_reg_seq(cs
, reg
, 1);
806 radeon_emit(cs
, value
);
809 static INLINE
void r600_write_context_reg_flag(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
, unsigned flag
)
811 if (flag
& RADEON_CP_PACKET3_COMPUTE_MODE
) {
812 r600_write_compute_context_reg(cs
, reg
, value
);
814 r600_write_context_reg(cs
, reg
, value
);
818 static INLINE
void r600_write_ctl_const(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
820 r600_write_ctl_const_seq(cs
, reg
, 1);
821 radeon_emit(cs
, value
);
827 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
829 return value
* (1 << frac_bits
);
831 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
833 /* 12.4 fixed-point */
834 static INLINE
unsigned r600_pack_float_12p4(float x
)
837 x
>= 4096 ? 0xffff : x
* 16;
840 /* Return if the depth format can be read without the DB->CB copy on r6xx-r7xx. */
841 static INLINE
bool r600_can_read_depth(struct r600_texture
*rtex
)
843 return rtex
->resource
.b
.b
.nr_samples
<= 1 &&
844 (rtex
->resource
.b
.b
.format
== PIPE_FORMAT_Z16_UNORM
||
845 rtex
->resource
.b
.b
.format
== PIPE_FORMAT_Z32_FLOAT
);
848 #define V_028A6C_OUTPRIM_TYPE_POINTLIST 0
849 #define V_028A6C_OUTPRIM_TYPE_LINESTRIP 1
850 #define V_028A6C_OUTPRIM_TYPE_TRISTRIP 2
852 static INLINE
unsigned r600_conv_prim_to_gs_out(unsigned mode
)
854 static const int prim_conv
[] = {
855 V_028A6C_OUTPRIM_TYPE_POINTLIST
,
856 V_028A6C_OUTPRIM_TYPE_LINESTRIP
,
857 V_028A6C_OUTPRIM_TYPE_LINESTRIP
,
858 V_028A6C_OUTPRIM_TYPE_LINESTRIP
,
859 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
860 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
861 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
862 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
863 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
864 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
865 V_028A6C_OUTPRIM_TYPE_LINESTRIP
,
866 V_028A6C_OUTPRIM_TYPE_LINESTRIP
,
867 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
868 V_028A6C_OUTPRIM_TYPE_TRISTRIP
,
869 V_028A6C_OUTPRIM_TYPE_TRISTRIP
871 assert(mode
< Elements(prim_conv
));
873 return prim_conv
[mode
];