program: Remove dead Aux field from prog_instruction.
[mesa.git] / src / mesa / program / prog_instruction.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file prog_instruction.h
28 *
29 * Vertex/fragment program instruction datatypes and constants.
30 *
31 * \author Brian Paul
32 * \author Keith Whitwell
33 * \author Ian Romanick <idr@us.ibm.com>
34 */
35
36
37 #ifndef PROG_INSTRUCTION_H
38 #define PROG_INSTRUCTION_H
39
40
41 #include "main/glheader.h"
42
43
44 /**
45 * Swizzle indexes.
46 * Do not change!
47 */
48 /*@{*/
49 #define SWIZZLE_X 0
50 #define SWIZZLE_Y 1
51 #define SWIZZLE_Z 2
52 #define SWIZZLE_W 3
53 #define SWIZZLE_ZERO 4 /**< For SWZ instruction only */
54 #define SWIZZLE_ONE 5 /**< For SWZ instruction only */
55 #define SWIZZLE_NIL 7 /**< used during shader code gen (undefined value) */
56 /*@}*/
57
58 #define MAKE_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<3) | ((c)<<6) | ((d)<<9))
59 #define SWIZZLE_NOOP MAKE_SWIZZLE4(0,1,2,3)
60 #define GET_SWZ(swz, idx) (((swz) >> ((idx)*3)) & 0x7)
61 #define GET_BIT(msk, idx) (((msk) >> (idx)) & 0x1)
62 /** Determine if swz contains SWIZZLE_ZERO/ONE/NIL for any components. */
63 #define HAS_EXTENDED_SWIZZLE(swz) (swz & 0x924)
64
65 #define SWIZZLE_XYZW MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W)
66 #define SWIZZLE_XXXX MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X)
67 #define SWIZZLE_YYYY MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y)
68 #define SWIZZLE_ZZZZ MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z)
69 #define SWIZZLE_WWWW MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
70
71
72 /**
73 * Writemask values, 1 bit per component.
74 */
75 /*@{*/
76 #define WRITEMASK_X 0x1
77 #define WRITEMASK_Y 0x2
78 #define WRITEMASK_XY 0x3
79 #define WRITEMASK_Z 0x4
80 #define WRITEMASK_XZ 0x5
81 #define WRITEMASK_YZ 0x6
82 #define WRITEMASK_XYZ 0x7
83 #define WRITEMASK_W 0x8
84 #define WRITEMASK_XW 0x9
85 #define WRITEMASK_YW 0xa
86 #define WRITEMASK_XYW 0xb
87 #define WRITEMASK_ZW 0xc
88 #define WRITEMASK_XZW 0xd
89 #define WRITEMASK_YZW 0xe
90 #define WRITEMASK_XYZW 0xf
91 /*@}*/
92
93
94 /**
95 * Condition codes
96 */
97 /*@{*/
98 #define COND_GT 1 /**< greater than zero */
99 #define COND_EQ 2 /**< equal to zero */
100 #define COND_LT 3 /**< less than zero */
101 #define COND_UN 4 /**< unordered (NaN) */
102 #define COND_GE 5 /**< greater than or equal to zero */
103 #define COND_LE 6 /**< less than or equal to zero */
104 #define COND_NE 7 /**< not equal to zero */
105 #define COND_TR 8 /**< always true */
106 #define COND_FL 9 /**< always false */
107 /*@}*/
108
109
110 /**
111 * Instruction precision for GL_NV_fragment_program
112 */
113 /*@{*/
114 #define FLOAT32 0x1
115 #define FLOAT16 0x2
116 #define FIXED12 0x4
117 /*@}*/
118
119
120 /**
121 * Per-component negation masks
122 */
123 /*@{*/
124 #define NEGATE_X 0x1
125 #define NEGATE_Y 0x2
126 #define NEGATE_Z 0x4
127 #define NEGATE_W 0x8
128 #define NEGATE_XYZ 0x7
129 #define NEGATE_XYZW 0xf
130 #define NEGATE_NONE 0x0
131 /*@}*/
132
133
134 /**
135 * Program instruction opcodes for vertex, fragment and geometry programs.
136 */
137 typedef enum prog_opcode {
138 /* ARB_vp ARB_fp NV_vp NV_fp GLSL */
139 /*------------------------------------------*/
140 OPCODE_NOP = 0, /* X */
141 OPCODE_ABS, /* X X 1.1 X */
142 OPCODE_ADD, /* X X X X X */
143 OPCODE_ARL, /* X X X */
144 OPCODE_BGNLOOP, /* opt */
145 OPCODE_BGNSUB, /* opt */
146 OPCODE_BRK, /* 2 opt */
147 OPCODE_CAL, /* 2 2 opt */
148 OPCODE_CMP, /* X X */
149 OPCODE_CONT, /* opt */
150 OPCODE_COS, /* X 2 X X */
151 OPCODE_DDX, /* X X */
152 OPCODE_DDY, /* X X */
153 OPCODE_DP2, /* 2 X */
154 OPCODE_DP3, /* X X X X X */
155 OPCODE_DP4, /* X X X X X */
156 OPCODE_DPH, /* X X 1.1 */
157 OPCODE_DST, /* X X X X */
158 OPCODE_ELSE, /* opt */
159 OPCODE_END, /* X X X X opt */
160 OPCODE_ENDIF, /* opt */
161 OPCODE_ENDLOOP, /* opt */
162 OPCODE_ENDSUB, /* opt */
163 OPCODE_EX2, /* X X 2 X X */
164 OPCODE_EXP, /* X X */
165 OPCODE_FLR, /* X X 2 X X */
166 OPCODE_FRC, /* X X 2 X X */
167 OPCODE_IF, /* opt */
168 OPCODE_KIL, /* X X */
169 OPCODE_KIL_NV, /* X X */
170 OPCODE_LG2, /* X X 2 X X */
171 OPCODE_LIT, /* X X X X */
172 OPCODE_LOG, /* X X */
173 OPCODE_LRP, /* X X */
174 OPCODE_MAD, /* X X X X X */
175 OPCODE_MAX, /* X X X X X */
176 OPCODE_MIN, /* X X X X X */
177 OPCODE_MOV, /* X X X X X */
178 OPCODE_MUL, /* X X X X X */
179 OPCODE_NOISE1, /* X */
180 OPCODE_NOISE2, /* X */
181 OPCODE_NOISE3, /* X */
182 OPCODE_NOISE4, /* X */
183 OPCODE_POW, /* X X X X */
184 OPCODE_RCP, /* X X X X X */
185 OPCODE_RET, /* 2 2 opt */
186 OPCODE_RSQ, /* X X X X X */
187 OPCODE_SCS, /* X X */
188 OPCODE_SEQ, /* 2 X X */
189 OPCODE_SGE, /* X X X X X */
190 OPCODE_SGT, /* 2 X X */
191 OPCODE_SIN, /* X 2 X X */
192 OPCODE_SLE, /* 2 X X */
193 OPCODE_SLT, /* X X X X X */
194 OPCODE_SNE, /* 2 X X */
195 OPCODE_SSG, /* 2 X */
196 OPCODE_SUB, /* X X 1.1 X X */
197 OPCODE_SWZ, /* X X X */
198 OPCODE_TEX, /* X 3 X X */
199 OPCODE_TXB, /* X 3 X */
200 OPCODE_TXD, /* X X */
201 OPCODE_TXL, /* 3 2 X */
202 OPCODE_TXP, /* X X */
203 OPCODE_TXP_NV, /* 3 X */
204 OPCODE_TRUNC, /* X */
205 OPCODE_XPD, /* X X */
206 MAX_OPCODE
207 } gl_inst_opcode;
208
209
210 /**
211 * Number of bits for the src/dst register Index field.
212 * This limits the size of temp/uniform register files.
213 */
214 #define INST_INDEX_BITS 12
215
216
217 /**
218 * Instruction source register.
219 */
220 struct prog_src_register
221 {
222 GLuint File:4; /**< One of the PROGRAM_* register file values. */
223 GLint Index:(INST_INDEX_BITS+1); /**< Extra bit here for sign bit.
224 * May be negative for relative addressing.
225 */
226 GLuint Swizzle:12;
227 GLuint RelAddr:1;
228
229 /** Take the component-wise absolute value */
230 GLuint Abs:1;
231
232 /**
233 * Post-Abs negation.
234 * This will either be NEGATE_NONE or NEGATE_XYZW, except for the SWZ
235 * instruction which allows per-component negation.
236 */
237 GLuint Negate:4;
238
239 /**
240 * Is the register two-dimensional.
241 * Two dimensional registers are of the
242 * REGISTER[index][index2] format.
243 * They are used by the geometry shaders where
244 * the first index is the index within an array
245 * and the second index is the semantic of the
246 * array, e.g. gl_PositionIn[index] would become
247 * INPUT[index][gl_PositionIn]
248 */
249 GLuint HasIndex2:1;
250 GLuint RelAddr2:1;
251 GLint Index2:(INST_INDEX_BITS+1); /**< Extra bit here for sign bit.
252 * May be negative for relative
253 * addressing. */
254 };
255
256
257 /**
258 * Instruction destination register.
259 */
260 struct prog_dst_register
261 {
262 GLuint File:4; /**< One of the PROGRAM_* register file values */
263 GLuint Index:INST_INDEX_BITS; /**< Unsigned, never negative */
264 GLuint WriteMask:4;
265 GLuint RelAddr:1;
266
267 /**
268 * \name Conditional destination update control.
269 *
270 * \since
271 * NV_fragment_program_option, NV_vertex_program2, NV_vertex_program2_option.
272 */
273 /*@{*/
274 /**
275 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
276 * NE, TR, or UN). Dest reg is only written to if the matching
277 * (swizzled) condition code value passes. When a conditional update mask
278 * is not specified, this will be \c COND_TR.
279 */
280 GLuint CondMask:4;
281
282 /**
283 * Condition code swizzle value.
284 */
285 GLuint CondSwizzle:12;
286 };
287
288
289 /**
290 * Vertex/fragment program instruction.
291 */
292 struct prog_instruction
293 {
294 gl_inst_opcode Opcode;
295 struct prog_src_register SrcReg[3];
296 struct prog_dst_register DstReg;
297
298 /**
299 * Indicates that the instruction should update the condition code
300 * register.
301 *
302 * \since
303 * NV_fragment_program_option, NV_vertex_program2, NV_vertex_program2_option.
304 */
305 GLuint CondUpdate:1;
306
307 /**
308 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
309 * condition code register that is to be updated.
310 *
311 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
312 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
313 * code registers 0 and 1 are available.
314 *
315 * \since
316 * NV_fragment_program_option, NV_vertex_program2, NV_vertex_program2_option.
317 */
318 GLuint CondDst:1;
319
320 /**
321 * Saturate each value of the vectored result to the range [0,1].
322 *
323 * \since
324 * NV_fragment_program_option, NV_vertex_program3.
325 */
326 GLuint Saturate:1;
327
328 /**
329 * Per-instruction selectable precision: FLOAT32, FLOAT16, FIXED12.
330 *
331 * \since
332 * NV_fragment_program_option.
333 */
334 GLuint Precision:3;
335
336 /**
337 * \name Extra fields for TEX, TXB, TXD, TXL, TXP instructions.
338 */
339 /*@{*/
340 /** Source texture unit. */
341 GLuint TexSrcUnit:5;
342
343 /** Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX */
344 GLuint TexSrcTarget:4;
345
346 /** True if tex instruction should do shadow comparison */
347 GLuint TexShadow:1;
348 /*@}*/
349
350 /**
351 * For BRA and CAL instructions, the location to jump to.
352 * For BGNLOOP, points to ENDLOOP (and vice-versa).
353 * For BRK, points to ENDLOOP
354 * For IF, points to ELSE or ENDIF.
355 * For ELSE, points to ENDIF.
356 */
357 GLint BranchTarget;
358
359 /** for debugging purposes */
360 const char *Comment;
361 };
362
363
364 #ifdef __cplusplus
365 extern "C" {
366 #endif
367
368 extern void
369 _mesa_init_instructions(struct prog_instruction *inst, GLuint count);
370
371 extern struct prog_instruction *
372 _mesa_alloc_instructions(GLuint numInst);
373
374 extern struct prog_instruction *
375 _mesa_copy_instructions(struct prog_instruction *dest,
376 const struct prog_instruction *src, GLuint n);
377
378 extern void
379 _mesa_free_instructions(struct prog_instruction *inst, GLuint count);
380
381 extern GLuint
382 _mesa_num_inst_src_regs(gl_inst_opcode opcode);
383
384 extern GLuint
385 _mesa_num_inst_dst_regs(gl_inst_opcode opcode);
386
387 extern GLboolean
388 _mesa_is_tex_instruction(gl_inst_opcode opcode);
389
390 extern GLboolean
391 _mesa_check_soa_dependencies(const struct prog_instruction *inst);
392
393 extern const char *
394 _mesa_opcode_string(gl_inst_opcode opcode);
395
396
397 #ifdef __cplusplus
398 } /* extern "C" */
399 #endif
400
401 #endif /* PROG_INSTRUCTION_H */