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