mesa: move nvprogram.[ch] to main/
[mesa.git] / src / mesa / shader / slang / library / slang_common_builtin.gc
index 3e03b101b87384ef72b699ddeda91efd8907239b..d75354deffe71909da2bc2482dfd535d5fff2043 100644 (file)
@@ -27,8 +27,9 @@
 // From Shader Spec, ver. 1.10, rev. 59
 //
 
-//bp: XXX these will probably go away since the value needs to be
-//determined at runtime and may vary from one GLcontext to another...
+// Note: the values assigned to these constants here aren't actually used.
+// They're set by the compiler according to the GL context limits.
+// See slang_simplify.c
 const int gl_MaxLights = 8;
 const int gl_MaxClipPlanes = 6;
 const int gl_MaxTextureUnits = 8;
@@ -601,42 +602,44 @@ vec4 exp2(const vec4 a)
 
 float sqrt(const float x)
 {
+   const float nx = -x;
    float r;
    __asm float_rsq r, x;
-   __asm float_rcp __retVal, r;
+   r = r * x;
+   __asm vec4_cmp __retVal, nx, r, 0.0;
 }
 
-vec2 sqrt(const vec2 v)
+vec2 sqrt(const vec2 x)
 {
-   float r;
-   __asm float_rsq r, v.x;
-   __asm float_rcp __retVal.x, r;
-   __asm float_rsq r, v.y;
-   __asm float_rcp __retVal.y, r;
+   const vec2 nx = -x, zero = vec2(0.0);
+   vec2 r;
+   __asm float_rsq r.x, x.x;
+   __asm float_rsq r.y, x.y;
+   r = r * x;
+   __asm vec4_cmp __retVal, nx, r, zero;
 }
 
-vec3 sqrt(const vec3 v)
+vec3 sqrt(const vec3 x)
 {
-   float r;
-   __asm float_rsq r, v.x;
-   __asm float_rcp __retVal.x, r;
-   __asm float_rsq r, v.y;
-   __asm float_rcp __retVal.y, r;
-   __asm float_rsq r, v.z;
-   __asm float_rcp __retVal.z, r;
+   const vec3 nx = -x, zero = vec3(0.0);
+   vec3 r;
+   __asm float_rsq r.x, x.x;
+   __asm float_rsq r.y, x.y;
+   __asm float_rsq r.z, x.z;
+   r = r * x;
+   __asm vec4_cmp __retVal, nx, r, zero;
 }
 
-vec4 sqrt(const vec4 v)
+vec4 sqrt(const vec4 x)
 {
-   float r;
-   __asm float_rsq r, v.x;
-   __asm float_rcp __retVal.x, r;
-   __asm float_rsq r, v.y;
-   __asm float_rcp __retVal.y, r;
-   __asm float_rsq r, v.z;
-   __asm float_rcp __retVal.z, r;
-   __asm float_rsq r, v.w;
-   __asm float_rcp __retVal.w, r;
+   const vec4 nx = -x, zero = vec4(0.0);
+   vec4 r;
+   __asm float_rsq r.x, x.x;
+   __asm float_rsq r.y, x.y;
+   __asm float_rsq r.z, x.z;
+   __asm float_rsq r.w, x.w;
+   r = r * x;
+   __asm vec4_cmp __retVal, nx, r, zero;
 }
 
 
@@ -686,7 +689,7 @@ vec3 normalize(const vec3 v)
 {
 //   const float s = inversesqrt(dot(v, v));
 //   __retVal = v * s;
-// XXX note, we _could_ use __retVal.w instead of tmp and and save a
+// XXX note, we _could_ use __retVal.w instead of tmp and save a
 // register, but that's actually a compilation error because v is a vec3
 // and the .w suffix is illegal.  Oh well.
    float tmp;
@@ -1157,7 +1160,7 @@ float length(const vec2 v)
    float r;
    const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y
    __asm float_rsq r, p;           // r = 1 / sqrt(p)
-   __asm float_rcp __retVal.x, r;  // retVal = 1 / r
+   __retVal = p * r;               // p * r = sqrt(p);
 }
 
 float length(const vec3 v)
@@ -1165,7 +1168,7 @@ float length(const vec3 v)
    float r;
    const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y + v.z * v.z
    __asm float_rsq r, p;           // r = 1 / sqrt(p)
-   __asm float_rcp __retVal, r;    // retVal = 1 / r
+   __retVal = p * r;               // p * r = sqrt(p);
 }
 
 float length(const vec4 v)
@@ -1173,7 +1176,7 @@ float length(const vec4 v)
    float r;
    const float p = dot(v, v);      // p = v.x * v.x + v.y * v.y + ...
    __asm float_rsq r, p;           // r = 1 / sqrt(p)
-   __asm float_rcp __retVal, r;    // retVal = 1 / r
+   __retVal = p * r;               // p * r = sqrt(p);
 }
 
 
