jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
Greg Daniel | 54bfb18 | 2018-11-20 17:12:36 -0500 | [diff] [blame] | 9 | #include "VulkanWindowContext.h" |
| 10 | |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 11 | #include "GrBackendSemaphore.h" |
Greg Daniel | e79b473 | 2017-04-20 14:07:46 -0400 | [diff] [blame] | 12 | #include "GrBackendSurface.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 13 | #include "GrContext.h" |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 14 | #include "SkAutoMalloc.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 15 | #include "SkSurface.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 16 | |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame] | 17 | #include "vk/GrVkExtensions.h" |
Greg Daniel | 6ddbafc | 2018-05-24 12:34:29 -0400 | [diff] [blame] | 18 | #include "vk/GrVkImage.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 19 | #include "vk/GrVkTypes.h" |
Greg Daniel | a31f4e5 | 2018-08-01 16:48:52 -0400 | [diff] [blame] | 20 | #include "vk/GrVkUtil.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 21 | |
| 22 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 23 | // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
| 24 | #undef CreateSemaphore |
| 25 | #endif |
| 26 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 27 | #define GET_PROC(F) f ## F = (PFN_vk ## F) fGetInstanceProcAddr(fInstance, "vk" #F) |
| 28 | #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) fGetDeviceProcAddr(fDevice, "vk" #F) |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 29 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 30 | namespace sk_app { |
| 31 | |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 32 | VulkanWindowContext::VulkanWindowContext(const DisplayParams& params, |
| 33 | CreateVkSurfaceFn createVkSurface, |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame] | 34 | CanPresentFn canPresent, |
| 35 | PFN_vkGetInstanceProcAddr instProc, |
| 36 | PFN_vkGetDeviceProcAddr devProc) |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 37 | : WindowContext(params) |
| 38 | , fCreateVkSurfaceFn(createVkSurface) |
| 39 | , fCanPresentFn(canPresent) |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 40 | , fSurface(VK_NULL_HANDLE) |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 41 | , fSwapchain(VK_NULL_HANDLE) |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 42 | , fImages(nullptr) |
| 43 | , fImageLayouts(nullptr) |
| 44 | , fSurfaces(nullptr) |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 45 | , fBackbuffers(nullptr) { |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame] | 46 | fGetInstanceProcAddr = instProc; |
| 47 | fGetDeviceProcAddr = devProc; |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 48 | this->initializeContext(); |
| 49 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 50 | |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 51 | void VulkanWindowContext::initializeContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 52 | // any config code here (particularly for msaa)? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 53 | |
Greg Daniel | d3e65aa | 2018-08-01 09:19:45 -0400 | [diff] [blame] | 54 | PFN_vkGetInstanceProcAddr getInstanceProc = fGetInstanceProcAddr; |
| 55 | PFN_vkGetDeviceProcAddr getDeviceProc = fGetDeviceProcAddr; |
| 56 | auto getProc = [getInstanceProc, getDeviceProc](const char* proc_name, |
| 57 | VkInstance instance, VkDevice device) { |
| 58 | if (device != VK_NULL_HANDLE) { |
| 59 | return getDeviceProc(device, proc_name); |
| 60 | } |
| 61 | return getInstanceProc(instance, proc_name); |
| 62 | }; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 63 | GrVkBackendContext backendContext; |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame] | 64 | GrVkExtensions extensions; |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 65 | VkPhysicalDeviceFeatures2 features; |
| 66 | if (!sk_gpu_test::CreateVkBackendContext(getProc, &backendContext, &extensions, &features, |
| 67 | &fDebugCallback, &fPresentQueueIndex, fCanPresentFn)) { |
| 68 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | |
Greg Daniel | a31f4e5 | 2018-08-01 16:48:52 -0400 | [diff] [blame] | 72 | if (!extensions.hasExtension(VK_KHR_SURFACE_EXTENSION_NAME, 25) || |
| 73 | !extensions.hasExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME, 68)) { |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 74 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 75 | return; |
| 76 | } |
| 77 | |
| 78 | fInstance = backendContext.fInstance; |
| 79 | fPhysicalDevice = backendContext.fPhysicalDevice; |
| 80 | fDevice = backendContext.fDevice; |
| 81 | fGraphicsQueueIndex = backendContext.fGraphicsQueueIndex; |
| 82 | fGraphicsQueue = backendContext.fQueue; |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 83 | |
| 84 | PFN_vkGetPhysicalDeviceProperties localGetPhysicalDeviceProperties = |
| 85 | reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>( |
| 86 | backendContext.fGetProc("vkGetPhysicalDeviceProperties", |
| 87 | backendContext.fInstance, |
| 88 | VK_NULL_HANDLE)); |
| 89 | if (!localGetPhysicalDeviceProperties) { |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 90 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | VkPhysicalDeviceProperties physDeviceProperties; |
| 94 | localGetPhysicalDeviceProperties(backendContext.fPhysicalDevice, &physDeviceProperties); |
| 95 | uint32_t physDevVersion = physDeviceProperties.apiVersion; |
| 96 | |
Greg Daniel | c8cd45a | 2018-07-12 10:02:37 -0400 | [diff] [blame] | 97 | fInterface.reset(new GrVkInterface(backendContext.fGetProc, fInstance, fDevice, |
Greg Daniel | c0b03d8 | 2018-08-03 14:41:15 -0400 | [diff] [blame] | 98 | backendContext.fInstanceVersion, physDevVersion, |
Greg Daniel | 98bffae | 2018-08-01 13:25:41 -0400 | [diff] [blame] | 99 | &extensions)); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 100 | |
| 101 | GET_PROC(DestroyInstance); |
Greg Daniel | a31f4e5 | 2018-08-01 16:48:52 -0400 | [diff] [blame] | 102 | if (fDebugCallback != VK_NULL_HANDLE) { |
| 103 | GET_PROC(DestroyDebugReportCallbackEXT); |
| 104 | } |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 105 | GET_PROC(DestroySurfaceKHR); |
| 106 | GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); |
| 107 | GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); |
| 108 | GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); |
| 109 | GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 110 | GET_DEV_PROC(DeviceWaitIdle); |
| 111 | GET_DEV_PROC(QueueWaitIdle); |
| 112 | GET_DEV_PROC(DestroyDevice); |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 113 | GET_DEV_PROC(CreateSwapchainKHR); |
| 114 | GET_DEV_PROC(DestroySwapchainKHR); |
| 115 | GET_DEV_PROC(GetSwapchainImagesKHR); |
| 116 | GET_DEV_PROC(AcquireNextImageKHR); |
| 117 | GET_DEV_PROC(QueuePresentKHR); |
Greg Daniel | 35970ec | 2017-11-10 10:03:05 -0500 | [diff] [blame] | 118 | GET_DEV_PROC(GetDeviceQueue); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 119 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 120 | fContext = GrContext::MakeVulkan(backendContext, fDisplayParams.fGrContextOptions); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 121 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 122 | fSurface = fCreateVkSurfaceFn(fInstance); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 123 | if (VK_NULL_HANDLE == fSurface) { |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 124 | this->destroyContext(); |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 125 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 129 | VkBool32 supported; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 130 | VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fPhysicalDevice, fPresentQueueIndex, |
| 131 | fSurface, &supported); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 132 | if (VK_SUCCESS != res) { |
| 133 | this->destroyContext(); |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 134 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 138 | if (!this->createSwapchain(-1, -1, fDisplayParams)) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 139 | this->destroyContext(); |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 140 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 141 | return; |
| 142 | } |
| 143 | |
| 144 | // create presentQueue |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 145 | fGetDeviceQueue(fDevice, fPresentQueueIndex, 0, &fPresentQueue); |
Greg Daniel | a0651ac | 2018-08-08 09:23:18 -0400 | [diff] [blame] | 146 | sk_gpu_test::FreeVulkanFeaturesStructs(&features); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 147 | } |
| 148 | |
bsalomon | ccde4ab | 2016-07-27 08:50:12 -0700 | [diff] [blame] | 149 | bool VulkanWindowContext::createSwapchain(int width, int height, |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 150 | const DisplayParams& params) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 151 | // check for capabilities |
| 152 | VkSurfaceCapabilitiesKHR caps; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 153 | VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fPhysicalDevice, fSurface, &caps); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 154 | if (VK_SUCCESS != res) { |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | uint32_t surfaceFormatCount; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 159 | res = fGetPhysicalDeviceSurfaceFormatsKHR(fPhysicalDevice, fSurface, &surfaceFormatCount, |
| 160 | nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 161 | if (VK_SUCCESS != res) { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | SkAutoMalloc surfaceFormatAlloc(surfaceFormatCount * sizeof(VkSurfaceFormatKHR)); |
| 166 | VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)surfaceFormatAlloc.get(); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 167 | res = fGetPhysicalDeviceSurfaceFormatsKHR(fPhysicalDevice, fSurface, &surfaceFormatCount, |
| 168 | surfaceFormats); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 169 | if (VK_SUCCESS != res) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | uint32_t presentModeCount; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 174 | res = fGetPhysicalDeviceSurfacePresentModesKHR(fPhysicalDevice, fSurface, &presentModeCount, |
| 175 | nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 176 | if (VK_SUCCESS != res) { |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); |
| 181 | VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 182 | res = fGetPhysicalDeviceSurfacePresentModesKHR(fPhysicalDevice, fSurface, &presentModeCount, |
| 183 | presentModes); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 184 | if (VK_SUCCESS != res) { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | VkExtent2D extent = caps.currentExtent; |
| 189 | // use the hints |
| 190 | if (extent.width == (uint32_t)-1) { |
| 191 | extent.width = width; |
| 192 | extent.height = height; |
| 193 | } |
| 194 | |
jvanverth | 9fab59d | 2016-04-06 12:08:51 -0700 | [diff] [blame] | 195 | // clamp width; to protect us from broken hints |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 196 | if (extent.width < caps.minImageExtent.width) { |
| 197 | extent.width = caps.minImageExtent.width; |
| 198 | } else if (extent.width > caps.maxImageExtent.width) { |
| 199 | extent.width = caps.maxImageExtent.width; |
| 200 | } |
| 201 | // clamp height |
| 202 | if (extent.height < caps.minImageExtent.height) { |
| 203 | extent.height = caps.minImageExtent.height; |
| 204 | } else if (extent.height > caps.maxImageExtent.height) { |
| 205 | extent.height = caps.maxImageExtent.height; |
| 206 | } |
jvanverth | 1d15596 | 2016-05-23 13:13:36 -0700 | [diff] [blame] | 207 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 208 | fWidth = (int)extent.width; |
| 209 | fHeight = (int)extent.height; |
| 210 | |
| 211 | uint32_t imageCount = caps.minImageCount + 2; |
| 212 | if (caps.maxImageCount > 0 && imageCount > caps.maxImageCount) { |
| 213 | // Application must settle for fewer images than desired: |
| 214 | imageCount = caps.maxImageCount; |
| 215 | } |
| 216 | |
| 217 | VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 218 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 219 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 220 | SkASSERT((caps.supportedUsageFlags & usageFlags) == usageFlags); |
| 221 | SkASSERT(caps.supportedTransforms & caps.currentTransform); |
| 222 | SkASSERT(caps.supportedCompositeAlpha & (VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR | |
| 223 | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR)); |
| 224 | VkCompositeAlphaFlagBitsKHR composite_alpha = |
| 225 | (caps.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) ? |
| 226 | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR : |
| 227 | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 228 | |
Brian Osman | 294fe29 | 2018-07-09 10:23:19 -0400 | [diff] [blame] | 229 | // Pick our surface format. |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 230 | VkFormat surfaceFormat = VK_FORMAT_UNDEFINED; |
| 231 | VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 232 | for (uint32_t i = 0; i < surfaceFormatCount; ++i) { |
Greg Daniel | 81b8059 | 2017-12-13 10:20:04 -0500 | [diff] [blame] | 233 | VkFormat localFormat = surfaceFormats[i].format; |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 234 | if (GrVkFormatIsSupported(localFormat)) { |
Greg Daniel | 81b8059 | 2017-12-13 10:20:04 -0500 | [diff] [blame] | 235 | surfaceFormat = localFormat; |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 236 | colorSpace = surfaceFormats[i].colorSpace; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | fDisplayParams = params; |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 241 | fSampleCount = params.fMSAASampleCount; |
| 242 | fStencilBits = 8; |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 243 | |
| 244 | if (VK_FORMAT_UNDEFINED == surfaceFormat) { |
| 245 | return false; |
| 246 | } |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 247 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 248 | SkColorType colorType; |
| 249 | switch (surfaceFormat) { |
| 250 | case VK_FORMAT_R8G8B8A8_UNORM: // fall through |
| 251 | case VK_FORMAT_R8G8B8A8_SRGB: |
| 252 | colorType = kRGBA_8888_SkColorType; |
| 253 | break; |
| 254 | case VK_FORMAT_B8G8R8A8_UNORM: // fall through |
| 255 | case VK_FORMAT_B8G8R8A8_SRGB: |
| 256 | colorType = kBGRA_8888_SkColorType; |
| 257 | break; |
| 258 | default: |
| 259 | return false; |
| 260 | } |
| 261 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 262 | // If mailbox mode is available, use it, as it is the lowest-latency non- |
| 263 | // tearing mode. If not, fall back to FIFO which is always available. |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 264 | VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR; |
Greg Daniel | bb792aa | 2019-03-25 13:42:33 -0400 | [diff] [blame] | 265 | bool hasImmediate = false; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 266 | for (uint32_t i = 0; i < presentModeCount; ++i) { |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 267 | // use mailbox |
| 268 | if (VK_PRESENT_MODE_MAILBOX_KHR == presentModes[i]) { |
Greg Daniel | bb792aa | 2019-03-25 13:42:33 -0400 | [diff] [blame] | 269 | mode = VK_PRESENT_MODE_MAILBOX_KHR; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 270 | } |
Greg Daniel | bb792aa | 2019-03-25 13:42:33 -0400 | [diff] [blame] | 271 | if (VK_PRESENT_MODE_IMMEDIATE_KHR == presentModes[i]) { |
| 272 | hasImmediate = true; |
| 273 | } |
| 274 | } |
| 275 | if (params.fDisableVsync && hasImmediate) { |
| 276 | mode = VK_PRESENT_MODE_IMMEDIATE_KHR; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | VkSwapchainCreateInfoKHR swapchainCreateInfo; |
| 280 | memset(&swapchainCreateInfo, 0, sizeof(VkSwapchainCreateInfoKHR)); |
| 281 | swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 282 | swapchainCreateInfo.surface = fSurface; |
| 283 | swapchainCreateInfo.minImageCount = imageCount; |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 284 | swapchainCreateInfo.imageFormat = surfaceFormat; |
| 285 | swapchainCreateInfo.imageColorSpace = colorSpace; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 286 | swapchainCreateInfo.imageExtent = extent; |
| 287 | swapchainCreateInfo.imageArrayLayers = 1; |
| 288 | swapchainCreateInfo.imageUsage = usageFlags; |
| 289 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 290 | uint32_t queueFamilies[] = { fGraphicsQueueIndex, fPresentQueueIndex }; |
| 291 | if (fGraphicsQueueIndex != fPresentQueueIndex) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 292 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 293 | swapchainCreateInfo.queueFamilyIndexCount = 2; |
| 294 | swapchainCreateInfo.pQueueFamilyIndices = queueFamilies; |
| 295 | } else { |
| 296 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 297 | swapchainCreateInfo.queueFamilyIndexCount = 0; |
| 298 | swapchainCreateInfo.pQueueFamilyIndices = nullptr; |
| 299 | } |
| 300 | |
Greg Daniel | e897b97 | 2016-10-06 13:57:57 -0400 | [diff] [blame] | 301 | swapchainCreateInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 302 | swapchainCreateInfo.compositeAlpha = composite_alpha; |
| 303 | swapchainCreateInfo.presentMode = mode; |
| 304 | swapchainCreateInfo.clipped = true; |
| 305 | swapchainCreateInfo.oldSwapchain = fSwapchain; |
| 306 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 307 | res = fCreateSwapchainKHR(fDevice, &swapchainCreateInfo, nullptr, &fSwapchain); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 308 | if (VK_SUCCESS != res) { |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | // destroy the old swapchain |
| 313 | if (swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE) { |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 314 | fDeviceWaitIdle(fDevice); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 315 | |
| 316 | this->destroyBuffers(); |
| 317 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 318 | fDestroySwapchainKHR(fDevice, swapchainCreateInfo.oldSwapchain, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 321 | this->createBuffers(swapchainCreateInfo.imageFormat, colorType); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 322 | |
| 323 | return true; |
| 324 | } |
| 325 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 326 | void VulkanWindowContext::createBuffers(VkFormat format, SkColorType colorType) { |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 327 | fGetSwapchainImagesKHR(fDevice, fSwapchain, &fImageCount, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 328 | SkASSERT(fImageCount); |
| 329 | fImages = new VkImage[fImageCount]; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 330 | fGetSwapchainImagesKHR(fDevice, fSwapchain, &fImageCount, fImages); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 331 | |
| 332 | // set up initial image layouts and create surfaces |
| 333 | fImageLayouts = new VkImageLayout[fImageCount]; |
| 334 | fSurfaces = new sk_sp<SkSurface>[fImageCount]; |
| 335 | for (uint32_t i = 0; i < fImageCount; ++i) { |
| 336 | fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; |
| 337 | |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 338 | GrVkImageInfo info; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 339 | info.fImage = fImages[i]; |
Greg Daniel | 8385a8a | 2018-02-26 13:29:37 -0500 | [diff] [blame] | 340 | info.fAlloc = GrVkAlloc(); |
egdaniel | 580fa59 | 2016-08-31 11:03:50 -0700 | [diff] [blame] | 341 | info.fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 342 | info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 343 | info.fFormat = format; |
jvanverth | 3622a17 | 2016-05-10 06:42:18 -0700 | [diff] [blame] | 344 | info.fLevelCount = 1; |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 345 | info.fCurrentQueueFamily = fPresentQueueIndex; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 346 | |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 347 | GrBackendRenderTarget backendRT(fWidth, fHeight, fSampleCount, info); |
Greg Daniel | e79b473 | 2017-04-20 14:07:46 -0400 | [diff] [blame] | 348 | |
Brian Salomon | afdc6b1 | 2018-03-09 12:02:32 -0500 | [diff] [blame] | 349 | fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext.get(), |
| 350 | backendRT, |
| 351 | kTopLeft_GrSurfaceOrigin, |
| 352 | colorType, |
| 353 | fDisplayParams.fColorSpace, |
Ben Wagner | 37c5403 | 2018-04-13 14:30:23 -0400 | [diff] [blame] | 354 | &fDisplayParams.fSurfaceProps); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 355 | } |
| 356 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 357 | // set up the backbuffers |
| 358 | VkSemaphoreCreateInfo semaphoreInfo; |
| 359 | memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
| 360 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 361 | semaphoreInfo.pNext = nullptr; |
| 362 | semaphoreInfo.flags = 0; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 363 | |
Greg Daniel | 1f05f44 | 2016-10-27 16:37:17 -0400 | [diff] [blame] | 364 | // we create one additional backbuffer structure here, because we want to |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 365 | // give the command buffers they contain a chance to finish before we cycle back |
| 366 | fBackbuffers = new BackbufferInfo[fImageCount + 1]; |
| 367 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
| 368 | fBackbuffers[i].fImageIndex = -1; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 369 | GR_VK_CALL_ERRCHECK(fInterface, |
| 370 | CreateSemaphore(fDevice, &semaphoreInfo, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 371 | nullptr, &fBackbuffers[i].fRenderSemaphore)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 372 | } |
| 373 | fCurrentBackbufferIndex = fImageCount; |
| 374 | } |
| 375 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 376 | void VulkanWindowContext::destroyBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 377 | |
| 378 | if (fBackbuffers) { |
| 379 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 380 | fBackbuffers[i].fImageIndex = -1; |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 381 | GR_VK_CALL(fInterface, |
| 382 | DestroySemaphore(fDevice, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 383 | fBackbuffers[i].fRenderSemaphore, |
| 384 | nullptr)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | delete[] fBackbuffers; |
| 389 | fBackbuffers = nullptr; |
| 390 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 391 | // Does this actually free the surfaces? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 392 | delete[] fSurfaces; |
| 393 | fSurfaces = nullptr; |
| 394 | delete[] fImageLayouts; |
| 395 | fImageLayouts = nullptr; |
| 396 | delete[] fImages; |
| 397 | fImages = nullptr; |
| 398 | } |
| 399 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 400 | VulkanWindowContext::~VulkanWindowContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 401 | this->destroyContext(); |
| 402 | } |
| 403 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 404 | void VulkanWindowContext::destroyContext() { |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 405 | if (this->isValid()) { |
| 406 | fQueueWaitIdle(fPresentQueue); |
| 407 | fDeviceWaitIdle(fDevice); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 408 | |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 409 | this->destroyBuffers(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 410 | |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 411 | if (VK_NULL_HANDLE != fSwapchain) { |
| 412 | fDestroySwapchainKHR(fDevice, fSwapchain, nullptr); |
| 413 | fSwapchain = VK_NULL_HANDLE; |
| 414 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 415 | |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 416 | if (VK_NULL_HANDLE != fSurface) { |
| 417 | fDestroySurfaceKHR(fInstance, fSurface, nullptr); |
| 418 | fSurface = VK_NULL_HANDLE; |
| 419 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 422 | fContext.reset(); |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 423 | fInterface.reset(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 424 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 425 | if (VK_NULL_HANDLE != fDevice) { |
| 426 | fDestroyDevice(fDevice, nullptr); |
| 427 | fDevice = VK_NULL_HANDLE; |
| 428 | } |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 429 | |
| 430 | #ifdef SK_ENABLE_VK_LAYERS |
| 431 | if (fDebugCallback != VK_NULL_HANDLE) { |
Greg Daniel | a31f4e5 | 2018-08-01 16:48:52 -0400 | [diff] [blame] | 432 | fDestroyDebugReportCallbackEXT(fInstance, fDebugCallback, nullptr); |
Greg Daniel | 37329b3 | 2018-07-02 20:16:44 +0000 | [diff] [blame] | 433 | } |
| 434 | #endif |
| 435 | |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 436 | fPhysicalDevice = VK_NULL_HANDLE; |
| 437 | |
| 438 | if (VK_NULL_HANDLE != fInstance) { |
| 439 | fDestroyInstance(fInstance, nullptr); |
| 440 | fInstance = VK_NULL_HANDLE; |
| 441 | } |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 442 | } |
| 443 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 444 | VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 445 | SkASSERT(fBackbuffers); |
| 446 | |
| 447 | ++fCurrentBackbufferIndex; |
egdaniel | 804af7d | 2016-09-26 12:30:46 -0700 | [diff] [blame] | 448 | if (fCurrentBackbufferIndex > fImageCount) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 449 | fCurrentBackbufferIndex = 0; |
| 450 | } |
| 451 | |
| 452 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 453 | return backbuffer; |
| 454 | } |
| 455 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 456 | sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 457 | BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
| 458 | SkASSERT(backbuffer); |
| 459 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 460 | // semaphores should be in unsignaled state |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 461 | VkSemaphoreCreateInfo semaphoreInfo; |
| 462 | memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
| 463 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 464 | semaphoreInfo.pNext = nullptr; |
| 465 | semaphoreInfo.flags = 0; |
| 466 | VkSemaphore semaphore; |
| 467 | GR_VK_CALL_ERRCHECK(fInterface, CreateSemaphore(fDevice, &semaphoreInfo, |
| 468 | nullptr, &semaphore)); |
| 469 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 470 | // acquire the image |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 471 | VkResult res = fAcquireNextImageKHR(fDevice, fSwapchain, UINT64_MAX, |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 472 | semaphore, VK_NULL_HANDLE, |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 473 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 474 | if (VK_ERROR_SURFACE_LOST_KHR == res) { |
| 475 | // need to figure out how to create a new vkSurface without the platformData* |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 476 | // maybe use attach somehow? but need a Window |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 477 | GR_VK_CALL(fInterface, DestroySemaphore(fDevice, semaphore, nullptr)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 478 | return nullptr; |
| 479 | } |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 480 | if (VK_ERROR_OUT_OF_DATE_KHR == res) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 481 | // tear swapchain down and try again |
Greg Daniel | 1f05f44 | 2016-10-27 16:37:17 -0400 | [diff] [blame] | 482 | if (!this->createSwapchain(-1, -1, fDisplayParams)) { |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 483 | GR_VK_CALL(fInterface, DestroySemaphore(fDevice, semaphore, nullptr)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 484 | return nullptr; |
| 485 | } |
Jim Van Verth | d63c102 | 2017-01-05 13:50:49 -0500 | [diff] [blame] | 486 | backbuffer = this->getAvailableBackbuffer(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 487 | |
| 488 | // acquire the image |
Greg Daniel | f730c18 | 2018-07-02 20:15:37 +0000 | [diff] [blame] | 489 | res = fAcquireNextImageKHR(fDevice, fSwapchain, UINT64_MAX, |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 490 | semaphore, VK_NULL_HANDLE, |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 491 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 492 | |
| 493 | if (VK_SUCCESS != res) { |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 494 | GR_VK_CALL(fInterface, DestroySemaphore(fDevice, semaphore, nullptr)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 495 | return nullptr; |
| 496 | } |
| 497 | } |
| 498 | |
egdaniel | 580fa59 | 2016-08-31 11:03:50 -0700 | [diff] [blame] | 499 | SkSurface* surface = fSurfaces[backbuffer->fImageIndex].get(); |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 500 | |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 501 | GrBackendSemaphore beSemaphore; |
| 502 | beSemaphore.initVulkan(semaphore); |
| 503 | |
| 504 | surface->wait(1, &beSemaphore); |
egdaniel | 580fa59 | 2016-08-31 11:03:50 -0700 | [diff] [blame] | 505 | |
| 506 | return sk_ref_sp(surface); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 507 | } |
| 508 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 509 | void VulkanWindowContext::swapBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 510 | |
| 511 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
egdaniel | 580fa59 | 2016-08-31 11:03:50 -0700 | [diff] [blame] | 512 | SkSurface* surface = fSurfaces[backbuffer->fImageIndex].get(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 513 | |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 514 | GrBackendSemaphore beSemaphore; |
| 515 | beSemaphore.initVulkan(backbuffer->fRenderSemaphore); |
Robert Phillips | ba375a8 | 2018-04-11 10:08:06 -0400 | [diff] [blame] | 516 | |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame^] | 517 | GrFlushInfo info; |
| 518 | info.fNumSemaphores = 1; |
| 519 | info.fSignalSemaphores = &beSemaphore; |
| 520 | surface->flush(SkSurface::BackendSurfaceAccess::kPresent, info); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 521 | |
| 522 | // Submit present operation to present queue |
| 523 | const VkPresentInfoKHR presentInfo = |
| 524 | { |
| 525 | VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType |
| 526 | NULL, // pNext |
| 527 | 1, // waitSemaphoreCount |
| 528 | &backbuffer->fRenderSemaphore, // pWaitSemaphores |
| 529 | 1, // swapchainCount |
| 530 | &fSwapchain, // pSwapchains |
| 531 | &backbuffer->fImageIndex, // pImageIndices |
| 532 | NULL // pResults |
| 533 | }; |
| 534 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 535 | fQueuePresentKHR(fPresentQueue, &presentInfo); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 536 | } |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 537 | |
| 538 | } //namespace sk_app |