New asm instruction and IR_CLAMP node type to allow clamping to [0,1] with instructio...
[mesa.git] / src / mesa / shader / slang / slang_ir.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 2005-2007 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 * \file slang_ir.h
27 * Mesa GLSL Intermediate Representation tree types and constants.
28 * \author Brian Paul
29 */
30
31
32 #ifndef SLANG_IR_H
33 #define SLANG_IR_H
34
35
36 #include "imports.h"
37 #include "slang_compile.h"
38 #include "mtypes.h"
39
40
41 /**
42 * Intermediate Representation opcode
43 */
44 typedef enum
45 {
46 IR_NOP = 0,
47 IR_SEQ, /* sequence (eval left, then right) */
48 IR_SCOPE, /* new variable scope (one child) */
49 IR_LABEL, /* target of a jump or cjump */
50 IR_JUMP, /* unconditional jump */
51 IR_CJUMP0, /* conditional jump if zero */
52 IR_CJUMP1, /* conditional jump if one (or non-zero) */
53 IR_COND, /* conditional expression */
54 IR_IF, /* high-level IF */
55 IR_ELSE, /* high-level ELSE */
56 IR_ENDIF, /* high-level ENDIF */
57 IR_CALL, /* call subroutine */
58 IR_MOVE,
59 IR_ADD,
60 IR_SUB,
61 IR_MUL,
62 IR_DIV,
63 IR_DOT4,
64 IR_DOT3,
65 IR_CROSS, /* vec3 cross product */
66 IR_LRP,
67 IR_CLAMP,
68 IR_MIN,
69 IR_MAX,
70 IR_SEQUAL, /* Set if args are equal */
71 IR_SNEQUAL, /* Set if args are not equal */
72 IR_SGE, /* Set if greater or equal */
73 IR_SGT, /* Set if greater than */
74 IR_POW, /* x^y */
75 IR_EXP, /* e^x */
76 IR_EXP2, /* 2^x */
77 IR_LOG2, /* log base 2 */
78 IR_RSQ, /* 1/sqrt() */
79 IR_RCP, /* reciprocol */
80 IR_FLOOR,
81 IR_FRAC,
82 IR_ABS, /* absolute value */
83 IR_NEG, /* negate */
84 IR_DDX, /* derivative w.r.t. X */
85 IR_DDY, /* derivative w.r.t. Y */
86 IR_SIN, /* sine */
87 IR_COS, /* cosine */
88 IR_NOISE1, /* noise(x) */
89 IR_NOISE2, /* noise(x, y) */
90 IR_NOISE3, /* noise(x, y, z) */
91 IR_NOISE4, /* noise(x, y, z, w) */
92 IR_NOT, /* logical not */
93 IR_VAR, /* variable reference */
94 IR_VAR_DECL,/* var declaration */
95 IR_ELEMENT, /* array element */
96 IR_SWIZZLE, /* swizzled storage access */
97 IR_TEX, /* texture lookup */
98 IR_TEXB, /* texture lookup with LOD bias */
99 IR_TEXP, /* texture lookup with projection */
100 IR_FLOAT,
101 IR_FIELD,
102 IR_I_TO_F, /* int[4] to float[4] conversion */
103 IR_F_TO_I, /* float[4] to int[4] conversion */
104 IR_KILL /* fragment kill/discard */
105 } slang_ir_opcode;
106
107
108 /**
109 * Describes where data storage is allocated.
110 */
111 struct _slang_ir_storage
112 {
113 enum register_file File; /**< PROGRAM_TEMPORARY, PROGRAM_INPUT, etc */
114 GLint Index; /**< -1 means unallocated */
115 GLint Size; /**< number of floats */
116 GLuint Swizzle;
117 };
118
119 typedef struct _slang_ir_storage slang_ir_storage;
120
121
122 /**
123 * Intermediate Representation (IR) tree node
124 * Basically a binary tree, but IR_LRP has three children.
125 */
126 typedef struct slang_ir_node_
127 {
128 slang_ir_opcode Opcode;
129 struct slang_ir_node_ *Children[3];
130 const char *Comment;
131 const char *Target;
132 GLuint Writemask; /**< If Opcode == IR_MOVE */
133 GLfloat Value[4]; /**< If Opcode == IR_FLOAT */
134 slang_variable *Var;
135 slang_ir_storage *Store; /**< location of result of this operation */
136 } slang_ir_node;
137
138
139 #endif /* SLANG_IR_H */