OSDN Git Service

bfd658f81636ee05953329bdd13768cf2b23cae0
[android-x86/external-mesa.git] / src / gallium / drivers / i915 / 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
33 #include "i915_context.h"
34 #include "i915_reg.h"
35
36 #include "pipe/p_shader_tokens.h"
37
38 #include "tgsi/tgsi_parse.h"
39
40 #define I915_PROGRAM_SIZE (3 * I915_MAX_INSN)
41
42 /* Use those indices for pos/face routing, must be >= num of inputs */
43 #define I915_SEMANTIC_POS  100
44 #define I915_SEMANTIC_FACE 101
45
46
47 /**
48  * Program translation state
49  */
50 struct i915_fp_compile {
51    struct i915_fragment_shader *shader;  /* the shader we're compiling */
52
53    boolean used_constants[I915_MAX_CONSTANT];
54
55    /** maps TGSI immediate index to constant slot */
56    uint num_immediates;
57    uint immediates_map[I915_MAX_CONSTANT];
58    float immediates[I915_MAX_CONSTANT][4];
59
60    boolean first_instruction;
61
62    uint declarations[I915_PROGRAM_SIZE];
63    uint program[I915_PROGRAM_SIZE];
64
65    uint *csr;            /**< Cursor, points into program. */
66
67    uint *decl;           /**< Cursor, points into declarations. */
68
69    uint decl_s;          /**< flags for which s regs need to be decl'd */
70    uint decl_t;          /**< flags for which t regs need to be decl'd */
71
72    uint temp_flag;       /**< Tracks temporary regs which are in use */
73    uint utemp_flag;      /**< Tracks TYPE_U temporary regs which are in use */
74
75    uint register_phases[16];
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 NumNativeInstructions;
83    uint NumNativeAluInstructions;
84    uint NumNativeTexInstructions;
85    uint NumNativeTexIndirections;
86 };
87
88
89 /* Having zero and one in here makes the definition of swizzle a lot
90  * easier.
91  */
92 #define UREG_TYPE_SHIFT               29
93 #define UREG_NR_SHIFT                 24
94 #define UREG_CHANNEL_X_NEGATE_SHIFT   23
95 #define UREG_CHANNEL_X_SHIFT          20
96 #define UREG_CHANNEL_Y_NEGATE_SHIFT   19
97 #define UREG_CHANNEL_Y_SHIFT          16
98 #define UREG_CHANNEL_Z_NEGATE_SHIFT   15
99 #define UREG_CHANNEL_Z_SHIFT          12
100 #define UREG_CHANNEL_W_NEGATE_SHIFT   11
101 #define UREG_CHANNEL_W_SHIFT          8
102 #define UREG_CHANNEL_ZERO_NEGATE_MBZ  5
103 #define UREG_CHANNEL_ZERO_SHIFT       4
104 #define UREG_CHANNEL_ONE_NEGATE_MBZ   1
105 #define UREG_CHANNEL_ONE_SHIFT        0
106
107 #define UREG_BAD          0xffffffff    /* not a valid ureg */
108
109 #define X    SRC_X
110 #define Y    SRC_Y
111 #define Z    SRC_Z
112 #define W    SRC_W
113 #define ZERO SRC_ZERO
114 #define ONE  SRC_ONE
115
116 /* Construct a ureg:
117  */
118 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) |          \
119                           ((nr)  << UREG_NR_SHIFT) |            \
120                           (X     << UREG_CHANNEL_X_SHIFT) |     \
121                           (Y     << UREG_CHANNEL_Y_SHIFT) |     \
122                           (Z     << UREG_CHANNEL_Z_SHIFT) |     \
123                           (W     << UREG_CHANNEL_W_SHIFT) |     \
124                           (ZERO  << UREG_CHANNEL_ZERO_SHIFT) |  \
125                           (ONE   << UREG_CHANNEL_ONE_SHIFT))
126
127 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
128 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
129
130 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
131 #define GET_UREG_NR(reg)   (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
132
133
134
135 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
136
137 /* One neat thing about the UREG representation:  
138  */
139 static INLINE int
140 swizzle(int reg, uint x, uint y, uint z, uint w)
141 {
142    assert(x <= SRC_ONE);
143    assert(y <= SRC_ONE);
144    assert(z <= SRC_ONE);
145    assert(w <= SRC_ONE);
146    return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
147            CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
148            CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
149            CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
150            CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
151 }
152
153
154
155 /***********************************************************************
156  * Public interface for the compiler
157  */
158 extern void
159 i915_translate_fragment_program( struct i915_context *i915,
160                                  struct i915_fragment_shader *fs);
161
162
163
164 extern uint i915_get_temp(struct i915_fp_compile *p);
165 extern uint i915_get_utemp(struct i915_fp_compile *p);
166 extern void i915_release_utemps(struct i915_fp_compile *p);
167
168
169 extern uint i915_emit_texld(struct i915_fp_compile *p,
170                               uint dest,
171                               uint destmask,
172                               uint sampler,
173                               uint coord,
174                               uint op,
175                               uint num_coord);
176
177 extern uint i915_emit_arith(struct i915_fp_compile *p,
178                               uint op,
179                               uint dest,
180                               uint mask,
181                               uint saturate,
182                               uint src0, uint src1, uint src2);
183
184 extern uint i915_emit_decl(struct i915_fp_compile *p,
185                              uint type, uint nr, uint d0_flags);
186
187
188 extern uint i915_emit_const1f(struct i915_fp_compile *p, float c0);
189
190 extern uint i915_emit_const2f(struct i915_fp_compile *p,
191                                 float c0, float c1);
192
193 extern uint i915_emit_const4fv(struct i915_fp_compile *p,
194                                  const float * c);
195
196 extern uint i915_emit_const4f(struct i915_fp_compile *p,
197                                 float c0, float c1,
198                                 float c2, float c3);
199
200
201 /*======================================================================
202  * i915_fpc_translate.c
203  */
204
205 extern void
206 i915_program_error(struct i915_fp_compile *p, const char *msg, ...);
207
208
209 /*======================================================================
210  * i915_fpc_optimize.c
211  */
212
213
214 struct i915_src_register
215 {
216    unsigned File        : 4;  /* TGSI_FILE_ */
217    unsigned Indirect    : 1;  /* BOOL */
218    unsigned Dimension   : 1;  /* BOOL */
219    int      Index       : 16; /* SINT */
220    unsigned SwizzleX    : 3;  /* TGSI_SWIZZLE_ */
221    unsigned SwizzleY    : 3;  /* TGSI_SWIZZLE_ */
222    unsigned SwizzleZ    : 3;  /* TGSI_SWIZZLE_ */
223    unsigned SwizzleW    : 3;  /* TGSI_SWIZZLE_ */
224    unsigned Absolute    : 1;    /* BOOL */
225    unsigned Negate      : 1;    /* BOOL */
226 };
227
228 /* Additional swizzle supported in i915 */
229 #define TGSI_SWIZZLE_ZERO 4
230 #define TGSI_SWIZZLE_ONE 5
231
232 struct i915_dst_register
233 {
234    unsigned File        : 4;  /* TGSI_FILE_ */
235    unsigned WriteMask   : 4;  /* TGSI_WRITEMASK_ */
236    unsigned Indirect    : 1;  /* BOOL */
237    unsigned Dimension   : 1;  /* BOOL */
238    int      Index       : 16; /* SINT */
239    unsigned Padding     : 6;
240 };
241
242
243 struct i915_full_dst_register
244 {
245    struct i915_dst_register               Register;
246 /*
247    struct tgsi_src_register               Indirect;
248    struct tgsi_dimension                  Dimension;
249    struct tgsi_src_register               DimIndirect;
250 */
251 };
252
253 struct i915_full_src_register
254 {
255    struct i915_src_register         Register;
256 /*
257    struct tgsi_src_register         Indirect;
258    struct tgsi_dimension            Dimension;
259    struct tgsi_src_register         DimIndirect;
260 */
261 };
262
263 struct i915_full_instruction
264 {
265    struct tgsi_instruction             Instruction;
266 /*
267    struct tgsi_instruction_predicate   Predicate;
268    struct tgsi_instruction_label       Label;
269 */
270    struct tgsi_instruction_texture     Texture;
271    struct i915_full_dst_register       Dst[1];
272    struct i915_full_src_register       Src[3];
273 };
274
275
276 union i915_full_token
277 {
278    struct tgsi_token             Token;
279    struct tgsi_full_declaration  FullDeclaration;
280    struct tgsi_full_immediate    FullImmediate;
281    struct i915_full_instruction  FullInstruction;
282    struct tgsi_full_property     FullProperty;
283 };
284
285 struct i915_token_list
286 {
287    union i915_full_token*     Tokens;
288    unsigned                   NumTokens;
289 };
290
291 extern struct i915_token_list* i915_optimize(const struct tgsi_token *tokens);
292
293 extern void i915_optimize_free(struct i915_token_list* tokens);
294
295 #endif