ilo: embed ilo_state_vf in ilo_ve_state
[mesa.git] / src / gallium / drivers / ilo / ilo_state.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #ifndef ILO_STATE_H
29 #define ILO_STATE_H
30
31 #include "core/ilo_state_3d.h"
32 #include "core/ilo_state_cc.h"
33 #include "core/ilo_state_raster.h"
34 #include "core/ilo_state_sampler.h"
35 #include "core/ilo_state_sol.h"
36 #include "core/ilo_state_surface.h"
37 #include "core/ilo_state_urb.h"
38 #include "core/ilo_state_vf.h"
39 #include "core/ilo_state_viewport.h"
40 #include "core/ilo_state_zs.h"
41 #include "pipe/p_state.h"
42 #include "util/u_dynarray.h"
43
44 #include "ilo_common.h"
45
46 /**
47 * States that we track.
48 *
49 * XXX Do we want to count each sampler or vertex buffer as a state? If that
50 * is the case, there are simply not enough bits.
51 *
52 * XXX We want to treat primitive type and depth clear value as states, but
53 * there are not enough bits.
54 */
55 enum ilo_state {
56 ILO_STATE_VB,
57 ILO_STATE_VE,
58 ILO_STATE_IB,
59 ILO_STATE_VS,
60 ILO_STATE_GS,
61 ILO_STATE_SO,
62 ILO_STATE_CLIP,
63 ILO_STATE_VIEWPORT,
64 ILO_STATE_SCISSOR,
65 ILO_STATE_RASTERIZER,
66 ILO_STATE_POLY_STIPPLE,
67 ILO_STATE_SAMPLE_MASK,
68 ILO_STATE_FS,
69 ILO_STATE_DSA,
70 ILO_STATE_STENCIL_REF,
71 ILO_STATE_BLEND,
72 ILO_STATE_BLEND_COLOR,
73 ILO_STATE_FB,
74
75 ILO_STATE_SAMPLER_VS,
76 ILO_STATE_SAMPLER_GS,
77 ILO_STATE_SAMPLER_FS,
78 ILO_STATE_SAMPLER_CS,
79 ILO_STATE_VIEW_VS,
80 ILO_STATE_VIEW_GS,
81 ILO_STATE_VIEW_FS,
82 ILO_STATE_VIEW_CS,
83 ILO_STATE_CBUF,
84 ILO_STATE_RESOURCE,
85
86 ILO_STATE_CS,
87 ILO_STATE_CS_RESOURCE,
88 ILO_STATE_GLOBAL_BINDING,
89
90 ILO_STATE_COUNT,
91 };
92
93 /**
94 * Dirty flags of the states.
95 */
96 enum ilo_dirty_flags {
97 ILO_DIRTY_VB = 1 << ILO_STATE_VB,
98 ILO_DIRTY_VE = 1 << ILO_STATE_VE,
99 ILO_DIRTY_IB = 1 << ILO_STATE_IB,
100 ILO_DIRTY_VS = 1 << ILO_STATE_VS,
101 ILO_DIRTY_GS = 1 << ILO_STATE_GS,
102 ILO_DIRTY_SO = 1 << ILO_STATE_SO,
103 ILO_DIRTY_CLIP = 1 << ILO_STATE_CLIP,
104 ILO_DIRTY_VIEWPORT = 1 << ILO_STATE_VIEWPORT,
105 ILO_DIRTY_SCISSOR = 1 << ILO_STATE_SCISSOR,
106 ILO_DIRTY_RASTERIZER = 1 << ILO_STATE_RASTERIZER,
107 ILO_DIRTY_POLY_STIPPLE = 1 << ILO_STATE_POLY_STIPPLE,
108 ILO_DIRTY_SAMPLE_MASK = 1 << ILO_STATE_SAMPLE_MASK,
109 ILO_DIRTY_FS = 1 << ILO_STATE_FS,
110 ILO_DIRTY_DSA = 1 << ILO_STATE_DSA,
111 ILO_DIRTY_STENCIL_REF = 1 << ILO_STATE_STENCIL_REF,
112 ILO_DIRTY_BLEND = 1 << ILO_STATE_BLEND,
113 ILO_DIRTY_BLEND_COLOR = 1 << ILO_STATE_BLEND_COLOR,
114 ILO_DIRTY_FB = 1 << ILO_STATE_FB,
115 ILO_DIRTY_SAMPLER_VS = 1 << ILO_STATE_SAMPLER_VS,
116 ILO_DIRTY_SAMPLER_GS = 1 << ILO_STATE_SAMPLER_GS,
117 ILO_DIRTY_SAMPLER_FS = 1 << ILO_STATE_SAMPLER_FS,
118 ILO_DIRTY_SAMPLER_CS = 1 << ILO_STATE_SAMPLER_CS,
119 ILO_DIRTY_VIEW_VS = 1 << ILO_STATE_VIEW_VS,
120 ILO_DIRTY_VIEW_GS = 1 << ILO_STATE_VIEW_GS,
121 ILO_DIRTY_VIEW_FS = 1 << ILO_STATE_VIEW_FS,
122 ILO_DIRTY_VIEW_CS = 1 << ILO_STATE_VIEW_CS,
123 ILO_DIRTY_CBUF = 1 << ILO_STATE_CBUF,
124 ILO_DIRTY_RESOURCE = 1 << ILO_STATE_RESOURCE,
125 ILO_DIRTY_CS = 1 << ILO_STATE_CS,
126 ILO_DIRTY_CS_RESOURCE = 1 << ILO_STATE_CS_RESOURCE,
127 ILO_DIRTY_GLOBAL_BINDING = 1 << ILO_STATE_GLOBAL_BINDING,
128 ILO_DIRTY_ALL = 0xffffffff,
129 };
130
131 struct ilo_context;
132
133 struct ilo_ve_state {
134 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
135 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
136 unsigned vb_count;
137
138 /* these are not valid until the state is finalized */
139 uint32_t vf_data[PIPE_MAX_ATTRIBS][2];
140 struct ilo_state_vf_params_info vf_params;
141 struct ilo_state_vf vf;
142 };
143
144 struct ilo_cbuf_cso {
145 struct pipe_resource *resource;
146 struct ilo_state_surface_buffer_info info;
147 struct ilo_state_surface surface;
148
149 /*
150 * this CSO is not so constant because user buffer needs to be uploaded in
151 * finalize_constant_buffers()
152 */
153 const void *user_buffer;
154 };
155
156 struct ilo_sampler_cso {
157 struct ilo_state_sampler sampler;
158 struct ilo_state_sampler_border border;
159 bool saturate_s;
160 bool saturate_t;
161 bool saturate_r;
162 };
163
164 struct ilo_sampler_state {
165 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
166 };
167
168 struct ilo_cbuf_state {
169 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
170 uint32_t enabled_mask;
171 };
172
173 struct ilo_resource_state {
174 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
175 unsigned count;
176 };
177
178 struct ilo_view_cso {
179 struct pipe_sampler_view base;
180
181 struct ilo_state_surface surface;
182 };
183
184 struct ilo_view_state {
185 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
186 unsigned count;
187 };
188
189 struct ilo_rasterizer_state {
190 struct pipe_rasterizer_state state;
191
192 /* these are invalid until finalize_rasterizer() */
193 struct ilo_state_raster_info info;
194 struct ilo_state_raster rs;
195 };
196
197 struct ilo_viewport_state {
198 struct ilo_state_viewport_matrix_info matrices[ILO_MAX_VIEWPORTS];
199 struct ilo_state_viewport_scissor_info scissors[ILO_MAX_VIEWPORTS];
200 struct ilo_state_viewport_params_info params;
201
202 struct pipe_viewport_state viewport0;
203 struct pipe_scissor_state scissor0;
204
205 struct ilo_state_viewport vp;
206 uint32_t vp_data[20 * ILO_MAX_VIEWPORTS];
207 };
208
209 struct ilo_dsa_state {
210 struct ilo_state_cc_depth_info depth;
211
212 struct ilo_state_cc_stencil_info stencil;
213 struct {
214 uint8_t test_mask;
215 uint8_t write_mask;
216 } stencil_front, stencil_back;
217
218 bool alpha_test;
219 float alpha_ref;
220 enum gen_compare_function alpha_func;
221 };
222
223 struct ilo_blend_state {
224 struct ilo_state_cc_blend_rt_info rt[PIPE_MAX_COLOR_BUFS];
225 struct ilo_state_cc_blend_rt_info dummy_rt;
226 bool dual_blend;
227
228 /* these are invalid until finalize_blend() */
229 struct ilo_state_cc_blend_rt_info effective_rt[PIPE_MAX_COLOR_BUFS];
230 struct ilo_state_cc_info info;
231 struct ilo_state_cc cc;
232 bool alpha_may_kill;
233 };
234
235 struct ilo_global_binding_cso {
236 struct pipe_resource *resource;
237 uint32_t *handle;
238 };
239
240 /*
241 * In theory, we would like a "virtual" bo that serves as the global memory
242 * region. The virtual bo would reserve a region in the GTT aperture, but the
243 * pages of it would come from those of the global bindings.
244 *
245 * The virtual bo would be created in launch_grid(). The global bindings
246 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
247 * be created. The handles returned by set_global_binding() would be offsets
248 * into the virtual bo.
249 *
250 * But for now, we will create a SURFACE_STATE for each of the bindings. The
251 * handle of a global binding consists of the offset and the binding table
252 * index.
253 */
254 struct ilo_global_binding {
255 struct util_dynarray bindings;
256 unsigned count;
257 };
258
259 struct ilo_state_vector {
260 const struct pipe_draw_info *draw;
261
262 uint32_t dirty;
263
264 struct ilo_vb_state vb;
265 struct ilo_ve_state *ve;
266 struct ilo_ib_state ib;
267
268 struct ilo_shader_state *vs;
269 struct ilo_shader_state *gs;
270
271 struct ilo_so_state so;
272
273 struct pipe_clip_state clip;
274
275 struct ilo_viewport_state viewport;
276
277 struct ilo_rasterizer_state *rasterizer;
278
279 struct pipe_poly_stipple poly_stipple;
280 unsigned sample_mask;
281
282 struct ilo_shader_state *fs;
283
284 struct ilo_state_cc_params_info cc_params;
285 struct pipe_stencil_ref stencil_ref;
286 const struct ilo_dsa_state *dsa;
287 struct ilo_blend_state *blend;
288
289 struct ilo_fb_state fb;
290
291 struct ilo_state_urb urb;
292
293 /* shader resources */
294 struct ilo_sampler_state sampler[PIPE_SHADER_TYPES];
295 struct ilo_view_state view[PIPE_SHADER_TYPES];
296 struct ilo_cbuf_state cbuf[PIPE_SHADER_TYPES];
297 struct ilo_resource_state resource;
298
299 struct ilo_state_sampler disabled_sampler;
300
301 /* GPGPU */
302 struct ilo_shader_state *cs;
303 struct ilo_resource_state cs_resource;
304 struct ilo_global_binding global_binding;
305 };
306
307 void
308 ilo_init_state_functions(struct ilo_context *ilo);
309
310 void
311 ilo_finalize_3d_states(struct ilo_context *ilo,
312 const struct pipe_draw_info *draw);
313
314 void
315 ilo_finalize_compute_states(struct ilo_context *ilo);
316
317 void
318 ilo_state_vector_init(const struct ilo_dev *dev,
319 struct ilo_state_vector *vec);
320
321 void
322 ilo_state_vector_cleanup(struct ilo_state_vector *vec);
323
324 void
325 ilo_state_vector_resource_renamed(struct ilo_state_vector *vec,
326 struct pipe_resource *res);
327
328 void
329 ilo_state_vector_dump_dirty(const struct ilo_state_vector *vec);
330
331 #endif /* ILO_STATE_H */