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