jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTypes.h" |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 11 | |
Brian Osman | c7ad40f | 2018-05-31 14:27:17 -0400 | [diff] [blame] | 12 | #if defined(SK_VULKAN) |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/gpu/vk/GrVkVulkan.h" |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 15 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/gpu/GrBackendSurface.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/gpu/GrTexture.h" |
| 18 | #include "src/gpu/GrContextPriv.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "tools/gpu/GrContextFactory.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 21 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 22 | #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" |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 27 | |
kkinnunen | 2ae4b2e | 2016-03-31 08:08:20 -0700 | [diff] [blame] | 28 | using sk_gpu_test::GrContextFactory; |
| 29 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 30 | const int kW = 1024; |
| 31 | const int kH = 1024; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 32 | const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType; |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 33 | const GrColorType kGrColorType = GrColorType::kRGBA_8888; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 34 | |
| 35 | void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { |
| 36 | |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 37 | GrGpu* gpu = context->priv().getGpu(); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 38 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 39 | GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH, |
| 40 | kColorType, |
| 41 | SkColors::kTransparent, |
| 42 | GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 43 | GrRenderable::kNo, |
| 44 | GrProtected::kNo); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 45 | GrVkImageInfo imageInfo; |
| 46 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 47 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 48 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kGrColorType, |
| 49 | kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, |
| 50 | kRead_GrIOType); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 52 | |
| 53 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 54 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 55 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 56 | backendCopy.fImage = VK_NULL_HANDLE; |
| 57 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 58 | tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership, |
| 59 | GrWrapCacheable::kNo, kRead_GrIOType); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, !tex); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 61 | tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership, |
| 62 | GrWrapCacheable::kNo, kRead_GrIOType); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 63 | REPORTER_ASSERT(reporter, !tex); |
| 64 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 65 | |
| 66 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 67 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 68 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 69 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 70 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 71 | tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kBorrow_GrWrapOwnership, |
| 72 | GrWrapCacheable::kNo, kRead_GrIOType); |
Jim Van Verth | 658d499 | 2019-07-11 14:07:53 -0400 | [diff] [blame] | 73 | REPORTER_ASSERT(reporter, tex); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 74 | tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership, |
| 75 | GrWrapCacheable::kNo, kRead_GrIOType); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, !tex); |
| 77 | } |
| 78 | |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame] | 79 | // check adopt creation |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 80 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 81 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 82 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 83 | tex = gpu->wrapBackendTexture(backendTex, kGrColorType, kAdopt_GrWrapOwnership, |
| 84 | GrWrapCacheable::kNo, kRead_GrIOType); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 85 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 86 | REPORTER_ASSERT(reporter, tex); |
| 87 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 91 | GrGpu* gpu = context->priv().getGpu(); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 92 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 93 | GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH, |
| 94 | kColorType, |
| 95 | SkColors::kTransparent, |
| 96 | GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 97 | GrRenderable::kYes, |
| 98 | GrProtected::kNo); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 99 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 100 | GrVkImageInfo imageInfo; |
| 101 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 102 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 103 | GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo); |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 104 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 105 | sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT, kGrColorType); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 106 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 107 | |
| 108 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 109 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 110 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 111 | backendCopy.fImage = VK_NULL_HANDLE; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 112 | GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 113 | rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 114 | REPORTER_ASSERT(reporter, !rt); |
| 115 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 116 | |
| 117 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 118 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 119 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 120 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 121 | // can wrap null alloc |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 122 | GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 123 | rt = gpu->wrapBackendRenderTarget(backendRT, kGrColorType); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 124 | REPORTER_ASSERT(reporter, rt); |
| 125 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 126 | |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 127 | // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the |
| 128 | // resource when we're done. |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 129 | context->deleteBackendTexture(origBackendTex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 133 | GrGpu* gpu = context->priv().getGpu(); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 134 | |
Robert Phillips | 4bdd36f | 2019-06-04 11:03:06 -0400 | [diff] [blame] | 135 | GrBackendTexture origBackendTex = context->createBackendTexture(kW, kH, |
| 136 | kColorType, |
| 137 | SkColors::kTransparent, |
| 138 | GrMipMapped::kNo, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 139 | GrRenderable::kYes, |
| 140 | GrProtected::kNo); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 141 | GrVkImageInfo imageInfo; |
| 142 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 143 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 144 | sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture( |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 145 | origBackendTex, 1, kGrColorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 146 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 147 | |
| 148 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 149 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 150 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 151 | backendCopy.fImage = VK_NULL_HANDLE; |
| 152 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 153 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType, |
| 154 | kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, !tex); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 156 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType, |
| 157 | kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 158 | REPORTER_ASSERT(reporter, !tex); |
| 159 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 160 | |
| 161 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 162 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 163 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 164 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 165 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 166 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType, |
| 167 | kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); |
Jim Van Verth | 658d499 | 2019-07-11 14:07:53 -0400 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, tex); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 169 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType, |
| 170 | kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 171 | REPORTER_ASSERT(reporter, !tex); |
| 172 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 173 | |
| 174 | // check adopt creation |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 175 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 176 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 177 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 178 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kGrColorType, |
| 179 | kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 180 | REPORTER_ASSERT(reporter, tex); |
| 181 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 182 | } |
| 183 | |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 184 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 185 | wrap_tex_test(reporter, ctxInfo.grContext()); |
| 186 | wrap_rt_test(reporter, ctxInfo.grContext()); |
| 187 | wrap_trt_test(reporter, ctxInfo.grContext()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | #endif |