• 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 "util/u_memory.h"
48 
49 #include "util/compiler.h"
50 #include "p_defines.h"
51 #include "util/format/u_formats.h"
52 #include "util/box.h"
53 
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 struct nir_shader;
60 
61 /**
62  * Implementation limits
63  */
64 #define PIPE_MAX_ATTRIBS          32
65 #define PIPE_MAX_CLIP_PLANES       8
66 #define PIPE_MAX_COLOR_BUFS        8
67 #define PIPE_MAX_CONSTANT_BUFFERS 32
68 #define PIPE_MAX_SAMPLERS         32
69 #define PIPE_MAX_SHADER_INPUTS    80 /* 32 GENERIC + 32 PATCH + 16 others */
70 #define PIPE_MAX_SHADER_OUTPUTS   80 /* 32 GENERIC + 32 PATCH + 16 others */
71 #define PIPE_MAX_SHADER_SAMPLER_VIEWS 128
72 #define PIPE_MAX_SHADER_BUFFERS   32
73 #define PIPE_MAX_SHADER_IMAGES    64
74 #define PIPE_MAX_TEXTURE_LEVELS   16
75 #define PIPE_MAX_SO_BUFFERS        4
76 #define PIPE_MAX_SO_OUTPUTS       128
77 #define PIPE_MAX_VIEWPORTS        16
78 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
79 #define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
80 #define PIPE_MAX_WINDOW_RECTANGLES 8
81 #define PIPE_MAX_SAMPLE_LOCATION_GRID_SIZE 4
82 
83 #define PIPE_MAX_HW_ATOMIC_BUFFERS 32
84 #define PIPE_MAX_VERTEX_STREAMS   4
85 
86 struct pipe_reference
87 {
88    int32_t count; /* atomic */
89 };
90 
91 
92 
93 /**
94  * Primitive (point/line/tri) rasterization info
95  */
96 struct pipe_rasterizer_state
97 {
98    unsigned flatshade:1;
99    unsigned light_twoside:1;
100    unsigned clamp_vertex_color:1;
101    unsigned clamp_fragment_color:1;
102    unsigned front_ccw:1;
103    unsigned cull_face:2;      /**< PIPE_FACE_x */
104    unsigned fill_front:2;     /**< PIPE_POLYGON_MODE_x */
105    unsigned fill_back:2;      /**< PIPE_POLYGON_MODE_x */
106    unsigned offset_point:1;
107    unsigned offset_line:1;
108    unsigned offset_tri:1;
109    unsigned scissor:1;
110    unsigned poly_smooth:1;
111    unsigned poly_stipple_enable:1;
112    unsigned point_smooth:1;
113    unsigned sprite_coord_mode:1;     /**< PIPE_SPRITE_COORD_ */
114    unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
115    unsigned point_line_tri_clip:1; /** large points/lines clipped as tris or points/lines */
116    unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
117    unsigned multisample:1;         /* XXX maybe more ms state in future */
118    unsigned no_ms_sample_mask_out:1;
119    unsigned force_persample_interp:1;
120    unsigned line_smooth:1;
121    unsigned line_stipple_enable:1;
122    unsigned line_last_pixel:1;
123    unsigned line_rectangular:1; /** lines rasterized as rectangles or parallelograms */
124    unsigned conservative_raster_mode:2; /**< PIPE_CONSERVATIVE_RASTER_x */
125 
126    /**
127     * Use the first vertex of a primitive as the provoking vertex for
128     * flat shading.
129     */
130    unsigned flatshade_first:1;
131 
132    unsigned half_pixel_center:1;
133    unsigned bottom_edge_rule:1;
134 
135    /*
136     * Conservative rasterization subpixel precision bias in bits
137     */
138    unsigned subpixel_precision_x:4;
139    unsigned subpixel_precision_y:4;
140 
141    /**
142     * When true, rasterization is disabled and no pixels are written.
143     * This only makes sense with the Stream Out functionality.
144     */
145    unsigned rasterizer_discard:1;
146 
147    /**
148     * Exposed by pipe_caps.tile_raster_order.  When true,
149     * tile_raster_order_increasing_* indicate the order that the rasterizer
150     * should render tiles, to meet the requirements of
151     * GL_MESA_tile_raster_order.
152     */
153    unsigned tile_raster_order_fixed:1;
154    unsigned tile_raster_order_increasing_x:1;
155    unsigned tile_raster_order_increasing_y:1;
156 
157    /**
158     * When false, depth clipping is disabled and the depth value will be
159     * clamped later at the per-pixel level before depth testing.
160     * This depends on pipe_caps.depth_clip_disable.
161     *
162     * If pipe_caps.depth_clip_disable_separate is unsupported, depth_clip_near
163     * is equal to depth_clip_far.
164     */
165    unsigned depth_clip_near:1;
166    unsigned depth_clip_far:1;
167 
168    /**
169     * When true, depth clamp is enabled.
170     * If pipe_caps.depth_clamp_enable is unsupported, this is always the inverse
171     * of depth_clip_far.
172     */
173    unsigned depth_clamp:1;
174 
175    /**
176     * When true clip space in the z axis goes from [0..1] (D3D).  When false
177     * [-1, 1] (GL).
178     *
179     * NOTE: D3D will always use depth clamping.
180     */
181    unsigned clip_halfz:1;
182 
183    /**
184     * When true do not scale offset_units and use same rules for unorm and
185     * float depth buffers (D3D9). When false use GL/D3D1X behaviour.
186     * This depends on pipe_caps.polygon_offset_units_unscaled.
187     */
188    unsigned offset_units_unscaled:1;
189 
190    /**
191     * Depth values output from fragment shader may be outside 0..1.
192     * These have to be clamped for use with UNORM buffers.
193     * Vulkan can allow this with an extension,
194     * GL could with NV_depth_buffer_float, but GLES doesn't.
195     */
196    unsigned unclamped_fragment_depth_values:1;
197 
198    /**
199     * Enable bits for clipping half-spaces.
200     * This applies to both user clip planes and shader clip distances.
201     * Note that if the bound shader exports any clip distances, these
202     * replace all user clip planes, and clip half-spaces enabled here
203     * but not written by the shader count as disabled.
204     */
205    unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES;
206 
207    unsigned line_stipple_factor:8;  /**< [1..256] actually */
208    unsigned line_stipple_pattern:16;
209 
210    /**
211     * Replace the given TEXCOORD inputs with point coordinates, max. 8 inputs.
212     * If TEXCOORD (including PCOORD) are unsupported, replace GENERIC inputs
213     * instead. Max. 9 inputs: 8x GENERIC to emulate TEXCOORD, and 1x GENERIC
214     * to emulate PCOORD.
215     */
216    uint16_t sprite_coord_enable; /* 0-7: TEXCOORD/GENERIC, 8: PCOORD */
217 
218    float line_width;
219    float point_size;           /**< used when no per-vertex size */
220    float offset_units;
221    float offset_scale;
222    float offset_clamp;
223    float conservative_raster_dilate;
224 };
225 
226 
227 struct pipe_poly_stipple
228 {
229    unsigned stipple[32];
230 };
231 
232 
233 struct pipe_viewport_state
234 {
235    float scale[3];
236    float translate[3];
237    enum pipe_viewport_swizzle swizzle_x:8;
238    enum pipe_viewport_swizzle swizzle_y:8;
239    enum pipe_viewport_swizzle swizzle_z:8;
240    enum pipe_viewport_swizzle swizzle_w:8;
241 };
242 
243 
244 struct pipe_scissor_state
245 {
246    unsigned minx:16;
247    unsigned miny:16;
248    unsigned maxx:16;
249    unsigned maxy:16;
250 };
251 
252 
253 struct pipe_clip_state
254 {
255    float ucp[PIPE_MAX_CLIP_PLANES][4];
256 };
257 
258 /**
259  * A single output for vertex transform feedback.
260  */
261 struct pipe_stream_output
262 {
263    unsigned register_index:6;  /**< 0 to 63 (OUT index) */
264    unsigned start_component:2; /** 0 to 3 */
265    unsigned num_components:3;  /** 1 to 4 */
266    unsigned output_buffer:3;   /**< 0 to PIPE_MAX_SO_BUFFERS */
267    unsigned dst_offset:16;     /**< offset into the buffer in dwords */
268    unsigned stream:2;          /**< 0 to 3 */
269 };
270 
271 /**
272  * Stream output for vertex transform feedback.
273  */
274 struct pipe_stream_output_info
275 {
276    unsigned num_outputs;
277    /** stride for an entire vertex for each buffer in dwords */
278    uint16_t stride[PIPE_MAX_SO_BUFFERS];
279 
280    /**
281     * Array of stream outputs, in the order they are to be written in.
282     * Selected components are tightly packed into the output buffer.
283     */
284    struct pipe_stream_output output[PIPE_MAX_SO_OUTPUTS];
285 };
286 
287 /**
288  * The 'type' parameter identifies whether the shader state contains NIR, TGSI
289  * tokens, etc.
290  *
291  * TODO pipe_compute_state should probably get similar treatment to handle
292  * multiple IR's in a cleaner way..
293  *
294  * NOTE: since it is expected that the consumer will want to perform
295  * additional passes on the nir_shader, the driver takes ownership of
296  * the nir_shader.  If gallium frontends need to hang on to the IR (for
297  * example, variant management), it should use nir_shader_clone().
298  */
299 struct pipe_shader_state
300 {
301    enum pipe_shader_ir type;
302    /* TODO move tokens into union. */
303    const struct tgsi_token *tokens;
304    union {
305       void *native;
306       struct nir_shader *nir;
307    } ir;
308    struct pipe_stream_output_info stream_output;
309 
310    /* If the caller sets report_compile_error=true, the driver can fail
311     * compilation and should allocate a string with the error message and
312     * store it in the pointer below. The caller is responsible for reading
313     * and freeing the error message.
314     */
315    bool report_compile_error;
316    char *error_message;
317 };
318 
319 static inline void
pipe_shader_state_from_tgsi(struct pipe_shader_state * state,const struct tgsi_token * tokens)320 pipe_shader_state_from_tgsi(struct pipe_shader_state *state,
321                             const struct tgsi_token *tokens)
322 {
323    state->type = PIPE_SHADER_IR_TGSI;
324    state->tokens = tokens;
325    memset(&state->stream_output, 0, sizeof(state->stream_output));
326 }
327 
328 struct pipe_stencil_state
329 {
330    unsigned enabled:1;  /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
331    unsigned func:3;     /**< PIPE_FUNC_x */
332    unsigned fail_op:3;  /**< PIPE_STENCIL_OP_x */
333    unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
334    unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
335    unsigned valuemask:8;
336    unsigned writemask:8;
337 };
338 
339 
340 struct pipe_depth_stencil_alpha_state
341 {
342    struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
343 
344    unsigned alpha_enabled:1;         /**< alpha test enabled? */
345    unsigned alpha_func:3;            /**< PIPE_FUNC_x */
346 
347    unsigned depth_enabled:1;         /**< depth test enabled? */
348    unsigned depth_writemask:1;       /**< allow depth buffer writes? */
349    unsigned depth_func:3;            /**< depth test func (PIPE_FUNC_x) */
350    unsigned depth_bounds_test:1;     /**< depth bounds test enabled? */
351 
352    float alpha_ref_value;            /**< reference value */
353    double depth_bounds_min;          /**< minimum depth bound */
354    double depth_bounds_max;          /**< maximum depth bound */
355 };
356 
357 
358 struct pipe_rt_blend_state
359 {
360    unsigned blend_enable:1;
361 
362    unsigned rgb_func:3;          /**< PIPE_BLEND_x */
363    unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */
364    unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */
365 
366    unsigned alpha_func:3;        /**< PIPE_BLEND_x */
367    unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */
368    unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */
369 
370    unsigned colormask:4;         /**< bitmask of PIPE_MASK_R/G/B/A */
371 };
372 
373 
374 struct pipe_blend_state
375 {
376    unsigned independent_blend_enable:1;
377    unsigned logicop_enable:1;
378    unsigned logicop_func:4;      /**< PIPE_LOGICOP_x */
379    unsigned dither:1;
380    unsigned alpha_to_coverage:1;
381    unsigned alpha_to_coverage_dither:1;
382    unsigned alpha_to_one:1;
383    unsigned max_rt:3;            /* index of max rt, Ie. # of cbufs minus 1 */
384    unsigned advanced_blend_func:4;
385    unsigned blend_coherent:1;
386    struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
387 };
388 
389 
390 struct pipe_blend_color
391 {
392    float color[4];
393 };
394 
395 
396 struct pipe_stencil_ref
397 {
398    uint8_t ref_value[2];
399 };
400 
401 
402 /**
403  * Note that pipe_surfaces are "texture views for rendering"
404  * and so in the case of ARB_framebuffer_no_attachment there
405  * is no pipe_surface state available such that we may
406  * extract the number of samples and layers.
407  */
408 struct pipe_framebuffer_state
409 {
410    uint16_t width, height;
411    uint16_t layers;  /**< Number of layers  in a no-attachment framebuffer */
412    uint8_t samples; /**< Number of samples in a no-attachment framebuffer */
413 
414    /** multiple color buffers for multiple render targets */
415    uint8_t nr_cbufs;
416    /** used for multiview */
417    uint8_t viewmask;
418    struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
419 
420    struct pipe_surface *zsbuf;      /**< Z/stencil buffer */
421 
422    struct pipe_resource *resolve;
423 };
424 
425 
426 /**
427  * Texture sampler state.
428  */
429 struct pipe_sampler_state
430 {
431    unsigned wrap_s:3;            /**< PIPE_TEX_WRAP_x */
432    unsigned wrap_t:3;            /**< PIPE_TEX_WRAP_x */
433    unsigned wrap_r:3;            /**< PIPE_TEX_WRAP_x */
434    unsigned min_img_filter:1;    /**< PIPE_TEX_FILTER_x */
435    unsigned min_mip_filter:2;    /**< PIPE_TEX_MIPFILTER_x */
436    unsigned mag_img_filter:1;    /**< PIPE_TEX_FILTER_x */
437    unsigned compare_mode:1;      /**< PIPE_TEX_COMPARE_x */
438    unsigned compare_func:3;      /**< PIPE_FUNC_x */
439    unsigned unnormalized_coords:1; /**< Are coords normalized to [0,1]? */
440    unsigned max_anisotropy:5;
441    unsigned seamless_cube_map:1;
442    unsigned border_color_is_integer:1;
443    unsigned reduction_mode:2;    /**< PIPE_TEX_REDUCTION_x */
444    unsigned pad:5;               /**< take bits from this for new members */
445    float lod_bias;               /**< LOD/lambda bias */
446    float min_lod, max_lod;       /**< LOD clamp range, after bias */
447    union pipe_color_union border_color;
448    enum pipe_format border_color_format;      /**< only with PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO, must be last */
449 };
450 
451 union pipe_surface_desc {
452    struct {
453       unsigned level;
454       unsigned first_layer:16;
455       unsigned last_layer:16;
456    } tex;
457    struct {
458       unsigned first_element;
459       unsigned last_element;
460    } buf;
461 };
462 
463 /**
464  * A view into a texture that can be bound to a color render target /
465  * depth stencil attachment point.
466  */
467 struct pipe_surface
468 {
469    struct pipe_reference reference;
470    enum pipe_format format:16;
471    unsigned writable:1;          /**< writable shader resource */
472    struct pipe_resource *texture; /**< resource into which this is a view  */
473    struct pipe_context *context; /**< context this surface belongs to */
474 
475    /* XXX width/height should be removed */
476    uint16_t width;               /**< logical width in pixels */
477    uint16_t height;              /**< logical height in pixels */
478 
479    /**
480     * Number of samples for the surface.  This will be 0 if rendering
481     * should use the resource's nr_samples, or another value if the resource
482     * is bound using FramebufferTexture2DMultisampleEXT.
483     */
484    unsigned nr_samples:8;
485 
486    union pipe_surface_desc u;
487 };
488 
489 
490 /**
491  * A view into a texture that can be bound to a shader stage.
492  */
493 struct pipe_sampler_view
494 {
495    /* Put the refcount on its own cache line to prevent "False sharing". */
496    EXCLUSIVE_CACHELINE(struct pipe_reference reference);
497 
498    enum pipe_format format:12;      /**< typed PIPE_FORMAT_x */
499    unsigned astc_decode_format:2;   /**< intermediate format used for ASTC textures */
500    bool is_tex2d_from_buf:1;       /**< true if union is tex2d_from_buf */
501    enum pipe_texture_target target:5; /**< PIPE_TEXTURE_x */
502    unsigned swizzle_r:3;         /**< PIPE_SWIZZLE_x for red component */
503    unsigned swizzle_g:3;         /**< PIPE_SWIZZLE_x for green component */
504    unsigned swizzle_b:3;         /**< PIPE_SWIZZLE_x for blue component */
505    unsigned swizzle_a:3;         /**< PIPE_SWIZZLE_x for alpha component */
506    struct pipe_resource *texture; /**< texture into which this is a view  */
507    struct pipe_context *context; /**< context this view belongs to */
508    union {
509       struct {
510          unsigned first_layer:16;  /**< first layer to use for array textures */
511          unsigned last_layer:16;   /**< last layer to use for array textures */
512          unsigned first_level:8;   /**< first mipmap level to use */
513          unsigned last_level:8;    /**< last mipmap level to use */
514       } tex;
515       struct {
516          unsigned offset;   /**< offset in bytes */
517          unsigned size;     /**< size of the readable sub-range in bytes */
518       } buf;
519       struct {
520          unsigned offset;  /**< offset in pixels */
521          uint16_t row_stride; /**< size of the image row_stride in pixels */
522          uint16_t width;      /**< width of image provided by application */
523          uint16_t height;     /**< height of image provided by application */
524       } tex2d_from_buf;      /**< used in cl extension cl_khr_image2d_from_buffer */
525    } u;
526 };
527 
528 
529 /**
530  * A description of a buffer or texture image that can be bound to a shader
531  * stage.
532  *
533  * Note that pipe_image_view::access comes from the frontend API, while
534  * shader_access comes from the shader and may contain additional information
535  * (ie. coherent/volatile may be set on shader_access but not on access)
536  */
537 struct pipe_image_view
538 {
539    struct pipe_resource *resource; /**< resource into which this is a view  */
540    enum pipe_format format;      /**< typed PIPE_FORMAT_x */
541    uint16_t access;              /**< PIPE_IMAGE_ACCESS_x */
542    uint16_t shader_access;       /**< PIPE_IMAGE_ACCESS_x */
543    union {
544       struct {
545          unsigned first_layer:16;     /**< first layer to use for array textures */
546          unsigned last_layer:16;      /**< last layer to use for array textures */
547          unsigned level:8;            /**< mipmap level to use */
548          bool single_layer_view;      /**< single layer view of array */
549          bool is_2d_view_of_3d;
550       } tex;
551       struct {
552          unsigned offset;   /**< offset in bytes */
553          unsigned size;     /**< size of the accessible sub-range in bytes */
554       } buf;
555       struct {
556          unsigned offset;   /**< offset in pixels */
557          uint16_t row_stride;     /**< size of the image row_stride in pixels */
558          uint16_t width;     /**< width of image provided by application */
559          uint16_t height;     /**< height of image provided by application */
560       } tex2d_from_buf;      /**< used in cl extension cl_khr_image2d_from_buffer */
561    } u;
562 };
563 
564 
565 /**
566  * A memory object/resource such as a vertex buffer or texture.
567  */
568 struct pipe_resource
569 {
570    /* Put the refcount on its own cache line to prevent "False sharing". */
571    EXCLUSIVE_CACHELINE(struct pipe_reference reference);
572 
573    uint32_t width0; /**< Used by both buffers and textures. */
574    uint16_t height0; /* Textures: The maximum height/depth/array_size is 16k. */
575    uint16_t depth0;
576    uint16_t array_size;
577 
578    enum pipe_format format:16;         /**< PIPE_FORMAT_x */
579    enum pipe_texture_target target:8; /**< PIPE_TEXTURE_x */
580    uint8_t last_level;    /**< Index of last mipmap level present/defined */
581 
582    /** Number of samples determining quality, driving rasterizer, shading,
583     *  and framebuffer.
584     */
585    uint8_t nr_samples;
586 
587    /** Multiple samples within a pixel can have the same value.
588     *  nr_storage_samples determines how many slots for different values
589     *  there are per pixel. Only color buffers can set this lower than
590     *  nr_samples.
591     */
592    uint8_t nr_storage_samples;
593 
594    uint8_t nr_sparse_levels; /**< Mipmap levels support partial resident */
595 
596    unsigned compression_rate:4; /**< Fixed-rate compresion bitrate if any */
597 
598    enum pipe_resource_usage usage:4;
599    uint32_t bind;            /**< bitmask of PIPE_BIND_x */
600    uint32_t flags;           /**< bitmask of PIPE_RESOURCE_FLAG_x */
601 
602    /**
603     * For planar images, ie. YUV EGLImage external, etc, pointer to the
604     * next plane.
605     */
606    struct pipe_resource *next;
607    /* The screen pointer should be last for optimal structure packing.
608     * This pointer cannot be casted directly to a driver's screen. Use
609     * screen::get_driver_pipe_screen instead if it's non-NULL.
610     */
611    struct pipe_screen *screen; /**< screen that this texture belongs to */
612 };
613 
614 /**
615  * Opaque object used for separate resource/memory allocations.
616  */
617 struct pipe_memory_allocation;
618 
619 /**
620  * Transfer object.  For data transfer to/from a resource.
621  */
622 struct pipe_transfer
623 {
624    struct pipe_resource *resource; /**< resource to transfer to/from  */
625    enum pipe_map_flags usage:24;
626    unsigned level:8;               /**< texture mipmap level */
627    struct pipe_box box;            /**< region of the resource to access */
628    unsigned stride;                /**< row stride in bytes */
629    uintptr_t layer_stride;          /**< image/layer stride in bytes */
630 
631    /* Offset into a driver-internal staging buffer to make use of unused
632     * padding in this structure.
633     */
634    unsigned offset;
635 };
636 
637 
638 /**
639  * A vertex buffer.  Typically, all the vertex data/attributes for
640  * drawing something will be in one buffer.  But it's also possible, for
641  * example, to put colors in one buffer and texcoords in another.
642  */
643 struct pipe_vertex_buffer
644 {
645    bool is_user_buffer;
646    unsigned buffer_offset;  /**< offset to start of data in buffer, in bytes */
647 
648    union {
649       struct pipe_resource *resource;  /**< the actual buffer */
650       const void *user;  /**< pointer to a user buffer */
651    } buffer;
652 };
653 
654 
655 /**
656  * A constant buffer.  A subrange of an existing buffer can be set
657  * as a constant buffer.
658  */
659 struct pipe_constant_buffer
660 {
661    struct pipe_resource *buffer; /**< the actual buffer */
662    unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
663    unsigned buffer_size;   /**< how much data can be read in shader */
664    const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
665 };
666 
667 
668 /**
669  * An untyped shader buffer supporting loads, stores, and atomics.
670  */
671 struct pipe_shader_buffer {
672    struct pipe_resource *buffer; /**< the actual buffer */
673    unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
674    unsigned buffer_size;   /**< how much data can be read in shader */
675 };
676 
677 
678 /**
679  * A stream output target. The structure specifies the range vertices can
680  * be written to.
681  *
682  * In addition to that, the structure should internally maintain the offset
683  * into the buffer, which should be incremented everytime something is written
684  * (appended) to it. The internal offset is buffer_offset + how many bytes
685  * have been written. The internal offset can be stored on the device
686  * and the CPU actually doesn't have to query it.
687  *
688  * Note that the buffer_size variable is actually specifying the available
689  * space in the buffer, not the size of the attached buffer.
690  * In other words in majority of cases buffer_size would simply be
691  * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
692  * of the buffer left, after accounting for buffer offset, for stream output
693  * to write to.
694  *
695  * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
696  * actually been written.
697  */
698 struct pipe_stream_output_target
699 {
700    struct pipe_reference reference;
701    struct pipe_resource *buffer; /**< the output buffer */
702    struct pipe_context *context; /**< context this SO target belongs to */
703 
704    unsigned buffer_offset;  /**< offset where data should be written, in bytes */
705    unsigned buffer_size;    /**< how much data is allowed to be written */
706 };
707 
708 
709 /**
710  * Information to describe a vertex attribute (position, color, etc)
711  */
712 struct pipe_vertex_element
713 {
714    /** Offset of this attribute, in bytes, from the start of the vertex */
715    uint16_t src_offset;
716 
717    /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
718     * this attribute live in?
719     */
720    uint8_t vertex_buffer_index:7;
721 
722    /**
723     * Whether this element refers to a dual-slot vertex shader input.
724     * The purpose of this field is to do dual-slot lowering when the CSO is
725     * created instead of during every state change.
726     *
727     * It's lowered by util_lower_uint64_vertex_elements.
728     */
729    bool dual_slot:1;
730 
731    /**
732     * This has only 8 bits because all vertex formats should be <= 255.
733     */
734    uint8_t src_format; /* low 8 bits of enum pipe_format. */
735 
736    /**< stride to same attrib in next vertex, in bytes */
737    uint32_t src_stride; /* technically only uint16_t, expanded for struct padding */
738 
739    /** Instance data rate divisor. 0 means this is per-vertex data,
740     *  n means per-instance data used for n consecutive instances (n > 0).
741     */
742    unsigned instance_divisor;
743 };
744 
745 /**
746  * Opaque refcounted constant state object encapsulating a vertex buffer,
747  * index buffer, and vertex elements. Used by display lists to bind those
748  * states and pass buffer references quickly.
749  *
750  * The state contains 1 index buffer, 0 or 1 vertex buffer, and 0 or more
751  * vertex elements.
752  *
753  * Constraints on the buffers to get the fastest codepath:
754  * - All buffer contents are considered immutable and read-only after
755  *   initialization. This implies the following things.
756  * - No place is required to track whether these buffers are busy.
757  * - All CPU mappings of these buffers can be forced to UNSYNCHRONIZED by
758  *   both drivers and common code unconditionally.
759  * - Buffer invalidation can be skipped by both drivers and common code
760  *   unconditionally.
761  */
762 struct pipe_vertex_state {
763    struct pipe_reference reference;
764    struct pipe_screen *screen;
765 
766    /* The following structure is used as a key for util_vertex_state_cache
767     * to deduplicate identical state objects and thus enable more
768     * opportunities for draw merging.
769     */
770    struct {
771       struct pipe_resource *indexbuf;
772       struct pipe_vertex_buffer vbuffer;
773       unsigned num_elements;
774       struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
775       uint32_t full_velem_mask;
776    } input;
777 };
778 
779 struct pipe_draw_indirect_info
780 {
781    unsigned offset; /**< must be 4 byte aligned */
782    unsigned stride; /**< must be 4 byte aligned */
783    unsigned draw_count; /**< number of indirect draws */
784    unsigned indirect_draw_count_offset; /**< must be 4 byte aligned */
785 
786    /* Indirect draw parameters resource is laid out as follows:
787     *
788     * if using indexed drawing:
789     *  struct {
790     *     uint32_t count;
791     *     uint32_t instance_count;
792     *     uint32_t start;
793     *     int32_t index_bias;
794     *     uint32_t start_instance;
795     *  };
796     * otherwise:
797     *  struct {
798     *     uint32_t count;
799     *     uint32_t instance_count;
800     *     uint32_t start;
801     *     uint32_t start_instance;
802     *  };
803     *
804     * If NULL, count_from_stream_output != NULL.
805     */
806    struct pipe_resource *buffer;
807 
808    /* Indirect draw count resource: If not NULL, contains a 32-bit value which
809     * is to be used as the real draw_count.
810     */
811    struct pipe_resource *indirect_draw_count;
812 
813    /**
814     * Stream output target. If not NULL, it's used to provide the 'count'
815     * parameter based on the number vertices captured by the stream output
816     * stage. (or generally, based on the number of bytes captured)
817     *
818     * Only 'mode', 'start_instance', and 'instance_count' are taken into
819     * account, all the other variables from pipe_draw_info are ignored.
820     *
821     * 'start' is implicitly 0 and 'count' is set as discussed above.
822     * The draw command is non-indexed.
823     *
824     * Note that this only provides the count. The vertex buffers must
825     * be set via set_vertex_buffers manually.
826     */
827    struct pipe_stream_output_target *count_from_stream_output;
828 };
829 
830 struct pipe_draw_start_count_bias {
831    unsigned start;
832    unsigned count;
833    int index_bias; /**< a bias to be added to each index */
834 };
835 
836 /**
837  * Draw vertex state description. It's translated to pipe_draw_info as follows:
838  * - mode comes from this structure
839  * - index_size is 4
840  * - instance_count is 1
841  * - index.resource comes from pipe_vertex_state
842  * - everything else is 0
843  */
844 struct pipe_draw_vertex_state_info {
845 #if defined(__GNUC__)
846    /* sizeof(mode) == 1 because it's a packed enum. */
847    enum mesa_prim mode;  /**< the mode of the primitive */
848 #else
849    /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
850    uint8_t mode;              /**< the mode of the primitive */
851 #endif
852    bool take_vertex_state_ownership; /**< for skipping reference counting */
853 };
854 
855 /**
856  * Information to describe a draw_vbo call.
857  */
858 struct pipe_draw_info
859 {
860 #if defined(__GNUC__)
861    /* sizeof(mode) == 1 because it's a packed enum. */
862    enum mesa_prim mode;  /**< the mode of the primitive */
863 #else
864    /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
865    uint8_t mode;              /**< the mode of the primitive */
866 #endif
867    uint16_t index_size;        /**< if 0, the draw is not indexed. */
868    bool primitive_restart:1;
869    bool has_user_indices:1;   /**< if true, use index.user_buffer */
870    bool index_bounds_valid:1; /**< whether min_index and max_index are valid;
871                                    they're always invalid if index_size == 0 */
872    bool increment_draw_id:1;  /**< whether drawid increments for direct draws */
873    bool take_index_buffer_ownership:1; /**< callee inherits caller's refcount
874          (no need to reference indexbuf, but still needs to unreference it) */
875    bool index_bias_varies:1;   /**< true if index_bias varies between draws */
876    bool was_line_loop:1; /**< true if mesa_prim was LINE_LOOP before translation */
877    uint8_t _pad:1;
878 
879    unsigned start_instance; /**< first instance id */
880    unsigned instance_count; /**< number of instances */
881 
882    /**
883     * Primitive restart enable/index (only applies to indexed drawing)
884     */
885    unsigned restart_index;
886 
887    /* Pointers must be placed appropriately for optimal structure packing on
888     * 64-bit CPUs.
889     */
890 
891    /**
892     * An index buffer.  When an index buffer is bound, all indices to vertices
893     * will be looked up from the buffer.
894     *
895     * If has_user_indices, use index.user, else use index.resource.
896     */
897    union {
898       struct pipe_resource *resource;  /**< real buffer */
899       const void *user;  /**< pointer to a user buffer */
900    } index;
901 
902    /* These must be last for better packing in u_threaded_context. */
903    unsigned min_index; /**< the min index */
904    unsigned max_index; /**< the max index */
905 };
906 
907 
908 /**
909  * Information to describe a blit call.
910  */
911 struct pipe_blit_info
912 {
913    struct {
914       struct pipe_resource *resource;
915       unsigned level;
916       struct pipe_box box; /**< negative width, height only legal for src */
917       /* For pipe_surface-like format casting: */
918       enum pipe_format format; /**< must be supported for sampling (src)
919                                or rendering (dst), ZS is always supported */
920    } dst, src;
921 
922    unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
923    unsigned filter; /**< PIPE_TEX_FILTER_* */
924    uint8_t dst_sample; /**< if non-zero, set sample_mask to (1 << (dst_sample - 1)) */
925    bool sample0_only;
926    bool scissor_enable;
927    struct pipe_scissor_state scissor;
928 
929    /* Swizzling during a blit typically forces a slower
930       path, so it should be used only when necessary. It's
931       there mainly to support blitting between different formats
932       when one of them has been emulated (e.g. GL_ALPHA emulated
933       by GL_RGBA) */
934    bool swizzle_enable; /**< swizzle is only applied if this is set */
935    uint8_t swizzle[4];  /**< map to be applied while blitting */
936 
937    /* Window rectangles can either be inclusive or exclusive. */
938    bool window_rectangle_include;
939    unsigned num_window_rectangles;
940    struct pipe_scissor_state window_rectangles[PIPE_MAX_WINDOW_RECTANGLES];
941 
942    bool render_condition_enable; /**< whether the blit should honor the
943                                  current render condition */
944    bool alpha_blend; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
945 };
946 
947 /**
948  * Information to describe a launch_grid call.
949  */
950 struct pipe_grid_info
951 {
952    /**
953     * For drivers that use PIPE_SHADER_IR_NATIVE as their prefered IR, this
954     * value will be the index of the kernel in the opencl.kernels metadata
955     * list.
956     */
957    uint32_t pc;
958 
959    /**
960     * Will be used to initialize the INPUT resource, and it should point to a
961     * buffer of at least pipe_compute_state::req_input_mem bytes.
962     */
963    const void *input;
964 
965    /**
966     * Variable shared memory used by this invocation.
967     *
968     * This comes on top of shader declared shared memory.
969     */
970    uint32_t variable_shared_mem;
971 
972    /**
973     * Grid number of dimensions, 1-3, e.g. the work_dim parameter passed to
974     * clEnqueueNDRangeKernel. Note block[] and grid[] must be padded with
975     * 1 for non-used dimensions.
976     */
977    uint work_dim;
978 
979    /**
980     * Determine the layout of the working block (in thread units) to be used.
981     */
982    uint block[3];
983 
984    /**
985     * last_block allows disabling threads at the farthermost grid boundary.
986     * Full blocks as specified by "block" are launched, but the threads
987     * outside of "last_block" dimensions are disabled.
988     *
989     * If a block touches the grid boundary in the i-th axis, threads with
990     * THREAD_ID[i] >= last_block[i] are disabled.
991     *
992     * If last_block[i] is 0, it has the same behavior as last_block[i] = block[i],
993     * meaning no effect.
994     *
995     * It's equivalent to doing this at the beginning of the compute shader:
996     *
997     *   for (i = 0; i < 3; i++) {
998     *      if (block_id[i] == grid[i] - 1 &&
999     *          last_block[i] && thread_id[i] >= last_block[i])
1000     *         return;
1001     *   }
1002     */
1003    uint last_block[3];
1004 
1005    /**
1006     * Determine the layout of the grid (in block units) to be used.
1007     */
1008    uint grid[3];
1009 
1010    /**
1011     * Base offsets to launch grids from
1012     */
1013    uint grid_base[3];
1014 
1015    /* Indirect compute parameters resource: If not NULL, block sizes are taken
1016     * from this buffer instead, which is laid out as follows:
1017     *
1018     *  struct {
1019     *     uint32_t num_blocks_x;
1020     *     uint32_t num_blocks_y;
1021     *     uint32_t num_blocks_z;
1022     *  };
1023     */
1024    struct pipe_resource *indirect;
1025    unsigned indirect_offset; /**< must be 4 byte aligned */
1026    unsigned indirect_stride;
1027    /* draw related members are for task/mesh shaders */
1028    unsigned draw_count;
1029    unsigned indirect_draw_count_offset;
1030    struct pipe_resource *indirect_draw_count;
1031 };
1032 
1033 /**
1034  * Encapsulates all info about a tensor. Only types supported are INT8 and UINT8.
1035  */
1036 struct pipe_tensor {
1037    /**
1038     * Memory-backing for this tensor (use pipe_buffer_*).
1039     */
1040    struct pipe_resource *resource;
1041    /**
1042     * Index of this tensor in the subgraph that contains it.
1043     */
1044    unsigned index;
1045    /**
1046     * Dimensions of this tensor.
1047     */
1048    unsigned dims[4];
1049    /**
1050     * Scale used to quantize this tensor. Only per-tensor quantization is supported.
1051     */
1052    float scale;
1053    /**
1054     * Zero-point used to quantize this tensor.
1055     */
1056    int zero_point;
1057    /**
1058     * Whether the tensor contains data in INT8 or UINT8 format.
1059     */
1060    bool is_signed;
1061 };
1062 
1063 /**
1064  * Type of a pipe_ml_operation.
1065  */
1066 enum pipe_ml_operation_type {
1067    PIPE_ML_OPERATION_TYPE_ADD,
1068    PIPE_ML_OPERATION_TYPE_CONVOLUTION,
1069    PIPE_ML_OPERATION_TYPE_POOLING,
1070    PIPE_ML_OPERATION_TYPE_CONCATENATION,
1071    PIPE_ML_OPERATION_TYPE_SPLIT,
1072    PIPE_ML_OPERATION_TYPE_PAD,
1073    PIPE_ML_OPERATION_TYPE_FULLY_CONNECTED,
1074 };
1075 
1076 /**
1077  * Information about a single operation inside a ML subgraph.
1078  */
1079 struct pipe_ml_operation
1080 {
1081    /**
1082     * Type of operation.
1083     */
1084    enum pipe_ml_operation_type type;
1085 
1086    /**
1087     * Tensor used as input.
1088     */
1089    struct pipe_tensor **input_tensors;
1090    unsigned input_count;
1091 
1092    /**
1093     * Tensor used as output.
1094     */
1095    struct pipe_tensor **output_tensors;
1096    unsigned output_count;
1097 
1098    union {
1099       struct {
1100          /**
1101           * For convolutions, tensor containing the weights.
1102           */
1103          struct pipe_tensor *weight_tensor;
1104 
1105          /**
1106           * For convolutions, tensor containing the biases.
1107           */
1108          struct pipe_tensor *bias_tensor;
1109 
1110          /**
1111           * Stride used to access the input tensor on the x axis.
1112           */
1113          unsigned stride_x;
1114 
1115          /**
1116           * Stride used to access the input tensor on the x axis.
1117           */
1118          unsigned stride_y;
1119 
1120          /**
1121           * Whether to use padding of type same when accessing the input tensor.
1122           */
1123          bool padding_same;
1124 
1125          /**
1126           * Whether this is a pointwise (1x1 kernels) convolution.
1127           */
1128          bool pointwise;
1129 
1130          /**
1131           * Whether this is a depthwise convolution.
1132           */
1133          bool depthwise;
1134 
1135          /**
1136           * Whether this convolution has fused ReLU activation.
1137           */
1138          bool relu;
1139       } conv;
1140       struct {
1141          /**
1142           * Stride used to access the input tensor on the x axis.
1143           */
1144          unsigned stride_x;
1145 
1146          /**
1147           * Stride used to access the input tensor on the x axis.
1148           */
1149          unsigned stride_y;
1150 
1151          /**
1152           * Width of the area used for pooling.
1153           */
1154          unsigned filter_width;
1155 
1156          /**
1157           * Height of the area used for pooling.
1158           */
1159          unsigned filter_height;
1160 
1161          /**
1162           * Whether to use padding of type same when accessing the input tensor.
1163           */
1164          bool padding_same;
1165       } pooling;
1166       struct {
1167          /**
1168           * Left padding.
1169           */
1170          unsigned before_x;
1171 
1172          /**
1173           * Right padding.
1174           */
1175          unsigned after_x;
1176 
1177          /**
1178           * Top padding.
1179           */
1180          unsigned before_y;
1181          /**
1182           * Bottom padding.
1183           */
1184          unsigned after_y;
1185       } pad;
1186 
1187       struct {
1188          /**
1189           * Tensor containing the weights.
1190           */
1191          struct pipe_tensor *weight_tensor;
1192          /**
1193           * Tensor containing the biases.
1194           */
1195          struct pipe_tensor *bias_tensor;
1196 
1197          /**
1198           * Whether a ReLU activation should be applied to the output.
1199           */
1200          bool relu;
1201       } fcon;
1202    };
1203 };
1204 
1205 /**
1206  * Subgraph that drivers can subclass to keep the output of the subgraph
1207  * compilation process.
1208  */
1209 struct pipe_ml_subgraph
1210 {
1211    /**
1212     * pipe_context that owns this subgraph.
1213     */
1214    struct pipe_context *context;
1215 };
1216 
1217 /**
1218  * Structure used as a header for serialized compute programs.
1219  */
1220 struct pipe_binary_program_header
1221 {
1222    uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
1223    char blob[];
1224 };
1225 
1226 struct pipe_compute_state
1227 {
1228    enum pipe_shader_ir ir_type; /**< IR type contained in prog. */
1229    const void *prog; /**< Compute program to be executed. */
1230    unsigned static_shared_mem; /**< equal to info.shared_size, used for shaders passed as TGSI */
1231    unsigned req_input_mem; /**< Required size of the INPUT resource. */
1232 };
1233 
1234 struct pipe_compute_state_object_info
1235 {
1236    /**
1237     * Max number of threads per block supported for the given cso.
1238     */
1239    unsigned max_threads;
1240 
1241    /**
1242     * Which multiple should the block size be of for best performance.
1243     *
1244     * E.g. for 8 a block with n * 8 threads would result in optimal utilization
1245     * of the hardware.
1246     */
1247    unsigned preferred_simd_size;
1248 
1249    /**
1250     * Bitmask of supported SIMD sizes.
1251     */
1252    unsigned simd_sizes;
1253 
1254    /**
1255     * How much private memory does this CSO require per thread (a.k.a. NIR scratch memory).
1256     */
1257    unsigned private_memory;
1258 };
1259 
1260 /**
1261  * Structure that contains a callback for device reset messages from the driver
1262  * back to the gallium frontend.
1263  *
1264  * The callback must not be called from driver-created threads.
1265  */
1266 struct pipe_device_reset_callback
1267 {
1268    /**
1269     * Callback for the driver to report when a device reset is detected.
1270     *
1271     * \param data   user-supplied data pointer
1272     * \param status PIPE_*_RESET
1273     */
1274    void (*reset)(void *data, enum pipe_reset_status status);
1275 
1276    void *data;
1277 };
1278 
1279 /**
1280  * Information about memory usage. All sizes are in kilobytes.
1281  */
1282 struct pipe_memory_info
1283 {
1284    unsigned total_device_memory; /**< size of device memory, e.g. VRAM */
1285    unsigned avail_device_memory; /**< free device memory at the moment */
1286    unsigned total_staging_memory; /**< size of staging memory, e.g. GART */
1287    unsigned avail_staging_memory; /**< free staging memory at the moment */
1288    unsigned device_memory_evicted; /**< size of memory evicted (monotonic counter) */
1289    unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
1290 };
1291 
1292 /**
1293  * Structure that contains information about external memory
1294  */
1295 struct pipe_memory_object
1296 {
1297    bool dedicated;
1298 };
1299 
1300 #ifdef __cplusplus
1301 }
1302 #endif
1303 
1304 #endif
1305