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"
31 #include "util/u_suballoc.h"
33 #include "r600_llvm.h"
34 #include "r600_public.h"
35 #include "r600_resource.h"
36 #include "evergreen_compute.h"
38 #define R600_NUM_ATOMS 37
40 #define R600_TRACE_CS 0
42 #define R600_MAX_USER_CONST_BUFFERS 13
43 #define R600_MAX_DRIVER_CONST_BUFFERS 3
44 #define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
46 /* start driver buffers after user buffers */
47 #define R600_UCP_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
48 #define R600_TXQ_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
49 #define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
51 #define R600_MAX_CONST_BUFFER_SIZE 4096
53 #ifdef PIPE_ARCH_BIG_ENDIAN
54 #define R600_BIG_ENDIAN 1
56 #define R600_BIG_ENDIAN 0
59 #define R600_MAP_BUFFER_ALIGNMENT 64
62 struct r600_shader_key
;
64 /* This encapsulates a state or an operation which can emitted into the GPU
65 * command stream. It's not limited to states only, it can be used for anything
66 * that wants to write commands into the CS (e.g. cache flushes). */
68 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
);
74 /* This is an atom containing GPU commands that never change.
75 * This is supposed to be copied directly into the CS. */
76 struct r600_command_buffer
{
83 struct r600_db_state
{
84 struct r600_atom atom
;
85 struct r600_surface
*rsurf
;
88 struct r600_db_misc_state
{
89 struct r600_atom atom
;
90 bool occlusion_query_enabled
;
91 bool flush_depthstencil_through_cb
;
92 bool flush_depthstencil_in_place
;
93 bool copy_depth
, copy_stencil
;
96 unsigned db_shader_control
;
100 struct r600_cb_misc_state
{
101 struct r600_atom atom
;
102 unsigned cb_color_control
; /* this comes from blend state */
103 unsigned blend_colormask
; /* 8*4 bits for 8 RGBA colorbuffers */
105 unsigned nr_ps_color_outputs
;
110 struct r600_clip_misc_state
{
111 struct r600_atom atom
;
112 unsigned pa_cl_clip_cntl
; /* from rasterizer */
113 unsigned pa_cl_vs_out_cntl
; /* from vertex shader */
114 unsigned clip_plane_enable
; /* from rasterizer */
115 unsigned clip_dist_write
; /* from vertex shader */
118 struct r600_alphatest_state
{
119 struct r600_atom atom
;
120 unsigned sx_alpha_test_control
; /* this comes from dsa state */
121 unsigned sx_alpha_ref
; /* this comes from dsa state */
123 bool cb0_export_16bpc
; /* from set_framebuffer_state */
126 struct r600_vgt_state
{
127 struct r600_atom atom
;
128 uint32_t vgt_multi_prim_ib_reset_en
;
129 uint32_t vgt_multi_prim_ib_reset_indx
;
132 struct r600_vgt2_state
{
133 struct r600_atom atom
;
134 uint32_t vgt_indx_offset
;
137 struct r600_blend_color
{
138 struct r600_atom atom
;
139 struct pipe_blend_color state
;
142 struct r600_clip_state
{
143 struct r600_atom atom
;
144 struct pipe_clip_state state
;
147 struct r600_cs_shader_state
{
148 struct r600_atom atom
;
149 unsigned kernel_index
;
150 struct r600_pipe_compute
*shader
;
153 struct r600_framebuffer
{
154 struct r600_atom atom
;
155 struct pipe_framebuffer_state state
;
156 unsigned compressed_cb_mask
;
160 bool is_msaa_resolve
;
163 struct r600_sample_mask
{
164 struct r600_atom atom
;
165 uint16_t sample_mask
; /* there are only 8 bits on EG, 16 bits on Cayman */
168 struct r600_config_state
{
169 struct r600_atom atom
;
170 unsigned sq_gpr_resource_mgmt_1
;
173 struct r600_stencil_ref
180 struct r600_stencil_ref_state
{
181 struct r600_atom atom
;
182 struct r600_stencil_ref state
;
183 struct pipe_stencil_ref pipe_state
;
186 struct r600_viewport_state
{
187 struct r600_atom atom
;
188 struct pipe_viewport_state state
;
191 struct compute_memory_pool
;
192 void compute_memory_pool_delete(struct compute_memory_pool
* pool
);
193 struct compute_memory_pool
* compute_memory_pool_new(
194 struct r600_screen
*rscreen
);
196 struct r600_pipe_fences
{
197 struct r600_resource
*bo
;
200 /* linked list of preallocated blocks */
201 struct list_head blocks
;
202 /* linked list of freed fences */
203 struct list_head pool
;
207 enum r600_msaa_texture_mode
{
208 /* If the hw can fetch the first sample only (no decompression available).
209 * This means MSAA texturing is not fully implemented. */
210 MSAA_TEXTURE_SAMPLE_ZERO
,
212 /* If the hw can fetch decompressed MSAA textures.
213 * Supported families: R600, R700, Evergreen.
214 * Cayman cannot use this, because it cannot do the decompression. */
215 MSAA_TEXTURE_DECOMPRESSED
,
217 /* If the hw can fetch compressed MSAA textures, which means shaders can
218 * read resolved FMASK. This yields the best performance.
219 * Supported families: Evergreen, Cayman. */
220 MSAA_TEXTURE_COMPRESSED
223 typedef boolean (*r600g_dma_blit_t
)(struct pipe_context
*ctx
,
224 struct pipe_resource
*dst
,
226 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
227 struct pipe_resource
*src
,
229 const struct pipe_box
*src_box
);
232 struct pipe_screen screen
;
233 struct radeon_winsys
*ws
;
235 enum chip_class chip_class
;
236 struct radeon_info info
;
239 enum r600_msaa_texture_mode msaa_texture_support
;
241 struct r600_tiling_info tiling_info
;
242 struct r600_pipe_fences fences
;
244 /*for compute global memory binding, we allocate stuff here, instead of
246 * XXX: Not sure if this is the best place for global_pool. Also,
247 * it's not thread safe, so it won't work with multiple contexts. */
248 struct compute_memory_pool
*global_pool
;
250 struct r600_resource
*trace_bo
;
254 r600g_dma_blit_t dma_blit
;
257 struct r600_pipe_sampler_view
{
258 struct pipe_sampler_view base
;
259 struct r600_resource
*tex_resource
;
260 uint32_t tex_resource_words
[8];
261 bool skip_mip_address_reloc
;
264 struct r600_rasterizer_state
{
265 struct r600_command_buffer buffer
;
268 unsigned sprite_coord_enable
;
269 unsigned clip_plane_enable
;
270 unsigned pa_sc_line_stipple
;
271 unsigned pa_cl_clip_cntl
;
276 bool multisample_enable
;
279 struct r600_poly_offset_state
{
280 struct r600_atom atom
;
281 enum pipe_format zs_format
;
286 struct r600_blend_state
{
287 struct r600_command_buffer buffer
;
288 struct r600_command_buffer buffer_no_blend
;
289 unsigned cb_target_mask
;
290 unsigned cb_color_control
;
291 unsigned cb_color_control_no_blend
;
296 struct r600_dsa_state
{
297 struct r600_command_buffer buffer
;
302 unsigned sx_alpha_test_control
;
305 struct r600_pipe_shader
;
307 struct r600_pipe_shader_selector
{
308 struct r600_pipe_shader
*current
;
310 struct tgsi_token
*tokens
;
311 struct pipe_stream_output_info so
;
313 unsigned num_shaders
;
315 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
318 unsigned nr_ps_max_color_exports
;
321 struct r600_pipe_sampler_state
{
322 uint32_t tex_sampler_words
[3];
323 union pipe_color_union border_color
;
324 bool border_color_use
;
325 bool seamless_cube_map
;
328 /* needed for blitter save */
329 #define NUM_TEX_UNITS 16
331 struct r600_seamless_cube_map
{
332 struct r600_atom atom
;
336 struct r600_samplerview_state
{
337 struct r600_atom atom
;
338 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
339 uint32_t enabled_mask
;
341 uint32_t compressed_depthtex_mask
; /* which textures are depth */
342 uint32_t compressed_colortex_mask
;
343 boolean dirty_txq_constants
;
344 boolean dirty_buffer_constants
;
347 struct r600_sampler_states
{
348 struct r600_atom atom
;
349 struct r600_pipe_sampler_state
*states
[NUM_TEX_UNITS
];
350 uint32_t enabled_mask
;
352 uint32_t has_bordercolor_mask
; /* which states contain the border color */
355 struct r600_textures_info
{
356 struct r600_samplerview_state views
;
357 struct r600_sampler_states states
;
358 bool is_array_sampler
[NUM_TEX_UNITS
];
360 /* cube array txq workaround */
361 uint32_t *txq_constants
;
362 /* buffer related workarounds */
363 uint32_t *buffer_constants
;
367 struct pipe_reference reference
;
368 unsigned index
; /* in the shared bo */
369 struct r600_resource
*sleep_bo
;
370 struct list_head head
;
373 #define FENCE_BLOCK_SIZE 16
375 struct r600_fence_block
{
376 struct r600_fence fences
[FENCE_BLOCK_SIZE
];
377 struct list_head head
;
380 #define R600_CONSTANT_ARRAY_SIZE 256
381 #define R600_RESOURCE_ARRAY_SIZE 160
383 struct r600_constbuf_state
385 struct r600_atom atom
;
386 struct pipe_constant_buffer cb
[PIPE_MAX_CONSTANT_BUFFERS
];
387 uint32_t enabled_mask
;
391 struct r600_vertexbuf_state
393 struct r600_atom atom
;
394 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
395 uint32_t enabled_mask
; /* non-NULL buffers */
399 /* CSO (constant state object, in other words, immutable state). */
400 struct r600_cso_state
402 struct r600_atom atom
;
403 void *cso
; /* e.g. r600_blend_state */
404 struct r600_command_buffer
*cb
;
407 struct r600_scissor_state
409 struct r600_atom atom
;
410 struct pipe_scissor_state scissor
;
411 bool enable
; /* r6xx only */
414 struct r600_fetch_shader
{
415 struct r600_resource
*buffer
;
420 struct radeon_winsys_cs
*cs
;
422 void (*flush
)(void *ctx
, unsigned flags
);
426 struct r600_ring gfx
;
427 struct r600_ring dma
;
430 struct r600_context
{
431 struct pipe_context context
;
432 struct r600_screen
*screen
;
433 struct radeon_winsys
*ws
;
434 struct r600_rings rings
;
435 struct blitter_context
*blitter
;
436 struct u_upload_mgr
*uploader
;
437 struct u_suballocator
*allocator_so_filled_size
;
438 struct u_suballocator
*allocator_fetch_shader
;
439 struct util_slab_mempool pool_transfers
;
442 enum radeon_family family
;
443 enum chip_class chip_class
;
444 boolean has_vertex_cache
;
445 boolean keep_tiling_flags
;
446 unsigned default_ps_gprs
, default_vs_gprs
;
447 unsigned r6xx_num_clause_temp_gprs
;
448 unsigned backend_mask
;
449 unsigned max_db
; /* for OQ */
451 /* current unaccounted memory usage */
455 /* Miscellaneous state objects. */
456 void *custom_dsa_flush
;
457 void *custom_blend_resolve
;
458 void *custom_blend_decompress
;
459 void *custom_blend_fmask_decompress
;
460 /* With rasterizer discard, there doesn't have to be a pixel shader.
461 * In that case, we bind this one: */
462 void *dummy_pixel_shader
;
463 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
464 * bug where valid CMASK and FMASK are required to be present to avoid
465 * a hardlock in certain operations but aren't actually used
466 * for anything useful. */
467 struct r600_resource
*dummy_fmask
;
468 struct r600_resource
*dummy_cmask
;
470 /* State binding slots are here. */
471 struct r600_atom
*atoms
[R600_NUM_ATOMS
];
472 /* States for CS initialization. */
473 struct r600_command_buffer start_cs_cmd
; /* invariant state mostly */
474 /** Compute specific registers initializations. The start_cs_cmd atom
475 * must be emitted before start_compute_cs_cmd. */
476 struct r600_command_buffer start_compute_cs_cmd
;
477 /* Register states. */
478 struct r600_alphatest_state alphatest_state
;
479 struct r600_cso_state blend_state
;
480 struct r600_blend_color blend_color
;
481 struct r600_cb_misc_state cb_misc_state
;
482 struct r600_clip_misc_state clip_misc_state
;
483 struct r600_clip_state clip_state
;
484 struct r600_db_misc_state db_misc_state
;
485 struct r600_db_state db_state
;
486 struct r600_cso_state dsa_state
;
487 struct r600_framebuffer framebuffer
;
488 struct r600_poly_offset_state poly_offset_state
;
489 struct r600_cso_state rasterizer_state
;
490 struct r600_sample_mask sample_mask
;
491 struct r600_scissor_state scissor
;
492 struct r600_seamless_cube_map seamless_cube_map
;
493 struct r600_config_state config_state
;
494 struct r600_stencil_ref_state stencil_ref
;
495 struct r600_vgt_state vgt_state
;
496 struct r600_vgt2_state vgt2_state
;
497 struct r600_viewport_state viewport
;
498 /* Shaders and shader resources. */
499 struct r600_cso_state vertex_fetch_shader
;
500 struct r600_cs_shader_state cs_shader_state
;
501 struct r600_constbuf_state constbuf_state
[PIPE_SHADER_TYPES
];
502 struct r600_textures_info samplers
[PIPE_SHADER_TYPES
];
503 /** Vertex buffers for fetch shaders */
504 struct r600_vertexbuf_state vertex_buffer_state
;
505 /** Vertex buffers for compute shaders */
506 struct r600_vertexbuf_state cs_vertex_buffer_state
;
508 /* Additional context states. */
510 unsigned compute_cb_target_mask
;
511 struct r600_pipe_shader_selector
*ps_shader
;
512 struct r600_pipe_shader_selector
*vs_shader
;
513 struct r600_rasterizer_state
*rasterizer
;
515 bool force_blend_disable
;
516 boolean dual_src_blend
;
520 struct pipe_index_buffer index_buffer
;
522 /* Last draw state (-1 = unset). */
523 int last_primitive_type
; /* Last primitive type used in draw_vbo. */
524 int last_start_instance
;
527 /* The list of active queries. Only one query of each type can be active. */
528 int num_occlusion_queries
;
529 /* Keep track of non-timer queries, because they should be suspended
530 * during context flushing.
531 * The timer queries (TIME_ELAPSED) shouldn't be suspended. */
532 struct list_head active_nontimer_queries
;
533 unsigned num_cs_dw_nontimer_queries_suspend
;
534 /* If queries have been suspended. */
535 bool nontimer_queries_suspended
;
537 /* Render condition. */
538 struct pipe_query
*current_render_cond
;
539 unsigned current_render_cond_mode
;
540 boolean predicate_drawing
;
542 /* Streamout state. */
543 unsigned num_cs_dw_streamout_end
;
544 unsigned num_so_targets
;
545 struct r600_so_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
546 boolean streamout_start
;
547 unsigned streamout_append_bitmask
;
548 bool streamout_suspended
;
550 /* Deprecated state management. */
551 struct r600_range
*range
;
553 struct r600_block
**blocks
;
554 struct list_head dirty
;
555 struct list_head enable_list
;
556 unsigned pm4_dirty_cdwords
;
558 struct r600_isa
*isa
;
561 static INLINE
void r600_emit_command_buffer(struct radeon_winsys_cs
*cs
,
562 struct r600_command_buffer
*cb
)
564 assert(cs
->cdw
+ cb
->num_dw
<= RADEON_MAX_CMDBUF_DWORDS
);
565 memcpy(cs
->buf
+ cs
->cdw
, cb
->buf
, 4 * cb
->num_dw
);
566 cs
->cdw
+= cb
->num_dw
;
570 void r600_trace_emit(struct r600_context
*rctx
);
573 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
575 atom
->emit(rctx
, atom
);
578 if (rctx
->screen
->trace_bo
) {
579 r600_trace_emit(rctx
);
584 static INLINE
void r600_set_cso_state(struct r600_cso_state
*state
, void *cso
)
587 state
->atom
.dirty
= cso
!= NULL
;
590 static INLINE
void r600_set_cso_state_with_cb(struct r600_cso_state
*state
, void *cso
,
591 struct r600_command_buffer
*cb
)
594 state
->atom
.num_dw
= cb
->num_dw
;
595 r600_set_cso_state(state
, cso
);
598 /* evergreen_state.c */
599 struct pipe_sampler_view
*
600 evergreen_create_sampler_view_custom(struct pipe_context
*ctx
,
601 struct pipe_resource
*texture
,
602 const struct pipe_sampler_view
*state
,
603 unsigned width0
, unsigned height0
);
604 void evergreen_init_common_regs(struct r600_command_buffer
*cb
,
605 enum chip_class ctx_chip_class
,
606 enum radeon_family ctx_family
,
608 void cayman_init_common_regs(struct r600_command_buffer
*cb
,
609 enum chip_class ctx_chip_class
,
610 enum radeon_family ctx_family
,
613 void evergreen_init_state_functions(struct r600_context
*rctx
);
614 void evergreen_init_atom_start_cs(struct r600_context
*rctx
);
615 void evergreen_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
616 void evergreen_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
617 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
);
618 void *evergreen_create_resolve_blend(struct r600_context
*rctx
);
619 void *evergreen_create_decompress_blend(struct r600_context
*rctx
);
620 void *evergreen_create_fmask_decompress_blend(struct r600_context
*rctx
);
621 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
622 enum pipe_format format
,
623 enum pipe_texture_target target
,
624 unsigned sample_count
,
626 void evergreen_init_color_surface(struct r600_context
*rctx
,
627 struct r600_surface
*surf
);
628 void evergreen_init_color_surface_rat(struct r600_context
*rctx
,
629 struct r600_surface
*surf
);
630 void evergreen_update_db_shader_control(struct r600_context
* rctx
);
633 void r600_copy_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
, unsigned dstx
,
634 struct pipe_resource
*src
, const struct pipe_box
*src_box
);
635 void r600_init_blit_functions(struct r600_context
*rctx
);
636 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
637 struct r600_texture
*texture
,
638 struct r600_texture
*staging
,
639 unsigned first_level
, unsigned last_level
,
640 unsigned first_layer
, unsigned last_layer
,
641 unsigned first_sample
, unsigned last_sample
);
642 void r600_decompress_depth_textures(struct r600_context
*rctx
,
643 struct r600_samplerview_state
*textures
);
644 void r600_decompress_color_textures(struct r600_context
*rctx
,
645 struct r600_samplerview_state
*textures
);
648 bool r600_init_resource(struct r600_screen
*rscreen
,
649 struct r600_resource
*res
,
650 unsigned size
, unsigned alignment
,
651 bool use_reusable_pool
, unsigned usage
);
652 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
653 const struct pipe_resource
*templ
,
657 boolean
r600_rings_is_buffer_referenced(struct r600_context
*ctx
,
658 struct radeon_winsys_cs_handle
*buf
,
659 enum radeon_bo_usage usage
);
660 void *r600_buffer_mmap_sync_with_rings(struct r600_context
*ctx
,
661 struct r600_resource
*resource
,
665 void r600_init_query_functions(struct r600_context
*rctx
);
666 void r600_suspend_nontimer_queries(struct r600_context
*ctx
);
667 void r600_resume_nontimer_queries(struct r600_context
*ctx
);
669 /* r600_resource.c */
670 void r600_init_context_resource_functions(struct r600_context
*r600
);
673 int r600_pipe_shader_create(struct pipe_context
*ctx
,
674 struct r600_pipe_shader
*shader
,
675 struct r600_shader_key key
);
677 int r600_compute_shader_create(struct pipe_context
* ctx
,
678 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
);
680 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
683 struct pipe_sampler_view
*
684 r600_create_sampler_view_custom(struct pipe_context
*ctx
,
685 struct pipe_resource
*texture
,
686 const struct pipe_sampler_view
*state
,
687 unsigned width_first_level
, unsigned height_first_level
);
688 void r600_init_state_functions(struct r600_context
*rctx
);
689 void r600_init_atom_start_cs(struct r600_context
*rctx
);
690 void r600_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
691 void r600_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
692 void *r600_create_db_flush_dsa(struct r600_context
*rctx
);
693 void *r600_create_resolve_blend(struct r600_context
*rctx
);
694 void *r700_create_resolve_blend(struct r600_context
*rctx
);
695 void *r600_create_decompress_blend(struct r600_context
*rctx
);
696 bool r600_adjust_gprs(struct r600_context
*rctx
);
697 boolean
r600_is_format_supported(struct pipe_screen
*screen
,
698 enum pipe_format format
,
699 enum pipe_texture_target target
,
700 unsigned sample_count
,
702 void r600_update_db_shader_control(struct r600_context
* rctx
);
705 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
706 void r600_init_surface_functions(struct r600_context
*r600
);
707 uint32_t r600_translate_texformat(struct pipe_screen
*screen
, enum pipe_format format
,
708 const unsigned char *swizzle_view
,
709 uint32_t *word4_p
, uint32_t *yuv_format_p
);
710 unsigned r600_texture_get_offset(struct r600_texture
*rtex
,
711 unsigned level
, unsigned layer
);
712 struct pipe_surface
*r600_create_surface_custom(struct pipe_context
*pipe
,
713 struct pipe_resource
*texture
,
714 const struct pipe_surface
*templ
,
715 unsigned width
, unsigned height
);
717 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format
,
718 const unsigned char *swizzle_view
,
721 /* r600_state_common.c */
722 void r600_init_common_state_functions(struct r600_context
*rctx
);
723 void r600_emit_cso_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
724 void r600_emit_alphatest_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
725 void r600_emit_blend_color(struct r600_context
*rctx
, struct r600_atom
*atom
);
726 void r600_emit_vgt_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
727 void r600_emit_vgt2_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
728 void r600_emit_clip_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
729 void r600_emit_stencil_ref(struct r600_context
*rctx
, struct r600_atom
*atom
);
730 void r600_emit_viewport_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
731 void r600_init_atom(struct r600_context
*rctx
, struct r600_atom
*atom
, unsigned id
,
732 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
734 void r600_vertex_buffers_dirty(struct r600_context
*rctx
);
735 void r600_sampler_views_dirty(struct r600_context
*rctx
,
736 struct r600_samplerview_state
*state
);
737 void r600_sampler_states_dirty(struct r600_context
*rctx
,
738 struct r600_sampler_states
*state
);
739 void r600_constant_buffers_dirty(struct r600_context
*rctx
, struct r600_constbuf_state
*state
);
740 void r600_draw_rectangle(struct blitter_context
*blitter
,
741 int x1
, int y1
, int x2
, int y2
, float depth
,
742 enum blitter_attrib_type type
, const union pipe_color_union
*attrib
);
743 uint32_t r600_translate_stencil_op(int s_op
);
744 uint32_t r600_translate_fill(uint32_t func
);
745 unsigned r600_tex_wrap(unsigned wrap
);
746 unsigned r600_tex_filter(unsigned filter
);
747 unsigned r600_tex_mipfilter(unsigned filter
);
748 unsigned r600_tex_compare(unsigned compare
);
749 bool sampler_state_needs_border_color(const struct pipe_sampler_state
*state
);
752 * Helpers for building command buffers
755 #define PKT3_SET_CONFIG_REG 0x68
756 #define PKT3_SET_CONTEXT_REG 0x69
757 #define PKT3_SET_CTL_CONST 0x6F
758 #define PKT3_SET_LOOP_CONST 0x6C
760 #define R600_CONFIG_REG_OFFSET 0x08000
761 #define R600_CONTEXT_REG_OFFSET 0x28000
762 #define R600_CTL_CONST_OFFSET 0x3CFF0
763 #define R600_LOOP_CONST_OFFSET 0X0003E200
764 #define EG_LOOP_CONST_OFFSET 0x0003A200
766 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
767 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
768 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
769 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
770 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
772 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
774 /*Evergreen Compute packet3*/
775 #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)
777 static INLINE
void r600_store_value(struct r600_command_buffer
*cb
, unsigned value
)
779 cb
->buf
[cb
->num_dw
++] = value
;
782 static INLINE
void r600_store_config_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
784 assert(reg
< R600_CONTEXT_REG_OFFSET
);
785 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
786 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
787 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
791 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
794 static INLINE
void r600_store_context_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
796 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
797 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
798 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0) | cb
->pkt_flags
;
799 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
803 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
806 static INLINE
void r600_store_ctl_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
808 assert(reg
>= R600_CTL_CONST_OFFSET
);
809 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
810 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0) | cb
->pkt_flags
;
811 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
814 static INLINE
void r600_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
816 assert(reg
>= R600_LOOP_CONST_OFFSET
);
817 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
818 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
819 cb
->buf
[cb
->num_dw
++] = (reg
- R600_LOOP_CONST_OFFSET
) >> 2;
823 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
826 static INLINE
void eg_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
828 assert(reg
>= EG_LOOP_CONST_OFFSET
);
829 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
830 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0) | cb
->pkt_flags
;
831 cb
->buf
[cb
->num_dw
++] = (reg
- EG_LOOP_CONST_OFFSET
) >> 2;
834 static INLINE
void r600_store_config_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
836 r600_store_config_reg_seq(cb
, reg
, 1);
837 r600_store_value(cb
, value
);
840 static INLINE
void r600_store_context_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
842 r600_store_context_reg_seq(cb
, reg
, 1);
843 r600_store_value(cb
, value
);
846 static INLINE
void r600_store_ctl_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
848 r600_store_ctl_const_seq(cb
, reg
, 1);
849 r600_store_value(cb
, value
);
852 static INLINE
void r600_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
854 r600_store_loop_const_seq(cb
, reg
, 1);
855 r600_store_value(cb
, value
);
858 static INLINE
void eg_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
860 eg_store_loop_const_seq(cb
, reg
, 1);
861 r600_store_value(cb
, value
);
864 void r600_init_command_buffer(struct r600_command_buffer
*cb
, unsigned num_dw
);
865 void r600_release_command_buffer(struct r600_command_buffer
*cb
);
868 * Helpers for emitting state into a command stream directly.
870 static INLINE
unsigned r600_context_bo_reloc(struct r600_context
*ctx
,
871 struct r600_ring
*ring
,
872 struct r600_resource
*rbo
,
873 enum radeon_bo_usage usage
)
876 /* make sure that all previous ring use are flushed so everything
877 * look serialized from driver pov
879 if (!ring
->flushing
) {
880 if (ring
== &ctx
->rings
.gfx
) {
881 if (ctx
->rings
.dma
.cs
) {
883 ctx
->rings
.dma
.flush(ctx
, RADEON_FLUSH_ASYNC
);
887 ctx
->rings
.gfx
.flush(ctx
, RADEON_FLUSH_ASYNC
);
890 return ctx
->ws
->cs_add_reloc(ring
->cs
, rbo
->cs_buf
, usage
, rbo
->domains
) * 4;
893 static INLINE
void r600_write_value(struct radeon_winsys_cs
*cs
, unsigned value
)
895 cs
->buf
[cs
->cdw
++] = value
;
898 static INLINE
void r600_write_array(struct radeon_winsys_cs
*cs
, unsigned num
, unsigned *ptr
)
900 assert(cs
->cdw
+num
<= RADEON_MAX_CMDBUF_DWORDS
);
901 memcpy(&cs
->buf
[cs
->cdw
], ptr
, num
* sizeof(ptr
[0]));
905 static INLINE
void r600_write_config_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
907 assert(reg
< R600_CONTEXT_REG_OFFSET
);
908 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
909 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
910 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
913 static INLINE
void r600_write_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
915 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
916 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
917 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0);
918 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
921 static INLINE
void r600_write_compute_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
923 r600_write_context_reg_seq(cs
, reg
, num
);
924 /* Set the compute bit on the packet header */
925 cs
->buf
[cs
->cdw
- 2] |= RADEON_CP_PACKET3_COMPUTE_MODE
;
928 static INLINE
void r600_write_ctl_const_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
930 assert(reg
>= R600_CTL_CONST_OFFSET
);
931 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
932 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
933 cs
->buf
[cs
->cdw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
936 static INLINE
void r600_write_config_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
938 r600_write_config_reg_seq(cs
, reg
, 1);
939 r600_write_value(cs
, value
);
942 static INLINE
void r600_write_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
944 r600_write_context_reg_seq(cs
, reg
, 1);
945 r600_write_value(cs
, value
);
948 static INLINE
void r600_write_compute_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
950 r600_write_compute_context_reg_seq(cs
, reg
, 1);
951 r600_write_value(cs
, value
);
954 static INLINE
void r600_write_ctl_const(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
956 r600_write_ctl_const_seq(cs
, reg
, 1);
957 r600_write_value(cs
, value
);
963 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
965 return value
* (1 << frac_bits
);
967 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
969 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
971 if (filter
<= 1) return 0;
972 if (filter
<= 2) return 1;
973 if (filter
<= 4) return 2;
974 if (filter
<= 8) return 3;
978 /* 12.4 fixed-point */
979 static INLINE
unsigned r600_pack_float_12p4(float x
)
982 x
>= 4096 ? 0xffff : x
* 16;
985 static INLINE
uint64_t r600_resource_va(struct pipe_screen
*screen
, struct pipe_resource
*resource
)
987 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
988 struct r600_resource
*rresource
= (struct r600_resource
*)resource
;
990 return rscreen
->ws
->buffer_get_virtual_address(rresource
->cs_buf
);
993 static INLINE
void r600_context_add_resource_size(struct pipe_context
*ctx
, struct pipe_resource
*r
)
995 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
996 struct r600_resource
*rr
= (struct r600_resource
*)r
;
1003 * The idea is to compute a gross estimate of memory requirement of
1004 * each draw call. After each draw call, memory will be precisely
1005 * accounted. So the uncertainty is only on the current draw call.
1006 * In practice this gave very good estimate (+/- 10% of the target
1009 if (rr
->domains
& RADEON_DOMAIN_GTT
) {
1010 rctx
->gtt
+= rr
->buf
->size
;
1012 if (rr
->domains
& RADEON_DOMAIN_VRAM
) {
1013 rctx
->vram
+= rr
->buf
->size
;