blob: 2cb2014cd4852ea167f69b6710176245e17d138e [file] [log] [blame]
Brian00cdc0a2006-12-14 15:01:06 -07001/*
2 * Mesa 3-D graphics library
Brian6d4e5612007-01-23 17:39:25 -07003 * Version: 6.5.3
Brian00cdc0a2006-12-14 15:01:06 -07004 *
Brian6d4e5612007-01-23 17:39:25 -07005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Brian00cdc0a2006-12-14 15:01:06 -07006 *
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 *
Brianc920d202007-01-23 17:41:25 -070029 * Vertex/fragment program instruction datatypes and constants.
Brian00cdc0a2006-12-14 15:01:06 -070030 *
31 * \author Brian Paul
32 * \author Keith Whitwell
33 * \author Ian Romanick <idr@us.ibm.com>
34 */
35
36
37#ifndef PROG_INSTRUCTION_H
38#define PROG_INSTRUCTION_H
39
40
Brian6d4e5612007-01-23 17:39:25 -070041/**
42 * Swizzle indexes.
43 * Do not change!
44 */
45/*@{*/
Brian00cdc0a2006-12-14 15:01:06 -070046#define SWIZZLE_X 0
47#define SWIZZLE_Y 1
48#define SWIZZLE_Z 2
49#define SWIZZLE_W 3
Brian6d4e5612007-01-23 17:39:25 -070050#define SWIZZLE_ZERO 4 /**< For SWZ instruction only */
51#define SWIZZLE_ONE 5 /**< For SWZ instruction only */
Brianb63c1002007-01-31 16:34:54 -070052#define SWIZZLE_NIL 7 /**< used during shader code gen (undefined value) */
Brian6d4e5612007-01-23 17:39:25 -070053/*@}*/
Brian00cdc0a2006-12-14 15:01:06 -070054
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)
59
Brian629ec2b2007-03-21 15:40:54 -060060#define SWIZZLE_XYZW MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W)
Brianbd894c42007-02-20 10:40:08 -070061#define SWIZZLE_XXXX MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X)
62#define SWIZZLE_YYYY MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y)
63#define SWIZZLE_ZZZZ MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z)
64#define SWIZZLE_WWWW MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
65
Brian00cdc0a2006-12-14 15:01:06 -070066
Brian6d4e5612007-01-23 17:39:25 -070067/**
68 * Writemask values, 1 bit per component.
69 */
70/*@{*/
Brian00cdc0a2006-12-14 15:01:06 -070071#define WRITEMASK_X 0x1
72#define WRITEMASK_Y 0x2
73#define WRITEMASK_XY 0x3
74#define WRITEMASK_Z 0x4
75#define WRITEMASK_XZ 0x5
76#define WRITEMASK_YZ 0x6
77#define WRITEMASK_XYZ 0x7
78#define WRITEMASK_W 0x8
79#define WRITEMASK_XW 0x9
80#define WRITEMASK_YW 0xa
81#define WRITEMASK_XYW 0xb
82#define WRITEMASK_ZW 0xc
83#define WRITEMASK_XZW 0xd
84#define WRITEMASK_YZW 0xe
85#define WRITEMASK_XYZW 0xf
Brian6d4e5612007-01-23 17:39:25 -070086/*@}*/
Brian00cdc0a2006-12-14 15:01:06 -070087
88
89/**
Brian6d4e5612007-01-23 17:39:25 -070090 * Condition codes
Brian00cdc0a2006-12-14 15:01:06 -070091 */
92/*@{*/
Brian6d4e5612007-01-23 17:39:25 -070093#define COND_GT 1 /**< greater than zero */
94#define COND_EQ 2 /**< equal to zero */
95#define COND_LT 3 /**< less than zero */
96#define COND_UN 4 /**< unordered (NaN) */
97#define COND_GE 5 /**< greater then or equal to zero */
98#define COND_LE 6 /**< less then or equal to zero */
99#define COND_NE 7 /**< not equal to zero */
100#define COND_TR 8 /**< always true */
101#define COND_FL 9 /**< always false */
Brian00cdc0a2006-12-14 15:01:06 -0700102/*@}*/
103
104
105/**
106 * Instruction precision for GL_NV_fragment_program
107 */
108/*@{*/
109#define FLOAT32 0x1
110#define FLOAT16 0x2
111#define FIXED12 0x4
112/*@}*/
113
114
115/**
116 * Saturation modes when storing values.
117 */
118/*@{*/
119#define SATURATE_OFF 0
120#define SATURATE_ZERO_ONE 1
121#define SATURATE_PLUS_MINUS_ONE 2
122/*@}*/
123
124
125/**
126 * Per-component negation masks
127 */
128/*@{*/
129#define NEGATE_X 0x1
130#define NEGATE_Y 0x2
131#define NEGATE_Z 0x4
132#define NEGATE_W 0x8
133#define NEGATE_XYZW 0xf
134#define NEGATE_NONE 0x0
135/*@}*/
136
137
138/**
139 * Program instruction opcodes, for both vertex and fragment programs.
140 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
141 */
142typedef enum prog_opcode {
Brian6d4e5612007-01-23 17:39:25 -0700143 /* ARB_vp ARB_fp NV_vp NV_fp GLSL */
144 /*------------------------------------------*/
145 OPCODE_NOP = 0, /* X */
146 OPCODE_ABS, /* X X 1.1 X */
147 OPCODE_ADD, /* X X X X X */
Brian Paul37eef7b2008-11-07 09:33:55 -0700148 OPCODE_AND, /* */
Brian6d4e5612007-01-23 17:39:25 -0700149 OPCODE_ARA, /* 2 */
150 OPCODE_ARL, /* X X */
151 OPCODE_ARL_NV, /* 2 */
152 OPCODE_ARR, /* 2 */
Brian01001d82007-02-05 11:28:15 -0700153 OPCODE_BGNLOOP, /* opt */
154 OPCODE_BGNSUB, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700155 OPCODE_BRA, /* 2 X */
Brian01001d82007-02-05 11:28:15 -0700156 OPCODE_BRK, /* 2 opt */
Brian6d4e5612007-01-23 17:39:25 -0700157 OPCODE_CAL, /* 2 2 */
158 OPCODE_CMP, /* X */
Brian01001d82007-02-05 11:28:15 -0700159 OPCODE_CONT, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700160 OPCODE_COS, /* X 2 X X */
161 OPCODE_DDX, /* X X */
162 OPCODE_DDY, /* X X */
163 OPCODE_DP3, /* X X X X X */
164 OPCODE_DP4, /* X X X X X */
165 OPCODE_DPH, /* X X 1.1 */
166 OPCODE_DST, /* X X X X */
167 OPCODE_ELSE, /* X */
Brian01001d82007-02-05 11:28:15 -0700168 OPCODE_END, /* X X X X opt */
169 OPCODE_ENDIF, /* opt */
170 OPCODE_ENDLOOP, /* opt */
171 OPCODE_ENDSUB, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700172 OPCODE_EX2, /* X X 2 X X */
173 OPCODE_EXP, /* X X X */
174 OPCODE_FLR, /* X X 2 X X */
175 OPCODE_FRC, /* X X 2 X X */
Brian01001d82007-02-05 11:28:15 -0700176 OPCODE_IF, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700177 OPCODE_KIL, /* X */
178 OPCODE_KIL_NV, /* X X */
179 OPCODE_LG2, /* X X 2 X X */
180 OPCODE_LIT, /* X X X X */
181 OPCODE_LOG, /* X X X */
182 OPCODE_LRP, /* X X */
183 OPCODE_MAD, /* X X X X X */
184 OPCODE_MAX, /* X X X X X */
185 OPCODE_MIN, /* X X X X X */
186 OPCODE_MOV, /* X X X X X */
187 OPCODE_MUL, /* X X X X X */
Brian7aece102007-01-28 19:01:35 -0700188 OPCODE_NOISE1, /* X */
189 OPCODE_NOISE2, /* X */
190 OPCODE_NOISE3, /* X */
191 OPCODE_NOISE4, /* X */
Brian Paul37eef7b2008-11-07 09:33:55 -0700192 OPCODE_NOT, /* */
Brian Paulf6ead502008-11-07 08:51:31 -0700193 OPCODE_NRM3, /* */
194 OPCODE_NRM4, /* */
Brian Paul37eef7b2008-11-07 09:33:55 -0700195 OPCODE_OR, /* */
Brian6d4e5612007-01-23 17:39:25 -0700196 OPCODE_PK2H, /* X */
197 OPCODE_PK2US, /* X */
198 OPCODE_PK4B, /* X */
199 OPCODE_PK4UB, /* X */
200 OPCODE_POW, /* X X X X */
201 OPCODE_POPA, /* 3 */
202 OPCODE_PRINT, /* X X */
203 OPCODE_PUSHA, /* 3 */
204 OPCODE_RCC, /* 1.1 */
205 OPCODE_RCP, /* X X X X X */
206 OPCODE_RET, /* 2 2 */
207 OPCODE_RFL, /* X X */
208 OPCODE_RSQ, /* X X X X X */
209 OPCODE_SCS, /* X */
210 OPCODE_SEQ, /* 2 X X */
211 OPCODE_SFL, /* 2 X */
212 OPCODE_SGE, /* X X X X X */
213 OPCODE_SGT, /* 2 X X */
214 OPCODE_SIN, /* X 2 X X */
215 OPCODE_SLE, /* 2 X X */
216 OPCODE_SLT, /* X X X X X */
217 OPCODE_SNE, /* 2 X X */
218 OPCODE_SSG, /* 2 */
219 OPCODE_STR, /* 2 X */
220 OPCODE_SUB, /* X X 1.1 X X */
221 OPCODE_SWZ, /* X X */
222 OPCODE_TEX, /* X 3 X X */
223 OPCODE_TXB, /* X 3 X */
224 OPCODE_TXD, /* X X */
225 OPCODE_TXL, /* 3 2 X */
226 OPCODE_TXP, /* X X */
227 OPCODE_TXP_NV, /* 3 X */
Brian Paul035c0cf2008-11-06 17:14:33 -0700228 OPCODE_TRUNC, /* X */
Brian6d4e5612007-01-23 17:39:25 -0700229 OPCODE_UP2H, /* X */
230 OPCODE_UP2US, /* X */
231 OPCODE_UP4B, /* X */
232 OPCODE_UP4UB, /* X */
233 OPCODE_X2D, /* X */
Brian Paul37eef7b2008-11-07 09:33:55 -0700234 OPCODE_XOR, /* */
Brian6d4e5612007-01-23 17:39:25 -0700235 OPCODE_XPD, /* X X X */
Brian00cdc0a2006-12-14 15:01:06 -0700236 MAX_OPCODE
237} gl_inst_opcode;
238
239
Brian Paul035c0cf2008-11-06 17:14:33 -0700240/* temporary, just in case, remove soon */
241#define OPCODE_INT OPCODE_TRUNC
242
Brian00cdc0a2006-12-14 15:01:06 -0700243/**
244 * Instruction source register.
245 */
246struct prog_src_register
247{
248 GLuint File:4; /**< One of the PROGRAM_* register file values. */
249 GLint Index:9; /**< May be negative for relative addressing. */
250 GLuint Swizzle:12;
251 GLuint RelAddr:1;
252
253 /**
254 * \name Source register "sign" control.
255 *
256 * The ARB and NV extensions allow varrying degrees of control over the
257 * sign of the source vector components. These values allow enough control
258 * for all flavors of the extensions.
259 */
260 /*@{*/
261 /**
262 * Per-component negation for the SWZ instruction. For non-SWZ
263 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
264 *
265 * \since
266 * ARB_vertex_program, ARB_fragment_program
267 */
268 GLuint NegateBase:4;
269
270 /**
271 * Take the component-wise absolute value.
272 *
273 * \since
274 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
275 * NV_vertex_program2_option.
276 */
277 GLuint Abs:1;
278
279 /**
280 * Post-absolute value negation (all components).
281 */
282 GLuint NegateAbs:1;
283 /*@}*/
284};
285
286
287/**
288 * Instruction destination register.
289 */
290struct prog_dst_register
291{
292 /**
293 * One of the PROGRAM_* register file values.
294 */
295 GLuint File:4;
296
297 GLuint Index:8;
298 GLuint WriteMask:4;
299
300 /**
301 * \name Conditional destination update control.
302 *
303 * \since
304 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
305 * NV_vertex_program2_option.
306 */
307 /*@{*/
308 /**
309 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
Brianfe20a612007-03-22 16:07:43 -0600310 * NE, TR, or UN). Dest reg is only written to if the matching
Brian00cdc0a2006-12-14 15:01:06 -0700311 * (swizzled) condition code value passes. When a conditional update mask
312 * is not specified, this will be \c COND_TR.
313 */
314 GLuint CondMask:4;
315
316 /**
317 * Condition code swizzle value.
318 */
319 GLuint CondSwizzle:12;
320
321 /**
322 * Selects the condition code register to use for conditional destination
323 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
324 * condition code register 0 is available. In NV_vertex_program3 mode,
325 * condition code registers 0 and 1 are available.
326 */
327 GLuint CondSrc:1;
328 /*@}*/
329
330 GLuint pad:31;
331};
332
333
334/**
335 * Vertex/fragment program instruction.
336 */
337struct prog_instruction
338{
339 gl_inst_opcode Opcode;
340#if FEATURE_MESA_program_debug
341 GLshort StringPos;
342#endif
343 /**
344 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
345 */
346 void *Data;
347
348 struct prog_src_register SrcReg[3];
349 struct prog_dst_register DstReg;
350
351 /**
352 * Indicates that the instruction should update the condition code
353 * register.
354 *
355 * \since
356 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
357 * NV_vertex_program2_option.
358 */
359 GLuint CondUpdate:1;
360
361 /**
362 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
363 * condition code register that is to be updated.
364 *
365 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
366 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
367 * code registers 0 and 1 are available.
368 *
369 * \since
370 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
371 * NV_vertex_program2_option.
372 */
373 GLuint CondDst:1;
374
375 /**
376 * Saturate each value of the vectored result to the range [0,1] or the
377 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
378 * only available in NV_fragment_program2 mode.
379 * Value is one of the SATURATE_* tokens.
380 *
381 * \since
382 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
383 */
384 GLuint SaturateMode:2;
385
386 /**
387 * Per-instruction selectable precision.
388 *
389 * \since
390 * NV_fragment_program, NV_fragment_program_option.
391 */
392 GLuint Precision:3;
393
394 /**
395 * \name Texture source controls.
396 *
397 * The texture source controls are only used with the \c TEX, \c TXD,
398 * \c TXL, and \c TXP instructions.
399 *
400 * \since
401 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
402 */
403 /*@{*/
404 /**
405 * Source texture unit. OpenGL supports a maximum of 32 texture
406 * units.
407 */
408 GLuint TexSrcUnit:5;
409
410 /**
411 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
412 */
413 GLuint TexSrcTarget:3;
414 /*@}*/
415
416 /**
417 * For BRA and CAL instructions, the location to jump to.
Briand4340192007-02-05 18:04:35 -0700418 * For BGNLOOP, points to ENDLOOP (and vice-versa).
419 * For BRK, points to BGNLOOP (which points to ENDLOOP).
420 * For IF, points to else or endif.
421 * For ELSE, points to endif.
Brian00cdc0a2006-12-14 15:01:06 -0700422 */
Brianc81aede2007-02-08 14:09:34 -0700423 GLint BranchTarget;
Brian00cdc0a2006-12-14 15:01:06 -0700424
Brianeef70ff2007-01-05 16:01:26 -0700425 /**
426 * For TEX instructions in shaders, the sampler to use for the
427 * texture lookup.
428 */
429 GLint Sampler;
Brian Paul06399982008-05-16 13:15:03 -0700430
Brian00cdc0a2006-12-14 15:01:06 -0700431 const char *Comment;
432};
433
434
435extern void
436_mesa_init_instructions(struct prog_instruction *inst, GLuint count);
437
438extern struct prog_instruction *
439_mesa_alloc_instructions(GLuint numInst);
440
441extern struct prog_instruction *
442_mesa_realloc_instructions(struct prog_instruction *oldInst,
443 GLuint numOldInst, GLuint numNewInst);
444
Brian23d31ef2007-03-21 11:57:30 -0600445extern struct prog_instruction *
446_mesa_copy_instructions(struct prog_instruction *dest,
447 const struct prog_instruction *src, GLuint n);
448
Brian Paul450136d2008-05-14 12:37:07 -0600449extern void
450_mesa_free_instructions(struct prog_instruction *inst, GLuint count);
451
Brian00cdc0a2006-12-14 15:01:06 -0700452extern GLuint
453_mesa_num_inst_src_regs(gl_inst_opcode opcode);
454
Brian Paulbff695b2008-05-14 13:00:27 -0600455extern GLuint
456_mesa_num_inst_dst_regs(gl_inst_opcode opcode);
457
458extern GLboolean
459_mesa_is_tex_instruction(gl_inst_opcode opcode);
460
Brian00cdc0a2006-12-14 15:01:06 -0700461extern const char *
462_mesa_opcode_string(gl_inst_opcode opcode);
463
464
465#endif /* PROG_INSTRUCTION_H */