• 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 
311 static inline void
pipe_shader_state_from_tgsi(struct pipe_shader_state * state,const struct tgsi_token * tokens)312 pipe_shader_state_from_tgsi(struct pipe_shader_state *state,
313                             const struct tgsi_token *tokens)
314 {
315    state->type = PIPE_SHADER_IR_TGSI;
316    state->tokens = tokens;
317    memset(&state->stream_output, 0, sizeof(state->stream_output));
318 }
319 
320 struct pipe_stencil_state
321 {
322    unsigned enabled:1;  /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
323    unsigned func:3;     /**< PIPE_FUNC_x */
324    unsigned fail_op:3;  /**< PIPE_STENCIL_OP_x */
325    unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
326    unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
327    unsigned valuemask:8;
328    unsigned writemask:8;
329 };
330 
331 
332 struct pipe_depth_stencil_alpha_state
333 {
334    struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
335 
336    unsigned alpha_enabled:1;         /**< alpha test enabled? */
337    unsigned alpha_func:3;            /**< PIPE_FUNC_x */
338 
339    unsigned depth_enabled:1;         /**< depth test enabled? */
340    unsigned depth_writemask:1;       /**< allow depth buffer writes? */
341    unsigned depth_func:3;            /**< depth test func (PIPE_FUNC_x) */
342    unsigned depth_bounds_test:1;     /**< depth bounds test enabled? */
343 
344    float alpha_ref_value;            /**< reference value */
345    double depth_bounds_min;          /**< minimum depth bound */
346    double depth_bounds_max;          /**< maximum depth bound */
347 };
348 
349 
350 struct pipe_rt_blend_state
351 {
352    unsigned blend_enable:1;
353 
354    unsigned rgb_func:3;          /**< PIPE_BLEND_x */
355    unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */
356    unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */
357 
358    unsigned alpha_func:3;        /**< PIPE_BLEND_x */
359    unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */
360    unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */
361 
362    unsigned colormask:4;         /**< bitmask of PIPE_MASK_R/G/B/A */
363 };
364 
365 
366 struct pipe_blend_state
367 {
368    unsigned independent_blend_enable:1;
369    unsigned logicop_enable:1;
370    unsigned logicop_func:4;      /**< PIPE_LOGICOP_x */
371    unsigned dither:1;
372    unsigned alpha_to_coverage:1;
373    unsigned alpha_to_coverage_dither:1;
374    unsigned alpha_to_one:1;
375    unsigned max_rt:3;            /* index of max rt, Ie. # of cbufs minus 1 */
376    unsigned advanced_blend_func:4;
377    unsigned blend_coherent:1;
378    struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
379 };
380 
381 
382 struct pipe_blend_color
383 {
384    float color[4];
385 };
386 
387 
388 struct pipe_stencil_ref
389 {
390    uint8_t ref_value[2];
391 };
392 
393 
394 /**
395  * Note that pipe_surfaces are "texture views for rendering"
396  * and so in the case of ARB_framebuffer_no_attachment there
397  * is no pipe_surface state available such that we may
398  * extract the number of samples and layers.
399  */
400 struct pipe_framebuffer_state
401 {
402    uint16_t width, height;
403    uint16_t layers;  /**< Number of layers  in a no-attachment framebuffer */
404    uint8_t samples; /**< Number of samples in a no-attachment framebuffer */
405 
406    /** multiple color buffers for multiple render targets */
407    uint8_t nr_cbufs;
408    /** used for multiview */
409    uint8_t viewmask;
410    struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
411 
412    struct pipe_surface *zsbuf;      /**< Z/stencil buffer */
413 
414    struct pipe_resource *resolve;
415 };
416 
417 
418 /**
419  * Texture sampler state.
420  */
421 struct pipe_sampler_state
422 {
423    unsigned wrap_s:3;            /**< PIPE_TEX_WRAP_x */
424    unsigned wrap_t:3;            /**< PIPE_TEX_WRAP_x */
425    unsigned wrap_r:3;            /**< PIPE_TEX_WRAP_x */
426    unsigned min_img_filter:1;    /**< PIPE_TEX_FILTER_x */
427    unsigned min_mip_filter:2;    /**< PIPE_TEX_MIPFILTER_x */
428    unsigned mag_img_filter:1;    /**< PIPE_TEX_FILTER_x */
429    unsigned compare_mode:1;      /**< PIPE_TEX_COMPARE_x */
430    unsigned compare_func:3;      /**< PIPE_FUNC_x */
431    unsigned unnormalized_coords:1; /**< Are coords normalized to [0,1]? */
432    unsigned max_anisotropy:5;
433    unsigned seamless_cube_map:1;
434    unsigned border_color_is_integer:1;
435    unsigned reduction_mode:2;    /**< PIPE_TEX_REDUCTION_x */
436    unsigned pad:5;               /**< take bits from this for new members */
437    float lod_bias;               /**< LOD/lambda bias */
438    float min_lod, max_lod;       /**< LOD clamp range, after bias */
439    union pipe_color_union border_color;
440    enum pipe_format border_color_format;      /**< only with PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO, must be last */
441 };
442 
443 union pipe_surface_desc {
444    struct {
445       unsigned level;
446       unsigned first_layer:16;
447       unsigned last_layer:16;
448    } tex;
449    struct {
450       unsigned first_element;
451       unsigned last_element;
452    } buf;
453 };
454 
455 /**
456  * A view into a texture that can be bound to a color render target /
457  * depth stencil attachment point.
458  */
459 struct pipe_surface
460 {
461    struct pipe_reference reference;
462    enum pipe_format format:16;
463    unsigned writable:1;          /**< writable shader resource */
464    struct pipe_resource *texture; /**< resource into which this is a view  */
465    struct pipe_context *context; /**< context this surface belongs to */
466 
467    /* XXX width/height should be removed */
468    uint16_t width;               /**< logical width in pixels */
469    uint16_t height;              /**< logical height in pixels */
470 
471    /**
472     * Number of samples for the surface.  This will be 0 if rendering
473     * should use the resource's nr_samples, or another value if the resource
474     * is bound using FramebufferTexture2DMultisampleEXT.
475     */
476    unsigned nr_samples:8;
477 
478    union pipe_surface_desc u;
479 };
480 
481 
482 /**
483  * A view into a texture that can be bound to a shader stage.
484  */
485 struct pipe_sampler_view
486 {
487    /* Put the refcount on its own cache line to prevent "False sharing". */
488    EXCLUSIVE_CACHELINE(struct pipe_reference reference);
489 
490    enum pipe_format format:12;      /**< typed PIPE_FORMAT_x */
491    unsigned astc_decode_format:2;   /**< intermediate format used for ASTC textures */
492    bool is_tex2d_from_buf:1;       /**< true if union is tex2d_from_buf */
493    enum pipe_texture_target target:5; /**< PIPE_TEXTURE_x */
494    unsigned swizzle_r:3;         /**< PIPE_SWIZZLE_x for red component */
495    unsigned swizzle_g:3;         /**< PIPE_SWIZZLE_x for green component */
496    unsigned swizzle_b:3;         /**< PIPE_SWIZZLE_x for blue component */
497    unsigned swizzle_a:3;         /**< PIPE_SWIZZLE_x for alpha component */
498    struct pipe_resource *texture; /**< texture into which this is a view  */
499    struct pipe_context *context; /**< context this view belongs to */
500    union {
501       struct {
502          unsigned first_layer:16;  /**< first layer to use for array textures */
503          unsigned last_layer:16;   /**< last layer to use for array textures */
504          unsigned first_level:8;   /**< first mipmap level to use */
505          unsigned last_level:8;    /**< last mipmap level to use */
506       } tex;
507       struct {
508          unsigned offset;   /**< offset in bytes */
509          unsigned size;     /**< size of the readable sub-range in bytes */
510       } buf;
511       struct {
512          unsigned offset;  /**< offset in pixels */
513          uint16_t row_stride; /**< size of the image row_stride in pixels */
514          uint16_t width;      /**< width of image provided by application */
515          uint16_t height;     /**< height of image provided by application */
516       } tex2d_from_buf;      /**< used in cl extension cl_khr_image2d_from_buffer */
517    } u;
518 };
519 
520 
521 /**
522  * A description of a buffer or texture image that can be bound to a shader
523  * stage.
524  *
525  * Note that pipe_image_view::access comes from the frontend API, while
526  * shader_access comes from the shader and may contain additional information
527  * (ie. coherent/volatile may be set on shader_access but not on access)
528  */
529 struct pipe_image_view
530 {
531    struct pipe_resource *resource; /**< resource into which this is a view  */
532    enum pipe_format format;      /**< typed PIPE_FORMAT_x */
533    uint16_t access;              /**< PIPE_IMAGE_ACCESS_x */
534    uint16_t shader_access;       /**< PIPE_IMAGE_ACCESS_x */
535    union {
536       struct {
537          unsigned first_layer:16;     /**< first layer to use for array textures */
538          unsigned last_layer:16;      /**< last layer to use for array textures */
539          unsigned level:8;            /**< mipmap level to use */
540          bool single_layer_view;      /**< single layer view of array */
541          bool is_2d_view_of_3d;
542       } tex;
543       struct {
544          unsigned offset;   /**< offset in bytes */
545          unsigned size;     /**< size of the accessible sub-range in bytes */
546       } buf;
547       struct {
548          unsigned offset;   /**< offset in pixels */
549          uint16_t row_stride;     /**< size of the image row_stride in pixels */
550          uint16_t width;     /**< width of image provided by application */
551          uint16_t height;     /**< height of image provided by application */
552       } tex2d_from_buf;      /**< used in cl extension cl_khr_image2d_from_buffer */
553    } u;
554 };
555 
556 
557 /**
558  * A memory object/resource such as a vertex buffer or texture.
559  */
560 struct pipe_resource
561 {
562    /* Put the refcount on its own cache line to prevent "False sharing". */
563    EXCLUSIVE_CACHELINE(struct pipe_reference reference);
564 
565    uint32_t width0; /**< Used by both buffers and textures. */
566    uint16_t height0; /* Textures: The maximum height/depth/array_size is 16k. */
567    uint16_t depth0;
568    uint16_t array_size;
569 
570    enum pipe_format format:16;         /**< PIPE_FORMAT_x */
571    enum pipe_texture_target target:8; /**< PIPE_TEXTURE_x */
572    uint8_t last_level;    /**< Index of last mipmap level present/defined */
573 
574    /** Number of samples determining quality, driving rasterizer, shading,
575     *  and framebuffer.
576     */
577    uint8_t nr_samples;
578 
579    /** Multiple samples within a pixel can have the same value.
580     *  nr_storage_samples determines how many slots for different values
581     *  there are per pixel. Only color buffers can set this lower than
582     *  nr_samples.
583     */
584    uint8_t nr_storage_samples;
585 
586    uint8_t nr_sparse_levels; /**< Mipmap levels support partial resident */
587 
588    unsigned compression_rate:4; /**< Fixed-rate compresion bitrate if any */
589 
590    enum pipe_resource_usage usage:4;
591    uint32_t bind;            /**< bitmask of PIPE_BIND_x */
592    uint32_t flags;           /**< bitmask of PIPE_RESOURCE_FLAG_x */
593 
594    /**
595     * For planar images, ie. YUV EGLImage external, etc, pointer to the
596     * next plane.
597     */
598    struct pipe_resource *next;
599    /* The screen pointer should be last for optimal structure packing.
600     * This pointer cannot be casted directly to a driver's screen. Use
601     * screen::get_driver_pipe_screen instead if it's non-NULL.
602     */
603    struct pipe_screen *screen; /**< screen that this texture belongs to */
604 };
605 
606 /**
607  * Opaque object used for separate resource/memory allocations.
608  */
609 struct pipe_memory_allocation;
610 
611 /**
612  * Transfer object.  For data transfer to/from a resource.
613  */
614 struct pipe_transfer
615 {
616    struct pipe_resource *resource; /**< resource to transfer to/from  */
617    enum pipe_map_flags usage:24;
618    unsigned level:8;               /**< texture mipmap level */
619    struct pipe_box box;            /**< region of the resource to access */
620    unsigned stride;                /**< row stride in bytes */
621    uintptr_t layer_stride;          /**< image/layer stride in bytes */
622 
623    /* Offset into a driver-internal staging buffer to make use of unused
624     * padding in this structure.
625     */
626    unsigned offset;
627 };
628 
629 
630 /**
631  * A vertex buffer.  Typically, all the vertex data/attributes for
632  * drawing something will be in one buffer.  But it's also possible, for
633  * example, to put colors in one buffer and texcoords in another.
634  */
635 struct pipe_vertex_buffer
636 {
637    bool is_user_buffer;
638    unsigned buffer_offset;  /**< offset to start of data in buffer, in bytes */
639 
640    union {
641       struct pipe_resource *resource;  /**< the actual buffer */
642       const void *user;  /**< pointer to a user buffer */
643    } buffer;
644 };
645 
646 
647 /**
648  * A constant buffer.  A subrange of an existing buffer can be set
649  * as a constant buffer.
650  */
651 struct pipe_constant_buffer
652 {
653    struct pipe_resource *buffer; /**< the actual buffer */
654    unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
655    unsigned buffer_size;   /**< how much data can be read in shader */
656    const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
657 };
658 
659 
660 /**
661  * An untyped shader buffer supporting loads, stores, and atomics.
662  */
663 struct pipe_shader_buffer {
664    struct pipe_resource *buffer; /**< the actual buffer */
665    unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
666    unsigned buffer_size;   /**< how much data can be read in shader */
667 };
668 
669 
670 /**
671  * A stream output target. The structure specifies the range vertices can
672  * be written to.
673  *
674  * In addition to that, the structure should internally maintain the offset
675  * into the buffer, which should be incremented everytime something is written
676  * (appended) to it. The internal offset is buffer_offset + how many bytes
677  * have been written. The internal offset can be stored on the device
678  * and the CPU actually doesn't have to query it.
679  *
680  * Note that the buffer_size variable is actually specifying the available
681  * space in the buffer, not the size of the attached buffer.
682  * In other words in majority of cases buffer_size would simply be
683  * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
684  * of the buffer left, after accounting for buffer offset, for stream output
685  * to write to.
686  *
687  * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
688  * actually been written.
689  */
690 struct pipe_stream_output_target
691 {
692    struct pipe_reference reference;
693    struct pipe_resource *buffer; /**< the output buffer */
694    struct pipe_context *context; /**< context this SO target belongs to */
695 
696    unsigned buffer_offset;  /**< offset where data should be written, in bytes */
697    unsigned buffer_size;    /**< how much data is allowed to be written */
698 };
699 
700 
701 /**
702  * Information to describe a vertex attribute (position, color, etc)
703  */
704 struct pipe_vertex_element
705 {
706    /** Offset of this attribute, in bytes, from the start of the vertex */
707    uint16_t src_offset;
708 
709    /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
710     * this attribute live in?
711     */
712    uint8_t vertex_buffer_index:7;
713 
714    /**
715     * Whether this element refers to a dual-slot vertex shader input.
716     * The purpose of this field is to do dual-slot lowering when the CSO is
717     * created instead of during every state change.
718     *
719     * It's lowered by util_lower_uint64_vertex_elements.
720     */
721    bool dual_slot:1;
722 
723    /**
724     * This has only 8 bits because all vertex formats should be <= 255.
725     */
726    uint8_t src_format; /* low 8 bits of enum pipe_format. */
727 
728    /**< stride to same attrib in next vertex, in bytes */
729    uint32_t src_stride; /* technically only uint16_t, expanded for struct padding */
730 
731    /** Instance data rate divisor. 0 means this is per-vertex data,
732     *  n means per-instance data used for n consecutive instances (n > 0).
733     */
734    unsigned instance_divisor;
735 };
736 
737 /**
738  * Opaque refcounted constant state object encapsulating a vertex buffer,
739  * index buffer, and vertex elements. Used by display lists to bind those
740  * states and pass buffer references quickly.
741  *
742  * The state contains 1 index buffer, 0 or 1 vertex buffer, and 0 or more
743  * vertex elements.
744  *
745  * Constraints on the buffers to get the fastest codepath:
746  * - All buffer contents are considered immutable and read-only after
747  *   initialization. This implies the following things.
748  * - No place is required to track whether these buffers are busy.
749  * - All CPU mappings of these buffers can be forced to UNSYNCHRONIZED by
750  *   both drivers and common code unconditionally.
751  * - Buffer invalidation can be skipped by both drivers and common code
752  *   unconditionally.
753  */
754 struct pipe_vertex_state {
755    struct pipe_reference reference;
756    struct pipe_screen *screen;
757 
758    /* The following structure is used as a key for util_vertex_state_cache
759     * to deduplicate identical state objects and thus enable more
760     * opportunities for draw merging.
761     */
762    struct {
763       struct pipe_resource *indexbuf;
764       struct pipe_vertex_buffer vbuffer;
765       unsigned num_elements;
766       struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
767       uint32_t full_velem_mask;
768    } input;
769 };
770 
771 struct pipe_draw_indirect_info
772 {
773    unsigned offset; /**< must be 4 byte aligned */
774    unsigned stride; /**< must be 4 byte aligned */
775    unsigned draw_count; /**< number of indirect draws */
776    unsigned indirect_draw_count_offset; /**< must be 4 byte aligned */
777 
778    /* Indirect draw parameters resource is laid out as follows:
779     *
780     * if using indexed drawing:
781     *  struct {
782     *     uint32_t count;
783     *     uint32_t instance_count;
784     *     uint32_t start;
785     *     int32_t index_bias;
786     *     uint32_t start_instance;
787     *  };
788     * otherwise:
789     *  struct {
790     *     uint32_t count;
791     *     uint32_t instance_count;
792     *     uint32_t start;
793     *     uint32_t start_instance;
794     *  };
795     *
796     * If NULL, count_from_stream_output != NULL.
797     */
798    struct pipe_resource *buffer;
799 
800    /* Indirect draw count resource: If not NULL, contains a 32-bit value which
801     * is to be used as the real draw_count.
802     */
803    struct pipe_resource *indirect_draw_count;
804 
805    /**
806     * Stream output target. If not NULL, it's used to provide the 'count'
807     * parameter based on the number vertices captured by the stream output
808     * stage. (or generally, based on the number of bytes captured)
809     *
810     * Only 'mode', 'start_instance', and 'instance_count' are taken into
811     * account, all the other variables from pipe_draw_info are ignored.
812     *
813     * 'start' is implicitly 0 and 'count' is set as discussed above.
814     * The draw command is non-indexed.
815     *
816     * Note that this only provides the count. The vertex buffers must
817     * be set via set_vertex_buffers manually.
818     */
819    struct pipe_stream_output_target *count_from_stream_output;
820 };
821 
822 struct pipe_draw_start_count_bias {
823    unsigned start;
824    unsigned count;
825    int index_bias; /**< a bias to be added to each index */
826 };
827 
828 /**
829  * Draw vertex state description. It's translated to pipe_draw_info as follows:
830  * - mode comes from this structure
831  * - index_size is 4
832  * - instance_count is 1
833  * - index.resource comes from pipe_vertex_state
834  * - everything else is 0
835  */
836 struct pipe_draw_vertex_state_info {
837 #if defined(__GNUC__)
838    /* sizeof(mode) == 1 because it's a packed enum. */
839    enum mesa_prim mode;  /**< the mode of the primitive */
840 #else
841    /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
842    uint8_t mode;              /**< the mode of the primitive */
843 #endif
844    bool take_vertex_state_ownership; /**< for skipping reference counting */
845 };
846 
847 /**
848  * Information to describe a draw_vbo call.
849  */
850 struct pipe_draw_info
851 {
852 #if defined(__GNUC__)
853    /* sizeof(mode) == 1 because it's a packed enum. */
854    enum mesa_prim mode;  /**< the mode of the primitive */
855 #else
856    /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
857    uint8_t mode;              /**< the mode of the primitive */
858 #endif
859    uint16_t index_size;        /**< if 0, the draw is not indexed. */
860    bool primitive_restart:1;
861    bool has_user_indices:1;   /**< if true, use index.user_buffer */
862    bool index_bounds_valid:1; /**< whether min_index and max_index are valid;
863                                    they're always invalid if index_size == 0 */
864    bool increment_draw_id:1;  /**< whether drawid increments for direct draws */
865    bool take_index_buffer_ownership:1; /**< callee inherits caller's refcount
866          (no need to reference indexbuf, but still needs to unreference it) */
867    bool index_bias_varies:1;   /**< true if index_bias varies between draws */
868    bool was_line_loop:1; /**< true if mesa_prim was LINE_LOOP before translation */
869    uint8_t _pad:1;
870 
871    unsigned start_instance; /**< first instance id */
872    unsigned instance_count; /**< number of instances */
873 
874    /**
875     * Primitive restart enable/index (only applies to indexed drawing)
876     */
877    unsigned restart_index;
878 
879    /* Pointers must be placed appropriately for optimal structure packing on
880     * 64-bit CPUs.
881     */
882 
883    /**
884     * An index buffer.  When an index buffer is bound, all indices to vertices
885     * will be looked up from the buffer.
886     *
887     * If has_user_indices, use index.user, else use index.resource.
888     */
889    union {
890       struct pipe_resource *resource;  /**< real buffer */
891       const void *user;  /**< pointer to a user buffer */
892    } index;
893 
894    /* These must be last for better packing in u_threaded_context. */
895    unsigned min_index; /**< the min index */
896    unsigned max_index; /**< the max index */
897 };
898 
899 
900 /**
901  * Information to describe a blit call.
902  */
903 struct pipe_blit_info
904 {
905    struct {
906       struct pipe_resource *resource;
907       unsigned level;
908       struct pipe_box box; /**< negative width, height only legal for src */
909       /* For pipe_surface-like format casting: */
910       enum pipe_format format; /**< must be supported for sampling (src)
911                                or rendering (dst), ZS is always supported */
912    } dst, src;
913 
914    unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
915    unsigned filter; /**< PIPE_TEX_FILTER_* */
916    uint8_t dst_sample; /**< if non-zero, set sample_mask to (1 << (dst_sample - 1)) */
917    bool sample0_only;
918    bool scissor_enable;
919    struct pipe_scissor_state scissor;
920 
921    /* Swizzling during a blit typically forces a slower
922       path, so it should be used only when necessary. It's
923       there mainly to support blitting between different formats
924       when one of them has been emulated (e.g. GL_ALPHA emulated
925       by GL_RGBA) */
926    bool swizzle_enable; /**< swizzle is only applied if this is set */
927    uint8_t swizzle[4];  /**< map to be applied while blitting */
928 
929    /* Window rectangles can either be inclusive or exclusive. */
930    bool window_rectangle_include;
931    unsigned num_window_rectangles;
932    struct pipe_scissor_state window_rectangles[PIPE_MAX_WINDOW_RECTANGLES];
933 
934    bool render_condition_enable; /**< whether the blit should honor the
935                                  current render condition */
936    bool alpha_blend; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
937 };
938 
939 /**
940  * Information to describe a launch_grid call.
941  */
942 struct pipe_grid_info
943 {
944    /**
945     * For drivers that use PIPE_SHADER_IR_NATIVE as their prefered IR, this
946     * value will be the index of the kernel in the opencl.kernels metadata
947     * list.
948     */
949    uint32_t pc;
950 
951    /**
952     * Will be used to initialize the INPUT resource, and it should point to a
953     * buffer of at least pipe_compute_state::req_input_mem bytes.
954     */
955    const void *input;
956 
957    /**
958     * Variable shared memory used by this invocation.
959     *
960     * This comes on top of shader declared shared memory.
961     */
962    uint32_t variable_shared_mem;
963 
964    /**
965     * Grid number of dimensions, 1-3, e.g. the work_dim parameter passed to
966     * clEnqueueNDRangeKernel. Note block[] and grid[] must be padded with
967     * 1 for non-used dimensions.
968     */
969    uint work_dim;
970 
971    /**
972     * Determine the layout of the working block (in thread units) to be used.
973     */
974    uint block[3];
975 
976    /**
977     * last_block allows disabling threads at the farthermost grid boundary.
978     * Full blocks as specified by "block" are launched, but the threads
979     * outside of "last_block" dimensions are disabled.
980     *
981     * If a block touches the grid boundary in the i-th axis, threads with
982     * THREAD_ID[i] >= last_block[i] are disabled.
983     *
984     * If last_block[i] is 0, it has the same behavior as last_block[i] = block[i],
985     * meaning no effect.
986     *
987     * It's equivalent to doing this at the beginning of the compute shader:
988     *
989     *   for (i = 0; i < 3; i++) {
990     *      if (block_id[i] == grid[i] - 1 &&
991     *          last_block[i] && thread_id[i] >= last_block[i])
992     *         return;
993     *   }
994     */
995    uint last_block[3];
996 
997    /**
998     * Determine the layout of the grid (in block units) to be used.
999     */
1000    uint grid[3];
1001 
1002    /**
1003     * Base offsets to launch grids from
1004     */
1005    uint grid_base[3];
1006 
1007    /* Indirect compute parameters resource: If not NULL, block sizes are taken
1008     * from this buffer instead, which is laid out as follows:
1009     *
1010     *  struct {
1011     *     uint32_t num_blocks_x;
1012     *     uint32_t num_blocks_y;
1013     *     uint32_t num_blocks_z;
1014     *  };
1015     */
1016    struct pipe_resource *indirect;
1017    unsigned indirect_offset; /**< must be 4 byte aligned */
1018    unsigned indirect_stride;
1019    /* draw related members are for task/mesh shaders */
1020    unsigned draw_count;
1021    unsigned indirect_draw_count_offset;
1022    struct pipe_resource *indirect_draw_count;
1023 };
1024 
1025 /**
1026  * Encapsulates all info about a tensor. Only types supported are INT8 and UINT8.
1027  */
1028 struct pipe_tensor {
1029    /**
1030     * Memory-backing for this tensor (use pipe_buffer_*).
1031     */
1032    struct pipe_resource *resource;
1033    /**
1034     * Index of this tensor in the subgraph that contains it.
1035     */
1036    unsigned index;
1037    /**
1038     * Dimensions of this tensor.
1039     */
1040    unsigned dims[4];
1041    /**
1042     * Scale used to quantize this tensor. Only per-tensor quantization is supported.
1043     */
1044    float scale;
1045    /**
1046     * Zero-point used to quantize this tensor.
1047     */
1048    int zero_point;
1049    /**
1050     * Whether the tensor contains data in INT8 or UINT8 format.
1051     */
1052    bool is_signed;
1053 };
1054 
1055 /**
1056  * Type of a pipe_ml_operation.
1057  */
1058 enum pipe_ml_operation_type {
1059    PIPE_ML_OPERATION_TYPE_ADD,
1060    PIPE_ML_OPERATION_TYPE_CONVOLUTION,
1061    PIPE_ML_OPERATION_TYPE_POOLING,
1062    PIPE_ML_OPERATION_TYPE_CONCATENATION,
1063    PIPE_ML_OPERATION_TYPE_SPLIT,
1064    PIPE_ML_OPERATION_TYPE_PAD,
1065    PIPE_ML_OPERATION_TYPE_FULLY_CONNECTED,
1066 };
1067 
1068 /**
1069  * Information about a single operation inside a ML subgraph.
1070  */
1071 struct pipe_ml_operation
1072 {
1073    /**
1074     * Type of operation.
1075     */
1076    enum pipe_ml_operation_type type;
1077 
1078    /**
1079     * Tensor used as input.
1080     */
1081    struct pipe_tensor **input_tensors;
1082    unsigned input_count;
1083 
1084    /**
1085     * Tensor used as output.
1086     */
1087    struct pipe_tensor **output_tensors;
1088    unsigned output_count;
1089 
1090    union {
1091       struct {
1092          /**
1093           * For convolutions, tensor containing the weights.
1094           */
1095          struct pipe_tensor *weight_tensor;
1096 
1097          /**
1098           * For convolutions, tensor containing the biases.
1099           */
1100          struct pipe_tensor *bias_tensor;
1101 
1102          /**
1103           * Stride used to access the input tensor on the x axis.
1104           */
1105          unsigned stride_x;
1106 
1107          /**
1108           * Stride used to access the input tensor on the x axis.
1109           */
1110          unsigned stride_y;
1111 
1112          /**
1113           * Whether to use padding of type same when accessing the input tensor.
1114           */
1115          bool padding_same;
1116 
1117          /**
1118           * Whether this is a pointwise (1x1 kernels) convolution.
1119           */
1120          bool pointwise;
1121 
1122          /**
1123           * Whether this is a depthwise convolution.
1124           */
1125          bool depthwise;
1126 
1127          /**
1128           * Whether this convolution has fused ReLU activation.
1129           */
1130          bool relu;
1131       } conv;
1132       struct {
1133          /**
1134           * Stride used to access the input tensor on the x axis.
1135           */
1136          unsigned stride_x;
1137 
1138          /**
1139           * Stride used to access the input tensor on the x axis.
1140           */
1141          unsigned stride_y;
1142 
1143          /**
1144           * Width of the area used for pooling.
1145           */
1146          unsigned filter_width;
1147 
1148          /**
1149           * Height of the area used for pooling.
1150           */
1151          unsigned filter_height;
1152 
1153          /**
1154           * Whether to use padding of type same when accessing the input tensor.
1155           */
1156          bool padding_same;
1157       } pooling;
1158       struct {
1159          /**
1160           * Left padding.
1161           */
1162          unsigned before_x;
1163 
1164          /**
1165           * Right padding.
1166           */
1167          unsigned after_x;
1168 
1169          /**
1170           * Top padding.
1171           */
1172          unsigned before_y;
1173          /**
1174           * Bottom padding.
1175           */
1176          unsigned after_y;
1177       } pad;
1178 
1179       struct {
1180          /**
1181           * Tensor containing the weights.
1182           */
1183          struct pipe_tensor *weight_tensor;
1184          /**
1185           * Tensor containing the biases.
1186           */
1187          struct pipe_tensor *bias_tensor;
1188 
1189          /**
1190           * Whether a ReLU activation should be applied to the output.
1191           */
1192          bool relu;
1193       } fcon;
1194    };
1195 };
1196 
1197 /**
1198  * Subgraph that drivers can subclass to keep the output of the subgraph
1199  * compilation process.
1200  */
1201 struct pipe_ml_subgraph
1202 {
1203    /**
1204     * pipe_context that owns this subgraph.
1205     */
1206    struct pipe_context *context;
1207 };
1208 
1209 /**
1210  * Structure used as a header for serialized compute programs.
1211  */
1212 struct pipe_binary_program_header
1213 {
1214    uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
1215    char blob[];
1216 };
1217 
1218 struct pipe_compute_state
1219 {
1220    enum pipe_shader_ir ir_type; /**< IR type contained in prog. */
1221    const void *prog; /**< Compute program to be executed. */
1222    unsigned static_shared_mem; /**< equal to info.shared_size, used for shaders passed as TGSI */
1223    unsigned req_input_mem; /**< Required size of the INPUT resource. */
1224 };
1225 
1226 struct pipe_compute_state_object_info
1227 {
1228    /**
1229     * Max number of threads per block supported for the given cso.
1230     */
1231    unsigned max_threads;
1232 
1233    /**
1234     * Which multiple should the block size be of for best performance.
1235     *
1236     * E.g. for 8 a block with n * 8 threads would result in optimal utilization
1237     * of the hardware.
1238     */
1239    unsigned preferred_simd_size;
1240 
1241    /**
1242     * Bitmask of supported SIMD sizes.
1243     */
1244    unsigned simd_sizes;
1245 
1246    /**
1247     * How much private memory does this CSO require per thread (a.k.a. NIR scratch memory).
1248     */
1249    unsigned private_memory;
1250 };
1251 
1252 /**
1253  * Structure that contains a callback for device reset messages from the driver
1254  * back to the gallium frontend.
1255  *
1256  * The callback must not be called from driver-created threads.
1257  */
1258 struct pipe_device_reset_callback
1259 {
1260    /**
1261     * Callback for the driver to report when a device reset is detected.
1262     *
1263     * \param data   user-supplied data pointer
1264     * \param status PIPE_*_RESET
1265     */
1266    void (*reset)(void *data, enum pipe_reset_status status);
1267 
1268    void *data;
1269 };
1270 
1271 /**
1272  * Information about memory usage. All sizes are in kilobytes.
1273  */
1274 struct pipe_memory_info
1275 {
1276    unsigned total_device_memory; /**< size of device memory, e.g. VRAM */
1277    unsigned avail_device_memory; /**< free device memory at the moment */
1278    unsigned total_staging_memory; /**< size of staging memory, e.g. GART */
1279    unsigned avail_staging_memory; /**< free staging memory at the moment */
1280    unsigned device_memory_evicted; /**< size of memory evicted (monotonic counter) */
1281    unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
1282 };
1283 
1284 /**
1285  * Structure that contains information about external memory
1286  */
1287 struct pipe_memory_object
1288 {
1289    bool dedicated;
1290 };
1291 
1292 #ifdef __cplusplus
1293 }
1294 #endif
1295 
1296 #endif
1297