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_XXXX MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X)
61 #define SWIZZLE_YYYY MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y)
62 #define SWIZZLE_ZZZZ MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z)
63 #define SWIZZLE_WWWW MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
67 * Writemask values, 1 bit per component.
70 #define WRITEMASK_X 0x1
71 #define WRITEMASK_Y 0x2
72 #define WRITEMASK_XY 0x3
73 #define WRITEMASK_Z 0x4
74 #define WRITEMASK_XZ 0x5
75 #define WRITEMASK_YZ 0x6
76 #define WRITEMASK_XYZ 0x7
77 #define WRITEMASK_W 0x8
78 #define WRITEMASK_XW 0x9
79 #define WRITEMASK_YW 0xa
80 #define WRITEMASK_XYW 0xb
81 #define WRITEMASK_ZW 0xc
82 #define WRITEMASK_XZW 0xd
83 #define WRITEMASK_YZW 0xe
84 #define WRITEMASK_XYZW 0xf
92 #define COND_GT 1 /**< greater than zero */
93 #define COND_EQ 2 /**< equal to zero */
94 #define COND_LT 3 /**< less than zero */
95 #define COND_UN 4 /**< unordered (NaN) */
96 #define COND_GE 5 /**< greater then or equal to zero */
97 #define COND_LE 6 /**< less then or equal to zero */
98 #define COND_NE 7 /**< not equal to zero */
99 #define COND_TR 8 /**< always true */
100 #define COND_FL 9 /**< always false */
105 * Instruction precision for GL_NV_fragment_program
115 * Saturation modes when storing values.
118 #define SATURATE_OFF 0
119 #define SATURATE_ZERO_ONE 1
120 #define SATURATE_PLUS_MINUS_ONE 2
125 * Per-component negation masks
132 #define NEGATE_XYZW 0xf
133 #define NEGATE_NONE 0x0
138 * Program instruction opcodes, for both vertex and fragment programs.
139 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
141 typedef enum prog_opcode
{
142 /* ARB_vp ARB_fp NV_vp NV_fp GLSL */
143 /*------------------------------------------*/
144 OPCODE_NOP
= 0, /* X */
145 OPCODE_ABS
, /* X X 1.1 X */
146 OPCODE_ADD
, /* X X X X X */
148 OPCODE_ARL
, /* X X */
149 OPCODE_ARL_NV
, /* 2 */
151 OPCODE_BGNLOOP
, /* opt */
152 OPCODE_BGNSUB
, /* opt */
153 OPCODE_BRA
, /* 2 X */
154 OPCODE_BRK
, /* 2 opt */
155 OPCODE_CAL
, /* 2 2 */
157 OPCODE_CONT
, /* opt */
158 OPCODE_COS
, /* X 2 X X */
159 OPCODE_DDX
, /* X X */
160 OPCODE_DDY
, /* X X */
161 OPCODE_DP3
, /* X X X X X */
162 OPCODE_DP4
, /* X X X X X */
163 OPCODE_DPH
, /* X X 1.1 */
164 OPCODE_DST
, /* X X X X */
166 OPCODE_END
, /* X X X X opt */
167 OPCODE_ENDIF
, /* opt */
168 OPCODE_ENDLOOP
, /* opt */
169 OPCODE_ENDSUB
, /* opt */
170 OPCODE_EX2
, /* X X 2 X X */
171 OPCODE_EXP
, /* X X X */
172 OPCODE_FLR
, /* X X 2 X X */
173 OPCODE_FRC
, /* X X 2 X X */
177 OPCODE_KIL_NV
, /* X X */
178 OPCODE_LG2
, /* X X 2 X X */
179 OPCODE_LIT
, /* X X X X */
180 OPCODE_LOG
, /* X X X */
181 OPCODE_LRP
, /* X X */
182 OPCODE_MAD
, /* X X X X X */
183 OPCODE_MAX
, /* X X X X X */
184 OPCODE_MIN
, /* X X X X X */
185 OPCODE_MOV
, /* X X X X X */
186 OPCODE_MUL
, /* X X X X X */
187 OPCODE_NOISE1
, /* X */
188 OPCODE_NOISE2
, /* X */
189 OPCODE_NOISE3
, /* X */
190 OPCODE_NOISE4
, /* X */
192 OPCODE_PK2US
, /* X */
194 OPCODE_PK4UB
, /* X */
195 OPCODE_POW
, /* X X X X */
197 OPCODE_PRINT
, /* X X */
198 OPCODE_PUSHA
, /* 3 */
199 OPCODE_RCC
, /* 1.1 */
200 OPCODE_RCP
, /* X X X X X */
201 OPCODE_RET
, /* 2 2 */
202 OPCODE_RFL
, /* X X */
203 OPCODE_RSQ
, /* X X X X X */
205 OPCODE_SEQ
, /* 2 X X */
206 OPCODE_SFL
, /* 2 X */
207 OPCODE_SGE
, /* X X X X X */
208 OPCODE_SGT
, /* 2 X X */
209 OPCODE_SIN
, /* X 2 X X */
210 OPCODE_SLE
, /* 2 X X */
211 OPCODE_SLT
, /* X X X X X */
212 OPCODE_SNE
, /* 2 X X */
214 OPCODE_STR
, /* 2 X */
215 OPCODE_SUB
, /* X X 1.1 X X */
216 OPCODE_SWZ
, /* X X */
217 OPCODE_TEX
, /* X 3 X X */
218 OPCODE_TXB
, /* X 3 X */
219 OPCODE_TXD
, /* X X */
220 OPCODE_TXL
, /* 3 2 X */
221 OPCODE_TXP
, /* X X */
222 OPCODE_TXP_NV
, /* 3 X */
224 OPCODE_UP2US
, /* X */
226 OPCODE_UP4UB
, /* X */
228 OPCODE_XPD
, /* X X X */
234 * Instruction source register.
236 struct prog_src_register
238 GLuint File
:4; /**< One of the PROGRAM_* register file values. */
239 GLint Index
:9; /**< May be negative for relative addressing. */
244 * \name Source register "sign" control.
246 * The ARB and NV extensions allow varrying degrees of control over the
247 * sign of the source vector components. These values allow enough control
248 * for all flavors of the extensions.
252 * Per-component negation for the SWZ instruction. For non-SWZ
253 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
256 * ARB_vertex_program, ARB_fragment_program
261 * Take the component-wise absolute value.
264 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
265 * NV_vertex_program2_option.
270 * Post-absolute value negation (all components).
278 * Instruction destination register.
280 struct prog_dst_register
283 * One of the PROGRAM_* register file values.
291 * \name Conditional destination update control.
294 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
295 * NV_vertex_program2_option.
299 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
300 * NE, TR, or UN). Destination update is enabled if the matching
301 * (swizzled) condition code value passes. When a conditional update mask
302 * is not specified, this will be \c COND_TR.
307 * Condition code swizzle value.
309 GLuint CondSwizzle
:12;
312 * Selects the condition code register to use for conditional destination
313 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
314 * condition code register 0 is available. In NV_vertex_program3 mode,
315 * condition code registers 0 and 1 are available.
325 * Vertex/fragment program instruction.
327 struct prog_instruction
329 gl_inst_opcode Opcode
;
330 #if FEATURE_MESA_program_debug
334 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
338 struct prog_src_register SrcReg
[3];
339 struct prog_dst_register DstReg
;
342 * Indicates that the instruction should update the condition code
346 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
347 * NV_vertex_program2_option.
352 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
353 * condition code register that is to be updated.
355 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
356 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
357 * code registers 0 and 1 are available.
360 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
361 * NV_vertex_program2_option.
366 * Saturate each value of the vectored result to the range [0,1] or the
367 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
368 * only available in NV_fragment_program2 mode.
369 * Value is one of the SATURATE_* tokens.
372 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
374 GLuint SaturateMode
:2;
377 * Per-instruction selectable precision.
380 * NV_fragment_program, NV_fragment_program_option.
385 * \name Texture source controls.
387 * The texture source controls are only used with the \c TEX, \c TXD,
388 * \c TXL, and \c TXP instructions.
391 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
395 * Source texture unit. OpenGL supports a maximum of 32 texture
401 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
403 GLuint TexSrcTarget
:3;
407 * For BRA and CAL instructions, the location to jump to.
408 * For BGNLOOP, points to ENDLOOP (and vice-versa).
409 * For BRK, points to BGNLOOP (which points to ENDLOOP).
410 * For IF, points to else or endif.
411 * For ELSE, points to endif.
416 * For TEX instructions in shaders, the sampler to use for the
426 _mesa_init_instructions(struct prog_instruction
*inst
, GLuint count
);
428 extern struct prog_instruction
*
429 _mesa_alloc_instructions(GLuint numInst
);
431 extern struct prog_instruction
*
432 _mesa_realloc_instructions(struct prog_instruction
*oldInst
,
433 GLuint numOldInst
, GLuint numNewInst
);
435 extern struct prog_instruction
*
436 _mesa_copy_instructions(struct prog_instruction
*dest
,
437 const struct prog_instruction
*src
, GLuint n
);
440 _mesa_num_inst_src_regs(gl_inst_opcode opcode
);
443 _mesa_opcode_string(gl_inst_opcode opcode
);
446 #endif /* PROG_INSTRUCTION_H */