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