fix assertions in swizzle()
[mesa.git] / src / mesa / pipe / i915simple / i915_fpc.h
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #ifndef I915_FPC_H
30 #define I915_FPC_H
31
32 #include "pipe/p_util.h"
33
34 #include "i915_context.h"
35 #include "i915_reg.h"
36
37
38
39 #define I915_PROGRAM_SIZE 192
40
41 #define MAX_VARYING 8
42
43 enum
44 {
45 FRAG_ATTRIB_WPOS = 0,
46 FRAG_ATTRIB_COL0 = 1,
47 FRAG_ATTRIB_COL1 = 2,
48 FRAG_ATTRIB_FOGC = 3,
49 FRAG_ATTRIB_TEX0 = 4,
50 FRAG_ATTRIB_TEX1 = 5,
51 FRAG_ATTRIB_TEX2 = 6,
52 FRAG_ATTRIB_TEX3 = 7,
53 FRAG_ATTRIB_TEX4 = 8,
54 FRAG_ATTRIB_TEX5 = 9,
55 FRAG_ATTRIB_TEX6 = 10,
56 FRAG_ATTRIB_TEX7 = 11,
57 FRAG_ATTRIB_VAR0 = 12, /**< shader varying */
58 FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
59 };
60
61 /**
62 * Bitflags for fragment program input attributes.
63 */
64 /*@{*/
65 #define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS)
66 #define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
67 #define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
68 #define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
69 #define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
70 #define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
71 #define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
72 #define FRAG_BIT_TEX3 (1 << FRAG_ATTRIB_TEX3)
73 #define FRAG_BIT_TEX4 (1 << FRAG_ATTRIB_TEX4)
74 #define FRAG_BIT_TEX5 (1 << FRAG_ATTRIB_TEX5)
75 #define FRAG_BIT_TEX6 (1 << FRAG_ATTRIB_TEX6)
76 #define FRAG_BIT_TEX7 (1 << FRAG_ATTRIB_TEX7)
77 #define FRAG_BIT_VAR0 (1 << FRAG_ATTRIB_VAR0)
78
79 #define MAX_DRAW_BUFFERS 4
80
81 enum
82 {
83 FRAG_RESULT_COLR = 0,
84 FRAG_RESULT_COLH = 1,
85 FRAG_RESULT_DEPR = 2,
86 FRAG_RESULT_DATA0 = 3,
87 FRAG_RESULT_MAX = (FRAG_RESULT_DATA0 + MAX_DRAW_BUFFERS)
88 };
89
90
91
92 /**
93 * Program translation state
94 */
95 struct i915_fp_compile {
96 struct pipe_shader_state *shader;
97
98 uint declarations[I915_PROGRAM_SIZE];
99 uint program[I915_PROGRAM_SIZE];
100
101 /** points into the i915->current.constants array: */
102 float (*constants)[4];
103 uint num_constants;
104 uint constant_flags[I915_MAX_CONSTANT]; /**< status of each constant */
105
106 uint *csr; /* Cursor, points into program.
107 */
108
109 uint *decl; /* Cursor, points into declarations.
110 */
111
112 uint decl_s; /* flags for which s regs need to be decl'd */
113 uint decl_t; /* flags for which t regs need to be decl'd */
114
115 uint temp_flag; /* Tracks temporary regs which are in
116 * use.
117 */
118
119 uint utemp_flag; /* Tracks TYPE_U temporary regs which are in
120 * use.
121 */
122
123 uint nr_tex_indirect;
124 uint nr_tex_insn;
125 uint nr_alu_insn;
126 uint nr_decl_insn;
127
128 boolean error; /**< Set if i915_program_error() is called */
129 uint wpos_tex;
130 uint NumNativeInstructions;
131 uint NumNativeAluInstructions;
132 uint NumNativeTexInstructions;
133 uint NumNativeTexIndirections;
134 };
135
136
137 /* Having zero and one in here makes the definition of swizzle a lot
138 * easier.
139 */
140 #define UREG_TYPE_SHIFT 29
141 #define UREG_NR_SHIFT 24
142 #define UREG_CHANNEL_X_NEGATE_SHIFT 23
143 #define UREG_CHANNEL_X_SHIFT 20
144 #define UREG_CHANNEL_Y_NEGATE_SHIFT 19
145 #define UREG_CHANNEL_Y_SHIFT 16
146 #define UREG_CHANNEL_Z_NEGATE_SHIFT 15
147 #define UREG_CHANNEL_Z_SHIFT 12
148 #define UREG_CHANNEL_W_NEGATE_SHIFT 11
149 #define UREG_CHANNEL_W_SHIFT 8
150 #define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
151 #define UREG_CHANNEL_ZERO_SHIFT 4
152 #define UREG_CHANNEL_ONE_NEGATE_MBZ 1
153 #define UREG_CHANNEL_ONE_SHIFT 0
154
155 #define UREG_BAD 0xffffffff /* not a valid ureg */
156
157 #define X SRC_X
158 #define Y SRC_Y
159 #define Z SRC_Z
160 #define W SRC_W
161 #define ZERO SRC_ZERO
162 #define ONE SRC_ONE
163
164 /* Construct a ureg:
165 */
166 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \
167 ((nr) << UREG_NR_SHIFT) | \
168 (X << UREG_CHANNEL_X_SHIFT) | \
169 (Y << UREG_CHANNEL_Y_SHIFT) | \
170 (Z << UREG_CHANNEL_Z_SHIFT) | \
171 (W << UREG_CHANNEL_W_SHIFT) | \
172 (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \
173 (ONE << UREG_CHANNEL_ONE_SHIFT))
174
175 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
176 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
177
178 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
179 #define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
180
181
182
183 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
184
185 /* One neat thing about the UREG representation:
186 */
187 static INLINE int
188 swizzle(int reg, uint x, uint y, uint z, uint w)
189 {
190 assert(x <= SRC_ONE);
191 assert(y <= SRC_ONE);
192 assert(z <= SRC_ONE);
193 assert(w <= SRC_ONE);
194 return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
195 CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
196 CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
197 CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
198 CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
199 }
200
201
202
203 /***********************************************************************
204 * Public interface for the compiler
205 */
206 extern void i915_translate_fragment_program( struct i915_context *i915 );
207
208
209
210 extern uint i915_get_temp(struct i915_fp_compile *p);
211 extern uint i915_get_utemp(struct i915_fp_compile *p);
212 extern void i915_release_utemps(struct i915_fp_compile *p);
213
214
215 extern uint i915_emit_texld(struct i915_fp_compile *p,
216 uint dest,
217 uint destmask,
218 uint sampler, uint coord, uint op);
219
220 extern uint i915_emit_arith(struct i915_fp_compile *p,
221 uint op,
222 uint dest,
223 uint mask,
224 uint saturate,
225 uint src0, uint src1, uint src2);
226
227 extern uint i915_emit_decl(struct i915_fp_compile *p,
228 uint type, uint nr, uint d0_flags);
229
230
231 extern uint i915_emit_const1f(struct i915_fp_compile *p, float c0);
232
233 extern uint i915_emit_const2f(struct i915_fp_compile *p,
234 float c0, float c1);
235
236 extern uint i915_emit_const4fv(struct i915_fp_compile *p,
237 const float * c);
238
239 extern uint i915_emit_const4f(struct i915_fp_compile *p,
240 float c0, float c1,
241 float c2, float c3);
242
243
244 /*======================================================================
245 * i915_fpc_debug.c
246 */
247 extern void i915_disassemble_program(const uint * program, uint sz);
248
249
250 /*======================================================================
251 * i915_fpc_translate.c
252 */
253
254 extern void
255 i915_program_error(struct i915_fp_compile *p, const char *msg);
256
257 extern void
258 i915_translate_fragment_program(struct i915_context *i915);
259
260
261 #endif