2020-05-29 16:11:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-05-29 16:11:05 +00:00
|
|
|
#include "include/gpu/vk/GrVkTypes.h"
|
2020-06-09 21:29:32 +00:00
|
|
|
#include "src/gpu/GrContextPriv.h"
|
2020-05-29 16:11:05 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
|
|
|
#include "src/image/SkImage_Base.h"
|
|
|
|
#include "tests/Test.h"
|
|
|
|
|
|
|
|
#ifdef SK_VULKAN
|
2020-06-09 21:29:32 +00:00
|
|
|
#include "src/gpu/vk/GrVkGpu.h"
|
2020-05-29 16:11:05 +00:00
|
|
|
#include "src/gpu/vk/GrVkTexture.h"
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxInfo) {
|
2020-08-11 15:48:49 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2020-05-29 16:11:05 +00:00
|
|
|
|
|
|
|
GrBackendFormat format = GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
|
2020-08-11 15:48:49 +00:00
|
|
|
GrBackendTexture backendTex = dContext->createBackendTexture(
|
2020-07-21 13:27:25 +00:00
|
|
|
32, 32, format, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
|
2020-05-29 16:11:05 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
|
|
|
|
|
|
|
GrVkImageInfo info;
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
VkImageLayout initLayout = info.fImageLayout;
|
|
|
|
uint32_t initQueue = info.fCurrentQueueFamily;
|
|
|
|
GrBackendSurfaceMutableState initState(initLayout, initQueue);
|
|
|
|
|
|
|
|
// Verify that setting that state via a copy of a backendTexture is reflected in all the
|
|
|
|
// backendTextures.
|
|
|
|
GrBackendTexture backendTexCopy = backendTex;
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
GrBackendSurfaceMutableState newState(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
VK_QUEUE_FAMILY_IGNORED);
|
|
|
|
backendTexCopy.setMutableState(newState);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_IGNORED == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_IGNORED == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
// Setting back to the init state since we didn't actually change it
|
|
|
|
backendTex.setMutableState(initState);
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(dContext, backendTex,
|
2020-05-29 16:11:05 +00:00
|
|
|
kTopLeft_GrSurfaceOrigin,
|
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType, nullptr);
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
|
2020-05-29 16:11:05 +00:00
|
|
|
REPORTER_ASSERT(reporter, view);
|
|
|
|
REPORTER_ASSERT(reporter, view->proxy()->isInstantiated());
|
|
|
|
GrTexture* texture = view->proxy()->peekTexture();
|
|
|
|
REPORTER_ASSERT(reporter, texture);
|
|
|
|
|
|
|
|
// Verify that modifying the layout via the GrVkTexture is reflected in the GrBackendTexture
|
|
|
|
GrVkTexture* vkTexture = static_cast<GrVkTexture*>(texture);
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout());
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == vkTexture->currentQueueFamilyIndex());
|
|
|
|
vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false);
|
|
|
|
REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
// Verify that modifying the layout via the GrBackendTexutre is reflected in the GrVkTexture
|
|
|
|
backendTexImage.setMutableState(newState);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == vkTexture->currentLayout());
|
|
|
|
REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_IGNORED == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
vkTexture->setQueueFamilyIndex(initQueue);
|
|
|
|
vkTexture->updateImageLayout(initLayout);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
|
|
|
|
|
2020-06-09 21:29:32 +00:00
|
|
|
// Test using the setBackendTextureStateAPI. Unlike the previous test this will actually add
|
|
|
|
// real transitions to the image so we need to be careful about doing actual valid transitions.
|
2020-08-11 15:48:49 +00:00
|
|
|
GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
|
2020-06-09 21:29:32 +00:00
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
GrBackendSurfaceMutableState previousState;
|
|
|
|
|
|
|
|
dContext->setBackendTextureState(backendTex, newState, &previousState);
|
2020-06-09 21:29:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, previousState.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, previousState.backend() == GrBackendApi::kVulkan);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getVkImageLayout() == initLayout);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getQueueFamilyIndex() == initQueue);
|
|
|
|
|
2020-09-21 20:02:21 +00:00
|
|
|
// Make sure passing in VK_IMAGE_LAYOUT_UNDEFINED does not change the layout
|
|
|
|
GrBackendSurfaceMutableState noopState(VK_IMAGE_LAYOUT_UNDEFINED, VK_QUEUE_FAMILY_IGNORED);
|
2020-09-23 18:23:36 +00:00
|
|
|
dContext->setBackendTextureState(backendTex, noopState, &previousState);
|
2020-09-21 20:02:21 +00:00
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, previousState.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, previousState.backend() == GrBackendApi::kVulkan);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
previousState.getVkImageLayout() == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getQueueFamilyIndex() == gpu->queueIndex());
|
|
|
|
|
2020-06-09 21:29:32 +00:00
|
|
|
// To test queue transitions, we don't have any other valid queue available so instead we try
|
|
|
|
// to transition to external queue.
|
|
|
|
if (gpu->vkCaps().supportsExternalMemory()) {
|
|
|
|
GrBackendSurfaceMutableState externalState(VK_IMAGE_LAYOUT_GENERAL,
|
|
|
|
VK_QUEUE_FAMILY_EXTERNAL);
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
dContext->setBackendTextureState(backendTex, externalState, &previousState);
|
2020-06-09 21:29:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_GENERAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_EXTERNAL == info.fCurrentQueueFamily);
|
|
|
|
|
2020-09-23 18:23:36 +00:00
|
|
|
REPORTER_ASSERT(reporter, previousState.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, previousState.backend() == GrBackendApi::kVulkan);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
previousState.getVkImageLayout() == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getQueueFamilyIndex() == gpu->queueIndex());
|
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->submit();
|
2020-06-09 21:29:32 +00:00
|
|
|
|
2020-09-21 20:02:21 +00:00
|
|
|
// Go back to the initial queue. Also we should stay in VK_IMAGE_LAYOUT_GENERAL since we
|
|
|
|
// are passing in VK_IMAGE_LAYOUT_UNDEFINED
|
|
|
|
GrBackendSurfaceMutableState externalState2(VK_IMAGE_LAYOUT_UNDEFINED, initQueue);
|
2020-09-23 18:23:36 +00:00
|
|
|
dContext->setBackendTextureState(backendTex, externalState2, &previousState);
|
2020-06-09 21:29:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_GENERAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
|
2020-09-23 18:23:36 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, previousState.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, previousState.backend() == GrBackendApi::kVulkan);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getVkImageLayout() == VK_IMAGE_LAYOUT_GENERAL);
|
|
|
|
REPORTER_ASSERT(reporter, previousState.getQueueFamilyIndex() == VK_QUEUE_FAMILY_EXTERNAL);
|
2020-06-09 21:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We must submit this work before we try to delete the backend texture.
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->submit(true);
|
2020-06-09 21:29:32 +00:00
|
|
|
|
2020-08-11 15:48:49 +00:00
|
|
|
dContext->deleteBackendTexture(backendTex);
|
2020-05-29 16:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|