skia2/tests/VkBackendSurfaceTest.cpp

188 lines
7.9 KiB
C++
Raw Normal View History

/*
* 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 "include/core/SkTypes.h"
#if defined(SK_VULKAN)
#include "include/core/SkImage.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/vk/GrVkTypes.h"
#include "include/gpu/vk/GrVkVulkan.h"
#include "src/gpu/GrRenderTargetContext.h"
Reland "Move GrGpuResource GrSurface and GrTexture into src." This reverts commit f6ed96d1c23b79130ca7344c984b07ef9d94fb7b. Reason for revert: google3 change landed Original change's description: > Revert "Move GrGpuResource GrSurface and GrTexture into src." > > This reverts commit e5a06ce678aad7640411f99f70f220f82ad49908. > > Reason for revert: Need to make change in google3 first > > Original change's description: > > Move GrGpuResource GrSurface and GrTexture into src. > > > > Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980 > > before this can land. > > > > Bug: skia:7966 > > Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com > > Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:7966 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com Change-Id: I746ce739cb084cefc46f9dab24ef773e7c3cc621 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7966 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275436 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 19:14:18 +00:00
#include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/SkGpuDevice.h"
#include "src/gpu/vk/GrVkGpu.h"
#include "src/gpu/vk/GrVkImageLayout.h"
#include "src/gpu/vk/GrVkTexture.h"
#include "src/image/SkImage_Base.h"
#include "src/image/SkImage_GpuBase.h"
#include "src/image/SkSurface_Gpu.h"
#include "tests/Test.h"
#include "tools/gpu/ManagedBackendTexture.h"
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
auto dContext = ctxInfo.directContext();
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;
}
GrVkImageInfo info;
REPORTER_ASSERT(reporter, mbet->texture().getVkImageInfo(&info));
VkImageLayout initLayout = info.fImageLayout;
// Verify that setting that layout via a copy of a backendTexture is reflected in all the
// backendTextures.
GrBackendTexture backendTex1 = mbet->texture();
GrBackendTexture backendTex2 = backendTex1;
REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
backendTex2.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
REPORTER_ASSERT(reporter, backendTex2.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
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());
REPORTER_ASSERT(reporter, wrappedImage.get());
Reland "Migrate SkImage::MakeFromTexture to GrRecordingContext" This reverts commit 74b83a4ea9e31dbdc1996a1ed2d1844d5cdbe9b7. Reason for revert: Flutter is updated Original change's description: > Revert "Migrate SkImage::MakeFromTexture to GrRecordingContext" > > This reverts commit daa9e7455d4f0f54dc07f405becba5d0c5964847. > > Reason for revert: Broke Build-Debian9-Clang-arm-Release-Flutter_Android_Docker > > Original change's description: > > Migrate SkImage::MakeFromTexture to GrRecordingContext > > > > Android migration landed in Android CL 12234077 > > Chrome migration is landing in Chrome CL 2335812 > > > > Note: makeFromCompressedTexture is not used by Chrome. > > > > Bug: skia:104662 > > Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Auto-Submit: Adlai Holler <adlai@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: I570945521c6cd78dfeea81e492b7e2b31dd0e6f5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:104662 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308505 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:104662 Change-Id: Ie1d7fd9e597e6e6e5bd91bec086e83a8c1f45a37 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309321 Reviewed-by: Adlai Holler <adlai@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
2020-08-11 15:48:49 +00:00
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
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());
vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
REPORTER_ASSERT(reporter, backendTex1.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, backendTex1.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
REPORTER_ASSERT(reporter, backendTex2.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(backendTex1, backendTex2));
GrBackendTexture invalidTexture;
REPORTER_ASSERT(reporter, !invalidTexture.isValid());
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
backendTex2 = invalidTexture;
REPORTER_ASSERT(reporter, !backendTex2.isValid());
REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
invalidTexture = backendTex1;
REPORTER_ASSERT(reporter, invalidTexture.isValid());
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex1));
invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
REPORTER_ASSERT(reporter, invalidTexture.isValid());
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
}
// 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
// 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) {
auto dContext = ctxInfo.directContext();
GrGpu* gpu = dContext->priv().getGpu();
GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
if (!vkGpu->vkCaps().supportsExternalMemory()) {
return;
}
GrBackendTexture backendTex = dContext->createBackendTexture(
1, 1, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo);
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());
image = SkImage::MakeFromTexture(dContext, vkExtTex, kTopLeft_GrSurfaceOrigin,
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.
vkTex->setImageLayout(vkGpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0,
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));
REPORTER_ASSERT(reporter, newVkInfo.fCurrentQueueFamily == vkGpu->queueIndex());
image.reset();
gpu->testingOnly_flushGpuAndSync();
dContext->deleteBackendTexture(backendTex);
}
#endif
#endif