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 | |
Jim Van Verth | 9158931 | 2017-06-22 12:52:46 -0400 | [diff] [blame^] | 12 | #if SK_SUPPORT_GPU && defined(SK_VULKAN) |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 13 | |
| 14 | #include "GrContextFactory.h" |
| 15 | #include "GrTest.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 16 | #include "GrTexture.h" |
| 17 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 18 | #include "Test.h" |
| 19 | #include "vk/GrVkCaps.h" |
| 20 | #include "vk/GrVkGpu.h" |
| 21 | #include "vk/GrVkMemory.h" |
| 22 | #include "vk/GrVkTypes.h" |
| 23 | |
kkinnunen | 2ae4b2e | 2016-03-31 08:08:20 -0700 | [diff] [blame] | 24 | using sk_gpu_test::GrContextFactory; |
| 25 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 26 | const int kW = 1024; |
| 27 | const int kH = 1024; |
| 28 | const GrPixelConfig kPixelConfig = kRGBA_8888_GrPixelConfig; |
| 29 | |
| 30 | void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { |
| 31 | |
| 32 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 33 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 34 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 35 | false); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 36 | const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 37 | |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 38 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 39 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex, |
| 40 | kTopLeft_GrSurfaceOrigin, |
| 41 | kNone_GrBackendTextureFlag, |
| 42 | 0, |
| 43 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 45 | |
| 46 | // image is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 47 | GrVkImageInfo backendCopy = *imageInfo; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 48 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 49 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 50 | tex = gpu->wrapBackendTexture(backendTex, |
| 51 | kTopLeft_GrSurfaceOrigin, |
| 52 | kNone_GrBackendTextureFlag, |
| 53 | 0, |
| 54 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 56 | tex = gpu->wrapBackendTexture(backendTex, |
| 57 | kTopLeft_GrSurfaceOrigin, |
| 58 | kNone_GrBackendTextureFlag, |
| 59 | 0, |
| 60 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 61 | REPORTER_ASSERT(reporter, !tex); |
| 62 | |
| 63 | // alloc is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 64 | backendCopy.fImage = imageInfo->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 65 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 66 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 67 | tex = gpu->wrapBackendTexture(backendTex, |
| 68 | kTopLeft_GrSurfaceOrigin, |
| 69 | kNone_GrBackendTextureFlag, |
| 70 | 0, |
| 71 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 73 | tex = gpu->wrapBackendTexture(backendTex, |
| 74 | kTopLeft_GrSurfaceOrigin, |
| 75 | kNone_GrBackendTextureFlag, |
| 76 | 0, |
| 77 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 78 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame] | 79 | // check adopt creation |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 80 | backendCopy.fAlloc = imageInfo->fAlloc; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 81 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 82 | tex = gpu->wrapBackendTexture(backendTex, |
| 83 | kTopLeft_GrSurfaceOrigin, |
| 84 | kNone_GrBackendTextureFlag, |
| 85 | 0, |
| 86 | kAdopt_GrWrapOwnership); |
| 87 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 89 | |
| 90 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 91 | } |
| 92 | |
| 93 | void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 94 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 95 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 96 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 97 | true); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 98 | const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 99 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 100 | GrBackendRenderTarget backendRT(kW, kH, 0, 0, *backendTex); |
| 101 | |
| 102 | sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(backendRT, kTopLeft_GrSurfaceOrigin); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 103 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 104 | |
| 105 | // image is null |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 106 | GrVkImageInfo backendCopy = *backendTex; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 107 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 108 | GrBackendRenderTarget backendRT2(kW, kH, 0, 0, backendCopy); |
| 109 | rt = gpu->wrapBackendRenderTarget(backendRT2, kTopLeft_GrSurfaceOrigin); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 110 | REPORTER_ASSERT(reporter, !rt); |
| 111 | |
| 112 | // alloc is null |
| 113 | backendCopy.fImage = backendTex->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 114 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 115 | // can wrap null alloc |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 116 | GrBackendRenderTarget backendRT3(kW, kH, 0, 0, backendCopy); |
| 117 | rt = gpu->wrapBackendRenderTarget(backendRT3, kTopLeft_GrSurfaceOrigin); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 118 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 119 | |
Greg Daniel | af40127 | 2017-03-27 16:18:03 -0400 | [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(backendObj, false); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 126 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 127 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 128 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 129 | true); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 130 | const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 131 | |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 132 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 133 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(backendTex, |
| 134 | kTopLeft_GrSurfaceOrigin, |
| 135 | kRenderTarget_GrBackendTextureFlag, |
| 136 | 0, |
| 137 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 138 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 139 | |
| 140 | // image is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 141 | GrVkImageInfo backendCopy = *imageInfo; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 142 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 143 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 144 | tex = gpu->wrapBackendTexture(backendTex, |
| 145 | kTopLeft_GrSurfaceOrigin, |
| 146 | kRenderTarget_GrBackendTextureFlag, |
| 147 | 0, |
| 148 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 150 | tex = gpu->wrapBackendTexture(backendTex, |
| 151 | kTopLeft_GrSurfaceOrigin, |
| 152 | kRenderTarget_GrBackendTextureFlag, |
| 153 | 0, |
| 154 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, !tex); |
| 156 | |
| 157 | // alloc is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 158 | backendCopy.fImage = imageInfo->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 159 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 160 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 161 | tex = gpu->wrapBackendTexture(backendTex, |
| 162 | kTopLeft_GrSurfaceOrigin, |
| 163 | kRenderTarget_GrBackendTextureFlag, |
| 164 | 0, |
| 165 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 166 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 167 | tex = gpu->wrapBackendTexture(backendTex, |
| 168 | kTopLeft_GrSurfaceOrigin, |
| 169 | kRenderTarget_GrBackendTextureFlag, |
| 170 | 0, |
| 171 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 172 | REPORTER_ASSERT(reporter, !tex); |
| 173 | |
| 174 | // check adopt creation |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 175 | backendCopy.fAlloc = imageInfo->fAlloc; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 176 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 177 | tex = gpu->wrapBackendTexture(backendTex, |
| 178 | kTopLeft_GrSurfaceOrigin, |
| 179 | kRenderTarget_GrBackendTextureFlag, |
| 180 | 0, |
| 181 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 182 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 183 | |
| 184 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 185 | } |
| 186 | |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 187 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 188 | wrap_tex_test(reporter, ctxInfo.grContext()); |
| 189 | wrap_rt_test(reporter, ctxInfo.grContext()); |
| 190 | wrap_trt_test(reporter, ctxInfo.grContext()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | #endif |