mesa: glsl: grab latest fixes from gallium-0.1 branch
[mesa.git] / src / mesa / shader / slang / library / slang_fragment_builtin.gc
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 //
26 // From Shader Spec, ver. 1.10, rev. 59
27 //
28
29 __fixed_input vec4 gl_FragCoord;
30 __fixed_input bool gl_FrontFacing;
31 __fixed_output vec4 gl_FragColor;
32 __fixed_output vec4 gl_FragData[gl_MaxDrawBuffers];
33 __fixed_output float gl_FragDepth;
34
35 varying vec4 gl_Color;
36 varying vec4 gl_SecondaryColor;
37 varying vec4 gl_TexCoord[gl_MaxTextureCoords];
38 varying float gl_FogFragCoord;
39
40
41
42 //// 8.7 Texture Lookup Functions (with bias)
43
44 vec4 texture1D(const sampler1D sampler, const float coord, const float bias)
45 {
46 vec4 coord4;
47 coord4.x = coord;
48 coord4.w = bias;
49 __asm vec4_texb1d __retVal, sampler, coord4;
50 }
51
52 vec4 texture1DProj(const sampler1D sampler, const vec2 coord, const float bias)
53 {
54 // do projection here (there's no vec4_texbp1d instruction)
55 vec4 pcoord;
56 pcoord.x = coord.x / coord.y;
57 pcoord.w = bias;
58 __asm vec4_texb1d __retVal, sampler, pcoord;
59 }
60
61 vec4 texture1DProj(const sampler1D sampler, const vec4 coord, const float bias)
62 {
63 // do projection here (there's no vec4_texbp1d instruction)
64 vec4 pcoord;
65 pcoord.x = coord.x / coord.z;
66 pcoord.w = bias;
67 __asm vec4_texb1d __retVal, sampler, pcoord;
68 }
69
70
71
72
73 vec4 texture2D(const sampler2D sampler, const vec2 coord, const float bias)
74 {
75 vec4 coord4;
76 coord4.xy = coord.xy;
77 coord4.w = bias;
78 __asm vec4_texb2d __retVal, sampler, coord4;
79 }
80
81 vec4 texture2DProj(const sampler2D sampler, const vec3 coord, const float bias)
82 {
83 // do projection here (there's no vec4_texbp2d instruction)
84 vec4 pcoord;
85 pcoord.xy = coord.xy / coord.z;
86 pcoord.w = bias;
87 __asm vec4_texb2d __retVal, sampler, pcoord;
88 }
89
90 vec4 texture2DProj(const sampler2D sampler, const vec4 coord, const float bias)
91 {
92 // do projection here (there's no vec4_texbp2d instruction)
93 vec4 pcoord;
94 pcoord.xy = coord.xy / coord.w;
95 pcoord.w = bias;
96 __asm vec4_texb2d __retVal, sampler, pcoord;
97 }
98
99
100
101
102 vec4 texture3D(const sampler3D sampler, const vec3 coord, const float bias)
103 {
104 vec4 coord4;
105 coord4.xyz = coord.xyz;
106 coord4.w = bias;
107 __asm vec4_texb3d __retVal, sampler, coord4;
108 }
109
110 vec4 texture3DProj(const sampler3D sampler, const vec4 coord, const float bias)
111 {
112 // do projection here (there's no vec4_texbp3d instruction)
113 vec4 pcoord;
114 pcoord.xyz = coord.xyz / coord.w;
115 pcoord.w = bias;
116 __asm vec4_texb3d __retVal, sampler, pcoord;
117 }
118
119
120
121
122 vec4 textureCube(const samplerCube sampler, const vec3 coord, const float bias)
123 {
124 vec4 coord4;
125 coord4.xyz = coord;
126 coord4.w = bias;
127 __asm vec4_texcube __retVal, sampler, coord4;
128 }
129
130
131
132
133 // For shadow textures, we use the regular tex instructions since they should
134 // do the depth comparison step.
135
136 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
137 {
138 vec4 coord4;
139 coord4.xyz = coord;
140 coord4.w = bias;
141 __asm vec4_texb1d __retVal, sampler, coord4;
142 }
143
144 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
145 {
146 vec4 pcoord;
147 pcoord.x = coord.x / coord.w;
148 pcoord.z = coord.z;
149 pcoord.w = bias;
150 __asm vec4_texb1d __retVal, sampler, pcoord;
151 }
152
153 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
154 {
155 vec4 coord4;
156 coord4.xyz = coord;
157 coord4.w = bias;
158 __asm vec4_texb2d __retVal, sampler, coord4;
159 }
160
161 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
162 {
163 vec4 pcoord;
164 pcoord.xy = coord.xy / coord.w;
165 pcoord.z = coord.z;
166 pcoord.w = bias;
167 __asm vec4_texb2d __retVal, sampler, pcoord;
168 }
169
170
171
172 //
173 // 8.8 Fragment Processing Functions
174 //
175
176 float dFdx(const float p)
177 {
178 __asm vec4_ddx __retVal.x, p.xxxx;
179 }
180
181 vec2 dFdx(const vec2 p)
182 {
183 __asm vec4_ddx __retVal.xy, p.xyyy;
184 }
185
186 vec3 dFdx(const vec3 p)
187 {
188 __asm vec4_ddx __retVal.xyz, p.xyzz;
189 }
190
191 vec4 dFdx(const vec4 p)
192 {
193 __asm vec4_ddx __retVal, p;
194 }
195
196 float dFdy(const float p)
197 {
198 __asm vec4_ddy __retVal.x, p.xxxx;
199 }
200
201 vec2 dFdy(const vec2 p)
202 {
203 __asm vec4_ddy __retVal.xy, p.xyyy;
204 }
205
206 vec3 dFdy(const vec3 p)
207 {
208 __asm vec4_ddy __retVal.xyz, p.xyzz;
209 }
210
211 vec4 dFdy(const vec4 p)
212 {
213 __asm vec4_ddy __retVal, p;
214 }
215
216 float fwidth (const float p)
217 {
218 // XXX hand-write with __asm
219 return abs(dFdx(p)) + abs(dFdy(p));
220 }
221
222 vec2 fwidth(const vec2 p)
223 {
224 // XXX hand-write with __asm
225 return abs(dFdx(p)) + abs(dFdy(p));
226 }
227
228 vec3 fwidth(const vec3 p)
229 {
230 // XXX hand-write with __asm
231 return abs(dFdx(p)) + abs(dFdy(p));
232 }
233
234 vec4 fwidth(const vec4 p)
235 {
236 // XXX hand-write with __asm
237 return abs(dFdx(p)) + abs(dFdy(p));
238 }
239