• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2003 VMware, Inc.
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 VMWARE 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 swizzle(int reg, int x, int y, int z, int w)
89 {
90    return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
91            CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
92            CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
93            CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
94            CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
95 }
96 
97 /* Another neat thing about the UREG representation:
98  */
99 static inline int
negate(int reg,int x,int y,int z,int w)100 negate(int reg, int x, int y, int z, int w)
101 {
102    return reg ^ (((x & 1) << UREG_CHANNEL_X_NEGATE_SHIFT) |
103                  ((y & 1) << UREG_CHANNEL_Y_NEGATE_SHIFT) |
104                  ((z & 1) << UREG_CHANNEL_Z_NEGATE_SHIFT) |
105                  ((w & 1) << UREG_CHANNEL_W_NEGATE_SHIFT));
106 }
107 
108 
109 extern GLuint i915_get_temp(struct i915_fragment_program *p);
110 extern GLuint i915_get_utemp(struct i915_fragment_program *p);
111 extern void i915_release_utemps(struct i915_fragment_program *p);
112 
113 
114 extern GLuint i915_emit_texld(struct i915_fragment_program *p,
115                               GLuint live_regs,
116                               GLuint dest,
117                               GLuint destmask,
118                               GLuint sampler, GLuint coord, GLuint op);
119 
120 extern GLuint i915_emit_arith(struct i915_fragment_program *p,
121                               GLuint op,
122                               GLuint dest,
123                               GLuint mask,
124                               GLuint saturate,
125                               GLuint src0, GLuint src1, GLuint src2);
126 
127 extern GLuint i915_emit_decl(struct i915_fragment_program *p,
128                              GLuint type, GLuint nr, GLuint d0_flags);
129 
130 
131 extern GLuint i915_emit_const1f(struct i915_fragment_program *p, GLfloat c0);
132 
133 extern GLuint i915_emit_const2f(struct i915_fragment_program *p,
134                                 GLfloat c0, GLfloat c1);
135 
136 extern GLuint i915_emit_const4fv(struct i915_fragment_program *p,
137                                  const GLfloat * c);
138 
139 extern GLuint i915_emit_const4f(struct i915_fragment_program *p,
140                                 GLfloat c0, GLfloat c1,
141                                 GLfloat c2, GLfloat c3);
142 
143 
144 extern GLuint i915_emit_param4fv(struct i915_fragment_program *p,
145                                  const GLfloat * values);
146 
147 extern void i915_program_error(struct i915_fragment_program *p,
148                                const char *fmt, ...);
149 
150 extern void i915_init_program(struct i915_context *i915,
151                               struct i915_fragment_program *p);
152 
153 extern void i915_upload_program(struct i915_context *i915,
154                                 struct i915_fragment_program *p);
155 
156 extern void i915_fini_program(struct i915_fragment_program *p);
157 
158 extern void i915_update_program(struct gl_context *ctx);
159 
160 #endif
161