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