From: Greg Daniel Date: Wed, 22 Mar 2017 21:03:45 +0000 (-0400) Subject: In vulkan align data in buffer when copying to image X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~46^2~365 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=468fd63760283c56630d752583b234f44ab03024;p=platform%2Fupstream%2FlibSkiaSharp.git In vulkan align data in buffer when copying to image BUG=skia: Change-Id: If99ba2797dfca547ce98cd9c1a1f1c234cf8791e Reviewed-on: https://skia-review.googlesource.com/10027 Reviewed-by: Brian Osman Commit-Queue: Greg Daniel --- diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index e1ff70f..b634116 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -554,6 +554,10 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, size_t combinedBufferSize = width * bpp * height; int currentWidth = width; int currentHeight = height; + // The alignment must be at least 4 bytes and a multiple of the bytes per pixel of the image + // config. This works with the assumption that the bytes in pixel config is always a power of 2. + SkASSERT((bpp & (bpp - 1)) == 0); + const size_t alignmentMask = 0x3 | (bpp - 1); for (int currentMipLevel = 1; currentMipLevel < texelsShallowCopy.count(); currentMipLevel++) { currentWidth = SkTMax(1, currentWidth/2); currentHeight = SkTMax(1, currentHeight/2); @@ -565,6 +569,10 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, return false; } const size_t trimmedSize = currentWidth * bpp * currentHeight; + const size_t alignmentDiff = combinedBufferSize & alignmentMask; + if (alignmentDiff != 0) { + combinedBufferSize += alignmentMask - alignmentDiff + 1; + } individualMipOffsets.push_back(combinedBufferSize); combinedBufferSize += trimmedSize; }