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