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