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