2 * Copyright 2012 Advanced Micro Devices, Inc.
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.
24 * Christian König <christian.koenig@amd.com>
31 #include "../radeon/r600_pipe_common.h"
35 struct si_state_blend
{
36 struct si_pm4_state pm4
;
37 uint32_t cb_target_mask
;
41 struct si_state_viewport
{
42 struct si_pm4_state pm4
;
43 struct pipe_viewport_state viewport
;
46 struct si_state_rasterizer
{
47 struct si_pm4_state pm4
;
50 bool multisample_enable
;
51 bool line_stipple_enable
;
52 unsigned sprite_coord_enable
;
53 unsigned pa_sc_line_stipple
;
54 unsigned pa_su_sc_mode_cntl
;
55 unsigned pa_cl_clip_cntl
;
56 unsigned pa_cl_vs_out_cntl
;
57 unsigned clip_plane_enable
;
63 struct si_pm4_state pm4
;
66 unsigned db_render_control
;
71 struct si_vertex_element
74 uint32_t rsrc_word3
[PIPE_MAX_ATTRIBS
];
75 struct pipe_vertex_element elements
[PIPE_MAX_ATTRIBS
];
80 struct si_pm4_state
*init
;
81 struct si_state_blend
*blend
;
82 struct si_pm4_state
*blend_color
;
83 struct si_pm4_state
*clip
;
84 struct si_pm4_state
*sample_mask
;
85 struct si_pm4_state
*scissor
;
86 struct si_state_viewport
*viewport
;
87 struct si_state_rasterizer
*rasterizer
;
88 struct si_state_dsa
*dsa
;
89 struct si_pm4_state
*fb_rs
;
90 struct si_pm4_state
*fb_blend
;
91 struct si_pm4_state
*dsa_stencil_ref
;
92 struct si_pm4_state
*es
;
93 struct si_pm4_state
*gs
;
94 struct si_pm4_state
*gs_rings
;
95 struct si_pm4_state
*gs_sampler
;
96 struct si_pm4_state
*gs_onoff
;
97 struct si_pm4_state
*vs
;
98 struct si_pm4_state
*vs_sampler
;
99 struct si_pm4_state
*ps
;
100 struct si_pm4_state
*ps_sampler
;
101 struct si_pm4_state
*spi
;
102 struct si_pm4_state
*vertex_buffers
;
103 struct si_pm4_state
*draw_info
;
104 struct si_pm4_state
*draw
;
106 struct si_pm4_state
*array
[0];
109 #define NUM_TEX_UNITS 16
111 /* User sampler views: 0..15
112 * FMASK sampler views: 16..31 (no sampler states)
114 #define FMASK_TEX_OFFSET NUM_TEX_UNITS
115 #define NUM_SAMPLER_VIEWS (FMASK_TEX_OFFSET+NUM_TEX_UNITS)
116 #define NUM_SAMPLER_STATES NUM_TEX_UNITS
118 #define NUM_PIPE_CONST_BUFFERS 16
119 #define NUM_CONST_BUFFERS (NUM_PIPE_CONST_BUFFERS + 1)
121 #define SI_RING_ESGS 0
122 #define SI_RING_GSVS 1
124 /* This represents resource descriptors in memory, such as buffer resources,
125 * image resources, and sampler states.
127 struct si_descriptors
{
128 struct r600_atom atom
;
130 /* The size of one resource descriptor. */
131 unsigned element_dw_size
;
132 /* The maximum number of resource descriptors. */
133 unsigned num_elements
;
135 /* The buffer where resource descriptors are stored. */
136 struct r600_resource
*buffer
;
138 /* The i-th bit is set if that element is dirty (changed but not emitted). */
140 /* The i-th bit is set if that element is enabled (non-NULL resource). */
141 unsigned enabled_mask
;
143 /* We can't update descriptors directly because the GPU might be
144 * reading them at the same time, so we have to update them
145 * in a copy-on-write manner. Each such copy is called a context,
146 * which is just another array descriptors in the same buffer. */
147 unsigned current_context_id
;
148 /* The size of a context, should be equal to 4*element_dw_size*num_elements. */
149 unsigned context_size
;
151 /* The shader userdata register where the 64-bit pointer to the descriptor
152 * array will be stored. */
153 unsigned shader_userdata_reg
;
156 struct si_sampler_views
{
157 struct si_descriptors desc
;
158 struct pipe_sampler_view
*views
[NUM_SAMPLER_VIEWS
];
159 uint32_t *desc_data
[NUM_SAMPLER_VIEWS
];
162 struct si_buffer_resources
{
163 struct si_descriptors desc
;
164 unsigned num_buffers
;
165 enum radeon_bo_usage shader_usage
; /* READ, WRITE, or READWRITE */
166 enum radeon_bo_priority priority
;
167 struct pipe_resource
**buffers
; /* this has num_buffers elements */
168 uint32_t *desc_storage
; /* this has num_buffers*4 elements */
169 uint32_t **desc_data
; /* an array of pointers pointing to desc_storage */
172 #define si_pm4_block_idx(member) \
173 (offsetof(union si_state, named.member) / sizeof(struct si_pm4_state *))
175 #define si_pm4_state_changed(sctx, member) \
176 ((sctx)->queued.named.member != (sctx)->emitted.named.member)
178 #define si_pm4_bind_state(sctx, member, value) \
180 (sctx)->queued.named.member = (value); \
183 #define si_pm4_delete_state(sctx, member, value) \
185 if ((sctx)->queued.named.member == (value)) { \
186 (sctx)->queued.named.member = NULL; \
188 si_pm4_free_state(sctx, (struct si_pm4_state *)(value), \
189 si_pm4_block_idx(member)); \
192 #define si_pm4_set_state(sctx, member, value) \
194 if ((sctx)->queued.named.member != (value)) { \
195 si_pm4_free_state(sctx, \
196 (struct si_pm4_state *)(sctx)->queued.named.member, \
197 si_pm4_block_idx(member)); \
198 (sctx)->queued.named.member = (value); \
202 /* si_descriptors.c */
203 void si_set_sampler_view(struct si_context
*sctx
, unsigned shader
,
204 unsigned slot
, struct pipe_sampler_view
*view
,
205 unsigned *view_desc
);
206 void si_set_ring_buffer(struct pipe_context
*ctx
, uint shader
, uint slot
,
207 struct pipe_constant_buffer
*input
,
208 unsigned stride
, unsigned num_records
,
209 bool add_tid
, bool swizzle
,
210 unsigned element_size
, unsigned index_stride
);
211 void si_init_all_descriptors(struct si_context
*sctx
);
212 void si_release_all_descriptors(struct si_context
*sctx
);
213 void si_all_descriptors_begin_new_cs(struct si_context
*sctx
);
214 void si_copy_buffer(struct si_context
*sctx
,
215 struct pipe_resource
*dst
, struct pipe_resource
*src
,
216 uint64_t dst_offset
, uint64_t src_offset
, unsigned size
);
217 void si_upload_const_buffer(struct si_context
*sctx
, struct r600_resource
**rbuffer
,
218 const uint8_t *ptr
, unsigned size
, uint32_t *const_offset
);
221 struct si_pipe_shader_selector
;
223 boolean
si_is_format_supported(struct pipe_screen
*screen
,
224 enum pipe_format format
,
225 enum pipe_texture_target target
,
226 unsigned sample_count
,
228 int si_shader_select(struct pipe_context
*ctx
,
229 struct si_pipe_shader_selector
*sel
);
230 void si_init_state_functions(struct si_context
*sctx
);
231 void si_init_config(struct si_context
*sctx
);
232 unsigned cik_bank_wh(unsigned bankwh
);
233 unsigned cik_db_pipe_config(struct si_screen
*sscreen
, unsigned tile_mode
);
234 unsigned cik_macro_tile_aspect(unsigned macro_tile_aspect
);
235 unsigned cik_tile_split(unsigned tile_split
);
236 unsigned si_tile_mode_index(struct r600_texture
*rtex
, unsigned level
, bool stencil
);
238 /* si_state_draw.c */
239 extern const struct r600_atom si_atom_cache_flush
;
240 void si_emit_cache_flush(struct r600_common_context
*sctx
, struct r600_atom
*atom
);
241 void si_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*dinfo
);
244 void si_cmd_context_control(struct si_pm4_state
*pm4
);
245 void si_cmd_draw_index_2(struct si_pm4_state
*pm4
, uint32_t max_size
,
246 uint64_t index_base
, uint32_t index_count
,
247 uint32_t initiator
, bool predicate
);
248 void si_cmd_draw_index_auto(struct si_pm4_state
*pm4
, uint32_t count
,
249 uint32_t initiator
, bool predicate
);
250 void si_cmd_surface_sync(struct si_pm4_state
*pm4
, uint32_t cp_coher_cntl
);