1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 18 /* 16 public + 2 driver internal */
61 #define PIPE_MAX_SHADER_INPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
62 #define PIPE_MAX_SHADER_OUTPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
63 #define PIPE_MAX_SHADER_SAMPLER_VIEWS 32
64 #define PIPE_MAX_SHADER_BUFFERS 32
65 #define PIPE_MAX_SHADER_IMAGES 32
66 #define PIPE_MAX_TEXTURE_LEVELS 16
67 #define PIPE_MAX_SO_BUFFERS 4
68 #define PIPE_MAX_SO_OUTPUTS 64
69 #define PIPE_MAX_VIEWPORTS 16
70 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
71 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
76 int32_t count
; /* atomic */
82 * Primitive (point/line/tri) rasterization info
84 struct pipe_rasterizer_state
87 unsigned light_twoside
:1;
88 unsigned clamp_vertex_color
:1;
89 unsigned clamp_fragment_color
:1;
91 unsigned cull_face
:2; /**< PIPE_FACE_x */
92 unsigned fill_front
:2; /**< PIPE_POLYGON_MODE_x */
93 unsigned fill_back
:2; /**< PIPE_POLYGON_MODE_x */
94 unsigned offset_point
:1;
95 unsigned offset_line
:1;
96 unsigned offset_tri
:1;
98 unsigned poly_smooth
:1;
99 unsigned poly_stipple_enable
:1;
100 unsigned point_smooth
:1;
101 unsigned sprite_coord_mode
:1; /**< PIPE_SPRITE_COORD_ */
102 unsigned point_quad_rasterization
:1; /** points rasterized as quads or points */
103 unsigned point_tri_clip
:1; /** large points clipped as tris or points */
104 unsigned point_size_per_vertex
:1; /**< size computed in vertex shader */
105 unsigned multisample
:1; /* XXX maybe more ms state in future */
106 unsigned force_persample_interp
:1;
107 unsigned line_smooth
:1;
108 unsigned line_stipple_enable
:1;
109 unsigned line_last_pixel
:1;
112 * Use the first vertex of a primitive as the provoking vertex for
115 unsigned flatshade_first
:1;
117 unsigned half_pixel_center
:1;
118 unsigned bottom_edge_rule
:1;
121 * When true, rasterization is disabled and no pixels are written.
122 * This only makes sense with the Stream Out functionality.
124 unsigned rasterizer_discard
:1;
127 * When false, depth clipping is disabled and the depth value will be
128 * clamped later at the per-pixel level before depth testing.
129 * This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
131 unsigned depth_clip
:1;
134 * When true clip space in the z axis goes from [0..1] (D3D). When false
137 * NOTE: D3D will always use depth clamping.
139 unsigned clip_halfz
:1;
142 * Enable bits for clipping half-spaces.
143 * This applies to both user clip planes and shader clip distances.
144 * Note that if the bound shader exports any clip distances, these
145 * replace all user clip planes, and clip half-spaces enabled here
146 * but not written by the shader count as disabled.
148 unsigned clip_plane_enable
:PIPE_MAX_CLIP_PLANES
;
150 unsigned line_stipple_factor
:8; /**< [1..256] actually */
151 unsigned line_stipple_pattern
:16;
153 uint32_t sprite_coord_enable
; /* referring to 32 TEXCOORD/GENERIC inputs */
156 float point_size
; /**< used when no per-vertex size */
163 struct pipe_poly_stipple
165 unsigned stipple
[32];
169 struct pipe_viewport_state
176 struct pipe_scissor_state
185 struct pipe_clip_state
187 float ucp
[PIPE_MAX_CLIP_PLANES
][4];
192 * Stream output for vertex transform feedback.
194 struct pipe_stream_output_info
196 unsigned num_outputs
;
197 /** stride for an entire vertex for each buffer in dwords */
198 unsigned stride
[PIPE_MAX_SO_BUFFERS
];
201 * Array of stream outputs, in the order they are to be written in.
202 * Selected components are tightly packed into the output buffer.
205 unsigned register_index
:8; /**< 0 to PIPE_MAX_SHADER_OUTPUTS */
206 unsigned start_component
:2; /** 0 to 3 */
207 unsigned num_components
:3; /** 1 to 4 */
208 unsigned output_buffer
:3; /**< 0 to PIPE_MAX_SO_BUFFERS */
209 unsigned dst_offset
:16; /**< offset into the buffer in dwords */
210 unsigned stream
:2; /**< 0 to 3 */
211 } output
[PIPE_MAX_SO_OUTPUTS
];
215 struct pipe_shader_state
217 const struct tgsi_token
*tokens
;
218 struct pipe_stream_output_info stream_output
;
222 struct pipe_depth_state
224 unsigned enabled
:1; /**< depth test enabled? */
225 unsigned writemask
:1; /**< allow depth buffer writes? */
226 unsigned func
:3; /**< depth test func (PIPE_FUNC_x) */
227 unsigned bounds_test
:1; /**< depth bounds test enabled? */
228 float bounds_min
; /**< minimum depth bound */
229 float bounds_max
; /**< maximum depth bound */
233 struct pipe_stencil_state
235 unsigned enabled
:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
236 unsigned func
:3; /**< PIPE_FUNC_x */
237 unsigned fail_op
:3; /**< PIPE_STENCIL_OP_x */
238 unsigned zpass_op
:3; /**< PIPE_STENCIL_OP_x */
239 unsigned zfail_op
:3; /**< PIPE_STENCIL_OP_x */
240 unsigned valuemask
:8;
241 unsigned writemask
:8;
245 struct pipe_alpha_state
248 unsigned func
:3; /**< PIPE_FUNC_x */
249 float ref_value
; /**< reference value */
253 struct pipe_depth_stencil_alpha_state
255 struct pipe_depth_state depth
;
256 struct pipe_stencil_state stencil
[2]; /**< [0] = front, [1] = back */
257 struct pipe_alpha_state alpha
;
261 struct pipe_rt_blend_state
263 unsigned blend_enable
:1;
265 unsigned rgb_func
:3; /**< PIPE_BLEND_x */
266 unsigned rgb_src_factor
:5; /**< PIPE_BLENDFACTOR_x */
267 unsigned rgb_dst_factor
:5; /**< PIPE_BLENDFACTOR_x */
269 unsigned alpha_func
:3; /**< PIPE_BLEND_x */
270 unsigned alpha_src_factor
:5; /**< PIPE_BLENDFACTOR_x */
271 unsigned alpha_dst_factor
:5; /**< PIPE_BLENDFACTOR_x */
273 unsigned colormask
:4; /**< bitmask of PIPE_MASK_R/G/B/A */
277 struct pipe_blend_state
279 unsigned independent_blend_enable
:1;
280 unsigned logicop_enable
:1;
281 unsigned logicop_func
:4; /**< PIPE_LOGICOP_x */
283 unsigned alpha_to_coverage
:1;
284 unsigned alpha_to_one
:1;
285 struct pipe_rt_blend_state rt
[PIPE_MAX_COLOR_BUFS
];
289 struct pipe_blend_color
295 struct pipe_stencil_ref
301 struct pipe_framebuffer_state
303 unsigned width
, height
;
305 /** multiple color buffers for multiple render targets */
307 struct pipe_surface
*cbufs
[PIPE_MAX_COLOR_BUFS
];
309 struct pipe_surface
*zsbuf
; /**< Z/stencil buffer */
314 * Texture sampler state.
316 struct pipe_sampler_state
318 unsigned wrap_s
:3; /**< PIPE_TEX_WRAP_x */
319 unsigned wrap_t
:3; /**< PIPE_TEX_WRAP_x */
320 unsigned wrap_r
:3; /**< PIPE_TEX_WRAP_x */
321 unsigned min_img_filter
:2; /**< PIPE_TEX_FILTER_x */
322 unsigned min_mip_filter
:2; /**< PIPE_TEX_MIPFILTER_x */
323 unsigned mag_img_filter
:2; /**< PIPE_TEX_FILTER_x */
324 unsigned compare_mode
:1; /**< PIPE_TEX_COMPARE_x */
325 unsigned compare_func
:3; /**< PIPE_FUNC_x */
326 unsigned normalized_coords
:1; /**< Are coords normalized to [0,1]? */
327 unsigned max_anisotropy
:6;
328 unsigned seamless_cube_map
:1;
329 float lod_bias
; /**< LOD/lambda bias */
330 float min_lod
, max_lod
; /**< LOD clamp range, after bias */
331 union pipe_color_union border_color
;
336 * A view into a texture that can be bound to a color render target /
337 * depth stencil attachment point.
341 struct pipe_reference reference
;
342 struct pipe_resource
*texture
; /**< resource into which this is a view */
343 struct pipe_context
*context
; /**< context this surface belongs to */
344 enum pipe_format format
;
346 /* XXX width/height should be removed */
347 unsigned width
; /**< logical width in pixels */
348 unsigned height
; /**< logical height in pixels */
350 unsigned writable
:1; /**< writable shader resource */
355 unsigned first_layer
:16;
356 unsigned last_layer
:16;
359 unsigned first_element
;
360 unsigned last_element
;
367 * A view into a texture that can be bound to a shader stage.
369 struct pipe_sampler_view
371 struct pipe_reference reference
;
372 enum pipe_texture_target target
; /**< PIPE_TEXTURE_x */
373 enum pipe_format format
; /**< typed PIPE_FORMAT_x */
374 struct pipe_resource
*texture
; /**< texture into which this is a view */
375 struct pipe_context
*context
; /**< context this view belongs to */
378 unsigned first_layer
:16; /**< first layer to use for array textures */
379 unsigned last_layer
:16; /**< last layer to use for array textures */
380 unsigned first_level
:8; /**< first mipmap level to use */
381 unsigned last_level
:8; /**< last mipmap level to use */
384 unsigned first_element
;
385 unsigned last_element
;
388 unsigned swizzle_r
:3; /**< PIPE_SWIZZLE_x for red component */
389 unsigned swizzle_g
:3; /**< PIPE_SWIZZLE_x for green component */
390 unsigned swizzle_b
:3; /**< PIPE_SWIZZLE_x for blue component */
391 unsigned swizzle_a
:3; /**< PIPE_SWIZZLE_x for alpha component */
396 * A view into a writable buffer or texture that can be bound to a shader
399 struct pipe_image_view
401 struct pipe_reference reference
;
402 struct pipe_resource
*resource
; /**< resource into which this is a view */
403 struct pipe_context
*context
; /**< context this view belongs to */
404 enum pipe_format format
; /**< typed PIPE_FORMAT_x */
408 unsigned first_layer
:16; /**< first layer to use for array textures */
409 unsigned last_layer
:16; /**< last layer to use for array textures */
410 unsigned level
:8; /**< mipmap level to use */
413 unsigned first_element
;
414 unsigned last_element
;
421 * Subregion of 1D/2D/3D image resource.
435 * A memory object/resource such as a vertex buffer or texture.
439 struct pipe_reference reference
;
440 struct pipe_screen
*screen
; /**< screen that this texture belongs to */
441 enum pipe_texture_target target
; /**< PIPE_TEXTURE_x */
442 enum pipe_format format
; /**< PIPE_FORMAT_x */
449 unsigned last_level
:8; /**< Index of last mipmap level present/defined */
450 unsigned nr_samples
:8; /**< for multisampled surfaces, nr of samples */
451 unsigned usage
:8; /**< PIPE_USAGE_x (not a bitmask) */
453 unsigned bind
; /**< bitmask of PIPE_BIND_x */
454 unsigned flags
; /**< bitmask of PIPE_RESOURCE_FLAG_x */
459 * Transfer object. For data transfer to/from a resource.
463 struct pipe_resource
*resource
; /**< resource to transfer to/from */
464 unsigned level
; /**< texture mipmap level */
465 enum pipe_transfer_usage usage
;
466 struct pipe_box box
; /**< region of the resource to access */
467 unsigned stride
; /**< row stride in bytes */
468 unsigned layer_stride
; /**< image/layer stride in bytes */
474 * A vertex buffer. Typically, all the vertex data/attributes for
475 * drawing something will be in one buffer. But it's also possible, for
476 * example, to put colors in one buffer and texcoords in another.
478 struct pipe_vertex_buffer
480 unsigned stride
; /**< stride to same attrib in next vertex, in bytes */
481 unsigned buffer_offset
; /**< offset to start of data in buffer, in bytes */
482 struct pipe_resource
*buffer
; /**< the actual buffer */
483 const void *user_buffer
; /**< pointer to a user buffer if buffer == NULL */
488 * A constant buffer. A subrange of an existing buffer can be set
489 * as a constant buffer.
491 struct pipe_constant_buffer
493 struct pipe_resource
*buffer
; /**< the actual buffer */
494 unsigned buffer_offset
; /**< offset to start of data in buffer, in bytes */
495 unsigned buffer_size
; /**< how much data can be read in shader */
496 const void *user_buffer
; /**< pointer to a user buffer if buffer == NULL */
501 * An untyped shader buffer supporting loads, stores, and atomics.
503 struct pipe_shader_buffer
{
504 struct pipe_resource
*buffer
; /**< the actual buffer */
505 unsigned buffer_offset
; /**< offset to start of data in buffer, in bytes */
506 unsigned buffer_size
; /**< how much data can be read in shader */
511 * A stream output target. The structure specifies the range vertices can
514 * In addition to that, the structure should internally maintain the offset
515 * into the buffer, which should be incremented everytime something is written
516 * (appended) to it. The internal offset is buffer_offset + how many bytes
517 * have been written. The internal offset can be stored on the device
518 * and the CPU actually doesn't have to query it.
520 * Note that the buffer_size variable is actually specifying the available
521 * space in the buffer, not the size of the attached buffer.
522 * In other words in majority of cases buffer_size would simply be
523 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
524 * of the buffer left, after accounting for buffer offset, for stream output
527 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
528 * actually been written.
530 struct pipe_stream_output_target
532 struct pipe_reference reference
;
533 struct pipe_resource
*buffer
; /**< the output buffer */
534 struct pipe_context
*context
; /**< context this SO target belongs to */
536 unsigned buffer_offset
; /**< offset where data should be written, in bytes */
537 unsigned buffer_size
; /**< how much data is allowed to be written */
542 * Information to describe a vertex attribute (position, color, etc)
544 struct pipe_vertex_element
546 /** Offset of this attribute, in bytes, from the start of the vertex */
549 /** Instance data rate divisor. 0 means this is per-vertex data,
550 * n means per-instance data used for n consecutive instances (n > 0).
552 unsigned instance_divisor
;
554 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
555 * this attribute live in?
557 unsigned vertex_buffer_index
;
559 enum pipe_format src_format
;
564 * An index buffer. When an index buffer is bound, all indices to vertices
565 * will be looked up in the buffer.
567 struct pipe_index_buffer
569 unsigned index_size
; /**< size of an index, in bytes */
570 unsigned offset
; /**< offset to start of data in buffer, in bytes */
571 struct pipe_resource
*buffer
; /**< the actual buffer */
572 const void *user_buffer
; /**< pointer to a user buffer if buffer == NULL */
577 * Information to describe a draw_vbo call.
579 struct pipe_draw_info
581 boolean indexed
; /**< use index buffer */
583 unsigned mode
; /**< the mode of the primitive */
584 unsigned start
; /**< the index of the first vertex */
585 unsigned count
; /**< number of vertices */
587 unsigned start_instance
; /**< first instance id */
588 unsigned instance_count
; /**< number of instances */
590 unsigned drawid
; /**< id of this draw in a multidraw */
592 unsigned vertices_per_patch
; /**< the number of vertices per patch */
595 * For indexed drawing, these fields apply after index lookup.
597 int index_bias
; /**< a bias to be added to each index */
598 unsigned min_index
; /**< the min index */
599 unsigned max_index
; /**< the max index */
602 * Primitive restart enable/index (only applies to indexed drawing)
604 boolean primitive_restart
;
605 unsigned restart_index
;
608 * Stream output target. If not NULL, it's used to provide the 'count'
609 * parameter based on the number vertices captured by the stream output
610 * stage. (or generally, based on the number of bytes captured)
612 * Only 'mode', 'start_instance', and 'instance_count' are taken into
613 * account, all the other variables from pipe_draw_info are ignored.
615 * 'start' is implicitly 0 and 'count' is set as discussed above.
616 * The draw command is non-indexed.
618 * Note that this only provides the count. The vertex buffers must
619 * be set via set_vertex_buffers manually.
621 struct pipe_stream_output_target
*count_from_stream_output
;
623 /* Indirect draw parameters resource: If not NULL, most values are taken
624 * from this buffer instead, which is laid out as follows:
626 * if indexed is TRUE:
629 * uint32_t instance_count;
631 * int32_t index_bias;
632 * uint32_t start_instance;
637 * uint32_t instance_count;
639 * uint32_t start_instance;
642 struct pipe_resource
*indirect
;
643 unsigned indirect_offset
; /**< must be 4 byte aligned */
644 unsigned indirect_stride
; /**< must be 4 byte aligned */
645 unsigned indirect_count
; /**< number of indirect draws */
647 /* Indirect draw count resource: If not NULL, contains a 32-bit value which
648 * is to be used as the real indirect_count. In that case indirect_count
649 * becomes the maximum possible value.
651 struct pipe_resource
*indirect_params
;
652 unsigned indirect_params_offset
; /**< must be 4 byte aligned */
657 * Information to describe a blit call.
659 struct pipe_blit_info
662 struct pipe_resource
*resource
;
664 struct pipe_box box
; /**< negative width, height only legal for src */
665 /* For pipe_surface-like format casting: */
666 enum pipe_format format
; /**< must be supported for sampling (src)
667 or rendering (dst), ZS is always supported */
670 unsigned mask
; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
671 unsigned filter
; /**< PIPE_TEX_FILTER_* */
673 boolean scissor_enable
;
674 struct pipe_scissor_state scissor
;
676 boolean render_condition_enable
; /**< whether the blit should honor the
677 current render condition */
678 boolean alpha_blend
; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
683 * Structure used as a header for serialized LLVM programs.
685 struct pipe_llvm_program_header
687 uint32_t num_bytes
; /**< Number of bytes in the LLVM bytecode program. */
690 struct pipe_compute_state
692 const void *prog
; /**< Compute program to be executed. */
693 unsigned req_local_mem
; /**< Required size of the LOCAL resource. */
694 unsigned req_private_mem
; /**< Required size of the PRIVATE resource. */
695 unsigned req_input_mem
; /**< Required size of the INPUT resource. */
699 * Structure that contains a callback for debug messages from the driver back
700 * to the state tracker.
702 struct pipe_debug_callback
705 * Callback for the driver to report debug/performance/etc information back
706 * to the state tracker.
708 * \param data user-supplied data pointer
709 * \param id message type identifier, if pointed value is 0, then a
711 * \param type PIPE_DEBUG_TYPE_*
712 * \param format printf-style format string
713 * \param args args for format string
715 void (*debug_message
)(void *data
,
717 enum pipe_debug_type type
,