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"
32 #include "util/u_double_list.h"
33 #include "util/u_transfer.h"
34 #include "r600_llvm.h"
35 #include "r600_public.h"
36 #include "r600_resource.h"
38 #define R600_NUM_ATOMS 40
40 #define R600_TRACE_CS 0
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 34
45 #define R600_TRACE_CS_DWORDS 7
47 #define R600_MAX_USER_CONST_BUFFERS 13
48 #define R600_MAX_DRIVER_CONST_BUFFERS 3
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)
56 #define R600_MAX_CONST_BUFFER_SIZE 4096
58 #ifdef PIPE_ARCH_BIG_ENDIAN
59 #define R600_BIG_ENDIAN 1
61 #define R600_BIG_ENDIAN 0
64 #define R600_MAP_BUFFER_ALIGNMENT 64
66 #define R600_ERR(fmt, args...) \
67 fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
69 #define R600_CONTEXT_INVAL_READ_CACHES (1 << 0)
70 #define R600_CONTEXT_STREAMOUT_FLUSH (1 << 1)
71 #define R600_CONTEXT_WAIT_3D_IDLE (1 << 2)
72 #define R600_CONTEXT_WAIT_CP_DMA_IDLE (1 << 3)
73 #define R600_CONTEXT_FLUSH_AND_INV (1 << 4)
74 #define R600_CONTEXT_FLUSH_AND_INV_CB_META (1 << 5)
75 #define R600_CONTEXT_PS_PARTIAL_FLUSH (1 << 6)
76 #define R600_CONTEXT_FLUSH_AND_INV_DB_META (1 << 7)
78 #define R600_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
79 #define R600_QUERY_REQUESTED_VRAM (PIPE_QUERY_DRIVER_SPECIFIC + 1)
80 #define R600_QUERY_REQUESTED_GTT (PIPE_QUERY_DRIVER_SPECIFIC + 2)
84 struct r600_shader_key
;
86 /* This encapsulates a state or an operation which can emitted into the GPU
87 * command stream. It's not limited to states only, it can be used for anything
88 * that wants to write commands into the CS (e.g. cache flushes). */
90 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
);
96 /* This is an atom containing GPU commands that never change.
97 * This is supposed to be copied directly into the CS. */
98 struct r600_command_buffer
{
105 struct r600_db_state
{
106 struct r600_atom atom
;
107 struct r600_surface
*rsurf
;
110 struct r600_db_misc_state
{
111 struct r600_atom atom
;
112 bool occlusion_query_enabled
;
113 bool flush_depthstencil_through_cb
;
114 bool flush_depthstencil_in_place
;
115 bool copy_depth
, copy_stencil
;
116 unsigned copy_sample
;
117 unsigned log_samples
;
118 unsigned db_shader_control
;
122 struct r600_cb_misc_state
{
123 struct r600_atom atom
;
124 unsigned cb_color_control
; /* this comes from blend state */
125 unsigned blend_colormask
; /* 8*4 bits for 8 RGBA colorbuffers */
127 unsigned nr_ps_color_outputs
;
132 struct r600_clip_misc_state
{
133 struct r600_atom atom
;
134 unsigned pa_cl_clip_cntl
; /* from rasterizer */
135 unsigned pa_cl_vs_out_cntl
; /* from vertex shader */
136 unsigned clip_plane_enable
; /* from rasterizer */
137 unsigned clip_dist_write
; /* from vertex shader */
140 struct r600_alphatest_state
{
141 struct r600_atom atom
;
142 unsigned sx_alpha_test_control
; /* this comes from dsa state */
143 unsigned sx_alpha_ref
; /* this comes from dsa state */
145 bool cb0_export_16bpc
; /* from set_framebuffer_state */
148 struct r600_vgt_state
{
149 struct r600_atom atom
;
150 uint32_t vgt_multi_prim_ib_reset_en
;
151 uint32_t vgt_multi_prim_ib_reset_indx
;
152 uint32_t vgt_indx_offset
;
155 struct r600_blend_color
{
156 struct r600_atom atom
;
157 struct pipe_blend_color state
;
160 struct r600_clip_state
{
161 struct r600_atom atom
;
162 struct pipe_clip_state state
;
165 struct r600_cs_shader_state
{
166 struct r600_atom atom
;
167 unsigned kernel_index
;
168 struct r600_pipe_compute
*shader
;
171 struct r600_framebuffer
{
172 struct r600_atom atom
;
173 struct pipe_framebuffer_state state
;
174 unsigned compressed_cb_mask
;
178 bool is_msaa_resolve
;
181 struct r600_sample_mask
{
182 struct r600_atom atom
;
183 uint16_t sample_mask
; /* there are only 8 bits on EG, 16 bits on Cayman */
186 struct r600_config_state
{
187 struct r600_atom atom
;
188 unsigned sq_gpr_resource_mgmt_1
;
191 struct r600_stencil_ref
198 struct r600_stencil_ref_state
{
199 struct r600_atom atom
;
200 struct r600_stencil_ref state
;
201 struct pipe_stencil_ref pipe_state
;
204 struct r600_viewport_state
{
205 struct r600_atom atom
;
206 struct pipe_viewport_state state
;
209 struct r600_pipe_fences
{
210 struct r600_resource
*bo
;
213 /* linked list of preallocated blocks */
214 struct list_head blocks
;
215 /* linked list of freed fences */
216 struct list_head pool
;
220 enum r600_msaa_texture_mode
{
221 /* If the hw can fetch the first sample only (no decompression available).
222 * This means MSAA texturing is not fully implemented. */
223 MSAA_TEXTURE_SAMPLE_ZERO
,
225 /* If the hw can fetch decompressed MSAA textures.
226 * Supported families: R600, R700, Evergreen.
227 * Cayman cannot use this, because it cannot do the decompression. */
228 MSAA_TEXTURE_DECOMPRESSED
,
230 /* If the hw can fetch compressed MSAA textures, which means shaders can
231 * read resolved FMASK. This yields the best performance.
232 * Supported families: Evergreen, Cayman. */
233 MSAA_TEXTURE_COMPRESSED
236 typedef boolean (*r600g_dma_blit_t
)(struct pipe_context
*ctx
,
237 struct pipe_resource
*dst
,
239 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
240 struct pipe_resource
*src
,
242 const struct pipe_box
*src_box
);
245 #define DBG_TEX_DEPTH (1 << 0)
246 #define DBG_COMPUTE (1 << 1)
248 #define DBG_FS (1 << 8)
249 #define DBG_VS (1 << 9)
250 #define DBG_GS (1 << 10)
251 #define DBG_PS (1 << 11)
252 #define DBG_CS (1 << 12)
254 #define DBG_NO_HYPERZ (1 << 16)
255 #define DBG_NO_LLVM (1 << 17)
256 #define DBG_NO_CP_DMA (1 << 18)
257 #define DBG_NO_ASYNC_DMA (1 << 19)
258 #define DBG_NO_DISCARD_RANGE (1 << 20)
260 struct r600_tiling_info
{
261 unsigned num_channels
;
263 unsigned group_bytes
;
267 struct pipe_screen screen
;
268 struct radeon_winsys
*ws
;
269 unsigned debug_flags
;
271 enum chip_class chip_class
;
272 struct radeon_info info
;
276 enum r600_msaa_texture_mode msaa_texture_support
;
277 struct r600_tiling_info tiling_info
;
278 struct r600_pipe_fences fences
;
280 /*for compute global memory binding, we allocate stuff here, instead of
282 * XXX: Not sure if this is the best place for global_pool. Also,
283 * it's not thread safe, so it won't work with multiple contexts. */
284 struct compute_memory_pool
*global_pool
;
286 struct r600_resource
*trace_bo
;
290 r600g_dma_blit_t dma_blit
;
293 struct r600_pipe_sampler_view
{
294 struct pipe_sampler_view base
;
295 struct r600_resource
*tex_resource
;
296 uint32_t tex_resource_words
[8];
297 bool skip_mip_address_reloc
;
300 struct r600_rasterizer_state
{
301 struct r600_command_buffer buffer
;
304 unsigned sprite_coord_enable
;
305 unsigned clip_plane_enable
;
306 unsigned pa_sc_line_stipple
;
307 unsigned pa_cl_clip_cntl
;
312 bool multisample_enable
;
315 struct r600_poly_offset_state
{
316 struct r600_atom atom
;
317 enum pipe_format zs_format
;
322 struct r600_blend_state
{
323 struct r600_command_buffer buffer
;
324 struct r600_command_buffer buffer_no_blend
;
325 unsigned cb_target_mask
;
326 unsigned cb_color_control
;
327 unsigned cb_color_control_no_blend
;
332 struct r600_dsa_state
{
333 struct r600_command_buffer buffer
;
338 unsigned sx_alpha_test_control
;
341 struct r600_pipe_shader
;
343 struct r600_pipe_shader_selector
{
344 struct r600_pipe_shader
*current
;
346 struct tgsi_token
*tokens
;
347 struct pipe_stream_output_info so
;
349 unsigned num_shaders
;
351 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
354 unsigned nr_ps_max_color_exports
;
357 struct r600_pipe_sampler_state
{
358 uint32_t tex_sampler_words
[3];
359 union pipe_color_union border_color
;
360 bool border_color_use
;
361 bool seamless_cube_map
;
364 /* needed for blitter save */
365 #define NUM_TEX_UNITS 16
367 struct r600_seamless_cube_map
{
368 struct r600_atom atom
;
372 struct r600_samplerview_state
{
373 struct r600_atom atom
;
374 struct r600_pipe_sampler_view
*views
[NUM_TEX_UNITS
];
375 uint32_t enabled_mask
;
377 uint32_t compressed_depthtex_mask
; /* which textures are depth */
378 uint32_t compressed_colortex_mask
;
379 boolean dirty_txq_constants
;
380 boolean dirty_buffer_constants
;
383 struct r600_sampler_states
{
384 struct r600_atom atom
;
385 struct r600_pipe_sampler_state
*states
[NUM_TEX_UNITS
];
386 uint32_t enabled_mask
;
388 uint32_t has_bordercolor_mask
; /* which states contain the border color */
391 struct r600_textures_info
{
392 struct r600_samplerview_state views
;
393 struct r600_sampler_states states
;
394 bool is_array_sampler
[NUM_TEX_UNITS
];
396 /* cube array txq workaround */
397 uint32_t *txq_constants
;
398 /* buffer related workarounds */
399 uint32_t *buffer_constants
;
403 struct pipe_reference reference
;
404 unsigned index
; /* in the shared bo */
405 struct r600_resource
*sleep_bo
;
406 struct list_head head
;
409 #define FENCE_BLOCK_SIZE 16
411 struct r600_fence_block
{
412 struct r600_fence fences
[FENCE_BLOCK_SIZE
];
413 struct list_head head
;
416 #define R600_CONSTANT_ARRAY_SIZE 256
417 #define R600_RESOURCE_ARRAY_SIZE 160
419 struct r600_constbuf_state
421 struct r600_atom atom
;
422 struct pipe_constant_buffer cb
[PIPE_MAX_CONSTANT_BUFFERS
];
423 uint32_t enabled_mask
;
427 struct r600_vertexbuf_state
429 struct r600_atom atom
;
430 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
431 uint32_t enabled_mask
; /* non-NULL buffers */
435 /* CSO (constant state object, in other words, immutable state). */
436 struct r600_cso_state
438 struct r600_atom atom
;
439 void *cso
; /* e.g. r600_blend_state */
440 struct r600_command_buffer
*cb
;
443 struct r600_scissor_state
445 struct r600_atom atom
;
446 struct pipe_scissor_state scissor
;
447 bool enable
; /* r6xx only */
450 struct r600_fetch_shader
{
451 struct r600_resource
*buffer
;
455 struct r600_shader_state
{
456 struct r600_atom atom
;
457 struct r600_pipe_shader_selector
*shader
;
460 struct r600_query_buffer
{
461 /* The buffer where query results are stored. */
462 struct r600_resource
*buf
;
463 /* Offset of the next free result after current query data */
464 unsigned results_end
;
465 /* If a query buffer is full, a new buffer is created and the old one
466 * is put in here. When we calculate the result, we sum up the samples
467 * from all buffers. */
468 struct r600_query_buffer
*previous
;
472 /* The query buffer and how many results are in it. */
473 struct r600_query_buffer buffer
;
474 /* The type of query */
476 /* Size of the result in memory for both begin_query and end_query,
477 * this can be one or two numbers, or it could even be a size of a structure. */
478 unsigned result_size
;
479 /* The number of dwords for begin_query or end_query. */
481 /* linked list of queries */
482 struct list_head list
;
483 /* for custom non-GPU queries */
484 uint64_t begin_result
;
488 struct r600_so_target
{
489 struct pipe_stream_output_target b
;
491 /* The buffer where BUFFER_FILLED_SIZE is stored. */
492 struct r600_resource
*buf_filled_size
;
493 unsigned buf_filled_size_offset
;
495 unsigned stride_in_dw
;
499 struct r600_streamout
{
500 struct r600_atom begin_atom
;
502 unsigned num_dw_for_end
;
504 unsigned enabled_mask
;
505 unsigned num_targets
;
506 struct r600_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
508 unsigned append_bitmask
;
513 struct radeon_winsys_cs
*cs
;
515 void (*flush
)(void *ctx
, unsigned flags
);
519 struct r600_ring gfx
;
520 struct r600_ring dma
;
523 struct r600_context
{
524 struct pipe_context context
;
525 struct r600_screen
*screen
;
526 struct radeon_winsys
*ws
;
527 struct r600_rings rings
;
528 struct blitter_context
*blitter
;
529 struct u_upload_mgr
*uploader
;
530 struct u_suballocator
*allocator_so_filled_size
;
531 struct u_suballocator
*allocator_fetch_shader
;
532 struct util_slab_mempool pool_transfers
;
535 enum radeon_family family
;
536 enum chip_class chip_class
;
537 boolean has_vertex_cache
;
538 boolean keep_tiling_flags
;
539 unsigned default_ps_gprs
, default_vs_gprs
;
540 unsigned r6xx_num_clause_temp_gprs
;
541 unsigned backend_mask
;
542 unsigned max_db
; /* for OQ */
544 /* current unaccounted memory usage */
548 /* Miscellaneous state objects. */
549 void *custom_dsa_flush
;
550 void *custom_blend_resolve
;
551 void *custom_blend_decompress
;
552 void *custom_blend_fmask_decompress
;
553 /* With rasterizer discard, there doesn't have to be a pixel shader.
554 * In that case, we bind this one: */
555 void *dummy_pixel_shader
;
556 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
557 * bug where valid CMASK and FMASK are required to be present to avoid
558 * a hardlock in certain operations but aren't actually used
559 * for anything useful. */
560 struct r600_resource
*dummy_fmask
;
561 struct r600_resource
*dummy_cmask
;
563 /* State binding slots are here. */
564 struct r600_atom
*atoms
[R600_NUM_ATOMS
];
565 /* States for CS initialization. */
566 struct r600_command_buffer start_cs_cmd
; /* invariant state mostly */
567 /** Compute specific registers initializations. The start_cs_cmd atom
568 * must be emitted before start_compute_cs_cmd. */
569 struct r600_command_buffer start_compute_cs_cmd
;
570 /* Register states. */
571 struct r600_alphatest_state alphatest_state
;
572 struct r600_cso_state blend_state
;
573 struct r600_blend_color blend_color
;
574 struct r600_cb_misc_state cb_misc_state
;
575 struct r600_clip_misc_state clip_misc_state
;
576 struct r600_clip_state clip_state
;
577 struct r600_db_misc_state db_misc_state
;
578 struct r600_db_state db_state
;
579 struct r600_cso_state dsa_state
;
580 struct r600_framebuffer framebuffer
;
581 struct r600_poly_offset_state poly_offset_state
;
582 struct r600_cso_state rasterizer_state
;
583 struct r600_sample_mask sample_mask
;
584 struct r600_scissor_state scissor
;
585 struct r600_seamless_cube_map seamless_cube_map
;
586 struct r600_config_state config_state
;
587 struct r600_stencil_ref_state stencil_ref
;
588 struct r600_vgt_state vgt_state
;
589 struct r600_viewport_state viewport
;
590 /* Shaders and shader resources. */
591 struct r600_cso_state vertex_fetch_shader
;
592 struct r600_shader_state vertex_shader
;
593 struct r600_shader_state pixel_shader
;
594 struct r600_cs_shader_state cs_shader_state
;
595 struct r600_constbuf_state constbuf_state
[PIPE_SHADER_TYPES
];
596 struct r600_textures_info samplers
[PIPE_SHADER_TYPES
];
597 /** Vertex buffers for fetch shaders */
598 struct r600_vertexbuf_state vertex_buffer_state
;
599 /** Vertex buffers for compute shaders */
600 struct r600_vertexbuf_state cs_vertex_buffer_state
;
601 struct r600_streamout streamout
;
603 /* Additional context states. */
605 unsigned compute_cb_target_mask
;
606 struct r600_pipe_shader_selector
*ps_shader
;
607 struct r600_pipe_shader_selector
*vs_shader
;
608 struct r600_rasterizer_state
*rasterizer
;
610 bool force_blend_disable
;
611 boolean dual_src_blend
;
615 struct pipe_index_buffer index_buffer
;
617 /* Last draw state (-1 = unset). */
618 int last_primitive_type
; /* Last primitive type used in draw_vbo. */
619 int last_start_instance
;
622 /* The list of active queries. Only one query of each type can be active. */
623 int num_occlusion_queries
;
624 /* Keep track of non-timer queries, because they should be suspended
625 * during context flushing.
626 * The timer queries (TIME_ELAPSED) shouldn't be suspended. */
627 struct list_head active_nontimer_queries
;
628 unsigned num_cs_dw_nontimer_queries_suspend
;
629 /* If queries have been suspended. */
630 bool nontimer_queries_suspended
;
631 unsigned num_draw_calls
;
633 /* Render condition. */
634 struct pipe_query
*current_render_cond
;
635 unsigned current_render_cond_mode
;
636 boolean predicate_drawing
;
638 struct r600_isa
*isa
;
641 static INLINE
void r600_emit_command_buffer(struct radeon_winsys_cs
*cs
,
642 struct r600_command_buffer
*cb
)
644 assert(cs
->cdw
+ cb
->num_dw
<= RADEON_MAX_CMDBUF_DWORDS
);
645 memcpy(cs
->buf
+ cs
->cdw
, cb
->buf
, 4 * cb
->num_dw
);
646 cs
->cdw
+= cb
->num_dw
;
650 void r600_trace_emit(struct r600_context
*rctx
);
653 static INLINE
void r600_emit_atom(struct r600_context
*rctx
, struct r600_atom
*atom
)
655 atom
->emit(rctx
, atom
);
658 if (rctx
->screen
->trace_bo
) {
659 r600_trace_emit(rctx
);
664 static INLINE
void r600_set_cso_state(struct r600_cso_state
*state
, void *cso
)
667 state
->atom
.dirty
= cso
!= NULL
;
670 static INLINE
void r600_set_cso_state_with_cb(struct r600_cso_state
*state
, void *cso
,
671 struct r600_command_buffer
*cb
)
674 state
->atom
.num_dw
= cb
->num_dw
;
675 r600_set_cso_state(state
, cso
);
678 /* compute_memory_pool.c */
679 struct compute_memory_pool
;
680 void compute_memory_pool_delete(struct compute_memory_pool
* pool
);
681 struct compute_memory_pool
* compute_memory_pool_new(
682 struct r600_screen
*rscreen
);
684 /* evergreen_state.c */
685 struct pipe_sampler_view
*
686 evergreen_create_sampler_view_custom(struct pipe_context
*ctx
,
687 struct pipe_resource
*texture
,
688 const struct pipe_sampler_view
*state
,
689 unsigned width0
, unsigned height0
);
690 void evergreen_init_common_regs(struct r600_command_buffer
*cb
,
691 enum chip_class ctx_chip_class
,
692 enum radeon_family ctx_family
,
694 void cayman_init_common_regs(struct r600_command_buffer
*cb
,
695 enum chip_class ctx_chip_class
,
696 enum radeon_family ctx_family
,
699 void evergreen_init_state_functions(struct r600_context
*rctx
);
700 void evergreen_init_atom_start_cs(struct r600_context
*rctx
);
701 void evergreen_update_ps_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
702 void evergreen_update_vs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
703 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
);
704 void *evergreen_create_resolve_blend(struct r600_context
*rctx
);
705 void *evergreen_create_decompress_blend(struct r600_context
*rctx
);
706 void *evergreen_create_fmask_decompress_blend(struct r600_context
*rctx
);
707 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
708 enum pipe_format format
,
709 enum pipe_texture_target target
,
710 unsigned sample_count
,
712 void evergreen_init_color_surface(struct r600_context
*rctx
,
713 struct r600_surface
*surf
);
714 void evergreen_init_color_surface_rat(struct r600_context
*rctx
,
715 struct r600_surface
*surf
);
716 void evergreen_update_db_shader_control(struct r600_context
* rctx
);
719 void r600_copy_buffer(struct pipe_context
*ctx
, struct pipe_resource
*dst
, unsigned dstx
,
720 struct pipe_resource
*src
, const struct pipe_box
*src_box
);
721 void r600_init_blit_functions(struct r600_context
*rctx
);
722 void r600_blit_decompress_depth(struct pipe_context
*ctx
,
723 struct r600_texture
*texture
,
724 struct r600_texture
*staging
,
725 unsigned first_level
, unsigned last_level
,
726 unsigned first_layer
, unsigned last_layer
,
727 unsigned first_sample
, unsigned last_sample
);
728 void r600_decompress_depth_textures(struct r600_context
*rctx
,
729 struct r600_samplerview_state
*textures
);
730 void r600_decompress_color_textures(struct r600_context
*rctx
,
731 struct r600_samplerview_state
*textures
);
734 bool r600_init_resource(struct r600_screen
*rscreen
,
735 struct r600_resource
*res
,
736 unsigned size
, unsigned alignment
,
737 bool use_reusable_pool
, unsigned usage
);
738 struct pipe_resource
*r600_buffer_create(struct pipe_screen
*screen
,
739 const struct pipe_resource
*templ
,
743 boolean
r600_rings_is_buffer_referenced(struct r600_context
*ctx
,
744 struct radeon_winsys_cs_handle
*buf
,
745 enum radeon_bo_usage usage
);
746 void *r600_buffer_mmap_sync_with_rings(struct r600_context
*ctx
,
747 struct r600_resource
*resource
,
749 const char * r600_llvm_gpu_string(enum radeon_family family
);
753 void r600_init_query_functions(struct r600_context
*rctx
);
754 void r600_suspend_nontimer_queries(struct r600_context
*ctx
);
755 void r600_resume_nontimer_queries(struct r600_context
*ctx
);
757 /* r600_resource.c */
758 void r600_init_context_resource_functions(struct r600_context
*r600
);
761 int r600_pipe_shader_create(struct pipe_context
*ctx
,
762 struct r600_pipe_shader
*shader
,
763 struct r600_shader_key key
);
765 int r600_compute_shader_create(struct pipe_context
* ctx
,
766 LLVMModuleRef mod
, struct r600_bytecode
* bytecode
);
768 void r600_pipe_shader_destroy(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
771 struct pipe_sampler_view
*
772 r600_create_sampler_view_custom(struct pipe_context
*ctx
,
773 struct pipe_resource
*texture
,
774 const struct pipe_sampler_view
*state
,
775 unsigned width_first_level
, unsigned height_first_level
);
776 void r600_init_state_functions(struct r600_context
*rctx
);
777 void r600_init_atom_start_cs(struct r600_context
*rctx
);
778 void r600_update_ps_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
779 void r600_update_vs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
);
780 void *r600_create_db_flush_dsa(struct r600_context
*rctx
);
781 void *r600_create_resolve_blend(struct r600_context
*rctx
);
782 void *r700_create_resolve_blend(struct r600_context
*rctx
);
783 void *r600_create_decompress_blend(struct r600_context
*rctx
);
784 bool r600_adjust_gprs(struct r600_context
*rctx
);
785 boolean
r600_is_format_supported(struct pipe_screen
*screen
,
786 enum pipe_format format
,
787 enum pipe_texture_target target
,
788 unsigned sample_count
,
790 void r600_update_db_shader_control(struct r600_context
* rctx
);
793 void r600_init_screen_texture_functions(struct pipe_screen
*screen
);
794 void r600_init_surface_functions(struct r600_context
*r600
);
795 uint32_t r600_translate_texformat(struct pipe_screen
*screen
, enum pipe_format format
,
796 const unsigned char *swizzle_view
,
797 uint32_t *word4_p
, uint32_t *yuv_format_p
);
798 unsigned r600_texture_get_offset(struct r600_texture
*rtex
,
799 unsigned level
, unsigned layer
);
800 struct pipe_surface
*r600_create_surface_custom(struct pipe_context
*pipe
,
801 struct pipe_resource
*texture
,
802 const struct pipe_surface
*templ
,
803 unsigned width
, unsigned height
);
805 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format
,
806 const unsigned char *swizzle_view
,
809 /* r600_hw_context.c */
810 void r600_get_backend_mask(struct r600_context
*ctx
);
811 void r600_context_flush(struct r600_context
*ctx
, unsigned flags
);
812 void r600_begin_new_cs(struct r600_context
*ctx
);
813 void r600_context_emit_fence(struct r600_context
*ctx
, struct r600_resource
*fence
,
814 unsigned offset
, unsigned value
);
815 void r600_flush_emit(struct r600_context
*ctx
);
816 void r600_need_cs_space(struct r600_context
*ctx
, unsigned num_dw
, boolean count_draw_in
);
817 void r600_need_dma_space(struct r600_context
*ctx
, unsigned num_dw
);
818 void r600_cp_dma_copy_buffer(struct r600_context
*rctx
,
819 struct pipe_resource
*dst
, uint64_t dst_offset
,
820 struct pipe_resource
*src
, uint64_t src_offset
,
822 void r600_dma_copy(struct r600_context
*rctx
,
823 struct pipe_resource
*dst
,
824 struct pipe_resource
*src
,
828 boolean
r600_dma_blit(struct pipe_context
*ctx
,
829 struct pipe_resource
*dst
,
831 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
832 struct pipe_resource
*src
,
834 const struct pipe_box
*src_box
);
835 void r600_emit_streamout_begin(struct r600_context
*ctx
, struct r600_atom
*atom
);
836 void r600_emit_streamout_end(struct r600_context
*ctx
);
839 * evergreen_hw_context.c
841 void evergreen_flush_vgt_streamout(struct r600_context
*ctx
);
842 void evergreen_set_streamout_enable(struct r600_context
*ctx
, unsigned buffer_enable_bit
);
843 void evergreen_dma_copy(struct r600_context
*rctx
,
844 struct pipe_resource
*dst
,
845 struct pipe_resource
*src
,
849 boolean
evergreen_dma_blit(struct pipe_context
*ctx
,
850 struct pipe_resource
*dst
,
852 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
853 struct pipe_resource
*src
,
855 const struct pipe_box
*src_box
);
857 /* r600_state_common.c */
858 void r600_init_common_state_functions(struct r600_context
*rctx
);
859 void r600_emit_cso_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
860 void r600_emit_alphatest_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
861 void r600_emit_blend_color(struct r600_context
*rctx
, struct r600_atom
*atom
);
862 void r600_emit_vgt_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
863 void r600_emit_clip_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
864 void r600_emit_stencil_ref(struct r600_context
*rctx
, struct r600_atom
*atom
);
865 void r600_emit_viewport_state(struct r600_context
*rctx
, struct r600_atom
*atom
);
866 void r600_emit_shader(struct r600_context
*rctx
, struct r600_atom
*a
);
867 void r600_init_atom(struct r600_context
*rctx
, struct r600_atom
*atom
, unsigned id
,
868 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
870 void r600_vertex_buffers_dirty(struct r600_context
*rctx
);
871 void r600_sampler_views_dirty(struct r600_context
*rctx
,
872 struct r600_samplerview_state
*state
);
873 void r600_sampler_states_dirty(struct r600_context
*rctx
,
874 struct r600_sampler_states
*state
);
875 void r600_constant_buffers_dirty(struct r600_context
*rctx
, struct r600_constbuf_state
*state
);
876 void r600_streamout_buffers_dirty(struct r600_context
*rctx
);
877 void r600_draw_rectangle(struct blitter_context
*blitter
,
878 int x1
, int y1
, int x2
, int y2
, float depth
,
879 enum blitter_attrib_type type
, const union pipe_color_union
*attrib
);
880 uint32_t r600_translate_stencil_op(int s_op
);
881 uint32_t r600_translate_fill(uint32_t func
);
882 unsigned r600_tex_wrap(unsigned wrap
);
883 unsigned r600_tex_filter(unsigned filter
);
884 unsigned r600_tex_mipfilter(unsigned filter
);
885 unsigned r600_tex_compare(unsigned compare
);
886 bool sampler_state_needs_border_color(const struct pipe_sampler_state
*state
);
889 struct pipe_video_decoder
*r600_uvd_create_decoder(struct pipe_context
*context
,
890 enum pipe_video_profile profile
,
891 enum pipe_video_entrypoint entrypoint
,
892 enum pipe_video_chroma_format chroma_format
,
893 unsigned width
, unsigned height
,
894 unsigned max_references
, bool expect_chunked_decode
);
896 struct pipe_video_buffer
*r600_video_buffer_create(struct pipe_context
*pipe
,
897 const struct pipe_video_buffer
*tmpl
);
901 * Helpers for building command buffers
904 #define PKT3_SET_CONFIG_REG 0x68
905 #define PKT3_SET_CONTEXT_REG 0x69
906 #define PKT3_SET_CTL_CONST 0x6F
907 #define PKT3_SET_LOOP_CONST 0x6C
909 #define R600_CONFIG_REG_OFFSET 0x08000
910 #define R600_CONTEXT_REG_OFFSET 0x28000
911 #define R600_CTL_CONST_OFFSET 0x3CFF0
912 #define R600_LOOP_CONST_OFFSET 0X0003E200
913 #define EG_LOOP_CONST_OFFSET 0x0003A200
915 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
916 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
917 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
918 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
919 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
921 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
923 /*Evergreen Compute packet3*/
924 #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)
926 static INLINE
void r600_store_value(struct r600_command_buffer
*cb
, unsigned value
)
928 cb
->buf
[cb
->num_dw
++] = value
;
931 static INLINE
void r600_store_array(struct r600_command_buffer
*cb
, unsigned num
, unsigned *ptr
)
933 assert(cb
->num_dw
+num
<= cb
->max_num_dw
);
934 memcpy(&cb
->buf
[cb
->num_dw
], ptr
, num
* sizeof(ptr
[0]));
938 static INLINE
void r600_store_config_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
940 assert(reg
< R600_CONTEXT_REG_OFFSET
);
941 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
942 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
943 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
947 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
950 static INLINE
void r600_store_context_reg_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
952 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
953 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
954 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0) | cb
->pkt_flags
;
955 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
959 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
962 static INLINE
void r600_store_ctl_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
964 assert(reg
>= R600_CTL_CONST_OFFSET
);
965 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
966 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0) | cb
->pkt_flags
;
967 cb
->buf
[cb
->num_dw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
970 static INLINE
void r600_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
972 assert(reg
>= R600_LOOP_CONST_OFFSET
);
973 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
974 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0);
975 cb
->buf
[cb
->num_dw
++] = (reg
- R600_LOOP_CONST_OFFSET
) >> 2;
979 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
982 static INLINE
void eg_store_loop_const_seq(struct r600_command_buffer
*cb
, unsigned reg
, unsigned num
)
984 assert(reg
>= EG_LOOP_CONST_OFFSET
);
985 assert(cb
->num_dw
+2+num
<= cb
->max_num_dw
);
986 cb
->buf
[cb
->num_dw
++] = PKT3(PKT3_SET_LOOP_CONST
, num
, 0) | cb
->pkt_flags
;
987 cb
->buf
[cb
->num_dw
++] = (reg
- EG_LOOP_CONST_OFFSET
) >> 2;
990 static INLINE
void r600_store_config_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
992 r600_store_config_reg_seq(cb
, reg
, 1);
993 r600_store_value(cb
, value
);
996 static INLINE
void r600_store_context_reg(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
998 r600_store_context_reg_seq(cb
, reg
, 1);
999 r600_store_value(cb
, value
);
1002 static INLINE
void r600_store_ctl_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
1004 r600_store_ctl_const_seq(cb
, reg
, 1);
1005 r600_store_value(cb
, value
);
1008 static INLINE
void r600_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
1010 r600_store_loop_const_seq(cb
, reg
, 1);
1011 r600_store_value(cb
, value
);
1014 static INLINE
void eg_store_loop_const(struct r600_command_buffer
*cb
, unsigned reg
, unsigned value
)
1016 eg_store_loop_const_seq(cb
, reg
, 1);
1017 r600_store_value(cb
, value
);
1020 void r600_init_command_buffer(struct r600_command_buffer
*cb
, unsigned num_dw
);
1021 void r600_release_command_buffer(struct r600_command_buffer
*cb
);
1024 * Helpers for emitting state into a command stream directly.
1026 static INLINE
unsigned r600_context_bo_reloc(struct r600_context
*ctx
,
1027 struct r600_ring
*ring
,
1028 struct r600_resource
*rbo
,
1029 enum radeon_bo_usage usage
)
1032 /* make sure that all previous ring use are flushed so everything
1033 * look serialized from driver pov
1035 if (!ring
->flushing
) {
1036 if (ring
== &ctx
->rings
.gfx
) {
1037 if (ctx
->rings
.dma
.cs
) {
1038 /* flush dma ring */
1039 ctx
->rings
.dma
.flush(ctx
, RADEON_FLUSH_ASYNC
);
1042 /* flush gfx ring */
1043 ctx
->rings
.gfx
.flush(ctx
, RADEON_FLUSH_ASYNC
);
1046 return ctx
->ws
->cs_add_reloc(ring
->cs
, rbo
->cs_buf
, usage
, rbo
->domains
) * 4;
1049 static INLINE
void r600_write_value(struct radeon_winsys_cs
*cs
, unsigned value
)
1051 cs
->buf
[cs
->cdw
++] = value
;
1054 static INLINE
void r600_write_array(struct radeon_winsys_cs
*cs
, unsigned num
, unsigned *ptr
)
1056 assert(cs
->cdw
+num
<= RADEON_MAX_CMDBUF_DWORDS
);
1057 memcpy(&cs
->buf
[cs
->cdw
], ptr
, num
* sizeof(ptr
[0]));
1061 static INLINE
void r600_write_config_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
1063 assert(reg
< R600_CONTEXT_REG_OFFSET
);
1064 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
1065 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONFIG_REG
, num
, 0);
1066 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONFIG_REG_OFFSET
) >> 2;
1069 static INLINE
void r600_write_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
1071 assert(reg
>= R600_CONTEXT_REG_OFFSET
&& reg
< R600_CTL_CONST_OFFSET
);
1072 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
1073 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CONTEXT_REG
, num
, 0);
1074 cs
->buf
[cs
->cdw
++] = (reg
- R600_CONTEXT_REG_OFFSET
) >> 2;
1077 static INLINE
void r600_write_compute_context_reg_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
1079 r600_write_context_reg_seq(cs
, reg
, num
);
1080 /* Set the compute bit on the packet header */
1081 cs
->buf
[cs
->cdw
- 2] |= RADEON_CP_PACKET3_COMPUTE_MODE
;
1084 static INLINE
void r600_write_ctl_const_seq(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned num
)
1086 assert(reg
>= R600_CTL_CONST_OFFSET
);
1087 assert(cs
->cdw
+2+num
<= RADEON_MAX_CMDBUF_DWORDS
);
1088 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SET_CTL_CONST
, num
, 0);
1089 cs
->buf
[cs
->cdw
++] = (reg
- R600_CTL_CONST_OFFSET
) >> 2;
1092 static INLINE
void r600_write_config_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
1094 r600_write_config_reg_seq(cs
, reg
, 1);
1095 r600_write_value(cs
, value
);
1098 static INLINE
void r600_write_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
1100 r600_write_context_reg_seq(cs
, reg
, 1);
1101 r600_write_value(cs
, value
);
1104 static INLINE
void r600_write_compute_context_reg(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
1106 r600_write_compute_context_reg_seq(cs
, reg
, 1);
1107 r600_write_value(cs
, value
);
1110 static INLINE
void r600_write_ctl_const(struct radeon_winsys_cs
*cs
, unsigned reg
, unsigned value
)
1112 r600_write_ctl_const_seq(cs
, reg
, 1);
1113 r600_write_value(cs
, value
);
1119 static INLINE
uint32_t S_FIXED(float value
, uint32_t frac_bits
)
1121 return value
* (1 << frac_bits
);
1123 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
1125 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
1127 if (filter
<= 1) return 0;
1128 if (filter
<= 2) return 1;
1129 if (filter
<= 4) return 2;
1130 if (filter
<= 8) return 3;
1131 /* else */ return 4;
1134 /* 12.4 fixed-point */
1135 static INLINE
unsigned r600_pack_float_12p4(float x
)
1138 x
>= 4096 ? 0xffff : x
* 16;
1141 static INLINE
uint64_t r600_resource_va(struct pipe_screen
*screen
, struct pipe_resource
*resource
)
1143 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
1144 struct r600_resource
*rresource
= (struct r600_resource
*)resource
;
1146 return rscreen
->ws
->buffer_get_virtual_address(rresource
->cs_buf
);
1149 static INLINE
void r600_context_add_resource_size(struct pipe_context
*ctx
, struct pipe_resource
*r
)
1151 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
1152 struct r600_resource
*rr
= (struct r600_resource
*)r
;
1159 * The idea is to compute a gross estimate of memory requirement of
1160 * each draw call. After each draw call, memory will be precisely
1161 * accounted. So the uncertainty is only on the current draw call.
1162 * In practice this gave very good estimate (+/- 10% of the target
1165 if (rr
->domains
& RADEON_DOMAIN_GTT
) {
1166 rctx
->gtt
+= rr
->buf
->size
;
1168 if (rr
->domains
& RADEON_DOMAIN_VRAM
) {
1169 rctx
->vram
+= rr
->buf
->size
;