Fix checks for base and max level in Texture.

The dEQP unpack buffer tests were failing because they use a max and
base level of zero with mipmapping enabled. Update our sampler
completeness checks to account for min and max level.

We'll have to dig in to our code to find corner cases in D3D with
base and max level.

Change-Id: I74357c6dc2e1908d0463d2e5cbc8ee91b61a3b7f
Reviewed-on: https://chromium-review.googlesource.com/240763
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Texture.cpp b/src/libANGLE/Texture.cpp
index 359e1ef..90b8c41 100644
--- a/src/libANGLE/Texture.cpp
+++ b/src/libANGLE/Texture.cpp
@@ -106,9 +106,9 @@
 bool Texture::isSamplerComplete(const SamplerState &samplerState, const Data &data) const
 {
     GLenum baseTarget = getBaseImageTarget();
-    size_t width = getWidth(baseTarget, 0);
-    size_t height = getHeight(baseTarget, 0);
-    size_t depth = getDepth(baseTarget, 0);
+    size_t width = getWidth(baseTarget, samplerState.baseLevel);
+    size_t height = getHeight(baseTarget, samplerState.baseLevel);
+    size_t depth = getDepth(baseTarget, samplerState.baseLevel);
     if (width == 0 || height == 0 || depth == 0)
     {
         return false;
@@ -119,7 +119,7 @@
         return false;
     }
 
-    GLenum internalFormat = getInternalFormat(baseTarget, 0);
+    GLenum internalFormat = getInternalFormat(baseTarget, samplerState.baseLevel);
     const TextureCaps &textureCaps = data.textureCaps->get(internalFormat);
     if (!textureCaps.filterable && !IsPointSampled(samplerState))
     {
@@ -146,7 +146,7 @@
             }
         }
 
-        if (!isMipmapComplete())
+        if (!isMipmapComplete(samplerState))
         {
             return false;
         }
@@ -432,16 +432,19 @@
     }
 }
 
-bool Texture::isMipmapComplete() const
+bool Texture::isMipmapComplete(const gl::SamplerState &samplerState) const
 {
     size_t expectedMipLevels = getExpectedMipLevels();
-    for (size_t level = 0; level < expectedMipLevels; level++)
+
+    size_t maxLevel = std::min<size_t>(expectedMipLevels, samplerState.maxLevel + 1);
+
+    for (size_t level = samplerState.baseLevel; level < maxLevel; level++)
     {
         if (mTarget == GL_TEXTURE_CUBE_MAP)
         {
             for (GLenum face = FirstCubeMapTextureTarget; face <= LastCubeMapTextureTarget; face++)
             {
-                if (!isLevelComplete(face, level))
+                if (!isLevelComplete(face, level, samplerState))
                 {
                     return false;
                 }
@@ -449,7 +452,7 @@
         }
         else
         {
-            if (!isLevelComplete(mTarget, level))
+            if (!isLevelComplete(mTarget, level, samplerState))
             {
                 return false;
             }
@@ -460,7 +463,8 @@
 }
 
 
-bool Texture::isLevelComplete(GLenum target, size_t level) const
+bool Texture::isLevelComplete(GLenum target, size_t level,
+                              const gl::SamplerState &samplerState) const
 {
     ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
 
@@ -469,9 +473,9 @@
         return true;
     }
 
-    size_t width = getWidth(target, 0);
-    size_t height = getHeight(target, 0);
-    size_t depth = getHeight(target, 0);
+    size_t width = getWidth(target, samplerState.baseLevel);
+    size_t height = getHeight(target, samplerState.baseLevel);
+    size_t depth = getHeight(target, samplerState.baseLevel);
     if (width == 0 || height == 0 || depth == 0)
     {
         return false;
@@ -483,7 +487,7 @@
         return true;
     }
 
-    if (getInternalFormat(target, level) != getInternalFormat(target, 0))
+    if (getInternalFormat(target, level) != getInternalFormat(target, samplerState.baseLevel))
     {
         return false;
     }