2016-03-18 18:57:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 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"
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-05-31 18:27:17 +00:00
|
|
|
#if defined(SK_VULKAN)
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "include/gpu/vk/GrVkTypes.h"
|
|
|
|
#include "include/gpu/vk/GrVkVulkan.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-08-14 21:00:30 +00:00
|
|
|
#include "src/gpu/GrRenderTarget.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/vk/GrVkCaps.h"
|
|
|
|
#include "src/gpu/vk/GrVkGpu.h"
|
|
|
|
#include "src/gpu/vk/GrVkMemory.h"
|
|
|
|
#include "tests/Test.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2016-03-31 15:08:20 +00:00
|
|
|
using sk_gpu_test::GrContextFactory;
|
|
|
|
|
2016-03-18 18:57:24 +00:00
|
|
|
const int kW = 1024;
|
|
|
|
const int kH = 1024;
|
2019-05-13 14:40:06 +00:00
|
|
|
const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-07-20 19:00:36 +00:00
|
|
|
void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
|
2020-10-12 21:30:00 +00:00
|
|
|
GrGpu* gpu = dContext->priv().getGpu();
|
2020-10-12 18:45:12 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
|
|
|
|
dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo);
|
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not create backend texture.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrBackendTexture origBackendTex = mbet->texture();
|
2020-05-06 15:40:03 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo imageInfo;
|
|
|
|
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
{
|
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
|
|
|
// image is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
2017-12-12 18:01:25 +00:00
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(
|
|
|
|
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
2020-10-13 00:45:06 +00:00
|
|
|
tex = gpu->wrapBackendTexture(
|
|
|
|
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
|
|
|
// alloc is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
2018-02-26 18:29:37 +00:00
|
|
|
backendCopy.fAlloc = GrVkAlloc();
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(
|
|
|
|
backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
|
2019-07-11 18:07:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
2020-10-13 00:45:06 +00:00
|
|
|
tex = gpu->wrapBackendTexture(
|
|
|
|
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
|
|
|
|
2017-04-19 00:23:39 +00:00
|
|
|
// check adopt creation
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(
|
|
|
|
backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType);
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
2020-10-13 00:45:06 +00:00
|
|
|
if (tex) {
|
|
|
|
mbet->wasAdopted();
|
|
|
|
}
|
2020-09-28 21:02:49 +00:00
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 19:00:36 +00:00
|
|
|
void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
|
|
|
|
GrGpu* gpu = dContext->priv().getGpu();
|
2020-10-13 00:45:06 +00:00
|
|
|
GrColorType ct = SkColorTypeToGrColorType(kColorType);
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
for (int sampleCnt : {1, 4}) {
|
|
|
|
GrBackendFormat format = gpu->caps()->getDefaultBackendFormat(ct, GrRenderable::kYes);
|
|
|
|
if (sampleCnt > gpu->caps()->maxRenderTargetSampleCount(format)) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
GrBackendRenderTarget origBackendRT =
|
|
|
|
gpu->createTestingOnlyBackendRenderTarget({kW, kH}, ct, sampleCnt);
|
|
|
|
if (!origBackendRT.isValid()) {
|
|
|
|
ERRORF(reporter, "Could not create backend render target.");
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
GrVkImageInfo imageInfo;
|
|
|
|
REPORTER_ASSERT(reporter, origBackendRT.getVkImageInfo(&imageInfo));
|
2020-10-12 16:19:39 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
|
2020-10-12 21:30:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt);
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
// image is null
|
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
|
|
|
GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy);
|
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
|
|
|
REPORTER_ASSERT(reporter, !rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// alloc is null
|
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
|
|
|
backendCopy.fAlloc = GrVkAlloc();
|
|
|
|
// can wrap null alloc
|
|
|
|
GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy);
|
2020-10-06 14:07:38 +00:00
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
|
|
|
REPORTER_ASSERT(reporter, rt);
|
|
|
|
}
|
2020-10-12 21:30:00 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
gpu->deleteTestingOnlyBackendRenderTarget(origBackendRT);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 19:00:36 +00:00
|
|
|
void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
|
|
|
|
GrGpu* gpu = dContext->priv().getGpu();
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
|
|
|
|
dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kYes);
|
|
|
|
if (!mbet) {
|
|
|
|
ERRORF(reporter, "Could not create renderable backend texture.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GrBackendTexture origBackendTex = mbet->texture();
|
2020-05-06 15:40:03 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo imageInfo;
|
|
|
|
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
|
Revert "Revert "Plumb GrBackendTexture throughout skia.""
This reverts commit 7fa5c31c2c9af834bee66d5fcf476e250076c8d6.
Reason for revert: Relanding this change now that other fixes have landed.
Original change's description:
> Revert "Plumb GrBackendTexture throughout skia."
>
> This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12.
>
> Reason for revert: fix android roll
>
> Original change's description:
> > Plumb GrBackendTexture throughout skia.
> >
> > Bug: skia:
> > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875
> > Reviewed-on: https://skia-review.googlesource.com/13645
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> >
>
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89
> Reviewed-on: https://skia-review.googlesource.com/13773
> Reviewed-by: Stan Iliev <stani@google.com>
> Commit-Queue: Stan Iliev <stani@google.com>
>
TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org,brianosman@google.com,stani@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I92bc074e4fe37fa5c83186afadc472c03802e8f2
Reviewed-on: https://skia-review.googlesource.com/13975
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2017-04-20 16:41:55 +00:00
|
|
|
|
2019-01-24 21:03:07 +00:00
|
|
|
sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(
|
2020-03-27 14:42:15 +00:00
|
|
|
origBackendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
|
2016-03-18 18:57:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
|
|
|
|
// image is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
2017-12-12 18:01:25 +00:00
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2020-03-27 14:42:15 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
2020-03-27 14:42:15 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
|
|
|
// alloc is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
2018-02-26 18:29:37 +00:00
|
|
|
backendCopy.fAlloc = GrVkAlloc();
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2020-03-27 14:42:15 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2019-07-11 18:07:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
2020-03-27 14:42:15 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2020-09-28 21:02:49 +00:00
|
|
|
// check rendering with MSAA
|
|
|
|
{
|
|
|
|
int maxSamples = dContext->priv().caps()->maxRenderTargetSampleCount(
|
|
|
|
origBackendTex.getBackendFormat());
|
|
|
|
bool shouldSucceed = maxSamples > 1;
|
|
|
|
tex = gpu->wrapRenderableBackendTexture(origBackendTex, 2, kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
|
|
|
REPORTER_ASSERT(reporter, SkToBool(tex) == shouldSucceed);
|
|
|
|
}
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
// check adopt creation
|
2020-09-28 21:02:49 +00:00
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = imageInfo;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo);
|
2020-10-13 00:45:06 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
if (tex) {
|
|
|
|
mbet->wasAdopted();
|
|
|
|
}
|
2020-09-28 21:02:49 +00:00
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 21:21:33 +00:00
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) {
|
2020-07-20 19:00:36 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2020-07-06 14:56:46 +00:00
|
|
|
|
2020-07-20 19:00:36 +00:00
|
|
|
wrap_tex_test(reporter, dContext);
|
|
|
|
wrap_rt_test(reporter, dContext);
|
|
|
|
wrap_trt_test(reporter, dContext);
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|