2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \file prog_instruction.h
29 * Vertex/fragment program instruction datatypes and constants.
32 * \author Keith Whitwell
33 * \author Ian Romanick <idr@us.ibm.com>
37 #ifndef PROG_INSTRUCTION_H
38 #define PROG_INSTRUCTION_H
50 #define SWIZZLE_ZERO 4 /**< For SWZ instruction only */
51 #define SWIZZLE_ONE 5 /**< For SWZ instruction only */
52 #define SWIZZLE_NIL 7 /**< used during shader code gen (undefined value) */
55 #define MAKE_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<3) | ((c)<<6) | ((d)<<9))
56 #define SWIZZLE_NOOP MAKE_SWIZZLE4(0,1,2,3)
57 #define GET_SWZ(swz, idx) (((swz) >> ((idx)*3)) & 0x7)
58 #define GET_BIT(msk, idx) (((msk) >> (idx)) & 0x1)
60 #define SWIZZLE_XYZW MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W)
61 #define SWIZZLE_XXXX MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X)
62 #define SWIZZLE_YYYY MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y)
63 #define SWIZZLE_ZZZZ MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z)
64 #define SWIZZLE_WWWW MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
68 * Writemask values, 1 bit per component.
71 #define WRITEMASK_X 0x1
72 #define WRITEMASK_Y 0x2
73 #define WRITEMASK_XY 0x3
74 #define WRITEMASK_Z 0x4
75 #define WRITEMASK_XZ 0x5
76 #define WRITEMASK_YZ 0x6
77 #define WRITEMASK_XYZ 0x7
78 #define WRITEMASK_W 0x8
79 #define WRITEMASK_XW 0x9
80 #define WRITEMASK_YW 0xa
81 #define WRITEMASK_XYW 0xb
82 #define WRITEMASK_ZW 0xc
83 #define WRITEMASK_XZW 0xd
84 #define WRITEMASK_YZW 0xe
85 #define WRITEMASK_XYZW 0xf
93 #define COND_GT 1 /**< greater than zero */
94 #define COND_EQ 2 /**< equal to zero */
95 #define COND_LT 3 /**< less than zero */
96 #define COND_UN 4 /**< unordered (NaN) */
97 #define COND_GE 5 /**< greater then or equal to zero */
98 #define COND_LE 6 /**< less then or equal to zero */
99 #define COND_NE 7 /**< not equal to zero */
100 #define COND_TR 8 /**< always true */
101 #define COND_FL 9 /**< always false */
106 * Instruction precision for GL_NV_fragment_program
116 * Saturation modes when storing values.
119 #define SATURATE_OFF 0
120 #define SATURATE_ZERO_ONE 1
121 #define SATURATE_PLUS_MINUS_ONE 2
126 * Per-component negation masks
133 #define NEGATE_XYZW 0xf
134 #define NEGATE_NONE 0x0
139 * Program instruction opcodes, for both vertex and fragment programs.
140 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
142 typedef enum prog_opcode
{
143 /* ARB_vp ARB_fp NV_vp NV_fp GLSL */
144 /*------------------------------------------*/
145 OPCODE_NOP
= 0, /* X */
146 OPCODE_ABS
, /* X X 1.1 X */
147 OPCODE_ADD
, /* X X X X X */
149 OPCODE_ARL
, /* X X */
150 OPCODE_ARL_NV
, /* 2 */
152 OPCODE_BGNLOOP
, /* opt */
153 OPCODE_BGNSUB
, /* opt */
154 OPCODE_BRA
, /* 2 X */
155 OPCODE_BRK
, /* 2 opt */
156 OPCODE_CAL
, /* 2 2 */
158 OPCODE_CONT
, /* opt */
159 OPCODE_COS
, /* X 2 X X */
160 OPCODE_DDX
, /* X X */
161 OPCODE_DDY
, /* X X */
162 OPCODE_DP3
, /* X X X X X */
163 OPCODE_DP4
, /* X X X X X */
164 OPCODE_DPH
, /* X X 1.1 */
165 OPCODE_DST
, /* X X X X */
167 OPCODE_END
, /* X X X X opt */
168 OPCODE_ENDIF
, /* opt */
169 OPCODE_ENDLOOP
, /* opt */
170 OPCODE_ENDSUB
, /* opt */
171 OPCODE_EX2
, /* X X 2 X X */
172 OPCODE_EXP
, /* X X X */
173 OPCODE_FLR
, /* X X 2 X X */
174 OPCODE_FRC
, /* X X 2 X X */
178 OPCODE_KIL_NV
, /* X X */
179 OPCODE_LG2
, /* X X 2 X X */
180 OPCODE_LIT
, /* X X X X */
181 OPCODE_LOG
, /* X X X */
182 OPCODE_LRP
, /* X X */
183 OPCODE_MAD
, /* X X X X X */
184 OPCODE_MAX
, /* X X X X X */
185 OPCODE_MIN
, /* X X X X X */
186 OPCODE_MOV
, /* X X X X X */
187 OPCODE_MUL
, /* X X X X X */
188 OPCODE_NOISE1
, /* X */
189 OPCODE_NOISE2
, /* X */
190 OPCODE_NOISE3
, /* X */
191 OPCODE_NOISE4
, /* X */
193 OPCODE_PK2US
, /* X */
195 OPCODE_PK4UB
, /* X */
196 OPCODE_POW
, /* X X X X */
198 OPCODE_PRINT
, /* X X */
199 OPCODE_PUSHA
, /* 3 */
200 OPCODE_RCC
, /* 1.1 */
201 OPCODE_RCP
, /* X X X X X */
202 OPCODE_RET
, /* 2 2 */
203 OPCODE_RFL
, /* X X */
204 OPCODE_RSQ
, /* X X X X X */
206 OPCODE_SEQ
, /* 2 X X */
207 OPCODE_SFL
, /* 2 X */
208 OPCODE_SGE
, /* X X X X X */
209 OPCODE_SGT
, /* 2 X X */
210 OPCODE_SIN
, /* X 2 X X */
211 OPCODE_SLE
, /* 2 X X */
212 OPCODE_SLT
, /* X X X X X */
213 OPCODE_SNE
, /* 2 X X */
215 OPCODE_STR
, /* 2 X */
216 OPCODE_SUB
, /* X X 1.1 X X */
217 OPCODE_SWZ
, /* X X */
218 OPCODE_TEX
, /* X 3 X X */
219 OPCODE_TXB
, /* X 3 X */
220 OPCODE_TXD
, /* X X */
221 OPCODE_TXL
, /* 3 2 X */
222 OPCODE_TXP
, /* X X */
223 OPCODE_TXP_NV
, /* 3 X */
225 OPCODE_UP2US
, /* X */
227 OPCODE_UP4UB
, /* X */
229 OPCODE_XPD
, /* X X X */
235 * Instruction source register.
237 struct prog_src_register
239 GLuint File
:4; /**< One of the PROGRAM_* register file values. */
240 GLint Index
:9; /**< May be negative for relative addressing. */
245 * \name Source register "sign" control.
247 * The ARB and NV extensions allow varrying degrees of control over the
248 * sign of the source vector components. These values allow enough control
249 * for all flavors of the extensions.
253 * Per-component negation for the SWZ instruction. For non-SWZ
254 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
257 * ARB_vertex_program, ARB_fragment_program
262 * Take the component-wise absolute value.
265 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
266 * NV_vertex_program2_option.
271 * Post-absolute value negation (all components).
279 * Instruction destination register.
281 struct prog_dst_register
284 * One of the PROGRAM_* register file values.
292 * \name Conditional destination update control.
295 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
296 * NV_vertex_program2_option.
300 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
301 * NE, TR, or UN). Dest reg is only written to if the matching
302 * (swizzled) condition code value passes. When a conditional update mask
303 * is not specified, this will be \c COND_TR.
308 * Condition code swizzle value.
310 GLuint CondSwizzle
:12;
313 * Selects the condition code register to use for conditional destination
314 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
315 * condition code register 0 is available. In NV_vertex_program3 mode,
316 * condition code registers 0 and 1 are available.
326 * Vertex/fragment program instruction.
328 struct prog_instruction
330 gl_inst_opcode Opcode
;
331 #if FEATURE_MESA_program_debug
335 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
339 struct prog_src_register SrcReg
[3];
340 struct prog_dst_register DstReg
;
343 * Indicates that the instruction should update the condition code
347 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
348 * NV_vertex_program2_option.
353 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
354 * condition code register that is to be updated.
356 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
357 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
358 * code registers 0 and 1 are available.
361 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
362 * NV_vertex_program2_option.
367 * Saturate each value of the vectored result to the range [0,1] or the
368 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
369 * only available in NV_fragment_program2 mode.
370 * Value is one of the SATURATE_* tokens.
373 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
375 GLuint SaturateMode
:2;
378 * Per-instruction selectable precision.
381 * NV_fragment_program, NV_fragment_program_option.
386 * \name Texture source controls.
388 * The texture source controls are only used with the \c TEX, \c TXD,
389 * \c TXL, and \c TXP instructions.
392 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
396 * Source texture unit. OpenGL supports a maximum of 32 texture
402 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
404 GLuint TexSrcTarget
:3;
408 * For BRA and CAL instructions, the location to jump to.
409 * For BGNLOOP, points to ENDLOOP (and vice-versa).
410 * For BRK, points to BGNLOOP (which points to ENDLOOP).
411 * For IF, points to else or endif.
412 * For ELSE, points to endif.
418 * For TEX instructions in shaders, the sampler to use for the
429 _mesa_init_instructions(struct prog_instruction
*inst
, GLuint count
);
431 extern struct prog_instruction
*
432 _mesa_alloc_instructions(GLuint numInst
);
434 extern struct prog_instruction
*
435 _mesa_realloc_instructions(struct prog_instruction
*oldInst
,
436 GLuint numOldInst
, GLuint numNewInst
);
438 extern struct prog_instruction
*
439 _mesa_copy_instructions(struct prog_instruction
*dest
,
440 const struct prog_instruction
*src
, GLuint n
);
443 _mesa_free_instructions(struct prog_instruction
*inst
, GLuint count
);
446 _mesa_num_inst_src_regs(gl_inst_opcode opcode
);
449 _mesa_num_inst_dst_regs(gl_inst_opcode opcode
);
452 _mesa_is_tex_instruction(gl_inst_opcode opcode
);
455 _mesa_opcode_string(gl_inst_opcode opcode
);
458 #endif /* PROG_INSTRUCTION_H */