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