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