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 | |
| 10 | #include "SkTypes.h" |
| 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 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 14 | #include "vk/GrVkVulkan.h" |
| 15 | |
Herb Derby | d3895d8 | 2018-09-04 13:27:00 -0400 | [diff] [blame] | 16 | #include "GrBackendSurface.h" |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 17 | #include "GrContextPriv.h" |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 18 | #include "GrContextFactory.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 19 | #include "GrRenderTarget.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 20 | #include "GrTexture.h" |
| 21 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 22 | #include "Test.h" |
| 23 | #include "vk/GrVkCaps.h" |
| 24 | #include "vk/GrVkGpu.h" |
| 25 | #include "vk/GrVkMemory.h" |
| 26 | #include "vk/GrVkTypes.h" |
| 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; |
| 32 | const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig; |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 33 | const GrColorType kColorType = 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 | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 37 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 38 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 39 | GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 40 | kColorType, false, |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 41 | GrMipMapped::kNo); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 42 | GrVkImageInfo imageInfo; |
| 43 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 44 | |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 45 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, false); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 47 | |
| 48 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 49 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 50 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 51 | backendCopy.fImage = VK_NULL_HANDLE; |
| 52 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 53 | backendTex.setPixelConfig(kPixelConfig); |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 54 | tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, false); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 56 | tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, false); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 57 | REPORTER_ASSERT(reporter, !tex); |
| 58 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 59 | |
| 60 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 61 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 62 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 63 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 64 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 65 | backendTex.setPixelConfig(kPixelConfig); |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 66 | tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, false); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 67 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 68 | tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, false); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 69 | REPORTER_ASSERT(reporter, !tex); |
| 70 | } |
| 71 | |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame] | 72 | // check adopt creation |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 73 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 74 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 75 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 76 | backendTex.setPixelConfig(kPixelConfig); |
Greg Daniel | 2268ad2 | 2018-11-15 09:27:38 -0500 | [diff] [blame] | 77 | tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, false); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 78 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 79 | REPORTER_ASSERT(reporter, tex); |
| 80 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 84 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 85 | |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 86 | GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 87 | kColorType, true, |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 88 | GrMipMapped::kNo); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 89 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 90 | GrVkImageInfo imageInfo; |
| 91 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 92 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 93 | GrBackendRenderTarget origBackendRT(kW, kH, 1, 0, imageInfo); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 94 | origBackendRT.setPixelConfig(kPixelConfig); |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 95 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 96 | sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 97 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 98 | |
| 99 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 100 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 101 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 102 | backendCopy.fImage = VK_NULL_HANDLE; |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 103 | GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 104 | backendRT.setPixelConfig(kPixelConfig); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 105 | rt = gpu->wrapBackendRenderTarget(backendRT); |
| 106 | REPORTER_ASSERT(reporter, !rt); |
| 107 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 108 | |
| 109 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 110 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 111 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 112 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 113 | // can wrap null alloc |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 114 | GrBackendRenderTarget backendRT(kW, kH, 1, 0, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 115 | backendRT.setPixelConfig(kPixelConfig); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 116 | rt = gpu->wrapBackendRenderTarget(backendRT); |
| 117 | REPORTER_ASSERT(reporter, rt); |
| 118 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 119 | |
Greg Daniel | 8a3f55c | 2018-03-14 17:32:12 +0000 | [diff] [blame] | 120 | // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the |
| 121 | // resource when we're done. |
| 122 | gpu->deleteTestingOnlyBackendTexture(origBackendTex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
Robert Phillips | f35fd8d | 2018-01-22 10:48:15 -0500 | [diff] [blame] | 126 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->contextPriv().getGpu()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 127 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 128 | GrBackendTexture origBackendTex = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 129 | kColorType, true, |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 130 | GrMipMapped::kNo); |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 131 | GrVkImageInfo imageInfo; |
| 132 | SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 133 | |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 134 | sk_sp<GrTexture> tex = |
| 135 | gpu->wrapRenderableBackendTexture(origBackendTex, 1, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 137 | |
| 138 | // image is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 139 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 140 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 141 | backendCopy.fImage = VK_NULL_HANDLE; |
| 142 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 143 | backendTex.setPixelConfig(kPixelConfig); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 144 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, !tex); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 146 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 147 | REPORTER_ASSERT(reporter, !tex); |
| 148 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 149 | |
| 150 | // alloc is null |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 151 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 152 | GrVkImageInfo backendCopy = imageInfo; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 153 | backendCopy.fAlloc = GrVkAlloc(); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 154 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 155 | backendTex.setPixelConfig(kPixelConfig); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 156 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 157 | REPORTER_ASSERT(reporter, !tex); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 158 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 159 | REPORTER_ASSERT(reporter, !tex); |
| 160 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 161 | |
| 162 | // check adopt creation |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 163 | { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 164 | GrVkImageInfo backendCopy = imageInfo; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 165 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 166 | backendTex.setPixelConfig(kPixelConfig); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 167 | tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, tex); |
| 169 | } |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 170 | } |
| 171 | |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 172 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 173 | wrap_tex_test(reporter, ctxInfo.grContext()); |
| 174 | wrap_rt_test(reporter, ctxInfo.grContext()); |
| 175 | wrap_trt_test(reporter, ctxInfo.grContext()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | #endif |