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