diff options
author | Greg Daniel <egdaniel@google.com> | 2017-09-29 09:32:44 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-29 14:08:04 +0000 |
commit | 55afd6dcee62b403ab888bb8a333c538a79041d3 (patch) | |
tree | 0926f4ef773d9a65b89e1d19b28beb186f54ba53 /src/gpu/vk | |
parent | 135db05fa114f0fc545c53f3047990c027cec9f6 (diff) |
Revert "Revert "Update GrBitmapTextureMaker for handling mipped requests""
This reverts commit 8b059bd946d9f14607f6d2e8b966267dd8e5a54d.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> Revert "Update GrBitmapTextureMaker for handling mipped requests"
>
> This reverts commit d1935c16e889b6707a522f711e79c75353caa343.
>
> Reason for revert: breaking lots of GMs, especially on gles
>
> Original change's description:
> > Update GrBitmapTextureMaker for handling mipped requests
> >
> > Specifically this updates the case when we are requesting to use mip
> > maps but there is already an unmipped version in the cache. Previously
> > we just grabbed the unmipped.
> >
> > Now we will create a new mipped resource. Upload the cpu data to all
> > the levels besides the base, copy the base level on GPU from the
> > original resource to the mipped one. Then the mipped resource will
> > take over the originals unique key.
> >
> > Bug: skia:
> > Change-Id: I38e9725c93280dc2460a0be8a7a229e7f20e1614
> > Reviewed-on: https://skia-review.googlesource.com/43840
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
>
> TBR=egdaniel@google.com,robertphillips@google.com,brianosman@google.com
>
> Change-Id: Id82e8b6e8ab69e46ff018bb07ae5d1f6ea8d7e76
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:
> Reviewed-on: https://skia-review.googlesource.com/52901
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,robertphillips@google.com,brianosman@google.com
Bug: skia:
Change-Id: Ie5b9553aa67def6f9c5a61f9b6b065b9fce3ff76
Reviewed-on: https://skia-review.googlesource.com/53240
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/gpu/vk')
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 6617318f26..e9adb4db67 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -661,10 +661,6 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, GrSurfaceOrigin texOrigin, memcpy(texelsShallowCopy.get(), texels, mipLevelCount*sizeof(GrMipLevel)); } - for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; ++currentMipLevel) { - SkASSERT(texelsShallowCopy[currentMipLevel].fPixels); - } - // Determine whether we need to flip when we copy into the buffer bool flipY = (kBottomLeft_GrSurfaceOrigin == texOrigin && mipLevelCount); @@ -673,6 +669,10 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, GrSurfaceOrigin texOrigin, size_t combinedBufferSize = width * bpp * height; int currentWidth = width; int currentHeight = height; + if (mipLevelCount > 0 && !texelsShallowCopy[0].fPixels) { + combinedBufferSize = 0; + } + // 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); @@ -681,13 +681,21 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, GrSurfaceOrigin texOrigin, currentWidth = SkTMax(1, currentWidth/2); currentHeight = SkTMax(1, currentHeight/2); - const size_t trimmedSize = currentWidth * bpp * currentHeight; - const size_t alignmentDiff = combinedBufferSize & alignmentMask; - if (alignmentDiff != 0) { - combinedBufferSize += alignmentMask - alignmentDiff + 1; + if (texelsShallowCopy[currentMipLevel].fPixels) { + 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; + } else { + individualMipOffsets.push_back(0); } - individualMipOffsets.push_back(combinedBufferSize); - combinedBufferSize += trimmedSize; + } + if (0 == combinedBufferSize) { + // We don't actually have any data to upload so just return success + return true; } // allocate buffer to hold our mip data @@ -704,35 +712,36 @@ bool GrVkGpu::uploadTexDataOptimal(GrVkTexture* tex, GrSurfaceOrigin texOrigin, currentHeight = height; int layerHeight = tex->height(); for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) { - SkASSERT(1 == mipLevelCount || currentHeight == layerHeight); - const size_t trimRowBytes = currentWidth * bpp; - const size_t rowBytes = texelsShallowCopy[currentMipLevel].fRowBytes ? - texelsShallowCopy[currentMipLevel].fRowBytes : - trimRowBytes; - - // copy data into the buffer, skipping the trailing bytes - char* dst = buffer + individualMipOffsets[currentMipLevel]; - const char* src = (const char*)texelsShallowCopy[currentMipLevel].fPixels; - if (flipY) { - src += (currentHeight - 1) * rowBytes; - for (int y = 0; y < currentHeight; y++) { - memcpy(dst, src, trimRowBytes); - src -= rowBytes; - dst += trimRowBytes; + if (texelsShallowCopy[currentMipLevel].fPixels) { + SkASSERT(1 == mipLevelCount || currentHeight == layerHeight); + const size_t trimRowBytes = currentWidth * bpp; + const size_t rowBytes = texelsShallowCopy[currentMipLevel].fRowBytes + ? texelsShallowCopy[currentMipLevel].fRowBytes + : trimRowBytes; + + // copy data into the buffer, skipping the trailing bytes + char* dst = buffer + individualMipOffsets[currentMipLevel]; + const char* src = (const char*)texelsShallowCopy[currentMipLevel].fPixels; + if (flipY) { + src += (currentHeight - 1) * rowBytes; + for (int y = 0; y < currentHeight; y++) { + memcpy(dst, src, trimRowBytes); + src -= rowBytes; + dst += trimRowBytes; + } + } else { + SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight); } - } else { - SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight); - } - - VkBufferImageCopy& region = regions.push_back(); - memset(®ion, 0, sizeof(VkBufferImageCopy)); - region.bufferOffset = transferBuffer->offset() + individualMipOffsets[currentMipLevel]; - region.bufferRowLength = currentWidth; - region.bufferImageHeight = currentHeight; - region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMipLevel), 0, 1 }; - region.imageOffset = { left, flipY ? layerHeight - top - currentHeight : top, 0 }; - region.imageExtent = { (uint32_t)currentWidth, (uint32_t)currentHeight, 1 }; + VkBufferImageCopy& region = regions.push_back(); + memset(®ion, 0, sizeof(VkBufferImageCopy)); + region.bufferOffset = transferBuffer->offset() + individualMipOffsets[currentMipLevel]; + region.bufferRowLength = currentWidth; + region.bufferImageHeight = currentHeight; + region.imageSubresource = { VK_IMAGE_ASPECT_COLOR_BIT, SkToU32(currentMipLevel), 0, 1 }; + 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; @@ -822,7 +831,6 @@ sk_sp<GrTexture> GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted } if (mipLevelCount) { - SkASSERT(texels[0].fPixels); if (!this->uploadTexDataOptimal(tex.get(), desc.fOrigin, 0, 0, desc.fWidth, desc.fHeight, desc.fConfig, texels, mipLevelCount)) { tex->unref(); |