Make Saturate a 2-bit field again, renamed to SaturateMode with three
[mesa.git] / src / mesa / shader / program_instruction.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 /**
27 * \file prog_instruction.h
28 *
29 * Private vertex program types and constants only used by files
30 * related to vertex programs.
31 *
32 * \author Brian Paul
33 * \author Keith Whitwell
34 * \author Ian Romanick <idr@us.ibm.com>
35 */
36
37
38 #ifndef PROG_INSTRUCTION_H
39 #define PROG_INSTRUCTION_H
40
41 /**
42 * Condition codes for GL_NV_fragment_program
43 */
44 /*@{*/
45 #define COND_GT 1 /* greater than zero */
46 #define COND_EQ 2 /* equal to zero */
47 #define COND_LT 3 /* less than zero */
48 #define COND_UN 4 /* unordered (NaN) */
49 #define COND_GE 5 /* greater then or equal to zero */
50 #define COND_LE 6 /* less then or equal to zero */
51 #define COND_NE 7 /* not equal to zero */
52 #define COND_TR 8 /* always true */
53 #define COND_FL 9 /* always false */
54 /*@}*/
55
56
57 /**
58 * Instruction precision for GL_NV_fragment_program
59 */
60 /*@{*/
61 #define FLOAT32 0x1
62 #define FLOAT16 0x2
63 #define FIXED12 0x4
64 /*@}*/
65
66
67 /**
68 * Saturation modes when storing values.
69 */
70 /*@{*/
71 #define SATURATE_OFF 0
72 #define SATURATE_ZERO_ONE 1
73 #define SATURATE_PLUS_MINUS_ONE 2
74 /*@}*/
75
76
77 /**
78 * Program instruction opcodes, for both vertex and fragment programs.
79 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
80 */
81 /* ARB_vp ARB_fp NV_vp NV_fp */
82 enum prog_opcode { /*---------------------------------*/
83 OPCODE_ABS, /* X X 1.1 */
84 OPCODE_ADD, /* X X X X */
85 OPCODE_ARA, /* 2 */
86 OPCODE_ARL, /* X X */
87 OPCODE_ARL_NV, /* 2 */
88 OPCODE_ARR, /* 2 */
89 OPCODE_BRA, /* 2 */
90 OPCODE_CAL, /* 2 2 */
91 OPCODE_CMP, /* X */
92 OPCODE_COS, /* X 2 X */
93 OPCODE_DDX, /* X */
94 OPCODE_DDY, /* X */
95 OPCODE_DP3, /* X X X X */
96 OPCODE_DP4, /* X X X X */
97 OPCODE_DPH, /* X X 1.1 */
98 OPCODE_DST, /* X X X X */
99 OPCODE_END, /* X X X X */
100 OPCODE_EX2, /* X X 2 X */
101 OPCODE_EXP, /* X X */
102 OPCODE_FLR, /* X X 2 X */
103 OPCODE_FRC, /* X X 2 X */
104 OPCODE_KIL, /* X */
105 OPCODE_KIL_NV, /* X */
106 OPCODE_LG2, /* X X 2 X */
107 OPCODE_LIT, /* X X X X */
108 OPCODE_LOG, /* X X */
109 OPCODE_LRP, /* X X */
110 OPCODE_MAD, /* X X X X */
111 OPCODE_MAX, /* X X X X */
112 OPCODE_MIN, /* X X X X */
113 OPCODE_MOV, /* X X X X */
114 OPCODE_MUL, /* X X X X */
115 OPCODE_PK2H, /* X */
116 OPCODE_PK2US, /* X */
117 OPCODE_PK4B, /* X */
118 OPCODE_PK4UB, /* X */
119 OPCODE_POW, /* X X X */
120 OPCODE_POPA, /* 3 */
121 OPCODE_PRINT, /* X X */
122 OPCODE_PUSHA, /* 3 */
123 OPCODE_RCC, /* 1.1 */
124 OPCODE_RCP, /* X X X X */
125 OPCODE_RET, /* 2 2 */
126 OPCODE_RFL, /* X X */
127 OPCODE_RSQ, /* X X X X */
128 OPCODE_SCS, /* X */
129 OPCODE_SEQ, /* 2 X */
130 OPCODE_SFL, /* 2 X */
131 OPCODE_SGE, /* X X X X */
132 OPCODE_SGT, /* 2 X */
133 OPCODE_SIN, /* X 2 X */
134 OPCODE_SLE, /* 2 X */
135 OPCODE_SLT, /* X X X X */
136 OPCODE_SNE, /* 2 X */
137 OPCODE_SSG, /* 2 */
138 OPCODE_STR, /* 2 X */
139 OPCODE_SUB, /* X X 1.1 X */
140 OPCODE_SWZ, /* X X */
141 OPCODE_TEX, /* X 3 X */
142 OPCODE_TXB, /* X 3 */
143 OPCODE_TXD, /* X */
144 OPCODE_TXL, /* 3 2 */
145 OPCODE_TXP, /* X */
146 OPCODE_TXP_NV, /* 3 X */
147 OPCODE_UP2H, /* X */
148 OPCODE_UP2US, /* X */
149 OPCODE_UP4B, /* X */
150 OPCODE_UP4UB, /* X */
151 OPCODE_X2D, /* X */
152 OPCODE_XPD, /* X X */
153 MAX_OPCODE
154 };
155
156
157 /**
158 * Instruction source register.
159 */
160 struct prog_src_register
161 {
162 GLuint File:4; /**< One of the PROGRAM_* register file values. */
163 GLint Index:9; /**< May be negative for relative addressing. */
164 GLuint Swizzle:12;
165 GLuint RelAddr:1;
166
167 /**
168 * \name Source register "sign" control.
169 *
170 * The ARB and NV extensions allow varrying degrees of control over the
171 * sign of the source vector components. These values allow enough control
172 * for all flavors of the extensions.
173 */
174 /*@{*/
175 /**
176 * Per-component negation for the SWZ instruction.
177 *
178 * \since
179 * ARB_vertex_program, ARB_fragment_program
180 */
181 GLuint NegateBase:4;
182
183 /**
184 * Take the component-wise absolute value.
185 *
186 * \since
187 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
188 * NV_vertex_program2_option.
189 */
190 GLuint Abs:1;
191
192 /**
193 * Take the component-wise negation. The negation occurs \b after the
194 * (optional) absolute value operation.
195 */
196 GLuint NegateAbs:1;
197 /*@}*/
198 };
199
200
201 /**
202 * Instruction destination register.
203 */
204 struct prog_dst_register
205 {
206 /**
207 * One of the PROGRAM_* register file values.
208 */
209 GLuint File:4;
210
211 GLuint Index:8;
212 GLuint WriteMask:4;
213
214 /**
215 * \name Conditional destination update control.
216 *
217 * \since
218 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
219 * NV_vertex_program2_option.
220 */
221 /*@{*/
222 /**
223 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
224 * NE, TR, or UN). Destination update is enabled if the matching
225 * (swizzled) condition code value passes. When a conditional update mask
226 * is not specified, this will be \c COND_TR.
227 */
228 GLuint CondMask:4;
229
230 /**
231 * Condition code swizzle value.
232 */
233 GLuint CondSwizzle:12;
234
235 /**
236 * Selects the condition code register to use for conditional destination
237 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
238 * condition code register 0 is available. In NV_vertex_program3 mode,
239 * condition code registers 0 and 1 are available.
240 */
241 GLuint CondSrc:1;
242 /*@}*/
243
244 GLuint pad:31;
245 };
246
247
248 /**
249 * Vertex/fragment program instruction.
250 */
251 struct prog_instruction
252 {
253 enum prog_opcode Opcode;
254 #if FEATURE_MESA_program_debug
255 GLshort StringPos;
256 #endif
257 /**
258 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
259 */
260 void *Data;
261
262 struct prog_src_register SrcReg[3];
263 struct prog_dst_register DstReg;
264
265 /**
266 * Indicates that the instruction should update the condition code
267 * register.
268 *
269 * \since
270 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
271 * NV_vertex_program2_option.
272 */
273 GLuint CondUpdate:1;
274
275 /**
276 * If prog_instruction::cc_update is \c GL_TRUE, this value selects the
277 * condition code register that is to be updated.
278 *
279 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
280 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
281 * code registers 0 and 1 are available.
282 *
283 * \since
284 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
285 * NV_vertex_program2_option.
286 */
287 GLuint CondDst:1;
288
289 /**
290 * Saturate each value of the vectored result to the range [0,1] or the
291 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
292 * only available in NV_fragment_program2 mode.
293 * Value is one of the SATURATE_* tokens.
294 *
295 * \since
296 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
297 */
298 GLuint SaturateMode:2;
299
300 /**
301 * Per-instruction selectable precision.
302 *
303 * \since
304 * NV_fragment_program, NV_fragment_program_option.
305 */
306 GLuint Precision:3;
307
308 /**
309 * \name Texture source controls.
310 *
311 * The texture source controls are only used with the \c TEX, \c TXD,
312 * \c TXL, and \c TXP instructions.
313 *
314 * \since
315 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
316 */
317 /*@{*/
318 /**
319 * Source texture unit. OpenGL supports a maximum of 32 texture
320 * units.
321 */
322 GLuint TexSrcUnit:5;
323
324 /**
325 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
326 */
327 GLuint TexSrcTarget:3;
328 /*@}*/
329 };
330
331
332 extern void
333 _mesa_init_instruction(struct prog_instruction *inst);
334
335 extern GLuint
336 _mesa_num_inst_src_regs(enum prog_opcode opcode);
337
338 extern const char *
339 _mesa_opcode_string(enum prog_opcode opcode);
340
341
342 #endif /* PROG_INSTRUCTION_H */