blob: 1bd64d95c91acc454a52a123fd6489ba03ad9e1d [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
10#include "SkTypes.h"
11
Brian Osmanc7ad40f2018-05-31 14:27:17 -040012#if defined(SK_VULKAN)
jvanverthfd359ca2016-03-18 11:57:24 -070013
Greg Daniel54bfb182018-11-20 17:12:36 -050014#include "vk/GrVkVulkan.h"
15
Herb Derbyd3895d82018-09-04 13:27:00 -040016#include "GrBackendSurface.h"
Robert Phillipsf35fd8d2018-01-22 10:48:15 -050017#include "GrContextPriv.h"
jvanverthfd359ca2016-03-18 11:57:24 -070018#include "GrContextFactory.h"
Robert Phillips2890fbf2017-07-26 15:48:41 -040019#include "GrRenderTarget.h"
Robert Phillips646e4292017-06-13 12:44:56 -040020#include "GrTexture.h"
21
jvanverthfd359ca2016-03-18 11:57:24 -070022#include "Test.h"
23#include "vk/GrVkCaps.h"
24#include "vk/GrVkGpu.h"
25#include "vk/GrVkMemory.h"
26#include "vk/GrVkTypes.h"
27
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;
32const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig;
Robert Phillips646f6372018-09-25 09:31:10 -040033const GrColorType kColorType = GrColorType::kRGBA_8888;
jvanverthfd359ca2016-03-18 11:57:24 -070034
35void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
36
Robert Phillips9da87e02019-02-04 13:26:26 -050037 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
jvanverthfd359ca2016-03-18 11:57:24 -070038
Robert Phillipsd21b2a52017-12-12 13:01:25 -050039 GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
Robert Phillips646f6372018-09-25 09:31:10 -040040 kColorType, false,
Robert Phillipsd21b2a52017-12-12 13:01:25 -050041 GrMipMapped::kNo);
Greg Daniel52e16d92018-04-10 09:34:07 -040042 GrVkImageInfo imageInfo;
43 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -070044
Brian Salomonfa2ebea2019-01-24 15:58:58 -050045 sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050046 GrWrapCacheable::kNo, kRead_GrIOType);
jvanverthfd359ca2016-03-18 11:57:24 -070047 REPORTER_ASSERT(reporter, tex);
jvanverthfd359ca2016-03-18 11:57:24 -070048
49 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -050050 {
Greg Daniel52e16d92018-04-10 09:34:07 -040051 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -050052 backendCopy.fImage = VK_NULL_HANDLE;
53 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -040054 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050055 tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050056 kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050057 REPORTER_ASSERT(reporter, !tex);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050058 tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050059 kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050060 REPORTER_ASSERT(reporter, !tex);
61 }
jvanverthfd359ca2016-03-18 11:57:24 -070062
63 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -050064 {
Greg Daniel52e16d92018-04-10 09:34:07 -040065 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -050066 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -050067 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -040068 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050069 tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050070 kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050071 REPORTER_ASSERT(reporter, !tex);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050072 tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050073 kRead_GrIOType);
Robert Phillipsd21b2a52017-12-12 13:01:25 -050074 REPORTER_ASSERT(reporter, !tex);
75 }
76
Stan Iliev7fa5c312017-04-19 00:23:39 +000077 // check adopt creation
Robert Phillipsd21b2a52017-12-12 13:01:25 -050078 {
Greg Daniel52e16d92018-04-10 09:34:07 -040079 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -050080 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -040081 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050082 tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050083 kRead_GrIOType);
Greg Daniel7ef28f32017-04-20 16:41:55 +000084
Robert Phillipsd21b2a52017-12-12 13:01:25 -050085 REPORTER_ASSERT(reporter, tex);
86 }
jvanverthfd359ca2016-03-18 11:57:24 -070087}
88
89void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) {
Robert Phillips9da87e02019-02-04 13:26:26 -050090 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
jvanverthfd359ca2016-03-18 11:57:24 -070091
Greg Daniel8a3f55c2018-03-14 17:32:12 +000092 GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
Robert Phillips646f6372018-09-25 09:31:10 -040093 kColorType, true,
Greg Daniel8a3f55c2018-03-14 17:32:12 +000094 GrMipMapped::kNo);
Greg Daniel108bb232018-07-03 16:18:29 -040095
Greg Daniel52e16d92018-04-10 09:34:07 -040096 GrVkImageInfo imageInfo;
97 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -070098
Greg Daniel52e16d92018-04-10 09:34:07 -040099 GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo);
Greg Daniel108bb232018-07-03 16:18:29 -0400100 origBackendRT.setPixelConfig(kPixelConfig);
Greg Danielbcf612b2017-05-01 13:50:58 +0000101
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500102 sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
jvanverthfd359ca2016-03-18 11:57:24 -0700103 REPORTER_ASSERT(reporter, rt);
jvanverthfd359ca2016-03-18 11:57:24 -0700104
105 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500106 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400107 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500108 backendCopy.fImage = VK_NULL_HANDLE;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500109 GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -0400110 backendRT.setPixelConfig(kPixelConfig);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500111 rt = gpu->wrapBackendRenderTarget(backendRT);
112 REPORTER_ASSERT(reporter, !rt);
113 }
jvanverthfd359ca2016-03-18 11:57:24 -0700114
115 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500116 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400117 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -0500118 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500119 // can wrap null alloc
Brian Salomonbdecacf2018-02-02 20:32:49 -0500120 GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -0400121 backendRT.setPixelConfig(kPixelConfig);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500122 rt = gpu->wrapBackendRenderTarget(backendRT);
123 REPORTER_ASSERT(reporter, rt);
124 }
jvanverthfd359ca2016-03-18 11:57:24 -0700125
Greg Daniel8a3f55c2018-03-14 17:32:12 +0000126 // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the
127 // resource when we're done.
128 gpu->deleteTestingOnlyBackendTexture(origBackendTex);
jvanverthfd359ca2016-03-18 11:57:24 -0700129}
130
131void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) {
Robert Phillips9da87e02019-02-04 13:26:26 -0500132 GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
jvanverthfd359ca2016-03-18 11:57:24 -0700133
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500134 GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH,
Robert Phillips646f6372018-09-25 09:31:10 -0400135 kColorType, true,
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500136 GrMipMapped::kNo);
Greg Daniel52e16d92018-04-10 09:34:07 -0400137 GrVkImageInfo imageInfo;
138 SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
jvanverthfd359ca2016-03-18 11:57:24 -0700139
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500140 sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(
141 origBackendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
jvanverthfd359ca2016-03-18 11:57:24 -0700142 REPORTER_ASSERT(reporter, tex);
jvanverthfd359ca2016-03-18 11:57:24 -0700143
144 // image is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500145 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400146 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500147 backendCopy.fImage = VK_NULL_HANDLE;
148 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -0400149 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500150 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
151 GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500152 REPORTER_ASSERT(reporter, !tex);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500153 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
154 GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500155 REPORTER_ASSERT(reporter, !tex);
156 }
jvanverthfd359ca2016-03-18 11:57:24 -0700157
158 // alloc is null
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500159 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400160 GrVkImageInfo backendCopy = imageInfo;
Greg Daniel8385a8a2018-02-26 13:29:37 -0500161 backendCopy.fAlloc = GrVkAlloc();
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500162 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -0400163 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500164 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership,
165 GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500166 REPORTER_ASSERT(reporter, !tex);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500167 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
168 GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500169 REPORTER_ASSERT(reporter, !tex);
170 }
jvanverthfd359ca2016-03-18 11:57:24 -0700171
172 // check adopt creation
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500173 {
Greg Daniel52e16d92018-04-10 09:34:07 -0400174 GrVkImageInfo backendCopy = imageInfo;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500175 GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy);
Greg Daniel108bb232018-07-03 16:18:29 -0400176 backendTex.setPixelConfig(kPixelConfig);
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500177 tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership,
178 GrWrapCacheable::kNo);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500179 REPORTER_ASSERT(reporter, tex);
180 }
jvanverthfd359ca2016-03-18 11:57:24 -0700181}
182
bsalomondc0fcd42016-04-11 14:21:33 -0700183DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) {
bsalomon8b7451a2016-05-11 06:33:06 -0700184 wrap_tex_test(reporter, ctxInfo.grContext());
185 wrap_rt_test(reporter, ctxInfo.grContext());
186 wrap_trt_test(reporter, ctxInfo.grContext());
jvanverthfd359ca2016-03-18 11:57:24 -0700187}
188
189#endif