1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 /**
30 * @file
31 *
32 * Abstract graphics pipe state objects.
33 *
34 * Basic notes:
35 * 1. Want compact representations, so we use bitfields.
36 * 2. Put bitfields before other (GLfloat) fields.
37 * 3. enum bitfields need to be at least one bit extra in size so the most
38 * significant bit is zero. MSVC treats enums as signed so if the high
39 * bit is set, the value will be interpreted as a negative number.
40 * That causes trouble in various places.
41 */
42
43
44 #ifndef PIPE_STATE_H
45 #define PIPE_STATE_H
46
47 #include "p_compiler.h"
48 #include "p_defines.h"
49 #include "p_format.h"
50
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 struct gl_buffer_object;
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 64
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_tri_clip:1; /** large points clipped as tris or points */
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 TGSI
286 * tokens, etc. If the driver returns 'PIPE_SHADER_IR_TGSI' for the
287 * 'PIPE_SHADER_CAP_PREFERRED_IR' shader param, the ir will *always* be
288 * 'PIPE_SHADER_IR_TGSI' and the tokens ptr will be valid. If the driver
289 * requests a different 'pipe_shader_ir' type, then it must check the 'type'
290 * enum to see if it is getting TGSI tokens or its preferred IR.
291 *
292 * TODO pipe_compute_state should probably get similar treatment to handle
293 * multiple IR's in a cleaner way..
294 *
295 * NOTE: since it is expected that the consumer will want to perform
296 * additional passes on the nir_shader, the driver takes ownership of
297 * the nir_shader. If gallium frontends need to hang on to the IR (for
298 * example, variant management), it should use nir_shader_clone().
299 */
300 struct pipe_shader_state
301 {
302 enum pipe_shader_ir type;
303 /* TODO move tokens into union. */
304 const struct tgsi_token *tokens;
305 union {
306 void *native;
307 void *nir;
308 } ir;
309 struct pipe_stream_output_info stream_output;
310 };
311
312 static inline void
pipe_shader_state_from_tgsi(struct pipe_shader_state * state,const struct tgsi_token * tokens)313 pipe_shader_state_from_tgsi(struct pipe_shader_state *state,
314 const struct tgsi_token *tokens)
315 {
316 state->type = PIPE_SHADER_IR_TGSI;
317 state->tokens = tokens;
318 memset(&state->stream_output, 0, sizeof(state->stream_output));
319 }
320
321
322 struct pipe_stencil_state
323 {
324 unsigned enabled:1; /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
325 unsigned func:3; /**< PIPE_FUNC_x */
326 unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */
327 unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
328 unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
329 unsigned valuemask:8;
330 unsigned writemask:8;
331 };
332
333
334 struct pipe_depth_stencil_alpha_state
335 {
336 struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
337
338 unsigned alpha_enabled:1; /**< alpha test enabled? */
339 unsigned alpha_func:3; /**< PIPE_FUNC_x */
340
341 unsigned depth_enabled:1; /**< depth test enabled? */
342 unsigned depth_writemask:1; /**< allow depth buffer writes? */
343 unsigned depth_func:3; /**< depth test func (PIPE_FUNC_x) */
344 unsigned depth_bounds_test:1; /**< depth bounds test enabled? */
345
346 float alpha_ref_value; /**< reference value */
347 double depth_bounds_min; /**< minimum depth bound */
348 double depth_bounds_max; /**< maximum depth bound */
349 };
350
351
352 struct pipe_rt_blend_state
353 {
354 unsigned blend_enable:1;
355
356 unsigned rgb_func:3; /**< PIPE_BLEND_x */
357 unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
358 unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
359
360 unsigned alpha_func:3; /**< PIPE_BLEND_x */
361 unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
362 unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
363
364 unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */
365 };
366
367
368 struct pipe_blend_state
369 {
370 unsigned independent_blend_enable:1;
371 unsigned logicop_enable:1;
372 unsigned logicop_func:4; /**< PIPE_LOGICOP_x */
373 unsigned dither:1;
374 unsigned alpha_to_coverage:1;
375 unsigned alpha_to_coverage_dither:1;
376 unsigned alpha_to_one:1;
377 unsigned max_rt:3; /* index of max rt, Ie. # of cbufs minus 1 */
378 unsigned advanced_blend_func:4;
379 struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
380 };
381
382
383 struct pipe_blend_color
384 {
385 float color[4];
386 };
387
388
389 struct pipe_stencil_ref
390 {
391 ubyte ref_value[2];
392 };
393
394
395 /**
396 * Note that pipe_surfaces are "texture views for rendering"
397 * and so in the case of ARB_framebuffer_no_attachment there
398 * is no pipe_surface state available such that we may
399 * extract the number of samples and layers.
400 */
401 struct pipe_framebuffer_state
402 {
403 uint16_t width, height;
404 uint16_t layers; /**< Number of layers in a no-attachment framebuffer */
405 ubyte samples; /**< Number of samples in a no-attachment framebuffer */
406
407 /** multiple color buffers for multiple render targets */
408 ubyte nr_cbufs;
409 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
410
411 struct pipe_surface *zsbuf; /**< Z/stencil buffer */
412 };
413
414
415 /**
416 * Texture sampler state.
417 */
418 struct pipe_sampler_state
419 {
420 unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */
421 unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */
422 unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */
423 unsigned min_img_filter:1; /**< PIPE_TEX_FILTER_x */
424 unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */
425 unsigned mag_img_filter:1; /**< PIPE_TEX_FILTER_x */
426 unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */
427 unsigned compare_func:3; /**< PIPE_FUNC_x */
428 unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
429 unsigned max_anisotropy:5;
430 unsigned seamless_cube_map:1;
431 unsigned border_color_is_integer:1;
432 unsigned reduction_mode:2; /**< PIPE_TEX_REDUCTION_x */
433 unsigned pad:5; /**< take bits from this for new members */
434 float lod_bias; /**< LOD/lambda bias */
435 float min_lod, max_lod; /**< LOD clamp range, after bias */
436 union pipe_color_union border_color;
437 enum pipe_format border_color_format; /**< only with PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_FREEDRENO, must be last */
438 };
439
440 union pipe_surface_desc {
441 struct {
442 unsigned level;
443 unsigned first_layer:16;
444 unsigned last_layer:16;
445 } tex;
446 struct {
447 unsigned first_element;
448 unsigned last_element;
449 } buf;
450 };
451
452 /**
453 * A view into a texture that can be bound to a color render target /
454 * depth stencil attachment point.
455 */
456 struct pipe_surface
457 {
458 struct pipe_reference reference;
459 enum pipe_format format:16;
460 unsigned writable:1; /**< writable shader resource */
461 struct pipe_resource *texture; /**< resource into which this is a view */
462 struct pipe_context *context; /**< context this surface belongs to */
463
464 /* XXX width/height should be removed */
465 uint16_t width; /**< logical width in pixels */
466 uint16_t height; /**< logical height in pixels */
467
468 /**
469 * Number of samples for the surface. This will be 0 if rendering
470 * should use the resource's nr_samples, or another value if the resource
471 * is bound using FramebufferTexture2DMultisampleEXT.
472 */
473 unsigned nr_samples:8;
474
475 union pipe_surface_desc u;
476 };
477
478
479 /**
480 * A view into a texture that can be bound to a shader stage.
481 */
482 struct pipe_sampler_view
483 {
484 /* Put the refcount on its own cache line to prevent "False sharing". */
485 EXCLUSIVE_CACHELINE(struct pipe_reference reference);
486
487 enum pipe_format format:15; /**< typed PIPE_FORMAT_x */
488 enum pipe_texture_target target:5; /**< PIPE_TEXTURE_x */
489 unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */
490 unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */
491 unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */
492 unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */
493 struct pipe_resource *texture; /**< texture into which this is a view */
494 struct pipe_context *context; /**< context this view belongs to */
495 union {
496 struct {
497 unsigned first_layer:16; /**< first layer to use for array textures */
498 unsigned last_layer:16; /**< last layer to use for array textures */
499 unsigned first_level:8; /**< first mipmap level to use */
500 unsigned last_level:8; /**< last mipmap level to use */
501 } tex;
502 struct {
503 unsigned offset; /**< offset in bytes */
504 unsigned size; /**< size of the readable sub-range in bytes */
505 } buf;
506 } u;
507 };
508
509
510 /**
511 * A description of a buffer or texture image that can be bound to a shader
512 * stage.
513 */
514 struct pipe_image_view
515 {
516 struct pipe_resource *resource; /**< resource into which this is a view */
517 enum pipe_format format; /**< typed PIPE_FORMAT_x */
518 uint16_t access; /**< PIPE_IMAGE_ACCESS_x */
519 uint16_t shader_access; /**< PIPE_IMAGE_ACCESS_x */
520
521 union {
522 struct {
523 unsigned first_layer:16; /**< first layer to use for array textures */
524 unsigned last_layer:16; /**< last layer to use for array textures */
525 unsigned level:8; /**< mipmap level to use */
526 } tex;
527 struct {
528 unsigned offset; /**< offset in bytes */
529 unsigned size; /**< size of the accessible sub-range in bytes */
530 } buf;
531 } u;
532 };
533
534
535 /**
536 * Subregion of 1D/2D/3D image resource.
537 */
538 struct pipe_box
539 {
540 /* Fields only used by textures use int16_t instead of int.
541 * x and width are used by buffers, so they need the full 32-bit range.
542 */
543 int x;
544 int16_t y;
545 int16_t z;
546 int width;
547 int16_t height;
548 int16_t depth;
549 };
550
551
552 /**
553 * A memory object/resource such as a vertex buffer or texture.
554 */
555 struct pipe_resource
556 {
557 /* Put the refcount on its own cache line to prevent "False sharing". */
558 EXCLUSIVE_CACHELINE(struct pipe_reference reference);
559
560 unsigned width0; /**< Used by both buffers and textures. */
561 uint16_t height0; /* Textures: The maximum height/depth/array_size is 16k. */
562 uint16_t depth0;
563 uint16_t array_size;
564
565 enum pipe_format format:16; /**< PIPE_FORMAT_x */
566 enum pipe_texture_target target:8; /**< PIPE_TEXTURE_x */
567 unsigned last_level:8; /**< Index of last mipmap level present/defined */
568
569 /** Number of samples determining quality, driving rasterizer, shading,
570 * and framebuffer.
571 */
572 unsigned nr_samples:8;
573
574 /** Multiple samples within a pixel can have the same value.
575 * nr_storage_samples determines how many slots for different values
576 * there are per pixel. Only color buffers can set this lower than
577 * nr_samples.
578 */
579 unsigned nr_storage_samples:8;
580
581 unsigned nr_sparse_levels:8; /**< Mipmap levels support partial resident */
582
583 unsigned usage:8; /**< PIPE_USAGE_x (not a bitmask) */
584 unsigned bind; /**< bitmask of PIPE_BIND_x */
585 unsigned flags; /**< bitmask of PIPE_RESOURCE_FLAG_x */
586
587 /**
588 * For planar images, ie. YUV EGLImage external, etc, pointer to the
589 * next plane.
590 */
591 struct pipe_resource *next;
592 /* The screen pointer should be last for optimal structure packing. */
593 struct pipe_screen *screen; /**< screen that this texture belongs to */
594 };
595
596 /**
597 * Opaque object used for separate resource/memory allocations.
598 */
599 struct pipe_memory_allocation;
600
601 /**
602 * Transfer object. For data transfer to/from a resource.
603 */
604 struct pipe_transfer
605 {
606 struct pipe_resource *resource; /**< resource to transfer to/from */
607 enum pipe_map_flags usage:24;
608 unsigned level:8; /**< texture mipmap level */
609 struct pipe_box box; /**< region of the resource to access */
610 unsigned stride; /**< row stride in bytes */
611 unsigned layer_stride; /**< image/layer stride in bytes */
612
613 /* Offset into a driver-internal staging buffer to make use of unused
614 * padding in this structure.
615 */
616 unsigned offset;
617 };
618
619
620 /**
621 * A vertex buffer. Typically, all the vertex data/attributes for
622 * drawing something will be in one buffer. But it's also possible, for
623 * example, to put colors in one buffer and texcoords in another.
624 */
625 struct pipe_vertex_buffer
626 {
627 uint16_t stride; /**< stride to same attrib in next vertex, in bytes */
628 bool is_user_buffer;
629 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
630
631 union {
632 struct pipe_resource *resource; /**< the actual buffer */
633 const void *user; /**< pointer to a user buffer */
634 } buffer;
635 };
636
637
638 /**
639 * A constant buffer. A subrange of an existing buffer can be set
640 * as a constant buffer.
641 */
642 struct pipe_constant_buffer
643 {
644 struct pipe_resource *buffer; /**< the actual buffer */
645 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
646 unsigned buffer_size; /**< how much data can be read in shader */
647 const void *user_buffer; /**< pointer to a user buffer if buffer == NULL */
648 };
649
650
651 /**
652 * An untyped shader buffer supporting loads, stores, and atomics.
653 */
654 struct pipe_shader_buffer {
655 struct pipe_resource *buffer; /**< the actual buffer */
656 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
657 unsigned buffer_size; /**< how much data can be read in shader */
658 };
659
660
661 /**
662 * A stream output target. The structure specifies the range vertices can
663 * be written to.
664 *
665 * In addition to that, the structure should internally maintain the offset
666 * into the buffer, which should be incremented everytime something is written
667 * (appended) to it. The internal offset is buffer_offset + how many bytes
668 * have been written. The internal offset can be stored on the device
669 * and the CPU actually doesn't have to query it.
670 *
671 * Note that the buffer_size variable is actually specifying the available
672 * space in the buffer, not the size of the attached buffer.
673 * In other words in majority of cases buffer_size would simply be
674 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
675 * of the buffer left, after accounting for buffer offset, for stream output
676 * to write to.
677 *
678 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
679 * actually been written.
680 */
681 struct pipe_stream_output_target
682 {
683 struct pipe_reference reference;
684 struct pipe_resource *buffer; /**< the output buffer */
685 struct pipe_context *context; /**< context this SO target belongs to */
686
687 unsigned buffer_offset; /**< offset where data should be written, in bytes */
688 unsigned buffer_size; /**< how much data is allowed to be written */
689 };
690
691
692 /**
693 * Information to describe a vertex attribute (position, color, etc)
694 */
695 struct pipe_vertex_element
696 {
697 /** Offset of this attribute, in bytes, from the start of the vertex */
698 uint16_t src_offset;
699
700 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
701 * this attribute live in?
702 */
703 uint8_t vertex_buffer_index:7;
704
705 /**
706 * Whether this element refers to a dual-slot vertex shader input.
707 * The purpose of this field is to do dual-slot lowering when the CSO is
708 * created instead of during every state change.
709 *
710 * It's lowered by util_lower_uint64_vertex_elements.
711 */
712 bool dual_slot:1;
713
714 /**
715 * This has only 8 bits because all vertex formats should be <= 255.
716 */
717 uint8_t src_format; /* low 8 bits of enum pipe_format. */
718
719 /** Instance data rate divisor. 0 means this is per-vertex data,
720 * n means per-instance data used for n consecutive instances (n > 0).
721 */
722 unsigned instance_divisor;
723 };
724
725 /**
726 * Opaque refcounted constant state object encapsulating a vertex buffer,
727 * index buffer, and vertex elements. Used by display lists to bind those
728 * states and pass buffer references quickly.
729 *
730 * The state contains 1 index buffer, 0 or 1 vertex buffer, and 0 or more
731 * vertex elements.
732 *
733 * Constraints on the buffers to get the fastest codepath:
734 * - All buffer contents are considered immutable and read-only after
735 * initialization. This implies the following things.
736 * - No place is required to track whether these buffers are busy.
737 * - All CPU mappings of these buffers can be forced to UNSYNCHRONIZED by
738 * both drivers and common code unconditionally.
739 * - Buffer invalidation can be skipped by both drivers and common code
740 * unconditionally.
741 */
742 struct pipe_vertex_state {
743 struct pipe_reference reference;
744 struct pipe_screen *screen;
745
746 /* The following structure is used as a key for util_vertex_state_cache
747 * to deduplicate identical state objects and thus enable more
748 * opportunities for draw merging.
749 */
750 struct {
751 struct pipe_resource *indexbuf;
752 struct pipe_vertex_buffer vbuffer;
753 unsigned num_elements;
754 struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
755 uint32_t full_velem_mask;
756 } input;
757 };
758
759 struct pipe_draw_indirect_info
760 {
761 unsigned offset; /**< must be 4 byte aligned */
762 unsigned stride; /**< must be 4 byte aligned */
763 unsigned draw_count; /**< number of indirect draws */
764 unsigned indirect_draw_count_offset; /**< must be 4 byte aligned */
765
766 /* Indirect draw parameters resource is laid out as follows:
767 *
768 * if using indexed drawing:
769 * struct {
770 * uint32_t count;
771 * uint32_t instance_count;
772 * uint32_t start;
773 * int32_t index_bias;
774 * uint32_t start_instance;
775 * };
776 * otherwise:
777 * struct {
778 * uint32_t count;
779 * uint32_t instance_count;
780 * uint32_t start;
781 * uint32_t start_instance;
782 * };
783 *
784 * If NULL, count_from_stream_output != NULL.
785 */
786 struct pipe_resource *buffer;
787
788 /* Indirect draw count resource: If not NULL, contains a 32-bit value which
789 * is to be used as the real draw_count.
790 */
791 struct pipe_resource *indirect_draw_count;
792
793 /**
794 * Stream output target. If not NULL, it's used to provide the 'count'
795 * parameter based on the number vertices captured by the stream output
796 * stage. (or generally, based on the number of bytes captured)
797 *
798 * Only 'mode', 'start_instance', and 'instance_count' are taken into
799 * account, all the other variables from pipe_draw_info are ignored.
800 *
801 * 'start' is implicitly 0 and 'count' is set as discussed above.
802 * The draw command is non-indexed.
803 *
804 * Note that this only provides the count. The vertex buffers must
805 * be set via set_vertex_buffers manually.
806 */
807 struct pipe_stream_output_target *count_from_stream_output;
808 };
809
810 struct pipe_draw_start_count_bias {
811 unsigned start;
812 unsigned count;
813 int index_bias; /**< a bias to be added to each index */
814 };
815
816 /**
817 * Draw vertex state description. It's translated to pipe_draw_info as follows:
818 * - mode comes from this structure
819 * - index_size is 4
820 * - instance_count is 1
821 * - index.resource comes from pipe_vertex_state
822 * - everything else is 0
823 */
824 struct pipe_draw_vertex_state_info {
825 #if defined(__GNUC__)
826 /* sizeof(mode) == 1 because it's a packed enum. */
827 enum pipe_prim_type mode; /**< the mode of the primitive */
828 #else
829 /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
830 uint8_t mode; /**< the mode of the primitive */
831 #endif
832 bool take_vertex_state_ownership; /**< for skipping reference counting */
833 };
834
835 /**
836 * Information to describe a draw_vbo call.
837 */
838 struct pipe_draw_info
839 {
840 #if defined(__GNUC__)
841 /* sizeof(mode) == 1 because it's a packed enum. */
842 enum pipe_prim_type mode; /**< the mode of the primitive */
843 #else
844 /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
845 uint8_t mode; /**< the mode of the primitive */
846 #endif
847 uint8_t index_size; /**< if 0, the draw is not indexed. */
848 uint8_t view_mask; /**< mask of multiviews for this draw */
849 bool primitive_restart:1;
850 bool has_user_indices:1; /**< if true, use index.user_buffer */
851 bool index_bounds_valid:1; /**< whether min_index and max_index are valid;
852 they're always invalid if index_size == 0 */
853 bool increment_draw_id:1; /**< whether drawid increments for direct draws */
854 bool take_index_buffer_ownership:1; /**< callee inherits caller's refcount
855 (no need to reference indexbuf, but still needs to unreference it) */
856 bool index_bias_varies:1; /**< true if index_bias varies between draws */
857 bool was_line_loop:1; /**< true if pipe_prim_type was LINE_LOOP before translation */
858 uint8_t _pad:1;
859
860 unsigned start_instance; /**< first instance id */
861 unsigned instance_count; /**< number of instances */
862
863 /**
864 * Primitive restart enable/index (only applies to indexed drawing)
865 */
866 unsigned restart_index;
867
868 /* Pointers must be placed appropriately for optimal structure packing on
869 * 64-bit CPUs.
870 */
871
872 /**
873 * An index buffer. When an index buffer is bound, all indices to vertices
874 * will be looked up from the buffer.
875 *
876 * If has_user_indices, use index.user, else use index.resource.
877 */
878 union {
879 struct pipe_resource *resource; /**< real buffer */
880 struct gl_buffer_object *gl_bo; /**< for the GL frontend, not passed to drivers */
881 const void *user; /**< pointer to a user buffer */
882 } index;
883
884 /* These must be last for better packing in u_threaded_context. */
885 unsigned min_index; /**< the min index */
886 unsigned max_index; /**< the max index */
887 };
888
889
890 /**
891 * Information to describe a blit call.
892 */
893 struct pipe_blit_info
894 {
895 struct {
896 struct pipe_resource *resource;
897 unsigned level;
898 struct pipe_box box; /**< negative width, height only legal for src */
899 /* For pipe_surface-like format casting: */
900 enum pipe_format format; /**< must be supported for sampling (src)
901 or rendering (dst), ZS is always supported */
902 } dst, src;
903
904 unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
905 unsigned filter; /**< PIPE_TEX_FILTER_* */
906 uint8_t dst_sample; /**< if non-zero, set sample_mask to (1 << (dst_sample - 1)) */
907 bool sample0_only;
908 bool scissor_enable;
909 struct pipe_scissor_state scissor;
910
911 /* Window rectangles can either be inclusive or exclusive. */
912 bool window_rectangle_include;
913 unsigned num_window_rectangles;
914 struct pipe_scissor_state window_rectangles[PIPE_MAX_WINDOW_RECTANGLES];
915
916 bool render_condition_enable; /**< whether the blit should honor the
917 current render condition */
918 bool alpha_blend; /* dst.rgb = src.rgb * src.a + dst.rgb * (1 - src.a) */
919 };
920
921 /**
922 * Information to describe a launch_grid call.
923 */
924 struct pipe_grid_info
925 {
926 /**
927 * For drivers that use PIPE_SHADER_IR_NATIVE as their prefered IR, this
928 * value will be the index of the kernel in the opencl.kernels metadata
929 * list.
930 */
931 uint32_t pc;
932
933 /**
934 * Will be used to initialize the INPUT resource, and it should point to a
935 * buffer of at least pipe_compute_state::req_input_mem bytes.
936 */
937 void *input;
938
939 /**
940 * Grid number of dimensions, 1-3, e.g. the work_dim parameter passed to
941 * clEnqueueNDRangeKernel. Note block[] and grid[] must be padded with
942 * 1 for non-used dimensions.
943 */
944 uint work_dim;
945
946 /**
947 * Determine the layout of the working block (in thread units) to be used.
948 */
949 uint block[3];
950
951 /**
952 * last_block allows disabling threads at the farthermost grid boundary.
953 * Full blocks as specified by "block" are launched, but the threads
954 * outside of "last_block" dimensions are disabled.
955 *
956 * If a block touches the grid boundary in the i-th axis, threads with
957 * THREAD_ID[i] >= last_block[i] are disabled.
958 *
959 * If last_block[i] is 0, it has the same behavior as last_block[i] = block[i],
960 * meaning no effect.
961 *
962 * It's equivalent to doing this at the beginning of the compute shader:
963 *
964 * for (i = 0; i < 3; i++) {
965 * if (block_id[i] == grid[i] - 1 &&
966 * last_block[i] && thread_id[i] >= last_block[i])
967 * return;
968 * }
969 */
970 uint last_block[3];
971
972 /**
973 * Determine the layout of the grid (in block units) to be used.
974 */
975 uint grid[3];
976
977 /**
978 * Base offsets to launch grids from
979 */
980 uint grid_base[3];
981
982 /* Indirect compute parameters resource: If not NULL, block sizes are taken
983 * from this buffer instead, which is laid out as follows:
984 *
985 * struct {
986 * uint32_t num_blocks_x;
987 * uint32_t num_blocks_y;
988 * uint32_t num_blocks_z;
989 * };
990 */
991 struct pipe_resource *indirect;
992 unsigned indirect_offset; /**< must be 4 byte aligned */
993 };
994
995 /**
996 * Structure used as a header for serialized compute programs.
997 */
998 struct pipe_binary_program_header
999 {
1000 uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
1001 char blob[];
1002 };
1003
1004 struct pipe_compute_state
1005 {
1006 enum pipe_shader_ir ir_type; /**< IR type contained in prog. */
1007 const void *prog; /**< Compute program to be executed. */
1008 unsigned req_local_mem; /**< Required size of the LOCAL resource. */
1009 unsigned req_private_mem; /**< Required size of the PRIVATE resource. */
1010 unsigned req_input_mem; /**< Required size of the INPUT resource. */
1011 };
1012
1013 /**
1014 * Structure that contains a callback for device reset messages from the driver
1015 * back to the gallium frontend.
1016 *
1017 * The callback must not be called from driver-created threads.
1018 */
1019 struct pipe_device_reset_callback
1020 {
1021 /**
1022 * Callback for the driver to report when a device reset is detected.
1023 *
1024 * \param data user-supplied data pointer
1025 * \param status PIPE_*_RESET
1026 */
1027 void (*reset)(void *data, enum pipe_reset_status status);
1028
1029 void *data;
1030 };
1031
1032 /**
1033 * Information about memory usage. All sizes are in kilobytes.
1034 */
1035 struct pipe_memory_info
1036 {
1037 unsigned total_device_memory; /**< size of device memory, e.g. VRAM */
1038 unsigned avail_device_memory; /**< free device memory at the moment */
1039 unsigned total_staging_memory; /**< size of staging memory, e.g. GART */
1040 unsigned avail_staging_memory; /**< free staging memory at the moment */
1041 unsigned device_memory_evicted; /**< size of memory evicted (monotonic counter) */
1042 unsigned nr_device_memory_evictions; /**< # of evictions (monotonic counter) */
1043 };
1044
1045 /**
1046 * Structure that contains information about external memory
1047 */
1048 struct pipe_memory_object
1049 {
1050 bool dedicated;
1051 };
1052
1053 #ifdef __cplusplus
1054 }
1055 #endif
1056
1057 #endif
1058