Unify vertex/fragment program instuctions.
[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 * Program instruction opcodes, for both vertex and fragment programs.
69 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
70 */
71 /* ARB_vp ARB_fp NV_vp NV_fp */
72 enum prog_opcode { /*---------------------------------*/
73 OPCODE_ABS, /* X 1.1 */
74 OPCODE_ADD, /* X X X X */
75 OPCODE_ARL, /* X X */
76 OPCODE_CMP, /* X */
77 OPCODE_COS, /* X 2 */
78 OPCODE_DDX, /* X */
79 OPCODE_DDY, /* X */
80 OPCODE_DP3, /* X X X X */
81 OPCODE_DP4, /* X X X X */
82 OPCODE_DPH, /* X X 1.1 */
83 OPCODE_DST, /* X X X */
84 OPCODE_END, /* X X X X */
85 OPCODE_EX2, /* X X 2 X */
86 OPCODE_EXP, /* X X */
87 OPCODE_FLR, /* X X 2 X */
88 OPCODE_FRC, /* X X 2 X */
89 OPCODE_KIL, /* X */
90 OPCODE_KIL_NV, /* X */
91 OPCODE_LG2, /* X X 2 X */
92 OPCODE_LIT, /* X X X X */
93 OPCODE_LOG, /* X X X */
94 OPCODE_LRP, /* X X */
95 OPCODE_MAD, /* X X X X */
96 OPCODE_MAX, /* X X X X */
97 OPCODE_MIN, /* X X X X */
98 OPCODE_MOV, /* X X X X */
99 OPCODE_MUL, /* X X X X */
100 OPCODE_PK2H, /* X */
101 OPCODE_PK2US, /* X */
102 OPCODE_PK4B, /* X */
103 OPCODE_PK4UB, /* X */
104 OPCODE_POW, /* X X X */
105 OPCODE_PRINT, /* X X */
106 OPCODE_RCC, /* 1.1 */
107 OPCODE_RCP, /* X X X X */
108 OPCODE_RFL, /* X X */
109 OPCODE_RSQ, /* X X X X */
110 OPCODE_SCS, /* X */
111 OPCODE_SEQ, /* 2 X */
112 OPCODE_SFL, /* 2 X */
113 OPCODE_SGE, /* X X X X */
114 OPCODE_SGT, /* 2 X */
115 OPCODE_SIN, /* X 2 X */
116 OPCODE_SLE, /* 2 X */
117 OPCODE_SLT, /* X X X X */
118 OPCODE_SNE, /* 2 X */
119 OPCODE_STR, /* X 2 X */
120 OPCODE_SUB, /* X X 1.1 X */
121 OPCODE_SWZ, /* X X */
122 OPCODE_TEX, /* X X */
123 OPCODE_TXB, /* X */
124 OPCODE_TXD, /* X X */
125 OPCODE_TXP, /* X */
126 OPCODE_TXP_NV, /* X */
127 OPCODE_UP2H, /* X */
128 OPCODE_UP2US, /* X */
129 OPCODE_UP4B, /* X */
130 OPCODE_UP4UB, /* X */
131 OPCODE_X2D, /* X */
132 OPCODE_XPD, /* X X */
133 #if 0
134 OPCODE_ARA, /* NV_vertex_program2 */
135 OPCODE_ARL_NV, /* NV_vertex_program2 */
136 OPCODE_ARR, /* NV_vertex_program2 */
137
138 OPCODE_SEQ, /* NV_vertex_program2 */
139 OPCODE_SFL, /* NV_vertex_program2 */
140 OPCODE_SGT, /* NV_vertex_program2 */
141 OPCODE_SLE, /* NV_vertex_program2 */
142 OPCODE_SNE, /* NV_vertex_program2 */
143 OPCODE_STR, /* NV_vertex_program2 */
144
145 OPCODE_SSG, /* NV_vertex_program2 */
146 OPCODE_COS, /* NV_vertex_program2 */
147 OPCODE_SIN, /* NV_vertex_program2 */
148
149 OPCODE_BRA, /* NV_vertex_program2 */
150 OPCODE_CAL, /* NV_vertex_program2 */
151 OPCODE_RET, /* NV_vertex_program2 */
152
153 OPCODE_PUSHA, /* NV_vertex_program3 */
154 OPCODE_POPA, /* NV_vertex_program3 */
155
156 OPCODE_TEX, /* NV_vertex_program3 */
157 OPCODE_TXB, /* NV_vertex_program3 */
158 OPCODE_TXL, /* NV_vertex_program3 */
159 OPCODE_TXP, /* NV_vertex_program3 */
160 #endif
161 MAX_OPCODE
162 };
163
164
165 /**
166 * Instruction source register.
167 */
168 struct prog_src_register
169 {
170 GLuint File:4; /**< One of the PROGRAM_* register file values. */
171 GLint Index:9; /**< May be negative for relative addressing. */
172 GLuint Swizzle:12;
173 GLuint RelAddr:1;
174
175 /**
176 * \name Source register "sign" control.
177 *
178 * The ARB and NV extensions allow varrying degrees of control over the
179 * sign of the source vector components. These values allow enough control
180 * for all flavors of the extensions.
181 */
182 /*@{*/
183 /**
184 * Per-component negation for the SWZ instruction.
185 *
186 * \since
187 * ARB_vertex_program, ARB_fragment_program
188 */
189 GLuint NegateBase:4;
190
191 /**
192 * Take the component-wise absolute value.
193 *
194 * \since
195 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
196 * NV_vertex_program2_option.
197 */
198 GLuint Abs:1;
199
200 /**
201 * Take the component-wise negation. The negation occurs \b after the
202 * (optional) absolute value operation.
203 */
204 GLuint NegateAbs:1;
205 /*@}*/
206 };
207
208
209 /**
210 * Instruction destination register.
211 */
212 struct prog_dst_register
213 {
214 /**
215 * One of the PROGRAM_* register file values.
216 */
217 GLuint File:4;
218
219 GLuint Index:8;
220 GLuint WriteMask:4;
221
222 /**
223 * \name Conditional destination update control.
224 *
225 * \since
226 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
227 * NV_vertex_program2_option.
228 */
229 /*@{*/
230 /**
231 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
232 * NE, TR, or UN). Destination update is enabled if the matching
233 * (swizzled) condition code value passes. When a conditional update mask
234 * is not specified, this will be \c COND_TR.
235 */
236 GLuint CondMask:4;
237
238 /**
239 * Condition code swizzle value.
240 */
241 GLuint CondSwizzle:12;
242
243 /**
244 * Selects the condition code register to use for conditional destination
245 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
246 * condition code register 0 is available. In NV_vertex_program3 mode,
247 * condition code registers 0 and 1 are available.
248 */
249 GLuint CondSrc:1;
250 /*@}*/
251
252 GLuint pad:31;
253 };
254
255
256 /**
257 * Vertex/fragment program instruction.
258 */
259 struct prog_instruction
260 {
261 enum prog_opcode Opcode;
262 #if FEATURE_MESA_program_debug
263 GLshort StringPos;
264 #endif
265 /**
266 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
267 */
268 void *Data;
269
270 struct prog_src_register SrcReg[3];
271 struct prog_dst_register DstReg;
272
273 /**
274 * Indicates that the instruction should update the condition code
275 * register.
276 *
277 * \since
278 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
279 * NV_vertex_program2_option.
280 */
281 GLuint CondUpdate:1;
282
283 /**
284 * If prog_instruction::cc_update is \c GL_TRUE, this value selects the
285 * condition code register that is to be updated.
286 *
287 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
288 * code register 0 is available. In GL_NV_vertex_program3 mode, condition code registers
289 * 0 and 1 are available.
290 *
291 * \since
292 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
293 * NV_vertex_program2_option.
294 */
295 GLuint CondDst:1;
296
297 /**
298 * Saturate each value of the vectored result to the range [0,1] or the
299 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
300 * only available in NV_fragment_program2 mode.
301 *
302 * \since
303 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
304 */
305 GLuint Saturate:2;
306
307 /**
308 * Per-instruction selectable precision.
309 *
310 * \since
311 * NV_fragment_program, NV_fragment_program_option.
312 */
313 GLuint Precision:3;
314
315 /**
316 * \name Texture source controls.
317 *
318 * The texture source controls are only used with the \c TEX, \c TXD,
319 * \c TXL, and \c TXP instructions.
320 *
321 * \since
322 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
323 */
324 /*@{*/
325 /**
326 * Source texture unit. OpenGL supports a maximum of 32 texture
327 * units.
328 */
329 GLuint TexSrcUnit:5;
330
331 /**
332 * Source texture target (e.g., GL_TEXTURE_1D, GL_TEXTURE_2D,
333 * GL_TEXTURE_3D, GL_TEXTURE_CUBE, GL_TEXTURE_RECTANGLE_ARB).
334 */
335 GLuint TexSrcTarget:3;
336 /*@}*/
337 };
338
339
340 extern void
341 _mesa_init_instruction(struct prog_instruction *inst);
342
343
344 #endif /* PROG_INSTRUCTION_H */