1fa225cbcSrjs#ifndef _I915_PROGRAM_H
2fa225cbcSrjs#define _I915_PROGRAM_H
3fa225cbcSrjs
4fa225cbcSrjs#define REG_TYPE_R                 0    /* temporary regs, no need to
5fa225cbcSrjs                                         * dcl, must be written before
6fa225cbcSrjs                                         * read -- Preserved between
7fa225cbcSrjs                                         * phases.
8fa225cbcSrjs                                         */
9fa225cbcSrjs#define REG_TYPE_T                 1    /* Interpolated values, must be
10fa225cbcSrjs                                         * dcl'ed before use.
11fa225cbcSrjs                                         *
12fa225cbcSrjs                                         * 0..7: texture coord,
13fa225cbcSrjs                                         * 8: diffuse spec,
14fa225cbcSrjs                                         * 9: specular color,
15fa225cbcSrjs                                         * 10: fog parameter in w.
16fa225cbcSrjs                                         */
17fa225cbcSrjs#define REG_TYPE_CONST             2    /* Restriction: only one const
18fa225cbcSrjs                                         * can be referenced per
19fa225cbcSrjs                                         * instruction, though it may be
20fa225cbcSrjs                                         * selected for multiple inputs.
21fa225cbcSrjs                                         * Constants not initialized
22fa225cbcSrjs                                         * default to zero.
23fa225cbcSrjs                                         */
24fa225cbcSrjs#define REG_TYPE_S                 3    /* sampler */
25fa225cbcSrjs#define REG_TYPE_OC                4    /* output color (rgba) */
26fa225cbcSrjs#define REG_TYPE_OD                5    /* output depth (w), xyz are
27fa225cbcSrjs                                         * temporaries.  If not written,
28fa225cbcSrjs                                         * interpolated depth is used?
29fa225cbcSrjs                                         */
30fa225cbcSrjs#define REG_TYPE_U                 6    /* unpreserved temporaries */
31fa225cbcSrjs#define REG_TYPE_MASK              0x7
32fa225cbcSrjs#define REG_NR_MASK                0xf
33fa225cbcSrjs
34fa225cbcSrjs/* REG_TYPE_T:
35fa225cbcSrjs */
36fa225cbcSrjs#define T_TEX0     0
37fa225cbcSrjs#define T_TEX1     1
38fa225cbcSrjs#define T_TEX2     2
39fa225cbcSrjs#define T_TEX3     3
40fa225cbcSrjs#define T_TEX4     4
41fa225cbcSrjs#define T_TEX5     5
42fa225cbcSrjs#define T_TEX6     6
43fa225cbcSrjs#define T_TEX7     7
44fa225cbcSrjs#define T_DIFFUSE  8
45fa225cbcSrjs#define T_SPECULAR 9
46fa225cbcSrjs#define T_FOG_W    10           /* interpolated fog is in W coord */
47fa225cbcSrjs
48fa225cbcSrjs/* Arithmetic instructions */
49fa225cbcSrjs
50fa225cbcSrjs/* .replicate_swizzle == selection and replication of a particular
51fa225cbcSrjs * scalar channel, ie., .xxxx, .yyyy, .zzzz or .wwww
52fa225cbcSrjs */
53fa225cbcSrjs#define A0_NOP    (0x0<<24)     /* no operation */
54fa225cbcSrjs#define A0_ADD    (0x1<<24)     /* dst = src0 + src1 */
55fa225cbcSrjs#define A0_MOV    (0x2<<24)     /* dst = src0 */
56fa225cbcSrjs#define A0_MUL    (0x3<<24)     /* dst = src0 * src1 */
57fa225cbcSrjs#define A0_MAD    (0x4<<24)     /* dst = src0 * src1 + src2 */
58fa225cbcSrjs#define A0_DP2ADD (0x5<<24)     /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */
59fa225cbcSrjs#define A0_DP3    (0x6<<24)     /* dst.xyzw = src0.xyz dot src1.xyz */
60fa225cbcSrjs#define A0_DP4    (0x7<<24)     /* dst.xyzw = src0.xyzw dot src1.xyzw */
61fa225cbcSrjs#define A0_FRC    (0x8<<24)     /* dst = src0 - floor(src0) */
62fa225cbcSrjs#define A0_RCP    (0x9<<24)     /* dst.xyzw = 1/(src0.replicate_swizzle) */
63fa225cbcSrjs#define A0_RSQ    (0xa<<24)     /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */
64fa225cbcSrjs#define A0_EXP    (0xb<<24)     /* dst.xyzw = exp2(src0.replicate_swizzle) */
65fa225cbcSrjs#define A0_LOG    (0xc<<24)     /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */
66fa225cbcSrjs#define A0_CMP    (0xd<<24)     /* dst = (src0 >= 0.0) ? src1 : src2 */
67fa225cbcSrjs#define A0_MIN    (0xe<<24)     /* dst = (src0 < src1) ? src0 : src1 */
68fa225cbcSrjs#define A0_MAX    (0xf<<24)     /* dst = (src0 >= src1) ? src0 : src1 */
69fa225cbcSrjs#define A0_FLR    (0x10<<24)    /* dst = floor(src0) */
70fa225cbcSrjs#define A0_MOD    (0x11<<24)    /* dst = src0 fmod 1.0 */
71fa225cbcSrjs#define A0_TRC    (0x12<<24)    /* dst = int(src0) */
72fa225cbcSrjs#define A0_SGE    (0x13<<24)    /* dst = src0 >= src1 ? 1.0 : 0.0 */
73fa225cbcSrjs#define A0_SLT    (0x14<<24)    /* dst = src0 < src1 ? 1.0 : 0.0 */
74fa225cbcSrjs#define A0_DEST_SATURATE                 (1<<22)
75fa225cbcSrjs#define A0_DEST_TYPE_SHIFT                19
76fa225cbcSrjs/* Allow: R, OC, OD, U */
77fa225cbcSrjs#define A0_DEST_NR_SHIFT                 14
78fa225cbcSrjs/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
79fa225cbcSrjs#define A0_DEST_CHANNEL_X                (1<<10)
80fa225cbcSrjs#define A0_DEST_CHANNEL_Y                (2<<10)
81fa225cbcSrjs#define A0_DEST_CHANNEL_Z                (4<<10)
82fa225cbcSrjs#define A0_DEST_CHANNEL_W                (8<<10)
83fa225cbcSrjs#define A0_DEST_CHANNEL_ALL              (0xf<<10)
84fa225cbcSrjs#define A0_DEST_CHANNEL_SHIFT            10
85fa225cbcSrjs#define A0_SRC0_TYPE_SHIFT               7
86fa225cbcSrjs#define A0_SRC0_NR_SHIFT                 2
87fa225cbcSrjs
88fa225cbcSrjs#define A0_DEST_CHANNEL_XY              (A0_DEST_CHANNEL_X|A0_DEST_CHANNEL_Y)
89fa225cbcSrjs#define A0_DEST_CHANNEL_XYZ             (A0_DEST_CHANNEL_XY|A0_DEST_CHANNEL_Z)
90fa225cbcSrjs
91fa225cbcSrjs#define SRC_X        0
92fa225cbcSrjs#define SRC_Y        1
93fa225cbcSrjs#define SRC_Z        2
94fa225cbcSrjs#define SRC_W        3
95fa225cbcSrjs#define SRC_ZERO     4
96fa225cbcSrjs#define SRC_ONE      5
97fa225cbcSrjs
98fa225cbcSrjs#define A1_SRC0_CHANNEL_X_NEGATE         (1<<31)
99fa225cbcSrjs#define A1_SRC0_CHANNEL_X_SHIFT          28
100fa225cbcSrjs#define A1_SRC0_CHANNEL_Y_NEGATE         (1<<27)
101fa225cbcSrjs#define A1_SRC0_CHANNEL_Y_SHIFT          24
102fa225cbcSrjs#define A1_SRC0_CHANNEL_Z_NEGATE         (1<<23)
103fa225cbcSrjs#define A1_SRC0_CHANNEL_Z_SHIFT          20
104fa225cbcSrjs#define A1_SRC0_CHANNEL_W_NEGATE         (1<<19)
105fa225cbcSrjs#define A1_SRC0_CHANNEL_W_SHIFT          16
106fa225cbcSrjs#define A1_SRC1_TYPE_SHIFT               13
107fa225cbcSrjs#define A1_SRC1_NR_SHIFT                 8
108fa225cbcSrjs#define A1_SRC1_CHANNEL_X_NEGATE         (1<<7)
109fa225cbcSrjs#define A1_SRC1_CHANNEL_X_SHIFT          4
110fa225cbcSrjs#define A1_SRC1_CHANNEL_Y_NEGATE         (1<<3)
111fa225cbcSrjs#define A1_SRC1_CHANNEL_Y_SHIFT          0
112fa225cbcSrjs
113fa225cbcSrjs#define A2_SRC1_CHANNEL_Z_NEGATE         (1<<31)
114fa225cbcSrjs#define A2_SRC1_CHANNEL_Z_SHIFT          28
115fa225cbcSrjs#define A2_SRC1_CHANNEL_W_NEGATE         (1<<27)
116fa225cbcSrjs#define A2_SRC1_CHANNEL_W_SHIFT          24
117fa225cbcSrjs#define A2_SRC2_TYPE_SHIFT               21
118fa225cbcSrjs#define A2_SRC2_NR_SHIFT                 16
119fa225cbcSrjs#define A2_SRC2_CHANNEL_X_NEGATE         (1<<15)
120fa225cbcSrjs#define A2_SRC2_CHANNEL_X_SHIFT          12
121fa225cbcSrjs#define A2_SRC2_CHANNEL_Y_NEGATE         (1<<11)
122fa225cbcSrjs#define A2_SRC2_CHANNEL_Y_SHIFT          8
123fa225cbcSrjs#define A2_SRC2_CHANNEL_Z_NEGATE         (1<<7)
124fa225cbcSrjs#define A2_SRC2_CHANNEL_Z_SHIFT          4
125fa225cbcSrjs#define A2_SRC2_CHANNEL_W_NEGATE         (1<<3)
126fa225cbcSrjs#define A2_SRC2_CHANNEL_W_SHIFT          0
127fa225cbcSrjs
128fa225cbcSrjs/* Declaration instructions */
129fa225cbcSrjs#define D0_DCL       (0x19<<24) /* Declare a t (interpolated attrib)
130fa225cbcSrjs                                 * register or an s (sampler)
131fa225cbcSrjs                                 * register. */
132fa225cbcSrjs#define D0_SAMPLE_TYPE_SHIFT              22
133fa225cbcSrjs#define D0_SAMPLE_TYPE_2D                 (0x0<<22)
134fa225cbcSrjs#define D0_SAMPLE_TYPE_CUBE               (0x1<<22)
135fa225cbcSrjs#define D0_SAMPLE_TYPE_VOLUME             (0x2<<22)
136fa225cbcSrjs#define D0_SAMPLE_TYPE_MASK               (0x3<<22)
137fa225cbcSrjs
138fa225cbcSrjs#define D0_TYPE_SHIFT                19
139fa225cbcSrjs/* Allow: T, S */
140fa225cbcSrjs#define D0_NR_SHIFT                  14
141fa225cbcSrjs/* Allow T: 0..10, S: 0..15 */
142fa225cbcSrjs#define D0_CHANNEL_X                (1<<10)
143fa225cbcSrjs#define D0_CHANNEL_Y                (2<<10)
144fa225cbcSrjs#define D0_CHANNEL_Z                (4<<10)
145fa225cbcSrjs#define D0_CHANNEL_W                (8<<10)
146fa225cbcSrjs#define D0_CHANNEL_ALL              (0xf<<10)
147fa225cbcSrjs#define D0_CHANNEL_NONE             (0<<10)
148fa225cbcSrjs
149fa225cbcSrjs#define D0_CHANNEL_XY               (D0_CHANNEL_X|D0_CHANNEL_Y)
150fa225cbcSrjs#define D0_CHANNEL_XYZ              (D0_CHANNEL_XY|D0_CHANNEL_Z)
151fa225cbcSrjs
152fa225cbcSrjs/* I915 Errata: Do not allow (xz), (xw), (xzw) combinations for diffuse
153fa225cbcSrjs * or specular declarations.
154fa225cbcSrjs *
155fa225cbcSrjs * For T dcls, only allow: (x), (xy), (xyz), (w), (xyzw)
156fa225cbcSrjs *
157fa225cbcSrjs * Must be zero for S (sampler) dcls
158fa225cbcSrjs */
159fa225cbcSrjs#define D1_MBZ                          0
160fa225cbcSrjs#define D2_MBZ                          0
161fa225cbcSrjs
162fa225cbcSrjs/* Texture instructions */
163fa225cbcSrjs#define T0_TEXLD     (0x15<<24) /* Sample texture using predeclared
164fa225cbcSrjs                                 * sampler and address, and output
165fa225cbcSrjs                                 * filtered texel data to destination
166fa225cbcSrjs                                 * register */
167fa225cbcSrjs#define T0_TEXLDP    (0x16<<24) /* Same as texld but performs a
168fa225cbcSrjs                                 * perspective divide of the texture
169fa225cbcSrjs                                 * coordinate .xyz values by .w before
170fa225cbcSrjs                                 * sampling. */
171fa225cbcSrjs#define T0_TEXLDB    (0x17<<24) /* Same as texld but biases the
172fa225cbcSrjs                                 * computed LOD by w.  Only S4.6 two's
173fa225cbcSrjs                                 * comp is used.  This implies that a
174fa225cbcSrjs                                 * float to fixed conversion is
175fa225cbcSrjs                                 * done. */
176fa225cbcSrjs#define T0_TEXKILL   (0x18<<24) /* Does not perform a sampling
177fa225cbcSrjs                                 * operation.  Simply kills the pixel
178fa225cbcSrjs                                 * if any channel of the address
179fa225cbcSrjs                                 * register is < 0.0. */
180fa225cbcSrjs#define T0_DEST_TYPE_SHIFT                19
181fa225cbcSrjs/* Allow: R, OC, OD, U */
182fa225cbcSrjs/* Note: U (unpreserved) regs do not retain their values between
183fa225cbcSrjs * phases (cannot be used for feedback)
184fa225cbcSrjs *
185fa225cbcSrjs * Note: oC and OD registers can only be used as the destination of a
186fa225cbcSrjs * texture instruction once per phase (this is an implementation
187fa225cbcSrjs * restriction).
188fa225cbcSrjs */
189fa225cbcSrjs#define T0_DEST_NR_SHIFT                 14
190fa225cbcSrjs/* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */
191fa225cbcSrjs#define T0_SAMPLER_NR_SHIFT              0      /* This field ignored for TEXKILL */
192fa225cbcSrjs#define T0_SAMPLER_NR_MASK               (0xf<<0)
193fa225cbcSrjs
194fa225cbcSrjs#define T1_ADDRESS_REG_TYPE_SHIFT        24     /* Reg to use as texture coord */
195fa225cbcSrjs/* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */
196fa225cbcSrjs#define T1_ADDRESS_REG_NR_SHIFT          17
197fa225cbcSrjs#define T2_MBZ                           0
198fa225cbcSrjs
199fa225cbcSrjs
200fa225cbcSrjs/* Having zero and one in here makes the definition of swizzle a lot
201fa225cbcSrjs * easier.
202fa225cbcSrjs */
203fa225cbcSrjs#define UREG_TYPE_SHIFT               29
204fa225cbcSrjs#define UREG_NR_SHIFT                 24
205fa225cbcSrjs#define UREG_CHANNEL_X_NEGATE_SHIFT   23
206fa225cbcSrjs#define UREG_CHANNEL_X_SHIFT          20
207fa225cbcSrjs#define UREG_CHANNEL_Y_NEGATE_SHIFT   19
208fa225cbcSrjs#define UREG_CHANNEL_Y_SHIFT          16
209fa225cbcSrjs#define UREG_CHANNEL_Z_NEGATE_SHIFT   15
210fa225cbcSrjs#define UREG_CHANNEL_Z_SHIFT          12
211fa225cbcSrjs#define UREG_CHANNEL_W_NEGATE_SHIFT   11
212fa225cbcSrjs#define UREG_CHANNEL_W_SHIFT          8
213fa225cbcSrjs#define UREG_CHANNEL_ZERO_NEGATE_MBZ  5
214fa225cbcSrjs#define UREG_CHANNEL_ZERO_SHIFT       4
215fa225cbcSrjs#define UREG_CHANNEL_ONE_NEGATE_MBZ   1
216fa225cbcSrjs#define UREG_CHANNEL_ONE_SHIFT        0
217fa225cbcSrjs
218fa225cbcSrjs#define UREG_BAD          0xffffffff    /* not a valid ureg */
219fa225cbcSrjs
220fa225cbcSrjs#define X    SRC_X
221fa225cbcSrjs#define Y    SRC_Y
222fa225cbcSrjs#define Z    SRC_Z
223fa225cbcSrjs#define W    SRC_W
224fa225cbcSrjs#define ZERO SRC_ZERO
225fa225cbcSrjs#define ONE  SRC_ONE
226fa225cbcSrjs
227fa225cbcSrjs/* Construct a ureg:
228fa225cbcSrjs */
229fa225cbcSrjs#define UREG(type, nr) (((type) << UREG_TYPE_SHIFT) |           \
230fa225cbcSrjs                        ((nr)  << UREG_NR_SHIFT) |              \
231fa225cbcSrjs                        (X     << UREG_CHANNEL_X_SHIFT) |       \
232fa225cbcSrjs                        (Y     << UREG_CHANNEL_Y_SHIFT) |       \
233fa225cbcSrjs                        (Z     << UREG_CHANNEL_Z_SHIFT) |       \
234fa225cbcSrjs                        (W     << UREG_CHANNEL_W_SHIFT) |       \
235fa225cbcSrjs                        (ZERO  << UREG_CHANNEL_ZERO_SHIFT) |    \
236fa225cbcSrjs                        (ONE   << UREG_CHANNEL_ONE_SHIFT))
237fa225cbcSrjs
238fa225cbcSrjs#define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
239fa225cbcSrjs#define CHANNEL_SRC( src, channel ) (src>>(channel*4))
240fa225cbcSrjs
241fa225cbcSrjs#define GET_UREG_TYPE(reg) (((reg) >> UREG_TYPE_SHIFT) & REG_TYPE_MASK)
242fa225cbcSrjs#define GET_UREG_NR(reg)   (((reg) >> UREG_NR_SHIFT) & REG_NR_MASK)
243fa225cbcSrjs
244fa225cbcSrjs#define UREG_XYZW_CHANNEL_MASK 0x00ffff00
245fa225cbcSrjs
246fa225cbcSrjs#define A0_DEST(reg) (((reg) & UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
247fa225cbcSrjs#define D0_DEST(reg) (((reg) & UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
248fa225cbcSrjs#define T0_DEST(reg) (((reg) & UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
249fa225cbcSrjs#define A0_SRC0(reg) (((reg) & UREG_MASK) >> UREG_A0_SRC0_SHIFT_LEFT)
250fa225cbcSrjs#define A1_SRC0(reg) (((reg) & UREG_MASK) << UREG_A1_SRC0_SHIFT_RIGHT)
251fa225cbcSrjs#define A1_SRC1(reg) (((reg) & UREG_MASK) >> UREG_A1_SRC1_SHIFT_LEFT)
252fa225cbcSrjs#define A2_SRC1(reg) (((reg) & UREG_MASK) << UREG_A2_SRC1_SHIFT_RIGHT)
253fa225cbcSrjs#define A2_SRC2(reg) (((reg) & UREG_MASK) >> UREG_A2_SRC2_SHIFT_LEFT)
254fa225cbcSrjs
255fa225cbcSrjs/* These are special, and don't have swizzle/negate bits.
256fa225cbcSrjs */
257fa225cbcSrjs#define T0_SAMPLER( reg )     (GET_UREG_NR(reg) << T0_SAMPLER_NR_SHIFT)
258fa225cbcSrjs#define T1_ADDRESS_REG( reg ) ((GET_UREG_NR(reg) << T1_ADDRESS_REG_NR_SHIFT) | \
259fa225cbcSrjs                               (GET_UREG_TYPE(reg) << T1_ADDRESS_REG_TYPE_SHIFT))
260fa225cbcSrjs
261fa225cbcSrjs
262fa225cbcSrjs/* Macros for translating UREG's into the various register fields used
263fa225cbcSrjs * by the I915 programmable unit.
264fa225cbcSrjs */
265fa225cbcSrjs#define UREG_A0_DEST_SHIFT_LEFT  (UREG_TYPE_SHIFT - A0_DEST_TYPE_SHIFT)
266fa225cbcSrjs#define UREG_A0_SRC0_SHIFT_LEFT  (UREG_TYPE_SHIFT - A0_SRC0_TYPE_SHIFT)
267fa225cbcSrjs#define UREG_A1_SRC0_SHIFT_RIGHT (A1_SRC0_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
268fa225cbcSrjs#define UREG_A1_SRC1_SHIFT_LEFT  (UREG_TYPE_SHIFT - A1_SRC1_TYPE_SHIFT)
269fa225cbcSrjs#define UREG_A2_SRC1_SHIFT_RIGHT (A2_SRC1_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
270fa225cbcSrjs#define UREG_A2_SRC2_SHIFT_LEFT  (UREG_TYPE_SHIFT - A2_SRC2_TYPE_SHIFT)
271fa225cbcSrjs
272fa225cbcSrjs#define UREG_MASK         0xffffff00
273fa225cbcSrjs#define UREG_TYPE_NR_MASK ((REG_TYPE_MASK << UREG_TYPE_SHIFT) | \
274fa225cbcSrjs                           (REG_NR_MASK << UREG_NR_SHIFT))
275fa225cbcSrjs
276fa225cbcSrjs#endif
277