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