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