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); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 34 | const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 35 | |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 36 | // check basic borrowed creation |
| 37 | GrBackendTextureDesc desc; |
| 38 | desc.fConfig = kPixelConfig; |
| 39 | desc.fWidth = kW; |
| 40 | desc.fHeight = kH; |
| 41 | desc.fTextureHandle = backendObj; |
| 42 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, 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 |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 46 | GrVkImageInfo backendCopy = *backendTex; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 47 | backendCopy.fImage = VK_NULL_HANDLE; |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 48 | desc.fTextureHandle = (GrBackendObject) &backendCopy; |
| 49 | tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 51 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 52 | REPORTER_ASSERT(reporter, !tex); |
| 53 | |
| 54 | // alloc is null |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 55 | backendCopy.fImage = backendTex->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 56 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 57 | tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 59 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 60 | REPORTER_ASSERT(reporter, !tex); |
Greg Daniel | 7da62b9 | 2017-04-18 17:12:32 -0400 | [diff] [blame] | 61 | |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 62 | // check adopt creation |
| 63 | backendCopy.fAlloc = backendTex->fAlloc; |
| 64 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 65 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 66 | |
| 67 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 68 | } |
| 69 | |
| 70 | void wrap_rt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 71 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 72 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 73 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 74 | true); |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 75 | const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 76 | |
| 77 | // check basic borrowed creation |
| 78 | GrBackendRenderTargetDesc desc; |
| 79 | desc.fWidth = kW; |
| 80 | desc.fHeight = kH; |
| 81 | desc.fConfig = kPixelConfig; |
| 82 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 83 | desc.fSampleCnt = 0; |
| 84 | desc.fStencilBits = 0; |
| 85 | desc.fRenderTargetHandle = backendObj; |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 86 | sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(desc); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 87 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 88 | |
| 89 | // image is null |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 90 | GrVkImageInfo backendCopy = *backendTex; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 91 | backendCopy.fImage = VK_NULL_HANDLE; |
| 92 | desc.fRenderTargetHandle = (GrBackendObject)&backendCopy; |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 93 | rt = gpu->wrapBackendRenderTarget(desc); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 94 | REPORTER_ASSERT(reporter, !rt); |
| 95 | |
| 96 | // alloc is null |
| 97 | backendCopy.fImage = backendTex->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 98 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Brian Osman | 0b791f5 | 2017-03-10 08:30:22 -0500 | [diff] [blame] | 99 | // can wrap null alloc |
| 100 | rt = gpu->wrapBackendRenderTarget(desc); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 101 | REPORTER_ASSERT(reporter, rt); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 102 | |
Greg Daniel | af40127 | 2017-03-27 16:18:03 -0400 | [diff] [blame] | 103 | // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the |
| 104 | // resource when we're done. |
| 105 | gpu->deleteTestingOnlyBackendTexture(backendObj, false); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { |
| 109 | GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu()); |
| 110 | |
egdaniel | 0a3a7f7 | 2016-06-24 09:22:31 -0700 | [diff] [blame] | 111 | GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, |
| 112 | true); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 113 | const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 114 | |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 115 | // check basic borrowed creation |
| 116 | GrBackendTextureDesc desc; |
| 117 | desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 118 | desc.fConfig = kPixelConfig; |
| 119 | desc.fWidth = kW; |
| 120 | desc.fHeight = kH; |
| 121 | desc.fTextureHandle = backendObj; |
| 122 | sk_sp<GrTexture> tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 124 | |
| 125 | // image is null |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 126 | GrVkImageInfo backendCopy = *backendTex; |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 127 | backendCopy.fImage = VK_NULL_HANDLE; |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 128 | desc.fTextureHandle = (GrBackendObject)&backendCopy; |
| 129 | tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 130 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 131 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 132 | REPORTER_ASSERT(reporter, !tex); |
| 133 | |
| 134 | // alloc is null |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 135 | backendCopy.fImage = backendTex->fImage; |
jvanverth | 65b8cb0 | 2016-09-20 13:18:00 -0700 | [diff] [blame] | 136 | backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 137 | tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 138 | REPORTER_ASSERT(reporter, !tex); |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 139 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, !tex); |
| 141 | |
| 142 | // check adopt creation |
Stan Iliev | 7fa5c31 | 2017-04-19 00:23:39 +0000 | [diff] [blame^] | 143 | backendCopy.fAlloc = backendTex->fAlloc; |
| 144 | tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, tex); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 146 | |
| 147 | gpu->deleteTestingOnlyBackendTexture(backendObj, true); |
| 148 | } |
| 149 | |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 150 | DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkWrapTests, reporter, ctxInfo) { |
bsalomon | 8b7451a | 2016-05-11 06:33:06 -0700 | [diff] [blame] | 151 | wrap_tex_test(reporter, ctxInfo.grContext()); |
| 152 | wrap_rt_test(reporter, ctxInfo.grContext()); |
| 153 | wrap_trt_test(reporter, ctxInfo.grContext()); |
jvanverth | fd359ca | 2016-03-18 11:57:24 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | #endif |