p_shader_tokens.h revision d4ef0f6c67aefe06d8dd647acf8d9005df39a709
1/**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2009-2010 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29#ifndef P_SHADER_TOKENS_H
30#define P_SHADER_TOKENS_H
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#include "p_compiler.h"
37
38
39struct tgsi_header
40{
41   unsigned HeaderSize : 8;
42   unsigned BodySize   : 24;
43};
44
45#define TGSI_PROCESSOR_FRAGMENT  0
46#define TGSI_PROCESSOR_VERTEX    1
47#define TGSI_PROCESSOR_GEOMETRY  2
48
49struct tgsi_processor
50{
51   unsigned Processor  : 4;  /* TGSI_PROCESSOR_ */
52   unsigned Padding    : 28;
53};
54
55#define TGSI_TOKEN_TYPE_DECLARATION    0
56#define TGSI_TOKEN_TYPE_IMMEDIATE      1
57#define TGSI_TOKEN_TYPE_INSTRUCTION    2
58#define TGSI_TOKEN_TYPE_PROPERTY       3
59
60struct tgsi_token
61{
62   unsigned Type       : 4;  /**< TGSI_TOKEN_TYPE_x */
63   unsigned NrTokens   : 8;  /**< UINT */
64   unsigned Padding    : 20;
65};
66
67enum tgsi_file_type {
68   TGSI_FILE_NULL         =0,
69   TGSI_FILE_CONSTANT     =1,
70   TGSI_FILE_INPUT        =2,
71   TGSI_FILE_OUTPUT       =3,
72   TGSI_FILE_TEMPORARY    =4,
73   TGSI_FILE_SAMPLER      =5,
74   TGSI_FILE_ADDRESS      =6,
75   TGSI_FILE_IMMEDIATE    =7,
76   TGSI_FILE_PREDICATE    =8,
77   TGSI_FILE_SYSTEM_VALUE =9,
78   TGSI_FILE_COUNT      /**< how many TGSI_FILE_ types */
79};
80
81
82#define TGSI_WRITEMASK_NONE     0x00
83#define TGSI_WRITEMASK_X        0x01
84#define TGSI_WRITEMASK_Y        0x02
85#define TGSI_WRITEMASK_XY       0x03
86#define TGSI_WRITEMASK_Z        0x04
87#define TGSI_WRITEMASK_XZ       0x05
88#define TGSI_WRITEMASK_YZ       0x06
89#define TGSI_WRITEMASK_XYZ      0x07
90#define TGSI_WRITEMASK_W        0x08
91#define TGSI_WRITEMASK_XW       0x09
92#define TGSI_WRITEMASK_YW       0x0A
93#define TGSI_WRITEMASK_XYW      0x0B
94#define TGSI_WRITEMASK_ZW       0x0C
95#define TGSI_WRITEMASK_XZW      0x0D
96#define TGSI_WRITEMASK_YZW      0x0E
97#define TGSI_WRITEMASK_XYZW     0x0F
98
99#define TGSI_INTERPOLATE_CONSTANT      0
100#define TGSI_INTERPOLATE_LINEAR        1
101#define TGSI_INTERPOLATE_PERSPECTIVE   2
102#define TGSI_INTERPOLATE_COUNT         3
103
104#define TGSI_CYLINDRICAL_WRAP_X (1 << 0)
105#define TGSI_CYLINDRICAL_WRAP_Y (1 << 1)
106#define TGSI_CYLINDRICAL_WRAP_Z (1 << 2)
107#define TGSI_CYLINDRICAL_WRAP_W (1 << 3)
108
109struct tgsi_declaration
110{
111   unsigned Type        : 4;  /**< TGSI_TOKEN_TYPE_DECLARATION */
112   unsigned NrTokens    : 8;  /**< UINT */
113   unsigned File        : 4;  /**< one of TGSI_FILE_x */
114   unsigned UsageMask   : 4;  /**< bitmask of TGSI_WRITEMASK_x flags */
115   unsigned Interpolate : 4;  /**< one of TGSI_INTERPOLATE_x */
116   unsigned Dimension   : 1;  /**< any extra dimension info? */
117   unsigned Semantic    : 1;  /**< BOOL, any semantic info? */
118   unsigned Centroid    : 1;  /**< centroid sampling? */
119   unsigned Invariant   : 1;  /**< invariant optimization? */
120   unsigned CylindricalWrap:4;   /**< TGSI_CYLINDRICAL_WRAP_x flags */
121};
122
123struct tgsi_declaration_range
124{
125   unsigned First   : 16; /**< UINT */
126   unsigned Last    : 16; /**< UINT */
127};
128
129struct tgsi_declaration_dimension
130{
131   unsigned Index2D:16; /**< UINT */
132   unsigned Padding:16;
133};
134
135#define TGSI_SEMANTIC_POSITION   0
136#define TGSI_SEMANTIC_COLOR      1
137#define TGSI_SEMANTIC_BCOLOR     2  /**< back-face color */
138#define TGSI_SEMANTIC_FOG        3
139#define TGSI_SEMANTIC_PSIZE      4
140#define TGSI_SEMANTIC_GENERIC    5
141#define TGSI_SEMANTIC_NORMAL     6
142#define TGSI_SEMANTIC_FACE       7
143#define TGSI_SEMANTIC_EDGEFLAG   8
144#define TGSI_SEMANTIC_PRIMID     9
145#define TGSI_SEMANTIC_INSTANCEID 10
146#define TGSI_SEMANTIC_COUNT      11 /**< number of semantic values */
147
148struct tgsi_declaration_semantic
149{
150   unsigned Name           : 8;  /**< one of TGSI_SEMANTIC_x */
151   unsigned Index          : 16; /**< UINT */
152   unsigned Padding        : 8;
153};
154
155#define TGSI_IMM_FLOAT32   0
156#define TGSI_IMM_UINT32    1
157#define TGSI_IMM_INT32     2
158
159struct tgsi_immediate
160{
161   unsigned Type       : 4;  /**< TGSI_TOKEN_TYPE_IMMEDIATE */
162   unsigned NrTokens   : 8;  /**< UINT */
163   unsigned DataType   : 4;  /**< one of TGSI_IMM_x */
164   unsigned Padding    : 16;
165};
166
167union tgsi_immediate_data
168{
169   float Float;
170   unsigned Uint;
171   int Int;
172};
173
174#define TGSI_PROPERTY_GS_INPUT_PRIM          0
175#define TGSI_PROPERTY_GS_OUTPUT_PRIM         1
176#define TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES 2
177#define TGSI_PROPERTY_FS_COORD_ORIGIN        3
178#define TGSI_PROPERTY_FS_COORD_PIXEL_CENTER  4
179#define TGSI_PROPERTY_COUNT                  5
180
181struct tgsi_property {
182   unsigned Type         : 4;  /**< TGSI_TOKEN_TYPE_PROPERTY */
183   unsigned NrTokens     : 8;  /**< UINT */
184   unsigned PropertyName : 8;  /**< one of TGSI_PROPERTY */
185   unsigned Padding      : 12;
186};
187
188#define TGSI_FS_COORD_ORIGIN_UPPER_LEFT 0
189#define TGSI_FS_COORD_ORIGIN_LOWER_LEFT 1
190
191#define TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER 0
192#define TGSI_FS_COORD_PIXEL_CENTER_INTEGER 1
193
194struct tgsi_property_data {
195   unsigned Data;
196};
197
198/* TGSI opcodes.
199 *
200 * For more information on semantics of opcodes and
201 * which APIs are known to use which opcodes, see
202 * auxiliary/tgsi/tgsi-instruction-set.txt
203 */
204#define TGSI_OPCODE_ARL                 0
205#define TGSI_OPCODE_MOV                 1
206#define TGSI_OPCODE_LIT                 2
207#define TGSI_OPCODE_RCP                 3
208#define TGSI_OPCODE_RSQ                 4
209#define TGSI_OPCODE_EXP                 5
210#define TGSI_OPCODE_LOG                 6
211#define TGSI_OPCODE_MUL                 7
212#define TGSI_OPCODE_ADD                 8
213#define TGSI_OPCODE_DP3                 9
214#define TGSI_OPCODE_DP4                 10
215#define TGSI_OPCODE_DST                 11
216#define TGSI_OPCODE_MIN                 12
217#define TGSI_OPCODE_MAX                 13
218#define TGSI_OPCODE_SLT                 14
219#define TGSI_OPCODE_SGE                 15
220#define TGSI_OPCODE_MAD                 16
221#define TGSI_OPCODE_SUB                 17
222#define TGSI_OPCODE_LRP                 18
223#define TGSI_OPCODE_CND                 19
224                                /* gap */
225#define TGSI_OPCODE_DP2A                21
226                                /* gap */
227#define TGSI_OPCODE_FRC                 24
228#define TGSI_OPCODE_CLAMP               25
229#define TGSI_OPCODE_FLR                 26
230#define TGSI_OPCODE_ROUND               27
231#define TGSI_OPCODE_EX2                 28
232#define TGSI_OPCODE_LG2                 29
233#define TGSI_OPCODE_POW                 30
234#define TGSI_OPCODE_XPD                 31
235                                /* gap */
236#define TGSI_OPCODE_ABS                 33
237#define TGSI_OPCODE_RCC                 34
238#define TGSI_OPCODE_DPH                 35
239#define TGSI_OPCODE_COS                 36
240#define TGSI_OPCODE_DDX                 37
241#define TGSI_OPCODE_DDY                 38
242#define TGSI_OPCODE_KILP                39  /* predicated kill */
243#define TGSI_OPCODE_PK2H                40
244#define TGSI_OPCODE_PK2US               41
245#define TGSI_OPCODE_PK4B                42
246#define TGSI_OPCODE_PK4UB               43
247#define TGSI_OPCODE_RFL                 44
248#define TGSI_OPCODE_SEQ                 45
249#define TGSI_OPCODE_SFL                 46
250#define TGSI_OPCODE_SGT                 47
251#define TGSI_OPCODE_SIN                 48
252#define TGSI_OPCODE_SLE                 49
253#define TGSI_OPCODE_SNE                 50
254#define TGSI_OPCODE_STR                 51
255#define TGSI_OPCODE_TEX                 52
256#define TGSI_OPCODE_TXD                 53
257#define TGSI_OPCODE_TXP                 54
258#define TGSI_OPCODE_UP2H                55
259#define TGSI_OPCODE_UP2US               56
260#define TGSI_OPCODE_UP4B                57
261#define TGSI_OPCODE_UP4UB               58
262#define TGSI_OPCODE_X2D                 59
263#define TGSI_OPCODE_ARA                 60
264#define TGSI_OPCODE_ARR                 61
265#define TGSI_OPCODE_BRA                 62
266#define TGSI_OPCODE_CAL                 63
267#define TGSI_OPCODE_RET                 64
268#define TGSI_OPCODE_SSG                 65 /* SGN */
269#define TGSI_OPCODE_CMP                 66
270#define TGSI_OPCODE_SCS                 67
271#define TGSI_OPCODE_TXB                 68
272#define TGSI_OPCODE_NRM                 69
273#define TGSI_OPCODE_DIV                 70
274#define TGSI_OPCODE_DP2                 71
275#define TGSI_OPCODE_TXL                 72
276#define TGSI_OPCODE_BRK                 73
277#define TGSI_OPCODE_IF                  74
278                                /* gap */
279#define TGSI_OPCODE_ELSE                77
280#define TGSI_OPCODE_ENDIF               78
281                                /* gap */
282#define TGSI_OPCODE_PUSHA               81
283#define TGSI_OPCODE_POPA                82
284#define TGSI_OPCODE_CEIL                83
285#define TGSI_OPCODE_I2F                 84
286#define TGSI_OPCODE_NOT                 85
287#define TGSI_OPCODE_TRUNC               86
288#define TGSI_OPCODE_SHL                 87
289                                /* gap */
290#define TGSI_OPCODE_AND                 89
291#define TGSI_OPCODE_OR                  90
292#define TGSI_OPCODE_MOD                 91
293#define TGSI_OPCODE_XOR                 92
294#define TGSI_OPCODE_SAD                 93
295#define TGSI_OPCODE_TXF                 94
296#define TGSI_OPCODE_TXQ                 95
297#define TGSI_OPCODE_CONT                96
298#define TGSI_OPCODE_EMIT                97
299#define TGSI_OPCODE_ENDPRIM             98
300#define TGSI_OPCODE_BGNLOOP             99
301#define TGSI_OPCODE_BGNSUB              100
302#define TGSI_OPCODE_ENDLOOP             101
303#define TGSI_OPCODE_ENDSUB              102
304                                /* gap */
305#define TGSI_OPCODE_NOP                 107
306                                /* gap */
307#define TGSI_OPCODE_NRM4                112
308#define TGSI_OPCODE_CALLNZ              113
309#define TGSI_OPCODE_IFC                 114
310#define TGSI_OPCODE_BREAKC              115
311#define TGSI_OPCODE_KIL                 116  /* conditional kill */
312#define TGSI_OPCODE_END                 117  /* aka HALT */
313                                /* gap */
314#define TGSI_OPCODE_F2I                 119
315#define TGSI_OPCODE_IDIV                120
316#define TGSI_OPCODE_IMAX                121
317#define TGSI_OPCODE_IMIN                122
318#define TGSI_OPCODE_INEG                123
319#define TGSI_OPCODE_ISGE                124
320#define TGSI_OPCODE_ISHR                125
321#define TGSI_OPCODE_ISLT                126
322#define TGSI_OPCODE_F2U                 127
323#define TGSI_OPCODE_U2F                 128
324#define TGSI_OPCODE_UADD                129
325#define TGSI_OPCODE_UDIV                130
326#define TGSI_OPCODE_UMAD                131
327#define TGSI_OPCODE_UMAX                132
328#define TGSI_OPCODE_UMIN                133
329#define TGSI_OPCODE_UMOD                134
330#define TGSI_OPCODE_UMUL                135
331#define TGSI_OPCODE_USEQ                136
332#define TGSI_OPCODE_USGE                137
333#define TGSI_OPCODE_USHR                138
334#define TGSI_OPCODE_USLT                139
335#define TGSI_OPCODE_USNE                140
336#define TGSI_OPCODE_SWITCH              141
337#define TGSI_OPCODE_CASE                142
338#define TGSI_OPCODE_DEFAULT             143
339#define TGSI_OPCODE_ENDSWITCH           144
340#define TGSI_OPCODE_LAST                145
341
342#define TGSI_SAT_NONE            0  /* do not saturate */
343#define TGSI_SAT_ZERO_ONE        1  /* clamp to [0,1] */
344#define TGSI_SAT_MINUS_PLUS_ONE  2  /* clamp to [-1,1] */
345
346/**
347 * Opcode is the operation code to execute. A given operation defines the
348 * semantics how the source registers (if any) are interpreted and what is
349 * written to the destination registers (if any) as a result of execution.
350 *
351 * NumDstRegs and NumSrcRegs is the number of destination and source registers,
352 * respectively. For a given operation code, those numbers are fixed and are
353 * present here only for convenience.
354 *
355 * If Predicate is TRUE, tgsi_instruction_predicate token immediately follows.
356 *
357 * Saturate controls how are final results in destination registers modified.
358 */
359
360struct tgsi_instruction
361{
362   unsigned Type       : 4;  /* TGSI_TOKEN_TYPE_INSTRUCTION */
363   unsigned NrTokens   : 8;  /* UINT */
364   unsigned Opcode     : 8;  /* TGSI_OPCODE_ */
365   unsigned Saturate   : 2;  /* TGSI_SAT_ */
366   unsigned NumDstRegs : 2;  /* UINT */
367   unsigned NumSrcRegs : 4;  /* UINT */
368   unsigned Predicate  : 1;  /* BOOL */
369   unsigned Label      : 1;
370   unsigned Texture    : 1;
371   unsigned Padding    : 1;
372};
373
374/*
375 * If tgsi_instruction::Label is TRUE, tgsi_instruction_label follows.
376 *
377 * If tgsi_instruction::Texture is TRUE, tgsi_instruction_texture follows.
378 *
379 * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow.
380 *
381 * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow.
382 *
383 * tgsi_instruction::NrTokens contains the total number of words that make the
384 * instruction, including the instruction word.
385 */
386
387#define TGSI_SWIZZLE_X      0
388#define TGSI_SWIZZLE_Y      1
389#define TGSI_SWIZZLE_Z      2
390#define TGSI_SWIZZLE_W      3
391
392struct tgsi_instruction_label
393{
394   unsigned Label    : 24;   /* UINT */
395   unsigned Padding  : 8;
396};
397
398#define TGSI_TEXTURE_UNKNOWN        0
399#define TGSI_TEXTURE_1D             1
400#define TGSI_TEXTURE_2D             2
401#define TGSI_TEXTURE_3D             3
402#define TGSI_TEXTURE_CUBE           4
403#define TGSI_TEXTURE_RECT           5
404#define TGSI_TEXTURE_SHADOW1D       6
405#define TGSI_TEXTURE_SHADOW2D       7
406#define TGSI_TEXTURE_SHADOWRECT     8
407#define TGSI_TEXTURE_COUNT          9
408
409struct tgsi_instruction_texture
410{
411   unsigned Texture  : 8;    /* TGSI_TEXTURE_ */
412   unsigned Padding  : 24;
413};
414
415/*
416 * For SM3, the following constraint applies.
417 *   - Swizzle is either set to identity or replicate.
418 */
419struct tgsi_instruction_predicate
420{
421   int      Index    : 16; /* SINT */
422   unsigned SwizzleX : 2;  /* TGSI_SWIZZLE_x */
423   unsigned SwizzleY : 2;  /* TGSI_SWIZZLE_x */
424   unsigned SwizzleZ : 2;  /* TGSI_SWIZZLE_x */
425   unsigned SwizzleW : 2;  /* TGSI_SWIZZLE_x */
426   unsigned Negate   : 1;  /* BOOL */
427   unsigned Padding  : 7;
428};
429
430/**
431 * File specifies the register array to access.
432 *
433 * Index specifies the element number of a register in the register file.
434 *
435 * If Indirect is TRUE, Index should be offset by the X component of a source
436 * register that follows. The register can be now fetched into local storage
437 * for further processing.
438 *
439 * If Negate is TRUE, all components of the fetched register are negated.
440 *
441 * The fetched register components are swizzled according to SwizzleX, SwizzleY,
442 * SwizzleZ and SwizzleW.
443 *
444 */
445
446struct tgsi_src_register
447{
448   unsigned File        : 4;  /* TGSI_FILE_ */
449   unsigned Indirect    : 1;  /* BOOL */
450   unsigned Dimension   : 1;  /* BOOL */
451   int      Index       : 16; /* SINT */
452   unsigned SwizzleX    : 2;  /* TGSI_SWIZZLE_ */
453   unsigned SwizzleY    : 2;  /* TGSI_SWIZZLE_ */
454   unsigned SwizzleZ    : 2;  /* TGSI_SWIZZLE_ */
455   unsigned SwizzleW    : 2;  /* TGSI_SWIZZLE_ */
456   unsigned Absolute    : 1;    /* BOOL */
457   unsigned Negate      : 1;    /* BOOL */
458};
459
460/**
461 * If tgsi_src_register::Modifier is TRUE, tgsi_src_register_modifier follows.
462 *
463 * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register
464 * follows.
465 *
466 * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows.
467 */
468
469
470struct tgsi_dimension
471{
472   unsigned Indirect    : 1;  /* BOOL */
473   unsigned Dimension   : 1;  /* BOOL */
474   unsigned Padding     : 14;
475   int      Index       : 16; /* SINT */
476};
477
478struct tgsi_dst_register
479{
480   unsigned File        : 4;  /* TGSI_FILE_ */
481   unsigned WriteMask   : 4;  /* TGSI_WRITEMASK_ */
482   unsigned Indirect    : 1;  /* BOOL */
483   unsigned Dimension   : 1;  /* BOOL */
484   int      Index       : 16; /* SINT */
485   unsigned Padding     : 6;
486};
487
488
489#ifdef __cplusplus
490}
491#endif
492
493#endif /* P_SHADER_TOKENS_H */
494