OSDN Git Service

Fix initializing LOD for 3D sampling.
authorNicolas Capens <capn@google.com>
Tue, 2 Jan 2018 19:22:23 +0000 (14:22 -0500)
committerNicolas Capens <nicolascapens@google.com>
Wed, 3 Jan 2018 14:10:53 +0000 (14:10 +0000)
The LOD value was not being computed for 3D texture sampling when no
mipmapping is done. We still need the LOD in case the minification and
magnification filters differ.

Change-Id: If32d7aaf8a92ace33bcc6ca6f0b60fe33c7e771b
Reviewed-on: https://swiftshader-review.googlesource.com/15588
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/OpenGL/libGLESv2/utilities.cpp
src/Shader/SamplerCore.cpp

index b43d32f..0a26f30 100644 (file)
@@ -2057,15 +2057,12 @@ namespace es2sw
                case GL_NEAREST:
                case GL_LINEAR:
                        return sw::MIPMAP_NONE;
-                       break;
                case GL_NEAREST_MIPMAP_NEAREST:
                case GL_LINEAR_MIPMAP_NEAREST:
                        return sw::MIPMAP_POINT;
-                       break;
                case GL_NEAREST_MIPMAP_LINEAR:
                case GL_LINEAR_MIPMAP_LINEAR:
                        return sw::MIPMAP_LINEAR;
-                       break;
                default:
                        UNREACHABLE(minFilter);
                        return sw::MIPMAP_NONE;
@@ -2079,12 +2076,13 @@ namespace es2sw
                        return sw::FILTER_ANISOTROPIC;
                }
 
-               sw::FilterType magFilterType = sw::FILTER_POINT;
                switch(magFilter)
                {
-               case GL_NEAREST: magFilterType = sw::FILTER_POINT;  break;
-               case GL_LINEAR:  magFilterType = sw::FILTER_LINEAR; break;
-               default: UNREACHABLE(magFilter);
+               case GL_NEAREST:
+               case GL_LINEAR:
+                       break;
+               default:
+                       UNREACHABLE(magFilter);
                }
 
                switch(minFilter)
@@ -2092,14 +2090,14 @@ namespace es2sw
                case GL_NEAREST:
                case GL_NEAREST_MIPMAP_NEAREST:
                case GL_NEAREST_MIPMAP_LINEAR:
-                       return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR;
+                       return (magFilter == GL_NEAREST) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR;
                case GL_LINEAR:
                case GL_LINEAR_MIPMAP_NEAREST:
                case GL_LINEAR_MIPMAP_LINEAR:
-                       return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_MIN_LINEAR_MAG_POINT : sw::FILTER_LINEAR;
+                       return (magFilter == GL_NEAREST) ? sw::FILTER_MIN_LINEAR_MAG_POINT : sw::FILTER_LINEAR;
                default:
                        UNREACHABLE(minFilter);
-                       return (magFilterType == sw::FILTER_POINT) ? sw::FILTER_POINT : sw::FILTER_MIN_POINT_MAG_LINEAR;
+                       return sw::FILTER_POINT;
                }
        }
 
index b28d6e3..cae1ecd 100644 (file)
@@ -573,7 +573,7 @@ namespace sw
                        return c;
                }
 
