ilo: initialize constant buffer SURFACE_STATE early
[mesa.git] / src / gallium / drivers / ilo / ilo_gpe.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 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_GPE_H
29 #define ILO_GPE_H
30
31 #include "ilo_common.h"
32
33 /**
34 * \see brw_context.h
35 */
36 #define ILO_MAX_DRAW_BUFFERS 8
37 #define ILO_MAX_CONST_BUFFERS (1 + 12)
38 #define ILO_MAX_SAMPLER_VIEWS 16
39 #define ILO_MAX_SAMPLERS 16
40 #define ILO_MAX_SO_BINDINGS 64
41 #define ILO_MAX_SO_BUFFERS 4
42 #define ILO_MAX_VIEWPORTS 1
43
44 #define ILO_MAX_VS_SURFACES (ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
45 #define ILO_VS_CONST_SURFACE(i) (i)
46 #define ILO_VS_TEXTURE_SURFACE(i) (ILO_MAX_CONST_BUFFERS + i)
47
48 #define ILO_MAX_GS_SURFACES (ILO_MAX_SO_BINDINGS)
49 #define ILO_GS_SO_SURFACE(i) (i)
50
51 #define ILO_MAX_WM_SURFACES (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + ILO_MAX_SAMPLER_VIEWS)
52 #define ILO_WM_DRAW_SURFACE(i) (i)
53 #define ILO_WM_CONST_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + i)
54 #define ILO_WM_TEXTURE_SURFACE(i) (ILO_MAX_DRAW_BUFFERS + ILO_MAX_CONST_BUFFERS + i)
55
56 #define ILO_GPE_VALID_GEN(dev, min_gen, max_gen) \
57 assert((dev)->gen >= ILO_GEN(min_gen) && (dev)->gen <= ILO_GEN(max_gen))
58
59 struct ilo_buffer;
60 struct ilo_texture;
61 struct ilo_shader_state;
62
63 struct ilo_vb_state {
64 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
65 uint32_t enabled_mask;
66 };
67
68 struct ilo_ib_state {
69 struct pipe_resource *buffer;
70 const void *user_buffer;
71 unsigned offset;
72 unsigned index_size;
73
74 /* these are not valid until the state is finalized */
75 struct pipe_resource *hw_resource;
76 unsigned hw_index_size;
77 /* an offset to be added to pipe_draw_info::start */
78 int64_t draw_start_offset;
79 };
80
81 struct ilo_ve_cso {
82 /* VERTEX_ELEMENT_STATE */
83 uint32_t payload[2];
84 };
85
86 struct ilo_ve_state {
87 struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
88 unsigned count;
89
90 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
91 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
92 unsigned vb_count;
93 };
94
95 struct ilo_so_state {
96 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
97 unsigned count;
98 unsigned append_bitmask;
99
100 bool enabled;
101 };
102
103 struct ilo_viewport_cso {
104 /* matrix form */
105 float m00, m11, m22, m30, m31, m32;
106
107 /* guardband in NDC space */
108 float min_gbx, min_gby, max_gbx, max_gby;
109
110 /* viewport in screen space */
111 float min_x, min_y, min_z;
112 float max_x, max_y, max_z;
113 };
114
115 struct ilo_viewport_state {
116 struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
117 unsigned count;
118
119 struct pipe_viewport_state viewport0;
120 };
121
122 struct ilo_scissor_state {
123 /* SCISSOR_RECT */
124 uint32_t payload[ILO_MAX_VIEWPORTS * 2];
125
126 struct pipe_scissor_state scissor0;
127 };
128
129 struct ilo_rasterizer_clip {
130 /* 3DSTATE_CLIP */
131 uint32_t payload[3];
132
133 uint32_t can_enable_guardband;
134 };
135
136 struct ilo_rasterizer_sf {
137 /* 3DSTATE_SF */
138 uint32_t payload[6];
139 uint32_t dw_msaa;
140 };
141
142 struct ilo_rasterizer_wm {
143 /* 3DSTATE_WM */
144 uint32_t payload[2];
145 uint32_t dw_msaa_rast;
146 uint32_t dw_msaa_disp;
147 };
148
149 struct ilo_rasterizer_state {
150 struct pipe_rasterizer_state state;
151
152 struct ilo_rasterizer_clip clip;
153 struct ilo_rasterizer_sf sf;
154 struct ilo_rasterizer_wm wm;
155 };
156
157 struct ilo_dsa_state {
158 /* DEPTH_STENCIL_STATE */
159 uint32_t payload[3];
160
161 uint32_t dw_alpha;
162 ubyte alpha_ref;
163 };
164
165 struct ilo_blend_cso {
166 /* BLEND_STATE */
167 uint32_t payload[2];
168
169 uint32_t dw_blend;
170 uint32_t dw_blend_dst_alpha_forced_one;
171
172 uint32_t dw_logicop;
173 uint32_t dw_alpha_mod;
174 };
175
176 struct ilo_blend_state {
177 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
178
179 bool independent_blend_enable;
180 bool dual_blend;
181 bool alpha_to_coverage;
182 };
183
184 struct ilo_sampler_cso {
185 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
186 uint32_t payload[15];
187
188 uint32_t dw_filter;
189 uint32_t dw_filter_aniso;
190 uint32_t dw_wrap;
191 uint32_t dw_wrap_1d;
192 uint32_t dw_wrap_cube;
193
194 bool anisotropic;
195 bool saturate_r;
196 bool saturate_s;
197 bool saturate_t;
198 };
199
200 struct ilo_sampler_state {
201 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
202 unsigned count;
203 };
204
205 struct ilo_view_surface {
206 /* SURFACE_STATE */
207 uint32_t payload[8];
208 struct intel_bo *bo;
209 };
210
211 struct ilo_view_cso {
212 struct pipe_sampler_view base;
213
214 struct ilo_view_surface surface;
215 };
216
217 struct ilo_view_state {
218 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
219 unsigned count;
220 };
221
222 struct ilo_cbuf_cso {
223 struct pipe_resource *resource;
224 struct ilo_view_surface surface;
225
226 /*
227 * this CSO is not so constant because user buffer needs to be uploaded in
228 * finalize_constant_buffers()
229 */
230 const void *user_buffer;
231 unsigned user_buffer_size;
232 };
233
234 struct ilo_cbuf_state {
235 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
236 uint32_t enabled_mask;
237 };
238
239 struct ilo_resource_state {
240 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
241 unsigned count;
242 };
243
244 struct ilo_surface_cso {
245 struct pipe_surface base;
246
247 bool is_rt;
248 union {
249 struct ilo_view_surface rt;
250 struct ilo_zs_surface {
251 uint32_t payload[10];
252 struct intel_bo *bo;
253 struct intel_bo *hiz_bo;
254 struct intel_bo *separate_s8_bo;
255 } zs;
256 } u;
257 };
258
259 struct ilo_fb_state {
260 struct pipe_framebuffer_state state;
261
262 struct ilo_zs_surface null_zs;
263 unsigned num_samples;
264 };
265
266 struct ilo_global_binding {
267 /*
268 * XXX These should not be treated as real resources (and there could be
269 * thousands of them). They should be treated as regions in GLOBAL
270 * resource, which is the only real resource.
271 *
272 * That is, a resource here should instead be
273 *
274 * struct ilo_global_region {
275 * struct pipe_resource base;
276 * int offset;
277 * int size;
278 * };
279 *
280 * and it describes the region [offset, offset + size) in GLOBAL
281 * resource.
282 */
283 struct pipe_resource *resources[PIPE_MAX_SHADER_RESOURCES];
284 uint32_t *handles[PIPE_MAX_SHADER_RESOURCES];
285 unsigned count;
286 };
287
288 struct ilo_shader_cso {
289 uint32_t payload[5];
290 };
291
292 void
293 ilo_gpe_init_ve(const struct ilo_dev_info *dev,
294 unsigned num_states,
295 const struct pipe_vertex_element *states,
296 struct ilo_ve_state *ve);
297
298 void
299 ilo_gpe_set_viewport_cso(const struct ilo_dev_info *dev,
300 const struct pipe_viewport_state *state,
301 struct ilo_viewport_cso *vp);
302
303 void
304 ilo_gpe_set_scissor(const struct ilo_dev_info *dev,
305 unsigned start_slot,
306 unsigned num_states,
307 const struct pipe_scissor_state *states,
308 struct ilo_scissor_state *scissor);
309
310 void
311 ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev,
312 struct ilo_scissor_state *scissor);
313
314 void
315 ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info *dev,
316 const struct pipe_rasterizer_state *state,
317 struct ilo_rasterizer_clip *clip);
318
319 void
320 ilo_gpe_init_rasterizer_sf(const struct ilo_dev_info *dev,
321 const struct pipe_rasterizer_state *state,
322 struct ilo_rasterizer_sf *sf);
323
324 void
325 ilo_gpe_init_rasterizer_wm_gen6(const struct ilo_dev_info *dev,
326 const struct pipe_rasterizer_state *state,
327 struct ilo_rasterizer_wm *wm);
328
329 void
330 ilo_gpe_init_rasterizer_wm_gen7(const struct ilo_dev_info *dev,
331 const struct pipe_rasterizer_state *state,
332 struct ilo_rasterizer_wm *wm);
333
334 static inline void
335 ilo_gpe_init_rasterizer(const struct ilo_dev_info *dev,
336 const struct pipe_rasterizer_state *state,
337 struct ilo_rasterizer_state *rasterizer)
338 {
339 ilo_gpe_init_rasterizer_clip(dev, state, &rasterizer->clip);
340 ilo_gpe_init_rasterizer_sf(dev, state, &rasterizer->sf);
341
342 if (dev->gen >= ILO_GEN(7))
343 ilo_gpe_init_rasterizer_wm_gen7(dev, state, &rasterizer->wm);
344 else
345 ilo_gpe_init_rasterizer_wm_gen6(dev, state, &rasterizer->wm);
346 }
347
348 void
349 ilo_gpe_init_dsa(const struct ilo_dev_info *dev,
350 const struct pipe_depth_stencil_alpha_state *state,
351 struct ilo_dsa_state *dsa);
352
353 void
354 ilo_gpe_init_blend(const struct ilo_dev_info *dev,
355 const struct pipe_blend_state *state,
356 struct ilo_blend_state *blend);
357
358 void
359 ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
360 const struct pipe_sampler_state *state,
361 struct ilo_sampler_cso *sampler);
362
363 void
364 ilo_gpe_init_view_surface_null_gen6(const struct ilo_dev_info *dev,
365 unsigned width, unsigned height,
366 unsigned depth, unsigned level,
367 struct ilo_view_surface *surf);
368
369 void
370 ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info *dev,
371 const struct ilo_buffer *buf,
372 unsigned offset, unsigned size,
373 unsigned struct_size,
374 enum pipe_format elem_format,
375 bool is_rt, bool render_cache_rw,
376 struct ilo_view_surface *surf);
377
378 void
379 ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info *dev,
380 const struct ilo_texture *tex,
381 enum pipe_format format,
382 unsigned first_level,
383 unsigned num_levels,
384 unsigned first_layer,
385 unsigned num_layers,
386 bool is_rt, bool render_cache_rw,
387 struct ilo_view_surface *surf);
388
389 void
390 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info *dev,
391 unsigned width, unsigned height,
392 unsigned depth, unsigned level,
393 struct ilo_view_surface *surf);
394
395 void
396 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
397 const struct ilo_buffer *buf,
398 unsigned offset, unsigned size,
399 unsigned struct_size,
400 enum pipe_format elem_format,
401 bool is_rt, bool render_cache_rw,
402 struct ilo_view_surface *surf);
403
404 void
405 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
406 const struct ilo_texture *tex,
407 enum pipe_format format,
408 unsigned first_level,
409 unsigned num_levels,
410 unsigned first_layer,
411 unsigned num_layers,
412 bool is_rt, bool render_cache_rw,
413 struct ilo_view_surface *surf);
414
415 static inline void
416 ilo_gpe_init_view_surface_null(const struct ilo_dev_info *dev,
417 unsigned width, unsigned height,
418 unsigned depth, unsigned level,
419 struct ilo_view_surface *surf)
420 {
421 if (dev->gen >= ILO_GEN(7)) {
422 ilo_gpe_init_view_surface_null_gen7(dev,
423 width, height, depth, level, surf);
424 }
425 else {
426 ilo_gpe_init_view_surface_null_gen6(dev,
427 width, height, depth, level, surf);
428 }
429 }
430
431 static inline void
432 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev_info *dev,
433 const struct ilo_buffer *buf,
434 unsigned offset, unsigned size,
435 unsigned struct_size,
436 enum pipe_format elem_format,
437 bool is_rt, bool render_cache_rw,
438 struct ilo_view_surface *surf)
439 {
440 if (dev->gen >= ILO_GEN(7)) {
441 ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf, offset, size,
442 struct_size, elem_format, is_rt, render_cache_rw, surf);
443 }
444 else {
445 ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf, offset, size,
446 struct_size, elem_format, is_rt, render_cache_rw, surf);
447 }
448 }
449
450 static inline void
451 ilo_gpe_init_view_surface_for_texture(const struct ilo_dev_info *dev,
452 const struct ilo_texture *tex,
453 enum pipe_format format,
454 unsigned first_level,
455 unsigned num_levels,
456 unsigned first_layer,
457 unsigned num_layers,
458 bool is_rt, bool render_cache_rw,
459 struct ilo_view_surface *surf)
460 {
461 if (dev->gen >= ILO_GEN(7)) {
462 ilo_gpe_init_view_surface_for_texture_gen7(dev, tex, format,
463 first_level, num_levels, first_layer, num_layers,
464 is_rt, render_cache_rw, surf);
465 }
466 else {
467 ilo_gpe_init_view_surface_for_texture_gen6(dev, tex, format,
468 first_level, num_levels, first_layer, num_layers,
469 is_rt, render_cache_rw, surf);
470 }
471 }
472
473 static inline void
474 ilo_gpe_set_view_surface_bo(const struct ilo_dev_info *dev,
475 struct intel_bo *bo, unsigned offset,
476 struct ilo_view_surface *surf)
477 {
478 ILO_GPE_VALID_GEN(dev, 6, 7);
479
480 /* do not increment reference count */
481 surf->bo = bo;
482 surf->payload[1] = offset;
483 }
484
485 void
486 ilo_gpe_init_zs_surface(const struct ilo_dev_info *dev,
487 const struct ilo_texture *tex,
488 enum pipe_format format,
489 unsigned level,
490 unsigned first_layer, unsigned num_layers,
491 struct ilo_zs_surface *zs);
492
493 void
494 ilo_gpe_init_vs_cso(const struct ilo_dev_info *dev,
495 const struct ilo_shader_state *vs,
496 struct ilo_shader_cso *cso);
497
498 void
499 ilo_gpe_init_gs_cso_gen6(const struct ilo_dev_info *dev,
500 const struct ilo_shader_state *gs,
501 struct ilo_shader_cso *cso);
502
503 void
504 ilo_gpe_init_gs_cso_gen7(const struct ilo_dev_info *dev,
505 const struct ilo_shader_state *gs,
506 struct ilo_shader_cso *cso);
507
508 static inline void
509 ilo_gpe_init_gs_cso(const struct ilo_dev_info *dev,
510 const struct ilo_shader_state *gs,
511 struct ilo_shader_cso *cso)
512 {
513 if (dev->gen >= ILO_GEN(7)) {
514 ilo_gpe_init_gs_cso_gen7(dev, gs, cso);
515 }
516 else {
517 ilo_gpe_init_gs_cso_gen6(dev, gs, cso);
518 }
519 }
520
521 void
522 ilo_gpe_init_fs_cso_gen6(const struct ilo_dev_info *dev,
523 const struct ilo_shader_state *fs,
524 struct ilo_shader_cso *cso);
525
526 void
527 ilo_gpe_init_fs_cso_gen7(const struct ilo_dev_info *dev,
528 const struct ilo_shader_state *fs,
529 struct ilo_shader_cso *cso);
530
531 static inline void
532 ilo_gpe_init_fs_cso(const struct ilo_dev_info *dev,
533 const struct ilo_shader_state *fs,
534 struct ilo_shader_cso *cso)
535 {
536 if (dev->gen >= ILO_GEN(7)) {
537 ilo_gpe_init_fs_cso_gen7(dev, fs, cso);
538 }
539 else {
540 ilo_gpe_init_fs_cso_gen6(dev, fs, cso);
541 }
542 }
543
544 #endif /* ILO_GPE_H */