blob: b1001885e0a09bf244df2b2decbcd6c3565f21d7 [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
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/* for GL_ARB_v_p and GL_ARB_f_p SWZ instruction */
43#define SWIZZLE_X 0
44#define SWIZZLE_Y 1
45#define SWIZZLE_Z 2
46#define SWIZZLE_W 3
47#define SWIZZLE_ZERO 4 /* keep these values together: KW */
48#define SWIZZLE_ONE 5 /* keep these values together: KW */
49
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)
54
55
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
71
72
73/**
74 * Condition codes for GL_NV_fragment_program
75 */
76/*@{*/
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 */
86/*@}*/
87
88
89/**
90 * Instruction precision for GL_NV_fragment_program
91 */
92/*@{*/
93#define FLOAT32 0x1
94#define FLOAT16 0x2
95#define FIXED12 0x4
96/*@}*/
97
98
99/**
100 * Saturation modes when storing values.
101 */
102/*@{*/
103#define SATURATE_OFF 0
104#define SATURATE_ZERO_ONE 1
105#define SATURATE_PLUS_MINUS_ONE 2
106/*@}*/
107
108
109/**
110 * Per-component negation masks
111 */
112/*@{*/
113#define NEGATE_X 0x1
114#define NEGATE_Y 0x2
115#define NEGATE_Z 0x4
116#define NEGATE_W 0x8
117#define NEGATE_XYZW 0xf
118#define NEGATE_NONE 0x0
119/*@}*/
120
121
122/**
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
125 */
126typedef enum prog_opcode {
127 /* ARB_vp ARB_fp NV_vp NV_fp */
128 /*---------------------------------*/
129 OPCODE_NOP = 0,
130 OPCODE_ABS, /* X X 1.1 */
131 OPCODE_ADD, /* X X X X */
132 OPCODE_ARA, /* 2 */
133 OPCODE_ARL, /* X X */
134 OPCODE_ARL_NV, /* 2 */
135 OPCODE_ARR, /* 2 */
136 OPCODE_BRA, /* 2 */
137 OPCODE_CAL, /* 2 2 */
138 OPCODE_CMP, /* X */
139 OPCODE_COS, /* X 2 X */
140 OPCODE_DDX, /* X */
141 OPCODE_DDY, /* 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 */
Brian5ae49cf2007-01-20 09:27:40 -0700146 OPCODE_ELSE,
Brian00cdc0a2006-12-14 15:01:06 -0700147 OPCODE_END, /* X X X X */
Brian5ae49cf2007-01-20 09:27:40 -0700148 OPCODE_ENDIF,
Brian00cdc0a2006-12-14 15:01:06 -0700149 OPCODE_EX2, /* X X 2 X */
150 OPCODE_EXP, /* X X */
151 OPCODE_FLR, /* X X 2 X */
152 OPCODE_FRC, /* X X 2 X */
Brian5ae49cf2007-01-20 09:27:40 -0700153 OPCODE_IF,
Brian0bad2362007-01-17 15:54:14 -0700154 OPCODE_INT, /* */
Brian00cdc0a2006-12-14 15:01:06 -0700155 OPCODE_KIL, /* X */
156 OPCODE_KIL_NV, /* X */
157 OPCODE_LG2, /* X X 2 X */
158 OPCODE_LIT, /* X X X X */
159 OPCODE_LOG, /* X X */
160 OPCODE_LRP, /* X X */
161 OPCODE_MAD, /* X X X X */
162 OPCODE_MAX, /* X X X X */
163 OPCODE_MIN, /* X X X X */
164 OPCODE_MOV, /* X X X X */
165 OPCODE_MUL, /* X X X X */
166 OPCODE_PK2H, /* X */
167 OPCODE_PK2US, /* X */
168 OPCODE_PK4B, /* X */
169 OPCODE_PK4UB, /* X */
170 OPCODE_POW, /* X X X */
171 OPCODE_POPA, /* 3 */
172 OPCODE_PRINT, /* X X */
173 OPCODE_PUSHA, /* 3 */
174 OPCODE_RCC, /* 1.1 */
175 OPCODE_RCP, /* X X X X */
176 OPCODE_RET, /* 2 2 */
177 OPCODE_RFL, /* X X */
178 OPCODE_RSQ, /* X X X X */
179 OPCODE_SCS, /* X */
180 OPCODE_SEQ, /* 2 X */
181 OPCODE_SFL, /* 2 X */
182 OPCODE_SGE, /* X X X X */
183 OPCODE_SGT, /* 2 X */
184 OPCODE_SIN, /* X 2 X */
185 OPCODE_SLE, /* 2 X */
186 OPCODE_SLT, /* X X X X */
187 OPCODE_SNE, /* 2 X */
188 OPCODE_SSG, /* 2 */
189 OPCODE_STR, /* 2 X */
190 OPCODE_SUB, /* X X 1.1 X */
191 OPCODE_SWZ, /* X X */
192 OPCODE_TEX, /* X 3 X */
193 OPCODE_TXB, /* X 3 */
194 OPCODE_TXD, /* X */
195 OPCODE_TXL, /* 3 2 */
196 OPCODE_TXP, /* X */
197 OPCODE_TXP_NV, /* 3 X */
198 OPCODE_UP2H, /* X */
199 OPCODE_UP2US, /* X */
200 OPCODE_UP4B, /* X */
201 OPCODE_UP4UB, /* X */
202 OPCODE_X2D, /* X */
203 OPCODE_XPD, /* X X */
204 MAX_OPCODE
205} gl_inst_opcode;
206
207
208/**
209 * Instruction source register.
210 */
211struct prog_src_register
212{
213 GLuint File:4; /**< One of the PROGRAM_* register file values. */
214 GLint Index:9; /**< May be negative for relative addressing. */
215 GLuint Swizzle:12;
216 GLuint RelAddr:1;
217
218 /**
219 * \name Source register "sign" control.
220 *
221 * The ARB and NV extensions allow varrying degrees of control over the
222 * sign of the source vector components. These values allow enough control
223 * for all flavors of the extensions.
224 */
225 /*@{*/
226 /**
227 * Per-component negation for the SWZ instruction. For non-SWZ
228 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
229 *
230 * \since
231 * ARB_vertex_program, ARB_fragment_program
232 */
233 GLuint NegateBase:4;
234
235 /**
236 * Take the component-wise absolute value.
237 *
238 * \since
239 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
240 * NV_vertex_program2_option.
241 */
242 GLuint Abs:1;
243
244 /**
245 * Post-absolute value negation (all components).
246 */
247 GLuint NegateAbs:1;
248 /*@}*/
249};
250
251
252/**
253 * Instruction destination register.
254 */
255struct prog_dst_register
256{
257 /**
258 * One of the PROGRAM_* register file values.
259 */
260 GLuint File:4;
261
262 GLuint Index:8;
263 GLuint WriteMask:4;
264
265 /**
266 * \name Conditional destination update control.
267 *
268 * \since
269 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
270 * NV_vertex_program2_option.
271 */
272 /*@{*/
273 /**
274 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
275 * NE, TR, or UN). Destination update is enabled if the matching
276 * (swizzled) condition code value passes. When a conditional update mask
277 * is not specified, this will be \c COND_TR.
278 */
279 GLuint CondMask:4;
280
281 /**
282 * Condition code swizzle value.
283 */
284 GLuint CondSwizzle:12;
285
286 /**
287 * Selects the condition code register to use for conditional destination
288 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
289 * condition code register 0 is available. In NV_vertex_program3 mode,
290 * condition code registers 0 and 1 are available.
291 */
292 GLuint CondSrc:1;
293 /*@}*/
294
295 GLuint pad:31;
296};
297
298
299/**
300 * Vertex/fragment program instruction.
301 */
302struct prog_instruction
303{
304 gl_inst_opcode Opcode;
305#if FEATURE_MESA_program_debug
306 GLshort StringPos;
307#endif
308 /**
309 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
310 */
311 void *Data;
312
313 struct prog_src_register SrcReg[3];
314 struct prog_dst_register DstReg;
315
316 /**
317 * Indicates that the instruction should update the condition code
318 * register.
319 *
320 * \since
321 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
322 * NV_vertex_program2_option.
323 */
324 GLuint CondUpdate:1;
325
326 /**
327 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
328 * condition code register that is to be updated.
329 *
330 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
331 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
332 * code registers 0 and 1 are available.
333 *
334 * \since
335 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
336 * NV_vertex_program2_option.
337 */
338 GLuint CondDst:1;
339
340 /**
341 * Saturate each value of the vectored result to the range [0,1] or the
342 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
343 * only available in NV_fragment_program2 mode.
344 * Value is one of the SATURATE_* tokens.
345 *
346 * \since
347 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
348 */
349 GLuint SaturateMode:2;
350
351 /**
352 * Per-instruction selectable precision.
353 *
354 * \since
355 * NV_fragment_program, NV_fragment_program_option.
356 */
357 GLuint Precision:3;
358
359 /**
360 * \name Texture source controls.
361 *
362 * The texture source controls are only used with the \c TEX, \c TXD,
363 * \c TXL, and \c TXP instructions.
364 *
365 * \since
366 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
367 */
368 /*@{*/
369 /**
370 * Source texture unit. OpenGL supports a maximum of 32 texture
371 * units.
372 */
373 GLuint TexSrcUnit:5;
374
375 /**
376 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
377 */
378 GLuint TexSrcTarget:3;
379 /*@}*/
380
381 /**
382 * For BRA and CAL instructions, the location to jump to.
383 */
384 GLuint BranchTarget;
385
Brianeef70ff2007-01-05 16:01:26 -0700386 /**
387 * For TEX instructions in shaders, the sampler to use for the
388 * texture lookup.
389 */
390 GLint Sampler;
391
Brian00cdc0a2006-12-14 15:01:06 -0700392 const char *Comment;
393};
394
395
396extern void
397_mesa_init_instructions(struct prog_instruction *inst, GLuint count);
398
399extern struct prog_instruction *
400_mesa_alloc_instructions(GLuint numInst);
401
402extern struct prog_instruction *
403_mesa_realloc_instructions(struct prog_instruction *oldInst,
404 GLuint numOldInst, GLuint numNewInst);
405
406extern GLuint
407_mesa_num_inst_src_regs(gl_inst_opcode opcode);
408
409extern const char *
410_mesa_opcode_string(gl_inst_opcode opcode);
411
412
413#endif /* PROG_INSTRUCTION_H */