2018-04-10 13:34:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test. It relies on static intializers to work
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2018-05-31 18:27:17 +00:00
|
|
|
#if defined(SK_VULKAN)
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/vk/GrVkTypes.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "include/gpu/vk/GrVkVulkan.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/vk/GrVkGpu.h"
|
|
|
|
#include "src/gpu/vk/GrVkImageLayout.h"
|
|
|
|
#include "src/gpu/vk/GrVkTexture.h"
|
|
|
|
#include "src/image/SkImage_Base.h"
|
2020-03-06 18:07:10 +00:00
|
|
|
#include "src/image/SkImage_GpuBase.h"
|
2019-05-09 18:04:20 +00:00
|
|
|
#include "src/image/SkSurface_Gpu.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2021-02-23 15:45:39 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2018-04-10 13:34:07 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
|
|
|
|
dContext, 1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo);
|
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not create backend texture.");
|
|
|
|
return;
|
|
|
|
}
|
2018-04-10 13:34:07 +00:00
|
|
|
|
|
|
|
GrVkImageInfo info;
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, mbet->texture().getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
VkImageLayout initLayout = info.fImageLayout;
|
|
|
|
|
|
|
|
// Verify that setting that layout via a copy of a backendTexture is reflected in all the
|
|
|
|
// backendTextures.
|
2020-10-13 00:45:06 +00:00
|
|
|
GrBackendTexture backendTex1 = mbet->texture();
|
|
|
|
GrBackendTexture backendTex2 = backendTex1;
|
|
|
|
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
backendTex2.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
|
|
|
|
// Setting back the layout since we didn't actually change it
|
2020-10-13 00:45:06 +00:00
|
|
|
backendTex1.setVkImageLayout(initLayout);
|
|
|
|
|
|
|
|
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(
|
|
|
|
dContext,
|
|
|
|
backendTex1,
|
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
/*color space*/ nullptr,
|
|
|
|
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, wrappedImage.get());
|
|
|
|
|
2021-02-23 15:45:39 +00:00
|
|
|
GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
|
2021-02-03 15:15:31 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
REPORTER_ASSERT(reporter, proxy->isInstantiated());
|
|
|
|
GrTexture* texture = proxy->peekTexture();
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
|
|
|
|
// Verify that modifying the layout via the GrVkTexture is reflected in the GrBackendTexture
|
2021-03-12 21:29:40 +00:00
|
|
|
GrVkAttachment* vkTexture = static_cast<GrVkTexture*>(texture)->textureAttachment();
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout());
|
|
|
|
vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout);
|
|
|
|
|
|
|
|
GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false);
|
|
|
|
REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout);
|
|
|
|
|
|
|
|
// Verify that modifying the layout via the GrBackendTexutre is reflected in the GrVkTexture
|
|
|
|
backendTexImage.setVkImageLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL == vkTexture->currentLayout());
|
|
|
|
|
|
|
|
vkTexture->updateImageLayout(initLayout);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info));
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
|
|
|
|
// Check that we can do things like assigning the backend texture to invalid one, assign an
|
|
|
|
// invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of
|
|
|
|
// our ref counting asserts.
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex1, backendTex2));
|
2018-04-10 13:34:07 +00:00
|
|
|
|
|
|
|
GrBackendTexture invalidTexture;
|
|
|
|
REPORTER_ASSERT(reporter, !invalidTexture.isValid());
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
backendTex2 = invalidTexture;
|
|
|
|
REPORTER_ASSERT(reporter, !backendTex2.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
invalidTexture = backendTex1;
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex1));
|
2018-04-10 13:34:07 +00:00
|
|
|
|
2018-04-24 20:29:16 +00:00
|
|
|
invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
|
2018-04-10 13:34:07 +00:00
|
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
|
|
|
|
}
|
|
|
|
|
2019-06-26 17:48:12 +00:00
|
|
|
// This test is disabled because it executes illegal vulkan calls which cause the validations layers
|
|
|
|
// to fail and makes us assert. Once fixed to use a valid vulkan call sequence it should be
|
|
|
|
// renenabled, see skbug.com/8936.
|
|
|
|
#if 0
|
2019-03-23 00:46:55 +00:00
|
|
|
// Test to make sure we transition from the EXTERNAL queue even when no layout transition is needed.
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkTransitionExternalQueueTest, reporter, ctxInfo) {
|
2020-07-23 13:41:57 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
GrGpu* gpu = dContext->priv().getGpu();
|
2019-05-13 14:40:06 +00:00
|
|
|
GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
|
|
|
|
if (!vkGpu->vkCaps().supportsExternalMemory()) {
|
2019-03-23 00:46:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-23 13:41:57 +00:00
|
|
|
GrBackendTexture backendTex = dContext->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
1, 1, kRGBA_8888_SkColorType,
|
2020-07-21 13:27:25 +00:00
|
|
|
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo);
|
2019-03-23 00:46:55 +00:00
|
|
|
sk_sp<SkImage> image;
|
|
|
|
// Make a backend texture with an external queue family and general layout.
|
|
|
|
GrVkImageInfo vkInfo;
|
|
|
|
if (!backendTex.getVkImageInfo(&vkInfo)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vkInfo.fCurrentQueueFamily = VK_QUEUE_FAMILY_EXTERNAL;
|
|
|
|
// Use a read-only layout as these are the ones where we can otherwise skip a transition.
|
|
|
|
vkInfo.fImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
|
|
|
|
GrBackendTexture vkExtTex(1, 1, vkInfo);
|
|
|
|
REPORTER_ASSERT(reporter, vkExtTex.isValid());
|
2020-07-23 13:41:57 +00:00
|
|
|
image = SkImage::MakeFromTexture(dContext, vkExtTex, kTopLeft_GrSurfaceOrigin,
|
2019-03-23 00:46:55 +00:00
|
|
|
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
if (!image) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrTexture* texture = image->getTexture();
|
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
GrVkTexture* vkTex = static_cast<GrVkTexture*>(texture);
|
|
|
|
|
|
|
|
// Change our backend texture to the internal queue, with the same layout. This should force a
|
|
|
|
// queue transition even though the layouts match.
|
2019-05-13 14:40:06 +00:00
|
|
|
vkTex->setImageLayout(vkGpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0,
|
2019-03-23 00:46:55 +00:00
|
|
|
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, false, false);
|
|
|
|
|
|
|
|
// Get our image info again and make sure we transitioned queues.
|
|
|
|
GrBackendTexture newBackendTexture = image->getBackendTexture(true);
|
|
|
|
GrVkImageInfo newVkInfo;
|
|
|
|
REPORTER_ASSERT(reporter, newBackendTexture.getVkImageInfo(&newVkInfo));
|
2019-05-13 14:40:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex());
|
2019-03-23 00:46:55 +00:00
|
|
|
|
|
|
|
image.reset();
|
2021-02-12 17:10:43 +00:00
|
|
|
dContext->submit(true);
|
2020-07-23 13:41:57 +00:00
|
|
|
dContext->deleteBackendTexture(backendTex);
|
2019-03-23 00:46:55 +00:00
|
|
|
}
|
2019-06-26 17:48:12 +00:00
|
|
|
#endif
|
2019-03-23 00:46:55 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
#endif
|