54bfb18dad
This should allow clients to include Skia and their vulkan files in any order. However, it does require that when clients are building their files that include skia with vulkan, they must have vulkan/vulkan_core.h on their include path somewhere. Bug: skia: Change-Id: I969db396c92127be7c8df754926d175f38b8aafa Reviewed-on: https://skia-review.googlesource.com/c/172147 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
124 lines
5.3 KiB
C++
124 lines
5.3 KiB
C++
/*
|
|
* 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
|
|
|
|
#include "SkTypes.h"
|
|
|
|
#if defined(SK_VULKAN)
|
|
|
|
#include "vk/GrVkVulkan.h"
|
|
|
|
#include "Test.h"
|
|
|
|
#include "GrBackendSurface.h"
|
|
#include "GrContextPriv.h"
|
|
#include "GrTextureProxy.h"
|
|
#include "GrTexture.h"
|
|
#include "SkImage.h"
|
|
#include "SkImage_Base.h"
|
|
#include "vk/GrVkGpu.h"
|
|
#include "vk/GrVkImageLayout.h"
|
|
#include "vk/GrVkTexture.h"
|
|
#include "vk/GrVkTypes.h"
|
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
|
|
GrContext* context = ctxInfo.grContext();
|
|
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu());
|
|
|
|
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(nullptr, 1, 1,
|
|
GrColorType::kRGBA_8888,
|
|
false,
|
|
GrMipMapped::kNo);
|
|
REPORTER_ASSERT(reporter, backendTex.isValid());
|
|
|
|
GrVkImageInfo info;
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
VkImageLayout initLayout = info.fImageLayout;
|
|
|
|
// Verify that setting that layout 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);
|
|
|
|
backendTexCopy.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
|
|
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
|
|
|
|
// Setting back the layout since we didn't actually change it
|
|
backendTex.setVkImageLayout(initLayout);
|
|
|
|
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(context, backendTex,
|
|
kTopLeft_GrSurfaceOrigin,
|
|
kRGBA_8888_SkColorType,
|
|
kPremul_SkAlphaType, nullptr);
|
|
REPORTER_ASSERT(reporter, wrappedImage.get());
|
|
|
|
sk_sp<GrTextureProxy> texProxy = as_IB(wrappedImage)->asTextureProxyRef();
|
|
REPORTER_ASSERT(reporter, texProxy.get());
|
|
REPORTER_ASSERT(reporter, texProxy->isInstantiated());
|
|
GrTexture* texture = texProxy->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());
|
|
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);
|
|
|
|
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);
|
|
|
|
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
|
|
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
|
|
|
|
REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info));
|
|
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.
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy));
|
|
|
|
GrBackendTexture invalidTexture;
|
|
REPORTER_ASSERT(reporter, !invalidTexture.isValid());
|
|
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
|
|
|
|
backendTexCopy = invalidTexture;
|
|
REPORTER_ASSERT(reporter, !backendTexCopy.isValid());
|
|
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy));
|
|
|
|
invalidTexture = backendTex;
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex));
|
|
|
|
invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
|
|
REPORTER_ASSERT(reporter, invalidTexture.isValid());
|
|
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
|
|
|
|
gpu->deleteTestingOnlyBackendTexture(backendTex);
|
|
}
|
|
|
|
#endif
|