@@ -1658,76 +1661,76 @@ bvec4 not (const bvec4 v)
 
 vec4 texture1D(const sampler1D sampler, const float coord)
 {
-   __asm vec4_tex1d __retVal, sampler, coord;
+   __asm vec4_tex_1d __retVal, sampler, coord;
 }
 
 vec4 texture1DProj(const sampler1D sampler, const vec2 coord)
 {
    // need to swizzle .y into .w
-   __asm vec4_texp1d __retVal, sampler, coord.xyyy;
+   __asm vec4_tex_1d_proj __retVal, sampler, coord.xyyy;
 }
 
 vec4 texture1DProj(const sampler1D sampler, const vec4 coord)
 {
-   __asm vec4_texp1d __retVal, sampler, coord;
+   __asm vec4_tex_1d_proj __retVal, sampler, coord;
 }
 
 
 vec4 texture2D(const sampler2D sampler, const vec2 coord)
 {
-   __asm vec4_tex2d __retVal, sampler, coord;
+   __asm vec4_tex_2d __retVal, sampler, coord;
 }
 
 vec4 texture2DProj(const sampler2D sampler, const vec3 coord)
 {
    // need to swizzle 'z' into 'w'.
-   __asm vec4_texp2d __retVal, sampler, coord.xyzz;
+   __asm vec4_tex_2d_proj __retVal, sampler, coord.xyzz;
 }
 
 vec4 texture2DProj(const sampler2D sampler, const vec4 coord)
 {
-   __asm vec4_texp2d __retVal, sampler, coord;
+   __asm vec4_tex_2d_proj __retVal, sampler, coord;
 }
 
 
 vec4 texture3D(const sampler3D sampler, const vec3 coord)
 {
-   __asm vec4_tex3d __retVal, sampler, coord;
+   __asm vec4_tex_3d __retVal, sampler, coord;
 }
 
 vec4 texture3DProj(const sampler3D sampler, const vec4 coord)
 {
-   __asm vec4_texp3d __retVal, sampler, coord;
+   __asm vec4_tex_3d_proj __retVal, sampler, coord;
 }
 
 
 vec4 textureCube(const samplerCube sampler, const vec3 coord)
 {
-   __asm vec4_texcube __retVal, sampler, coord;
+   __asm vec4_tex_cube __retVal, sampler, coord;
 }
 
 
 
 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord)
 {
-   __asm vec4_tex1d __retVal, sampler, coord;
+   __asm vec4_tex_1d_shadow __retVal, sampler, coord;
 }
 
 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord)
 {
    // .s and .p will be divided by .q
-   __asm vec4_texp1d __retVal, sampler, coord;
+   __asm vec4_tex_1d_proj_shadow __retVal, sampler, coord;
 }
 
 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord)
 {
-   __asm vec4_tex2d __retVal, sampler, coord;
+   __asm vec4_tex_2d_shadow __retVal, sampler, coord;
 }
 
 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord)
 {
    // .s, .t and .p will be divided by .q
-   __asm vec4_texp2d __retVal, sampler, coord;
+   __asm vec4_tex_2d_proj_shadow __retVal, sampler, coord;
 }
 
 
@@ -1740,26 +1743,38 @@ vec4 texture2DRect(const sampler2DRect sampler, const vec2 coord)
 vec4 texture2DRectProj(const sampler2DRect sampler, const vec3 coord)
 {
    // need to swizzle .y into .w
-   __asm vec4_texp_rect __retVal, sampler, coord.xyzz;
+   __asm vec4_tex_rect_proj __retVal, sampler, coord.xyzz;
 }
 
 vec4 texture2DRectProj(const sampler2DRect sampler, const vec4 coord)
 {
-   __asm vec4_texp_rect __retVal, sampler, ccoord;
+   __asm vec4_tex_rect_proj __retVal, sampler, ccoord;
 }
 
 vec4 shadow2DRect(const sampler2DRectShadow sampler, const vec3 coord)
 {
-   __asm vec4_tex_rect __retVal, sampler, coord;
+   __asm vec4_tex_rect_shadow __retVal, sampler, coord;
 }
 
 vec4 shadow2DRectProj(const sampler2DRectShadow sampler, const vec4 coord)
 {
-   __asm vec4_texp_rect __retVal, sampler, coord;
+   __asm vec4_tex_rect_proj_shadow __retVal, sampler, coord;
 }
 
 
 
+//// GL_EXT_texture_array
+vec4 texture1DArray(const sampler1DArray sampler, const vec2 coord)
+{
+   __asm vec4_tex_1d_array __retVal, sampler, coord;
+}
+
+vec4 texture2DArray(const sampler2DArray sampler, const vec3 coord)
+{
+   __asm vec4_tex_2d_array __retVal, sampler, coord;
+}
+
+
 //
 // 8.9 Noise Functions
 //