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 : 20;
74 TGSI_FILE_CONSTANT =1,
77 TGSI_FILE_TEMPORARY =4,
80 TGSI_FILE_IMMEDIATE =7,
82 TGSI_FILE_PREDICATE =9,
83 TGSI_FILE_COUNT /**< how many TGSI_FILE_ types */
87 #define TGSI_WRITEMASK_NONE 0x00
88 #define TGSI_WRITEMASK_X 0x01
89 #define TGSI_WRITEMASK_Y 0x02
90 #define TGSI_WRITEMASK_XY 0x03
91 #define TGSI_WRITEMASK_Z 0x04
92 #define TGSI_WRITEMASK_XZ 0x05
93 #define TGSI_WRITEMASK_YZ 0x06
94 #define TGSI_WRITEMASK_XYZ 0x07
95 #define TGSI_WRITEMASK_W 0x08
96 #define TGSI_WRITEMASK_XW 0x09
97 #define TGSI_WRITEMASK_YW 0x0A
98 #define TGSI_WRITEMASK_XYW 0x0B
99 #define TGSI_WRITEMASK_ZW 0x0C
100 #define TGSI_WRITEMASK_XZW 0x0D
101 #define TGSI_WRITEMASK_YZW 0x0E
102 #define TGSI_WRITEMASK_XYZW 0x0F
104 #define TGSI_INTERPOLATE_CONSTANT 0
105 #define TGSI_INTERPOLATE_LINEAR 1
106 #define TGSI_INTERPOLATE_PERSPECTIVE 2
107 #define TGSI_INTERPOLATE_COUNT 3
109 struct tgsi_declaration
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 Semantic : 1; /**< BOOL, any semantic info? */
117 unsigned Centroid : 1; /**< centroid sampling? */
118 unsigned Invariant : 1; /**< invariant optimization? */
119 unsigned Padding : 5;
122 struct tgsi_declaration_range
124 unsigned First : 16; /**< UINT */
125 unsigned Last : 16; /**< UINT */
128 #define TGSI_SEMANTIC_POSITION 0
129 #define TGSI_SEMANTIC_COLOR 1
130 #define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */
131 #define TGSI_SEMANTIC_FOG 3
132 #define TGSI_SEMANTIC_PSIZE 4
133 #define TGSI_SEMANTIC_GENERIC 5
134 #define TGSI_SEMANTIC_NORMAL 6
135 #define TGSI_SEMANTIC_FACE 7
136 #define TGSI_SEMANTIC_COUNT 8 /**< number of semantic values */
138 struct tgsi_declaration_semantic
140 unsigned SemanticName : 8; /**< one of TGSI_SEMANTIC_x */
141 unsigned SemanticIndex : 16; /**< UINT */
142 unsigned Padding : 8;
145 #define TGSI_IMM_FLOAT32 0
147 struct tgsi_immediate
149 unsigned Type : 4; /**< TGSI_TOKEN_TYPE_IMMEDIATE */
150 unsigned NrTokens : 8; /**< UINT */
151 unsigned DataType : 4; /**< one of TGSI_IMM_x */
152 unsigned Padding : 16;
155 union tgsi_immediate_data
162 * For more information on semantics of opcodes and
163 * which APIs are known to use which opcodes, see
164 * auxiliary/tgsi/tgsi-instruction-set.txt
166 #define TGSI_OPCODE_ARL 0
167 #define TGSI_OPCODE_MOV 1
168 #define TGSI_OPCODE_LIT 2
169 #define TGSI_OPCODE_RCP 3
170 #define TGSI_OPCODE_RSQ 4
171 #define TGSI_OPCODE_EXP 5
172 #define TGSI_OPCODE_LOG 6
173 #define TGSI_OPCODE_MUL 7
174 #define TGSI_OPCODE_ADD 8
175 #define TGSI_OPCODE_DP3 9
176 #define TGSI_OPCODE_DP4 10
177 #define TGSI_OPCODE_DST 11
178 #define TGSI_OPCODE_MIN 12
179 #define TGSI_OPCODE_MAX 13
180 #define TGSI_OPCODE_SLT 14
181 #define TGSI_OPCODE_SGE 15
182 #define TGSI_OPCODE_MAD 16
183 #define TGSI_OPCODE_SUB 17
184 #define TGSI_OPCODE_LRP 18
185 #define TGSI_OPCODE_CND 19
187 #define TGSI_OPCODE_DP2A 21
189 #define TGSI_OPCODE_FRC 24
190 #define TGSI_OPCODE_CLAMP 25
191 #define TGSI_OPCODE_FLR 26
192 #define TGSI_OPCODE_ROUND 27
193 #define TGSI_OPCODE_EX2 28
194 #define TGSI_OPCODE_LG2 29
195 #define TGSI_OPCODE_POW 30
196 #define TGSI_OPCODE_XPD 31
198 #define TGSI_OPCODE_ABS 33
199 #define TGSI_OPCODE_RCC 34
200 #define TGSI_OPCODE_DPH 35
201 #define TGSI_OPCODE_COS 36
202 #define TGSI_OPCODE_DDX 37
203 #define TGSI_OPCODE_DDY 38
204 #define TGSI_OPCODE_KILP 39 /* predicated kill */
205 #define TGSI_OPCODE_PK2H 40
206 #define TGSI_OPCODE_PK2US 41
207 #define TGSI_OPCODE_PK4B 42
208 #define TGSI_OPCODE_PK4UB 43
209 #define TGSI_OPCODE_RFL 44
210 #define TGSI_OPCODE_SEQ 45
211 #define TGSI_OPCODE_SFL 46
212 #define TGSI_OPCODE_SGT 47
213 #define TGSI_OPCODE_SIN 48
214 #define TGSI_OPCODE_SLE 49
215 #define TGSI_OPCODE_SNE 50
216 #define TGSI_OPCODE_STR 51
217 #define TGSI_OPCODE_TEX 52
218 #define TGSI_OPCODE_TXD 53
219 #define TGSI_OPCODE_TXP 54
220 #define TGSI_OPCODE_UP2H 55
221 #define TGSI_OPCODE_UP2US 56
222 #define TGSI_OPCODE_UP4B 57
223 #define TGSI_OPCODE_UP4UB 58
224 #define TGSI_OPCODE_X2D 59
225 #define TGSI_OPCODE_ARA 60
226 #define TGSI_OPCODE_ARR 61
227 #define TGSI_OPCODE_BRA 62
228 #define TGSI_OPCODE_CAL 63
229 #define TGSI_OPCODE_RET 64
230 #define TGSI_OPCODE_SSG 65 /* SGN */
231 #define TGSI_OPCODE_CMP 66
232 #define TGSI_OPCODE_SCS 67
233 #define TGSI_OPCODE_TXB 68
234 #define TGSI_OPCODE_NRM 69
235 #define TGSI_OPCODE_DIV 70
236 #define TGSI_OPCODE_DP2 71
237 #define TGSI_OPCODE_TXL 72
238 #define TGSI_OPCODE_BRK 73
239 #define TGSI_OPCODE_IF 74
240 #define TGSI_OPCODE_BGNFOR 75
241 #define TGSI_OPCODE_REP 76
242 #define TGSI_OPCODE_ELSE 77
243 #define TGSI_OPCODE_ENDIF 78
244 #define TGSI_OPCODE_ENDFOR 79
245 #define TGSI_OPCODE_ENDREP 80
246 #define TGSI_OPCODE_PUSHA 81
247 #define TGSI_OPCODE_POPA 82
248 #define TGSI_OPCODE_CEIL 83
249 #define TGSI_OPCODE_I2F 84
250 #define TGSI_OPCODE_NOT 85
251 #define TGSI_OPCODE_TRUNC 86
252 #define TGSI_OPCODE_SHL 87
253 #define TGSI_OPCODE_SHR 88
254 #define TGSI_OPCODE_AND 89
255 #define TGSI_OPCODE_OR 90
256 #define TGSI_OPCODE_MOD 91
257 #define TGSI_OPCODE_XOR 92
258 #define TGSI_OPCODE_SAD 93
259 #define TGSI_OPCODE_TXF 94
260 #define TGSI_OPCODE_TXQ 95
261 #define TGSI_OPCODE_CONT 96
262 #define TGSI_OPCODE_EMIT 97
263 #define TGSI_OPCODE_ENDPRIM 98
264 #define TGSI_OPCODE_BGNLOOP 99
265 #define TGSI_OPCODE_BGNSUB 100
266 #define TGSI_OPCODE_ENDLOOP 101
267 #define TGSI_OPCODE_ENDSUB 102
269 #define TGSI_OPCODE_NOP 107
271 #define TGSI_OPCODE_NRM4 112
272 #define TGSI_OPCODE_CALLNZ 113
273 #define TGSI_OPCODE_IFC 114
274 #define TGSI_OPCODE_BREAKC 115
275 #define TGSI_OPCODE_KIL 116 /* conditional kill */
276 #define TGSI_OPCODE_END 117 /* aka HALT */
278 #define TGSI_OPCODE_LAST 119
280 #define TGSI_SAT_NONE 0 /* do not saturate */
281 #define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */
282 #define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */
285 * Opcode is the operation code to execute. A given operation defines the
286 * semantics how the source registers (if any) are interpreted and what is
287 * written to the destination registers (if any) as a result of execution.
289 * NumDstRegs and NumSrcRegs is the number of destination and source registers,
290 * respectively. For a given operation code, those numbers are fixed and are
291 * present here only for convenience.
293 * If Predicate is TRUE, tgsi_instruction_predicate token immediately follows.
295 * Saturate controls how are final results in destination registers modified.
298 struct tgsi_instruction
300 unsigned Type : 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */
301 unsigned NrTokens : 8; /* UINT */
302 unsigned Opcode : 8; /* TGSI_OPCODE_ */
303 unsigned Saturate : 2; /* TGSI_SAT_ */
304 unsigned NumDstRegs : 2; /* UINT */
305 unsigned NumSrcRegs : 4; /* UINT */
306 unsigned Predicate : 1; /* BOOL */
308 unsigned Texture : 1;
309 unsigned Padding : 1;
313 * If tgsi_instruction::Label is TRUE, tgsi_instruction_label follows.
315 * If tgsi_instruction::Texture is TRUE, tgsi_instruction_texture follows.
317 * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow.
319 * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow.
321 * tgsi_instruction::NrTokens contains the total number of words that make the
322 * instruction, including the instruction word.
325 #define TGSI_SWIZZLE_X 0
326 #define TGSI_SWIZZLE_Y 1
327 #define TGSI_SWIZZLE_Z 2
328 #define TGSI_SWIZZLE_W 3
330 struct tgsi_instruction_label
332 unsigned Label : 24; /* UINT */
333 unsigned Padding : 8;
336 #define TGSI_TEXTURE_UNKNOWN 0
337 #define TGSI_TEXTURE_1D 1
338 #define TGSI_TEXTURE_2D 2
339 #define TGSI_TEXTURE_3D 3
340 #define TGSI_TEXTURE_CUBE 4
341 #define TGSI_TEXTURE_RECT 5
342 #define TGSI_TEXTURE_SHADOW1D 6
343 #define TGSI_TEXTURE_SHADOW2D 7
344 #define TGSI_TEXTURE_SHADOWRECT 8
345 #define TGSI_TEXTURE_COUNT 9
347 struct tgsi_instruction_texture
349 unsigned Texture : 8; /* TGSI_TEXTURE_ */
350 unsigned Padding : 24;
354 * For SM3, the following constraint applies.
355 * - Swizzle is either set to identity or replicate.
357 struct tgsi_instruction_predicate
359 int Index : 16; /* SINT */
360 unsigned SwizzleX : 2; /* TGSI_SWIZZLE_x */
361 unsigned SwizzleY : 2; /* TGSI_SWIZZLE_x */
362 unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_x */
363 unsigned SwizzleW : 2; /* TGSI_SWIZZLE_x */
364 unsigned Negate : 1; /* BOOL */
365 unsigned Padding : 7;
369 * File specifies the register array to access.
371 * Index specifies the element number of a register in the register file.
373 * If Indirect is TRUE, Index should be offset by the X component of a source
374 * register that follows. The register can be now fetched into local storage
375 * for further processing.
377 * If Negate is TRUE, all components of the fetched register are negated.
379 * The fetched register components are swizzled according to SwizzleX, SwizzleY,
380 * SwizzleZ and SwizzleW.
384 struct tgsi_src_register
386 unsigned File : 4; /* TGSI_FILE_ */
387 unsigned Indirect : 1; /* BOOL */
388 unsigned Dimension : 1; /* BOOL */
389 int Index : 16; /* SINT */
390 unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */
391 unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */
392 unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */
393 unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */
394 unsigned Absolute : 1; /* BOOL */
395 unsigned Negate : 1; /* BOOL */
399 * If tgsi_src_register::Modifier is TRUE, tgsi_src_register_modifier follows.
401 * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register
404 * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows.
408 struct tgsi_dimension
410 unsigned Indirect : 1; /* BOOL */
411 unsigned Dimension : 1; /* BOOL */
412 unsigned Padding : 14;
413 int Index : 16; /* SINT */
416 struct tgsi_dst_register
418 unsigned File : 4; /* TGSI_FILE_ */
419 unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */
420 unsigned Indirect : 1; /* BOOL */
421 unsigned Dimension : 1; /* BOOL */
422 int Index : 16; /* SINT */
423 unsigned Padding : 6;
431 #endif /* P_SHADER_TOKENS_H */