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