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