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