Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4358 Serge 1
/**************************************************************************
2
 *
3
 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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
 */
38
 
39
 
40
#ifndef PIPE_STATE_H
41
#define PIPE_STATE_H
42
 
43
#include "p_compiler.h"
44
#include "p_defines.h"
45
#include "p_format.h"
46
 
47
 
48
#ifdef __cplusplus
49
extern "C" {
50
#endif
51
 
52
 
53
/**
54
 * Implementation limits
55
 */
56
#define PIPE_MAX_ATTRIBS          32
57
#define PIPE_MAX_CLIP_PLANES       8
58
#define PIPE_MAX_COLOR_BUFS        8
59
#define PIPE_MAX_CONSTANT_BUFFERS 32
60
#define PIPE_MAX_SAMPLERS         16
61
#define PIPE_MAX_SHADER_INPUTS    32
62
#define PIPE_MAX_SHADER_OUTPUTS   48 /* 32 GENERICs + POS, PSIZE, FOG, etc. */
63
#define PIPE_MAX_SHADER_SAMPLER_VIEWS 32
64
#define PIPE_MAX_SHADER_RESOURCES 32
65
#define PIPE_MAX_TEXTURE_LEVELS   16
66
#define PIPE_MAX_SO_BUFFERS        4
67
#define PIPE_MAX_SO_OUTPUTS       64
68
#define PIPE_MAX_VIEWPORTS        16
69
#define PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT 8
70
#define PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2
71
 
72
 
73
struct pipe_reference
74
{
75
   int32_t count; /* atomic */
76
};
77
 
78
 
79
 
80
/**
81
 * Primitive (point/line/tri) rasterization info
82
 */
83
struct pipe_rasterizer_state
84
{
85
   unsigned flatshade:1;
86
   unsigned light_twoside:1;
87
   unsigned clamp_vertex_color:1;
88
   unsigned clamp_fragment_color:1;
89
   unsigned front_ccw:1;
90
   unsigned cull_face:2;      /**< PIPE_FACE_x */
91
   unsigned fill_front:2;     /**< PIPE_POLYGON_MODE_x */
92
   unsigned fill_back:2;      /**< PIPE_POLYGON_MODE_x */
93
   unsigned offset_point:1;
94
   unsigned offset_line:1;
95
   unsigned offset_tri:1;
96
   unsigned scissor:1;
97
   unsigned poly_smooth:1;
98
   unsigned poly_stipple_enable:1;
99
   unsigned point_smooth:1;
100
   unsigned sprite_coord_mode:1;     /**< PIPE_SPRITE_COORD_ */
101
   unsigned point_quad_rasterization:1; /** points rasterized as quads or points */
102
   unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
103
   unsigned multisample:1;         /* XXX maybe more ms state in future */
104
   unsigned line_smooth:1;
105
   unsigned line_stipple_enable:1;
106
   unsigned line_last_pixel:1;
107
 
108
   /**
109
    * Use the first vertex of a primitive as the provoking vertex for
110
    * flat shading.
111
    */
112
   unsigned flatshade_first:1;
113
 
114
   unsigned half_pixel_center:1;
115
   unsigned bottom_edge_rule:1;
116
 
117
   /**
118
    * When true, rasterization is disabled and no pixels are written.
119
    * This only makes sense with the Stream Out functionality.
120
    */
121
   unsigned rasterizer_discard:1;
122
 
123
   /**
124
    * When false, depth clipping is disabled and the depth value will be
125
    * clamped later at the per-pixel level before depth testing.
126
    * This depends on PIPE_CAP_DEPTH_CLIP_DISABLE.
127
    */
128
   unsigned depth_clip:1;
129
 
130
   /**
131
    * When true clip space in the z axis goes from [0..1] (D3D).  When false
132
    * [-1, 1] (GL).
133
    */
134
   unsigned clip_halfz:1;
135
 
136
   /**
137
    * Enable bits for clipping half-spaces.
138
    * This applies to both user clip planes and shader clip distances.
139
    * Note that if the bound shader exports any clip distances, these
140
    * replace all user clip planes, and clip half-spaces enabled here
141
    * but not written by the shader count as disabled.
142
    */
143
   unsigned clip_plane_enable:PIPE_MAX_CLIP_PLANES;
144
 
145
   unsigned line_stipple_factor:8;  /**< [1..256] actually */
146
   unsigned line_stipple_pattern:16;
147
 
148
   uint32_t sprite_coord_enable; /* referring to 32 TEXCOORD/GENERIC inputs */
149
 
150
   float line_width;
151
   float point_size;           /**< used when no per-vertex size */
152
   float offset_units;
153
   float offset_scale;
154
   float offset_clamp;
155
};
156
 
157
 
158
struct pipe_poly_stipple
159
{
160
   unsigned stipple[32];
161
};
162
 
163
 
164
struct pipe_viewport_state
165
{
166
   float scale[4];
167
   float translate[4];
168
};
169
 
170
 
171
struct pipe_scissor_state
172
{
173
   unsigned minx:16;
174
   unsigned miny:16;
175
   unsigned maxx:16;
176
   unsigned maxy:16;
177
};
178
 
179
 
180
struct pipe_clip_state
181
{
182
   float ucp[PIPE_MAX_CLIP_PLANES][4];
183
};
184
 
185
 
186
/**
187
 * Stream output for vertex transform feedback.
188
 */
189
struct pipe_stream_output_info
190
{
191
   unsigned num_outputs;
192
   /** stride for an entire vertex for each buffer in dwords */
193
   unsigned stride[PIPE_MAX_SO_BUFFERS];
194
 
195
   /**
196
    * Array of stream outputs, in the order they are to be written in.
197
    * Selected components are tightly packed into the output buffer.
198
    */
199
   struct {
200
      unsigned register_index:8;  /**< 0 to PIPE_MAX_SHADER_OUTPUTS */
201
      unsigned start_component:2; /** 0 to 3 */
202
      unsigned num_components:3;  /** 1 to 4 */
203
      unsigned output_buffer:3;   /**< 0 to PIPE_MAX_SO_BUFFERS */
204
      unsigned dst_offset:16;     /**< offset into the buffer in dwords */
205
   } output[PIPE_MAX_SO_OUTPUTS];
206
};
207
 
208
 
209
struct pipe_shader_state
210
{
211
   const struct tgsi_token *tokens;
212
   struct pipe_stream_output_info stream_output;
213
};
214
 
215
 
216
struct pipe_depth_state
217
{
218
   unsigned enabled:1;         /**< depth test enabled? */
219
   unsigned writemask:1;       /**< allow depth buffer writes? */
220
   unsigned func:3;            /**< depth test func (PIPE_FUNC_x) */
221
};
222
 
223
 
224
struct pipe_stencil_state
225
{
226
   unsigned enabled:1;  /**< stencil[0]: stencil enabled, stencil[1]: two-side enabled */
227
   unsigned func:3;     /**< PIPE_FUNC_x */
228
   unsigned fail_op:3;  /**< PIPE_STENCIL_OP_x */
229
   unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */
230
   unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */
231
   unsigned valuemask:8;
232
   unsigned writemask:8;
233
};
234
 
235
 
236
struct pipe_alpha_state
237
{
238
   unsigned enabled:1;
239
   unsigned func:3;     /**< PIPE_FUNC_x */
240
   float ref_value;     /**< reference value */
241
};
242
 
243
 
244
struct pipe_depth_stencil_alpha_state
245
{
246
   struct pipe_depth_state depth;
247
   struct pipe_stencil_state stencil[2]; /**< [0] = front, [1] = back */
248
   struct pipe_alpha_state alpha;
249
};
250
 
251
 
252
struct pipe_rt_blend_state
253
{
254
   unsigned blend_enable:1;
255
 
256
   unsigned rgb_func:3;          /**< PIPE_BLEND_x */
257
   unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */
258
   unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */
259
 
260
   unsigned alpha_func:3;        /**< PIPE_BLEND_x */
261
   unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */
262
   unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */
263
 
264
   unsigned colormask:4;         /**< bitmask of PIPE_MASK_R/G/B/A */
265
};
266
 
267
struct pipe_blend_state
268
{
269
   unsigned independent_blend_enable:1;
270
   unsigned logicop_enable:1;
271
   unsigned logicop_func:4;      /**< PIPE_LOGICOP_x */
272
   unsigned dither:1;
273
   unsigned alpha_to_coverage:1;
274
   unsigned alpha_to_one:1;
275
   struct pipe_rt_blend_state rt[PIPE_MAX_COLOR_BUFS];
276
};
277
 
278
 
279
struct pipe_blend_color
280
{
281
   float color[4];
282
};
283
 
284
struct pipe_stencil_ref
285
{
286
   ubyte ref_value[2];
287
};
288
 
289
struct pipe_framebuffer_state
290
{
291
   unsigned width, height;
292
 
293
   /** multiple color buffers for multiple render targets */
294
   unsigned nr_cbufs;
295
   struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
296
 
297
   struct pipe_surface *zsbuf;      /**< Z/stencil buffer */
298
};
299
 
300
 
301
/**
302
 * Texture sampler state.
303
 */
304
struct pipe_sampler_state
305
{
306
   unsigned wrap_s:3;            /**< PIPE_TEX_WRAP_x */
307
   unsigned wrap_t:3;            /**< PIPE_TEX_WRAP_x */
308
   unsigned wrap_r:3;            /**< PIPE_TEX_WRAP_x */
309
   unsigned min_img_filter:2;    /**< PIPE_TEX_FILTER_x */
310
   unsigned min_mip_filter:2;    /**< PIPE_TEX_MIPFILTER_x */
311
   unsigned mag_img_filter:2;    /**< PIPE_TEX_FILTER_x */
312
   unsigned compare_mode:1;      /**< PIPE_TEX_COMPARE_x */
313
   unsigned compare_func:3;      /**< PIPE_FUNC_x */
314
   unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */
315
   unsigned max_anisotropy:6;
316
   unsigned seamless_cube_map:1;
317
   float lod_bias;               /**< LOD/lambda bias */
318
   float min_lod, max_lod;       /**< LOD clamp range, after bias */
319
   union pipe_color_union border_color;
320
};
321
 
322
 
323
/**
324
 * A view into a texture that can be bound to a color render target /
325
 * depth stencil attachment point.
326
 */
327
struct pipe_surface
328
{
329
   struct pipe_reference reference;
330
   struct pipe_resource *texture; /**< resource into which this is a view  */
331
   struct pipe_context *context; /**< context this surface belongs to */
332
   enum pipe_format format;
333
 
334
   /* XXX width/height should be removed */
335
   unsigned width;               /**< logical width in pixels */
336
   unsigned height;              /**< logical height in pixels */
337
 
338
   unsigned writable:1;          /**< writable shader resource */
339
 
340
   union {
341
      struct {
342
         unsigned level;
343
         unsigned first_layer:16;
344
         unsigned last_layer:16;
345
      } tex;
346
      struct {
347
         unsigned first_element;
348
         unsigned last_element;
349
      } buf;
350
   } u;
351
};
352
 
353
 
354
/**
355
 * A view into a texture that can be bound to a shader stage.
356
 */
357
struct pipe_sampler_view
358
{
359
   struct pipe_reference reference;
360
   enum pipe_format format;      /**< typed PIPE_FORMAT_x */
361
   struct pipe_resource *texture; /**< texture into which this is a view  */
362
   struct pipe_context *context; /**< context this view belongs to */
363
   union {
364
      struct {
365
         unsigned first_layer:16;     /**< first layer to use for array textures */
366
         unsigned last_layer:16;      /**< last layer to use for array textures */
367
         unsigned first_level:8;      /**< first mipmap level to use */
368
         unsigned last_level:8;       /**< last mipmap level to use */
369
      } tex;
370
      struct {
371
         unsigned first_element;
372
         unsigned last_element;
373
      } buf;
374
   } u;
375
   unsigned swizzle_r:3;         /**< PIPE_SWIZZLE_x for red component */
376
   unsigned swizzle_g:3;         /**< PIPE_SWIZZLE_x for green component */
377
   unsigned swizzle_b:3;         /**< PIPE_SWIZZLE_x for blue component */
378
   unsigned swizzle_a:3;         /**< PIPE_SWIZZLE_x for alpha component */
379
};
380
 
381
 
382
/**
383
 * Subregion of 1D/2D/3D image resource.
384
 */
385
struct pipe_box
386
{
387
   int x;
388
   int y;
389
   int z;
390
   int width;
391
   int height;
392
   int depth;
393
};
394
 
395
 
396
/**
397
 * A memory object/resource such as a vertex buffer or texture.
398
 */
399
struct pipe_resource
400
{
401
   struct pipe_reference reference;
402
   struct pipe_screen *screen; /**< screen that this texture belongs to */
403
   enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
404
   enum pipe_format format;         /**< PIPE_FORMAT_x */
405
 
406
   unsigned width0;
407
   unsigned height0;
408
   unsigned depth0;
409
   unsigned array_size;
410
 
411
   unsigned last_level:8;    /**< Index of last mipmap level present/defined */
412
   unsigned nr_samples:8;    /**< for multisampled surfaces, nr of samples */
413
   unsigned usage:8;         /**< PIPE_USAGE_x (not a bitmask) */
414
 
415
   unsigned bind;            /**< bitmask of PIPE_BIND_x */
416
   unsigned flags;           /**< bitmask of PIPE_RESOURCE_FLAG_x */
417
};
418
 
419
 
420
/**
421
 * Transfer object.  For data transfer to/from a resource.
422
 */
423
struct pipe_transfer
424
{
425
   struct pipe_resource *resource; /**< resource to transfer to/from  */
426
   unsigned level;                 /**< texture mipmap level */
427
   enum pipe_transfer_usage usage;
428
   struct pipe_box box;            /**< region of the resource to access */
429
   unsigned stride;                /**< row stride in bytes */
430
   unsigned layer_stride;          /**< image/layer stride in bytes */
431
};
432
 
433
 
434
 
435
/**
436
 * A vertex buffer.  Typically, all the vertex data/attributes for
437
 * drawing something will be in one buffer.  But it's also possible, for
438
 * example, to put colors in one buffer and texcoords in another.
439
 */
440
struct pipe_vertex_buffer
441
{
442
   unsigned stride;    /**< stride to same attrib in next vertex, in bytes */
443
   unsigned buffer_offset;  /**< offset to start of data in buffer, in bytes */
444
   struct pipe_resource *buffer;  /**< the actual buffer */
445
   const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
446
};
447
 
448
 
449
/**
450
 * A constant buffer.  A subrange of an existing buffer can be set
451
 * as a constant buffer.
452
 */
453
struct pipe_constant_buffer {
454
   struct pipe_resource *buffer; /**< the actual buffer */
455
   unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
456
   unsigned buffer_size;   /**< how much data can be read in shader */
457
   const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
458
};
459
 
460
 
461
/**
462
 * A stream output target. The structure specifies the range vertices can
463
 * be written to.
464
 *
465
 * In addition to that, the structure should internally maintain the offset
466
 * into the buffer, which should be incremented everytime something is written
467
 * (appended) to it. The internal offset is buffer_offset + how many bytes
468
 * have been written. The internal offset can be stored on the device
469
 * and the CPU actually doesn't have to query it.
470
 *
471
 * Note that the buffer_size variable is actually specifying the available
472
 * space in the buffer, not the size of the attached buffer.
473
 * In other words in majority of cases buffer_size would simply be
474
 * 'buffer->width0 - buffer_offset', so buffer_size refers to the size
475
 * of the buffer left, after accounting for buffer offset, for stream output
476
 * to write to.
477
 *
478
 * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have
479
 * actually been written.
480
 */
481
struct pipe_stream_output_target
482
{
483
   struct pipe_reference reference;
484
   struct pipe_resource *buffer; /**< the output buffer */
485
   struct pipe_context *context; /**< context this SO target belongs to */
486
 
487
   unsigned buffer_offset;  /**< offset where data should be written, in bytes */
488
   unsigned buffer_size;    /**< how much data is allowed to be written */
489
};
490
 
491
 
492
/**
493
 * Information to describe a vertex attribute (position, color, etc)
494
 */
495
struct pipe_vertex_element
496
{
497
   /** Offset of this attribute, in bytes, from the start of the vertex */
498
   unsigned src_offset;
499
 
500
   /** Instance data rate divisor. 0 means this is per-vertex data,
501
    *  n means per-instance data used for n consecutive instances (n > 0).
502
    */
503
   unsigned instance_divisor;
504
 
505
   /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
506
    * this attribute live in?
507
    */
508
   unsigned vertex_buffer_index;
509
 
510
   enum pipe_format src_format;
511
};
512
 
513
 
514
/**
515
 * An index buffer.  When an index buffer is bound, all indices to vertices
516
 * will be looked up in the buffer.
517
 */
518
struct pipe_index_buffer
519
{
520
   unsigned index_size;  /**< size of an index, in bytes */
521
   unsigned offset;  /**< offset to start of data in buffer, in bytes */
522
   struct pipe_resource *buffer; /**< the actual buffer */
523
   const void *user_buffer;  /**< pointer to a user buffer if buffer == NULL */
524
};
525
 
526
 
527
/**
528
 * Information to describe a draw_vbo call.
529
 */
530
struct pipe_draw_info
531
{
532
   boolean indexed;  /**< use index buffer */
533
 
534
   unsigned mode;  /**< the mode of the primitive */
535
   unsigned start;  /**< the index of the first vertex */
536
   unsigned count;  /**< number of vertices */
537
 
538
   unsigned start_instance; /**< first instance id */
539
   unsigned instance_count; /**< number of instances */
540
 
541
   /**
542
    * For indexed drawing, these fields apply after index lookup.
543
    */
544
   int index_bias; /**< a bias to be added to each index */
545
   unsigned min_index; /**< the min index */
546
   unsigned max_index; /**< the max index */
547
 
548
   /**
549
    * Primitive restart enable/index (only applies to indexed drawing)
550
    */
551
   boolean primitive_restart;
552
   unsigned restart_index;
553
 
554
   /**
555
    * Stream output target. If not NULL, it's used to provide the 'count'
556
    * parameter based on the number vertices captured by the stream output
557
    * stage. (or generally, based on the number of bytes captured)
558
    *
559
    * Only 'mode', 'start_instance', and 'instance_count' are taken into
560
    * account, all the other variables from pipe_draw_info are ignored.
561
    *
562
    * 'start' is implicitly 0 and 'count' is set as discussed above.
563
    * The draw command is non-indexed.
564
    *
565
    * Note that this only provides the count. The vertex buffers must
566
    * be set via set_vertex_buffers manually.
567
    */
568
   struct pipe_stream_output_target *count_from_stream_output;
569
};
570
 
571
 
572
/**
573
 * Information to describe a blit call.
574
 */
575
struct pipe_blit_info
576
{
577
   struct {
578
      struct pipe_resource *resource;
579
      unsigned level;
580
      struct pipe_box box; /**< negative width, height only legal for src */
581
      /* For pipe_surface-like format casting: */
582
      enum pipe_format format; /**< must be supported for sampling (src)
583
                               or rendering (dst), ZS is always supported */
584
   } dst, src;
585
 
586
   unsigned mask; /**< bitmask of PIPE_MASK_R/G/B/A/Z/S */
587
   unsigned filter; /**< PIPE_TEX_FILTER_* */
588
 
589
   boolean scissor_enable;
590
   struct pipe_scissor_state scissor;
591
};
592
 
593
 
594
/**
595
 * Structure used as a header for serialized LLVM programs.
596
 */
597
struct pipe_llvm_program_header
598
{
599
   uint32_t num_bytes; /**< Number of bytes in the LLVM bytecode program. */
600
};
601
 
602
struct pipe_compute_state
603
{
604
   const void *prog; /**< Compute program to be executed. */
605
   unsigned req_local_mem; /**< Required size of the LOCAL resource. */
606
   unsigned req_private_mem; /**< Required size of the PRIVATE resource. */
607
   unsigned req_input_mem; /**< Required size of the INPUT resource. */
608
};
609
 
610
#ifdef __cplusplus
611
}
612
#endif
613
 
614
#endif