gallium: add support for stream in so info
[mesa.git] / src / gallium / include / pipe / p_state.h
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * @file
31 *
32 * Abstract graphics pipe state objects.
33 *
34 * Basic notes:
35 * 1. Want compact representations, so we use bitfields.
36 * 2. Put bitfields before other (GLfloat) fields.
37 */
38
39
40 #ifndef PIPE_STATE_H
41 #define PIPE_STATE_H
42
43 #include "p_compiler.h"
44 #include "p_defines.h"
45 #include "p_format.h"
46
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52
53 /**
54 * Implementation limits
55 */
56 #define PIPE_MAX_ATTRIBS 32
57 #define PIPE_MAX_CLIP_PLANES 8
58 #define PIPE_MAX_COLOR_BUFS 8
59 #define PIPE_MAX_CONSTANT_BUFFERS 32
60 #define PIPE_MAX_SAMPLERS 16
61 #define PIPE_MAX_SHADER_INPUTS 32
62 #define PIPE_MAX_SHADER_OUTPUTS 48 /* 32 GENERICs + POS, PSIZE, FOG, etc. */
63 #define PIPE_MAX_SHADER_SAMPLER_VIEWS 32
64 #define PIPE_MAX_SHADER_RESOURCES 32
65 #define PIPE_MAX_TEXTURE_LEVELS 16
66 #define PIPE_MAX_SO_BUFFERS 4
67 #define PIPE_MAX_SO_OUTPUTS 64
68 #define PIPE_MAX_VIEWPORTS 16
69 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
70 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
71
72
73 struct pipe_reference
74 {
75 int32_t count; /* atomic */
76 };
77
78
79
80 /**
81 * Primitive (point/line/tri) rasterization info
82 */
83 struct pipe_rasterizer_state
84 {
85 unsigned flatshade:1;
86 unsigned light_twoside:1;
87 unsigned clamp_vertex_color:1;
88 unsigned clamp_fragment_color:1;
89 unsigned front_ccw:1;
90 unsigned cull_face:2; /**< PIPE_FACE_x */
91 unsigned fill_front:2; /**< PIPE_POLYGON_MODE_x */
92 unsigned fill_back:2; /**< PIPE_POLYGON_MODE_x */
93 unsigned offset_point:1;
94 unsigned offset_line:1;
95 unsigned offset_tri:1;
96 unsigned scissor:1;
97 unsigned poly_smooth:1;
98 unsigned poly_stipple_enable:1;
99 unsigned point_smooth:1;
100 unsigned sprite_coord_mode:1; /**< PIPE_SPRITE_COORD_ */
101 unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
102 unsigned point_tri_clip:1; /** large points clipped as tris or points */
103 unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
104 unsigned multisample:1; /* XXX maybe more ms state in future */
105 unsigned line_smooth:1;
106 unsigned line_stipple_enable:1;
107 unsigned line_last_pixel:1;
108
109 /**
110 * Use the first vertex of a primitive as the provoking vertex for
111 * flat shading.
112 */
113 unsigned flatshade_first:1;
114
115 unsigned half_pixel_center:1;
116 unsigned bottom_edge_rule:1;
117
118 /**
119 * When true, rasterization is disabled and no pixels are written.
120 * This only makes sense with the Stream Out functionality.
121 */
122 unsigned rasterizer_discard:1;
123
124 /**
125 * When false, depth clipping is disabled and the depth value will be
126 * clamped later at the per-pixel level before depth testing.
127 * This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
128 */
129 unsigned depth_clip:1;
130
131 /**
132 * When true clip space in the z axis goes from [0..1] (D3D). When false
133 * [-1, 1] (GL).
134 *
135 * NOTE: D3D will always use depth clamping.
136 */
137 unsigned clip_halfz:1;
138
139 /**
140 * Enable bits for clipping half-spaces.
141 * This applies to both user clip planes and shader clip distances.
142 * Note that if the bound shader exports any clip distances, these
143 * replace all user clip planes, and clip half-spaces enabled here
144 * but not written by the shader count as disabled.
145 */
146 unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES;
147
148 unsigned line_stipple_factor:8; /**< [1..256] actually */
149 unsigned line_stipple_pattern:16;
150
151 uint32_t sprite_coord_enable; /* referring to 32 TEXCOORD/GENERIC inputs */
152
153 float line_width;
154 float point_size; /**< used when no per-vertex size */
155 float offset_units;
156 float offset_scale;
157 float offset_clamp;
158 };
159
160
161 struct pipe_poly_stipple
162 {
163 unsigned stipple[32];
164 };
165
166
167 struct pipe_viewport_state
168 {
169 float scale[4];
170 float translate[4];
171 };
172
173
174 struct pipe_scissor_state
175 {
176 unsigned minx:16;
177 unsigned miny:16;
178 unsigned maxx:16;
179 unsigned maxy:16;
180 };
181
182
183 struct pipe_clip_state
184 {
185 float ucp[PIPE_MAX_CLIP_PLANES][4];
186 };
187
188
189 /**
190 * Stream output for vertex transform feedback.
191 */
192 struct pipe_stream_output_info
193 {
194 unsigned num_outputs;
195 /** stride for an entire vertex for each buffer in dwords */
196 unsigned stride[PIPE_MAX_SO_BUFFERS];
197
198 /**
199 * Array of stream outputs, in the order they are to be written in.
200 * Selected components are tightly packed into the output buffer.
201 */
202 struct {
203 unsigned register_index:8; /**< 0 to PIPE_MAX_SHADER_OUTPUTS */
204 unsigned start_component:2; /** 0 to 3 */
205 unsigned num_components:3; /** 1 to 4 */
206 unsigned output_buffer:3; /**< 0 to PIPE_MAX_SO_BUFFERS */
207 unsigned dst_offset:16; /**< offset into the buffer in dwords */
208 unsigned stream:2; /**< 0 to 3 */
209 } output[PIPE_MAX_SO_OUTPUTS];
210 };
211
212
213 struct pipe_shader_state
214 {
215 const struct tgsi_token *tokens;
216 struct pipe_stream_output_info stream_output;
217 };
218
219
220 struct pipe_depth_state
221 {
222 unsigned enabled:1; /**< depth test enabled? */
223 unsigned writemask:1; /**< allow depth buffer writes? */
224 unsigned func:3; /**< depth test func (PIPE_FUNC_x) */
225 };
226
227
228 struct pipe_stencil_state
229 {
230 unsigned enabled:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
231 unsigned func:3; /**< PIPE_FUNC_x */
232 unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */
233 unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
234 unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
235 unsigned valuemask:8;
236 unsigned writemask:8;
237 };
238
239
240 struct pipe_alpha_state
241 {
242 unsigned enabled:1;
243 unsigned func:3; /**< PIPE_FUNC_x */
244 float ref_value; /**< reference value */
245 };
246
247
248 struct pipe_depth_stencil_alpha_state
249 {
250 struct pipe_depth_state depth;
251 struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
252 struct pipe_alpha_state alpha;
253 };
254
255
256 struct pipe_rt_blend_state
257 {
258 unsigned blend_enable:1;
259
260 unsigned rgb_func:3; /**< PIPE_BLEND_x */
261 unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
262 unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
263
264 unsigned alpha_func:3; /**< PIPE_BLEND_x */
265 unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
266 unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
267
268 unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */
269 };
270
271 struct pipe_blend_state
272 {
273 unsigned independent_blend_enable:1;
274 unsigned logicop_enable:1;
275 unsigned logicop_func:4; /**< PIPE_LOGICOP_x */
276 unsigned dither:1;
277 unsigned alpha_to_coverage:1;
278 unsigned alpha_to_one:1;
279 struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
280 };
281
282
283 struct pipe_blend_color
284 {
285 float color[4];
286 };
287
288 struct pipe_stencil_ref
289 {
290 ubyte ref_value[2];
291 };
292
293 struct pipe_framebuffer_state
294 {
295 unsigned width, height;
296
297 /** multiple color buffers for multiple render targets */
298 unsigned nr_cbufs;
299 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
300
301 struct pipe_surface *zsbuf; /**< Z/stencil buffer */
302 };
303
304
305 /**
306 * Texture sampler state.
307 */
308 struct pipe_sampler_state
309 {
310 unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
311 unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
312 unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
313 unsigned min_img_filter:2; /**< PIPE_TEX_FILTER_x */
314 unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */
315 unsigned mag_img_filter:2; /**< PIPE_TEX_FILTER_x */
316 unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
317 unsigned compare_func:3; /**< PIPE_FUNC_x */
318 unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
319 unsigned max_anisotropy:6;
320 unsigned seamless_cube_map:1;
321 float lod_bias; /**< LOD/lambda bias */
322 float min_lod, max_lod; /**< LOD clamp range, after bias */
323 union pipe_color_union border_color;
324 };
325
326
327 /**
328 * A view into a texture that can be bound to a color render target /
329 * depth stencil attachment point.
330 */
331 struct pipe_surface
332 {
333 struct pipe_reference reference;
334 struct pipe_resource *texture; /**< resource into which this is a view */
335 struct pipe_context *context; /**< context this surface belongs to */
336 enum pipe_format format;
337
338 /* XXX width/height should be removed */
339 unsigned width; /**< logical width in pixels */
340 unsigned height; /**< logical height in pixels */
341
342 unsigned writable:1; /**< writable shader resource */
343
344 union {
345 struct {
346 unsigned level;
347 unsigned first_layer:16;
348 unsigned last_layer:16;
349 } tex;
350 struct {
351 unsigned first_element;
352 unsigned last_element;
353 } buf;
354 } u;
355 };
356
357
358 /**
359 * A view into a texture that can be bound to a shader stage.
360 */
361 struct pipe_sampler_view
362 {
363 struct pipe_reference reference;
364 enum pipe_format format; /**< typed PIPE_FORMAT_x */
365 struct pipe_resource *texture; /**< texture into which this is a view */
366 struct pipe_context *context; /**< context this view belongs to */
367 union {
368 struct {
369 unsigned first_layer:16; /**< first layer to use for array textures */
370 unsigned last_layer:16; /**< last layer to use for array textures */
371 unsigned first_level:8; /**< first mipmap level to use */
372 unsigned last_level:8; /**< last mipmap level to use */
373 } tex;
374 struct {
375 unsigned first_element;
376 unsigned last_element;
377 } buf;
378 } u;
379 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */
380 unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */
381 unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */
382 unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */
383 };
384
385
386 /**
387 * Subregion of 1D/2D/3D image resource.
388 */
389 struct pipe_box
390 {
391 int x;
392 int y;
393 int z;
394 int width;
395 int height;
396 int depth;
397 };
398
399
400 /**
401 * A memory object/resource such as a vertex buffer or texture.
402 */
403 struct pipe_resource
404 {
405 struct pipe_reference reference;
406 struct pipe_screen *screen; /**< screen that this texture belongs to */
407 enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
408 enum pipe_format format; /**< PIPE_FORMAT_x */
409
410 unsigned width0;
411 unsigned height0;
412 unsigned depth0;
413 unsigned array_size;
414
415 unsigned last_level:8; /**< Index of last mipmap level present/defined */
416 unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */
417 unsigned usage:8; /**< PIPE_USAGE_x (not a bitmask) */
418
419 unsigned bind; /**< bitmask of PIPE_BIND_x */
420 unsigned flags; /**< bitmask of PIPE_RESOURCE_FLAG_x */
421 };
422
423
424 /**
425 * Transfer object. For data transfer to/from a resource.
426 */
427 struct pipe_transfer
428 {
429 struct pipe_resource *resource; /**< resource to transfer to/from */
430 unsigned level; /**< texture mipmap level */
431 enum pipe_transfer_usage usage;
432 struct pipe_box box; /**< region of the resource to access */
433 unsigned stride; /**< row stride in bytes */
434 unsigned layer_stride; /**< image/layer stride in bytes */
435 };
436
437
438
439 /**
440 * A vertex buffer. Typically, all the vertex data/attributes for
441 * drawing something will be in one buffer. But it's also possible, for
442 * example, to put colors in one buffer and texcoords in another.
443 */
444 struct pipe_vertex_buffer
445 {
446 unsigned stride; /**< stride to same attrib in next vertex, in bytes */
447 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
448 struct pipe_resource *buffer; /**< the actual buffer */
449 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
450 };
451
452
453 /**
454 * A constant buffer. A subrange of an existing buffer can be set
455 * as a constant buffer.
456 */
457 struct pipe_constant_buffer {
458 struct pipe_resource *buffer; /**< the actual buffer */
459 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
460 unsigned buffer_size; /**< how much data can be read in shader */
461 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
462 };
463
464
465 /**
466 * A stream output target. The structure specifies the range vertices can
467 * be written to.
468 *
469 * In addition to that, the structure should internally maintain the offset
470 * into the buffer, which should be incremented everytime something is written
471 * (appended) to it. The internal offset is buffer_offset + how many bytes
472 * have been written. The internal offset can be stored on the device
473 * and the CPU actually doesn't have to query it.
474 *
475 * Note that the buffer_size variable is actually specifying the available
476 * space in the buffer, not the size of the attached buffer.
477 * In other words in majority of cases buffer_size would simply be
478 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
479 * of the buffer left, after accounting for buffer offset, for stream output
480 * to write to.
481 *
482 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
483 * actually been written.
484 */
485 struct pipe_stream_output_target
486 {
487 struct pipe_reference reference;
488 struct pipe_resource *buffer; /**< the output buffer */
489 struct pipe_context *context; /**< context this SO target belongs to */
490
491 unsigned buffer_offset; /**< offset where data should be written, in bytes */
492 unsigned buffer_size; /**< how much data is allowed to be written */
493 };
494
495
496 /**
497 * Information to describe a vertex attribute (position, color, etc)
498 */
499 struct pipe_vertex_element
500 {
501 /** Offset of this attribute, in bytes, from the start of the vertex */
502 unsigned src_offset;
503
504 /** Instance data rate divisor. 0 means this is per-vertex data,
505 * n means per-instance data used for n consecutive instances (n > 0).
506 */
507 unsigned instance_divisor;
508
509 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
510 * this attribute live in?
511 */
512 unsigned vertex_buffer_index;
513
514 enum pipe_format src_format;
515 };
516
517
518 /**
519 * An index buffer. When an index buffer is bound, all indices to vertices
520 * will be looked up in the buffer.
521 */
522 struct pipe_index_buffer
523 {
524 unsigned index_size; /**< size of an index, in bytes */
525 unsigned offset; /**< offset to start of data in buffer, in bytes */
526 struct pipe_resource *buffer; /**< the actual buffer */
527 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
528 };
529
530
531 /**
532 * Information to describe a draw_vbo call.
533 */
534 struct pipe_draw_info
535 {
536 boolean indexed; /**< use index buffer */
537
538 unsigned mode; /**< the mode of the primitive */
539 unsigned start; /**< the index of the first vertex */
540 unsigned count; /**< number of vertices */
541
542 unsigned start_instance; /**< first instance id */
543 unsigned instance_count; /**< number of instances */
544
545 /**
546 * For indexed drawing, these fields apply after index lookup.
547 */
548 int index_bias; /**< a bias to be added to each index */
549 unsigned min_index; /**< the min index */
550 unsigned max_index; /**< the max index */
551
552 /**
553 * Primitive restart enable/index (only applies to indexed drawing)
554 */
555 boolean primitive_restart;
556 unsigned restart_index;
557
558 /**
559 * Stream output target. If not NULL, it's used to provide the 'count'
560 * parameter based on the number vertices captured by the stream output
561 * stage. (or generally, based on the number of bytes captured)
562 *
563 * Only 'mode', 'start_instance', and 'instance_count' are taken into
564 * account, all the other variables from pipe_draw_info are ignored.
565 *
566 * 'start' is implicitly 0 and 'count' is set as discussed above.
567 * The draw command is non-indexed.
568 *
569 * Note that this only provides the count. The vertex buffers must
570 * be set via set_vertex_buffers manually.
571 */
572 struct pipe_stream_output_target *count_from_stream_output;
573 };
574
575
576 /**
577 * Information to describe a blit call.
578 */
579 struct pipe_blit_info
580 {
581 struct {
582 struct pipe_resource *resource;
583 unsigned level;
584 struct pipe_box box; /**< negative width, height only legal for src */
585 /* For pipe_surface-like format casting: */
586 enum pipe_format format; /**< must be supported for sampling (src)
587 or rendering (dst), ZS is always supported */
588 } dst, src;
589
590 unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
591 unsigned filter; /**< PIPE_TEX_FILTER_* */
592
593 boolean scissor_enable;
594 struct pipe_scissor_state scissor;
595
596 boolean render_condition_enable; /**< whether the blit should honor the
597 current render condition */
598 };
599
600
601 /**
602 * Structure used as a header for serialized LLVM programs.
603 */
604 struct pipe_llvm_program_header
605 {
606 uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
607 };
608
609 struct pipe_compute_state
610 {
611 const void *prog; /**< Compute program to be executed. */
612 unsigned req_local_mem; /**< Required size of the LOCAL resource. */
613 unsigned req_private_mem; /**< Required size of the PRIVATE resource. */
614 unsigned req_input_mem; /**< Required size of the INPUT resource. */
615 };
616
617 #ifdef __cplusplus
618 }
619 #endif
620
621 #endif