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, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 41 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 43 | |
| 44 | // image is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 45 | GrVkImageInfo backendCopy = *imageInfo; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 46 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 47 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 48 | tex = gpu->wrapBackendTexture(backendTex, |
| 49 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 50 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 51 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 52 | tex = gpu->wrapBackendTexture(backendTex, |
| 53 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 54 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 55 | REPORTER_ASSERT(reporter, !tex); |
| 56 | |
| 57 | // alloc is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 58 | backendCopy.fImage = imageInfo->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 59 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 60 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 61 | tex = gpu->wrapBackendTexture(backendTex, |
| 62 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 63 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 64 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 65 | tex = gpu->wrapBackendTexture(backendTex, |
| 66 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 67 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 68 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame] | 69 | // check adopt creation |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 70 | backendCopy.fAlloc = imageInfo->fAlloc; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 71 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 72 | tex = gpu->wrapBackendTexture(backendTex, |
| 73 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 74 | kAdopt_GrWrapOwnership); |
| 75 | |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 76 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 77 | |
| 78 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 79 | } |
| 80 | |
| 81 | void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 82 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 83 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 84 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 85 | true); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 86 | const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 87 | |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 88 | GrBackendRenderTarget backendRT(kW, kH, 0, 0, *backendTex); |
| 89 | |
| 90 | sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(backendRT, kTopLeft_GrSurfaceOrigin); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 91 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 92 | |
| 93 | // image is null |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 94 | GrVkImageInfo backendCopy = *backendTex; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 95 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 96 | GrBackendRenderTarget backendRT2(kW, kH, 0, 0, backendCopy); |
| 97 | rt = gpu->wrapBackendRenderTarget(backendRT2, kTopLeft_GrSurfaceOrigin); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 98 | REPORTER_ASSERT(reporter, !rt); |
| 99 | |
| 100 | // alloc is null |
| 101 | backendCopy.fImage = backendTex->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 102 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 103 | // can wrap null alloc |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 104 | GrBackendRenderTarget backendRT3(kW, kH, 0, 0, backendCopy); |
| 105 | rt = gpu->wrapBackendRenderTarget(backendRT3, kTopLeft_GrSurfaceOrigin); |
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 | |
Greg Daniel | af40127 | 2017-03-27 16:18:03 -0400 | [diff] [blame] | 108 | // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the |
| 109 | // resource when we're done. |
| 110 | gpu->deleteTestingOnlyBackendTexture(backendObj, false); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 114 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 115 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 116 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 117 | true); |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 118 | const GrVkImageInfo* imageInfo = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 119 | |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 120 | GrBackendTexture backendTex = GrBackendTexture(kW, kH, *imageInfo); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 121 | sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 122 | kTopLeft_GrSurfaceOrigin, |
| 123 | 0, |
| 124 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 125 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 126 | |
| 127 | // image is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 128 | GrVkImageInfo backendCopy = *imageInfo; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 129 | backendCopy.fImage = VK_NULL_HANDLE; |
Greg Daniel | 207282e | 2017-04-26 13:29:21 -0400 | [diff] [blame] | 130 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 131 | tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 132 | kTopLeft_GrSurfaceOrigin, |
| 133 | 0, |
| 134 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 135 | REPORTER_ASSERT(reporter, !tex); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 136 | tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 137 | kTopLeft_GrSurfaceOrigin, |
| 138 | 0, |
| 139 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, !tex); |
| 141 | |
| 142 | // alloc is null |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 143 | backendCopy.fImage = imageInfo->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 144 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 145 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 146 | tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 147 | kTopLeft_GrSurfaceOrigin, |
| 148 | 0, |
| 149 | kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, !tex); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 151 | tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 152 | kTopLeft_GrSurfaceOrigin, |
| 153 | 0, |
| 154 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 155 | REPORTER_ASSERT(reporter, !tex); |
| 156 | |
| 157 | // check adopt creation |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 158 | backendCopy.fAlloc = imageInfo->fAlloc; |
Greg Daniel | a18d2db | 2017-05-02 11:39:10 -0400 | [diff] [blame] | 159 | backendTex = GrBackendTexture(kW, kH, backendCopy); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame^] | 160 | tex = gpu->wrapRenderableBackendTexture(backendTex, |
| 161 | kTopLeft_GrSurfaceOrigin, |
| 162 | 0, |
| 163 | kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 164 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 165 | |
| 166 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 167 | } |
| 168 | |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 169 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 170 | wrap_tex_test(reporter, ctxInfo.grContext()); |
| 171 | wrap_rt_test(reporter, ctxInfo.grContext()); |
| 172 | wrap_trt_test(reporter, ctxInfo.grContext()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | #endif |