2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 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 * Private vertex program types and constants only used by files
30 * related to vertex programs.
33 * \author Keith Whitwell
34 * \author Ian Romanick <idr@us.ibm.com>
38 #ifndef PROG_INSTRUCTION_H
39 #define PROG_INSTRUCTION_H
42 /* for GL_ARB_v_p and GL_ARB_f_p SWZ instruction */
47 #define SWIZZLE_ZERO 4 /* keep these values together: KW */
48 #define SWIZZLE_ONE 5 /* keep these values together: KW */
50 #define MAKE_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<3) | ((c)<<6) | ((d)<<9))
51 #define SWIZZLE_NOOP MAKE_SWIZZLE4(0,1,2,3)
52 #define GET_SWZ(swz, idx) (((swz) >> ((idx)*3)) & 0x7)
53 #define GET_BIT(msk, idx) (((msk) >> (idx)) & 0x1)
56 #define WRITEMASK_X 0x1
57 #define WRITEMASK_Y 0x2
58 #define WRITEMASK_XY 0x3
59 #define WRITEMASK_Z 0x4
60 #define WRITEMASK_XZ 0x5
61 #define WRITEMASK_YZ 0x6
62 #define WRITEMASK_XYZ 0x7
63 #define WRITEMASK_W 0x8
64 #define WRITEMASK_XW 0x9
65 #define WRITEMASK_YW 0xa
66 #define WRITEMASK_XYW 0xb
67 #define WRITEMASK_ZW 0xc
68 #define WRITEMASK_XZW 0xd
69 #define WRITEMASK_YZW 0xe
70 #define WRITEMASK_XYZW 0xf
74 * Condition codes for GL_NV_fragment_program
77 #define COND_GT 1 /* greater than zero */
78 #define COND_EQ 2 /* equal to zero */
79 #define COND_LT 3 /* less than zero */
80 #define COND_UN 4 /* unordered (NaN) */
81 #define COND_GE 5 /* greater then or equal to zero */
82 #define COND_LE 6 /* less then or equal to zero */
83 #define COND_NE 7 /* not equal to zero */
84 #define COND_TR 8 /* always true */
85 #define COND_FL 9 /* always false */
90 * Instruction precision for GL_NV_fragment_program
100 * Saturation modes when storing values.
103 #define SATURATE_OFF 0
104 #define SATURATE_ZERO_ONE 1
105 #define SATURATE_PLUS_MINUS_ONE 2
110 * Per-component negation masks
117 #define NEGATE_XYZW 0xf
118 #define NEGATE_NONE 0x0
123 * Program instruction opcodes, for both vertex and fragment programs.
124 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
126 typedef enum prog_opcode
{
127 /* ARB_vp ARB_fp NV_vp NV_fp */
128 /*---------------------------------*/
130 OPCODE_ABS
, /* X X 1.1 */
131 OPCODE_ADD
, /* X X X X */
133 OPCODE_ARL
, /* X X */
134 OPCODE_ARL_NV
, /* 2 */
137 OPCODE_CAL
, /* 2 2 */
139 OPCODE_COS
, /* X 2 X */
142 OPCODE_DP3
, /* X X X X */
143 OPCODE_DP4
, /* X X X X */
144 OPCODE_DPH
, /* X X 1.1 */
145 OPCODE_DST
, /* X X X X */
146 OPCODE_END
, /* X X X X */
147 OPCODE_EX2
, /* X X 2 X */
148 OPCODE_EXP
, /* X X */
149 OPCODE_FLR
, /* X X 2 X */
150 OPCODE_FRC
, /* X X 2 X */
153 OPCODE_KIL_NV
, /* X */
154 OPCODE_LG2
, /* X X 2 X */
155 OPCODE_LIT
, /* X X X X */
156 OPCODE_LOG
, /* X X */
157 OPCODE_LRP
, /* X X */
158 OPCODE_MAD
, /* X X X X */
159 OPCODE_MAX
, /* X X X X */
160 OPCODE_MIN
, /* X X X X */
161 OPCODE_MOV
, /* X X X X */
162 OPCODE_MUL
, /* X X X X */
164 OPCODE_PK2US
, /* X */
166 OPCODE_PK4UB
, /* X */
167 OPCODE_POW
, /* X X X */
169 OPCODE_PRINT
, /* X X */
170 OPCODE_PUSHA
, /* 3 */
171 OPCODE_RCC
, /* 1.1 */
172 OPCODE_RCP
, /* X X X X */
173 OPCODE_RET
, /* 2 2 */
174 OPCODE_RFL
, /* X X */
175 OPCODE_RSQ
, /* X X X X */
177 OPCODE_SEQ
, /* 2 X */
178 OPCODE_SFL
, /* 2 X */
179 OPCODE_SGE
, /* X X X X */
180 OPCODE_SGT
, /* 2 X */
181 OPCODE_SIN
, /* X 2 X */
182 OPCODE_SLE
, /* 2 X */
183 OPCODE_SLT
, /* X X X X */
184 OPCODE_SNE
, /* 2 X */
186 OPCODE_STR
, /* 2 X */
187 OPCODE_SUB
, /* X X 1.1 X */
188 OPCODE_SWZ
, /* X X */
189 OPCODE_TEX
, /* X 3 X */
190 OPCODE_TXB
, /* X 3 */
192 OPCODE_TXL
, /* 3 2 */
194 OPCODE_TXP_NV
, /* 3 X */
196 OPCODE_UP2US
, /* X */
198 OPCODE_UP4UB
, /* X */
200 OPCODE_XPD
, /* X X */
206 * Instruction source register.
208 struct prog_src_register
210 GLuint File
:4; /**< One of the PROGRAM_* register file values. */
211 GLint Index
:9; /**< May be negative for relative addressing. */
216 * \name Source register "sign" control.
218 * The ARB and NV extensions allow varrying degrees of control over the
219 * sign of the source vector components. These values allow enough control
220 * for all flavors of the extensions.
224 * Per-component negation for the SWZ instruction. For non-SWZ
225 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
228 * ARB_vertex_program, ARB_fragment_program
233 * Take the component-wise absolute value.
236 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
237 * NV_vertex_program2_option.
242 * Post-absolute value negation (all components).
250 * Instruction destination register.
252 struct prog_dst_register
255 * One of the PROGRAM_* register file values.
263 * \name Conditional destination update control.
266 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
267 * NV_vertex_program2_option.
271 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
272 * NE, TR, or UN). Destination update is enabled if the matching
273 * (swizzled) condition code value passes. When a conditional update mask
274 * is not specified, this will be \c COND_TR.
279 * Condition code swizzle value.
281 GLuint CondSwizzle
:12;
284 * Selects the condition code register to use for conditional destination
285 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
286 * condition code register 0 is available. In NV_vertex_program3 mode,
287 * condition code registers 0 and 1 are available.
297 * Vertex/fragment program instruction.
299 struct prog_instruction
301 gl_inst_opcode Opcode
;
302 #if FEATURE_MESA_program_debug
306 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
310 struct prog_src_register SrcReg
[3];
311 struct prog_dst_register DstReg
;
314 * Indicates that the instruction should update the condition code
318 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
319 * NV_vertex_program2_option.
324 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
325 * condition code register that is to be updated.
327 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
328 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
329 * code registers 0 and 1 are available.
332 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
333 * NV_vertex_program2_option.
338 * Saturate each value of the vectored result to the range [0,1] or the
339 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
340 * only available in NV_fragment_program2 mode.
341 * Value is one of the SATURATE_* tokens.
344 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
346 GLuint SaturateMode
:2;
349 * Per-instruction selectable precision.
352 * NV_fragment_program, NV_fragment_program_option.
357 * \name Texture source controls.
359 * The texture source controls are only used with the \c TEX, \c TXD,
360 * \c TXL, and \c TXP instructions.
363 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
367 * Source texture unit. OpenGL supports a maximum of 32 texture
373 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
375 GLuint TexSrcTarget
:3;
379 * For BRA and CAL instructions, the location to jump to.
384 * For TEX instructions in shaders, the sampler to use for the
394 _mesa_init_instructions(struct prog_instruction
*inst
, GLuint count
);
396 extern struct prog_instruction
*
397 _mesa_alloc_instructions(GLuint numInst
);
399 extern struct prog_instruction
*
400 _mesa_realloc_instructions(struct prog_instruction
*oldInst
,
401 GLuint numOldInst
, GLuint numNewInst
);
404 _mesa_num_inst_src_regs(gl_inst_opcode opcode
);
407 _mesa_opcode_string(gl_inst_opcode opcode
);
410 #endif /* PROG_INSTRUCTION_H */