1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2009-2010 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
39 unsigned HeaderSize
: 8;
40 unsigned BodySize
: 24;
43 #define TGSI_PROCESSOR_FRAGMENT 0
44 #define TGSI_PROCESSOR_VERTEX 1
45 #define TGSI_PROCESSOR_GEOMETRY 2
49 unsigned Processor
: 4; /* TGSI_PROCESSOR_ */
50 unsigned Padding
: 28;
53 #define TGSI_TOKEN_TYPE_DECLARATION 0
54 #define TGSI_TOKEN_TYPE_IMMEDIATE 1
55 #define TGSI_TOKEN_TYPE_INSTRUCTION 2
56 #define TGSI_TOKEN_TYPE_PROPERTY 3
60 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_x */
61 unsigned NrTokens
: 8; /**< UINT */
62 unsigned Padding
: 20;
67 TGSI_FILE_CONSTANT
=1,
70 TGSI_FILE_TEMPORARY
=4,
73 TGSI_FILE_IMMEDIATE
=7,
74 TGSI_FILE_PREDICATE
=8,
75 TGSI_FILE_SYSTEM_VALUE
=9,
76 TGSI_FILE_IMMEDIATE_ARRAY
=10,
77 TGSI_FILE_TEMPORARY_ARRAY
=11,
78 TGSI_FILE_RESOURCE
=12,
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 #define TGSI_CYLINDRICAL_WRAP_X (1 << 0)
106 #define TGSI_CYLINDRICAL_WRAP_Y (1 << 1)
107 #define TGSI_CYLINDRICAL_WRAP_Z (1 << 2)
108 #define TGSI_CYLINDRICAL_WRAP_W (1 << 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 Dimension
: 1; /**< any extra dimension info? */
118 unsigned Semantic
: 1; /**< BOOL, any semantic info? */
119 unsigned Centroid
: 1; /**< centroid sampling? */
120 unsigned Invariant
: 1; /**< invariant optimization? */
121 unsigned CylindricalWrap
:4; /**< TGSI_CYLINDRICAL_WRAP_x flags */
124 struct tgsi_declaration_range
126 unsigned First
: 16; /**< UINT */
127 unsigned Last
: 16; /**< UINT */
130 struct tgsi_declaration_dimension
132 unsigned Index2D
:16; /**< UINT */
136 #define TGSI_SEMANTIC_POSITION 0
137 #define TGSI_SEMANTIC_COLOR 1
138 #define TGSI_SEMANTIC_BCOLOR 2 /**< back-face color */
139 #define TGSI_SEMANTIC_FOG 3
140 #define TGSI_SEMANTIC_PSIZE 4
141 #define TGSI_SEMANTIC_GENERIC 5
142 #define TGSI_SEMANTIC_NORMAL 6
143 #define TGSI_SEMANTIC_FACE 7
144 #define TGSI_SEMANTIC_EDGEFLAG 8
145 #define TGSI_SEMANTIC_PRIMID 9
146 #define TGSI_SEMANTIC_INSTANCEID 10
147 #define TGSI_SEMANTIC_STENCIL 11
148 #define TGSI_SEMANTIC_COUNT 12 /**< number of semantic values */
150 struct tgsi_declaration_semantic
152 unsigned Name
: 8; /**< one of TGSI_SEMANTIC_x */
153 unsigned Index
: 16; /**< UINT */
154 unsigned Padding
: 8;
157 struct tgsi_declaration_resource
{
158 unsigned Resource
: 8; /**< one of TGSI_TEXTURE_ */
159 unsigned ReturnTypeX
: 6; /**< one of enum pipe_type */
160 unsigned ReturnTypeY
: 6; /**< one of enum pipe_type */
161 unsigned ReturnTypeZ
: 6; /**< one of enum pipe_type */
162 unsigned ReturnTypeW
: 6; /**< one of enum pipe_type */
165 #define TGSI_IMM_FLOAT32 0
166 #define TGSI_IMM_UINT32 1
167 #define TGSI_IMM_INT32 2
169 struct tgsi_immediate
171 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_IMMEDIATE */
172 unsigned NrTokens
: 14; /**< UINT */
173 unsigned DataType
: 4; /**< one of TGSI_IMM_x */
174 unsigned Padding
: 10;
177 union tgsi_immediate_data
184 #define TGSI_PROPERTY_GS_INPUT_PRIM 0
185 #define TGSI_PROPERTY_GS_OUTPUT_PRIM 1
186 #define TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES 2
187 #define TGSI_PROPERTY_FS_COORD_ORIGIN 3
188 #define TGSI_PROPERTY_FS_COORD_PIXEL_CENTER 4
189 #define TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS 5
190 #define TGSI_PROPERTY_COUNT 6
192 struct tgsi_property
{
193 unsigned Type
: 4; /**< TGSI_TOKEN_TYPE_PROPERTY */
194 unsigned NrTokens
: 8; /**< UINT */
195 unsigned PropertyName
: 8; /**< one of TGSI_PROPERTY */
196 unsigned Padding
: 12;
199 #define TGSI_FS_COORD_ORIGIN_UPPER_LEFT 0
200 #define TGSI_FS_COORD_ORIGIN_LOWER_LEFT 1
202 #define TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER 0
203 #define TGSI_FS_COORD_PIXEL_CENTER_INTEGER 1
205 struct tgsi_property_data
{
211 * For more information on semantics of opcodes and
212 * which APIs are known to use which opcodes, see
213 * gallium/docs/source/tgsi.rst
215 #define TGSI_OPCODE_ARL 0
216 #define TGSI_OPCODE_MOV 1
217 #define TGSI_OPCODE_LIT 2
218 #define TGSI_OPCODE_RCP 3
219 #define TGSI_OPCODE_RSQ 4
220 #define TGSI_OPCODE_EXP 5
221 #define TGSI_OPCODE_LOG 6
222 #define TGSI_OPCODE_MUL 7
223 #define TGSI_OPCODE_ADD 8
224 #define TGSI_OPCODE_DP3 9
225 #define TGSI_OPCODE_DP4 10
226 #define TGSI_OPCODE_DST 11
227 #define TGSI_OPCODE_MIN 12
228 #define TGSI_OPCODE_MAX 13
229 #define TGSI_OPCODE_SLT 14
230 #define TGSI_OPCODE_SGE 15
231 #define TGSI_OPCODE_MAD 16
232 #define TGSI_OPCODE_SUB 17
233 #define TGSI_OPCODE_LRP 18
234 #define TGSI_OPCODE_CND 19
236 #define TGSI_OPCODE_DP2A 21
238 #define TGSI_OPCODE_FRC 24
239 #define TGSI_OPCODE_CLAMP 25
240 #define TGSI_OPCODE_FLR 26
241 #define TGSI_OPCODE_ROUND 27
242 #define TGSI_OPCODE_EX2 28
243 #define TGSI_OPCODE_LG2 29
244 #define TGSI_OPCODE_POW 30
245 #define TGSI_OPCODE_XPD 31
247 #define TGSI_OPCODE_ABS 33
248 #define TGSI_OPCODE_RCC 34
249 #define TGSI_OPCODE_DPH 35
250 #define TGSI_OPCODE_COS 36
251 #define TGSI_OPCODE_DDX 37
252 #define TGSI_OPCODE_DDY 38
253 #define TGSI_OPCODE_KILP 39 /* predicated kill */
254 #define TGSI_OPCODE_PK2H 40
255 #define TGSI_OPCODE_PK2US 41
256 #define TGSI_OPCODE_PK4B 42
257 #define TGSI_OPCODE_PK4UB 43
258 #define TGSI_OPCODE_RFL 44
259 #define TGSI_OPCODE_SEQ 45
260 #define TGSI_OPCODE_SFL 46
261 #define TGSI_OPCODE_SGT 47
262 #define TGSI_OPCODE_SIN 48
263 #define TGSI_OPCODE_SLE 49
264 #define TGSI_OPCODE_SNE 50
265 #define TGSI_OPCODE_STR 51
266 #define TGSI_OPCODE_TEX 52
267 #define TGSI_OPCODE_TXD 53
268 #define TGSI_OPCODE_TXP 54
269 #define TGSI_OPCODE_UP2H 55
270 #define TGSI_OPCODE_UP2US 56
271 #define TGSI_OPCODE_UP4B 57
272 #define TGSI_OPCODE_UP4UB 58
273 #define TGSI_OPCODE_X2D 59
274 #define TGSI_OPCODE_ARA 60
275 #define TGSI_OPCODE_ARR 61
276 #define TGSI_OPCODE_BRA 62
277 #define TGSI_OPCODE_CAL 63
278 #define TGSI_OPCODE_RET 64
279 #define TGSI_OPCODE_SSG 65 /* SGN */
280 #define TGSI_OPCODE_CMP 66
281 #define TGSI_OPCODE_SCS 67
282 #define TGSI_OPCODE_TXB 68
283 #define TGSI_OPCODE_NRM 69
284 #define TGSI_OPCODE_DIV 70
285 #define TGSI_OPCODE_DP2 71
286 #define TGSI_OPCODE_TXL 72
287 #define TGSI_OPCODE_BRK 73
288 #define TGSI_OPCODE_IF 74
290 #define TGSI_OPCODE_ELSE 77
291 #define TGSI_OPCODE_ENDIF 78
293 #define TGSI_OPCODE_PUSHA 81
294 #define TGSI_OPCODE_POPA 82
295 #define TGSI_OPCODE_CEIL 83
296 #define TGSI_OPCODE_I2F 84
297 #define TGSI_OPCODE_NOT 85
298 #define TGSI_OPCODE_TRUNC 86
299 #define TGSI_OPCODE_SHL 87
301 #define TGSI_OPCODE_AND 89
302 #define TGSI_OPCODE_OR 90
303 #define TGSI_OPCODE_MOD 91
304 #define TGSI_OPCODE_XOR 92
305 #define TGSI_OPCODE_SAD 93
306 #define TGSI_OPCODE_TXF 94
307 #define TGSI_OPCODE_TXQ 95
308 #define TGSI_OPCODE_CONT 96
309 #define TGSI_OPCODE_EMIT 97
310 #define TGSI_OPCODE_ENDPRIM 98
311 #define TGSI_OPCODE_BGNLOOP 99
312 #define TGSI_OPCODE_BGNSUB 100
313 #define TGSI_OPCODE_ENDLOOP 101
314 #define TGSI_OPCODE_ENDSUB 102
316 #define TGSI_OPCODE_NOP 107
318 #define TGSI_OPCODE_NRM4 112
319 #define TGSI_OPCODE_CALLNZ 113
320 #define TGSI_OPCODE_IFC 114
321 #define TGSI_OPCODE_BREAKC 115
322 #define TGSI_OPCODE_KIL 116 /* conditional kill */
323 #define TGSI_OPCODE_END 117 /* aka HALT */
325 #define TGSI_OPCODE_F2I 119
326 #define TGSI_OPCODE_IDIV 120
327 #define TGSI_OPCODE_IMAX 121
328 #define TGSI_OPCODE_IMIN 122
329 #define TGSI_OPCODE_INEG 123
330 #define TGSI_OPCODE_ISGE 124
331 #define TGSI_OPCODE_ISHR 125
332 #define TGSI_OPCODE_ISLT 126
333 #define TGSI_OPCODE_F2U 127
334 #define TGSI_OPCODE_U2F 128
335 #define TGSI_OPCODE_UADD 129
336 #define TGSI_OPCODE_UDIV 130
337 #define TGSI_OPCODE_UMAD 131
338 #define TGSI_OPCODE_UMAX 132
339 #define TGSI_OPCODE_UMIN 133
340 #define TGSI_OPCODE_UMOD 134
341 #define TGSI_OPCODE_UMUL 135
342 #define TGSI_OPCODE_USEQ 136
343 #define TGSI_OPCODE_USGE 137
344 #define TGSI_OPCODE_USHR 138
345 #define TGSI_OPCODE_USLT 139
346 #define TGSI_OPCODE_USNE 140
347 #define TGSI_OPCODE_SWITCH 141
348 #define TGSI_OPCODE_CASE 142
349 #define TGSI_OPCODE_DEFAULT 143
350 #define TGSI_OPCODE_ENDSWITCH 144
352 /* resource related opcodes */
353 #define TGSI_OPCODE_LOAD 145
354 #define TGSI_OPCODE_LOAD_MS 146
355 #define TGSI_OPCODE_SAMPLE 147
356 #define TGSI_OPCODE_SAMPLE_B 148
357 #define TGSI_OPCODE_SAMPLE_C 149
358 #define TGSI_OPCODE_SAMPLE_C_LZ 150
359 #define TGSI_OPCODE_SAMPLE_D 151
360 #define TGSI_OPCODE_SAMPLE_L 152
361 #define TGSI_OPCODE_GATHER4 153
362 #define TGSI_OPCODE_RESINFO 154
363 #define TGSI_OPCODE_SAMPLE_POS 155
364 #define TGSI_OPCODE_SAMPLE_INFO 156
366 #define TGSI_OPCODE_LAST 157
368 #define TGSI_SAT_NONE 0 /* do not saturate */
369 #define TGSI_SAT_ZERO_ONE 1 /* clamp to [0,1] */
370 #define TGSI_SAT_MINUS_PLUS_ONE 2 /* clamp to [-1,1] */
373 * Opcode is the operation code to execute. A given operation defines the
374 * semantics how the source registers (if any) are interpreted and what is
375 * written to the destination registers (if any) as a result of execution.
377 * NumDstRegs and NumSrcRegs is the number of destination and source registers,
378 * respectively. For a given operation code, those numbers are fixed and are
379 * present here only for convenience.
381 * If Predicate is TRUE, tgsi_instruction_predicate token immediately follows.
383 * Saturate controls how are final results in destination registers modified.
386 struct tgsi_instruction
388 unsigned Type
: 4; /* TGSI_TOKEN_TYPE_INSTRUCTION */
389 unsigned NrTokens
: 8; /* UINT */
390 unsigned Opcode
: 8; /* TGSI_OPCODE_ */
391 unsigned Saturate
: 2; /* TGSI_SAT_ */
392 unsigned NumDstRegs
: 2; /* UINT */
393 unsigned NumSrcRegs
: 4; /* UINT */
394 unsigned Predicate
: 1; /* BOOL */
396 unsigned Texture
: 1;
397 unsigned Padding
: 1;
401 * If tgsi_instruction::Label is TRUE, tgsi_instruction_label follows.
403 * If tgsi_instruction::Texture is TRUE, tgsi_instruction_texture follows.
405 * Then, tgsi_instruction::NumDstRegs of tgsi_dst_register follow.
407 * Then, tgsi_instruction::NumSrcRegs of tgsi_src_register follow.
409 * tgsi_instruction::NrTokens contains the total number of words that make the
410 * instruction, including the instruction word.
413 #define TGSI_SWIZZLE_X 0
414 #define TGSI_SWIZZLE_Y 1
415 #define TGSI_SWIZZLE_Z 2
416 #define TGSI_SWIZZLE_W 3
418 struct tgsi_instruction_label
420 unsigned Label
: 24; /* UINT */
421 unsigned Padding
: 8;
424 #define TGSI_TEXTURE_UNKNOWN 0
425 #define TGSI_TEXTURE_1D 1
426 #define TGSI_TEXTURE_2D 2
427 #define TGSI_TEXTURE_3D 3
428 #define TGSI_TEXTURE_CUBE 4
429 #define TGSI_TEXTURE_RECT 5
430 #define TGSI_TEXTURE_SHADOW1D 6
431 #define TGSI_TEXTURE_SHADOW2D 7
432 #define TGSI_TEXTURE_SHADOWRECT 8
433 #define TGSI_TEXTURE_1D_ARRAY 9
434 #define TGSI_TEXTURE_2D_ARRAY 10
435 #define TGSI_TEXTURE_COUNT 11
437 struct tgsi_instruction_texture
439 unsigned Texture
: 8; /* TGSI_TEXTURE_ */
440 unsigned Padding
: 24;
444 * For SM3, the following constraint applies.
445 * - Swizzle is either set to identity or replicate.
447 struct tgsi_instruction_predicate
449 int Index
: 16; /* SINT */
450 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_x */
451 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_x */
452 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_x */
453 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_x */
454 unsigned Negate
: 1; /* BOOL */
455 unsigned Padding
: 7;
459 * File specifies the register array to access.
461 * Index specifies the element number of a register in the register file.
463 * If Indirect is TRUE, Index should be offset by the X component of a source
464 * register that follows. The register can be now fetched into local storage
465 * for further processing.
467 * If Negate is TRUE, all components of the fetched register are negated.
469 * The fetched register components are swizzled according to SwizzleX, SwizzleY,
470 * SwizzleZ and SwizzleW.
474 struct tgsi_src_register
476 unsigned File
: 4; /* TGSI_FILE_ */
477 unsigned Indirect
: 1; /* BOOL */
478 unsigned Dimension
: 1; /* BOOL */
479 int Index
: 16; /* SINT */
480 unsigned SwizzleX
: 2; /* TGSI_SWIZZLE_ */
481 unsigned SwizzleY
: 2; /* TGSI_SWIZZLE_ */
482 unsigned SwizzleZ
: 2; /* TGSI_SWIZZLE_ */
483 unsigned SwizzleW
: 2; /* TGSI_SWIZZLE_ */
484 unsigned Absolute
: 1; /* BOOL */
485 unsigned Negate
: 1; /* BOOL */
489 * If tgsi_src_register::Modifier is TRUE, tgsi_src_register_modifier follows.
491 * Then, if tgsi_src_register::Indirect is TRUE, another tgsi_src_register
494 * Then, if tgsi_src_register::Dimension is TRUE, tgsi_dimension follows.
498 struct tgsi_dimension
500 unsigned Indirect
: 1; /* BOOL */
501 unsigned Dimension
: 1; /* BOOL */
502 unsigned Padding
: 14;
503 int Index
: 16; /* SINT */
506 struct tgsi_dst_register
508 unsigned File
: 4; /* TGSI_FILE_ */
509 unsigned WriteMask
: 4; /* TGSI_WRITEMASK_ */
510 unsigned Indirect
: 1; /* BOOL */
511 unsigned Dimension
: 1; /* BOOL */
512 int Index
: 16; /* SINT */
513 unsigned Padding
: 6;
521 #endif /* P_SHADER_TOKENS_H */