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/vk/GrVkVulkan.h"
|
2018-11-20 22:12:36 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "src/gpu/GrContextPriv.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 "tools/gpu/GrContextFactory.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/vk/GrVkTypes.h"
|
|
|
|
#include "src/gpu/vk/GrVkCaps.h"
|
|
|
|
#include "src/gpu/vk/GrVkGpu.h"
|
|
|
|
#include "src/gpu/vk/GrVkMemory.h"
|
|
|
|
#include "tests/Test.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
|
|
|
|
|
|
|
void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
|
|
|
|
kColorType,
|
|
|
|
SkColors::kTransparent,
|
|
|
|
GrMipMapped::kNo,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
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-03-27 14:42:15 +00:00
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, kRead_GrIOType);
|
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->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
|
|
|
|
kRead_GrIOType);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
2020-03-27 14:42:15 +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-03-27 14:42:15 +00:00
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
|
|
|
|
kRead_GrIOType);
|
2019-07-11 18:07:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
2020-03-27 14:42:15 +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-03-27 14:42:15 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
|
2019-05-13 14:40:06 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
|
|
|
|
kColorType,
|
|
|
|
SkColors::kTransparent,
|
|
|
|
GrMipMapped::kNo,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrRenderable::kYes,
|
|
|
|
GrProtected::kNo);
|
2018-07-03 20:18:29 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
GrVkImageInfo imageInfo;
|
|
|
|
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-04-10 13:34:07 +00:00
|
|
|
GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo);
|
2017-05-01 13:50:58 +00:00
|
|
|
|
2020-03-27 14:42:15 +00:00
|
|
|
sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
|
2016-03-18 18:57:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt);
|
|
|
|
|
|
|
|
// 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;
|
2018-02-03 01:32:49 +00:00
|
|
|
GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
|
2020-03-27 14:42:15 +00:00
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !rt);
|
|
|
|
}
|
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
|
|
|
// can wrap null alloc
|
2018-02-03 01:32:49 +00:00
|
|
|
GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
|
2020-03-27 14:42:15 +00:00
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, rt);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-03-14 17:32:12 +00:00
|
|
|
// When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the
|
|
|
|
// resource when we're done.
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(origBackendTex);
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
|
2019-05-13 14:40:06 +00:00
|
|
|
GrGpu* gpu = context->priv().getGpu();
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2019-06-04 15:03:06 +00:00
|
|
|
GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
|
|
|
|
kColorType,
|
|
|
|
SkColors::kTransparent,
|
|
|
|
GrMipMapped::kNo,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrRenderable::kYes,
|
|
|
|
GrProtected::kNo);
|
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
|
|
|
|
|
|
|
// 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-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
|
|
|
}
|
|
|
|
|
2016-04-11 21:21:33 +00:00
|
|
|
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) {
|
2016-05-11 13:33:06 +00:00
|
|
|
wrap_tex_test(reporter, ctxInfo.grContext());
|
|
|
|
wrap_rt_test(reporter, ctxInfo.grContext());
|
|
|
|
wrap_trt_test(reporter, ctxInfo.grContext());
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|