Make Vulkan testing-only backend textures have optimal layout

Change-Id: I984a6a657417565c36687d32e41b5f7d9bbc39f8
Reviewed-on: https://skia-review.googlesource.com/112800
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2018-03-07 14:23:58 -05:00 committed by Skia Commit-Bot
parent 7578f3ecdd
commit de9f546a04

View File

@ -1191,7 +1191,6 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
return GrBackendTexture(); // invalid
}
bool linearTiling = false;
if (!fVkCaps->isConfigTexturable(config)) {
return GrBackendTexture(); // invalid
}
@ -1205,12 +1204,6 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
return GrBackendTexture(); // invalid
}
if (fVkCaps->isConfigTexturableLinearly(config) &&
(!isRenderTarget || fVkCaps->isConfigRenderableLinearly(config, false)) &&
GrMipMapped::kNo == mipMapped) {
linearTiling = true;
}
VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
usageFlags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
usageFlags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
@ -1220,11 +1213,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
VkImage image = VK_NULL_HANDLE;
GrVkAlloc alloc;
VkImageTiling imageTiling = linearTiling ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
VkImageLayout initialLayout = (VK_IMAGE_TILING_LINEAR == imageTiling)
? VK_IMAGE_LAYOUT_PREINITIALIZED
: VK_IMAGE_LAYOUT_UNDEFINED;
VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
// Create Image
VkSampleCountFlagBits vkSamples;
@ -1248,7 +1237,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
mipLevels, // mipLevels
1, // arrayLayers
vkSamples, // samples
imageTiling, // VkImageTiling
VK_IMAGE_TILING_OPTIMAL, // VkImageTiling
usageFlags, // VkImageUsageFlags
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode
0, // queueFamilyCount
@ -1258,7 +1247,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateImage(this->device(), &imageCreateInfo, nullptr, &image));
if (!GrVkMemory::AllocAndBindImageMemory(this, image, linearTiling, &alloc)) {
if (!GrVkMemory::AllocAndBindImageMemory(this, image, false, &alloc)) {
VK_CALL(DestroyImage(this->device(), image, nullptr));
return GrBackendTexture(); // invalid
}
@ -1295,26 +1284,6 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
SkASSERT(!err);
size_t bpp = GrBytesPerPixel(config);
size_t rowCopyBytes = bpp * w;
if (linearTiling) {
const VkImageSubresource subres = {
VK_IMAGE_ASPECT_COLOR_BIT,
0, // mipLevel
0, // arraySlice
};
VkSubresourceLayout layout;
VK_CALL(GetImageSubresourceLayout(fDevice, image, &subres, &layout));
if (!copy_testing_data(this, srcData, alloc, 0, rowCopyBytes,
static_cast<size_t>(layout.rowPitch), h)) {
GrVkMemory::FreeImageMemory(this, true, alloc);
VK_CALL(DestroyImage(fDevice, image, nullptr));
VK_CALL(EndCommandBuffer(cmdBuffer));
VK_CALL(FreeCommandBuffers(fDevice, fCmdPool, 1, &cmdBuffer));
return GrBackendTexture(); // invalid
}
} else {
SkASSERT(w && h);
SkTArray<size_t> individualMipOffsets(mipLevels);
@ -1359,8 +1328,8 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
return GrBackendTexture(); // invalid
}
if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer::kCopyRead_Type,
true, &bufferAlloc)) {
if (!GrVkMemory::AllocAndBindBufferMemory(this, buffer, GrVkBuffer::kCopyRead_Type, true,
&bufferAlloc)) {
GrVkMemory::FreeImageMemory(this, false, alloc);
VK_CALL(DestroyImage(fDevice, image, nullptr));
VK_CALL(DestroyBuffer(fDevice, buffer, nullptr));
@ -1375,8 +1344,8 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
SkASSERT(0 == currentMipLevel || !srcData);
size_t currentRowBytes = bpp * currentWidth;
size_t bufferOffset = individualMipOffsets[currentMipLevel];
if (!copy_testing_data(this, srcData, bufferAlloc, bufferOffset,
currentRowBytes, currentRowBytes, currentHeight)) {
if (!copy_testing_data(this, srcData, bufferAlloc, bufferOffset, currentRowBytes,
currentRowBytes, currentHeight)) {
GrVkMemory::FreeImageMemory(this, false, alloc);
VK_CALL(DestroyImage(fDevice, image, nullptr));
GrVkMemory::FreeBufferMemory(this, GrVkBuffer::kCopyRead_Type, bufferAlloc);
@ -1403,13 +1372,9 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
barrier.image = image;
barrier.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, mipLevels, 0, 1};
VK_CALL(CmdPipelineBarrier(cmdBuffer,
GrVkMemory::LayoutToPipelineStageFlags(initialLayout),
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0, nullptr,
0, nullptr,
1, &barrier));
VK_CALL(CmdPipelineBarrier(cmdBuffer, GrVkMemory::LayoutToPipelineStageFlags(initialLayout),
VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1,
&barrier));
initialLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
SkTArray<VkBufferImageCopy> regions(mipLevels);
@ -1432,10 +1397,9 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
VK_CALL(CmdCopyBufferToImage(cmdBuffer, buffer, image, initialLayout, regions.count(),
regions.begin()));
}
// Change Image layout to shader read since if we use this texture as a borrowed textures within
// Ganesh we require that its layout be set to that
VkImageMemoryBarrier barrier;
memset(&barrier, 0, sizeof(VkImageMemoryBarrier));
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.pNext = nullptr;
@ -1508,7 +1472,7 @@ GrBackendTexture GrVkGpu::createTestingOnlyBackendTexture(void* srcData, int w,
GrVkImageInfo info;
info.fImage = image;
info.fAlloc = alloc;
info.fImageTiling = imageTiling;
info.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
info.fImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
info.fFormat = pixelFormat;
info.fLevelCount = mipLevels;