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