1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
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.
27 **************************************************************************/
29 #ifndef P_SHADER_TOKENS_H
30 #define P_SHADER_TOKENS_H
36 #include "p_compiler.h"
40 unsigned MajorVersion
: 8;
41 unsigned MinorVersion
: 8;
42 unsigned Padding
: 16;
47 unsigned HeaderSize
: 8;
48 unsigned BodySize
: 24;
51 #define TGSI_PROCESSOR_FRAGMENT 0
52 #define TGSI_PROCESSOR_VERTEX 1
53 #define TGSI_PROCESSOR_GEOMETRY 2
57 unsigned Processor
: 4; /* TGSI_PROCESSOR_ */
58 unsigned Padding
: 28;
61 #define TGSI_TOKEN_TYPE_DECLARATION 0
62 #define TGSI_TOKEN_TYPE_IMMEDIATE 1
63 #define TGSI_TOKEN_TYPE_INSTRUCTION 2
67 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_x */
68 unsigned NrTokens
: 8; /**< UINT */
69 unsigned Padding
: 19;
70 unsigned Extended
: 1; /**< BOOL */
75 TGSI_FILE_CONSTANT
=1,
78 TGSI_FILE_TEMPORARY
=4,
81 TGSI_FILE_IMMEDIATE
=7,
83 TGSI_FILE_PREDICATE
=9,
84 TGSI_FILE_COUNT
/**< how many TGSI_FILE_ types */
88 #define TGSI_WRITEMASK_NONE 0x00
89 #define TGSI_WRITEMASK_X 0x01
90 #define TGSI_WRITEMASK_Y 0x02
91 #define TGSI_WRITEMASK_XY 0x03
92 #define TGSI_WRITEMASK_Z 0x04
93 #define TGSI_WRITEMASK_XZ 0x05
94 #define TGSI_WRITEMASK_YZ 0x06
95 #define TGSI_WRITEMASK_XYZ 0x07
96 #define TGSI_WRITEMASK_W 0x08
97 #define TGSI_WRITEMASK_XW 0x09
98 #define TGSI_WRITEMASK_YW 0x0A
99 #define TGSI_WRITEMASK_XYW 0x0B
100 #define TGSI_WRITEMASK_ZW 0x0C
101 #define TGSI_WRITEMASK_XZW 0x0D
102 #define TGSI_WRITEMASK_YZW 0x0E
103 #define TGSI_WRITEMASK_XYZW 0x0F
105 #define TGSI_INTERPOLATE_CONSTANT 0
106 #define TGSI_INTERPOLATE_LINEAR 1
107 #define TGSI_INTERPOLATE_PERSPECTIVE 2
108 #define TGSI_INTERPOLATE_COUNT 3
110 struct tgsi_declaration
112 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_DECLARATION */
113 unsigned NrTokens
: 8; /**< UINT */
114 unsigned File
: 4; /**< one of TGSI_FILE_x */
115 unsigned UsageMask
: 4; /**< bitmask of TGSI_WRITEMASK_x flags */
116 unsigned Interpolate
: 4; /**< one of TGSI_INTERPOLATE_x */
117 unsigned Semantic
: 1; /**< BOOL, any semantic info? */
118 unsigned Centroid
: 1; /**< centroid sampling? */
119 unsigned Invariant
: 1; /**< invariant optimization? */
120 unsigned Padding
: 4;
121 unsigned Extended
: 1; /**< BOOL */
124 struct tgsi_declaration_range
126 unsigned First
: 16; /**< UINT */
127 unsigned Last
: 16; /**< UINT */
130 #define TGSI_SEMANTIC_POSITION 0
131 #define TGSI_SEMANTIC_COLOR 1
132 #define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */
133 #define TGSI_SEMANTIC_FOG 3
134 #define TGSI_SEMANTIC_PSIZE 4
135 #define TGSI_SEMANTIC_GENERIC 5
136 #define TGSI_SEMANTIC_NORMAL 6
137 #define TGSI_SEMANTIC_FACE 7
138 #define TGSI_SEMANTIC_COUNT 8 /**< number of semantic values */
140 struct tgsi_declaration_semantic
142 unsigned SemanticName
: 8; /**< one of TGSI_SEMANTIC_x */
143 unsigned SemanticIndex
: 16; /**< UINT */
144 unsigned Padding
: 8;
147 #define TGSI_IMM_FLOAT32 0
149 struct tgsi_immediate
151 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_IMMEDIATE */
152 unsigned NrTokens
: 8; /**< UINT */
153 unsigned DataType
: 4; /**< one of TGSI_IMM_x */
154 unsigned Padding
: 15;
155 unsigned Extended
: 1; /**< BOOL */
158 union tgsi_immediate_data
165 * For more information on semantics of opcodes and
166 * which APIs are known to use which opcodes, see
167 * auxiliary/tgsi/tgsi-instruction-set.txt
169 #define TGSI_OPCODE_ARL 0
170 #define TGSI_OPCODE_MOV 1
171 #define TGSI_OPCODE_LIT 2
172 #define TGSI_OPCODE_RCP 3
173 #define TGSI_OPCODE_RSQ 4
174 #define TGSI_OPCODE_EXP 5
175 #define TGSI_OPCODE_LOG 6
176 #define TGSI_OPCODE_MUL 7
177 #define TGSI_OPCODE_ADD 8
178 #define TGSI_OPCODE_DP3 9
179 #define TGSI_OPCODE_DP4 10
180 #define TGSI_OPCODE_DST 11
181 #define TGSI_OPCODE_MIN 12
182 #define TGSI_OPCODE_MAX 13
183 #define TGSI_OPCODE_SLT 14
184 #define TGSI_OPCODE_SGE 15
185 #define TGSI_OPCODE_MAD 16
186 #define TGSI_OPCODE_SUB 17
187 #define TGSI_OPCODE_LRP 18
188 #define TGSI_OPCODE_CND 19
190 #define TGSI_OPCODE_DP2A 21
192 #define TGSI_OPCODE_FRC 24
193 #define TGSI_OPCODE_CLAMP 25
194 #define TGSI_OPCODE_FLR 26
195 #define TGSI_OPCODE_ROUND 27
196 #define TGSI_OPCODE_EX2 28
197 #define TGSI_OPCODE_LG2 29
198 #define TGSI_OPCODE_POW 30
199 #define TGSI_OPCODE_XPD 31
201 #define TGSI_OPCODE_ABS 33
202 #define TGSI_OPCODE_RCC 34
203 #define TGSI_OPCODE_DPH 35
204 #define TGSI_OPCODE_COS 36
205 #define TGSI_OPCODE_DDX 37
206 #define TGSI_OPCODE_DDY 38
207 #define TGSI_OPCODE_KILP 39 /* predicated kill */
208 #define TGSI_OPCODE_PK2H 40
209 #define TGSI_OPCODE_PK2US 41
210 #define TGSI_OPCODE_PK4B 42
211 #define TGSI_OPCODE_PK4UB 43
212 #define TGSI_OPCODE_RFL 44
213 #define TGSI_OPCODE_SEQ 45
214 #define TGSI_OPCODE_SFL 46
215 #define TGSI_OPCODE_SGT 47
216 #define TGSI_OPCODE_SIN 48
217 #define TGSI_OPCODE_SLE 49
218 #define TGSI_OPCODE_SNE 50
219 #define TGSI_OPCODE_STR 51
220 #define TGSI_OPCODE_TEX 52
221 #define TGSI_OPCODE_TXD 53
222 #define TGSI_OPCODE_TXP 54
223 #define TGSI_OPCODE_UP2H 55
224 #define TGSI_OPCODE_UP2US 56
225 #define TGSI_OPCODE_UP4B 57
226 #define TGSI_OPCODE_UP4UB 58
227 #define TGSI_OPCODE_X2D 59
228 #define TGSI_OPCODE_ARA 60
229 #define TGSI_OPCODE_ARR 61
230 #define TGSI_OPCODE_BRA 62
231 #define TGSI_OPCODE_CAL 63
232 #define TGSI_OPCODE_RET 64
233 #define TGSI_OPCODE_SSG 65 /* SGN */
234 #define TGSI_OPCODE_CMP 66
235 #define TGSI_OPCODE_SCS 67
236 #define TGSI_OPCODE_TXB 68
237 #define TGSI_OPCODE_NRM 69
238 #define TGSI_OPCODE_DIV 70
239 #define TGSI_OPCODE_DP2 71
240 #define TGSI_OPCODE_TXL 72
241 #define TGSI_OPCODE_BRK 73
242 #define TGSI_OPCODE_IF 74
243 #define TGSI_OPCODE_BGNFOR 75
244 #define TGSI_OPCODE_REP 76
245 #define TGSI_OPCODE_ELSE 77
246 #define TGSI_OPCODE_ENDIF 78
247 #define TGSI_OPCODE_ENDFOR 79
248 #define TGSI_OPCODE_ENDREP 80
249 #define TGSI_OPCODE_PUSHA 81
250 #define TGSI_OPCODE_POPA 82
251 #define TGSI_OPCODE_CEIL 83
252 #define TGSI_OPCODE_I2F 84
253 #define TGSI_OPCODE_NOT 85
254 #define TGSI_OPCODE_TRUNC 86
255 #define TGSI_OPCODE_SHL 87
256 #define TGSI_OPCODE_SHR 88
257 #define TGSI_OPCODE_AND 89
258 #define TGSI_OPCODE_OR 90
259 #define TGSI_OPCODE_MOD 91
260 #define TGSI_OPCODE_XOR 92
261 #define TGSI_OPCODE_SAD 93
262 #define TGSI_OPCODE_TXF 94
263 #define TGSI_OPCODE_TXQ 95
264 #define TGSI_OPCODE_CONT 96
265 #define TGSI_OPCODE_EMIT 97
266 #define TGSI_OPCODE_ENDPRIM 98
267 #define TGSI_OPCODE_BGNLOOP 99
268 #define TGSI_OPCODE_BGNSUB 100
269 #define TGSI_OPCODE_ENDLOOP 101
270 #define TGSI_OPCODE_ENDSUB 102
272 #define TGSI_OPCODE_NOP 107
274 #define TGSI_OPCODE_NRM4 112
275 #define TGSI_OPCODE_CALLNZ 113
276 #define TGSI_OPCODE_IFC 114
277 #define TGSI_OPCODE_BREAKC 115
278 #define TGSI_OPCODE_KIL 116 /* conditional kill */
279 #define TGSI_OPCODE_END 117 /* aka HALT */
281 #define TGSI_OPCODE_LAST 119
283 #define TGSI_SAT_NONE 0 /* do not saturate */
284 #define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */
285 #define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */
288 * Opcode is the operation code to execute. A given operation defines the
289 * semantics how the source registers (if any) are interpreted and what is
290 * written to the destination registers (if any) as a result of execution.
292 * NumDstRegs and NumSrcRegs is the number of destination and source registers,
293 * respectively. For a given operation code, those numbers are fixed and are
294 * present here only for convenience.
296 * If Predicate is TRUE, tgsi_instruction_predicate token immediately follows.
298 * If Extended is TRUE, it is now executed.
300 * Saturate controls how are final results in destination registers modified.
303 struct tgsi_instruction
305 unsigned Type
: 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */
306 unsigned NrTokens
: 8; /* UINT */
307 unsigned Opcode
: 8; /* TGSI_OPCODE_ */
308 unsigned Saturate
: 2; /* TGSI_SAT_ */
309 unsigned NumDstRegs
: 2; /* UINT */
310 unsigned NumSrcRegs
: 4; /* UINT */
311 unsigned Predicate
: 1; /* BOOL */
312 unsigned Padding
: 2;
313 unsigned Extended
: 1; /* BOOL */
317 * If tgsi_instruction::Extended is TRUE, tgsi_instruction_ext follows.
319 * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow.
321 * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow.
323 * tgsi_instruction::NrTokens contains the total number of words that make the
324 * instruction, including the instruction word.
327 #define TGSI_INSTRUCTION_EXT_TYPE_LABEL 1
328 #define TGSI_INSTRUCTION_EXT_TYPE_TEXTURE 2
330 struct tgsi_instruction_ext
332 unsigned Type
: 4; /* TGSI_INSTRUCTION_EXT_TYPE_ */
333 unsigned Padding
: 27;
334 unsigned Extended
: 1; /* BOOL */
338 * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_LABEL, it
339 * should be cast to tgsi_instruction_ext_label.
341 * If tgsi_instruction_ext::Type is TGSI_INSTRUCTION_EXT_TYPE_TEXTURE, it
342 * should be cast to tgsi_instruction_ext_texture.
344 * If tgsi_instruction_ext::Extended is TRUE, another tgsi_instruction_ext
348 #define TGSI_SWIZZLE_X 0
349 #define TGSI_SWIZZLE_Y 1
350 #define TGSI_SWIZZLE_Z 2
351 #define TGSI_SWIZZLE_W 3
353 struct tgsi_instruction_ext_label
355 unsigned Type
: 4; /* TGSI_INSTRUCTION_EXT_TYPE_LABEL */
356 unsigned Label
: 24; /* UINT */
357 unsigned Padding
: 3;
358 unsigned Extended
: 1; /* BOOL */
361 #define TGSI_TEXTURE_UNKNOWN 0
362 #define TGSI_TEXTURE_1D 1
363 #define TGSI_TEXTURE_2D 2
364 #define TGSI_TEXTURE_3D 3
365 #define TGSI_TEXTURE_CUBE 4
366 #define TGSI_TEXTURE_RECT 5
367 #define TGSI_TEXTURE_SHADOW1D 6
368 #define TGSI_TEXTURE_SHADOW2D 7
369 #define TGSI_TEXTURE_SHADOWRECT 8
370 #define TGSI_TEXTURE_COUNT 9
372 struct tgsi_instruction_ext_texture
374 unsigned Type
: 4; /* TGSI_INSTRUCTION_EXT_TYPE_TEXTURE */
375 unsigned Texture
: 8; /* TGSI_TEXTURE_ */
376 unsigned Padding
: 19;
377 unsigned Extended
: 1; /* BOOL */
381 * For SM3, the following constraint applies.
382 * - Swizzle is either set to identity or replicate.
384 struct tgsi_instruction_predicate
386 int Index
: 16; /* SINT */
387 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_x */
388 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_x */
389 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_x */
390 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_x */
391 unsigned Negate
: 1; /* BOOL */
392 unsigned Padding
: 7;
396 * File specifies the register array to access.
398 * Index specifies the element number of a register in the register file.
400 * If Indirect is TRUE, Index should be offset by the X component of a source
401 * register that follows. The register can be now fetched into local storage
402 * for further processing.
404 * If Negate is TRUE, all components of the fetched register are negated.
406 * The fetched register components are swizzled according to SwizzleX, SwizzleY,
407 * SwizzleZ and SwizzleW.
409 * If Extended is TRUE, any further modifications to the source register are
410 * made to this temporary storage.
413 struct tgsi_src_register
415 unsigned File
: 4; /* TGSI_FILE_ */
416 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_ */
417 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_ */
418 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_ */
419 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_ */
420 unsigned Negate
: 1; /* BOOL */
421 unsigned Indirect
: 1; /* BOOL */
422 unsigned Dimension
: 1; /* BOOL */
423 int Index
: 16; /* SINT */
424 unsigned Extended
: 1; /* BOOL */
428 * If tgsi_src_register::Extended is TRUE, tgsi_src_register_ext follows.
430 * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register
433 * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows.
436 #define TGSI_SRC_REGISTER_EXT_TYPE_MOD 1
438 struct tgsi_src_register_ext
440 unsigned Type
: 4; /* TGSI_SRC_REGISTER_EXT_TYPE_ */
441 unsigned Padding
: 27;
442 unsigned Extended
: 1; /* BOOL */
446 * If tgsi_src_register_ext::Type is TGSI_SRC_REGISTER_EXT_TYPE_MOD,
447 * it should be cast to tgsi_src_register_ext_mod.
449 * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext
455 * Extra src register modifiers
457 * If Complement is TRUE, the source register is modified by subtracting it
460 * If Bias is TRUE, the source register is modified by subtracting 0.5 from it.
462 * If Scale2X is TRUE, the source register is modified by multiplying it by 2.0.
464 * If Absolute is TRUE, the source register is modified by removing the sign.
466 * If Negate is TRUE, the source register is modified by negating it.
469 struct tgsi_src_register_ext_mod
471 unsigned Type
: 4; /* TGSI_SRC_REGISTER_EXT_TYPE_MOD */
472 unsigned Complement
: 1; /* BOOL */
473 unsigned Bias
: 1; /* BOOL */
474 unsigned Scale2X
: 1; /* BOOL */
475 unsigned Absolute
: 1; /* BOOL */
476 unsigned Negate
: 1; /* BOOL */
477 unsigned Padding
: 22;
478 unsigned Extended
: 1; /* BOOL */
481 struct tgsi_dimension
483 unsigned Indirect
: 1; /* BOOL */
484 unsigned Dimension
: 1; /* BOOL */
485 unsigned Padding
: 13;
486 int Index
: 16; /* SINT */
487 unsigned Extended
: 1; /* BOOL */
490 struct tgsi_dst_register
492 unsigned File
: 4; /* TGSI_FILE_ */
493 unsigned WriteMask
: 4; /* TGSI_WRITEMASK_ */
494 unsigned Indirect
: 1; /* BOOL */
495 unsigned Dimension
: 1; /* BOOL */
496 int Index
: 16; /* SINT */
497 unsigned Padding
: 5;
498 unsigned Extended
: 1; /* BOOL */
502 * If tgsi_dst_register::Extended is TRUE, tgsi_dst_register_ext follows.
504 * Then, if tgsi_dst_register::Indirect is TRUE, tgsi_src_register follows.
507 #define TGSI_DST_REGISTER_EXT_TYPE_MODULATE 1
509 struct tgsi_dst_register_ext
511 unsigned Type
: 4; /* TGSI_DST_REGISTER_EXT_TYPE_ */
512 unsigned Padding
: 27;
513 unsigned Extended
: 1; /* BOOL */
517 * Extra destination register modifiers
519 * If tgsi_dst_register_ext::Type is TGSI_DST_REGISTER_EXT_TYPE_MODULATE,
520 * it should be cast to tgsi_dst_register_ext_modulate.
522 * If tgsi_dst_register_ext::Extended is TRUE, another tgsi_dst_register_ext
526 #define TGSI_MODULATE_1X 0
527 #define TGSI_MODULATE_2X 1
528 #define TGSI_MODULATE_4X 2
529 #define TGSI_MODULATE_8X 3
530 #define TGSI_MODULATE_HALF 4
531 #define TGSI_MODULATE_QUARTER 5
532 #define TGSI_MODULATE_EIGHTH 6
533 #define TGSI_MODULATE_COUNT 7
535 struct tgsi_dst_register_ext_modulate
537 unsigned Type
: 4; /* TGSI_DST_REGISTER_EXT_TYPE_MODULATE */
538 unsigned Modulate
: 4; /* TGSI_MODULATE_ */
539 unsigned Padding
: 23;
540 unsigned Extended
: 1; /* BOOL */
547 #endif /* P_SHADER_TOKENS_H */