Allow Vulkan to upload to main mip level without uploading to all levels.
authorGreg Daniel <egdaniel@google.com>
Fri, 7 Apr 2017 18:42:23 +0000 (14:42 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 7 Apr 2017 19:27:14 +0000 (19:27 +0000)
It should be allowed for the client to upload original data to a texture via
writePixels and then we just regenerate the mipmaps. I think it also resonable
to limit this to either writting to all levels or just the top level.

Bug: skia:
Change-Id: I66943cca54c2a7187a781788653948fb69c17c68
Reviewed-on: https://skia-review.googlesource.com/11798
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>

src/gpu/vk/GrVkGpu.cpp

index ed64590..b3401e1 100644 (file)
@@ -368,7 +368,7 @@ bool GrVkGpu::onWritePixels(GrSurface* surface,
         } else {
             int newMipLevels = texels.count();
             int currentMipLevels = vkTex->texturePriv().maxMipMapLevel() + 1;
-            if (newMipLevels != currentMipLevels) {
+            if (newMipLevels > currentMipLevels) {
                 if (!vkTex->reallocForMipmap(this, newMipLevels)) {
                     return false;
                 }
@@ -517,6 +517,10 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
     SkASSERT(1 == texels.count() ||
              (0 == left && 0 == top && width == tex->width() && height == tex->height()));
 
+    // We assume that if the texture has mip levels, we either upload to all the levels or just the
+    // first.
+    SkASSERT(1 == texels.count() || texels.count() == (tex->texturePriv().maxMipMapLevel() + 1));
+
     // If we're uploading compressed data then we should be using uploadCompressedTexData
     SkASSERT(!GrPixelConfigIsCompressed(dataConfig));
 
@@ -642,6 +646,9 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex,
                                          regions.count(),
                                          regions.begin());
     transferBuffer->unref();
+    if (1 == texelsShallowCopy.count()) {
+       tex->texturePriv().dirtyMipMaps(true);
+    }
 
     return true;
 }