blob: 100aac4b97f6e4cb16a3fd84ce083570e97e0a6c [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
60
Brian6d4e5612007-01-23 17:39:25 -070061/**
62 * Writemask values, 1 bit per component.
63 */
64/*@{*/
Brian00cdc0a2006-12-14 15:01:06 -070065#define WRITEMASK_X 0x1
66#define WRITEMASK_Y 0x2
67#define WRITEMASK_XY 0x3
68#define WRITEMASK_Z 0x4
69#define WRITEMASK_XZ 0x5
70#define WRITEMASK_YZ 0x6
71#define WRITEMASK_XYZ 0x7
72#define WRITEMASK_W 0x8
73#define WRITEMASK_XW 0x9
74#define WRITEMASK_YW 0xa
75#define WRITEMASK_XYW 0xb
76#define WRITEMASK_ZW 0xc
77#define WRITEMASK_XZW 0xd
78#define WRITEMASK_YZW 0xe
79#define WRITEMASK_XYZW 0xf
Brian6d4e5612007-01-23 17:39:25 -070080/*@}*/
Brian00cdc0a2006-12-14 15:01:06 -070081
82
83/**
Brian6d4e5612007-01-23 17:39:25 -070084 * Condition codes
Brian00cdc0a2006-12-14 15:01:06 -070085 */
86/*@{*/
Brian6d4e5612007-01-23 17:39:25 -070087#define COND_GT 1 /**< greater than zero */
88#define COND_EQ 2 /**< equal to zero */
89#define COND_LT 3 /**< less than zero */
90#define COND_UN 4 /**< unordered (NaN) */
91#define COND_GE 5 /**< greater then or equal to zero */
92#define COND_LE 6 /**< less then or equal to zero */
93#define COND_NE 7 /**< not equal to zero */
94#define COND_TR 8 /**< always true */
95#define COND_FL 9 /**< always false */
Brian00cdc0a2006-12-14 15:01:06 -070096/*@}*/
97
98
99/**
100 * Instruction precision for GL_NV_fragment_program
101 */
102/*@{*/
103#define FLOAT32 0x1
104#define FLOAT16 0x2
105#define FIXED12 0x4
106/*@}*/
107
108
109/**
110 * Saturation modes when storing values.
111 */
112/*@{*/
113#define SATURATE_OFF 0
114#define SATURATE_ZERO_ONE 1
115#define SATURATE_PLUS_MINUS_ONE 2
116/*@}*/
117
118
119/**
120 * Per-component negation masks
121 */
122/*@{*/
123#define NEGATE_X 0x1
124#define NEGATE_Y 0x2
125#define NEGATE_Z 0x4
126#define NEGATE_W 0x8
127#define NEGATE_XYZW 0xf
128#define NEGATE_NONE 0x0
129/*@}*/
130
131
132/**
133 * Program instruction opcodes, for both vertex and fragment programs.
134 * \note changes to this opcode list must be reflected in t_vb_arbprogram.c
135 */
136typedef enum prog_opcode {
Brian6d4e5612007-01-23 17:39:25 -0700137 /* ARB_vp ARB_fp NV_vp NV_fp GLSL */
138 /*------------------------------------------*/
139 OPCODE_NOP = 0, /* X */
140 OPCODE_ABS, /* X X 1.1 X */
141 OPCODE_ADD, /* X X X X X */
142 OPCODE_ARA, /* 2 */
143 OPCODE_ARL, /* X X */
144 OPCODE_ARL_NV, /* 2 */
145 OPCODE_ARR, /* 2 */
Brian01001d82007-02-05 11:28:15 -0700146 OPCODE_BGNLOOP, /* opt */
147 OPCODE_BGNSUB, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700148 OPCODE_BRA, /* 2 X */
Brian01001d82007-02-05 11:28:15 -0700149 OPCODE_BRK, /* 2 opt */
Brian6d4e5612007-01-23 17:39:25 -0700150 OPCODE_CAL, /* 2 2 */
151 OPCODE_CMP, /* X */
Brian01001d82007-02-05 11:28:15 -0700152 OPCODE_CONT, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700153 OPCODE_COS, /* X 2 X X */
154 OPCODE_DDX, /* X X */
155 OPCODE_DDY, /* X X */
156 OPCODE_DP3, /* X X X X X */
157 OPCODE_DP4, /* X X X X X */
158 OPCODE_DPH, /* X X 1.1 */
159 OPCODE_DST, /* X X X X */
160 OPCODE_ELSE, /* X */
Brian01001d82007-02-05 11:28:15 -0700161 OPCODE_END, /* X X X X opt */
162 OPCODE_ENDIF, /* opt */
163 OPCODE_ENDLOOP, /* opt */
164 OPCODE_ENDSUB, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700165 OPCODE_EX2, /* X X 2 X X */
166 OPCODE_EXP, /* X X X */
167 OPCODE_FLR, /* X X 2 X X */
168 OPCODE_FRC, /* X X 2 X X */
Brian01001d82007-02-05 11:28:15 -0700169 OPCODE_IF, /* opt */
Brian6d4e5612007-01-23 17:39:25 -0700170 OPCODE_INT, /* X */
171 OPCODE_KIL, /* X */
172 OPCODE_KIL_NV, /* X X */
173 OPCODE_LG2, /* X X 2 X X */
174 OPCODE_LIT, /* X X X X */
175 OPCODE_LOG, /* X X X */
176 OPCODE_LRP, /* X X */
177 OPCODE_MAD, /* X X X X X */
178 OPCODE_MAX, /* X X X X X */
179 OPCODE_MIN, /* X X X X X */
180 OPCODE_MOV, /* X X X X X */
181 OPCODE_MUL, /* X X X X X */
Brian7aece102007-01-28 19:01:35 -0700182 OPCODE_NOISE1, /* X */
183 OPCODE_NOISE2, /* X */
184 OPCODE_NOISE3, /* X */
185 OPCODE_NOISE4, /* X */
Brian6d4e5612007-01-23 17:39:25 -0700186 OPCODE_PK2H, /* X */
187 OPCODE_PK2US, /* X */
188 OPCODE_PK4B, /* X */
189 OPCODE_PK4UB, /* X */
190 OPCODE_POW, /* X X X X */
191 OPCODE_POPA, /* 3 */
192 OPCODE_PRINT, /* X X */
193 OPCODE_PUSHA, /* 3 */
194 OPCODE_RCC, /* 1.1 */
195 OPCODE_RCP, /* X X X X X */
196 OPCODE_RET, /* 2 2 */
197 OPCODE_RFL, /* X X */
198 OPCODE_RSQ, /* X X X X X */
199 OPCODE_SCS, /* X */
200 OPCODE_SEQ, /* 2 X X */
201 OPCODE_SFL, /* 2 X */
202 OPCODE_SGE, /* X X X X X */
203 OPCODE_SGT, /* 2 X X */
204 OPCODE_SIN, /* X 2 X X */
205 OPCODE_SLE, /* 2 X X */
206 OPCODE_SLT, /* X X X X X */
207 OPCODE_SNE, /* 2 X X */
208 OPCODE_SSG, /* 2 */
209 OPCODE_STR, /* 2 X */
210 OPCODE_SUB, /* X X 1.1 X X */
211 OPCODE_SWZ, /* X X */
212 OPCODE_TEX, /* X 3 X X */
213 OPCODE_TXB, /* X 3 X */
214 OPCODE_TXD, /* X X */
215 OPCODE_TXL, /* 3 2 X */
216 OPCODE_TXP, /* X X */
217 OPCODE_TXP_NV, /* 3 X */
218 OPCODE_UP2H, /* X */
219 OPCODE_UP2US, /* X */
220 OPCODE_UP4B, /* X */
221 OPCODE_UP4UB, /* X */
222 OPCODE_X2D, /* X */
223 OPCODE_XPD, /* X X X */
Brian00cdc0a2006-12-14 15:01:06 -0700224 MAX_OPCODE
225} gl_inst_opcode;
226
227
228/**
229 * Instruction source register.
230 */
231struct prog_src_register
232{
233 GLuint File:4; /**< One of the PROGRAM_* register file values. */
234 GLint Index:9; /**< May be negative for relative addressing. */
235 GLuint Swizzle:12;
236 GLuint RelAddr:1;
237
238 /**
239 * \name Source register "sign" control.
240 *
241 * The ARB and NV extensions allow varrying degrees of control over the
242 * sign of the source vector components. These values allow enough control
243 * for all flavors of the extensions.
244 */
245 /*@{*/
246 /**
247 * Per-component negation for the SWZ instruction. For non-SWZ
248 * instructions the only possible values are NEGATE_XYZW and NEGATE_NONE.
249 *
250 * \since
251 * ARB_vertex_program, ARB_fragment_program
252 */
253 GLuint NegateBase:4;
254
255 /**
256 * Take the component-wise absolute value.
257 *
258 * \since
259 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
260 * NV_vertex_program2_option.
261 */
262 GLuint Abs:1;
263
264 /**
265 * Post-absolute value negation (all components).
266 */
267 GLuint NegateAbs:1;
268 /*@}*/
269};
270
271
272/**
273 * Instruction destination register.
274 */
275struct prog_dst_register
276{
277 /**
278 * One of the PROGRAM_* register file values.
279 */
280 GLuint File:4;
281
282 GLuint Index:8;
283 GLuint WriteMask:4;
284
285 /**
286 * \name Conditional destination update control.
287 *
288 * \since
289 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
290 * NV_vertex_program2_option.
291 */
292 /*@{*/
293 /**
294 * Takes one of the 9 possible condition values (EQ, FL, GT, GE, LE, LT,
295 * NE, TR, or UN). Destination update is enabled if the matching
296 * (swizzled) condition code value passes. When a conditional update mask
297 * is not specified, this will be \c COND_TR.
298 */
299 GLuint CondMask:4;
300
301 /**
302 * Condition code swizzle value.
303 */
304 GLuint CondSwizzle:12;
305
306 /**
307 * Selects the condition code register to use for conditional destination
308 * update masking. In NV_fragmnet_program or NV_vertex_program2 mode, only
309 * condition code register 0 is available. In NV_vertex_program3 mode,
310 * condition code registers 0 and 1 are available.
311 */
312 GLuint CondSrc:1;
313 /*@}*/
314
315 GLuint pad:31;
316};
317
318
319/**
320 * Vertex/fragment program instruction.
321 */
322struct prog_instruction
323{
324 gl_inst_opcode Opcode;
325#if FEATURE_MESA_program_debug
326 GLshort StringPos;
327#endif
328 /**
329 * Arbitrary data. Used for the PRINT, CAL, and BRA instructions.
330 */
331 void *Data;
332
333 struct prog_src_register SrcReg[3];
334 struct prog_dst_register DstReg;
335
336 /**
337 * Indicates that the instruction should update the condition code
338 * register.
339 *
340 * \since
341 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
342 * NV_vertex_program2_option.
343 */
344 GLuint CondUpdate:1;
345
346 /**
347 * If prog_instruction::CondUpdate is \c GL_TRUE, this value selects the
348 * condition code register that is to be updated.
349 *
350 * In GL_NV_fragment_program or GL_NV_vertex_program2 mode, only condition
351 * code register 0 is available. In GL_NV_vertex_program3 mode, condition
352 * code registers 0 and 1 are available.
353 *
354 * \since
355 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program2,
356 * NV_vertex_program2_option.
357 */
358 GLuint CondDst:1;
359
360 /**
361 * Saturate each value of the vectored result to the range [0,1] or the
362 * range [-1,1]. \c SSAT mode (i.e., saturation to the range [-1,1]) is
363 * only available in NV_fragment_program2 mode.
364 * Value is one of the SATURATE_* tokens.
365 *
366 * \since
367 * NV_fragment_program, NV_fragment_program_option, NV_vertex_program3.
368 */
369 GLuint SaturateMode:2;
370
371 /**
372 * Per-instruction selectable precision.
373 *
374 * \since
375 * NV_fragment_program, NV_fragment_program_option.
376 */
377 GLuint Precision:3;
378
379 /**
380 * \name Texture source controls.
381 *
382 * The texture source controls are only used with the \c TEX, \c TXD,
383 * \c TXL, and \c TXP instructions.
384 *
385 * \since
386 * ARB_fragment_program, NV_fragment_program, NV_vertex_program3.
387 */
388 /*@{*/
389 /**
390 * Source texture unit. OpenGL supports a maximum of 32 texture
391 * units.
392 */
393 GLuint TexSrcUnit:5;
394
395 /**
396 * Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX.
397 */
398 GLuint TexSrcTarget:3;
399 /*@}*/
400
401 /**
402 * For BRA and CAL instructions, the location to jump to.
403 */
404 GLuint BranchTarget;
405
Brianeef70ff2007-01-05 16:01:26 -0700406 /**
407 * For TEX instructions in shaders, the sampler to use for the
408 * texture lookup.
409 */
410 GLint Sampler;
411
Brian00cdc0a2006-12-14 15:01:06 -0700412 const char *Comment;
413};
414
415
416extern void
417_mesa_init_instructions(struct prog_instruction *inst, GLuint count);
418
419extern struct prog_instruction *
420_mesa_alloc_instructions(GLuint numInst);
421
422extern struct prog_instruction *
423_mesa_realloc_instructions(struct prog_instruction *oldInst,
424 GLuint numOldInst, GLuint numNewInst);
425
426extern GLuint
427_mesa_num_inst_src_regs(gl_inst_opcode opcode);
428
429extern const char *
430_mesa_opcode_string(gl_inst_opcode opcode);
431
432
433#endif /* PROG_INSTRUCTION_H */