1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 * Abstract graphics pipe state objects.
35 * 1. Want compact representations, so we use bitfields.
36 * 2. Put bitfields before other (GLfloat) fields.
43 #include "p_compiler.h"
44 #include "p_defines.h"
54 * Implementation limits
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
72 int32_t count
; /* atomic */
78 * Primitive (point/line/tri) rasterization info
80 struct pipe_rasterizer_state
83 unsigned light_twoside
:1;
84 unsigned clamp_vertex_color
:1;
85 unsigned clamp_fragment_color
: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;
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;
106 * Use the first vertex of a primitive as the provoking vertex for
109 unsigned flatshade_first
:1;
112 * When true, triangle rasterization uses (0.5, 0.5) pixel centers
113 * for determining pixel ownership.
115 * When false, triangle rasterization uses (0,0) pixel centers for
116 * determining pixel ownership.
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.
122 unsigned gl_rasterization_rules
:1;
125 * When true, rasterization is disabled and no pixels are written.
126 * This only makes sense with the Stream Out functionality.
128 unsigned rasterizer_discard
:1;
130 unsigned line_stipple_factor
:8; /**< [1..256] actually */
131 unsigned line_stipple_pattern
:16;
133 unsigned sprite_coord_enable
:PIPE_MAX_SHADER_OUTPUTS
;
136 float point_size
; /**< used when no per-vertex size */
143 struct pipe_poly_stipple
145 unsigned stipple
[32];
149 struct pipe_viewport_state
156 struct pipe_scissor_state
165 struct pipe_clip_state
167 float ucp
[PIPE_MAX_CLIP_PLANES
][4];
169 unsigned depth_clamp
:1;
174 * Stream output for vertex transform feedback.
176 struct pipe_stream_output_info
178 unsigned num_outputs
;
179 /** stride for an entire vertex, only used if all output_buffers are 0 */
182 * Array of stream outputs, in the order they are to be written in.
183 * Selected components are tightly packed into the output buffer.
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
];
193 struct pipe_shader_state
195 const struct tgsi_token
*tokens
;
196 struct pipe_stream_output_info stream_output
;
200 struct pipe_depth_state
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) */
208 struct pipe_stencil_state
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;
220 struct pipe_alpha_state
223 unsigned func
:3; /**< PIPE_FUNC_x */
224 float ref_value
; /**< reference value */
228 struct pipe_depth_stencil_alpha_state
230 struct pipe_depth_state depth
;
231 struct pipe_stencil_state stencil
[2]; /**< [0] = front, [1] = back */
232 struct pipe_alpha_state alpha
;
236 struct pipe_rt_blend_state
238 unsigned blend_enable
:1;
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 */
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 */
248 unsigned colormask
:4; /**< bitmask of PIPE_MASK_R/G/B/A */
251 struct pipe_blend_state
253 unsigned independent_blend_enable
:1;
254 unsigned logicop_enable
:1;
255 unsigned logicop_func
:4; /**< PIPE_LOGICOP_x */
257 unsigned alpha_to_coverage
:1;
258 unsigned alpha_to_one
:1;
259 struct pipe_rt_blend_state rt
[PIPE_MAX_COLOR_BUFS
];
263 struct pipe_blend_color
268 struct pipe_stencil_ref
273 struct pipe_framebuffer_state
275 unsigned width
, height
;
277 /** multiple color buffers for multiple render targets */
279 struct pipe_surface
*cbufs
[PIPE_MAX_COLOR_BUFS
];
281 struct pipe_surface
*zsbuf
; /**< Z/stencil buffer */
286 * Texture sampler state.
288 struct pipe_sampler_state
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
;
308 * A view into a texture that can be bound to a color render target /
309 * depth stencil attachment point.
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
;
318 /* XXX width/height should be removed */
319 unsigned width
; /**< logical width in pixels */
320 unsigned height
; /**< logical height in pixels */
322 unsigned usage
; /**< bitmask of PIPE_BIND_x */
327 unsigned first_layer
:16;
328 unsigned last_layer
:16;
331 unsigned first_element
;
332 unsigned last_element
;
339 * A view into a texture that can be bound to a shader stage.
341 struct pipe_sampler_view
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 */
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 */
355 unsigned first_element
;
356 unsigned last_element
;
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 */
367 * Subregion of 1D/2D/3D image resource.
381 * A memory object/resource such as a vertex buffer or texture.
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 */
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) */
399 unsigned bind
; /**< bitmask of PIPE_BIND_x */
400 unsigned flags
; /**< bitmask of PIPE_RESOURCE_FLAG_x */
405 * Transfer object. For data transfer to/from a resource.
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 */
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.
425 struct pipe_vertex_buffer
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 */
434 * A stream output target. The structure specifies the range vertices can
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.
443 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
444 * actually been written.
446 struct pipe_stream_output_target
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 */
452 unsigned buffer_offset
; /**< offset where data should be written, in bytes */
453 unsigned buffer_size
; /**< how much data is allowed to be written */
458 * Information to describe a vertex attribute (position, color, etc)
460 struct pipe_vertex_element
462 /** Offset of this attribute, in bytes, from the start of the vertex */
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).
468 unsigned instance_divisor
;
470 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
471 * this attribute live in?
473 unsigned vertex_buffer_index
;
475 enum pipe_format src_format
;
480 * An index buffer. When an index buffer is bound, all indices to vertices
481 * will be looked up in the buffer.
483 struct pipe_index_buffer
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 */
492 * Information to describe a draw_vbo call.
494 struct pipe_draw_info
496 boolean indexed
; /**< use index buffer */
498 unsigned mode
; /**< the mode of the primitive */
499 unsigned start
; /**< the index of the first vertex */
500 unsigned count
; /**< number of vertices */
502 unsigned start_instance
; /**< first instance id */
503 unsigned instance_count
; /**< number of instances */
506 * For indexed drawing, these fields apply after index lookup.
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 */
513 * Primitive restart enable/index (only applies to indexed drawing)
515 boolean primitive_restart
;
516 unsigned restart_index
;
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)
523 * Only 'mode', 'start_instance', and 'instance_count' are taken into
524 * account, all the other variables from pipe_draw_info are ignored.
526 * 'start' is implicitly 0 and 'count' is set as discussed above.
527 * The draw command is non-indexed.
529 * Note that this only provides the count. The vertex buffers must
530 * be set via set_vertex_buffers manually.
532 struct pipe_stream_output_target
*count_from_stream_output
;
537 * Information to describe a resource_resolve call.
539 struct pipe_resolve_info
542 struct pipe_resource
*res
;
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 */
552 struct pipe_resource
*res
;
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 */
560 unsigned mask
; /**< PIPE_MASK_RGBA, Z, S or ZS */