8f6cce2b53a06cd4604068727886357d8e8f376c
[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_raster.h"
33 #include "core/ilo_state_sampler.h"
34 #include "core/ilo_state_surface.h"
35 #include "core/ilo_state_viewport.h"
36 #include "core/ilo_state_zs.h"
37 #include "pipe/p_state.h"
38 #include "util/u_dynarray.h"
39
40 #include "ilo_common.h"
41
42 /**
43 * States that we track.
44 *
45 * XXX Do we want to count each sampler or vertex buffer as a state? If that
46 * is the case, there are simply not enough bits.
47 *
48 * XXX We want to treat primitive type and depth clear value as states, but
49 * there are not enough bits.
50 */
51 enum ilo_state {
52 ILO_STATE_VB,
53 ILO_STATE_VE,
54 ILO_STATE_IB,
55 ILO_STATE_VS,
56 ILO_STATE_GS,
57 ILO_STATE_SO,
58 ILO_STATE_CLIP,
59 ILO_STATE_VIEWPORT,
60 ILO_STATE_SCISSOR,
61 ILO_STATE_RASTERIZER,
62 ILO_STATE_POLY_STIPPLE,
63 ILO_STATE_SAMPLE_MASK,
64 ILO_STATE_FS,
65 ILO_STATE_DSA,
66 ILO_STATE_STENCIL_REF,
67 ILO_STATE_BLEND,
68 ILO_STATE_BLEND_COLOR,
69 ILO_STATE_FB,
70
71 ILO_STATE_SAMPLER_VS,
72 ILO_STATE_SAMPLER_GS,
73 ILO_STATE_SAMPLER_FS,
74 ILO_STATE_SAMPLER_CS,
75 ILO_STATE_VIEW_VS,
76 ILO_STATE_VIEW_GS,
77 ILO_STATE_VIEW_FS,
78 ILO_STATE_VIEW_CS,
79 ILO_STATE_CBUF,
80 ILO_STATE_RESOURCE,
81
82 ILO_STATE_CS,
83 ILO_STATE_CS_RESOURCE,
84 ILO_STATE_GLOBAL_BINDING,
85
86 ILO_STATE_COUNT,
87 };
88
89 /**
90 * Dirty flags of the states.
91 */
92 enum ilo_dirty_flags {
93 ILO_DIRTY_VB = 1 << ILO_STATE_VB,
94 ILO_DIRTY_VE = 1 << ILO_STATE_VE,
95 ILO_DIRTY_IB = 1 << ILO_STATE_IB,
96 ILO_DIRTY_VS = 1 << ILO_STATE_VS,
97 ILO_DIRTY_GS = 1 << ILO_STATE_GS,
98 ILO_DIRTY_SO = 1 << ILO_STATE_SO,
99 ILO_DIRTY_CLIP = 1 << ILO_STATE_CLIP,
100 ILO_DIRTY_VIEWPORT = 1 << ILO_STATE_VIEWPORT,
101 ILO_DIRTY_SCISSOR = 1 << ILO_STATE_SCISSOR,
102 ILO_DIRTY_RASTERIZER = 1 << ILO_STATE_RASTERIZER,
103 ILO_DIRTY_POLY_STIPPLE = 1 << ILO_STATE_POLY_STIPPLE,
104 ILO_DIRTY_SAMPLE_MASK = 1 << ILO_STATE_SAMPLE_MASK,
105 ILO_DIRTY_FS = 1 << ILO_STATE_FS,
106 ILO_DIRTY_DSA = 1 << ILO_STATE_DSA,
107 ILO_DIRTY_STENCIL_REF = 1 << ILO_STATE_STENCIL_REF,
108 ILO_DIRTY_BLEND = 1 << ILO_STATE_BLEND,
109 ILO_DIRTY_BLEND_COLOR = 1 << ILO_STATE_BLEND_COLOR,
110 ILO_DIRTY_FB = 1 << ILO_STATE_FB,
111 ILO_DIRTY_SAMPLER_VS = 1 << ILO_STATE_SAMPLER_VS,
112 ILO_DIRTY_SAMPLER_GS = 1 << ILO_STATE_SAMPLER_GS,
113 ILO_DIRTY_SAMPLER_FS = 1 << ILO_STATE_SAMPLER_FS,
114 ILO_DIRTY_SAMPLER_CS = 1 << ILO_STATE_SAMPLER_CS,
115 ILO_DIRTY_VIEW_VS = 1 << ILO_STATE_VIEW_VS,
116 ILO_DIRTY_VIEW_GS = 1 << ILO_STATE_VIEW_GS,
117 ILO_DIRTY_VIEW_FS = 1 << ILO_STATE_VIEW_FS,
118 ILO_DIRTY_VIEW_CS = 1 << ILO_STATE_VIEW_CS,
119 ILO_DIRTY_CBUF = 1 << ILO_STATE_CBUF,
120 ILO_DIRTY_RESOURCE = 1 << ILO_STATE_RESOURCE,
121 ILO_DIRTY_CS = 1 << ILO_STATE_CS,
122 ILO_DIRTY_CS_RESOURCE = 1 << ILO_STATE_CS_RESOURCE,
123 ILO_DIRTY_GLOBAL_BINDING = 1 << ILO_STATE_GLOBAL_BINDING,
124 ILO_DIRTY_ALL = 0xffffffff,
125 };
126
127 struct ilo_context;
128
129 struct ilo_cbuf_cso {
130 struct pipe_resource *resource;
131 struct ilo_state_surface_buffer_info info;
132 struct ilo_state_surface surface;
133
134 /*
135 * this CSO is not so constant because user buffer needs to be uploaded in
136 * finalize_constant_buffers()
137 */
138 const void *user_buffer;
139 };
140
141 struct ilo_sampler_cso {
142 struct ilo_state_sampler sampler;
143 struct ilo_state_sampler_border border;
144 bool saturate_s;
145 bool saturate_t;
146 bool saturate_r;
147 };
148
149 struct ilo_sampler_state {
150 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
151 };
152
153 struct ilo_cbuf_state {
154 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
155 uint32_t enabled_mask;
156 };
157
158 struct ilo_resource_state {
159 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
160 unsigned count;
161 };
162
163 struct ilo_view_cso {
164 struct pipe_sampler_view base;
165
166 struct ilo_state_surface surface;
167 };
168
169 struct ilo_view_state {
170 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
171 unsigned count;
172 };
173
174 struct ilo_rasterizer_state {
175 struct pipe_rasterizer_state state;
176
177 /* these are invalid until finalize_rasterizer() */
178 struct ilo_state_raster_info info;
179 struct ilo_state_raster rs;
180 };
181
182 struct ilo_viewport_state {
183 struct ilo_state_viewport_matrix_info matrices[ILO_MAX_VIEWPORTS];
184 struct ilo_state_viewport_scissor_info scissors[ILO_MAX_VIEWPORTS];
185 struct ilo_state_viewport_params_info params;
186
187 struct pipe_viewport_state viewport0;
188 struct pipe_scissor_state scissor0;
189
190 struct ilo_state_viewport vp;
191 uint32_t vp_data[20 * ILO_MAX_VIEWPORTS];
192 };
193
194 struct ilo_global_binding_cso {
195 struct pipe_resource *resource;
196 uint32_t *handle;
197 };
198
199 /*
200 * In theory, we would like a "virtual" bo that serves as the global memory
201 * region. The virtual bo would reserve a region in the GTT aperture, but the
202 * pages of it would come from those of the global bindings.
203 *
204 * The virtual bo would be created in launch_grid(). The global bindings
205 * would be added to the virtual bo. A SURFACE_STATE for the virtual bo would
206 * be created. The handles returned by set_global_binding() would be offsets
207 * into the virtual bo.
208 *
209 * But for now, we will create a SURFACE_STATE for each of the bindings. The
210 * handle of a global binding consists of the offset and the binding table
211 * index.
212 */
213 struct ilo_global_binding {
214 struct util_dynarray bindings;
215 unsigned count;
216 };
217
218 struct ilo_state_vector {
219 const struct pipe_draw_info *draw;
220
221 uint32_t dirty;
222
223 struct ilo_vb_state vb;
224 struct ilo_ve_state *ve;
225 struct ilo_ib_state ib;
226
227 struct ilo_shader_state *vs;
228 struct ilo_shader_state *gs;
229
230 struct ilo_so_state so;
231
232 struct pipe_clip_state clip;
233
234 struct ilo_viewport_state viewport;
235
236 struct ilo_rasterizer_state *rasterizer;
237
238 struct pipe_poly_stipple poly_stipple;
239 unsigned sample_mask;
240
241 struct ilo_shader_state *fs;
242
243 const struct ilo_dsa_state *dsa;
244 struct pipe_stencil_ref stencil_ref;
245 const struct ilo_blend_state *blend;
246 struct pipe_blend_color blend_color;
247 struct ilo_fb_state fb;
248
249 /* shader resources */
250 struct ilo_sampler_state sampler[PIPE_SHADER_TYPES];
251 struct ilo_view_state view[PIPE_SHADER_TYPES];
252 struct ilo_cbuf_state cbuf[PIPE_SHADER_TYPES];
253 struct ilo_resource_state resource;
254
255 struct ilo_state_sampler disabled_sampler;
256
257 /* GPGPU */
258 struct ilo_shader_state *cs;
259 struct ilo_resource_state cs_resource;
260 struct ilo_global_binding global_binding;
261 };
262
263 void
264 ilo_init_state_functions(struct ilo_context *ilo);
265
266 void
267 ilo_finalize_3d_states(struct ilo_context *ilo,
268 const struct pipe_draw_info *draw);
269
270 void
271 ilo_finalize_compute_states(struct ilo_context *ilo);
272
273 void
274 ilo_state_vector_init(const struct ilo_dev *dev,
275 struct ilo_state_vector *vec);
276
277 void
278 ilo_state_vector_cleanup(struct ilo_state_vector *vec);
279
280 void
281 ilo_state_vector_resource_renamed(struct ilo_state_vector *vec,
282 struct pipe_resource *res);
283
284 void
285 ilo_state_vector_dump_dirty(const struct ilo_state_vector *vec);
286
287 #endif /* ILO_STATE_H */