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>
30 #include "radeonsi_pm4.h"
31 #include "../radeon/r600_pipe_common.h"
33 struct si_state_blend
{
34 struct si_pm4_state pm4
;
35 uint32_t cb_target_mask
;
39 struct si_state_viewport
{
40 struct si_pm4_state pm4
;
41 struct pipe_viewport_state viewport
;
44 struct si_state_rasterizer
{
45 struct si_pm4_state pm4
;
48 bool multisample_enable
;
49 unsigned sprite_coord_enable
;
50 unsigned pa_sc_line_stipple
;
51 unsigned pa_su_sc_mode_cntl
;
52 unsigned pa_cl_clip_cntl
;
53 unsigned pa_cl_vs_out_cntl
;
54 unsigned clip_plane_enable
;
60 struct si_pm4_state pm4
;
63 unsigned db_render_override
;
64 unsigned db_render_control
;
69 struct si_vertex_element
72 uint32_t rsrc_word3
[PIPE_MAX_ATTRIBS
];
73 struct pipe_vertex_element elements
[PIPE_MAX_ATTRIBS
];
78 struct si_pm4_state
*init
;
79 struct si_state_blend
*blend
;
80 struct si_pm4_state
*blend_color
;
81 struct si_pm4_state
*clip
;
82 struct si_pm4_state
*sample_mask
;
83 struct si_pm4_state
*scissor
;
84 struct si_state_viewport
*viewport
;
85 struct si_pm4_state
*framebuffer
;
86 struct si_state_rasterizer
*rasterizer
;
87 struct si_state_dsa
*dsa
;
88 struct si_pm4_state
*fb_rs
;
89 struct si_pm4_state
*fb_blend
;
90 struct si_pm4_state
*dsa_stencil_ref
;
91 struct si_pm4_state
*vs
;
92 struct si_pm4_state
*vs_sampler
;
93 struct si_pm4_state
*ps
;
94 struct si_pm4_state
*ps_sampler
;
95 struct si_pm4_state
*spi
;
96 struct si_pm4_state
*vertex_buffers
;
97 struct si_pm4_state
*draw_info
;
98 struct si_pm4_state
*draw
;
100 struct si_pm4_state
*array
[0];
103 #define NUM_TEX_UNITS 16
105 /* User sampler views: 0..15
106 * FMASK sampler views: 16..31 (no sampler states)
108 #define FMASK_TEX_OFFSET NUM_TEX_UNITS
109 #define NUM_SAMPLER_VIEWS (FMASK_TEX_OFFSET+NUM_TEX_UNITS)
110 #define NUM_SAMPLER_STATES NUM_TEX_UNITS
112 #define NUM_CONST_BUFFERS 2
114 /* This represents resource descriptors in memory, such as buffer resources,
115 * image resources, and sampler states.
117 struct si_descriptors
{
118 struct r600_atom atom
;
120 /* The size of one resource descriptor. */
121 unsigned element_dw_size
;
122 /* The maximum number of resource descriptors. */
123 unsigned num_elements
;
125 /* The buffer where resource descriptors are stored. */
126 struct r600_resource
*buffer
;
128 /* The i-th bit is set if that element is dirty (changed but not emitted). */
130 /* The i-th bit is set if that element is enabled (non-NULL resource). */
131 unsigned enabled_mask
;
133 /* We can't update descriptors directly because the GPU might be
134 * reading them at the same time, so we have to update them
135 * in a copy-on-write manner. Each such copy is called a context,
136 * which is just another array descriptors in the same buffer. */
137 unsigned current_context_id
;
138 /* The size of a context, should be equal to 4*element_dw_size*num_elements. */
139 unsigned context_size
;
141 /* The shader userdata register where the 64-bit pointer to the descriptor
142 * array will be stored. */
143 unsigned shader_userdata_reg
;
146 struct si_sampler_views
{
147 struct si_descriptors desc
;
148 struct pipe_sampler_view
*views
[NUM_SAMPLER_VIEWS
];
149 uint32_t *desc_data
[NUM_SAMPLER_VIEWS
];
152 struct si_buffer_resources
{
153 struct si_descriptors desc
;
154 unsigned num_buffers
;
155 enum radeon_bo_usage shader_usage
; /* READ, WRITE, or READWRITE */
156 struct pipe_resource
**buffers
; /* this has num_buffers elements */
157 uint32_t *desc_storage
; /* this has num_buffers*4 elements */
158 uint32_t **desc_data
; /* an array of pointers pointing to desc_storage */
161 #define si_pm4_block_idx(member) \
162 (offsetof(union si_state, named.member) / sizeof(struct si_pm4_state *))
164 #define si_pm4_state_changed(rctx, member) \
165 ((rctx)->queued.named.member != (rctx)->emitted.named.member)
167 #define si_pm4_bind_state(rctx, member, value) \
169 (rctx)->queued.named.member = (value); \
172 #define si_pm4_delete_state(rctx, member, value) \
174 if ((rctx)->queued.named.member == (value)) { \
175 (rctx)->queued.named.member = NULL; \
177 si_pm4_free_state(rctx, (struct si_pm4_state *)(value), \
178 si_pm4_block_idx(member)); \
181 #define si_pm4_set_state(rctx, member, value) \
183 if ((rctx)->queued.named.member != (value)) { \
184 si_pm4_free_state(rctx, \
185 (struct si_pm4_state *)(rctx)->queued.named.member, \
186 si_pm4_block_idx(member)); \
187 (rctx)->queued.named.member = (value); \
191 /* si_descriptors.c */
192 void si_set_sampler_view(struct r600_context
*rctx
, unsigned shader
,
193 unsigned slot
, struct pipe_sampler_view
*view
,
194 unsigned *view_desc
);
195 void si_init_all_descriptors(struct r600_context
*rctx
);
196 void si_release_all_descriptors(struct r600_context
*rctx
);
197 void si_all_descriptors_begin_new_cs(struct r600_context
*rctx
);
200 struct si_pipe_shader_selector
;
202 boolean
si_is_format_supported(struct pipe_screen
*screen
,
203 enum pipe_format format
,
204 enum pipe_texture_target target
,
205 unsigned sample_count
,
207 int si_shader_select(struct pipe_context
*ctx
,
208 struct si_pipe_shader_selector
*sel
,
210 void si_init_state_functions(struct r600_context
*rctx
);
211 void si_init_config(struct r600_context
*rctx
);
213 /* si_state_draw.c */
214 extern const struct r600_atom si_atom_cache_flush
;
215 void si_emit_cache_flush(struct r600_common_context
*rctx
, struct r600_atom
*atom
);
216 void si_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*dinfo
);
219 void si_cmd_context_control(struct si_pm4_state
*pm4
);
220 void si_cmd_draw_index_2(struct si_pm4_state
*pm4
, uint32_t max_size
,
221 uint64_t index_base
, uint32_t index_count
,
222 uint32_t initiator
, bool predicate
);
223 void si_cmd_draw_index_auto(struct si_pm4_state
*pm4
, uint32_t count
,
224 uint32_t initiator
, bool predicate
);
225 void si_cmd_surface_sync(struct si_pm4_state
*pm4
, uint32_t cp_coher_cntl
);