Merge remote branch 'main/master' into radeon-rewrite
[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_tex_1d_bias __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_tex_1d_bias __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_tex_1d_bias __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_tex_2d_bias __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_tex_2d_bias __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_tex_2d_bias __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_tex_3d_bias __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_tex_3d_bias __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_tex_cube __retVal, sampler, coord4;
128 }
129
130
131
132 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
133 {
134 vec4 coord4;
135 coord4.xyz = coord;
136 coord4.w = bias;
137 __asm vec4_tex_1d_bias_shadow __retVal, sampler, coord4;
138 }
139
140 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
141 {
142 vec4 pcoord;
143 pcoord.x = coord.x / coord.w;
144 pcoord.z = coord.z;
145 pcoord.w = bias;
146 __asm vec4_tex_1d_bias_shadow __retVal, sampler, pcoord;
147 }
148
149 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
150 {
151 vec4 coord4;
152 coord4.xyz = coord;
153 coord4.w = bias;
154 __asm vec4_tex_2d_bias_shadow __retVal, sampler, coord4;
155 }
156
157 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
158 {
159 vec4 pcoord;
160 pcoord.xy = coord.xy / coord.w;
161 pcoord.z = coord.z;
162 pcoord.w = bias;
163 __asm vec4_tex_2d_bias_shadow __retVal, sampler, pcoord;
164 }
165
166
167
168 //
169 // 8.8 Fragment Processing Functions
170 //
171
172 float dFdx(const float p)
173 {
174 __asm vec4_ddx __retVal.x, p.xxxx;
175 }
176
177 vec2 dFdx(const vec2 p)
178 {
179 __asm vec4_ddx __retVal.xy, p.xyyy;
180 }
181
182 vec3 dFdx(const vec3 p)
183 {
184 __asm vec4_ddx __retVal.xyz, p.xyzz;
185 }
186
187 vec4 dFdx(const vec4 p)
188 {
189 __asm vec4_ddx __retVal, p;
190 }
191
192 float dFdy(const float p)
193 {
194 __asm vec4_ddy __retVal.x, p.xxxx;
195 }
196
197 vec2 dFdy(const vec2 p)
198 {
199 __asm vec4_ddy __retVal.xy, p.xyyy;
200 }
201
202 vec3 dFdy(const vec3 p)
203 {
204 __asm vec4_ddy __retVal.xyz, p.xyzz;
205 }
206
207 vec4 dFdy(const vec4 p)
208 {
209 __asm vec4_ddy __retVal, p;
210 }
211
212 float fwidth (const float p)
213 {
214 // XXX hand-write with __asm
215 return abs(dFdx(p)) + abs(dFdy(p));
216 }
217
218 vec2 fwidth(const vec2 p)
219 {
220 // XXX hand-write with __asm
221 return abs(dFdx(p)) + abs(dFdy(p));
222 }
223
224 vec3 fwidth(const vec3 p)
225 {
226 // XXX hand-write with __asm
227 return abs(dFdx(p)) + abs(dFdy(p));
228 }
229
230 vec4 fwidth(const vec4 p)
231 {
232 // XXX hand-write with __asm
233 return abs(dFdx(p)) + abs(dFdy(p));
234 }
235