radeonsi: handle PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE
[mesa.git] / src / gallium / drivers / radeonsi / si_state.h
1 /*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 *
23 * Authors:
24 * Christian König <christian.koenig@amd.com>
25 */
26
27 #ifndef SI_STATE_H
28 #define SI_STATE_H
29
30 #include "radeonsi_pm4.h"
31 #include "../radeon/r600_pipe_common.h"
32
33 struct si_state_blend {
34 struct si_pm4_state pm4;
35 uint32_t cb_target_mask;
36 bool alpha_to_one;
37 };
38
39 struct si_state_viewport {
40 struct si_pm4_state pm4;
41 struct pipe_viewport_state viewport;
42 };
43
44 struct si_state_rasterizer {
45 struct si_pm4_state pm4;
46 bool flatshade;
47 bool two_side;
48 bool multisample_enable;
49 bool line_stipple_enable;
50 unsigned sprite_coord_enable;
51 unsigned pa_sc_line_stipple;
52 unsigned pa_su_sc_mode_cntl;
53 unsigned pa_cl_clip_cntl;
54 unsigned pa_cl_vs_out_cntl;
55 unsigned clip_plane_enable;
56 float offset_units;
57 float offset_scale;
58 };
59
60 struct si_state_dsa {
61 struct si_pm4_state pm4;
62 float alpha_ref;
63 unsigned alpha_func;
64 unsigned db_render_override;
65 unsigned db_render_control;
66 uint8_t valuemask[2];
67 uint8_t writemask[2];
68 };
69
70 struct si_vertex_element
71 {
72 unsigned count;
73 uint32_t rsrc_word3[PIPE_MAX_ATTRIBS];
74 struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
75 };
76
77 union si_state {
78 struct {
79 struct si_pm4_state *init;
80 struct si_state_blend *blend;
81 struct si_pm4_state *blend_color;
82 struct si_pm4_state *clip;
83 struct si_pm4_state *sample_mask;
84 struct si_pm4_state *scissor;
85 struct si_state_viewport *viewport;
86 struct si_pm4_state *framebuffer;
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 *vs;
93 struct si_pm4_state *vs_sampler;
94 struct si_pm4_state *ps;
95 struct si_pm4_state *ps_sampler;
96 struct si_pm4_state *spi;
97 struct si_pm4_state *vertex_buffers;
98 struct si_pm4_state *draw_info;
99 struct si_pm4_state *draw;
100 } named;
101 struct si_pm4_state *array[0];
102 };
103
104 #define NUM_TEX_UNITS 16
105
106 /* User sampler views: 0..15
107 * FMASK sampler views: 16..31 (no sampler states)
108 */
109 #define FMASK_TEX_OFFSET NUM_TEX_UNITS
110 #define NUM_SAMPLER_VIEWS (FMASK_TEX_OFFSET+NUM_TEX_UNITS)
111 #define NUM_SAMPLER_STATES NUM_TEX_UNITS
112
113 #define NUM_PIPE_CONST_BUFFERS 16
114 #define NUM_CONST_BUFFERS 17
115
116 /* This represents resource descriptors in memory, such as buffer resources,
117 * image resources, and sampler states.
118 */
119 struct si_descriptors {
120 struct r600_atom atom;
121
122 /* The size of one resource descriptor. */
123 unsigned element_dw_size;
124 /* The maximum number of resource descriptors. */
125 unsigned num_elements;
126
127 /* The buffer where resource descriptors are stored. */
128 struct r600_resource *buffer;
129
130 /* The i-th bit is set if that element is dirty (changed but not emitted). */
131 unsigned dirty_mask;
132 /* The i-th bit is set if that element is enabled (non-NULL resource). */
133 unsigned enabled_mask;
134
135 /* We can't update descriptors directly because the GPU might be
136 * reading them at the same time, so we have to update them
137 * in a copy-on-write manner. Each such copy is called a context,
138 * which is just another array descriptors in the same buffer. */
139 unsigned current_context_id;
140 /* The size of a context, should be equal to 4*element_dw_size*num_elements. */
141 unsigned context_size;
142
143 /* The shader userdata register where the 64-bit pointer to the descriptor
144 * array will be stored. */
145 unsigned shader_userdata_reg;
146 };
147
148 struct si_sampler_views {
149 struct si_descriptors desc;
150 struct pipe_sampler_view *views[NUM_SAMPLER_VIEWS];
151 uint32_t *desc_data[NUM_SAMPLER_VIEWS];
152 };
153
154 struct si_buffer_resources {
155 struct si_descriptors desc;
156 unsigned num_buffers;
157 enum radeon_bo_usage shader_usage; /* READ, WRITE, or READWRITE */
158 struct pipe_resource **buffers; /* this has num_buffers elements */
159 uint32_t *desc_storage; /* this has num_buffers*4 elements */
160 uint32_t **desc_data; /* an array of pointers pointing to desc_storage */
161 };
162
163 #define si_pm4_block_idx(member) \
164 (offsetof(union si_state, named.member) / sizeof(struct si_pm4_state *))
165
166 #define si_pm4_state_changed(rctx, member) \
167 ((rctx)->queued.named.member != (rctx)->emitted.named.member)
168
169 #define si_pm4_bind_state(rctx, member, value) \
170 do { \
171 (rctx)->queued.named.member = (value); \
172 } while(0)
173
174 #define si_pm4_delete_state(rctx, member, value) \
175 do { \
176 if ((rctx)->queued.named.member == (value)) { \
177 (rctx)->queued.named.member = NULL; \
178 } \
179 si_pm4_free_state(rctx, (struct si_pm4_state *)(value), \
180 si_pm4_block_idx(member)); \
181 } while(0)
182
183 #define si_pm4_set_state(rctx, member, value) \
184 do { \
185 if ((rctx)->queued.named.member != (value)) { \
186 si_pm4_free_state(rctx, \
187 (struct si_pm4_state *)(rctx)->queued.named.member, \
188 si_pm4_block_idx(member)); \
189 (rctx)->queued.named.member = (value); \
190 } \
191 } while(0)
192
193 /* si_descriptors.c */
194 void si_set_sampler_view(struct r600_context *rctx, unsigned shader,
195 unsigned slot, struct pipe_sampler_view *view,
196 unsigned *view_desc);
197 void si_init_all_descriptors(struct r600_context *rctx);
198 void si_release_all_descriptors(struct r600_context *rctx);
199 void si_all_descriptors_begin_new_cs(struct r600_context *rctx);
200 void si_copy_buffer(struct r600_context *rctx,
201 struct pipe_resource *dst, struct pipe_resource *src,
202 uint64_t dst_offset, uint64_t src_offset, unsigned size);
203 void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf);
204
205 /* si_state.c */
206 struct si_pipe_shader_selector;
207
208 boolean si_is_format_supported(struct pipe_screen *screen,
209 enum pipe_format format,
210 enum pipe_texture_target target,
211 unsigned sample_count,
212 unsigned usage);
213 int si_shader_select(struct pipe_context *ctx,
214 struct si_pipe_shader_selector *sel,
215 unsigned *dirty);
216 void si_init_state_functions(struct r600_context *rctx);
217 void si_init_config(struct r600_context *rctx);
218
219 /* si_state_draw.c */
220 extern const struct r600_atom si_atom_cache_flush;
221 void si_emit_cache_flush(struct r600_common_context *rctx, struct r600_atom *atom);
222 void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo);
223
224 /* si_commands.c */
225 void si_cmd_context_control(struct si_pm4_state *pm4);
226 void si_cmd_draw_index_2(struct si_pm4_state *pm4, uint32_t max_size,
227 uint64_t index_base, uint32_t index_count,
228 uint32_t initiator, bool predicate);
229 void si_cmd_draw_index_auto(struct si_pm4_state *pm4, uint32_t count,
230 uint32_t initiator, bool predicate);
231 void si_cmd_surface_sync(struct si_pm4_state *pm4, uint32_t cp_coher_cntl);
232
233 #endif