ilo: replace ilo_zs_surface with ilo_state_zs
[mesa.git] / src / gallium / drivers / ilo / core / ilo_state_3d.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2014 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_STATE_3D_H
29 #define ILO_STATE_3D_H
30
31 #include "genhw/genhw.h"
32 #include "pipe/p_state.h"
33
34 #include "ilo_core.h"
35 #include "ilo_dev.h"
36 #include "ilo_state_zs.h"
37
38 /**
39 * \see brw_context.h
40 */
41 #define ILO_MAX_DRAW_BUFFERS 8
42 #define ILO_MAX_CONST_BUFFERS (1 + 12)
43 #define ILO_MAX_SAMPLER_VIEWS 16
44 #define ILO_MAX_SAMPLERS 16
45 #define ILO_MAX_SO_BINDINGS 64
46 #define ILO_MAX_SO_BUFFERS 4
47 #define ILO_MAX_VIEWPORTS 1
48
49 #define ILO_MAX_SURFACES 256
50
51 struct intel_bo;
52 struct ilo_buffer;
53 struct ilo_image;
54 struct ilo_shader_state;
55
56 struct ilo_vb_state {
57 struct pipe_vertex_buffer states[PIPE_MAX_ATTRIBS];
58 uint32_t enabled_mask;
59 };
60
61 struct ilo_ib_state {
62 struct pipe_resource *buffer;
63 const void *user_buffer;
64 unsigned offset;
65 unsigned index_size;
66
67 /* these are not valid until the state is finalized */
68 struct pipe_resource *hw_resource;
69 unsigned hw_index_size;
70 /* an offset to be added to pipe_draw_info::start */
71 int64_t draw_start_offset;
72 };
73
74 struct ilo_ve_cso {
75 /* VERTEX_ELEMENT_STATE */
76 uint32_t payload[2];
77 };
78
79 struct ilo_ve_state {
80 struct ilo_ve_cso cso[PIPE_MAX_ATTRIBS];
81 unsigned count;
82
83 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
84 unsigned vb_mapping[PIPE_MAX_ATTRIBS];
85 unsigned vb_count;
86
87 /* these are not valid until the state is finalized */
88 struct ilo_ve_cso edgeflag_cso;
89 bool last_cso_edgeflag;
90
91 struct ilo_ve_cso nosrc_cso;
92 bool prepend_nosrc_cso;
93 };
94
95 struct ilo_so_state {
96 struct pipe_stream_output_target *states[ILO_MAX_SO_BUFFERS];
97 unsigned count;
98 unsigned append_bitmask;
99
100 bool enabled;
101 };
102
103 struct ilo_viewport_cso {
104 /* matrix form */
105 float m00, m11, m22, m30, m31, m32;
106
107 /* guardband in NDC space */
108 float min_gbx, min_gby, max_gbx, max_gby;
109
110 /* viewport in screen space */
111 float min_x, min_y, min_z;
112 float max_x, max_y, max_z;
113 };
114
115 struct ilo_viewport_state {
116 struct ilo_viewport_cso cso[ILO_MAX_VIEWPORTS];
117 unsigned count;
118
119 struct pipe_viewport_state viewport0;
120 };
121
122 struct ilo_scissor_state {
123 /* SCISSOR_RECT */
124 uint32_t payload[ILO_MAX_VIEWPORTS * 2];
125
126 struct pipe_scissor_state scissor0;
127 };
128
129 struct ilo_rasterizer_clip {
130 /* 3DSTATE_CLIP */
131 uint32_t payload[3];
132
133 uint32_t can_enable_guardband;
134 };
135
136 struct ilo_rasterizer_sf {
137 /* 3DSTATE_SF */
138 uint32_t payload[3];
139 uint32_t dw_msaa;
140
141 /* Global Depth Offset Constant/Scale/Clamp */
142 uint32_t dw_depth_offset_const;
143 uint32_t dw_depth_offset_scale;
144 uint32_t dw_depth_offset_clamp;
145
146 /* Gen8+ 3DSTATE_RASTER */
147 uint32_t dw_raster;
148 };
149
150 struct ilo_rasterizer_wm {
151 /* 3DSTATE_WM */
152 uint32_t payload[2];
153 uint32_t dw_msaa_rast;
154 uint32_t dw_msaa_disp;
155 };
156
157 struct ilo_rasterizer_state {
158 struct pipe_rasterizer_state state;
159
160 struct ilo_rasterizer_clip clip;
161 struct ilo_rasterizer_sf sf;
162 struct ilo_rasterizer_wm wm;
163 };
164
165 struct ilo_dsa_state {
166 /* DEPTH_STENCIL_STATE or Gen8+ 3DSTATE_WM_DEPTH_STENCIL */
167 uint32_t payload[3];
168
169 uint32_t dw_blend_alpha;
170 uint32_t dw_ps_blend_alpha;
171 ubyte alpha_ref;
172 };
173
174 struct ilo_blend_cso {
175 /* BLEND_STATE */
176 uint32_t payload[2];
177
178 uint32_t dw_blend;
179 uint32_t dw_blend_dst_alpha_forced_one;
180 };
181
182 struct ilo_blend_state {
183 struct ilo_blend_cso cso[ILO_MAX_DRAW_BUFFERS];
184
185 bool dual_blend;
186 bool alpha_to_coverage;
187
188 uint32_t dw_shared;
189 uint32_t dw_alpha_mod;
190 uint32_t dw_logicop;
191
192 /* a part of 3DSTATE_PS_BLEND */
193 uint32_t dw_ps_blend;
194 uint32_t dw_ps_blend_dst_alpha_forced_one;
195 };
196
197 struct ilo_sampler_cso {
198 /* SAMPLER_STATE and SAMPLER_BORDER_COLOR_STATE */
199 uint32_t payload[15];
200
201 uint32_t dw_filter;
202 uint32_t dw_filter_aniso;
203 uint32_t dw_wrap;
204 uint32_t dw_wrap_1d;
205 uint32_t dw_wrap_cube;
206
207 bool anisotropic;
208 bool saturate_r;
209 bool saturate_s;
210 bool saturate_t;
211 };
212
213 struct ilo_sampler_state {
214 const struct ilo_sampler_cso *cso[ILO_MAX_SAMPLERS];
215 };
216
217 struct ilo_view_surface {
218 /* SURFACE_STATE */
219 uint32_t payload[13];
220 struct intel_bo *bo;
221
222 uint32_t scanout;
223 };
224
225 struct ilo_view_cso {
226 struct pipe_sampler_view base;
227
228 struct ilo_view_surface surface;
229 };
230
231 struct ilo_view_state {
232 struct pipe_sampler_view *states[ILO_MAX_SAMPLER_VIEWS];
233 unsigned count;
234 };
235
236 struct ilo_cbuf_cso {
237 struct pipe_resource *resource;
238 struct ilo_view_surface surface;
239
240 /*
241 * this CSO is not so constant because user buffer needs to be uploaded in
242 * finalize_constant_buffers()
243 */
244 const void *user_buffer;
245 unsigned user_buffer_size;
246 };
247
248 struct ilo_cbuf_state {
249 struct ilo_cbuf_cso cso[ILO_MAX_CONST_BUFFERS];
250 uint32_t enabled_mask;
251 };
252
253 struct ilo_resource_state {
254 struct pipe_surface *states[PIPE_MAX_SHADER_RESOURCES];
255 unsigned count;
256 };
257
258 struct ilo_surface_cso {
259 struct pipe_surface base;
260
261 bool is_rt;
262 union {
263 struct ilo_view_surface rt;
264 struct ilo_state_zs zs;
265 } u;
266 };
267
268 struct ilo_fb_state {
269 struct pipe_framebuffer_state state;
270
271 struct ilo_view_surface null_rt;
272 struct ilo_state_zs null_zs;
273
274 struct ilo_fb_blend_caps {
275 bool can_logicop;
276 bool can_blend;
277 bool can_alpha_test;
278 bool dst_alpha_forced_one;
279 } blend_caps[PIPE_MAX_COLOR_BUFS];
280
281 unsigned num_samples;
282 };
283
284 struct ilo_shader_cso {
285 uint32_t payload[5];
286 };
287
288 /**
289 * Translate a pipe texture target to the matching hardware surface type.
290 */
291 static inline int
292 ilo_gpe_gen6_translate_texture(enum pipe_texture_target target)
293 {
294 switch (target) {
295 case PIPE_BUFFER:
296 return GEN6_SURFTYPE_BUFFER;
297 case PIPE_TEXTURE_1D:
298 case PIPE_TEXTURE_1D_ARRAY:
299 return GEN6_SURFTYPE_1D;
300 case PIPE_TEXTURE_2D:
301 case PIPE_TEXTURE_RECT:
302 case PIPE_TEXTURE_2D_ARRAY:
303 return GEN6_SURFTYPE_2D;
304 case PIPE_TEXTURE_3D:
305 return GEN6_SURFTYPE_3D;
306 case PIPE_TEXTURE_CUBE:
307 case PIPE_TEXTURE_CUBE_ARRAY:
308 return GEN6_SURFTYPE_CUBE;
309 default:
310 assert(!"unknown texture target");
311 return GEN6_SURFTYPE_BUFFER;
312 }
313 }
314
315 void
316 ilo_gpe_init_ve(const struct ilo_dev *dev,
317 unsigned num_states,
318 const struct pipe_vertex_element *states,
319 struct ilo_ve_state *ve);
320
321 void
322 ilo_gpe_set_ve_edgeflag(const struct ilo_dev *dev,
323 struct ilo_ve_cso *cso);
324
325 void
326 ilo_gpe_init_ve_nosrc(const struct ilo_dev *dev,
327 int comp0, int comp1, int comp2, int comp3,
328 struct ilo_ve_cso *cso);
329
330 void
331 ilo_gpe_set_viewport_cso(const struct ilo_dev *dev,
332 const struct pipe_viewport_state *state,
333 struct ilo_viewport_cso *vp);
334
335 void
336 ilo_gpe_set_scissor(const struct ilo_dev *dev,
337 unsigned start_slot,
338 unsigned num_states,
339 const struct pipe_scissor_state *states,
340 struct ilo_scissor_state *scissor);
341
342 void
343 ilo_gpe_set_scissor_null(const struct ilo_dev *dev,
344 struct ilo_scissor_state *scissor);
345
346 void
347 ilo_gpe_init_rasterizer(const struct ilo_dev *dev,
348 const struct pipe_rasterizer_state *state,
349 struct ilo_rasterizer_state *rasterizer);
350 void
351 ilo_gpe_init_dsa(const struct ilo_dev *dev,
352 const struct pipe_depth_stencil_alpha_state *state,
353 struct ilo_dsa_state *dsa);
354
355 void
356 ilo_gpe_init_blend(const struct ilo_dev *dev,
357 const struct pipe_blend_state *state,
358 struct ilo_blend_state *blend);
359
360 void
361 ilo_gpe_init_sampler_cso(const struct ilo_dev *dev,
362 const struct pipe_sampler_state *state,
363 struct ilo_sampler_cso *sampler);
364
365 void
366 ilo_gpe_init_view_surface_null(const struct ilo_dev *dev,
367 unsigned width, unsigned height,
368 unsigned depth, unsigned level,
369 struct ilo_view_surface *surf);
370
371 void
372 ilo_gpe_init_view_surface_for_buffer(const struct ilo_dev *dev,
373 const struct ilo_buffer *buf,
374 unsigned offset, unsigned size,
375 unsigned struct_size,
376 enum pipe_format elem_format,
377 bool is_rt,
378 struct ilo_view_surface *surf);
379
380 void
381 ilo_gpe_init_view_surface_for_image(const struct ilo_dev *dev,
382 const struct ilo_image *img,
383 enum pipe_format format,
384 unsigned first_level,
385 unsigned num_levels,
386 unsigned first_layer,
387 unsigned num_layers,
388 bool is_rt,
389 struct ilo_view_surface *surf);
390
391 void
392 ilo_gpe_init_vs_cso(const struct ilo_dev *dev,
393 const struct ilo_shader_state *vs,
394 struct ilo_shader_cso *cso);
395
396 void
397 ilo_gpe_init_gs_cso(const struct ilo_dev *dev,
398 const struct ilo_shader_state *gs,
399 struct ilo_shader_cso *cso);
400
401 void
402 ilo_gpe_init_fs_cso(const struct ilo_dev *dev,
403 const struct ilo_shader_state *fs,
404 struct ilo_shader_cso *cso);
405
406 void
407 ilo_gpe_set_fb(const struct ilo_dev *dev,
408 const struct pipe_framebuffer_state *state,
409 struct ilo_fb_state *fb);
410
411 #endif /* ILO_STATE_3D_H */