Fix copy offset when uploading initial mip data in Vulkan
authorGreg Daniel <egdaniel@google.com>
Tue, 28 Mar 2017 18:56:46 +0000 (14:56 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 29 Mar 2017 15:40:15 +0000 (15:40 +0000)
This is a fix to an original fix which was reverted

BUG=skia:

Change-Id: I21fcda28a5d342984784a35d2b3e985c6e4199cf
Reviewed-on: https://skia-review.googlesource.com/10290
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
src/gpu/vk/GrVkGpu.cpp

index 7676964..77816e0 100644 (file)
@@ -590,7 +590,9 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
 
     currentWidth = width;
     currentHeight = height;
+    int layerHeight = tex->height();
     for (int currentMipLevel = 0; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) {
+        SkASSERT(1 == texelsShallowCopy.count() || currentHeight == layerHeight);
         const size_t trimRowBytes = currentWidth * bpp;
         const size_t rowBytes = texelsShallowCopy[currentMipLevel].fRowBytes;
 
@@ -614,11 +616,12 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
         region.bufferRowLength = currentWidth;
         region.bufferImageHeight = currentHeight;
         region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMipLevel), 0, 1 };
-        region.imageOffset = { left, flipY ? tex->height() - top - currentHeight : top, 0 };
+        region.imageOffset = { left, flipY ? layerHeight - top - currentHeight : top, 0 };
         region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 };
 
         currentWidth = SkTMax(1, currentWidth/2);
         currentHeight = SkTMax(1, currentHeight/2);
+        layerHeight = currentHeight;
     }
 
     // no need to flush non-coherent memory, unmap will do that for us