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;
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.
135 unsigned depth_clip
:1;
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.
144 unsigned clip_plane_enable
:PIPE_MAX_CLIP_PLANES
;
146 unsigned line_stipple_factor
:8; /**< [1..256] actually */
147 unsigned line_stipple_pattern
:16;
149 unsigned sprite_coord_enable
:PIPE_MAX_SHADER_OUTPUTS
;
152 float point_size
; /**< used when no per-vertex size */
159 struct pipe_poly_stipple
161 unsigned stipple
[32];
165 struct pipe_viewport_state
172 struct pipe_scissor_state
181 struct pipe_clip_state
183 float ucp
[PIPE_MAX_CLIP_PLANES
][4];
188 * Stream output for vertex transform feedback.
190 struct pipe_stream_output_info
192 unsigned num_outputs
;
193 /** stride for an entire vertex, only used if all output_buffers are 0 */
196 * Array of stream outputs, in the order they are to be written in.
197 * Selected components are tightly packed into the output buffer.
200 unsigned register_index
:8; /**< 0 to PIPE_MAX_SHADER_OUTPUTS */
201 unsigned register_mask
:4; /**< TGSI_WRITEMASK_x */
202 unsigned output_buffer
:4; /**< 0 to PIPE_MAX_SO_BUFFERS */
203 } output
[PIPE_MAX_SHADER_OUTPUTS
];
207 struct pipe_shader_state
209 const struct tgsi_token
*tokens
;
210 struct pipe_stream_output_info stream_output
;
214 struct pipe_depth_state
216 unsigned enabled
:1; /**< depth test enabled? */
217 unsigned writemask
:1; /**< allow depth buffer writes? */
218 unsigned func
:3; /**< depth test func (PIPE_FUNC_x) */
222 struct pipe_stencil_state
224 unsigned enabled
:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
225 unsigned func
:3; /**< PIPE_FUNC_x */
226 unsigned fail_op
:3; /**< PIPE_STENCIL_OP_x */
227 unsigned zpass_op
:3; /**< PIPE_STENCIL_OP_x */
228 unsigned zfail_op
:3; /**< PIPE_STENCIL_OP_x */
229 unsigned valuemask
:8;
230 unsigned writemask
:8;
234 struct pipe_alpha_state
237 unsigned func
:3; /**< PIPE_FUNC_x */
238 float ref_value
; /**< reference value */
242 struct pipe_depth_stencil_alpha_state
244 struct pipe_depth_state depth
;
245 struct pipe_stencil_state stencil
[2]; /**< [0] = front, [1] = back */
246 struct pipe_alpha_state alpha
;
250 struct pipe_rt_blend_state
252 unsigned blend_enable
:1;
254 unsigned rgb_func
:3; /**< PIPE_BLEND_x */
255 unsigned rgb_src_factor
:5; /**< PIPE_BLENDFACTOR_x */
256 unsigned rgb_dst_factor
:5; /**< PIPE_BLENDFACTOR_x */
258 unsigned alpha_func
:3; /**< PIPE_BLEND_x */
259 unsigned alpha_src_factor
:5; /**< PIPE_BLENDFACTOR_x */
260 unsigned alpha_dst_factor
:5; /**< PIPE_BLENDFACTOR_x */
262 unsigned colormask
:4; /**< bitmask of PIPE_MASK_R/G/B/A */
265 struct pipe_blend_state
267 unsigned independent_blend_enable
:1;
268 unsigned logicop_enable
:1;
269 unsigned logicop_func
:4; /**< PIPE_LOGICOP_x */
271 unsigned alpha_to_coverage
:1;
272 unsigned alpha_to_one
:1;
273 struct pipe_rt_blend_state rt
[PIPE_MAX_COLOR_BUFS
];
277 struct pipe_blend_color
282 struct pipe_stencil_ref
287 struct pipe_framebuffer_state
289 unsigned width
, height
;
291 /** multiple color buffers for multiple render targets */
293 struct pipe_surface
*cbufs
[PIPE_MAX_COLOR_BUFS
];
295 struct pipe_surface
*zsbuf
; /**< Z/stencil buffer */
300 * Texture sampler state.
302 struct pipe_sampler_state
304 unsigned wrap_s
:3; /**< PIPE_TEX_WRAP_x */
305 unsigned wrap_t
:3; /**< PIPE_TEX_WRAP_x */
306 unsigned wrap_r
:3; /**< PIPE_TEX_WRAP_x */
307 unsigned min_img_filter
:2; /**< PIPE_TEX_FILTER_x */
308 unsigned min_mip_filter
:2; /**< PIPE_TEX_MIPFILTER_x */
309 unsigned mag_img_filter
:2; /**< PIPE_TEX_FILTER_x */
310 unsigned compare_mode
:1; /**< PIPE_TEX_COMPARE_x */
311 unsigned compare_func
:3; /**< PIPE_FUNC_x */
312 unsigned normalized_coords
:1; /**< Are coords normalized to [0,1]? */
313 unsigned max_anisotropy
:6;
314 unsigned seamless_cube_map
:1;
315 float lod_bias
; /**< LOD/lambda bias */
316 float min_lod
, max_lod
; /**< LOD clamp range, after bias */
317 union pipe_color_union border_color
;
322 * A view into a texture that can be bound to a color render target /
323 * depth stencil attachment point.
327 struct pipe_reference reference
;
328 struct pipe_resource
*texture
; /**< resource into which this is a view */
329 struct pipe_context
*context
; /**< context this view belongs to */
330 enum pipe_format format
;
332 /* XXX width/height should be removed */
333 unsigned width
; /**< logical width in pixels */
334 unsigned height
; /**< logical height in pixels */
336 unsigned usage
; /**< bitmask of PIPE_BIND_x */
341 unsigned first_layer
:16;
342 unsigned last_layer
:16;
345 unsigned first_element
;
346 unsigned last_element
;
353 * A view into a texture that can be bound to a shader stage.
355 struct pipe_sampler_view
357 struct pipe_reference reference
;
358 enum pipe_format format
; /**< typed PIPE_FORMAT_x */
359 struct pipe_resource
*texture
; /**< texture into which this is a view */
360 struct pipe_context
*context
; /**< context this view belongs to */
363 unsigned first_layer
:16; /**< first layer to use for array textures */
364 unsigned last_layer
:16; /**< last layer to use for array textures */
365 unsigned first_level
:8; /**< first mipmap level to use */
366 unsigned last_level
:8; /**< last mipmap level to use */
369 unsigned first_element
;
370 unsigned last_element
;
373 unsigned swizzle_r
:3; /**< PIPE_SWIZZLE_x for red component */
374 unsigned swizzle_g
:3; /**< PIPE_SWIZZLE_x for green component */
375 unsigned swizzle_b
:3; /**< PIPE_SWIZZLE_x for blue component */
376 unsigned swizzle_a
:3; /**< PIPE_SWIZZLE_x for alpha component */
381 * Subregion of 1D/2D/3D image resource.
395 * A memory object/resource such as a vertex buffer or texture.
399 struct pipe_reference reference
;
400 struct pipe_screen
*screen
; /**< screen that this texture belongs to */
401 enum pipe_texture_target target
; /**< PIPE_TEXTURE_x */
402 enum pipe_format format
; /**< PIPE_FORMAT_x */
409 unsigned last_level
:8; /**< Index of last mipmap level present/defined */
410 unsigned nr_samples
:8; /**< for multisampled surfaces, nr of samples */
411 unsigned usage
:8; /**< PIPE_USAGE_x (not a bitmask) */
413 unsigned bind
; /**< bitmask of PIPE_BIND_x */
414 unsigned flags
; /**< bitmask of PIPE_RESOURCE_FLAG_x */
419 * Transfer object. For data transfer to/from a resource.
423 struct pipe_resource
*resource
; /**< resource to transfer to/from */
424 unsigned level
; /**< texture mipmap level */
425 enum pipe_transfer_usage usage
;
426 struct pipe_box box
; /**< region of the resource to access */
427 unsigned stride
; /**< row stride in bytes */
428 unsigned layer_stride
; /**< image/layer stride in bytes */
435 * A vertex buffer. Typically, all the vertex data/attributes for
436 * drawing something will be in one buffer. But it's also possible, for
437 * example, to put colors in one buffer and texcoords in another.
439 struct pipe_vertex_buffer
441 unsigned stride
; /**< stride to same attrib in next vertex, in bytes */
442 unsigned buffer_offset
; /**< offset to start of data in buffer, in bytes */
443 struct pipe_resource
*buffer
; /**< the actual buffer */
448 * A stream output target. The structure specifies the range vertices can
451 * In addition to that, the structure should internally maintain the offset
452 * into the buffer, which should be incremented everytime something is written
453 * (appended) to it. The internal offset is buffer_offset + how many bytes
454 * have been written. The internal offset can be stored on the device
455 * and the CPU actually doesn't have to query it.
457 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
458 * actually been written.
460 struct pipe_stream_output_target
462 struct pipe_reference reference
;
463 struct pipe_resource
*buffer
; /**< buffer into which this is a target view */
464 struct pipe_context
*context
; /**< context this view belongs to */
466 unsigned buffer_offset
; /**< offset where data should be written, in bytes */
467 unsigned buffer_size
; /**< how much data is allowed to be written */
472 * Information to describe a vertex attribute (position, color, etc)
474 struct pipe_vertex_element
476 /** Offset of this attribute, in bytes, from the start of the vertex */
479 /** Instance data rate divisor. 0 means this is per-vertex data,
480 * n means per-instance data used for n consecutive instances (n > 0).
482 unsigned instance_divisor
;
484 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
485 * this attribute live in?
487 unsigned vertex_buffer_index
;
489 enum pipe_format src_format
;
494 * An index buffer. When an index buffer is bound, all indices to vertices
495 * will be looked up in the buffer.
497 struct pipe_index_buffer
499 unsigned index_size
; /**< size of an index, in bytes */
500 unsigned offset
; /**< offset to start of data in buffer, in bytes */
501 struct pipe_resource
*buffer
; /**< the actual buffer */
506 * Information to describe a draw_vbo call.
508 struct pipe_draw_info
510 boolean indexed
; /**< use index buffer */
512 unsigned mode
; /**< the mode of the primitive */
513 unsigned start
; /**< the index of the first vertex */
514 unsigned count
; /**< number of vertices */
516 unsigned start_instance
; /**< first instance id */
517 unsigned instance_count
; /**< number of instances */
520 * For indexed drawing, these fields apply after index lookup.
522 int index_bias
; /**< a bias to be added to each index */
523 unsigned min_index
; /**< the min index */
524 unsigned max_index
; /**< the max index */
527 * Primitive restart enable/index (only applies to indexed drawing)
529 boolean primitive_restart
;
530 unsigned restart_index
;
533 * Stream output target. If not NULL, it's used to provide the 'count'
534 * parameter based on the number vertices captured by the stream output
535 * stage. (or generally, based on the number of bytes captured)
537 * Only 'mode', 'start_instance', and 'instance_count' are taken into
538 * account, all the other variables from pipe_draw_info are ignored.
540 * 'start' is implicitly 0 and 'count' is set as discussed above.
541 * The draw command is non-indexed.
543 * Note that this only provides the count. The vertex buffers must
544 * be set via set_vertex_buffers manually.
546 struct pipe_stream_output_target
*count_from_stream_output
;
551 * Information to describe a resource_resolve call.
553 struct pipe_resolve_info
556 struct pipe_resource
*res
;
559 int x0
; /**< always left */
560 int y0
; /**< always top */
561 int x1
; /**< determines scale if PIPE_CAP_SCALED_RESOLVE is supported */
562 int y1
; /**< determines scale if PIPE_CAP_SCALED_RESOLVE is supported */
566 struct pipe_resource
*res
;
570 int x1
; /**< may be < x0 only if PIPE_CAP_SCALED_RESOLVE is supported */
571 int y1
; /**< may be < y1 even if PIPE_CAP_SCALED_RESOLVE not supported */
574 unsigned mask
; /**< PIPE_MASK_RGBA, Z, S or ZS */