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; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 176 | auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 177 | bool wantSRGB = srgbColorSpace == params.fColorSpace; |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 178 | for (uint32_t i = 0; i < surfaceFormatCount; ++i) { |
| 179 | GrPixelConfig config; |
| 180 | if (GrVkFormatToPixelConfig(surfaceFormats[i].format, &config) && |
| 181 | GrPixelConfigIsSRGB(config) == wantSRGB) { |
| 182 | surfaceFormat = surfaceFormats[i].format; |
| 183 | colorSpace = surfaceFormats[i].colorSpace; |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | fDisplayParams = params; |
| 188 | |
| 189 | if (VK_FORMAT_UNDEFINED == surfaceFormat) { |
| 190 | return false; |
| 191 | } |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 192 | |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 193 | // If mailbox mode is available, use it, as it is the lowest-latency non- |
| 194 | // tearing mode. If not, fall back to FIFO which is always available. |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 195 | VkPresentModeKHR mode = VK_PRESENT_MODE_FIFO_KHR; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 196 | for (uint32_t i = 0; i < presentModeCount; ++i) { |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 197 | // use mailbox |
| 198 | if (VK_PRESENT_MODE_MAILBOX_KHR == presentModes[i]) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 199 | mode = presentModes[i]; |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 200 | break; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | VkSwapchainCreateInfoKHR swapchainCreateInfo; |
| 205 | memset(&swapchainCreateInfo, 0, sizeof(VkSwapchainCreateInfoKHR)); |
| 206 | swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
| 207 | swapchainCreateInfo.surface = fSurface; |
| 208 | swapchainCreateInfo.minImageCount = imageCount; |
jvanverth | a4b0fed | 2016-04-27 11:42:21 -0700 | [diff] [blame] | 209 | swapchainCreateInfo.imageFormat = surfaceFormat; |
| 210 | swapchainCreateInfo.imageColorSpace = colorSpace; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 211 | swapchainCreateInfo.imageExtent = extent; |
| 212 | swapchainCreateInfo.imageArrayLayers = 1; |
| 213 | swapchainCreateInfo.imageUsage = usageFlags; |
| 214 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 215 | uint32_t queueFamilies[] = { fBackendContext->fGraphicsQueueIndex, fPresentQueueIndex }; |
| 216 | if (fBackendContext->fGraphicsQueueIndex != fPresentQueueIndex) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 217 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
| 218 | swapchainCreateInfo.queueFamilyIndexCount = 2; |
| 219 | swapchainCreateInfo.pQueueFamilyIndices = queueFamilies; |
| 220 | } else { |
| 221 | swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
| 222 | swapchainCreateInfo.queueFamilyIndexCount = 0; |
| 223 | swapchainCreateInfo.pQueueFamilyIndices = nullptr; |
| 224 | } |
| 225 | |
| 226 | swapchainCreateInfo.preTransform = caps.currentTransform;; |
| 227 | swapchainCreateInfo.compositeAlpha = composite_alpha; |
| 228 | swapchainCreateInfo.presentMode = mode; |
| 229 | swapchainCreateInfo.clipped = true; |
| 230 | swapchainCreateInfo.oldSwapchain = fSwapchain; |
| 231 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 232 | res = fCreateSwapchainKHR(fBackendContext->fDevice, &swapchainCreateInfo, nullptr, &fSwapchain); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 233 | if (VK_SUCCESS != res) { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | // destroy the old swapchain |
| 238 | if (swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE) { |
| 239 | GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDevice)); |
| 240 | |
| 241 | this->destroyBuffers(); |
| 242 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 243 | fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSwapchain, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 244 | } |
| 245 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 246 | this->createBuffers(swapchainCreateInfo.imageFormat); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 247 | |
| 248 | return true; |
| 249 | } |
| 250 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 251 | void VulkanWindowContext::createBuffers(VkFormat format) { |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 252 | GrVkFormatToPixelConfig(format, &fPixelConfig); |
| 253 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 254 | fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 255 | SkASSERT(fImageCount); |
| 256 | fImages = new VkImage[fImageCount]; |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 257 | fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, fImages); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 258 | |
| 259 | // set up initial image layouts and create surfaces |
| 260 | fImageLayouts = new VkImageLayout[fImageCount]; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 261 | fRenderTargets = new sk_sp<GrRenderTarget>[fImageCount]; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 262 | fSurfaces = new sk_sp<SkSurface>[fImageCount]; |
| 263 | for (uint32_t i = 0; i < fImageCount; ++i) { |
| 264 | fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; |
| 265 | |
| 266 | GrBackendRenderTargetDesc desc; |
egdaniel | b2df0c2 | 2016-05-13 11:30:37 -0700 | [diff] [blame] | 267 | GrVkImageInfo info; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 268 | info.fImage = fImages[i]; |
jvanverth | 6b6ffc4 | 2016-06-13 14:28:07 -0700 | [diff] [blame] | 269 | info.fAlloc = { VK_NULL_HANDLE, 0, 0 }; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 270 | info.fImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 271 | info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 272 | info.fFormat = format; |
jvanverth | 3622a17 | 2016-05-10 06:42:18 -0700 | [diff] [blame] | 273 | info.fLevelCount = 1; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 274 | desc.fWidth = fWidth; |
| 275 | desc.fHeight = fHeight; |
| 276 | desc.fConfig = fPixelConfig; |
| 277 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 278 | desc.fSampleCnt = 0; |
| 279 | desc.fStencilBits = 0; |
| 280 | desc.fRenderTargetHandle = (GrBackendObject) &info; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 281 | fRenderTargets[i].reset(fContext->textureProvider()->wrapBackendRenderTarget(desc)); |
| 282 | |
| 283 | fSurfaces[i] = this->createRenderSurface(fRenderTargets[i], 24); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // create the command pool for the command buffers |
| 287 | if (VK_NULL_HANDLE == fCommandPool) { |
| 288 | VkCommandPoolCreateInfo commandPoolInfo; |
| 289 | memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); |
| 290 | commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
| 291 | // this needs to be on the render queue |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 292 | commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 293 | commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 294 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 295 | CreateCommandPool(fBackendContext->fDevice, &commandPoolInfo, |
| 296 | nullptr, &fCommandPool)); |
| 297 | } |
| 298 | |
| 299 | // set up the backbuffers |
| 300 | VkSemaphoreCreateInfo semaphoreInfo; |
| 301 | memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
| 302 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 303 | semaphoreInfo.pNext = nullptr; |
| 304 | semaphoreInfo.flags = 0; |
| 305 | VkCommandBufferAllocateInfo commandBuffersInfo; |
| 306 | memset(&commandBuffersInfo, 0, sizeof(VkCommandBufferAllocateInfo)); |
| 307 | commandBuffersInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 308 | commandBuffersInfo.pNext = nullptr; |
| 309 | commandBuffersInfo.commandPool = fCommandPool; |
| 310 | commandBuffersInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 311 | commandBuffersInfo.commandBufferCount = 2; |
| 312 | VkFenceCreateInfo fenceInfo; |
| 313 | memset(&fenceInfo, 0, sizeof(VkFenceCreateInfo)); |
| 314 | fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
| 315 | fenceInfo.pNext = nullptr; |
| 316 | fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
| 317 | |
| 318 | // we create one additional backbuffer structure here, because we want to |
| 319 | // give the command buffers they contain a chance to finish before we cycle back |
| 320 | fBackbuffers = new BackbufferInfo[fImageCount + 1]; |
| 321 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
| 322 | fBackbuffers[i].fImageIndex = -1; |
| 323 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 324 | CreateSemaphore(fBackendContext->fDevice, &semaphoreInfo, |
| 325 | nullptr, &fBackbuffers[i].fAcquireSemaphore)); |
| 326 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 327 | CreateSemaphore(fBackendContext->fDevice, &semaphoreInfo, |
| 328 | nullptr, &fBackbuffers[i].fRenderSemaphore)); |
| 329 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 330 | AllocateCommandBuffers(fBackendContext->fDevice, &commandBuffersInfo, |
| 331 | fBackbuffers[i].fTransitionCmdBuffers)); |
| 332 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 333 | CreateFence(fBackendContext->fDevice, &fenceInfo, nullptr, |
| 334 | &fBackbuffers[i].fUsageFences[0])); |
| 335 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 336 | CreateFence(fBackendContext->fDevice, &fenceInfo, nullptr, |
| 337 | &fBackbuffers[i].fUsageFences[1])); |
| 338 | } |
| 339 | fCurrentBackbufferIndex = fImageCount; |
| 340 | } |
| 341 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 342 | void VulkanWindowContext::destroyBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 343 | |
| 344 | if (fBackbuffers) { |
| 345 | for (uint32_t i = 0; i < fImageCount + 1; ++i) { |
| 346 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 347 | WaitForFences(fBackendContext->fDevice, 2, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 348 | fBackbuffers[i].fUsageFences, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 349 | true, UINT64_MAX)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 350 | fBackbuffers[i].fImageIndex = -1; |
| 351 | GR_VK_CALL(fBackendContext->fInterface, |
| 352 | DestroySemaphore(fBackendContext->fDevice, |
| 353 | fBackbuffers[i].fAcquireSemaphore, |
| 354 | nullptr)); |
| 355 | GR_VK_CALL(fBackendContext->fInterface, |
| 356 | DestroySemaphore(fBackendContext->fDevice, |
| 357 | fBackbuffers[i].fRenderSemaphore, |
| 358 | nullptr)); |
| 359 | GR_VK_CALL(fBackendContext->fInterface, |
| 360 | FreeCommandBuffers(fBackendContext->fDevice, fCommandPool, 2, |
| 361 | fBackbuffers[i].fTransitionCmdBuffers)); |
| 362 | GR_VK_CALL(fBackendContext->fInterface, |
| 363 | DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fUsageFences[0], 0)); |
| 364 | GR_VK_CALL(fBackendContext->fInterface, |
| 365 | DestroyFence(fBackendContext->fDevice, fBackbuffers[i].fUsageFences[1], 0)); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | delete[] fBackbuffers; |
| 370 | fBackbuffers = nullptr; |
| 371 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 372 | // Does this actually free the surfaces? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 373 | delete[] fSurfaces; |
| 374 | fSurfaces = nullptr; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 375 | delete[] fRenderTargets; |
| 376 | fRenderTargets = nullptr; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 377 | delete[] fImageLayouts; |
| 378 | fImageLayouts = nullptr; |
| 379 | delete[] fImages; |
| 380 | fImages = nullptr; |
| 381 | } |
| 382 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 383 | VulkanWindowContext::~VulkanWindowContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 384 | this->destroyContext(); |
| 385 | } |
| 386 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 387 | void VulkanWindowContext::destroyContext() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 388 | if (!fBackendContext.get()) { |
| 389 | return; |
| 390 | } |
| 391 | |
jvanverth | 85f758c | 2016-05-27 06:47:08 -0700 | [diff] [blame] | 392 | GR_VK_CALL(fBackendContext->fInterface, QueueWaitIdle(fPresentQueue)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 393 | GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDevice)); |
| 394 | |
| 395 | this->destroyBuffers(); |
| 396 | |
| 397 | if (VK_NULL_HANDLE != fCommandPool) { |
| 398 | GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendContext->fDevice, |
| 399 | fCommandPool, nullptr)); |
| 400 | fCommandPool = VK_NULL_HANDLE; |
| 401 | } |
| 402 | |
| 403 | if (VK_NULL_HANDLE != fSwapchain) { |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 404 | fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 405 | fSwapchain = VK_NULL_HANDLE; |
| 406 | } |
| 407 | |
| 408 | if (VK_NULL_HANDLE != fSurface) { |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 409 | fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 410 | fSurface = VK_NULL_HANDLE; |
| 411 | } |
| 412 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 413 | fContext->unref(); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 414 | |
| 415 | fBackendContext.reset(nullptr); |
| 416 | } |
| 417 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 418 | VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 419 | SkASSERT(fBackbuffers); |
| 420 | |
| 421 | ++fCurrentBackbufferIndex; |
| 422 | if (fCurrentBackbufferIndex > fImageCount) { |
| 423 | fCurrentBackbufferIndex = 0; |
| 424 | } |
| 425 | |
| 426 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 427 | |
| 428 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 429 | WaitForFences(fBackendContext->fDevice, 2, backbuffer->fUsageFences, |
| 430 | true, UINT64_MAX)); |
| 431 | return backbuffer; |
| 432 | } |
| 433 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 434 | sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 435 | BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
| 436 | SkASSERT(backbuffer); |
| 437 | |
| 438 | // reset the fence |
| 439 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 440 | ResetFences(fBackendContext->fDevice, 2, backbuffer->fUsageFences)); |
| 441 | // semaphores should be in unsignaled state |
| 442 | |
| 443 | // acquire the image |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 444 | VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, |
| 445 | backbuffer->fAcquireSemaphore, VK_NULL_HANDLE, |
| 446 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 447 | if (VK_ERROR_SURFACE_LOST_KHR == res) { |
| 448 | // need to figure out how to create a new vkSurface without the platformData* |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 449 | // maybe use attach somehow? but need a Window |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 450 | return nullptr; |
| 451 | } |
jvanverth | 3d6ed3a | 2016-04-07 11:09:51 -0700 | [diff] [blame] | 452 | if (VK_ERROR_OUT_OF_DATE_KHR == res) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 453 | // tear swapchain down and try again |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 454 | if (!this->createSwapchain(0, 0, fDisplayParams)) { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 455 | return nullptr; |
| 456 | } |
| 457 | |
| 458 | // acquire the image |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 459 | res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_MAX, |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 460 | backbuffer->fAcquireSemaphore, VK_NULL_HANDLE, |
| 461 | &backbuffer->fImageIndex); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 462 | |
| 463 | if (VK_SUCCESS != res) { |
| 464 | return nullptr; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // set up layout transfer from initial to color attachment |
| 469 | VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; |
| 470 | VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
| 471 | VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : |
| 472 | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 473 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 474 | VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 475 | 0 : VK_ACCESS_MEMORY_READ_BIT; |
| 476 | VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 477 | |
| 478 | VkImageMemoryBarrier imageMemoryBarrier = { |
| 479 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
| 480 | NULL, // pNext |
| 481 | srcAccessMask, // outputMask |
| 482 | dstAccessMask, // inputMask |
| 483 | layout, // oldLayout |
| 484 | VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout |
| 485 | fPresentQueueIndex, // srcQueueFamilyIndex |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 486 | fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 487 | fImages[backbuffer->fImageIndex], // image |
| 488 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
| 489 | }; |
| 490 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 491 | ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0], 0)); |
| 492 | VkCommandBufferBeginInfo info; |
| 493 | memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
| 494 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 495 | info.flags = 0; |
| 496 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 497 | BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[0], &info)); |
| 498 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 499 | GR_VK_CALL(fBackendContext->fInterface, |
| 500 | CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0], |
| 501 | srcStageMask, dstStageMask, 0, |
| 502 | 0, nullptr, |
| 503 | 0, nullptr, |
| 504 | 1, &imageMemoryBarrier)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 505 | |
| 506 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 507 | EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0])); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 508 | |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 509 | VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 510 | // insert the layout transfer into the queue and wait on the acquire |
| 511 | VkSubmitInfo submitInfo; |
| 512 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 513 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 514 | submitInfo.waitSemaphoreCount = 1; |
| 515 | submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; |
egdaniel | 58a8d92 | 2016-04-21 08:03:10 -0700 | [diff] [blame] | 516 | submitInfo.pWaitDstStageMask = &waitDstStageFlags; |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 517 | submitInfo.commandBufferCount = 1; |
| 518 | submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; |
| 519 | submitInfo.signalSemaphoreCount = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 520 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 521 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 522 | QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 523 | backbuffer->fUsageFences[0])); |
| 524 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 525 | return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 526 | } |
| 527 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 528 | void VulkanWindowContext::swapBuffers() { |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 529 | |
| 530 | BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 531 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 532 | this->presentRenderSurface(fSurfaces[backbuffer->fImageIndex], |
| 533 | fRenderTargets[backbuffer->fImageIndex], 24); |
| 534 | |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 535 | VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 536 | VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; |
| 537 | VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
| 538 | VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 539 | VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
| 540 | |
| 541 | VkImageMemoryBarrier imageMemoryBarrier = { |
| 542 | VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
| 543 | NULL, // pNext |
| 544 | srcAccessMask, // outputMask |
| 545 | dstAccessMask, // inputMask |
| 546 | layout, // oldLayout |
| 547 | VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 548 | fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 549 | fPresentQueueIndex, // dstQueueFamilyIndex |
| 550 | fImages[backbuffer->fImageIndex], // image |
| 551 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
| 552 | }; |
| 553 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 554 | ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1], 0)); |
| 555 | VkCommandBufferBeginInfo info; |
| 556 | memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
| 557 | info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 558 | info.flags = 0; |
| 559 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 560 | BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[1], &info)); |
| 561 | GR_VK_CALL(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 562 | CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1], |
| 563 | srcStageMask, dstStageMask, 0, |
| 564 | 0, nullptr, |
| 565 | 0, nullptr, |
| 566 | 1, &imageMemoryBarrier)); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 567 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 568 | EndCommandBuffer(backbuffer->fTransitionCmdBuffers[1])); |
| 569 | |
| 570 | fImageLayouts[backbuffer->fImageIndex] = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; |
| 571 | |
| 572 | // insert the layout transfer into the queue and wait on the acquire |
| 573 | VkSubmitInfo submitInfo; |
| 574 | memset(&submitInfo, 0, sizeof(VkSubmitInfo)); |
| 575 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 576 | submitInfo.waitSemaphoreCount = 0; |
| 577 | submitInfo.pWaitDstStageMask = 0; |
| 578 | submitInfo.commandBufferCount = 1; |
| 579 | submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[1]; |
| 580 | submitInfo.signalSemaphoreCount = 1; |
| 581 | submitInfo.pSignalSemaphores = &backbuffer->fRenderSemaphore; |
| 582 | |
| 583 | GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 584 | QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 585 | backbuffer->fUsageFences[1])); |
| 586 | |
| 587 | // Submit present operation to present queue |
| 588 | const VkPresentInfoKHR presentInfo = |
| 589 | { |
| 590 | VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType |
| 591 | NULL, // pNext |
| 592 | 1, // waitSemaphoreCount |
| 593 | &backbuffer->fRenderSemaphore, // pWaitSemaphores |
| 594 | 1, // swapchainCount |
| 595 | &fSwapchain, // pSwapchains |
| 596 | &backbuffer->fImageIndex, // pImageIndices |
| 597 | NULL // pResults |
| 598 | }; |
| 599 | |
jvanverth | b0d4352 | 2016-04-21 11:46:23 -0700 | [diff] [blame] | 600 | fQueuePresentKHR(fPresentQueue, &presentInfo); |
jvanverth | 9f37246 | 2016-04-06 06:08:59 -0700 | [diff] [blame] | 601 | |
| 602 | } |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 603 | |
| 604 | } //namespace sk_app |