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 | |
| 9 | #include "GrContext.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 10 | #include "GrRenderTarget.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 11 | #include "SkSurface.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 12 | #include "VulkanWindowContext.h" |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 13 | |
| 14 | #include "vk/GrVkInterface.h" |
| 15 | #include "vk/GrVkUtil.h" |
| 16 | #include "vk/GrVkTypes.h" |
| 17 | |
| 18 | #ifdef VK_USE_PLATFORM_WIN32_KHR |
| 19 | // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
| 20 | #undef CreateSemaphore |
| 21 | #endif |
| 22 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 23 | #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F) |
| 24 | #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F) |
| 25 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 26 | namespace sk_app { |
| 27 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 28 | VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams& params) |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 29 | : WindowContext() |
| 30 | , fSurface(VK_NULL_HANDLE) |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 31 | , fSwapchain(VK_NULL_HANDLE) |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 32 | , fImages(nullptr) |
| 33 | , fImageLayouts(nullptr) |
| 34 | , fSurfaces(nullptr) |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 35 | , fCommandPool(VK_NULL_HANDLE) |
| 36 | , fBackbuffers(nullptr) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 37 | |
| 38 | // any config code here (particularly for msaa)? |
| 39 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 40 | this->initializeContext(platformData, params); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 41 | } |
| 42 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 43 | void VulkanWindowContext::initializeContext(void* platformData, const DisplayParams& params) { |
jvanverth | 1d15596 | 2016-05-23 13:13:36 -0700 | [diff] [blame^] | 44 | fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPresent, |
| 45 | platformData)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 46 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 47 | if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || |
| 48 | !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { |
| 49 | fBackendContext.reset(nullptr); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | VkInstance instance = fBackendContext->fInstance; |
| 54 | VkDevice device = fBackendContext->fDevice; |
| 55 | GET_PROC(DestroySurfaceKHR); |
| 56 | GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); |
| 57 | GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); |
| 58 | GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); |
| 59 | GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); |
| 60 | GET_DEV_PROC(CreateSwapchainKHR); |
| 61 | GET_DEV_PROC(DestroySwapchainKHR); |
| 62 | GET_DEV_PROC(GetSwapchainImagesKHR); |
| 63 | GET_DEV_PROC(AcquireNextImageKHR); |
| 64 | GET_DEV_PROC(QueuePresentKHR); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 65 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 66 | fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendContext.get()); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 67 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 68 | fSurface = createVkSurface(instance, platformData); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 69 | if (VK_NULL_HANDLE == fSurface) { |
| 70 | fBackendContext.reset(nullptr); |
| 71 | return; |
| 72 | } |
| 73 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 74 | VkBool32 supported; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 75 | VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysicalDevice, |
| 76 | fPresentQueueIndex, fSurface, |
| 77 | &supported); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 78 | if (VK_SUCCESS != res) { |
| 79 | this->destroyContext(); |
| 80 | return; |
| 81 | } |
| 82 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 83 | if (!this->createSwapchain(-1, -1, params)) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 84 | this->destroyContext(); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | // create presentQueue |
| 89 | vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQueue); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 90 | } |
| 91 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 92 | bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height, |
| 93 | const DisplayParams& params) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 94 | // check for capabilities |
| 95 | VkSurfaceCapabilitiesKHR caps; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 96 | VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPhysicalDevice, |
| 97 | fSurface, &caps); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 98 | if (VK_SUCCESS != res) { |
| 99 | return false; |
| 100 | } |
| 101 | |
| 102 | uint32_t surfaceFormatCount; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 103 | res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface, |
| 104 | &surfaceFormatCount, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 105 | if (VK_SUCCESS != res) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | SkAutoMalloc surfaceFormatAlloc(surfaceFormatCount * sizeof(VkSurfaceFormatKHR)); |
| 110 | VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)surfaceFormatAlloc.get(); |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 111 | res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface, |
| 112 | &surfaceFormatCount, surfaceFormats); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 113 | if (VK_SUCCESS != res) { |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | uint32_t presentModeCount; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 118 | res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice, fSurface, |
| 119 | &presentModeCount, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 120 | if (VK_SUCCESS != res) { |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); |
| 125 | VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 126 | res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDevice, fSurface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 127 | &presentModeCount, presentModes); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 128 | if (VK_SUCCESS != res) { |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | VkExtent2D extent = caps.currentExtent; |
| 133 | // use the hints |
| 134 | if (extent.width == (uint32_t)-1) { |
| 135 | extent.width = width; |
| 136 | extent.height = height; |
| 137 | } |
| 138 | |
jvanverth | 9fab59d | 2016-04-06 12:08:51 -0700 | [diff] [blame] | 139 | // clamp width; to protect us from broken hints |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 140 | if (extent.width < caps.minImageExtent.width) { |
| 141 | extent.width = caps.minImageExtent.width; |
| 142 | } else if (extent.width > caps.maxImageExtent.width) { |
| 143 | extent.width = caps.maxImageExtent.width; |
| 144 | } |
| 145 | // clamp height |
| 146 | if (extent.height < caps.minImageExtent.height) { |
| 147 | extent.height = caps.minImageExtent.height; |
| 148 | } else if (extent.height > caps.maxImageExtent.height) { |
| 149 | extent.height = caps.maxImageExtent.height; |
| 150 | } |
jvanverth | 1d15596 | 2016-05-23 13:13:36 -0700 | [diff] [blame^] | 151 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 152 | fWidth = (int)extent.width; |
| 153 | fHeight = (int)extent.height; |
| 154 | |
| 155 | uint32_t imageCount = caps.minImageCount + 2; |
| 156 | if (caps.maxImageCount > 0 && imageCount > caps.maxImageCount) { |
| 157 | // Application must settle for fewer images than desired: |
| 158 | imageCount = caps.maxImageCount; |
| 159 | } |
| 160 | |
| 161 | VkImageUsageFlags usageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | |
| 162 | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | |
| 163 | VK_IMAGE_USAGE_TRANSFER_DST_BIT; |
| 164 | SkASSERT((caps.supportedUsageFlags & usageFlags) == usageFlags); |
| 165 | SkASSERT(caps.supportedTransforms & caps.currentTransform); |
| 166 | SkASSERT(caps.supportedCompositeAlpha & (VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR | |
| 167 | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR)); |
| 168 | VkCompositeAlphaFlagBitsKHR composite_alpha = |
| 169 | (caps.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) ? |
| 170 | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR : |
| 171 | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; |
| 172 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 173 | // Pick our surface format. For now, just make sure it matches our sRGB request: |
| 174 | VkFormat surfaceFormat = VK_FORMAT_UNDEFINED; |
| 175 | VkColorSpaceKHR colorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; |
| 176 | bool wantSRGB = kSRGB_SkColorProfileType == params.fProfileType; |
| 177 | for (uint32_t i = 0; i < surfaceFormatCount; ++i) { |
| 178 | GrPixelConfig config; |
| 179 | if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) && |
| 180 | GrPixelConfigIsSRGB(config) == wantSRGB) { |
| 181 | surfaceFormat = surfaceFormats[i].format; |
| 182 | colorSpace = surfaceFormats[i].colorSpace; |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | fDisplayParams = params; |
| 187 | |
| 188 | if (VK_FORMAT_UNDEFINED == surfaceFormat) { |
| 189 | return false; |
| 190 | } |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 191 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 192 | // If mailbox mode is available, use it, as it is the lowest-latency non- |
| 193 | // tearing mode. If not, fall back to FIFO which is always available. |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 194 | VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 195 | for (uint32_t i = 0; i < presentModeCount; ++i) { |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 196 | // use mailbox |
| 197 | if (VK_PRESENT_MODE_MAILBOX_KHR == presentModes[i]) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 198 | mode = presentModes[i]; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 199 | break; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
| 203 | VkSwapchainCreateInfoKHR swapchainCreateInfo; |
| 204 | memset(&swapchainCreateInfo, 0, sizeof(VkSwapchainCreateInfoKHR)); |
| 205 | swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 206 | swapchainCreateInfo.surface = fSurface; |
| 207 | swapchainCreateInfo.minImageCount = imageCount; |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 208 | swapchainCreateInfo.imageFormat = surfaceFormat; |
| 209 | swapchainCreateInfo.imageColorSpace = colorSpace; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 210 | swapchainCreateInfo.imageExtent = extent; |
| 211 | swapchainCreateInfo.imageArrayLayers = 1; |
| 212 | swapchainCreateInfo.imageUsage = usageFlags; |
| 213 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 214 | uint32_t queueFamilies[] = { fBackendContext->fGraphicsQueueIndex, fPresentQueueIndex }; |
| 215 | if (fBackendContext->fGraphicsQueueIndex != fPresentQueueIndex) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 216 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 217 | swapchainCreateInfo.queueFamilyIndexCount = 2; |
| 218 | swapchainCreateInfo.pQueueFamilyIndices = queueFamilies; |
| 219 | } else { |
| 220 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 221 | swapchainCreateInfo.queueFamilyIndexCount = 0; |
| 222 | swapchainCreateInfo.pQueueFamilyIndices = nullptr; |
| 223 | } |
| 224 | |
| 225 | swapchainCreateInfo.preTransform = caps.currentTransform;; |
| 226 | swapchainCreateInfo.compositeAlpha = composite_alpha; |
| 227 | swapchainCreateInfo.presentMode = mode; |
| 228 | swapchainCreateInfo.clipped = true; |
| 229 | swapchainCreateInfo.oldSwapchain = fSwapchain; |
| 230 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 231 | res = fCreateSwapchainKHR(fBackendContext->fDevice, &swapchainCreateInfo, nullptr, &fSwapchain); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 232 | if (VK_SUCCESS != res) { |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | // destroy the old swapchain |
| 237 | if (swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE) { |
| 238 | GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDevice)); |
| 239 | |
| 240 | this->destroyBuffers(); |
| 241 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 242 | fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSwapchain, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 243 | } |
| 244 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 245 | this->createBuffers(swapchainCreateInfo.imageFormat); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 246 | |
| 247 | return true; |
| 248 | } |
| 249 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 250 | void VulkanWindowContext::createBuffers(VkFormat format) { |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 251 | GrVkFormatToPixelConfig(format, &fPixelConfig); |
| 252 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 253 | fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 254 | SkASSERT(fImageCount); |
| 255 | fImages = new VkImage[fImageCount]; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 256 | fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, fImages); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 257 | |
| 258 | // set up initial image layouts and create surfaces |
| 259 | fImageLayouts = new VkImageLayout[fImageCount]; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 260 | fRenderTargets = new sk_sp<GrRenderTarget>[fImageCount]; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 261 | fSurfaces = new sk_sp<SkSurface>[fImageCount]; |
| 262 | for (uint32_t i = 0; i < fImageCount; ++i) { |
| 263 | fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; |
| 264 | |
| 265 | GrBackendRenderTargetDesc desc; |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 266 | GrVkImageInfo info; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 267 | info.fImage = fImages[i]; |
brianosman | 419ca64 | 2016-05-04 08:19:44 -0700 | [diff] [blame] | 268 | info.fAlloc = VK_NULL_HANDLE; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 269 | info.fImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 270 | info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 271 | info.fFormat = format; |
jvanverth | 3622a17 | 2016-05-10 06:42:18 -0700 | [diff] [blame] | 272 | info.fLevelCount = 1; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 273 | desc.fWidth = fWidth; |
| 274 | desc.fHeight = fHeight; |
| 275 | desc.fConfig = fPixelConfig; |
| 276 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 277 | desc.fSampleCnt = 0; |
| 278 | desc.fStencilBits = 0; |
| 279 | desc.fRenderTargetHandle = (GrBackendObject) &info; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 280 | fRenderTargets[i].reset(fContext->textureProvider()->wrapBackendRenderTarget(desc)); |
| 281 | |
| 282 | fSurfaces[i] = this->createRenderSurface(fRenderTargets[i], 24); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | // create the command pool for the command buffers |
| 286 | if (VK_NULL_HANDLE == fCommandPool) { |
| 287 | VkCommandPoolCreateInfo commandPoolInfo; |
| 288 | memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); |
| 289 | commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 290 | // this needs to be on the render queue |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 291 | commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 292 | commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 293 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 294 | CreateCommandPool(fBackendContext->fDevice, &commandPoolInfo, |
| 295 | nullptr, &fCommandPool)); |
| 296 | } |
| 297 | |
| 298 | // set up the backbuffers |
| 299 | VkSemaphoreCreateInfo semaphoreInfo; |
| 300 | memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
| 301 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 302 | semaphoreInfo.pNext = nullptr; |
| 303 | semaphoreInfo.flags = 0; |
| 304 | VkCommandBufferAllocateInfo commandBuffersInfo; |
| 305 | memset(&commandBuffersInfo, 0, sizeof(VkCommandBufferAllocateInfo)); |
| 306 | commandBuffersInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 307 | commandBuffersInfo.pNext = nullptr; |
| 308 | commandBuffersInfo.commandPool = fCommandPool; |
| 309 | commandBuffersInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 310 | commandBuffersInfo.commandBufferCount = 2; |
| 311 | VkFenceCreateInfo fenceInfo; |
| 312 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 313 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 314 | fenceInfo.pNext = nullptr; |
| 315 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
| 316 | |
| 317 | // we create one additional backbuffer structure here, because we want to |
| 318 | // give the command buffers they contain a chance to finish before we cycle back |
| 319 | fBackbuffers = new BackbufferInfo[fImageCount + 1]; |
| 320 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
| 321 | fBackbuffers[i].fImageIndex = -1; |
| 322 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 323 | CreateSemaphore(fBackendContext->fDevice, &semaphoreInfo, |
| 324 | nullptr, &fBackbuffers[i].fAcquireSemaphore)); |
| 325 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 326 | CreateSemaphore(fBackendContext->fDevice, &semaphoreInfo, |
| 327 | nullptr, &fBackbuffers[i].fRenderSemaphore)); |
| 328 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 329 | AllocateCommandBuffers(fBackendContext->fDevice, &commandBuffersInfo, |
| 330 | fBackbuffers[i].fTransitionCmdBuffers)); |
| 331 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 332 | CreateFence(fBackendContext->fDevice, &fenceInfo, nullptr, |
| 333 | &fBackbuffers[i].fUsageFences[0])); |
| 334 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 335 | CreateFence(fBackendContext->fDevice, &fenceInfo, nullptr, |
| 336 | &fBackbuffers[i].fUsageFences[1])); |
| 337 | } |
| 338 | fCurrentBackbufferIndex = fImageCount; |
| 339 | } |
| 340 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 341 | void VulkanWindowContext::destroyBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 342 | |
| 343 | if (fBackbuffers) { |
| 344 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
| 345 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 346 | WaitForFences(fBackendContext->fDevice, 2, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 347 | fBackbuffers[i].fUsageFences, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 348 | true, UINT64_MAX)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 349 | fBackbuffers[i].fImageIndex = -1; |
| 350 | GR_VK_CALL(fBackendContext->fInterface, |
| 351 | DestroySemaphore(fBackendContext->fDevice, |
| 352 | fBackbuffers[i].fAcquireSemaphore, |
| 353 | nullptr)); |
| 354 | GR_VK_CALL(fBackendContext->fInterface, |
| 355 | DestroySemaphore(fBackendContext->fDevice, |
| 356 | fBackbuffers[i].fRenderSemaphore, |
| 357 | nullptr)); |
| 358 | GR_VK_CALL(fBackendContext->fInterface, |
| 359 | FreeCommandBuffers(fBackendContext->fDevice, fCommandPool, 2, |
| 360 | fBackbuffers[i].fTransitionCmdBuffers)); |
| 361 | GR_VK_CALL(fBackendContext->fInterface, |
| 362 | DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fUsageFences[0], 0)); |
| 363 | GR_VK_CALL(fBackendContext->fInterface, |
| 364 | DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fUsageFences[1], 0)); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | delete[] fBackbuffers; |
| 369 | fBackbuffers = nullptr; |
| 370 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 371 | // Does this actually free the surfaces? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 372 | delete[] fSurfaces; |
| 373 | fSurfaces = nullptr; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 374 | delete[] fRenderTargets; |
| 375 | fRenderTargets = nullptr; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 376 | delete[] fImageLayouts; |
| 377 | fImageLayouts = nullptr; |
| 378 | delete[] fImages; |
| 379 | fImages = nullptr; |
| 380 | } |
| 381 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 382 | VulkanWindowContext::~VulkanWindowContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 383 | this->destroyContext(); |
| 384 | } |
| 385 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 386 | void VulkanWindowContext::destroyContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 387 | if (!fBackendContext.get()) { |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDevice)); |
| 392 | |
| 393 | this->destroyBuffers(); |
| 394 | |
| 395 | if (VK_NULL_HANDLE != fCommandPool) { |
| 396 | GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendContext->fDevice, |
| 397 | fCommandPool, nullptr)); |
| 398 | fCommandPool = VK_NULL_HANDLE; |
| 399 | } |
| 400 | |
| 401 | if (VK_NULL_HANDLE != fSwapchain) { |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 402 | fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 403 | fSwapchain = VK_NULL_HANDLE; |
| 404 | } |
| 405 | |
| 406 | if (VK_NULL_HANDLE != fSurface) { |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 407 | fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 408 | fSurface = VK_NULL_HANDLE; |
| 409 | } |
| 410 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 411 | fContext->abandonContext(); |
| 412 | fContext->unref(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 413 | |
| 414 | fBackendContext.reset(nullptr); |
| 415 | } |
| 416 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 417 | VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 418 | SkASSERT(fBackbuffers); |
| 419 | |
| 420 | ++fCurrentBackbufferIndex; |
| 421 | if (fCurrentBackbufferIndex > fImageCount) { |
| 422 | fCurrentBackbufferIndex = 0; |
| 423 | } |
| 424 | |
| 425 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 426 | |
| 427 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 428 | WaitForFences(fBackendContext->fDevice, 2, backbuffer->fUsageFences, |
| 429 | true, UINT64_MAX)); |
| 430 | return backbuffer; |
| 431 | } |
| 432 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 433 | sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 434 | BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
| 435 | SkASSERT(backbuffer); |
| 436 | |
| 437 | // reset the fence |
| 438 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 439 | ResetFences(fBackendContext->fDevice, 2, backbuffer->fUsageFences)); |
| 440 | // semaphores should be in unsignaled state |
| 441 | |
| 442 | // acquire the image |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 443 | VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, |
| 444 | backbuffer->fAcquireSemaphore, VK_NULL_HANDLE, |
| 445 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 446 | if (VK_ERROR_SURFACE_LOST_KHR == res) { |
| 447 | // need to figure out how to create a new vkSurface without the platformData* |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 448 | // maybe use attach somehow? but need a Window |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 449 | return nullptr; |
| 450 | } |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 451 | if (VK_ERROR_OUT_OF_DATE_KHR == res) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 452 | // tear swapchain down and try again |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 453 | if (!this->createSwapchain(0, 0, fDisplayParams)) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 454 | return nullptr; |
| 455 | } |
| 456 | |
| 457 | // acquire the image |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 458 | res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 459 | backbuffer->fAcquireSemaphore, VK_NULL_HANDLE, |
| 460 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 461 | |
| 462 | if (VK_SUCCESS != res) { |
| 463 | return nullptr; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // set up layout transfer from initial to color attachment |
| 468 | VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; |
| 469 | VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
| 470 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : |
| 471 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 472 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 473 | VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 474 | 0 : VK_ACCESS_MEMORY_READ_BIT; |
| 475 | VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 476 | |
| 477 | VkImageMemoryBarrier imageMemoryBarrier = { |
| 478 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
| 479 | NULL, // pNext |
| 480 | srcAccessMask, // outputMask |
| 481 | dstAccessMask, // inputMask |
| 482 | layout, // oldLayout |
| 483 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout |
| 484 | fPresentQueueIndex, // srcQueueFamilyIndex |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 485 | fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 486 | fImages[backbuffer->fImageIndex], // image |
| 487 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
| 488 | }; |
| 489 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 490 | ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0], 0)); |
| 491 | VkCommandBufferBeginInfo info; |
| 492 | memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
| 493 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 494 | info.flags = 0; |
| 495 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 496 | BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[0], &info)); |
| 497 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 498 | GR_VK_CALL(fBackendContext->fInterface, |
| 499 | CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0], |
| 500 | srcStageMask, dstStageMask, 0, |
| 501 | 0, nullptr, |
| 502 | 0, nullptr, |
| 503 | 1, &imageMemoryBarrier)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 504 | |
| 505 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 506 | EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0])); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 507 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 508 | VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 509 | // insert the layout transfer into the queue and wait on the acquire |
| 510 | VkSubmitInfo submitInfo; |
| 511 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 512 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 513 | submitInfo.waitSemaphoreCount = 1; |
| 514 | submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 515 | submitInfo.pWaitDstStageMask = &waitDstStageFlags; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 516 | submitInfo.commandBufferCount = 1; |
| 517 | submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; |
| 518 | submitInfo.signalSemaphoreCount = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 519 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 520 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 521 | QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 522 | backbuffer->fUsageFences[0])); |
| 523 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 524 | return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 525 | } |
| 526 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 527 | void VulkanWindowContext::swapBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 528 | |
| 529 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 530 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 531 | this->presentRenderSurface(fSurfaces[backbuffer->fImageIndex], |
| 532 | fRenderTargets[backbuffer->fImageIndex], 24); |
| 533 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 534 | VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 535 | VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 536 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
| 537 | VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 538 | VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
| 539 | |
| 540 | VkImageMemoryBarrier imageMemoryBarrier = { |
| 541 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
| 542 | NULL, // pNext |
| 543 | srcAccessMask, // outputMask |
| 544 | dstAccessMask, // inputMask |
| 545 | layout, // oldLayout |
| 546 | VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 547 | fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 548 | fPresentQueueIndex, // dstQueueFamilyIndex |
| 549 | fImages[backbuffer->fImageIndex], // image |
| 550 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
| 551 | }; |
| 552 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 553 | ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1], 0)); |
| 554 | VkCommandBufferBeginInfo info; |
| 555 | memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
| 556 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 557 | info.flags = 0; |
| 558 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 559 | BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[1], &info)); |
| 560 | GR_VK_CALL(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 561 | CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1], |
| 562 | srcStageMask, dstStageMask, 0, |
| 563 | 0, nullptr, |
| 564 | 0, nullptr, |
| 565 | 1, &imageMemoryBarrier)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 566 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 567 | EndCommandBuffer(backbuffer->fTransitionCmdBuffers[1])); |
| 568 | |
| 569 | fImageLayouts[backbuffer->fImageIndex] = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 570 | |
| 571 | // insert the layout transfer into the queue and wait on the acquire |
| 572 | VkSubmitInfo submitInfo; |
| 573 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 574 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 575 | submitInfo.waitSemaphoreCount = 0; |
| 576 | submitInfo.pWaitDstStageMask = 0; |
| 577 | submitInfo.commandBufferCount = 1; |
| 578 | submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[1]; |
| 579 | submitInfo.signalSemaphoreCount = 1; |
| 580 | submitInfo.pSignalSemaphores = &backbuffer->fRenderSemaphore; |
| 581 | |
| 582 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 583 | QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 584 | backbuffer->fUsageFences[1])); |
| 585 | |
| 586 | // Submit present operation to present queue |
| 587 | const VkPresentInfoKHR presentInfo = |
| 588 | { |
| 589 | VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType |
| 590 | NULL, // pNext |
| 591 | 1, // waitSemaphoreCount |
| 592 | &backbuffer->fRenderSemaphore, // pWaitSemaphores |
| 593 | 1, // swapchainCount |
| 594 | &fSwapchain, // pSwapchains |
| 595 | &backbuffer->fImageIndex, // pImageIndices |
| 596 | NULL // pResults |
| 597 | }; |
| 598 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 599 | fQueuePresentKHR(fPresentQueue, &presentInfo); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 600 | |
| 601 | } |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 602 | |
| 603 | } //namespace sk_app |