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