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
|
|
|
|
|
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2017-06-22 16:52:46 +00:00
|
|
|
#if SK_SUPPORT_GPU && defined(SK_VULKAN)
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
#include "GrContextPriv.h"
|
2016-03-18 18:57:24 +00:00
|
|
|
#include "GrContextFactory.h"
|
2017-07-26 19:48:41 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2016-03-18 18:57:24 +00:00
|
|
|
#include "GrTest.h"
|
2017-06-13 16:44:56 +00:00
|
|
|
#include "GrTexture.h"
|
|
|
|
|
2016-03-18 18:57:24 +00:00
|
|
|
#include "Test.h"
|
|
|
|
#include "vk/GrVkCaps.h"
|
|
|
|
#include "vk/GrVkGpu.h"
|
|
|
|
#include "vk/GrVkMemory.h"
|
|
|
|
#include "vk/GrVkTypes.h"
|
|
|
|
|
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;
|
|
|
|
const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig;
|
|
|
|
|
|
|
|
void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
|
|
|
|
|
2018-01-22 15:48:15 +00:00
|
|
|
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu());
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
|
|
|
|
kPixelConfig, false,
|
|
|
|
GrMipMapped::kNo);
|
|
|
|
const GrVkImageInfo* imageInfo = origBackendTex.getVkImageInfo();
|
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
|
|
|
sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership);
|
2016-03-18 18:57:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
|
|
|
|
// image is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = *imageInfo;
|
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership);
|
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership);
|
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
|
|
|
// alloc is null
|
2017-12-12 18:01:25 +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);
|
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership);
|
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership);
|
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
|
|
|
}
|
|
|
|
|
2017-04-19 00:23:39 +00:00
|
|
|
// check adopt creation
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = *imageInfo;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
|
|
|
tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership);
|
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) {
|
2018-01-22 15:48:15 +00:00
|
|
|
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu());
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-03-14 17:32:12 +00:00
|
|
|
GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
|
|
|
|
kPixelConfig, true,
|
|
|
|
GrMipMapped::kNo);
|
|
|
|
const GrVkImageInfo* imageInfo = origBackendTex.getVkImageInfo();
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2018-03-14 17:32:12 +00:00
|
|
|
GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, *imageInfo);
|
2017-05-01 13:50:58 +00:00
|
|
|
|
2017-12-12 18:01:25 +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
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = *imageInfo;
|
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
2018-02-03 01:32:49 +00:00
|
|
|
GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
|
2017-12-12 18:01:25 +00:00
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
|
|
|
REPORTER_ASSERT(reporter, !rt);
|
|
|
|
}
|
2016-03-18 18:57:24 +00:00
|
|
|
|
|
|
|
// alloc is null
|
2017-12-12 18:01:25 +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);
|
2017-12-12 18:01:25 +00:00
|
|
|
rt = gpu->wrapBackendRenderTarget(backendRT);
|
|
|
|
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.
|
|
|
|
gpu->deleteTestingOnlyBackendTexture(origBackendTex);
|
2016-03-18 18:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
|
2018-01-22 15:48:15 +00:00
|
|
|
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu());
|
2016-03-18 18:57:24 +00:00
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
|
|
|
|
kPixelConfig, true,
|
|
|
|
GrMipMapped::kNo);
|
|
|
|
const GrVkImageInfo* imageInfo = origBackendTex.getVkImageInfo();
|
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
|
|
|
|
2018-02-03 01:32:49 +00:00
|
|
|
sk_sp<GrTexture> tex =
|
|
|
|
gpu->wrapRenderableBackendTexture(origBackendTex, 1, kBorrow_GrWrapOwnership);
|
2016-03-18 18:57:24 +00:00
|
|
|
REPORTER_ASSERT(reporter, tex);
|
|
|
|
|
|
|
|
// image is null
|
2017-12-12 18:01:25 +00:00
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = *imageInfo;
|
|
|
|
backendCopy.fImage = VK_NULL_HANDLE;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership);
|
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
|
|
|
{
|
|
|
|
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);
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership);
|
2017-12-12 18:01:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, !tex);
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership);
|
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
|
|
|
{
|
|
|
|
GrVkImageInfo backendCopy = *imageInfo;
|
|
|
|
GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
|
2018-02-03 01:32:49 +00:00
|
|
|
tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership);
|
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
|