ilo: construct depth/stencil command in create_surface()
[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
59 struct ilo_vb_state {
60 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
61 uint32_t enabled_mask;
62 };
63
64 struct ilo_ib_state {
65 struct pipe_index_buffer state;
66 };
67
68 struct ilo_ve_cso {
69 /* VERTEX_ELEMENT_STATE */
70 uint32_t payload[2];
71 };
72
73 struct ilo_ve_state {
74 struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
75 unsigned count;
76
77 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
78 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
79 unsigned vb_count;
80 };
81
82 struct ilo_so_state {
83 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
84 unsigned count;
85 unsigned append_bitmask;
86
87 bool enabled;
88 };
89
90 struct ilo_viewport_cso {
91 /* matrix form */
92 float m00, m11, m22, m30, m31, m32;
93
94 /* guardband in NDC space */
95 float min_gbx, min_gby, max_gbx, max_gby;
96
97 /* viewport in screen space */
98 float min_x, min_y, min_z;
99 float max_x, max_y, max_z;
100 };
101
102 struct ilo_viewport_state {
103 struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
104 unsigned count;
105
106 struct pipe_viewport_state viewport0;
107 };
108
109 struct ilo_scissor_state {
110 /* SCISSOR_RECT */
111 uint32_t payload[ILO_MAX_VIEWPORTS * 2];
112 };
113
114 struct ilo_rasterizer_clip {
115 /* 3DSTATE_CLIP */
116 uint32_t payload[3];
117
118 uint32_t can_enable_guardband;
119 };
120
121 struct ilo_rasterizer_sf {
122 /* 3DSTATE_SF */
123 uint32_t payload[6];
124 uint32_t dw_msaa;
125 };
126
127 struct ilo_rasterizer_state {
128 struct pipe_rasterizer_state state;
129
130 struct ilo_rasterizer_clip clip;
131 struct ilo_rasterizer_sf sf;
132 };
133
134 struct ilo_dsa_state {
135 /* DEPTH_STENCIL_STATE */
136 uint32_t payload[3];
137
138 struct pipe_alpha_state alpha;
139 };
140
141 struct ilo_blend_cso {
142 /* BLEND_STATE */
143 uint32_t payload[2];
144
145 uint32_t dw_blend;
146 uint32_t dw_blend_dst_alpha_forced_one;
147
148 uint32_t dw_logicop;
149 uint32_t dw_alpha_mod;
150 };
151
152 struct ilo_blend_state {
153 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
154
155 bool independent_blend_enable;
156 bool dual_blend;
157 bool alpha_to_coverage;
158 };
159
160 struct ilo_sampler_cso {
161 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
162 uint32_t payload[15];
163
164 uint32_t dw_filter;
165 uint32_t dw_filter_aniso;
166 uint32_t dw_wrap;
167 uint32_t dw_wrap_1d;
168 uint32_t dw_wrap_cube;
169
170 bool anisotropic;
171 bool saturate_r;
172 bool saturate_s;
173 bool saturate_t;
174 };
175
176 struct ilo_sampler_state {
177 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
178 unsigned count;
179 };
180
181 struct ilo_view_surface {
182 /* SURFACE_STATE */
183 uint32_t payload[8];
184 struct intel_bo *bo;
185 };
186
187 struct ilo_view_cso {
188 struct pipe_sampler_view base;
189
190 struct ilo_view_surface surface;
191 };
192
193 struct ilo_view_state {
194 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
195 unsigned count;
196 };
197
198 struct ilo_cbuf_cso {
199 struct pipe_resource *resource;
200 struct ilo_view_surface surface;
201 };
202
203 struct ilo_cbuf_state {
204 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
205 unsigned count;
206 };
207
208 struct ilo_resource_state {
209 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
210 unsigned count;
211 };
212
213 struct ilo_surface_cso {
214 struct pipe_surface base;
215
216 bool is_rt;
217 union {
218 struct ilo_view_surface rt;
219 struct ilo_zs_surface {
220 uint32_t payload[10];
221 struct intel_bo *bo;
222 struct intel_bo *hiz_bo;
223 struct intel_bo *separate_s8_bo;
224 } zs;
225 } u;
226 };
227
228 struct ilo_fb_state {
229 struct pipe_framebuffer_state state;
230
231 struct ilo_zs_surface null_zs;
232 unsigned num_samples;
233 };
234
235 struct ilo_global_binding {
236 /*
237 * XXX These should not be treated as real resources (and there could be
238 * thousands of them). They should be treated as regions in GLOBAL
239 * resource, which is the only real resource.
240 *
241 * That is, a resource here should instead be
242 *
243 * struct ilo_global_region {
244 * struct pipe_resource base;
245 * int offset;
246 * int size;
247 * };
248 *
249 * and it describes the region [offset, offset + size) in GLOBAL
250 * resource.
251 */
252 struct pipe_resource *resources[PIPE_MAX_SHADER_RESOURCES];
253 uint32_t *handles[PIPE_MAX_SHADER_RESOURCES];
254 unsigned count;
255 };
256
257 void
258 ilo_gpe_init_ve(const struct ilo_dev_info *dev,
259 unsigned num_states,
260 const struct pipe_vertex_element *states,
261 struct ilo_ve_state *ve);
262
263 void
264 ilo_gpe_set_viewport_cso(const struct ilo_dev_info *dev,
265 const struct pipe_viewport_state *state,
266 struct ilo_viewport_cso *vp);
267
268 void
269 ilo_gpe_set_scissor(const struct ilo_dev_info *dev,
270 unsigned start_slot,
271 unsigned num_states,
272 const struct pipe_scissor_state *states,
273 struct ilo_scissor_state *scissor);
274
275 void
276 ilo_gpe_set_scissor_null(const struct ilo_dev_info *dev,
277 struct ilo_scissor_state *scissor);
278
279 void
280 ilo_gpe_init_rasterizer_clip(const struct ilo_dev_info *dev,
281 const struct pipe_rasterizer_state *state,
282 struct ilo_rasterizer_clip *clip);
283
284 void
285 ilo_gpe_init_rasterizer_sf(const struct ilo_dev_info *dev,
286 const struct pipe_rasterizer_state *state,
287 struct ilo_rasterizer_sf *sf);
288
289 static inline void
290 ilo_gpe_init_rasterizer(const struct ilo_dev_info *dev,
291 const struct pipe_rasterizer_state *state,
292 struct ilo_rasterizer_state *rasterizer)
293 {
294 ilo_gpe_init_rasterizer_clip(dev, state, &rasterizer->clip);
295 ilo_gpe_init_rasterizer_sf(dev, state, &rasterizer->sf);
296 }
297
298 void
299 ilo_gpe_init_dsa(const struct ilo_dev_info *dev,
300 const struct pipe_depth_stencil_alpha_state *state,
301 struct ilo_dsa_state *dsa);
302
303 void
304 ilo_gpe_init_blend(const struct ilo_dev_info *dev,
305 const struct pipe_blend_state *state,
306 struct ilo_blend_state *blend);
307
308 void
309 ilo_gpe_init_sampler_cso(const struct ilo_dev_info *dev,
310 const struct pipe_sampler_state *state,
311 struct ilo_sampler_cso *sampler);
312
313 void
314 ilo_gpe_init_view_surface_null_gen6(const struct ilo_dev_info *dev,
315 unsigned width, unsigned height,
316 unsigned depth, unsigned level,
317 struct ilo_view_surface *surf);
318
319 void
320 ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info *dev,
321 const struct ilo_buffer *buf,
322 unsigned offset, unsigned size,
323 unsigned struct_size,
324 enum pipe_format elem_format,
325 bool is_rt, bool render_cache_rw,
326 struct ilo_view_surface *surf);
327
328 void
329 ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info *dev,
330 const struct ilo_texture *tex,
331 enum pipe_format format,
332 unsigned first_level,
333 unsigned num_levels,
334 unsigned first_layer,
335 unsigned num_layers,
336 bool is_rt, bool render_cache_rw,
337 struct ilo_view_surface *surf);
338
339 void
340 ilo_gpe_init_view_surface_null_gen7(const struct ilo_dev_info *dev,
341 unsigned width, unsigned height,
342 unsigned depth, unsigned level,
343 struct ilo_view_surface *surf);
344
345 void
346 ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
347 const struct ilo_buffer *buf,
348 unsigned offset, unsigned size,
349 unsigned struct_size,
350 enum pipe_format elem_format,
351 bool is_rt, bool render_cache_rw,
352 struct ilo_view_surface *surf);
353
354 void
355 ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
356 const struct ilo_texture *tex,
357 enum pipe_format format,
358 unsigned first_level,
359 unsigned num_levels,
360 unsigned first_layer,
361 unsigned num_layers,
362 bool is_rt, bool render_cache_rw,
363 struct ilo_view_surface *surf);
364
365 static inline void
366 ilo_gpe_init_view_surface_null(const struct ilo_dev_info *dev,
367 unsigned width, unsigned height,
368 unsigned depth, unsigned level,
369 struct ilo_view_surface *surf)
370 {
371 if (dev->gen >= ILO_GEN(7)) {
372 ilo_gpe_init_view_surface_null_gen7(dev,
373 width, height, depth, level, surf);
374 }
375 else {
376 ilo_gpe_init_view_surface_null_gen6(dev,
377 width, height, depth, level, surf);
378 }
379 }
380
381 static inline void
382 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev_info *dev,
383 const struct ilo_buffer *buf,
384 unsigned offset, unsigned size,
385 unsigned struct_size,
386 enum pipe_format elem_format,
387 bool is_rt, bool render_cache_rw,
388 struct ilo_view_surface *surf)
389 {
390 if (dev->gen >= ILO_GEN(7)) {
391 ilo_gpe_init_view_surface_for_buffer_gen7(dev, buf, offset, size,
392 struct_size, elem_format, is_rt, render_cache_rw, surf);
393 }
394 else {
395 ilo_gpe_init_view_surface_for_buffer_gen6(dev, buf, offset, size,
396 struct_size, elem_format, is_rt, render_cache_rw, surf);
397 }
398 }
399
400 static inline void
401 ilo_gpe_init_view_surface_for_texture(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 if (dev->gen >= ILO_GEN(7)) {
412 ilo_gpe_init_view_surface_for_texture_gen7(dev, tex, format,
413 first_level, num_levels, first_layer, num_layers,
414 is_rt, render_cache_rw, surf);
415 }
416 else {
417 ilo_gpe_init_view_surface_for_texture_gen6(dev, tex, format,
418 first_level, num_levels, first_layer, num_layers,
419 is_rt, render_cache_rw, surf);
420 }
421 }
422
423 void
424 ilo_gpe_init_zs_surface(const struct ilo_dev_info *dev,
425 const struct ilo_texture *tex,
426 enum pipe_format format,
427 unsigned level,
428 unsigned first_layer, unsigned num_layers,
429 struct ilo_zs_surface *zs);
430
431 #endif /* ILO_GPE_H */