-               if(state.mipmapFilter > MIPMAP_POINT)
+               if(state.mipmapFilter == MIPMAP_LINEAR)
                {
                        Vector4s cc = sampleAniso(texture, u, v, w, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
 
@@ -1066,7 +1066,7 @@ namespace sw
                        return c;
                }
 
-               if(state.mipmapFilter > MIPMAP_POINT)
+               if(state.mipmapFilter == MIPMAP_LINEAR)
                {
                        Vector4f cc = sampleFloatAniso(texture, u, v, w, q, offset, lod, anisotropy, uDelta, vDelta, face, true, function);
 
@@ -1518,67 +1518,61 @@ namespace sw
 
        void SamplerCore::computeLod3D(Pointer<Byte> &texture, Float &lod, Float4 &uuuu, Float4 &vvvv, Float4 &wwww, const Float &lodBias, Vector4f &dsx, Vector4f &dsy, SamplerFunction function)
        {
-               if(state.mipmapFilter == MIPMAP_NONE)
-               {
-               }
-               else   // Point and linear filter
+               if(function != Lod && function != Fetch)
                {
-                       if(function != Lod && function != Fetch)
-                       {
-                               Float4 dudxy, dvdxy, dsdxy;
+                       Float4 dudxy, dvdxy, dsdxy;
 
-                               if(function != Grad)   // Implicit
-                               {
-                                       dudxy = uuuu - uuuu.xxxx;
-                                       dvdxy = vvvv - vvvv.xxxx;
-                                       dsdxy = wwww - wwww.xxxx;
-                               }
-                               else
-                               {
-                                       dudxy = Float4(dsx.x.xx, dsy.x.xx);
-                                       dvdxy = Float4(dsx.y.xx, dsy.y.xx);
-                                       dsdxy = Float4(dsx.z.xx, dsy.z.xx);
-                               }
+                       if(function != Grad)   // Implicit
+                       {
+                               dudxy = uuuu - uuuu.xxxx;
+                               dvdxy = vvvv - vvvv.xxxx;
+                               dsdxy = wwww - wwww.xxxx;
+                       }
+                       else
+                       {
+                               dudxy = Float4(dsx.x.xx, dsy.x.xx);
+                               dvdxy = Float4(dsx.y.xx, dsy.y.xx);
+                               dsdxy = Float4(dsx.z.xx, dsy.z.xx);
+                       }
 
-                               // Scale by texture dimensions and global LOD.
-                               dudxy *= *Pointer<Float4>(texture + OFFSET(Texture,widthLOD));
-                               dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture,heightLOD));
-                               dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture,depthLOD));
+                       // Scale by texture dimensions and global LOD.
+                       dudxy *= *Pointer<Float4>(texture + OFFSET(Texture,widthLOD));
+                       dvdxy *= *Pointer<Float4>(texture + OFFSET(Texture,heightLOD));
+                       dsdxy *= *Pointer<Float4>(texture + OFFSET(Texture,depthLOD));
 
-                               dudxy *= dudxy;
-                               dvdxy *= dvdxy;
-                               dsdxy *= dsdxy;
+                       dudxy *= dudxy;
+                       dvdxy *= dvdxy;
+                       dsdxy *= dsdxy;
 
-                               dudxy += dvdxy;
-                               dudxy += dsdxy;
+                       dudxy += dvdxy;
+                       dudxy += dsdxy;
 
-                               lod = Max(Float(dudxy.y), Float(dudxy.z));   // FIXME: Max(dudxy.y, dudxy.z);
+                       lod = Max(Float(dudxy.y), Float(dudxy.z));   // FIXME: Max(dudxy.y, dudxy.z);
 
-                               lod = log2sqrt(lod);   // log2(sqrt(lod))
+                       lod = log2sqrt(lod);   // log2(sqrt(lod))
 
-                               if(function == Bias)
-                               {
-                                       lod += lodBias;
-                               }
-                       }
-                       else if(function == Lod)
-                       {
-                               lod = lodBias;
-                       }
-                       else if(function == Fetch)
-                       {
-                               // TODO: Eliminate int-float-int conversion.
-                               lod = Float(As<Int>(lodBias));
-                       }
-                       else if(function == Base)
+                       if(function == Bias)
                        {
-                               lod = Float(0);
+                               lod += lodBias;
                        }
-                       else assert(false);
-
-                       lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
-                       lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
                }
+               else if(function == Lod)
+               {
+                       lod = lodBias;
+               }
+               else if(function == Fetch)
+               {
+                       // TODO: Eliminate int-float-int conversion.
+                       lod = Float(As<Int>(lodBias));
+               }
+               else if(function == Base)
+               {
+                       lod = Float(0);
+               }
+               else assert(false);
+
+               lod = Max(lod, *Pointer<Float>(texture + OFFSET(Texture, minLod)));
+               lod = Min(lod, *Pointer<Float>(texture + OFFSET(Texture, maxLod)));
        }
 
        void SamplerCore::cubeFace(Int face[4], Float4 &U, Float4 &V, Float4 &x, Float4 &y, Float4 &z, Float4 &M)
@@ -2240,7 +2234,7 @@ namespace sw
 
        void SamplerCore::selectMipmap(Pointer<Byte> &texture, Pointer<Byte> buffer[4], Pointer<Byte> &mipmap, Float &lod, Int face[4], bool secondLOD)
        {
-               if(state.mipmapFilter < MIPMAP_POINT)
+               if(state.mipmapFilter == MIPMAP_NONE)
                {
                        mipmap = texture + OFFSET(Texture,mipmap[0]);
                }
@@ -2252,7 +2246,7 @@ namespace sw
                        {
                                ilod = RoundInt(lod);
                        }
-                       else   // Linear
+                       else   // MIPMAP_LINEAR
                        {
                                ilod = Int(lod);
                        }