gallium/st: add pipe_context::get_timestamp()
[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 18 /* 16 public + 2 driver internal */
61 #define PIPE_MAX_SHADER_INPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
62 #define PIPE_MAX_SHADER_OUTPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
63 #define PIPE_MAX_SHADER_SAMPLER_VIEWS 32
64 #define PIPE_MAX_SHADER_BUFFERS 32
65 #define PIPE_MAX_SHADER_IMAGES 32
66 #define PIPE_MAX_TEXTURE_LEVELS 16
67 #define PIPE_MAX_SO_BUFFERS 4
68 #define PIPE_MAX_SO_OUTPUTS 64
69 #define PIPE_MAX_VIEWPORTS 16
70 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
71 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
72
73
74 struct pipe_reference
75 {
76 int32_t count; /* atomic */
77 };
78
79
80
81 /**
82 * Primitive (point/line/tri) rasterization info
83 */
84 struct pipe_rasterizer_state
85 {
86 unsigned flatshade:1;
87 unsigned light_twoside:1;
88 unsigned clamp_vertex_color:1;
89 unsigned clamp_fragment_color:1;
90 unsigned front_ccw:1;
91 unsigned cull_face:2; /**< PIPE_FACE_x */
92 unsigned fill_front:2; /**< PIPE_POLYGON_MODE_x */
93 unsigned fill_back:2; /**< PIPE_POLYGON_MODE_x */
94 unsigned offset_point:1;
95 unsigned offset_line:1;
96 unsigned offset_tri:1;
97 unsigned scissor:1;
98 unsigned poly_smooth:1;
99 unsigned poly_stipple_enable:1;
100 unsigned point_smooth:1;
101 unsigned sprite_coord_mode:1; /**< PIPE_SPRITE_COORD_ */
102 unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
103 unsigned point_tri_clip:1; /** large points clipped as tris or points */
104 unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
105 unsigned multisample:1; /* XXX maybe more ms state in future */
106 unsigned line_smooth:1;
107 unsigned line_stipple_enable:1;
108 unsigned line_last_pixel:1;
109
110 /**
111 * Use the first vertex of a primitive as the provoking vertex for
112 * flat shading.
113 */
114 unsigned flatshade_first:1;
115
116 unsigned half_pixel_center:1;
117 unsigned bottom_edge_rule:1;
118
119 /**
120 * When true, rasterization is disabled and no pixels are written.
121 * This only makes sense with the Stream Out functionality.
122 */
123 unsigned rasterizer_discard:1;
124
125 /**
126 * When false, depth clipping is disabled and the depth value will be
127 * clamped later at the per-pixel level before depth testing.
128 * This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
129 */
130 unsigned depth_clip:1;
131
132 /**
133 * When true clip space in the z axis goes from [0..1] (D3D). When false
134 * [-1, 1] (GL).
135 *
136 * NOTE: D3D will always use depth clamping.
137 */
138 unsigned clip_halfz:1;
139
140 /**
141 * Enable bits for clipping half-spaces.
142 * This applies to both user clip planes and shader clip distances.
143 * Note that if the bound shader exports any clip distances, these
144 * replace all user clip planes, and clip half-spaces enabled here
145 * but not written by the shader count as disabled.
146 */
147 unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES;
148
149 unsigned line_stipple_factor:8; /**< [1..256] actually */
150 unsigned line_stipple_pattern:16;
151
152 uint32_t sprite_coord_enable; /* referring to 32 TEXCOORD/GENERIC inputs */
153
154 float line_width;
155 float point_size; /**< used when no per-vertex size */
156 float offset_units;
157 float offset_scale;
158 float offset_clamp;
159 };
160
161
162 struct pipe_poly_stipple
163 {
164 unsigned stipple[32];
165 };
166
167
168 struct pipe_viewport_state
169 {
170 float scale[3];
171 float translate[3];
172 };
173
174
175 struct pipe_scissor_state
176 {
177 unsigned minx:16;
178 unsigned miny:16;
179 unsigned maxx:16;
180 unsigned maxy:16;
181 };
182
183
184 struct pipe_clip_state
185 {
186 float ucp[PIPE_MAX_CLIP_PLANES][4];
187 };
188
189
190 /**
191 * Stream output for vertex transform feedback.
192 */
193 struct pipe_stream_output_info
194 {
195 unsigned num_outputs;
196 /** stride for an entire vertex for each buffer in dwords */
197 unsigned stride[PIPE_MAX_SO_BUFFERS];
198
199 /**
200 * Array of stream outputs, in the order they are to be written in.
201 * Selected components are tightly packed into the output buffer.
202 */
203 struct {
204 unsigned register_index:8; /**< 0 to PIPE_MAX_SHADER_OUTPUTS */
205 unsigned start_component:2; /** 0 to 3 */
206 unsigned num_components:3; /** 1 to 4 */
207 unsigned output_buffer:3; /**< 0 to PIPE_MAX_SO_BUFFERS */
208 unsigned dst_offset:16; /**< offset into the buffer in dwords */
209 unsigned stream:2; /**< 0 to 3 */
210 } output[PIPE_MAX_SO_OUTPUTS];
211 };
212
213
214 struct pipe_shader_state
215 {
216 const struct tgsi_token *tokens;
217 struct pipe_stream_output_info stream_output;
218 };
219
220
221 struct pipe_depth_state
222 {
223 unsigned enabled:1; /**< depth test enabled? */
224 unsigned writemask:1; /**< allow depth buffer writes? */
225 unsigned func:3; /**< depth test func (PIPE_FUNC_x) */
226 unsigned bounds_test:1; /**< depth bounds test enabled? */
227 float bounds_min; /**< minimum depth bound */
228 float bounds_max; /**< maximum depth bound */
229 };
230
231
232 struct pipe_stencil_state
233 {
234 unsigned enabled:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
235 unsigned func:3; /**< PIPE_FUNC_x */
236 unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */
237 unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
238 unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
239 unsigned valuemask:8;
240 unsigned writemask:8;
241 };
242
243
244 struct pipe_alpha_state
245 {
246 unsigned enabled:1;
247 unsigned func:3; /**< PIPE_FUNC_x */
248 float ref_value; /**< reference value */
249 };
250
251
252 struct pipe_depth_stencil_alpha_state
253 {
254 struct pipe_depth_state depth;
255 struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
256 struct pipe_alpha_state alpha;
257 };
258
259
260 struct pipe_rt_blend_state
261 {
262 unsigned blend_enable:1;
263
264 unsigned rgb_func:3; /**< PIPE_BLEND_x */
265 unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
266 unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
267
268 unsigned alpha_func:3; /**< PIPE_BLEND_x */
269 unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
270 unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
271
272 unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */
273 };
274
275
276 struct pipe_blend_state
277 {
278 unsigned independent_blend_enable:1;
279 unsigned logicop_enable:1;
280 unsigned logicop_func:4; /**< PIPE_LOGICOP_x */
281 unsigned dither:1;
282 unsigned alpha_to_coverage:1;
283 unsigned alpha_to_one:1;
284 struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
285 };
286
287
288 struct pipe_blend_color
289 {
290 float color[4];
291 };
292
293
294 struct pipe_stencil_ref
295 {
296 ubyte ref_value[2];
297 };
298
299
300 struct pipe_framebuffer_state
301 {
302 unsigned width, height;
303
304 /** multiple color buffers for multiple render targets */
305 unsigned nr_cbufs;
306 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
307
308 struct pipe_surface *zsbuf; /**< Z/stencil buffer */
309 };
310
311
312 /**
313 * Texture sampler state.
314 */
315 struct pipe_sampler_state
316 {
317 unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
318 unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
319 unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
320 unsigned min_img_filter:2; /**< PIPE_TEX_FILTER_x */
321 unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */
322 unsigned mag_img_filter:2; /**< PIPE_TEX_FILTER_x */
323 unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
324 unsigned compare_func:3; /**< PIPE_FUNC_x */
325 unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
326 unsigned max_anisotropy:6;
327 unsigned seamless_cube_map:1;
328 float lod_bias; /**< LOD/lambda bias */
329 float min_lod, max_lod; /**< LOD clamp range, after bias */
330 union pipe_color_union border_color;
331 };
332
333
334 /**
335 * A view into a texture that can be bound to a color render target /
336 * depth stencil attachment point.
337 */
338 struct pipe_surface
339 {
340 struct pipe_reference reference;
341 struct pipe_resource *texture; /**< resource into which this is a view */
342 struct pipe_context *context; /**< context this surface belongs to */
343 enum pipe_format format;
344
345 /* XXX width/height should be removed */
346 unsigned width; /**< logical width in pixels */
347 unsigned height; /**< logical height in pixels */
348
349 unsigned writable:1; /**< writable shader resource */
350
351 union {
352 struct {
353 unsigned level;
354 unsigned first_layer:16;
355 unsigned last_layer:16;
356 } tex;
357 struct {
358 unsigned first_element;
359 unsigned last_element;
360 } buf;
361 } u;
362 };
363
364
365 /**
366 * A view into a texture that can be bound to a shader stage.
367 */
368 struct pipe_sampler_view
369 {
370 struct pipe_reference reference;
371 enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
372 enum pipe_format format; /**< typed PIPE_FORMAT_x */
373 struct pipe_resource *texture; /**< texture into which this is a view */
374 struct pipe_context *context; /**< context this view belongs to */
375 union {
376 struct {
377 unsigned first_layer:16; /**< first layer to use for array textures */
378 unsigned last_layer:16; /**< last layer to use for array textures */
379 unsigned first_level:8; /**< first mipmap level to use */
380 unsigned last_level:8; /**< last mipmap level to use */
381 } tex;
382 struct {
383 unsigned first_element;
384 unsigned last_element;
385 } buf;
386 } u;
387 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */
388 unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */
389 unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */
390 unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */
391 };
392
393
394 /**
395 * A view into a writable buffer or texture that can be bound to a shader
396 * stage.
397 */
398 struct pipe_image_view
399 {
400 struct pipe_reference reference;
401 struct pipe_resource *resource; /**< resource into which this is a view */
402 struct pipe_context *context; /**< context this view belongs to */
403 enum pipe_format format; /**< typed PIPE_FORMAT_x */
404
405 union {
406 struct {
407 unsigned first_layer:16; /**< first layer to use for array textures */
408 unsigned last_layer:16; /**< last layer to use for array textures */
409 unsigned level:8; /**< mipmap level to use */
410 } tex;
411 struct {
412 unsigned first_element;
413 unsigned last_element;
414 } buf;
415 } u;
416 };
417
418
419 /**
420 * Subregion of 1D/2D/3D image resource.
421 */
422 struct pipe_box
423 {
424 int x;
425 int y;
426 int z;
427 int width;
428 int height;
429 int depth;
430 };
431
432
433 /**
434 * A memory object/resource such as a vertex buffer or texture.
435 */
436 struct pipe_resource
437 {
438 struct pipe_reference reference;
439 struct pipe_screen *screen; /**< screen that this texture belongs to */
440 enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
441 enum pipe_format format; /**< PIPE_FORMAT_x */
442
443 unsigned width0;
444 unsigned height0;
445 unsigned depth0;
446 unsigned array_size;
447
448 unsigned last_level:8; /**< Index of last mipmap level present/defined */
449 unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */
450 unsigned usage:8; /**< PIPE_USAGE_x (not a bitmask) */
451
452 unsigned bind; /**< bitmask of PIPE_BIND_x */
453 unsigned flags; /**< bitmask of PIPE_RESOURCE_FLAG_x */
454 };
455
456
457 /**
458 * Transfer object. For data transfer to/from a resource.
459 */
460 struct pipe_transfer
461 {
462 struct pipe_resource *resource; /**< resource to transfer to/from */
463 unsigned level; /**< texture mipmap level */
464 enum pipe_transfer_usage usage;
465 struct pipe_box box; /**< region of the resource to access */
466 unsigned stride; /**< row stride in bytes */
467 unsigned layer_stride; /**< image/layer stride in bytes */
468 };
469
470
471
472 /**
473 * A vertex buffer. Typically, all the vertex data/attributes for
474 * drawing something will be in one buffer. But it's also possible, for
475 * example, to put colors in one buffer and texcoords in another.
476 */
477 struct pipe_vertex_buffer
478 {
479 unsigned stride; /**< stride to same attrib in next vertex, in bytes */
480 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
481 struct pipe_resource *buffer; /**< the actual buffer */
482 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
483 };
484
485
486 /**
487 * A constant buffer. A subrange of an existing buffer can be set
488 * as a constant buffer.
489 */
490 struct pipe_constant_buffer
491 {
492 struct pipe_resource *buffer; /**< the actual buffer */
493 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
494 unsigned buffer_size; /**< how much data can be read in shader */
495 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
496 };
497
498
499 /**
500 * An untyped shader buffer supporting loads, stores, and atomics.
501 */
502 struct pipe_shader_buffer {
503 struct pipe_resource *buffer; /**< the actual buffer */
504 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
505 unsigned buffer_size; /**< how much data can be read in shader */
506 };
507
508
509 /**
510 * A stream output target. The structure specifies the range vertices can
511 * be written to.
512 *
513 * In addition to that, the structure should internally maintain the offset
514 * into the buffer, which should be incremented everytime something is written
515 * (appended) to it. The internal offset is buffer_offset + how many bytes
516 * have been written. The internal offset can be stored on the device
517 * and the CPU actually doesn't have to query it.
518 *
519 * Note that the buffer_size variable is actually specifying the available
520 * space in the buffer, not the size of the attached buffer.
521 * In other words in majority of cases buffer_size would simply be
522 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
523 * of the buffer left, after accounting for buffer offset, for stream output
524 * to write to.
525 *
526 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
527 * actually been written.
528 */
529 struct pipe_stream_output_target
530 {
531 struct pipe_reference reference;
532 struct pipe_resource *buffer; /**< the output buffer */
533 struct pipe_context *context; /**< context this SO target belongs to */
534
535 unsigned buffer_offset; /**< offset where data should be written, in bytes */
536 unsigned buffer_size; /**< how much data is allowed to be written */
537 };
538
539
540 /**
541 * Information to describe a vertex attribute (position, color, etc)
542 */
543 struct pipe_vertex_element
544 {
545 /** Offset of this attribute, in bytes, from the start of the vertex */
546 unsigned src_offset;
547
548 /** Instance data rate divisor. 0 means this is per-vertex data,
549 * n means per-instance data used for n consecutive instances (n > 0).
550 */
551 unsigned instance_divisor;
552
553 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
554 * this attribute live in?
555 */
556 unsigned vertex_buffer_index;
557
558 enum pipe_format src_format;
559 };
560
561
562 /**
563 * An index buffer. When an index buffer is bound, all indices to vertices
564 * will be looked up in the buffer.
565 */
566 struct pipe_index_buffer
567 {
568 unsigned index_size; /**< size of an index, in bytes */
569 unsigned offset; /**< offset to start of data in buffer, in bytes */
570 struct pipe_resource *buffer; /**< the actual buffer */
571 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
572 };
573
574
575 /**
576 * Information to describe a draw_vbo call.
577 */
578 struct pipe_draw_info
579 {
580 boolean indexed; /**< use index buffer */
581
582 unsigned mode; /**< the mode of the primitive */
583 unsigned start; /**< the index of the first vertex */
584 unsigned count; /**< number of vertices */
585
586 unsigned start_instance; /**< first instance id */
587 unsigned instance_count; /**< number of instances */
588
589 unsigned vertices_per_patch; /**< the number of vertices per patch */
590
591 /**
592 * For indexed drawing, these fields apply after index lookup.
593 */
594 int index_bias; /**< a bias to be added to each index */
595 unsigned min_index; /**< the min index */
596 unsigned max_index; /**< the max index */
597
598 /**
599 * Primitive restart enable/index (only applies to indexed drawing)
600 */
601 boolean primitive_restart;
602 unsigned restart_index;
603
604 /**
605 * Stream output target. If not NULL, it's used to provide the 'count'
606 * parameter based on the number vertices captured by the stream output
607 * stage. (or generally, based on the number of bytes captured)
608 *
609 * Only 'mode', 'start_instance', and 'instance_count' are taken into
610 * account, all the other variables from pipe_draw_info are ignored.
611 *
612 * 'start' is implicitly 0 and 'count' is set as discussed above.
613 * The draw command is non-indexed.
614 *
615 * Note that this only provides the count. The vertex buffers must
616 * be set via set_vertex_buffers manually.
617 */
618 struct pipe_stream_output_target *count_from_stream_output;
619
620 /* Indirect parameters resource: If not NULL, most values are taken
621 * from this buffer instead, which is laid out as follows:
622 *
623 * if indexed is TRUE:
624 * struct {
625 * uint32_t count;
626 * uint32_t instance_count;
627 * uint32_t start;
628 * int32_t index_bias;
629 * uint32_t start_instance;
630 * };
631 * otherwise:
632 * struct {
633 * uint32_t count;
634 * uint32_t instance_count;
635 * uint32_t start;
636 * uint32_t start_instance;
637 * };
638 */
639 struct pipe_resource *indirect;
640 unsigned indirect_offset; /**< must be 4 byte aligned */
641 };
642
643
644 /**
645 * Information to describe a blit call.
646 */
647 struct pipe_blit_info
648 {
649 struct {
650 struct pipe_resource *resource;
651 unsigned level;
652 struct pipe_box box; /**< negative width, height only legal for src */
653 /* For pipe_surface-like format casting: */
654 enum pipe_format format; /**< must be supported for sampling (src)
655 or rendering (dst), ZS is always supported */
656 } dst, src;
657
658 unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
659 unsigned filter; /**< PIPE_TEX_FILTER_* */
660
661 boolean scissor_enable;
662 struct pipe_scissor_state scissor;
663
664 boolean render_condition_enable; /**< whether the blit should honor the
665 current render condition */
666 boolean alpha_blend; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
667 };
668
669
670 /**
671 * Structure used as a header for serialized LLVM programs.
672 */
673 struct pipe_llvm_program_header
674 {
675 uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
676 };
677
678 struct pipe_compute_state
679 {
680 const void *prog; /**< Compute program to be executed. */
681 unsigned req_local_mem; /**< Required size of the LOCAL resource. */
682 unsigned req_private_mem; /**< Required size of the PRIVATE resource. */
683 unsigned req_input_mem; /**< Required size of the INPUT resource. */
684 };
685
686 #ifdef __cplusplus
687 }
688 #endif
689
690 #endif