3a91ddd71b5b7c6a0d6415166512ee791e452ab0
[mesa.git] / src / gallium / include / pipe / p_state.h
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 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.
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 * 3. enum bitfields need to be at least one bit extra in size so the most
38 * significant bit is zero. MSVC treats enums as signed so if the high
39 * bit is set, the value will be interpreted as a negative number.
40 * That causes trouble in various places.
41 */
42
43
44 #ifndef PIPE_STATE_H
45 #define PIPE_STATE_H
46
47 #include "p_compiler.h"
48 #include "p_defines.h"
49 #include "p_format.h"
50
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56
57 /**
58 * Implementation limits
59 */
60 #define PIPE_MAX_ATTRIBS 32
61 #define PIPE_MAX_CLIP_PLANES 8
62 #define PIPE_MAX_COLOR_BUFS 8
63 #define PIPE_MAX_CONSTANT_BUFFERS 32
64 #define PIPE_MAX_SAMPLERS 32
65 #define PIPE_MAX_SHADER_INPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
66 #define PIPE_MAX_SHADER_OUTPUTS 80 /* 32 GENERIC + 32 PATCH + 16 others */
67 #define PIPE_MAX_SHADER_SAMPLER_VIEWS 128
68 #define PIPE_MAX_SHADER_BUFFERS 32
69 #define PIPE_MAX_SHADER_IMAGES 32
70 #define PIPE_MAX_TEXTURE_LEVELS 16
71 #define PIPE_MAX_SO_BUFFERS 4
72 #define PIPE_MAX_SO_OUTPUTS 64
73 #define PIPE_MAX_VIEWPORTS 16
74 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
75 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
76 #define PIPE_MAX_WINDOW_RECTANGLES 8
77 #define PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE 4
78
79 #define PIPE_MAX_HW_ATOMIC_BUFFERS 32
80
81 struct pipe_reference
82 {
83 int32_t count; /* atomic */
84 };
85
86
87
88 /**
89 * Primitive (point/line/tri) rasterization info
90 */
91 struct pipe_rasterizer_state
92 {
93 unsigned flatshade:1;
94 unsigned light_twoside:1;
95 unsigned clamp_vertex_color:1;
96 unsigned clamp_fragment_color:1;
97 unsigned front_ccw:1;
98 unsigned cull_face:2; /**< PIPE_FACE_x */
99 unsigned fill_front:2; /**< PIPE_POLYGON_MODE_x */
100 unsigned fill_back:2; /**< PIPE_POLYGON_MODE_x */
101 unsigned offset_point:1;
102 unsigned offset_line:1;
103 unsigned offset_tri:1;
104 unsigned scissor:1;
105 unsigned poly_smooth:1;
106 unsigned poly_stipple_enable:1;
107 unsigned point_smooth:1;
108 unsigned sprite_coord_mode:1; /**< PIPE_SPRITE_COORD_ */
109 unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
110 unsigned point_tri_clip:1; /** large points clipped as tris or points */
111 unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
112 unsigned multisample:1; /* XXX maybe more ms state in future */
113 unsigned force_persample_interp:1;
114 unsigned line_smooth:1;
115 unsigned line_stipple_enable:1;
116 unsigned line_last_pixel:1;
117 unsigned conservative_raster_mode:2; /**< PIPE_CONSERVATIVE_RASTER_x */
118
119 /**
120 * Use the first vertex of a primitive as the provoking vertex for
121 * flat shading.
122 */
123 unsigned flatshade_first:1;
124
125 unsigned half_pixel_center:1;
126 unsigned bottom_edge_rule:1;
127
128 /*
129 * Conservative rasterization subpixel precision bias in bits
130 */
131 unsigned subpixel_precision_x:4;
132 unsigned subpixel_precision_y:4;
133
134 /**
135 * When true, rasterization is disabled and no pixels are written.
136 * This only makes sense with the Stream Out functionality.
137 */
138 unsigned rasterizer_discard:1;
139
140 /**
141 * Exposed by PIPE_CAP_TILE_RASTER_ORDER. When true,
142 * tile_raster_order_increasing_* indicate the order that the rasterizer
143 * should render tiles, to meet the requirements of
144 * GL_MESA_tile_raster_order.
145 */
146 unsigned tile_raster_order_fixed:1;
147 unsigned tile_raster_order_increasing_x:1;
148 unsigned tile_raster_order_increasing_y:1;
149
150 /**
151 * When false, depth clipping is disabled and the depth value will be
152 * clamped later at the per-pixel level before depth testing.
153 * This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
154 *
155 * If PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE is unsupported, depth_clip_near
156 * is equal to depth_clip_far.
157 */
158 unsigned depth_clip_near:1;
159 unsigned depth_clip_far:1;
160
161 /**
162 * When true clip space in the z axis goes from [0..1] (D3D). When false
163 * [-1, 1] (GL).
164 *
165 * NOTE: D3D will always use depth clamping.
166 */
167 unsigned clip_halfz:1;
168
169 /**
170 * When true do not scale offset_units and use same rules for unorm and
171 * float depth buffers (D3D9). When false use GL/D3D1X behaviour.
172 * This depends on PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED.
173 */
174 unsigned offset_units_unscaled:1;
175
176 /**
177 * Enable bits for clipping half-spaces.
178 * This applies to both user clip planes and shader clip distances.
179 * Note that if the bound shader exports any clip distances, these
180 * replace all user clip planes, and clip half-spaces enabled here
181 * but not written by the shader count as disabled.
182 */
183 unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES;
184
185 unsigned line_stipple_factor:8; /**< [1..256] actually */
186 unsigned line_stipple_pattern:16;
187
188 /**
189 * Replace the given TEXCOORD inputs with point coordinates, max. 8 inputs.
190 * If TEXCOORD (including PCOORD) are unsupported, replace GENERIC inputs
191 * instead. Max. 9 inputs: 8x GENERIC to emulate TEXCOORD, and 1x GENERIC
192 * to emulate PCOORD.
193 */
194 uint16_t sprite_coord_enable; /* 0-7: TEXCOORD/GENERIC, 8: PCOORD */
195
196 float line_width;
197 float point_size; /**< used when no per-vertex size */
198 float offset_units;
199 float offset_scale;
200 float offset_clamp;
201 float conservative_raster_dilate;
202 };
203
204
205 struct pipe_poly_stipple
206 {
207 unsigned stipple[32];
208 };
209
210
211 struct pipe_viewport_state
212 {
213 float scale[3];
214 float translate[3];
215 };
216
217
218 struct pipe_scissor_state
219 {
220 unsigned minx:16;
221 unsigned miny:16;
222 unsigned maxx:16;
223 unsigned maxy:16;
224 };
225
226
227 struct pipe_clip_state
228 {
229 float ucp[PIPE_MAX_CLIP_PLANES][4];
230 };
231
232 /**
233 * A single output for vertex transform feedback.
234 */
235 struct pipe_stream_output
236 {
237 unsigned register_index:6; /**< 0 to 63 (OUT index) */
238 unsigned start_component:2; /** 0 to 3 */
239 unsigned num_components:3; /** 1 to 4 */
240 unsigned output_buffer:3; /**< 0 to PIPE_MAX_SO_BUFFERS */
241 unsigned dst_offset:16; /**< offset into the buffer in dwords */
242 unsigned stream:2; /**< 0 to 3 */
243 };
244
245 /**
246 * Stream output for vertex transform feedback.
247 */
248 struct pipe_stream_output_info
249 {
250 unsigned num_outputs;
251 /** stride for an entire vertex for each buffer in dwords */
252 uint16_t stride[PIPE_MAX_SO_BUFFERS];
253
254 /**
255 * Array of stream outputs, in the order they are to be written in.
256 * Selected components are tightly packed into the output buffer.
257 */
258 struct pipe_stream_output output[PIPE_MAX_SO_OUTPUTS];
259 };
260
261 /**
262 * The 'type' parameter identifies whether the shader state contains TGSI
263 * tokens, etc. If the driver returns 'PIPE_SHADER_IR_TGSI' for the
264 * 'PIPE_SHADER_CAP_PREFERRED_IR' shader param, the ir will *always* be
265 * 'PIPE_SHADER_IR_TGSI' and the tokens ptr will be valid. If the driver
266 * requests a different 'pipe_shader_ir' type, then it must check the 'type'
267 * enum to see if it is getting TGSI tokens or its preferred IR.
268 *
269 * TODO pipe_compute_state should probably get similar treatment to handle
270 * multiple IR's in a cleaner way..
271 *
272 * NOTE: since it is expected that the consumer will want to perform
273 * additional passes on the nir_shader, the driver takes ownership of
274 * the nir_shader. If state trackers need to hang on to the IR (for
275 * example, variant management), it should use nir_shader_clone().
276 */
277 struct pipe_shader_state
278 {
279 enum pipe_shader_ir type;
280 /* TODO move tokens into union. */
281 const struct tgsi_token *tokens;
282 union {
283 void *native;
284 void *nir;
285 } ir;
286 struct pipe_stream_output_info stream_output;
287 };
288
289 static inline void
290 pipe_shader_state_from_tgsi(struct pipe_shader_state *state,
291 const struct tgsi_token *tokens)
292 {
293 state->type = PIPE_SHADER_IR_TGSI;
294 state->tokens = tokens;
295 memset(&state->stream_output, 0, sizeof(state->stream_output));
296 }
297
298 struct pipe_depth_state
299 {
300 unsigned enabled:1; /**< depth test enabled? */
301 unsigned writemask:1; /**< allow depth buffer writes? */
302 unsigned func:3; /**< depth test func (PIPE_FUNC_x) */
303 unsigned bounds_test:1; /**< depth bounds test enabled? */
304 float bounds_min; /**< minimum depth bound */
305 float bounds_max; /**< maximum depth bound */
306 };
307
308
309 struct pipe_stencil_state
310 {
311 unsigned enabled:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
312 unsigned func:3; /**< PIPE_FUNC_x */
313 unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */
314 unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
315 unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
316 unsigned valuemask:8;
317 unsigned writemask:8;
318 };
319
320
321 struct pipe_alpha_state
322 {
323 unsigned enabled:1;
324 unsigned func:3; /**< PIPE_FUNC_x */
325 float ref_value; /**< reference value */
326 };
327
328
329 struct pipe_depth_stencil_alpha_state
330 {
331 struct pipe_depth_state depth;
332 struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
333 struct pipe_alpha_state alpha;
334 };
335
336
337 struct pipe_rt_blend_state
338 {
339 unsigned blend_enable:1;
340
341 unsigned rgb_func:3; /**< PIPE_BLEND_x */
342 unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
343 unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
344
345 unsigned alpha_func:3; /**< PIPE_BLEND_x */
346 unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
347 unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
348
349 unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */
350 };
351
352
353 struct pipe_blend_state
354 {
355 unsigned independent_blend_enable:1;
356 unsigned logicop_enable:1;
357 unsigned logicop_func:4; /**< PIPE_LOGICOP_x */
358 unsigned dither:1;
359 unsigned alpha_to_coverage:1;
360 unsigned alpha_to_one:1;
361 struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
362 };
363
364
365 struct pipe_blend_color
366 {
367 float color[4];
368 };
369
370
371 struct pipe_stencil_ref
372 {
373 ubyte ref_value[2];
374 };
375
376
377 /**
378 * Note that pipe_surfaces are "texture views for rendering"
379 * and so in the case of ARB_framebuffer_no_attachment there
380 * is no pipe_surface state available such that we may
381 * extract the number of samples and layers.
382 */
383 struct pipe_framebuffer_state
384 {
385 uint16_t width, height;
386 uint16_t layers; /**< Number of layers in a no-attachment framebuffer */
387 ubyte samples; /**< Number of samples in a no-attachment framebuffer */
388
389 /** multiple color buffers for multiple render targets */
390 ubyte nr_cbufs;
391 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
392
393 struct pipe_surface *zsbuf; /**< Z/stencil buffer */
394 };
395
396
397 /**
398 * Texture sampler state.
399 */
400 struct pipe_sampler_state
401 {
402 unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
403 unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
404 unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
405 unsigned min_img_filter:1; /**< PIPE_TEX_FILTER_x */
406 unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */
407 unsigned mag_img_filter:1; /**< PIPE_TEX_FILTER_x */
408 unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
409 unsigned compare_func:3; /**< PIPE_FUNC_x */
410 unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
411 unsigned max_anisotropy:5;
412 unsigned seamless_cube_map:1;
413 float lod_bias; /**< LOD/lambda bias */
414 float min_lod, max_lod; /**< LOD clamp range, after bias */
415 union pipe_color_union border_color;
416 };
417
418 union pipe_surface_desc {
419 struct {
420 unsigned level;
421 unsigned first_layer:16;
422 unsigned last_layer:16;
423 } tex;
424 struct {
425 unsigned first_element;
426 unsigned last_element;
427 } buf;
428 };
429
430 /**
431 * A view into a texture that can be bound to a color render target /
432 * depth stencil attachment point.
433 */
434 struct pipe_surface
435 {
436 struct pipe_reference reference;
437 enum pipe_format format:16;
438 unsigned writable:1; /**< writable shader resource */
439 struct pipe_resource *texture; /**< resource into which this is a view */
440 struct pipe_context *context; /**< context this surface belongs to */
441
442 /* XXX width/height should be removed */
443 uint16_t width; /**< logical width in pixels */
444 uint16_t height; /**< logical height in pixels */
445
446 /**
447 * Number of samples for the surface. This will be 0 if rendering
448 * should use the resource's nr_samples, or another value if the resource
449 * is bound using FramebufferTexture2DMultisampleEXT.
450 */
451 unsigned nr_samples:8;
452
453 union pipe_surface_desc u;
454 };
455
456
457 /**
458 * A view into a texture that can be bound to a shader stage.
459 */
460 struct pipe_sampler_view
461 {
462 struct pipe_reference reference;
463 enum pipe_format format:15; /**< typed PIPE_FORMAT_x */
464 enum pipe_texture_target target:5; /**< PIPE_TEXTURE_x */
465 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */
466 unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */
467 unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */
468 unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */
469 struct pipe_resource *texture; /**< texture into which this is a view */
470 struct pipe_context *context; /**< context this view belongs to */
471 union {
472 struct {
473 unsigned first_layer:16; /**< first layer to use for array textures */
474 unsigned last_layer:16; /**< last layer to use for array textures */
475 unsigned first_level:8; /**< first mipmap level to use */
476 unsigned last_level:8; /**< last mipmap level to use */
477 } tex;
478 struct {
479 unsigned offset; /**< offset in bytes */
480 unsigned size; /**< size of the readable sub-range in bytes */
481 } buf;
482 } u;
483 };
484
485
486 /**
487 * A description of a buffer or texture image that can be bound to a shader
488 * stage.
489 */
490 struct pipe_image_view
491 {
492 struct pipe_resource *resource; /**< resource into which this is a view */
493 enum pipe_format format; /**< typed PIPE_FORMAT_x */
494 uint16_t access; /**< PIPE_IMAGE_ACCESS_x */
495 uint16_t shader_access; /**< PIPE_IMAGE_ACCESS_x */
496
497 union {
498 struct {
499 unsigned first_layer:16; /**< first layer to use for array textures */
500 unsigned last_layer:16; /**< last layer to use for array textures */
501 unsigned level:8; /**< mipmap level to use */
502 } tex;
503 struct {
504 unsigned offset; /**< offset in bytes */
505 unsigned size; /**< size of the accessible sub-range in bytes */
506 } buf;
507 } u;
508 };
509
510
511 /**
512 * Subregion of 1D/2D/3D image resource.
513 */
514 struct pipe_box
515 {
516 /* Fields only used by textures use int16_t instead of int.
517 * x and width are used by buffers, so they need the full 32-bit range.
518 */
519 int x;
520 int16_t y;
521 int16_t z;
522 int width;
523 int16_t height;
524 int16_t depth;
525 };
526
527
528 /**
529 * A memory object/resource such as a vertex buffer or texture.
530 */
531 struct pipe_resource
532 {
533 struct pipe_reference reference;
534
535 unsigned width0; /**< Used by both buffers and textures. */
536 uint16_t height0; /* Textures: The maximum height/depth/array_size is 16k. */
537 uint16_t depth0;
538 uint16_t array_size;
539
540 enum pipe_format format:16; /**< PIPE_FORMAT_x */
541 enum pipe_texture_target target:8; /**< PIPE_TEXTURE_x */
542 unsigned last_level:8; /**< Index of last mipmap level present/defined */
543
544 /** Number of samples determining quality, driving rasterizer, shading,
545 * and framebuffer.
546 */
547 unsigned nr_samples:8;
548
549 /** Multiple samples within a pixel can have the same value.
550 * nr_storage_samples determines how many slots for different values
551 * there are per pixel. Only color buffers can set this lower than
552 * nr_samples.
553 */
554 unsigned nr_storage_samples:8;
555
556 unsigned usage:8; /**< PIPE_USAGE_x (not a bitmask) */
557 unsigned bind; /**< bitmask of PIPE_BIND_x */
558 unsigned flags; /**< bitmask of PIPE_RESOURCE_FLAG_x */
559
560 /**
561 * For planar images, ie. YUV EGLImage external, etc, pointer to the
562 * next plane.
563 */
564 struct pipe_resource *next;
565 /* The screen pointer should be last for optimal structure packing. */
566 struct pipe_screen *screen; /**< screen that this texture belongs to */
567 };
568
569
570 /**
571 * Transfer object. For data transfer to/from a resource.
572 */
573 struct pipe_transfer
574 {
575 struct pipe_resource *resource; /**< resource to transfer to/from */
576 unsigned level; /**< texture mipmap level */
577 enum pipe_transfer_usage usage;
578 struct pipe_box box; /**< region of the resource to access */
579 unsigned stride; /**< row stride in bytes */
580 unsigned layer_stride; /**< image/layer stride in bytes */
581 };
582
583
584 /**
585 * A vertex buffer. Typically, all the vertex data/attributes for
586 * drawing something will be in one buffer. But it's also possible, for
587 * example, to put colors in one buffer and texcoords in another.
588 */
589 struct pipe_vertex_buffer
590 {
591 uint16_t stride; /**< stride to same attrib in next vertex, in bytes */
592 bool is_user_buffer;
593 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
594
595 union {
596 struct pipe_resource *resource; /**< the actual buffer */
597 const void *user; /**< pointer to a user buffer */
598 } buffer;
599 };
600
601
602 /**
603 * A constant buffer. A subrange of an existing buffer can be set
604 * as a constant buffer.
605 */
606 struct pipe_constant_buffer
607 {
608 struct pipe_resource *buffer; /**< the actual buffer */
609 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
610 unsigned buffer_size; /**< how much data can be read in shader */
611 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
612 };
613
614
615 /**
616 * An untyped shader buffer supporting loads, stores, and atomics.
617 */
618 struct pipe_shader_buffer {
619 struct pipe_resource *buffer; /**< the actual buffer */
620 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
621 unsigned buffer_size; /**< how much data can be read in shader */
622 };
623
624
625 /**
626 * A stream output target. The structure specifies the range vertices can
627 * be written to.
628 *
629 * In addition to that, the structure should internally maintain the offset
630 * into the buffer, which should be incremented everytime something is written
631 * (appended) to it. The internal offset is buffer_offset + how many bytes
632 * have been written. The internal offset can be stored on the device
633 * and the CPU actually doesn't have to query it.
634 *
635 * Note that the buffer_size variable is actually specifying the available
636 * space in the buffer, not the size of the attached buffer.
637 * In other words in majority of cases buffer_size would simply be
638 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
639 * of the buffer left, after accounting for buffer offset, for stream output
640 * to write to.
641 *
642 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
643 * actually been written.
644 */
645 struct pipe_stream_output_target
646 {
647 struct pipe_reference reference;
648 struct pipe_resource *buffer; /**< the output buffer */
649 struct pipe_context *context; /**< context this SO target belongs to */
650
651 unsigned buffer_offset; /**< offset where data should be written, in bytes */
652 unsigned buffer_size; /**< how much data is allowed to be written */
653 };
654
655
656 /**
657 * Information to describe a vertex attribute (position, color, etc)
658 */
659 struct pipe_vertex_element
660 {
661 /** Offset of this attribute, in bytes, from the start of the vertex */
662 unsigned src_offset:16;
663
664 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
665 * this attribute live in?
666 */
667 unsigned vertex_buffer_index:5;
668
669 enum pipe_format src_format:11;
670
671 /** Instance data rate divisor. 0 means this is per-vertex data,
672 * n means per-instance data used for n consecutive instances (n > 0).
673 */
674 unsigned instance_divisor;
675 };
676
677
678 struct pipe_draw_indirect_info
679 {
680 unsigned offset; /**< must be 4 byte aligned */
681 unsigned stride; /**< must be 4 byte aligned */
682 unsigned draw_count; /**< number of indirect draws */
683 unsigned indirect_draw_count_offset; /**< must be 4 byte aligned */
684
685 /* Indirect draw parameters resource is laid out as follows:
686 *
687 * if using indexed drawing:
688 * struct {
689 * uint32_t count;
690 * uint32_t instance_count;
691 * uint32_t start;
692 * int32_t index_bias;
693 * uint32_t start_instance;
694 * };
695 * otherwise:
696 * struct {
697 * uint32_t count;
698 * uint32_t instance_count;
699 * uint32_t start;
700 * uint32_t start_instance;
701 * };
702 */
703 struct pipe_resource *buffer;
704
705 /* Indirect draw count resource: If not NULL, contains a 32-bit value which
706 * is to be used as the real draw_count.
707 */
708 struct pipe_resource *indirect_draw_count;
709 };
710
711
712 /**
713 * Information to describe a draw_vbo call.
714 */
715 struct pipe_draw_info
716 {
717 ubyte index_size; /**< if 0, the draw is not indexed. */
718 enum pipe_prim_type mode:8; /**< the mode of the primitive */
719 unsigned primitive_restart:1;
720 unsigned has_user_indices:1; /**< if true, use index.user_buffer */
721 ubyte vertices_per_patch; /**< the number of vertices per patch */
722
723 /**
724 * Direct draws: start is the index of the first vertex
725 * Non-indexed indirect draws: not used
726 * Indexed indirect draws: start is added to the indirect start.
727 */
728 unsigned start;
729 unsigned count; /**< number of vertices */
730
731 unsigned start_instance; /**< first instance id */
732 unsigned instance_count; /**< number of instances */
733
734 unsigned drawid; /**< id of this draw in a multidraw */
735
736 /**
737 * For indexed drawing, these fields apply after index lookup.
738 */
739 int index_bias; /**< a bias to be added to each index */
740 unsigned min_index; /**< the min index */
741 unsigned max_index; /**< the max index */
742
743 /**
744 * Primitive restart enable/index (only applies to indexed drawing)
745 */
746 unsigned restart_index;
747
748 /* Pointers must be at the end for an optimal structure layout on 64-bit. */
749
750 /**
751 * An index buffer. When an index buffer is bound, all indices to vertices
752 * will be looked up from the buffer.
753 *
754 * If has_user_indices, use index.user, else use index.resource.
755 */
756 union {
757 struct pipe_resource *resource; /**< real buffer */
758 const void *user; /**< pointer to a user buffer */
759 } index;
760
761 struct pipe_draw_indirect_info *indirect; /**< Indirect draw. */
762
763 /**
764 * Stream output target. If not NULL, it's used to provide the 'count'
765 * parameter based on the number vertices captured by the stream output
766 * stage. (or generally, based on the number of bytes captured)
767 *
768 * Only 'mode', 'start_instance', and 'instance_count' are taken into
769 * account, all the other variables from pipe_draw_info are ignored.
770 *
771 * 'start' is implicitly 0 and 'count' is set as discussed above.
772 * The draw command is non-indexed.
773 *
774 * Note that this only provides the count. The vertex buffers must
775 * be set via set_vertex_buffers manually.
776 */
777 struct pipe_stream_output_target *count_from_stream_output;
778 };
779
780
781 /**
782 * Information to describe a blit call.
783 */
784 struct pipe_blit_info
785 {
786 struct {
787 struct pipe_resource *resource;
788 unsigned level;
789 struct pipe_box box; /**< negative width, height only legal for src */
790 /* For pipe_surface-like format casting: */
791 enum pipe_format format; /**< must be supported for sampling (src)
792 or rendering (dst), ZS is always supported */
793 } dst, src;
794
795 unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
796 unsigned filter; /**< PIPE_TEX_FILTER_* */
797
798 boolean scissor_enable;
799 struct pipe_scissor_state scissor;
800
801 /* Window rectangles can either be inclusive or exclusive. */
802 boolean window_rectangle_include;
803 unsigned num_window_rectangles;
804 struct pipe_scissor_state window_rectangles[PIPE_MAX_WINDOW_RECTANGLES];
805
806 boolean render_condition_enable; /**< whether the blit should honor the
807 current render condition */
808 boolean alpha_blend; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
809 };
810
811 /**
812 * Information to describe a launch_grid call.
813 */
814 struct pipe_grid_info
815 {
816 /**
817 * For drivers that use PIPE_SHADER_IR_NATIVE as their prefered IR, this
818 * value will be the index of the kernel in the opencl.kernels metadata
819 * list.
820 */
821 uint32_t pc;
822
823 /**
824 * Will be used to initialize the INPUT resource, and it should point to a
825 * buffer of at least pipe_compute_state::req_input_mem bytes.
826 */
827 void *input;
828
829 /**
830 * Grid number of dimensions, 1-3, e.g. the work_dim parameter passed to
831 * clEnqueueNDRangeKernel. Note block[] and grid[] must be padded with
832 * 1 for non-used dimensions.
833 */
834 uint work_dim;
835
836 /**
837 * Determine the layout of the working block (in thread units) to be used.
838 */
839 uint block[3];
840
841 /**
842 * last_block allows disabling threads at the farthermost grid boundary.
843 * Full blocks as specified by "block" are launched, but the threads
844 * outside of "last_block" dimensions are disabled.
845 *
846 * If a block touches the grid boundary in the i-th axis, threads with
847 * THREAD_ID[i] >= last_block[i] are disabled.
848 *
849 * If last_block[i] is 0, it has the same behavior as last_block[i] = block[i],
850 * meaning no effect.
851 *
852 * It's equivalent to doing this at the beginning of the compute shader:
853 *
854 * for (i = 0; i < 3; i++) {
855 * if (block_id[i] == grid[i] - 1 &&
856 * last_block[i] && thread_id[i] >= last_block[i])
857 * return;
858 * }
859 */
860 uint last_block[3];
861
862 /**
863 * Determine the layout of the grid (in block units) to be used.
864 */
865 uint grid[3];
866
867 /* Indirect compute parameters resource: If not NULL, block sizes are taken
868 * from this buffer instead, which is laid out as follows:
869 *
870 * struct {
871 * uint32_t num_blocks_x;
872 * uint32_t num_blocks_y;
873 * uint32_t num_blocks_z;
874 * };
875 */
876 struct pipe_resource *indirect;
877 unsigned indirect_offset; /**< must be 4 byte aligned */
878 };
879
880 /**
881 * Structure used as a header for serialized LLVM programs.
882 */
883 struct pipe_llvm_program_header
884 {
885 uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
886 };
887
888 struct pipe_compute_state
889 {
890 enum pipe_shader_ir ir_type; /**< IR type contained in prog. */
891 const void *prog; /**< Compute program to be executed. */
892 unsigned req_local_mem; /**< Required size of the LOCAL resource. */
893 unsigned req_private_mem; /**< Required size of the PRIVATE resource. */
894 unsigned req_input_mem; /**< Required size of the INPUT resource. */
895 };
896
897 /**
898 * Structure that contains a callback for debug messages from the driver back
899 * to the state tracker.
900 */
901 struct pipe_debug_callback
902 {
903 /**
904 * When set to \c true, the callback may be called asynchronously from a
905 * driver-created thread.
906 */
907 bool async;
908
909 /**
910 * Callback for the driver to report debug/performance/etc information back
911 * to the state tracker.
912 *
913 * \param data user-supplied data pointer
914 * \param id message type identifier, if pointed value is 0, then a
915 * new id is assigned
916 * \param type PIPE_DEBUG_TYPE_*
917 * \param format printf-style format string
918 * \param args args for format string
919 */
920 void (*debug_message)(void *data,
921 unsigned *id,
922 enum pipe_debug_type type,
923 const char *fmt,
924 va_list args);
925 void *data;
926 };
927
928 /**
929 * Structure that contains a callback for device reset messages from the driver
930 * back to the state tracker.
931 *
932 * The callback must not be called from driver-created threads.
933 */
934 struct pipe_device_reset_callback
935 {
936 /**
937 * Callback for the driver to report when a device reset is detected.
938 *
939 * \param data user-supplied data pointer
940 * \param status PIPE_*_RESET
941 */
942 void (*reset)(void *data, enum pipe_reset_status status);
943
944 void *data;
945 };
946
947 /**
948 * Information about memory usage. All sizes are in kilobytes.
949 */
950 struct pipe_memory_info
951 {
952 unsigned total_device_memory; /**< size of device memory, e.g. VRAM */
953 unsigned avail_device_memory; /**< free device memory at the moment */
954 unsigned total_staging_memory; /**< size of staging memory, e.g. GART */
955 unsigned avail_staging_memory; /**< free staging memory at the moment */
956 unsigned device_memory_evicted; /**< size of memory evicted (monotonic counter) */
957 unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
958 };
959
960 /**
961 * Structure that contains information about external memory
962 */
963 struct pipe_memory_object
964 {
965 bool dedicated;
966 };
967
968 #ifdef __cplusplus
969 }
970 #endif
971
972 #endif