aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2017-03-22 17:03:45 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-23 15:31:00 +0000
commit468fd63760283c56630d752583b234f44ab03024 (patch)
treed46a678d5f209f5779a4be194aa51463dcdf3f7b /src/gpu/vk
parenta88a646b375ab116125664f64c4db64dc5259a6b (diff)
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 <brianosman@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r--src/gpu/vk/GrVkGpu.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index e1ff70f7d0..b634116841 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;
}