blob: ead96d88253d0b5a73d990f36daa86b6d565d351 [file] [log] [blame]
jvanverthfd359ca2016-03-18 11:57:24 -07001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This is a GPU-backend specific test. It relies on static intializers to work
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTypes.h"
jvanverthfd359ca2016-03-18 11:57:24 -070011
Brian Osmanc7ad40f2018-05-31 14:27:17 -040012#if defined(SK_VULKAN)
jvanverthfd359ca2016-03-18 11:57:24 -070013
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/gpu/vk/GrVkVulkan.h"
Greg Daniel54bfb182018-11-20 17:12:36 -050015
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "include/gpu/GrBackendSurface.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "include/gpu/GrTexture.h"
18#include "src/gpu/GrContextPriv.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040019#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "tools/gpu/GrContextFactory.h"
Robert Phillips646e4292017-06-13 12:44:56 -040021
Mike Kleinc0bd9f92019-04-23 12:05:21 -050022#include "include/gpu/vk/GrVkTypes.h"
23#include "src/gpu/vk/GrVkCaps.h"
24#include "src/gpu/vk/GrVkGpu.h"
25#include "src/gpu/vk/GrVkMemory.h"
26#include "tests/Test.h"
jvanverthfd359ca2016-03-18 11:57:24 -070027
kkinnunen2ae4b2e2016-03-31 08:08:20 -070028using sk_gpu_test::GrContextFactory;
29
jvanverthfd359ca2016-03-18 11:57:24 -070030const int kW = 1024;
31const int kH = 1024;
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040032const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
Robert Phillips0902c982019-07-16 07:47:56 -040033const GrColorType kGrColorType = GrColorType::kRGBA_8888;
jvanverthfd359ca2016-03-18 11:57:24 -070034
35void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
36
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040037 GrGpu* gpu = context->priv().getGpu();
jvanverthfd359ca2016-03-18 11:57:24 -070038
Robert Phillips4bdd36f2019-06-04 11:03:06 -040039 GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
40 kColorType,
41 SkColors::kTransparent,
42 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -040043 GrRenderable::kNo,
44 GrProtected::kNo);
Greg Daniel52e16d92018-04-10 09:34:07 -040045 GrVkImageInfo imageInfo;
46 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -070047
Robert Phillipsc80b0e92019-07-23 10:27:09 -040048 sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kGrColorType,
49 kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
50 kRead_GrIOType);
jvanverthfd359ca2016-03-18 11:57:24 -070051 REPORTER_ASSERT(reporter, tex);
jvanverthfd359ca2016-03-18 11:57:24 -070052
53 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -050054 {
Greg Daniel52e16d92018-04-10 09:34:07 -040055 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -050056 backendCopy.fImage = VK_NULL_HANDLE;
57 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040058 tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership,
59 GrWrapCacheable::kNo, kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050060 REPORTER_ASSERT(reporter, !tex);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040061 tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
62 GrWrapCacheable::kNo, kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050063 REPORTER_ASSERT(reporter, !tex);
64 }
jvanverthfd359ca2016-03-18 11:57:24 -070065
66 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -050067 {
Greg Daniel52e16d92018-04-10 09:34:07 -040068 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -050069 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -050070 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040071 tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership,
72 GrWrapCacheable::kNo, kRead_GrIOType);
Jim Van Verth658d4992019-07-11 14:07:53 -040073 REPORTER_ASSERT(reporter, tex);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040074 tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
75 GrWrapCacheable::kNo, kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050076 REPORTER_ASSERT(reporter, !tex);
77 }
78
Stan Iliev7fa5c312017-04-19 00:23:39 +000079 // check adopt creation
Robert Phillipsd21b2a52017-12-12 13:01:25 -050080 {
Greg Daniel52e16d92018-04-10 09:34:07 -040081 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -050082 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillipsc80b0e92019-07-23 10:27:09 -040083 tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership,
84 GrWrapCacheable::kNo, kRead_GrIOType);
Greg Daniel7ef28f32017-04-20 16:41:55 +000085
Robert Phillipsd21b2a52017-12-12 13:01:25 -050086 REPORTER_ASSERT(reporter, tex);
87 }
jvanverthfd359ca2016-03-18 11:57:24 -070088}
89
90void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040091 GrGpu* gpu = context->priv().getGpu();
jvanverthfd359ca2016-03-18 11:57:24 -070092
Robert Phillips4bdd36f2019-06-04 11:03:06 -040093 GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
94 kColorType,
95 SkColors::kTransparent,
96 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -040097 GrRenderable::kYes,
98 GrProtected::kNo);
Greg Daniel108bb232018-07-03 16:18:29 -040099
Greg Daniel52e16d92018-04-10 09:34:07 -0400100 GrVkImageInfo imageInfo;
101 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -0700102
Greg Daniel52e16d92018-04-10 09:34:07 -0400103 GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo);
Greg Danielbcf612b2017-05-01 13:50:58 +0000104
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400105 sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT, kGrColorType);
jvanverthfd359ca2016-03-18 11:57:24 -0700106 REPORTER_ASSERT(reporter, rt);
jvanverthfd359ca2016-03-18 11:57:24 -0700107
108 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500109 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400110 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500111 backendCopy.fImage = VK_NULL_HANDLE;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500112 GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400113 rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500114 REPORTER_ASSERT(reporter, !rt);
115 }
jvanverthfd359ca2016-03-18 11:57:24 -0700116
117 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500118 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400119 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -0500120 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500121 // can wrap null alloc
Brian Salomonbdecacf2018-02-02 20:32:49 -0500122 GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400123 rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500124 REPORTER_ASSERT(reporter, rt);
125 }
jvanverthfd359ca2016-03-18 11:57:24 -0700126
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000127 // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the
128 // resource when we're done.
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400129 context->deleteBackendTexture(origBackendTex);
jvanverthfd359ca2016-03-18 11:57:24 -0700130}
131
132void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
Robert Phillips9dbcdcc2019-05-13 10:40:06 -0400133 GrGpu* gpu = context->priv().getGpu();
jvanverthfd359ca2016-03-18 11:57:24 -0700134
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400135 GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH,
136 kColorType,
137 SkColors::kTransparent,
138 GrMipMapped::kNo,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400139 GrRenderable::kYes,
140 GrProtected::kNo);
Greg Daniel52e16d92018-04-10 09:34:07 -0400141 GrVkImageInfo imageInfo;
142 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -0700143
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500144 sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(
Robert Phillips0902c982019-07-16 07:47:56 -0400145 origBackendTex, 1, kGrColorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
jvanverthfd359ca2016-03-18 11:57:24 -0700146 REPORTER_ASSERT(reporter, tex);
jvanverthfd359ca2016-03-18 11:57:24 -0700147
148 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500149 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400150 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500151 backendCopy.fImage = VK_NULL_HANDLE;
152 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillips0902c982019-07-16 07:47:56 -0400153 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
154 kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500155 REPORTER_ASSERT(reporter, !tex);
Robert Phillips0902c982019-07-16 07:47:56 -0400156 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
157 kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500158 REPORTER_ASSERT(reporter, !tex);
159 }
jvanverthfd359ca2016-03-18 11:57:24 -0700160
161 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500162 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400163 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -0500164 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500165 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillips0902c982019-07-16 07:47:56 -0400166 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
167 kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
Jim Van Verth658d4992019-07-11 14:07:53 -0400168 REPORTER_ASSERT(reporter, tex);
Robert Phillips0902c982019-07-16 07:47:56 -0400169 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
170 kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500171 REPORTER_ASSERT(reporter, !tex);
172 }
jvanverthfd359ca2016-03-18 11:57:24 -0700173
174 // check adopt creation
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500175 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400176 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500177 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Robert Phillips0902c982019-07-16 07:47:56 -0400178 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType,
179 kAdopt_GrWrapOwnership, GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500180 REPORTER_ASSERT(reporter, tex);
181 }
jvanverthfd359ca2016-03-18 11:57:24 -0700182}
183
bsalomondc0fcd42016-04-11 14:21:33 -0700184DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700185 wrap_tex_test(reporter, ctxInfo.grContext());
186 wrap_rt_test(reporter, ctxInfo.grContext());
187 wrap_trt_test(reporter, ctxInfo.grContext());
jvanverthfd359ca2016-03-18 11:57:24 -0700188}
189
190#endif