| 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 Reed | ac9f0c9 | 2020-12-23 10:11:33 -0500 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
| Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkSurface.h" |
| 11 | #include "include/gpu/GrBackendSemaphore.h" |
| 12 | #include "include/gpu/GrBackendSurface.h" |
| Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 13 | #include "include/gpu/GrDirectContext.h" |
| Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrCaps.h" |
| Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 15 | #include "src/gpu/GrDirectContextPriv.h" |
| Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 16 | #include "tests/Test.h" |
| 17 | #include "tools/gpu/GrContextFactory.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" |
| Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 26 | #include "include/gpu/vk/GrVkVulkan.h" |
| Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/gpu/vk/GrVkCommandPool.h" |
| 28 | #include "src/gpu/vk/GrVkGpu.h" |
| 29 | #include "src/gpu/vk/GrVkUtil.h" |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 30 | |
| 31 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 32 | // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
| Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 33 | #undef CreateSemaphore |
| 34 | #endif |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 35 | #endif |
| 36 | |
| 37 | static const int MAIN_W = 8, MAIN_H = 16; |
| 38 | static const int CHILD_W = 16, CHILD_H = 16; |
| 39 | |
| 40 | void check_pixels(skiatest::Reporter* reporter, const SkBitmap& bitmap) { |
| 41 | const uint32_t* canvasPixels = static_cast<const uint32_t*>(bitmap.getPixels()); |
| 42 | |
| 43 | bool failureFound = false; |
| 44 | SkPMColor expectedPixel; |
| 45 | for (int cy = 0; cy < CHILD_H && !failureFound; ++cy) { |
| 46 | for (int cx = 0; cx < CHILD_W && !failureFound; ++cx) { |
| 47 | SkPMColor canvasPixel = canvasPixels[cy * CHILD_W + cx]; |
| 48 | if (cy < CHILD_H / 2) { |
| 49 | if (cx < CHILD_W / 2) { |
| 50 | expectedPixel = 0xFF0000FF; // Red |
| 51 | } else { |
| 52 | expectedPixel = 0xFFFF0000; // Blue |
| 53 | } |
| 54 | } else { |
| 55 | expectedPixel = 0xFF00FF00; // Green |
| 56 | } |
| 57 | if (expectedPixel != canvasPixel) { |
| 58 | failureFound = true; |
| 59 | ERRORF(reporter, "Wrong color at %d, %d. Got 0x%08x when we expected 0x%08x", |
| 60 | cx, cy, canvasPixel, expectedPixel); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void draw_child(skiatest::Reporter* reporter, |
| 67 | const sk_gpu_test::ContextInfo& childInfo, |
| Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 68 | const GrBackendTexture& backendTexture, |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 69 | const GrBackendSemaphore& semaphore) { |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 70 | |
| 71 | childInfo.testContext()->makeCurrent(); |
| 72 | |
| 73 | const SkImageInfo childII = SkImageInfo::Make(CHILD_W, CHILD_H, kRGBA_8888_SkColorType, |
| 74 | kPremul_SkAlphaType); |
| 75 | |
| Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 76 | auto childDContext = childInfo.directContext(); |
| 77 | sk_sp<SkSurface> childSurface(SkSurface::MakeRenderTarget(childDContext, SkBudgeted::kNo, |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 78 | childII, 0, kTopLeft_GrSurfaceOrigin, |
| 79 | nullptr)); |
| 80 | |
| Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 81 | sk_sp<SkImage> childImage = SkImage::MakeFromTexture(childDContext, |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 82 | backendTexture, |
| 83 | kTopLeft_GrSurfaceOrigin, |
| Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 84 | kRGBA_8888_SkColorType, |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 85 | kPremul_SkAlphaType, |
| Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 86 | nullptr, |
| 87 | nullptr, |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 88 | nullptr); |
| 89 | |
| 90 | SkCanvas* childCanvas = childSurface->getCanvas(); |
| 91 | childCanvas->clear(SK_ColorRED); |
| 92 | |
| 93 | childSurface->wait(1, &semaphore); |
| 94 | |
| 95 | childCanvas->drawImage(childImage, CHILD_W/2, 0); |
| 96 | |
| 97 | SkPaint paint; |
| 98 | paint.setColor(SK_ColorGREEN); |
| 99 | SkIRect rect = SkIRect::MakeLTRB(0, CHILD_H/2, CHILD_W, CHILD_H); |
| 100 | childCanvas->drawIRect(rect, paint); |
| 101 | |
| 102 | // read pixels |
| 103 | SkBitmap bitmap; |
| 104 | bitmap.allocPixels(childII); |
| Mike Reed | f194219 | 2017-07-21 14:24:29 -0400 | [diff] [blame] | 105 | childSurface->readPixels(bitmap, 0, 0); |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 106 | |
| 107 | check_pixels(reporter, bitmap); |
| 108 | } |
| 109 | |
| Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 110 | enum class FlushType { kSurface, kImage, kContext }; |
| 111 | |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 112 | void surface_semaphore_test(skiatest::Reporter* reporter, |
| 113 | const sk_gpu_test::ContextInfo& mainInfo, |
| 114 | const sk_gpu_test::ContextInfo& childInfo1, |
| Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 115 | const sk_gpu_test::ContextInfo& childInfo2, |
| Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 116 | FlushType flushType) { |
| Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 117 | auto mainCtx = mainInfo.directContext(); |
| Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 118 | if (!mainCtx->priv().caps()->semaphoreSupport()) { |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 119 | return; |
| 120 | } |
| 121 | |
| 122 | const SkImageInfo ii = SkImageInfo::Make(MAIN_W, MAIN_H, kRGBA_8888_SkColorType, |
| 123 | kPremul_SkAlphaType); |
| 124 | |
| 125 | sk_sp<SkSurface> mainSurface(SkSurface::MakeRenderTarget(mainCtx, SkBudgeted::kNo, |
| 126 | ii, 0, kTopLeft_GrSurfaceOrigin, |
| 127 | nullptr)); |
| 128 | SkCanvas* mainCanvas = mainSurface->getCanvas(); |
| Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 129 | auto blueSurface = mainSurface->makeSurface(ii); |
| 130 | blueSurface->getCanvas()->clear(SK_ColorBLUE); |
| 131 | auto blueImage = blueSurface->makeImageSnapshot(); |
| 132 | blueSurface.reset(); |
| 133 | mainCanvas->drawImage(blueImage, 0, 0); |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 134 | |
| 135 | SkAutoTArray<GrBackendSemaphore> semaphores(2); |
| Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 136 | #ifdef SK_VULKAN |
| Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 137 | if (GrBackendApi::kVulkan == mainInfo.backend()) { |
| Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 138 | // Initialize the secondary semaphore instead of having Ganesh create one internally |
| Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 139 | GrVkGpu* gpu = static_cast<GrVkGpu*>(mainCtx->priv().getGpu()); |
| Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 140 | VkDevice device = gpu->device(); |
| 141 | |
| 142 | VkSemaphore vkSem; |
| 143 | |
| 144 | VkSemaphoreCreateInfo createInfo; |
| 145 | createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 146 | createInfo.pNext = nullptr; |
| 147 | createInfo.flags = 0; |
| Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 148 | GR_VK_CALL_ERRCHECK(gpu, CreateSemaphore(device, &createInfo, nullptr, &vkSem)); |
| Greg Daniel | 8761e0c | 2017-07-20 16:36:01 -0400 | [diff] [blame] | 149 | |
| 150 | semaphores[1].initVulkan(vkSem); |
| 151 | } |
| 152 | #endif |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 153 | |
| Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 154 | GrFlushInfo info; |
| 155 | info.fNumSemaphores = 2; |
| 156 | info.fSignalSemaphores = semaphores.get(); |
| Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 157 | switch (flushType) { |
| 158 | case FlushType::kSurface: |
| 159 | mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, info); |
| 160 | break; |
| 161 | case FlushType::kImage: |
| 162 | blueImage->flush(mainCtx, info); |
| 163 | break; |
| 164 | case FlushType::kContext: |
| 165 | mainCtx->flush(info); |
| 166 | break; |
| Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 167 | } |
| Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 168 | mainCtx->submit(); |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 169 | |
| Brian Salomon | d63638b | 2021-03-05 14:00:07 -0500 | [diff] [blame] | 170 | GrBackendTexture backendTexture = mainSurface->getBackendTexture( |
| 171 | SkSurface::BackendHandleAccess::kFlushRead_BackendHandleAccess); |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 172 | |
| Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 173 | draw_child(reporter, childInfo1, backendTexture, semaphores[0]); |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 174 | |
| 175 | #ifdef SK_VULKAN |
| Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 176 | if (GrBackendApi::kVulkan == mainInfo.backend()) { |
| Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 177 | // In Vulkan we need to make sure we are sending the correct VkImageLayout in with the |
| 178 | // backendImage. After the first child draw the layout gets changed to SHADER_READ, so |
| 179 | // we just manually set that here. |
| Jim Van Verth | 6ec5688 | 2020-03-26 11:47:26 -0400 | [diff] [blame] | 180 | backendTexture.setVkImageLayout(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))); |
| Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 214 | if (ctxInfo.directContext()) { |
| Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 215 | sk_gpu_test::ContextInfo child1 = |
| Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 216 | factory.getSharedContextInfo(ctxInfo.directContext(), 0); |
| Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 217 | sk_gpu_test::ContextInfo child2 = |
| Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 218 | factory.getSharedContextInfo(ctxInfo.directContext(), 1); |
| Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 219 | if (!child1.directContext() || !child2.directContext()) { |
| Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 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) { |
| Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 231 | auto ctx = ctxInfo.directContext(); |
| 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. |
| Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 244 | mainSurface->flushAndSubmit(); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 245 | |
| 246 | GrBackendSemaphore semaphore; |
| Greg Daniel | 49de103 | 2020-05-19 18:06:26 -0400 | [diff] [blame] | 247 | GrFlushInfo flushInfo; |
| 248 | flushInfo.fNumSemaphores = 1; |
| 249 | flushInfo.fSignalSemaphores = &semaphore; |
| Greg Daniel | 04283f3 | 2020-05-20 13:16:00 -0400 | [diff] [blame] | 250 | GrSemaphoresSubmitted submitted = |
| 251 | mainSurface->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo); |
| Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 252 | REPORTER_ASSERT(reporter, GrSemaphoresSubmitted::kYes == submitted); |
| Greg Daniel | 04283f3 | 2020-05-20 13:16:00 -0400 | [diff] [blame] | 253 | ctx->submit(); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 254 | |
| John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 255 | #ifdef SK_GL |
| Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 256 | if (GrBackendApi::kOpenGL == ctxInfo.backend()) { |
| Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 257 | GrGLGpu* gpu = static_cast<GrGLGpu*>(ctx->priv().getGpu()); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 258 | const GrGLInterface* interface = gpu->glInterface(); |
| 259 | GrGLsync sync = semaphore.glSync(); |
| 260 | REPORTER_ASSERT(reporter, sync); |
| 261 | bool result; |
| 262 | GR_GL_CALL_RET(interface, result, IsSync(sync)); |
| 263 | REPORTER_ASSERT(reporter, result); |
| 264 | } |
| John Rosasco | a9b348f | 2019-11-08 13:18:15 -0800 | [diff] [blame] | 265 | #endif |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 266 | |
| 267 | #ifdef SK_VULKAN |
| Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 268 | if (GrBackendApi::kVulkan == ctxInfo.backend()) { |
| Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 269 | GrVkGpu* gpu = static_cast<GrVkGpu*>(ctx->priv().getGpu()); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 270 | const GrVkInterface* interface = gpu->vkInterface(); |
| 271 | VkDevice device = gpu->device(); |
| 272 | VkQueue queue = gpu->queue(); |
| Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 273 | GrVkCommandPool* cmdPool = gpu->cmdPool(); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 274 | VkCommandBuffer cmdBuffer; |
| 275 | |
| 276 | // Create Command Buffer |
| 277 | const VkCommandBufferAllocateInfo cmdInfo = { |
| 278 | VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType |
| 279 | nullptr, // pNext |
| Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 280 | cmdPool->vkCommandPool(), // commandPool |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 281 | VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level |
| 282 | 1 // bufferCount |
| 283 | }; |
| 284 | |
| 285 | VkResult err = GR_VK_CALL(interface, AllocateCommandBuffers(device, &cmdInfo, &cmdBuffer)); |
| 286 | if (err) { |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | VkCommandBufferBeginInfo cmdBufferBeginInfo; |
| 291 | memset(&cmdBufferBeginInfo, 0, sizeof(VkCommandBufferBeginInfo)); |
| 292 | cmdBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 293 | cmdBufferBeginInfo.pNext = nullptr; |
| 294 | cmdBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 295 | cmdBufferBeginInfo.pInheritanceInfo = nullptr; |
| 296 | |
| Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 297 | GR_VK_CALL_ERRCHECK(gpu, BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo)); |
| 298 | GR_VK_CALL_ERRCHECK(gpu, EndCommandBuffer(cmdBuffer)); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 299 | |
| 300 | VkFenceCreateInfo fenceInfo; |
| 301 | VkFence fence; |
| 302 | |
| 303 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 304 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 305 | err = GR_VK_CALL(interface, CreateFence(device, &fenceInfo, nullptr, &fence)); |
| 306 | SkASSERT(!err); |
| 307 | |
| 308 | VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; |
| 309 | VkSubmitInfo submitInfo; |
| 310 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 311 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 312 | submitInfo.pNext = nullptr; |
| 313 | submitInfo.waitSemaphoreCount = 1; |
| 314 | VkSemaphore vkSem = semaphore.vkSemaphore(); |
| 315 | submitInfo.pWaitSemaphores = &vkSem; |
| 316 | submitInfo.pWaitDstStageMask = &waitStages; |
| 317 | submitInfo.commandBufferCount = 1; |
| 318 | submitInfo.pCommandBuffers = &cmdBuffer; |
| 319 | submitInfo.signalSemaphoreCount = 0; |
| 320 | submitInfo.pSignalSemaphores = nullptr; |
| Greg Daniel | e643da6 | 2019-11-05 12:36:42 -0500 | [diff] [blame] | 321 | GR_VK_CALL_ERRCHECK(gpu, QueueSubmit(queue, 1, &submitInfo, fence)); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 322 | |
| 323 | err = GR_VK_CALL(interface, WaitForFences(device, 1, &fence, true, 3000000000)); |
| 324 | |
| 325 | REPORTER_ASSERT(reporter, err != VK_TIMEOUT); |
| 326 | |
| 327 | GR_VK_CALL(interface, DestroyFence(device, fence, nullptr)); |
| 328 | GR_VK_CALL(interface, DestroySemaphore(device, vkSem, nullptr)); |
| 329 | // If the above test fails the wait semaphore will never be signaled which can cause the |
| 330 | // device to hang when tearing down (even if just tearing down GL). So we Fail here to |
| 331 | // kill things. |
| 332 | if (err == VK_TIMEOUT) { |
| Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 333 | SK_ABORT("Waiting on semaphore indefinitely"); |
| Greg Daniel | dba7e7c | 2017-07-20 15:47:30 -0400 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | #endif |
| 337 | } |