fix up radeon span functions using latest r200 code from Brian,
[mesa.git] / src / mesa / drivers / dri / i915 / i915_program.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_PROGRAM_H
30 #define I915_PROGRAM_H
31
32 #include "i915_context.h"
33 #include "i915_reg.h"
34
35
36
37 /* Having zero and one in here makes the definition of swizzle a lot
38 * easier.
39 */
40 #define UREG_TYPE_SHIFT 29
41 #define UREG_NR_SHIFT 24
42 #define UREG_CHANNEL_X_NEGATE_SHIFT 23
43 #define UREG_CHANNEL_X_SHIFT 20
44 #define UREG_CHANNEL_Y_NEGATE_SHIFT 19
45 #define UREG_CHANNEL_Y_SHIFT 16
46 #define UREG_CHANNEL_Z_NEGATE_SHIFT 15
47 #define UREG_CHANNEL_Z_SHIFT 12
48 #define UREG_CHANNEL_W_NEGATE_SHIFT 11
49 #define UREG_CHANNEL_W_SHIFT 8
50 #define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
51 #define UREG_CHANNEL_ZERO_SHIFT 4
52 #define UREG_CHANNEL_ONE_NEGATE_MBZ 1
53 #define UREG_CHANNEL_ONE_SHIFT 0
54
55 #define UREG_BAD 0xffffffff /* not a valid ureg */
56
57 #define X SRC_X
58 #define Y SRC_Y
59 #define Z SRC_Z
60 #define W SRC_W
61 #define ZERO SRC_ZERO
62 #define ONE SRC_ONE
63
64 /* Construct a ureg:
65 */
66 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) | \
67 ((nr) << UREG_NR_SHIFT) | \
68 (X << UREG_CHANNEL_X_SHIFT) | \
69 (Y << UREG_CHANNEL_Y_SHIFT) | \
70 (Z << UREG_CHANNEL_Z_SHIFT) | \
71 (W << UREG_CHANNEL_W_SHIFT) | \
72 (ZERO << UREG_CHANNEL_ZERO_SHIFT) | \
73 (ONE << UREG_CHANNEL_ONE_SHIFT))
74
75 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
76 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
77
78 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
79 #define GET_UREG_NR(reg) (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
80
81
82
83 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
84
85 /* One neat thing about the UREG representation:
86 */
87 static __inline int swizzle( int reg, int x, int y, int z, int w )
88 {
89 return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
90 CHANNEL_SRC( GET_CHANNEL_SRC( reg, x ), 0 ) |
91 CHANNEL_SRC( GET_CHANNEL_SRC( reg, y ), 1 ) |
92 CHANNEL_SRC( GET_CHANNEL_SRC( reg, z ), 2 ) |
93 CHANNEL_SRC( GET_CHANNEL_SRC( reg, w ), 3 ));
94 }
95
96 /* Another neat thing about the UREG representation:
97 */
98 static __inline int negate( int reg, int x, int y, int z, int w )
99 {
100 return reg ^ (((x&1)<<UREG_CHANNEL_X_NEGATE_SHIFT)|
101 ((y&1)<<UREG_CHANNEL_Y_NEGATE_SHIFT)|
102 ((z&1)<<UREG_CHANNEL_Z_NEGATE_SHIFT)|
103 ((w&1)<<UREG_CHANNEL_W_NEGATE_SHIFT));
104 }
105
106
107 extern GLuint i915_get_temp( struct i915_fragment_program *p );
108 extern GLuint i915_get_utemp( struct i915_fragment_program *p );
109 extern void i915_release_utemps( struct i915_fragment_program *p );
110
111
112 extern GLuint i915_emit_texld( struct i915_fragment_program *p,
113 GLuint dest,
114 GLuint destmask,
115 GLuint sampler,
116 GLuint coord,
117 GLuint op );
118
119 extern GLuint i915_emit_arith( struct i915_fragment_program *p,
120 GLuint op,
121 GLuint dest,
122 GLuint mask,
123 GLuint saturate,
124 GLuint src0,
125 GLuint src1,
126 GLuint src2 );
127
128 extern GLuint i915_emit_decl( struct i915_fragment_program *p,
129 GLuint type, GLuint nr, GLuint d0_flags );
130
131
132 extern GLuint i915_emit_const1f( struct i915_fragment_program *p,
133 GLfloat c0 );
134
135 extern GLuint i915_emit_const2f( struct i915_fragment_program *p,
136 GLfloat c0, GLfloat c1 );
137
138 extern GLuint i915_emit_const4fv( struct i915_fragment_program *p,
139 const GLfloat *c );
140
141 extern GLuint i915_emit_const4f( struct i915_fragment_program *p,
142 GLfloat c0, GLfloat c1,
143 GLfloat c2, GLfloat c3 );
144
145
146 extern GLuint i915_emit_param4fv( struct i915_fragment_program *p,
147 const GLfloat *values );
148
149 extern void i915_program_error( struct i915_fragment_program *p,
150 const char *msg );
151
152 extern void i915_init_program( i915ContextPtr i915,
153 struct i915_fragment_program *p );
154
155 extern void i915_upload_program( i915ContextPtr i915,
156 struct i915_fragment_program *p );
157
158 extern void i915_fini_program( struct i915_fragment_program *p );
159
160
161
162
163 #endif