7bbfc69d2932f6a25373a8f21ba7d8a9eb0ba432
[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
42
43 /**
44 * Program translation state
45 */
46 struct i915_fp_compile {
47 struct pipe_shader_state *shader;
48
49 struct vertex_info *vertex_info;
50
51 uint declarations[I915_PROGRAM_SIZE];
52 uint program[I915_PROGRAM_SIZE];
53
54 /** points into the i915->current.constants array: */
55 float (*constants)[4];
56 uint num_constants;
57 uint constant_flags[I915_MAX_CONSTANT]; /**< status of each constant */
58
59 uint *csr; /* Cursor, points into program.
60 */
61
62 uint *decl; /* Cursor, points into declarations.
63 */
64
65 uint decl_s; /* flags for which s regs need to be decl'd */
66 uint decl_t; /* flags for which t regs need to be decl'd */
67
68 uint temp_flag; /* Tracks temporary regs which are in
69 * use.
70 */
71
72 uint utemp_flag; /* Tracks TYPE_U temporary regs which are in
73 * use.
74 */
75
76 uint nr_tex_indirect;
77 uint nr_tex_insn;
78 uint nr_alu_insn;
79 uint nr_decl_insn;
80
81 boolean error; /**< Set if i915_program_error() is called */
82 uint wpos_tex;
83 uint NumNativeInstructions;
84 uint NumNativeAluInstructions;
85 uint NumNativeTexInstructions;
86 uint NumNativeTexIndirections;
87 };
88
89
90 /* Having zero and one in here makes the definition of swizzle a lot
91 * easier.
92 */
93 #define UREG_TYPE_SHIFT 29
94 #define UREG_NR_SHIFT 24
95 #define UREG_CHANNEL_X_NEGATE_SHIFT 23
96 #define UREG_CHANNEL_X_SHIFT 20
97 #define UREG_CHANNEL_Y_NEGATE_SHIFT 19
98 #define UREG_CHANNEL_Y_SHIFT 16
99 #define UREG_CHANNEL_Z_NEGATE_SHIFT 15
100 #define UREG_CHANNEL_Z_SHIFT 12
101 #define UREG_CHANNEL_W_NEGATE_SHIFT 11
102 #define UREG_CHANNEL_W_SHIFT 8
103 #define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
104 #define UREG_CHANNEL_ZERO_SHIFT 4
105 #define UREG_CHANNEL_ONE_NEGATE_MBZ 1
106 #define UREG_CHANNEL_ONE_SHIFT 0
107
108 #define UREG_BAD 0xffffffff /* not a valid ureg */
109
110 #define X SRC_X
111 #define Y SRC_Y
112 #define Z SRC_Z
113 #define W SRC_W
114 #define ZERO SRC_ZERO
115 #define ONE SRC_ONE
116
117 /* Construct a ureg:
118 */
119 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \
120 ((nr) << UREG_NR_SHIFT) | \
121 (X << UREG_CHANNEL_X_SHIFT) | \
122 (Y << UREG_CHANNEL_Y_SHIFT) | \
123 (Z << UREG_CHANNEL_Z_SHIFT) | \
124 (W << UREG_CHANNEL_W_SHIFT) | \
125 (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \
126 (ONE << UREG_CHANNEL_ONE_SHIFT))
127
128 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
129 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
130
131 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
132 #define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
133
134
135
136 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
137
138 /* One neat thing about the UREG representation:
139 */
140 static INLINE int
141 swizzle(int reg, uint x, uint y, uint z, uint w)
142 {
143 assert(x <= SRC_ONE);
144 assert(y <= SRC_ONE);
145 assert(z <= SRC_ONE);
146 assert(w <= SRC_ONE);
147 return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
148 CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
149 CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
150 CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
151 CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
152 }
153
154
155
156 /***********************************************************************
157 * Public interface for the compiler
158 */
159 extern void i915_translate_fragment_program( struct i915_context *i915 );
160
161
162
163 extern uint i915_get_temp(struct i915_fp_compile *p);
164 extern uint i915_get_utemp(struct i915_fp_compile *p);
165 extern void i915_release_utemps(struct i915_fp_compile *p);
166
167
168 extern uint i915_emit_texld(struct i915_fp_compile *p,
169 uint dest,
170 uint destmask,
171 uint sampler, uint coord, uint op);
172
173 extern uint i915_emit_arith(struct i915_fp_compile *p,
174 uint op,
175 uint dest,
176 uint mask,
177 uint saturate,
178 uint src0, uint src1, uint src2);
179
180 extern uint i915_emit_decl(struct i915_fp_compile *p,
181 uint type, uint nr, uint d0_flags);
182
183
184 extern uint i915_emit_const1f(struct i915_fp_compile *p, float c0);
185
186 extern uint i915_emit_const2f(struct i915_fp_compile *p,
187 float c0, float c1);
188
189 extern uint i915_emit_const4fv(struct i915_fp_compile *p,
190 const float * c);
191
192 extern uint i915_emit_const4f(struct i915_fp_compile *p,
193 float c0, float c1,
194 float c2, float c3);
195
196
197 /*======================================================================
198 * i915_fpc_debug.c
199 */
200 extern void i915_disassemble_program(const uint * program, uint sz);
201
202
203 /*======================================================================
204 * i915_fpc_translate.c
205 */
206
207 extern void
208 i915_program_error(struct i915_fp_compile *p, const char *msg);
209
210 extern void
211 i915_translate_fragment_program(struct i915_context *i915);
212
213
214 #endif