ilo: enable dumping of WM PCB
[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 uint32_t dw_alpha;
159 ubyte alpha_ref;
160 };
161
162 struct ilo_blend_cso {
163 /* BLEND_STATE */
164 uint32_t payload[2];
165
166 uint32_t dw_blend;
167 uint32_t dw_blend_dst_alpha_forced_one;
168
169 uint32_t dw_logicop;
170 uint32_t dw_alpha_mod;
171 };
172
173 struct ilo_blend_state {
174 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
175
176 bool independent_blend_enable;
177 bool dual_blend;
178 bool alpha_to_coverage;
179 };
180
181 struct ilo_sampler_cso {
182 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
183 uint32_t payload[15];
184
185 uint32_t dw_filter;
186 uint32_t dw_filter_aniso;
187 uint32_t dw_wrap;
188 uint32_t dw_wrap_1d;
189 uint32_t dw_wrap_cube;
190
191 bool anisotropic;
192 bool saturate_r;
193 bool saturate_s;
194 bool saturate_t;
195 };
196
197 struct ilo_sampler_state {
198 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
199 unsigned count;
200 };
201
202 struct ilo_view_surface {
203 /* SURFACE_STATE */
204 uint32_t payload[8];
205 struct intel_bo *bo;
206 };
207
208 struct ilo_view_cso {
209 struct pipe_sampler_view base;
210
211 struct ilo_view_surface surface;
212 };
213
214 struct ilo_view_state {
215 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
216 unsigned count;
217 };
218
219 struct ilo_cbuf_cso {
220 struct pipe_resource *resource;
221 struct ilo_view_surface surface;
222
223 /*
224 * this CSO is not so constant because user buffer needs to be uploaded in
225 * finalize_constant_buffers()
226 */
227 const void *user_buffer;
228 unsigned user_buffer_size;
229 };
230
231 struct ilo_cbuf_state {
232 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
233 uint32_t enabled_mask;
234 };
235
236 struct ilo_resource_state {
237 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
238 unsigned count;
239 };
240
241 struct ilo_surface_cso {
242 struct pipe_surface base;
243
244 bool is_rt;
245 union {
246 struct ilo_view_surface rt;
247 struct ilo_zs_surface {
248 uint32_t payload[10];
249 struct intel_bo *bo;
250 struct intel_bo *hiz_bo;
251 struct intel_bo *separate_s8_bo;
252 } zs;
253 } u;
254 };
255
256 struct ilo_fb_state {
257 struct pipe_framebuffer_state state;
258
259 struct ilo_zs_surface null_zs;
260 unsigned num_samples;
261 };
262
263 struct ilo_global_binding {
264 /*
265 * XXX These should not be treated as real resources (and there could be
266 * thousands of them). They should be treated as regions in GLOBAL
267 * resource, which is the only real resource.
268 *
269 * That is, a resource here should instead be
270 *
271 * struct ilo_global_region {
272 * struct pipe_resource base;
273 * int offset;
274 * int size;
275 * };
276 *
277 * and it describes the region [offset, offset + size) in GLOBAL
278 * resource.
279 */
280 struct pipe_resource *resources[PIPE_MAX_SHADER_RESOURCES];
281 uint32_t *handles[PIPE_MAX_SHADER_RESOURCES];
282 unsigned count;
283 };
284
285 struct ilo_shader_cso {
286 uint32_t payload[5];
287 };
288
289 void
290 ilo_gpe_init_ve(const struct ilo_dev_info *dev,
291 unsigned num_states,
292 const struct pipe_vertex_element *states,
293 struct ilo_ve_state *ve);
294
295 void
296 ilo_gpe_set_viewport_cso(const struct ilo_dev_info *dev,
297 const struct pipe_viewport_state *state,
298 struct ilo_viewport_cso *vp);
299
300 void
301 ilo_gpe_set_scissor(const struct ilo_dev_info *dev,
302 unsigned start_slot,
303 unsigned num_states,
304 const struct pipe_scissor_state *states,
305 struct ilo_scissor_state *scissor);
306
307 void
308 ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev,
309 struct ilo_scissor_state *scissor);
310
311 void
312 ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info *dev,
313 const struct pipe_rasterizer_state *state,
314 struct ilo_rasterizer_clip *clip);
315
316 void
317 ilo_gpe_init_rasterizer_sf(const struct ilo_dev_info *dev,
318 const struct pipe_rasterizer_state *state,
319 struct ilo_rasterizer_sf *sf);
320
321 void
322 ilo_gpe_init_rasterizer_wm_gen6(const struct ilo_dev_info *dev,
323 const struct pipe_rasterizer_state *state,
324 struct ilo_rasterizer_wm *wm);
325
326 void
327 ilo_gpe_init_rasterizer_wm_gen7(const struct ilo_dev_info *dev,
328 const struct pipe_rasterizer_state *state,
329 struct ilo_rasterizer_wm *wm);
330
331 static inline void
332 ilo_gpe_init_rasterizer(const struct ilo_dev_info *dev,
333 const struct pipe_rasterizer_state *state,
334 struct ilo_rasterizer_state *rasterizer)
335 {
336 ilo_gpe_init_rasterizer_clip(dev, state, &rasterizer->clip);
337 ilo_gpe_init_rasterizer_sf(dev, state, &rasterizer->sf);
338
339 if (dev->gen >= ILO_GEN(7))
340 ilo_gpe_init_rasterizer_wm_gen7(dev, state, &rasterizer->wm);
341 else
342 ilo_gpe_init_rasterizer_wm_gen6(dev, state, &rasterizer->wm);
343 }
344
345 void
346 ilo_gpe_init_dsa(const struct ilo_dev_info *dev,
347 const struct pipe_depth_stencil_alpha_state *state,
348 struct ilo_dsa_state *dsa);
349
350 void
351 ilo_gpe_init_blend(const struct ilo_dev_info *dev,
352 const struct pipe_blend_state *state,
353 struct ilo_blend_state *blend);
354
355 void
356 ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
357 const struct pipe_sampler_state *state,
358 struct ilo_sampler_cso *sampler);
359
360 void
361 ilo_gpe_init_view_surface_null_gen6(const struct ilo_dev_info *dev,
362 unsigned width, unsigned height,
363 unsigned depth, unsigned level,
364 struct ilo_view_surface *surf);
365
366 void
367 ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info *dev,
368 const struct ilo_buffer *buf,
369 unsigned offset, unsigned size,
370 unsigned struct_size,
371 enum pipe_format elem_format,
372 bool is_rt, bool render_cache_rw,
373 struct ilo_view_surface *surf);
374
375 void
376 ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info *dev,
377 const struct ilo_texture *tex,
378 enum pipe_format format,
379 unsigned first_level,
380 unsigned num_levels,
381 unsigned first_layer,
382 unsigned num_layers,
383 bool is_rt, bool render_cache_rw,
384 struct ilo_view_surface *surf);
385
386 void
387 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info *dev,
388 unsigned width, unsigned height,
389 unsigned depth, unsigned level,
390 struct ilo_view_surface *surf);
391
392 void
393 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
394 const struct ilo_buffer *buf,
395 unsigned offset, unsigned size,
396 unsigned struct_size,
397 enum pipe_format elem_format,
398 bool is_rt, bool render_cache_rw,
399 struct ilo_view_surface *surf);
400
401 void
402 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
403 const struct ilo_texture *tex,
404 enum pipe_format format,
405 unsigned first_level,
406 unsigned num_levels,
407 unsigned first_layer,
408 unsigned num_layers,
409 bool is_rt, bool render_cache_rw,
410 struct ilo_view_surface *surf);
411
412 static inline void
413 ilo_gpe_init_view_surface_null(const struct ilo_dev_info *dev,
414 unsigned width, unsigned height,
415 unsigned depth, unsigned level,
416 struct ilo_view_surface *surf)
417 {
418 if (dev->gen >= ILO_GEN(7)) {
419 ilo_gpe_init_view_surface_null_gen7(dev,
420 width, height, depth, level, surf);
421 }
422 else {
423 ilo_gpe_init_view_surface_null_gen6(dev,
424 width, height, depth, level, surf);
425 }
426 }
427
428 static inline void
429 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev_info *dev,
430 const struct ilo_buffer *buf,
431 unsigned offset, unsigned size,
432 unsigned struct_size,
433 enum pipe_format elem_format,
434 bool is_rt, bool render_cache_rw,
435 struct ilo_view_surface *surf)
436 {
437 if (dev->gen >= ILO_GEN(7)) {
438 ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf, offset, size,
439 struct_size, elem_format, is_rt, render_cache_rw, surf);
440 }
441 else {
442 ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf, offset, size,
443 struct_size, elem_format, is_rt, render_cache_rw, surf);
444 }
445 }
446
447 static inline void
448 ilo_gpe_init_view_surface_for_texture(const struct ilo_dev_info *dev,
449 const struct ilo_texture *tex,
450 enum pipe_format format,
451 unsigned first_level,
452 unsigned num_levels,
453 unsigned first_layer,
454 unsigned num_layers,
455 bool is_rt, bool render_cache_rw,
456 struct ilo_view_surface *surf)
457 {
458 if (dev->gen >= ILO_GEN(7)) {
459 ilo_gpe_init_view_surface_for_texture_gen7(dev, tex, format,
460 first_level, num_levels, first_layer, num_layers,
461 is_rt, render_cache_rw, surf);
462 }
463 else {
464 ilo_gpe_init_view_surface_for_texture_gen6(dev, tex, format,
465 first_level, num_levels, first_layer, num_layers,
466 is_rt, render_cache_rw, surf);
467 }
468 }
469
470 void
471 ilo_gpe_init_zs_surface(const struct ilo_dev_info *dev,
472 const struct ilo_texture *tex,
473 enum pipe_format format,
474 unsigned level,
475 unsigned first_layer, unsigned num_layers,
476 struct ilo_zs_surface *zs);
477
478 void
479 ilo_gpe_init_vs_cso(const struct ilo_dev_info *dev,
480 const struct ilo_shader_state *vs,
481 struct ilo_shader_cso *cso);
482
483 void
484 ilo_gpe_init_gs_cso_gen6(const struct ilo_dev_info *dev,
485 const struct ilo_shader_state *gs,
486 struct ilo_shader_cso *cso);
487
488 void
489 ilo_gpe_init_gs_cso_gen7(const struct ilo_dev_info *dev,
490 const struct ilo_shader_state *gs,
491 struct ilo_shader_cso *cso);
492
493 static inline void
494 ilo_gpe_init_gs_cso(const struct ilo_dev_info *dev,
495 const struct ilo_shader_state *gs,
496 struct ilo_shader_cso *cso)
497 {
498 if (dev->gen >= ILO_GEN(7)) {
499 ilo_gpe_init_gs_cso_gen7(dev, gs, cso);
500 }
501 else {
502 ilo_gpe_init_gs_cso_gen6(dev, gs, cso);
503 }
504 }
505
506 void
507 ilo_gpe_init_fs_cso_gen6(const struct ilo_dev_info *dev,
508 const struct ilo_shader_state *fs,
509 struct ilo_shader_cso *cso);
510
511 void
512 ilo_gpe_init_fs_cso_gen7(const struct ilo_dev_info *dev,
513 const struct ilo_shader_state *fs,
514 struct ilo_shader_cso *cso);
515
516 static inline void
517 ilo_gpe_init_fs_cso(const struct ilo_dev_info *dev,
518 const struct ilo_shader_state *fs,
519 struct ilo_shader_cso *cso)
520 {
521 if (dev->gen >= ILO_GEN(7)) {
522 ilo_gpe_init_fs_cso_gen7(dev, fs, cso);
523 }
524 else {
525 ilo_gpe_init_fs_cso_gen6(dev, fs, cso);
526 }
527 }
528
529 #endif /* ILO_GPE_H */