Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/gpu/vk/GrVkVulkan.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/gpu/GrContextPriv.h" |
| 11 | #include "tests/Test.h" |
| 12 | #include "tools/gpu/GrContextFactory.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkCanvas.h" |
| 15 | #include "include/core/SkSurface.h" |
| 16 | #include "include/gpu/GrBackendSemaphore.h" |
| 17 | #include "include/gpu/GrBackendSurface.h" |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 18 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 19 | #ifdef SK_GL |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/gl/GrGLGpu.h" |
| 21 | #include "src/gpu/gl/GrGLUtil.h" |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 22 | #endif |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 23 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 24 | #ifdef SK_VULKAN |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "include/gpu/vk/GrVkTypes.h" |
| 26 | #include "src/gpu/vk/GrVkCommandPool.h" |
| 27 | #include "src/gpu/vk/GrVkGpu.h" |
| 28 | #include "src/gpu/vk/GrVkUtil.h" |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 29 | |
| 30 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 31 | // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 32 | #undef CreateSemaphore |
| 33 | #endif |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | static const int MAIN_W = 8, MAIN_H = 16; |
| 37 | static const int CHILD_W = 16, CHILD_H = 16; |
| 38 | |
| 39 | void check_pixels(skiatest::Reporter* reporter, const SkBitmap& bitmap) { |
| 40 | const uint32_t* canvasPixels = static_cast<const uint32_t*>(bitmap.getPixels()); |
| 41 | |
| 42 | bool failureFound = false; |
| 43 | SkPMColor expectedPixel; |
| 44 | for (int cy = 0; cy < CHILD_H && !failureFound; ++cy) { |
| 45 | for (int cx = 0; cx < CHILD_W && !failureFound; ++cx) { |
| 46 | SkPMColor canvasPixel = canvasPixels[cy * CHILD_W + cx]; |
| 47 | if (cy < CHILD_H / 2) { |
| 48 | if (cx < CHILD_W / 2) { |
| 49 | expectedPixel = 0xFF0000FF; // Red |
| 50 | } else { |
| 51 | expectedPixel = 0xFFFF0000; // Blue |
| 52 | } |
| 53 | } else { |
| 54 | expectedPixel = 0xFF00FF00; // Green |
| 55 | } |
| 56 | if (expectedPixel != canvasPixel) { |
| 57 | failureFound = true; |
| 58 | ERRORF(reporter, "Wrong color at %d, %d. Got 0x%08x when we expected 0x%08x", |
| 59 | cx, cy, canvasPixel, expectedPixel); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void draw_child(skiatest::Reporter* reporter, |
| 66 | const sk_gpu_test::ContextInfo& childInfo, |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 67 | const GrBackendTexture& backendTexture, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 68 | const GrBackendSemaphore& semaphore) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 69 | |
| 70 | childInfo.testContext()->makeCurrent(); |
| 71 | |
| 72 | const SkImageInfo childII = SkImageInfo::Make(CHILD_W, CHILD_H, kRGBA_8888_SkColorType, |
| 73 | kPremul_SkAlphaType); |
| 74 | |
| 75 | GrContext* childCtx = childInfo.grContext(); |
| 76 | sk_sp<SkSurface> childSurface(SkSurface::MakeRenderTarget(childCtx, SkBudgeted::kNo, |
| 77 | childII, 0, kTopLeft_GrSurfaceOrigin, |
| 78 | nullptr)); |
| 79 | |
| 80 | sk_sp<SkImage> childImage = SkImage::MakeFromTexture(childCtx, |
| 81 | backendTexture, |
| 82 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 83 | kRGBA_8888_SkColorType, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 84 | kPremul_SkAlphaType, |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 85 | nullptr, |
| 86 | nullptr, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 87 | nullptr); |
| 88 | |
| 89 | SkCanvas* childCanvas = childSurface->getCanvas(); |
| 90 | childCanvas->clear(SK_ColorRED); |
| 91 | |
| 92 | childSurface->wait(1, &semaphore); |
| 93 | |
| 94 | childCanvas->drawImage(childImage, CHILD_W/2, 0); |
| 95 | |
| 96 | SkPaint paint; |
| 97 | paint.setColor(SK_ColorGREEN); |
| 98 | SkIRect rect = SkIRect::MakeLTRB(0, CHILD_H/2, CHILD_W, CHILD_H); |
| 99 | childCanvas->drawIRect(rect, paint); |
| 100 | |
| 101 | // read pixels |
| 102 | SkBitmap bitmap; |
| 103 | bitmap.allocPixels(childII); |
Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 104 | childSurface->readPixels(bitmap, 0, 0); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 105 | |
| 106 | check_pixels(reporter, bitmap); |
| 107 | } |
| 108 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 109 | enum class FlushType { kSurface, kImage, kContext }; |
| 110 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 111 | void surface_semaphore_test(skiatest::Reporter* reporter, |
| 112 | const sk_gpu_test::ContextInfo& mainInfo, |
| 113 | const sk_gpu_test::ContextInfo& childInfo1, |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 114 | const sk_gpu_test::ContextInfo& childInfo2, |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 115 | FlushType flushType) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 116 | GrContext* mainCtx = mainInfo.grContext(); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 117 | if (!mainCtx->priv().caps()->semaphoreSupport()) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
| 121 | const SkImageInfo ii = SkImageInfo::Make(MAIN_W, MAIN_H, kRGBA_8888_SkColorType, |
| 122 | kPremul_SkAlphaType); |
| 123 | |
| 124 | sk_sp<SkSurface> mainSurface(SkSurface::MakeRenderTarget(mainCtx, SkBudgeted::kNo, |
| 125 | ii, 0, kTopLeft_GrSurfaceOrigin, |
| 126 | nullptr)); |
| 127 | SkCanvas* mainCanvas = mainSurface->getCanvas(); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 128 | auto blueSurface = mainSurface->makeSurface(ii); |
| 129 | blueSurface->getCanvas()->clear(SK_ColorBLUE); |
| 130 | auto blueImage = blueSurface->makeImageSnapshot(); |
| 131 | blueSurface.reset(); |
| 132 | mainCanvas->drawImage(blueImage, 0, 0); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 133 | |
| 134 | SkAutoTArray<GrBackendSemaphore> semaphores(2); |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 135 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 136 | if (GrBackendApi::kVulkan == mainInfo.backend()) { |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 137 | // Initialize the secondary semaphore instead of having Ganesh create one internally |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 138 | GrVkGpu* gpu = static_cast<GrVkGpu*>(mainCtx->priv().getGpu()); |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 139 | VkDevice device = gpu->device(); |
| 140 | |
| 141 | VkSemaphore vkSem; |
| 142 | |
| 143 | VkSemaphoreCreateInfo createInfo; |
| 144 | createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 145 | createInfo.pNext = nullptr; |
| 146 | createInfo.flags = 0; |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 147 | GR_VK_CALL_ERRCHECK(gpu, CreateSemaphore(device, &createInfo, nullptr, &vkSem)); |
Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 148 | |
| 149 | semaphores[1].initVulkan(vkSem); |
| 150 | } |
| 151 | #endif |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 152 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 153 | GrFlushInfo info; |
| 154 | info.fNumSemaphores = 2; |
| 155 | info.fSignalSemaphores = semaphores.get(); |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 156 | switch (flushType) { |
| 157 | case FlushType::kSurface: |
| 158 | mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info); |
| 159 | break; |
| 160 | case FlushType::kImage: |
| 161 | blueImage->flush(mainCtx, info); |
| 162 | break; |
| 163 | case FlushType::kContext: |
| 164 | mainCtx->flush(info); |
| 165 | break; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 166 | } |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 167 | |
| 168 | sk_sp<SkImage> mainImage = mainSurface->makeImageSnapshot(); |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 169 | GrBackendTexture backendTexture = mainImage->getBackendTexture(false); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 170 | |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 171 | draw_child(reporter, childInfo1, backendTexture, semaphores[0]); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 172 | |
| 173 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 174 | if (GrBackendApi::kVulkan == mainInfo.backend()) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 175 | // In Vulkan we need to make sure we are sending the correct VkImageLayout in with the |
| 176 | // backendImage. After the first child draw the layout gets changed to SHADER_READ, so |
| 177 | // we just manually set that here. |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 178 | GrVkImageInfo vkInfo; |
| 179 | SkAssertResult(backendTexture.getVkImageInfo(&vkInfo)); |
| 180 | vkInfo.updateImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 181 | } |
| 182 | #endif |
| 183 | |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 184 | draw_child(reporter, childInfo2, backendTexture, semaphores[1]); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 185 | } |
| 186 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 187 | #ifdef SK_GL |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 188 | DEF_GPUTEST(SurfaceSemaphores, reporter, options) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 189 | #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC) |
| 190 | static constexpr auto kNativeGLType = sk_gpu_test::GrContextFactory::kGL_ContextType; |
| 191 | #else |
| 192 | static constexpr auto kNativeGLType = sk_gpu_test::GrContextFactory::kGLES_ContextType; |
| 193 | #endif |
| 194 | |
| 195 | for (int typeInt = 0; typeInt < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++typeInt) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 196 | for (auto flushType : {FlushType::kSurface, FlushType::kImage, FlushType::kContext}) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 197 | sk_gpu_test::GrContextFactory::ContextType contextType = |
| 198 | (sk_gpu_test::GrContextFactory::ContextType) typeInt; |
| 199 | // Use "native" instead of explicitly trying OpenGL and OpenGL ES. Do not use GLES on |
| 200 | // desktop since tests do not account for not fixing http://skbug.com/2809 |
| 201 | if (contextType == sk_gpu_test::GrContextFactory::kGL_ContextType || |
| 202 | contextType == sk_gpu_test::GrContextFactory::kGLES_ContextType) { |
| 203 | if (contextType != kNativeGLType) { |
| 204 | continue; |
| 205 | } |
| 206 | } |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 207 | sk_gpu_test::GrContextFactory factory(options); |
Chris Dalton | b3c9745 | 2019-06-25 20:07:56 -0600 | [diff] [blame] | 208 | sk_gpu_test::ContextInfo ctxInfo = factory.getContextInfo(contextType); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 209 | if (!sk_gpu_test::GrContextFactory::IsRenderingContext(contextType)) { |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 210 | continue; |
| 211 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 212 | skiatest::ReporterContext ctx( |
| 213 | reporter, SkString(sk_gpu_test::GrContextFactory::ContextTypeName(contextType))); |
| 214 | if (ctxInfo.grContext()) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 215 | sk_gpu_test::ContextInfo child1 = |
| 216 | factory.getSharedContextInfo(ctxInfo.grContext(), 0); |
| 217 | sk_gpu_test::ContextInfo child2 = |
| 218 | factory.getSharedContextInfo(ctxInfo.grContext(), 1); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 219 | if (!child1.grContext() || !child2.grContext()) { |
| 220 | continue; |
| 221 | } |
Yuqian Li | cc8eb60 | 2017-08-01 17:43:30 +0000 | [diff] [blame] | 222 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 223 | surface_semaphore_test(reporter, ctxInfo, child1, child2, flushType); |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 224 | } |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 228 | #endif |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 229 | |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 230 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EmptySurfaceSemaphoreTest, reporter, ctxInfo) { |
| 231 | GrContext* ctx = ctxInfo.grContext(); |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 232 | if (!ctx->priv().caps()->semaphoreSupport()) { |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
| 236 | const SkImageInfo ii = SkImageInfo::Make(MAIN_W, MAIN_H, kRGBA_8888_SkColorType, |
| 237 | kPremul_SkAlphaType); |
| 238 | |
| 239 | sk_sp<SkSurface> mainSurface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, |
| 240 | ii, 0, kTopLeft_GrSurfaceOrigin, |
| 241 | nullptr)); |
| 242 | |
| 243 | // Flush surface once without semaphores to make sure there is no peneding IO for it. |
| 244 | mainSurface->flush(); |
| 245 | |
| 246 | GrBackendSemaphore semaphore; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 247 | GrSemaphoresSubmitted submitted = mainSurface->flushAndSignalSemaphores(1, &semaphore); |
| 248 | REPORTER_ASSERT(reporter, GrSemaphoresSubmitted::kYes == submitted); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 249 | |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 250 | #ifdef SK_GL |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 251 | if (GrBackendApi::kOpenGL == ctxInfo.backend()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 252 | GrGLGpu* gpu = static_cast<GrGLGpu*>(ctx->priv().getGpu()); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 253 | const GrGLInterface* interface = gpu->glInterface(); |
| 254 | GrGLsync sync = semaphore.glSync(); |
| 255 | REPORTER_ASSERT(reporter, sync); |
| 256 | bool result; |
| 257 | GR_GL_CALL_RET(interface, result, IsSync(sync)); |
| 258 | REPORTER_ASSERT(reporter, result); |
| 259 | } |
John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 260 | #endif |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 261 | |
| 262 | #ifdef SK_VULKAN |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 263 | if (GrBackendApi::kVulkan == ctxInfo.backend()) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 264 | GrVkGpu* gpu = static_cast<GrVkGpu*>(ctx->priv().getGpu()); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 265 | const GrVkInterface* interface = gpu->vkInterface(); |
| 266 | VkDevice device = gpu->device(); |
| 267 | VkQueue queue = gpu->queue(); |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 268 | GrVkCommandPool* cmdPool = gpu->cmdPool(); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 269 | VkCommandBuffer cmdBuffer; |
| 270 | |
| 271 | // Create Command Buffer |
| 272 | const VkCommandBufferAllocateInfo cmdInfo = { |
| 273 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType |
| 274 | nullptr, // pNext |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 275 | cmdPool->vkCommandPool(), // commandPool |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 276 | VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level |
| 277 | 1 // bufferCount |
| 278 | }; |
| 279 | |
| 280 | VkResult err = GR_VK_CALL(interface, AllocateCommandBuffers(device, &cmdInfo, &cmdBuffer)); |
| 281 | if (err) { |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | VkCommandBufferBeginInfo cmdBufferBeginInfo; |
| 286 | memset(&cmdBufferBeginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 287 | cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 288 | cmdBufferBeginInfo.pNext = nullptr; |
| 289 | cmdBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 290 | cmdBufferBeginInfo.pInheritanceInfo = nullptr; |
| 291 | |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 292 | GR_VK_CALL_ERRCHECK(gpu, BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo)); |
| 293 | GR_VK_CALL_ERRCHECK(gpu, EndCommandBuffer(cmdBuffer)); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 294 | |
| 295 | VkFenceCreateInfo fenceInfo; |
| 296 | VkFence fence; |
| 297 | |
| 298 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 299 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 300 | err = GR_VK_CALL(interface, CreateFence(device, &fenceInfo, nullptr, &fence)); |
| 301 | SkASSERT(!err); |
| 302 | |
| 303 | VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 304 | VkSubmitInfo submitInfo; |
| 305 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 306 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 307 | submitInfo.pNext = nullptr; |
| 308 | submitInfo.waitSemaphoreCount = 1; |
| 309 | VkSemaphore vkSem = semaphore.vkSemaphore(); |
| 310 | submitInfo.pWaitSemaphores = &vkSem; |
| 311 | submitInfo.pWaitDstStageMask = &waitStages; |
| 312 | submitInfo.commandBufferCount = 1; |
| 313 | submitInfo.pCommandBuffers = &cmdBuffer; |
| 314 | submitInfo.signalSemaphoreCount = 0; |
| 315 | submitInfo.pSignalSemaphores = nullptr; |
Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 316 | GR_VK_CALL_ERRCHECK(gpu, QueueSubmit(queue, 1, &submitInfo, fence)); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 317 | |
| 318 | err = GR_VK_CALL(interface, WaitForFences(device, 1, &fence, true, 3000000000)); |
| 319 | |
| 320 | REPORTER_ASSERT(reporter, err != VK_TIMEOUT); |
| 321 | |
| 322 | GR_VK_CALL(interface, DestroyFence(device, fence, nullptr)); |
| 323 | GR_VK_CALL(interface, DestroySemaphore(device, vkSem, nullptr)); |
| 324 | // If the above test fails the wait semaphore will never be signaled which can cause the |
| 325 | // device to hang when tearing down (even if just tearing down GL). So we Fail here to |
| 326 | // kill things. |
| 327 | if (err == VK_TIMEOUT) { |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 328 | SK_ABORT("Waiting on semaphore indefinitely"); |
Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | #endif |
| 332 | } |