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