From dddf709101fe3feb7a362805da5b2100e479339c Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Wed, 6 May 2020 11:52:37 -0400 Subject: [PATCH] When creating with data, always set vk GrBackendTexture layout to sampled. We won't lose much by not going to color attachment layout since when the renderable GrBackendTexture gets wrapped in an SkSurface we still will put in a barrier to protect from write after write. The barrier will now just also include a layout change. Change-Id: I91cddd0a4de415760c3e7e4382c243946f788301 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/288136 Commit-Queue: Greg Daniel Reviewed-by: Robert Phillips Reviewed-by: Brian Salomon --- include/gpu/GrContext.h | 10 ++++------ src/gpu/vk/GrVkGpu.cpp | 9 +-------- tests/BackendAllocationTest.cpp | 14 +++----------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 4019092e23..bc664ee974 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -467,8 +467,7 @@ public: * client can assume the upload work has been submitted to the gpu. The finishedProc will always * get called even if we failed to create the GrBackendTexture. * For the Vulkan backend the layout of the created VkImage will be: - * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if renderable is kNo - * and VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL if renderable is kYes + * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL */ GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat&, @@ -488,8 +487,7 @@ public: * If successful, the created backend texture will be compatible with the provided * SkColorType. * For the Vulkan backend the layout of the created VkImage will be: - * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if renderable is kNo - * and VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL if renderable is kYes + * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL */ GrBackendTexture createBackendTexture(int width, int height, SkColorType, @@ -508,7 +506,8 @@ public: * the upload work has been submitted to the gpu. The finishedProc will always get called even * if we failed to create the GrBackendTexture. * For the Vulkan backend the layout of the created VkImage will be: - * VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL + * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL if texturaeble + * VK_IMAGE_LAYOUT_UNDEFINED if not textureable */ GrBackendTexture createBackendTexture(const SkSurfaceCharacterization& characterization, const SkColor4f& color, @@ -531,7 +530,6 @@ public: * Note: the pixmap's alphatypes and colorspaces are ignored. * For the Vulkan backend the layout of the created VkImage will be: * VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL - * regardless of the renderability setting */ GrBackendTexture createBackendTexture(const SkPixmap srcData[], int numLevels, GrRenderable, GrProtected, diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index b82bf9b504..41a1b99170 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1705,14 +1705,7 @@ bool GrVkGpu::createVkImageForBackendSurface(VkFormat vkFormat, regions.count(), regions.begin()); } - if (data->type() == BackendTextureData::Type::kColor && renderable == GrRenderable::kYes) { - // Change image layout to color-attachment-optimal since if we use this texture as a - // borrowed texture within Ganesh we are probably going to render to it - VkAccessFlags access = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | - VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - image->setImageLayout(this, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, access, - VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, false); - } else if (texturable == GrTexturable::kYes) { + if (texturable == GrTexturable::kYes) { // Change image layout to shader read since if we use this texture as a borrowed // texture within Ganesh we require that its layout be set to that image->setImageLayout(this, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp index cd7d4191ca..fb7a21195f 100644 --- a/tests/BackendAllocationTest.cpp +++ b/tests/BackendAllocationTest.cpp @@ -483,7 +483,6 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter, enum class VkLayout { kUndefined, kReadOnlyOptimal, - kColorAttachmentOptimal }; void check_vk_layout(const GrBackendTexture& backendTex, VkLayout layout) { @@ -497,9 +496,6 @@ void check_vk_layout(const GrBackendTexture& backendTex, VkLayout layout) { case VkLayout::kReadOnlyOptimal: expected = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; break; - case VkLayout::kColorAttachmentOptimal: - expected = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - break; default: SkUNREACHABLE; } @@ -582,7 +578,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CharacterizationBackendAllocationTest, report SkColors::kRed, mark_signaled, &finished); - check_vk_layout(backendTex, VkLayout::kColorAttachmentOptimal); + check_vk_layout(backendTex, VkLayout::kReadOnlyOptimal); REPORTER_ASSERT(reporter, backendTex.isValid()); REPORTER_ASSERT(reporter, c.isCompatible(backendTex)); @@ -712,9 +708,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx GrProtected::kNo, mark_signaled, finishedPtr); - check_vk_layout(result, GrRenderable::kYes == renderable - ? VkLayout::kColorAttachmentOptimal - : VkLayout::kReadOnlyOptimal); + check_vk_layout(result, VkLayout::kReadOnlyOptimal); #ifdef SK_DEBUG { @@ -1066,9 +1060,7 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) { GrProtected::kNo, mark_signaled, finishedPtr); - check_vk_layout(beTex, GrRenderable::kYes == renderable - ? VkLayout::kColorAttachmentOptimal - : VkLayout::kReadOnlyOptimal); + check_vk_layout(beTex, VkLayout::kReadOnlyOptimal); return beTex; }; test_color_init(context, reporter, createWithColorMtd,