Merge branch 'master' of git+ssh://brianp@git.freedesktop.org/git/mesa/mesa into...
[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 vec4 texture2D(const sampler2D sampler, const vec2 coord, const float bias)
72 {
73 vec4 coord4;
74 coord4.xy = coord.xy;
75 coord4.w = bias;
76 __asm vec4_texb2d __retVal, sampler, coord4;
77 }
78
79 vec4 texture2DProj(const sampler2D sampler, const vec3 coord, const float bias)
80 {
81 // do projection here (there's no vec4_texbp2d instruction)
82 vec4 pcoord;
83 pcoord.xy = coord.xy / coord.z;
84 pcoord.w = bias;
85 __asm vec4_texb2d __retVal, sampler, pcoord;
86 }
87
88 vec4 texture2DProj(const sampler2D sampler, const vec4 coord, const float bias)
89 {
90 // do projection here (there's no vec4_texbp2d instruction)
91 vec4 pcoord;
92 pcoord.xy = coord.xy / coord.w;
93 pcoord.w = bias;
94 __asm vec4_texb2d __retVal, sampler, pcoord;
95 }
96
97
98 vec4 texture3D(const sampler3D sampler, const vec3 coord, const float bias)
99 {
100 vec4 coord4;
101 coord4.xyz = coord.xyz;
102 coord4.w = bias;
103 __asm vec4_texb3d __retVal, sampler, coord4;
104 }
105
106 vec4 texture3DProj(const sampler3D sampler, const vec4 coord, const float bias)
107 {
108 // do projection here (there's no vec4_texbp3d instruction)
109 vec4 pcoord;
110 pcoord.xyz = coord.xyz / coord.w;
111 pcoord.w = bias;
112 __asm vec4_texb3d __retVal, sampler, pcoord;
113 }
114
115
116 vec4 textureCube(const samplerCube sampler, const vec3 coord, const float bias)
117 {
118 vec4 coord4;
119 coord4.xyz = coord;
120 coord4.w = bias;
121 __asm vec4_texcube __retVal, sampler, coord4;
122 }
123
124
125 // For shadow textures, we use the regular tex instructions since they should
126 // do the depth comparison step.
127
128 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
129 {
130 vec4 coord4;
131 coord4.xyz = coord;
132 coord4.w = bias;
133 __asm vec4_texb1d __retVal, sampler, coord4;
134 }
135
136 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
137 {
138 vec4 pcoord;
139 pcoord.x = coord.x / coord.w;
140 pcoord.z = coord.z;
141 pcoord.w = bias;
142 __asm vec4_texb1d __retVal, sampler, pcoord;
143 }
144
145 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
146 {
147 vec4 coord4;
148 coord4.xyz = coord;
149 coord4.w = bias;
150 __asm vec4_texb2d __retVal, sampler, coord4;
151 }
152
153 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
154 {
155 vec4 pcoord;
156 pcoord.xy = coord.xy / coord.w;
157 pcoord.z = coord.z;
158 pcoord.w = bias;
159 __asm vec4_texb2d __retVal, sampler, pcoord;
160 }
161
162
163
164
165
166 //
167 // 8.8 Fragment Processing Functions
168 //
169
170 float dFdx(const float p)
171 {
172 __asm vec4_ddx __retVal.x, p.xxxx;
173 }
174
175 vec2 dFdx(const vec2 p)
176 {
177 __asm vec4_ddx __retVal.xy, p.xyyy;
178 }
179
180 vec3 dFdx(const vec3 p)
181 {
182 __asm vec4_ddx __retVal.xyz, p.xyzz;
183 }
184
185 vec4 dFdx(const vec4 p)
186 {
187 __asm vec4_ddx __retVal, p;
188 }
189
190 float dFdy(const float p)
191 {
192 __asm vec4_ddy __retVal.x, p.xxxx;
193 }
194
195 vec2 dFdy(const vec2 p)
196 {
197 __asm vec4_ddy __retVal.xy, p.xyyy;
198 }
199
200 vec3 dFdy(const vec3 p)
201 {
202 __asm vec4_ddy __retVal.xyz, p.xyzz;
203 }
204
205 vec4 dFdy(const vec4 p)
206 {
207 __asm vec4_ddy __retVal, p;
208 }
209
210 float fwidth (const float p)
211 {
212 // XXX hand-write with __asm
213 return abs(dFdx(p)) + abs(dFdy(p));
214 }
215
216 vec2 fwidth(const vec2 p)
217 {
218 // XXX hand-write with __asm
219 return abs(dFdx(p)) + abs(dFdy(p));
220 }
221
222 vec3 fwidth(const vec3 p)
223 {
224 // XXX hand-write with __asm
225 return abs(dFdx(p)) + abs(dFdy(p));
226 }
227
228 vec4 fwidth(const vec4 p)
229 {
230 // XXX hand-write with __asm
231 return abs(dFdx(p)) + abs(dFdy(p));
232 }
233