OpenGL: Use the correct size to lazy-clear mips

We would incorrectly use the size of the first mip level to clear
non-zero mip levels. This was found while enabling debug output in
the OpenGL backend.

BUG=dawn:190

Change-Id: I29a87b87057d425d1c131d11afdc7ca4716607c8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9202
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp
index f2f35a6..224a10d 100644
--- a/src/dawn_native/Texture.cpp
+++ b/src/dawn_native/Texture.cpp
@@ -408,7 +408,7 @@
         return mSampleCount > 1;
     }
 
-    Extent3D TextureBase::GetMipLevelVirtualSize(uint64_t level) const {
+    Extent3D TextureBase::GetMipLevelVirtualSize(uint32_t level) const {
         Extent3D extent;
         extent.width = std::max(mSize.width >> level, 1u);
         extent.height = std::max(mSize.height >> level, 1u);
@@ -416,7 +416,7 @@
         return extent;
     }
 
-    Extent3D TextureBase::GetMipLevelPhysicalSize(uint64_t level) const {
+    Extent3D TextureBase::GetMipLevelPhysicalSize(uint32_t level) const {
         Extent3D extent = GetMipLevelVirtualSize(level);
 
         // Compressed Textures will have paddings if their width or height is not a multiple of
diff --git a/src/dawn_native/Texture.h b/src/dawn_native/Texture.h
index fa32758..066a7d7 100644
--- a/src/dawn_native/Texture.h
+++ b/src/dawn_native/Texture.h
@@ -75,8 +75,8 @@
         // size is the one with paddings if necessary, which is always a multiple of the block size
         // and used in texture copying. The virtual size is the one without paddings, which is not
         // required to be a multiple of the block size and used in texture sampling.
-        Extent3D GetMipLevelPhysicalSize(uint64_t level) const;
-        Extent3D GetMipLevelVirtualSize(uint64_t level) const;
+        Extent3D GetMipLevelPhysicalSize(uint32_t level) const;
+        Extent3D GetMipLevelVirtualSize(uint32_t level) const;
 
         // Dawn API
         TextureViewBase* CreateDefaultView();
diff --git a/src/dawn_native/opengl/TextureGL.cpp b/src/dawn_native/opengl/TextureGL.cpp
index ade6652..e27c506 100644
--- a/src/dawn_native/opengl/TextureGL.cpp
+++ b/src/dawn_native/opengl/TextureGL.cpp
@@ -245,9 +245,10 @@
         } else {
             auto formatInfo = GetGLFormatInfo(GetFormat().format);
             for (GLint level = baseMipLevel; level < baseMipLevel + levelCount; ++level) {
-                gl.ClearTexSubImage(mHandle, level, 0, 0, baseArrayLayer, GetSize().width,
-                                    GetSize().height, layerCount, formatInfo.format,
-                                    formatInfo.type, nullptr);
+                Extent3D mipSize = GetMipLevelPhysicalSize(level);
+                gl.ClearTexSubImage(mHandle, level, 0, 0, baseArrayLayer, mipSize.width,
+                                    mipSize.height, layerCount, formatInfo.format, formatInfo.type,
+                                    nullptr);
             }
         }
         SetIsSubresourceContentInitialized(baseMipLevel, levelCount, baseArrayLayer, layerCount);