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