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