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