OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
11 #include "VulkanTestContext.h" | 11 #include "VulkanTestContext.h" |
12 | 12 |
13 #include "vk/GrVkInterface.h" | 13 #include "vk/GrVkInterface.h" |
14 #include "vk/GrVkUtil.h" | 14 #include "vk/GrVkUtil.h" |
15 #include "vk/GrVkTypes.h" | 15 #include "vk/GrVkTypes.h" |
16 | 16 |
17 #ifdef VK_USE_PLATFORM_WIN32_KHR | 17 #ifdef VK_USE_PLATFORM_WIN32_KHR |
18 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW | 18 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
19 #undef CreateSemaphore | 19 #undef CreateSemaphore |
20 #endif | 20 #endif |
21 | 21 |
| 22 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk"
#F) |
| 23 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk"
#F) |
| 24 |
22 VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount) | 25 VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount) |
23 : fSurface(VK_NULL_HANDLE) | 26 : fSurface(VK_NULL_HANDLE) |
24 , fSwapchain(VK_NULL_HANDLE) | 27 , fSwapchain(VK_NULL_HANDLE) |
25 , fCommandPool(VK_NULL_HANDLE) | 28 , fCommandPool(VK_NULL_HANDLE) |
26 , fBackbuffers(nullptr) { | 29 , fBackbuffers(nullptr) { |
27 | 30 |
28 // any config code here (particularly for msaa)? | 31 // any config code here (particularly for msaa)? |
29 | 32 |
30 this->initializeContext(platformData); | 33 this->initializeContext(platformData); |
31 } | 34 } |
32 | 35 |
33 void VulkanTestContext::initializeContext(void* platformData) { | 36 void VulkanTestContext::initializeContext(void* platformData) { |
34 | 37 |
35 fBackendContext.reset(GrVkBackendContext::Create()); | 38 fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPre
sent)); |
| 39 if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || |
| 40 !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { |
| 41 fBackendContext.reset(nullptr); |
| 42 return; |
| 43 } |
| 44 |
| 45 VkInstance instance = fBackendContext->fInstance; |
| 46 VkDevice device = fBackendContext->fDevice; |
| 47 GET_PROC(DestroySurfaceKHR); |
| 48 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); |
| 49 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); |
| 50 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); |
| 51 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); |
| 52 GET_DEV_PROC(CreateSwapchainKHR); |
| 53 GET_DEV_PROC(DestroySwapchainKHR); |
| 54 GET_DEV_PROC(GetSwapchainImagesKHR); |
| 55 GET_DEV_PROC(AcquireNextImageKHR); |
| 56 GET_DEV_PROC(QueuePresentKHR); |
36 | 57 |
37 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext)fBackendCo
ntext.get()); | 58 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext)fBackendCo
ntext.get()); |
38 | 59 |
39 fSurface = createVkSurface(platformData); | 60 fSurface = createVkSurface(instance, platformData); |
40 if (VK_NULL_HANDLE == fSurface) { | 61 if (VK_NULL_HANDLE == fSurface) { |
41 fBackendContext.reset(nullptr); | 62 fBackendContext.reset(nullptr); |
42 return; | 63 return; |
43 } | 64 } |
44 | 65 |
45 // query to get the initial queue props size | 66 // query to get the initial queue props size |
46 uint32_t queueCount; | 67 uint32_t queueCount; |
47 GR_VK_CALL(fBackendContext->fInterface, | 68 GR_VK_CALL(fBackendContext->fInterface, |
48 GetPhysicalDeviceQueueFamilyProperties(fBackendContext->fPhysical
Device, &queueCount, | 69 GetPhysicalDeviceQueueFamilyProperties(fBackendContext->fPhysical
Device, &queueCount, |
49 nullptr)); | 70 nullptr)); |
50 SkASSERT(queueCount >= 1); | 71 SkASSERT(queueCount >= 1); |
51 | 72 |
52 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); | 73 SkAutoMalloc queuePropsAlloc(queueCount * sizeof(VkQueueFamilyProperties)); |
53 // now get the actual queue props | 74 // now get the actual queue props |
54 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl
loc.get(); | 75 VkQueueFamilyProperties* queueProps = (VkQueueFamilyProperties*)queuePropsAl
loc.get(); |
55 | 76 |
56 GR_VK_CALL(fBackendContext->fInterface, | 77 GR_VK_CALL(fBackendContext->fInterface, |
57 GetPhysicalDeviceQueueFamilyProperties(fBackendContext->fPhysical
Device, &queueCount, | 78 GetPhysicalDeviceQueueFamilyProperties(fBackendContext->fPhysical
Device, &queueCount, |
58 queueProps)); | 79 queueProps)); |
59 | 80 |
60 // iterate to find the present queue | |
61 fPresentQueueIndex = -1; | |
62 for (uint32_t i = 0; i < queueCount; i++) { | |
63 if ((queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) && canPresent(i))
{ | |
64 fPresentQueueIndex = i; | |
65 break; | |
66 } | |
67 } | |
68 SkASSERT(fPresentQueueIndex < queueCount); | |
69 | |
70 VkBool32 supported; | 81 VkBool32 supported; |
71 VkResult res = GR_VK_CALL(fBackendContext->fInterface, | 82 VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysica
lDevice, |
72 GetPhysicalDeviceSurfaceSupportKHR(fBackendContext
->fPhysicalDevice, | 83 fPresentQueueIndex, fSurf
ace, |
73 fPresentQueueIn
dex, | 84 &supported); |
74 fSurface, | |
75 &supported)); | |
76 if (VK_SUCCESS != res) { | 85 if (VK_SUCCESS != res) { |
77 this->destroyContext(); | 86 this->destroyContext(); |
78 return; | 87 return; |
79 } | 88 } |
80 | 89 |
81 if (!this->createSwapchain(-1, -1)) { | 90 if (!this->createSwapchain(-1, -1)) { |
82 this->destroyContext(); | 91 this->destroyContext(); |
83 return; | 92 return; |
84 } | 93 } |
85 | 94 |
86 // create presentQueue | 95 // create presentQueue |
87 vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQ
ueue); | 96 vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQ
ueue); |
88 | |
89 | |
90 } | 97 } |
91 | 98 |
92 bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) | 99 bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) |
93 { | 100 { |
94 // check for capabilities | 101 // check for capabilities |
95 VkSurfaceCapabilitiesKHR caps; | 102 VkSurfaceCapabilitiesKHR caps; |
96 VkResult res = GR_VK_CALL(fBackendContext->fInterface, | 103 VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPh
ysicalDevice, |
97 GetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendConte
xt->fPhysicalDevice, | 104 fSurface, &caps); |
98 fSurface, | |
99 &caps)); | |
100 if (VK_SUCCESS != res) { | 105 if (VK_SUCCESS != res) { |
101 return false; | 106 return false; |
102 } | 107 } |
103 | 108 |
104 uint32_t surfaceFormatCount; | 109 uint32_t surfaceFormatCount; |
105 res = GR_VK_CALL(fBackendContext->fInterface, | 110 res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice,
fSurface, |
106 GetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysic
alDevice, | 111 &surfaceFormatCount, nullptr); |
107 fSurface, | |
108 &surfaceFormatCount, | |
109 nullptr)); | |
110 if (VK_SUCCESS != res) { | 112 if (VK_SUCCESS != res) { |
111 return false; | 113 return false; |
112 } | 114 } |
113 | 115 |
114 SkAutoMalloc surfaceFormatAlloc(surfaceFormatCount * sizeof(VkSurfaceFormatK
HR)); | 116 SkAutoMalloc surfaceFormatAlloc(surfaceFormatCount * sizeof(VkSurfaceFormatK
HR)); |
115 VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)surfaceFormatAlloc
.get(); | 117 VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)surfaceFormatAlloc
.get(); |
116 res = GR_VK_CALL(fBackendContext->fInterface, | 118 res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice,
fSurface, |
117 GetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysic
alDevice, | 119 &surfaceFormatCount, surfaceFormat
s); |
118 fSurface, | |
119 &surfaceFormatCount, | |
120 surfaceFormats)); | |
121 if (VK_SUCCESS != res) { | 120 if (VK_SUCCESS != res) { |
122 return false; | 121 return false; |
123 } | 122 } |
124 | 123 |
125 uint32_t presentModeCount; | 124 uint32_t presentModeCount; |
126 res = GR_VK_CALL(fBackendContext->fInterface, | 125 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev
ice, fSurface, |
127 GetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fP
hysicalDevice, | 126 &presentModeCount, nullptr); |
128 fSurface, | |
129 &presentModeCount, | |
130 nullptr)); | |
131 if (VK_SUCCESS != res) { | 127 if (VK_SUCCESS != res) { |
132 return false; | 128 return false; |
133 } | 129 } |
134 | 130 |
135 SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); | 131 SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); |
136 VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); | 132 VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); |
137 res = GR_VK_CALL(fBackendContext->fInterface, | 133 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev
ice, fSurface, |
138 GetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fP
hysicalDevice, | 134 &presentModeCount, presentMo
des); |
139 fSurface, | |
140 &presentModeCount, | |
141 presentModes)); | |
142 if (VK_SUCCESS != res) { | 135 if (VK_SUCCESS != res) { |
143 return false; | 136 return false; |
144 } | 137 } |
145 | 138 |
146 VkExtent2D extent = caps.currentExtent; | 139 VkExtent2D extent = caps.currentExtent; |
147 // use the hints | 140 // use the hints |
148 if (extent.width == (uint32_t)-1) { | 141 if (extent.width == (uint32_t)-1) { |
149 extent.width = width; | 142 extent.width = width; |
150 extent.height = height; | 143 extent.height = height; |
151 } | 144 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 memset(&swapchainCreateInfo, 0, sizeof(VkSwapchainCreateInfoKHR)); | 191 memset(&swapchainCreateInfo, 0, sizeof(VkSwapchainCreateInfoKHR)); |
199 swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; | 192 swapchainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; |
200 swapchainCreateInfo.surface = fSurface; | 193 swapchainCreateInfo.surface = fSurface; |
201 swapchainCreateInfo.minImageCount = imageCount; | 194 swapchainCreateInfo.minImageCount = imageCount; |
202 swapchainCreateInfo.imageFormat = surfaceFormats[0].format; // for now
, use the first one | 195 swapchainCreateInfo.imageFormat = surfaceFormats[0].format; // for now
, use the first one |
203 swapchainCreateInfo.imageColorSpace = surfaceFormats[0].colorSpace; | 196 swapchainCreateInfo.imageColorSpace = surfaceFormats[0].colorSpace; |
204 swapchainCreateInfo.imageExtent = extent; | 197 swapchainCreateInfo.imageExtent = extent; |
205 swapchainCreateInfo.imageArrayLayers = 1; | 198 swapchainCreateInfo.imageArrayLayers = 1; |
206 swapchainCreateInfo.imageUsage = usageFlags; | 199 swapchainCreateInfo.imageUsage = usageFlags; |
207 | 200 |
208 uint32_t queueFamilies[] = { fBackendContext->fQueueFamilyIndex, fPresentQue
ueIndex }; | 201 uint32_t queueFamilies[] = { fBackendContext->fGraphicsQueueIndex, fPresentQ
ueueIndex }; |
209 if (fBackendContext->fQueueFamilyIndex != fPresentQueueIndex) { | 202 if (fBackendContext->fGraphicsQueueIndex != fPresentQueueIndex) { |
210 swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; | 203 swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; |
211 swapchainCreateInfo.queueFamilyIndexCount = 2; | 204 swapchainCreateInfo.queueFamilyIndexCount = 2; |
212 swapchainCreateInfo.pQueueFamilyIndices = queueFamilies; | 205 swapchainCreateInfo.pQueueFamilyIndices = queueFamilies; |
213 } else { | 206 } else { |
214 swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; | 207 swapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; |
215 swapchainCreateInfo.queueFamilyIndexCount = 0; | 208 swapchainCreateInfo.queueFamilyIndexCount = 0; |
216 swapchainCreateInfo.pQueueFamilyIndices = nullptr; | 209 swapchainCreateInfo.pQueueFamilyIndices = nullptr; |
217 } | 210 } |
218 | 211 |
219 swapchainCreateInfo.preTransform = caps.currentTransform;; | 212 swapchainCreateInfo.preTransform = caps.currentTransform;; |
220 swapchainCreateInfo.compositeAlpha = composite_alpha; | 213 swapchainCreateInfo.compositeAlpha = composite_alpha; |
221 swapchainCreateInfo.presentMode = mode; | 214 swapchainCreateInfo.presentMode = mode; |
222 swapchainCreateInfo.clipped = true; | 215 swapchainCreateInfo.clipped = true; |
223 swapchainCreateInfo.oldSwapchain = fSwapchain; | 216 swapchainCreateInfo.oldSwapchain = fSwapchain; |
224 | 217 |
225 res = GR_VK_CALL(fBackendContext->fInterface, | 218 res = fCreateSwapchainKHR(fBackendContext->fDevice, &swapchainCreateInfo, nu
llptr, &fSwapchain); |
226 CreateSwapchainKHR(fBackendContext->fDevice, | |
227 &swapchainCreateInfo, nullptr, &fSwapcha
in)); | |
228 if (VK_SUCCESS != res) { | 219 if (VK_SUCCESS != res) { |
229 return false; | 220 return false; |
230 } | 221 } |
231 | 222 |
232 // destroy the old swapchain | 223 // destroy the old swapchain |
233 if (swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE) { | 224 if (swapchainCreateInfo.oldSwapchain != VK_NULL_HANDLE) { |
234 GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->
fDevice)); | 225 GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->
fDevice)); |
235 | 226 |
236 this->destroyBuffers(); | 227 this->destroyBuffers(); |
237 | 228 |
238 GR_VK_CALL(fBackendContext->fInterface, DestroySwapchainKHR(fBackendCont
ext->fDevice, | 229 fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSw
apchain, nullptr); |
239 swapchainCrea
teInfo.oldSwapchain, | |
240 nullptr)); | |
241 } | 230 } |
242 | 231 |
243 this->createBuffers(swapchainCreateInfo.imageFormat); | 232 this->createBuffers(swapchainCreateInfo.imageFormat); |
244 | 233 |
245 return true; | 234 return true; |
246 } | 235 } |
247 | 236 |
248 void VulkanTestContext::createBuffers(VkFormat format) { | 237 void VulkanTestContext::createBuffers(VkFormat format) { |
249 GrVkFormatToPixelConfig(format, &fPixelConfig); | 238 GrVkFormatToPixelConfig(format, &fPixelConfig); |
250 | 239 |
251 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, GetSwapchainImagesKHR(fBack
endContext->fDevice, | 240 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, n
ullptr); |
252 fSwap
chain, | |
253 &fIma
geCount, | |
254 nullp
tr)); | |
255 SkASSERT(fImageCount); | 241 SkASSERT(fImageCount); |
256 fImages = new VkImage[fImageCount]; | 242 fImages = new VkImage[fImageCount]; |
257 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, GetSwapchainImagesKHR(fBack
endContext->fDevice, | 243 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, f
Images); |
258 fSwap
chain, | |
259 &fIma
geCount, | |
260 fImag
es)); | |
261 | 244 |
262 // set up initial image layouts and create surfaces | 245 // set up initial image layouts and create surfaces |
263 fImageLayouts = new VkImageLayout[fImageCount]; | 246 fImageLayouts = new VkImageLayout[fImageCount]; |
264 fSurfaces = new sk_sp<SkSurface>[fImageCount]; | 247 fSurfaces = new sk_sp<SkSurface>[fImageCount]; |
265 for (uint32_t i = 0; i < fImageCount; ++i) { | 248 for (uint32_t i = 0; i < fImageCount; ++i) { |
266 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; | 249 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; |
267 | 250 |
268 GrBackendRenderTargetDesc desc; | 251 GrBackendRenderTargetDesc desc; |
269 GrVkTextureInfo info; | 252 GrVkTextureInfo info; |
270 info.fImage = fImages[i]; | 253 info.fImage = fImages[i]; |
(...skipping 11 matching lines...) Expand all Loading... |
282 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 265 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
283 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); | 266 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); |
284 } | 267 } |
285 | 268 |
286 // create the command pool for the command buffers | 269 // create the command pool for the command buffers |
287 if (VK_NULL_HANDLE == fCommandPool) { | 270 if (VK_NULL_HANDLE == fCommandPool) { |
288 VkCommandPoolCreateInfo commandPoolInfo; | 271 VkCommandPoolCreateInfo commandPoolInfo; |
289 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); | 272 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); |
290 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; | 273 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
291 // this needs to be on the render queue | 274 // this needs to be on the render queue |
292 commandPoolInfo.queueFamilyIndex = fBackendContext->fQueueFamilyIndex; | 275 commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex; |
293 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; | 276 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
294 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 277 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
295 CreateCommandPool(fBackendContext->fDevice, &command
PoolInfo, | 278 CreateCommandPool(fBackendContext->fDevice, &command
PoolInfo, |
296 nullptr, &fCommandPool)); | 279 nullptr, &fCommandPool)); |
297 } | 280 } |
298 | 281 |
299 // set up the backbuffers | 282 // set up the backbuffers |
300 VkSemaphoreCreateInfo semaphoreInfo; | 283 VkSemaphoreCreateInfo semaphoreInfo; |
301 memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); | 284 memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
302 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; | 285 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 373 |
391 this->destroyBuffers(); | 374 this->destroyBuffers(); |
392 | 375 |
393 if (VK_NULL_HANDLE != fCommandPool) { | 376 if (VK_NULL_HANDLE != fCommandPool) { |
394 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte
xt->fDevice, | 377 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte
xt->fDevice, |
395 fCommandPool,
nullptr)); | 378 fCommandPool,
nullptr)); |
396 fCommandPool = VK_NULL_HANDLE; | 379 fCommandPool = VK_NULL_HANDLE; |
397 } | 380 } |
398 | 381 |
399 if (VK_NULL_HANDLE != fSwapchain) { | 382 if (VK_NULL_HANDLE != fSwapchain) { |
400 GR_VK_CALL(fBackendContext->fInterface, DestroySwapchainKHR(fBackendCont
ext->fDevice, | 383 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); |
401 fSwapchain,
nullptr)); | |
402 fSwapchain = VK_NULL_HANDLE; | 384 fSwapchain = VK_NULL_HANDLE; |
403 } | 385 } |
404 | 386 |
405 if (VK_NULL_HANDLE != fSurface) { | 387 if (VK_NULL_HANDLE != fSurface) { |
406 GR_VK_CALL(fBackendContext->fInterface, DestroySurfaceKHR(fBackendContex
t->fInstance, | 388 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); |
407 fSurface, null
ptr)); | |
408 fSurface = VK_NULL_HANDLE; | 389 fSurface = VK_NULL_HANDLE; |
409 } | 390 } |
410 | 391 |
411 delete fContext; | 392 delete fContext; |
412 | 393 |
413 fBackendContext.reset(nullptr); | 394 fBackendContext.reset(nullptr); |
414 } | 395 } |
415 | 396 |
416 VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { | 397 VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { |
417 SkASSERT(fBackbuffers); | 398 SkASSERT(fBackbuffers); |
(...skipping 14 matching lines...) Expand all Loading... |
432 SkSurface* VulkanTestContext::getBackbufferSurface() { | 413 SkSurface* VulkanTestContext::getBackbufferSurface() { |
433 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); | 414 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
434 SkASSERT(backbuffer); | 415 SkASSERT(backbuffer); |
435 | 416 |
436 // reset the fence | 417 // reset the fence |
437 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 418 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
438 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); | 419 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); |
439 // semaphores should be in unsignaled state | 420 // semaphores should be in unsignaled state |
440 | 421 |
441 // acquire the image | 422 // acquire the image |
442 VkResult res = GR_VK_CALL(fBackendContext->fInterface, | 423 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI
NT64_MAX, |
443 AcquireNextImageKHR(fBackendContext->fDevice, | 424 backbuffer->fAcquireSemaphore, VK_NULL_H
ANDLE, |
444 fSwapchain, | 425 &backbuffer->fImageIndex); |
445 UINT64_MAX, | |
446 backbuffer->fAcquireSemaphore, | |
447 VK_NULL_HANDLE, | |
448 &backbuffer->fImageIndex)); | |
449 if (VK_ERROR_SURFACE_LOST_KHR == res) { | 426 if (VK_ERROR_SURFACE_LOST_KHR == res) { |
450 // need to figure out how to create a new vkSurface without the platform
Data* | 427 // need to figure out how to create a new vkSurface without the platform
Data* |
451 // maybe use attach somehow? but need a Window | 428 // maybe use attach somehow? but need a Window |
452 return nullptr; | 429 return nullptr; |
453 } | 430 } |
454 if (VK_ERROR_OUT_OF_DATE_KHR == res) { | 431 if (VK_ERROR_OUT_OF_DATE_KHR == res) { |
455 // tear swapchain down and try again | 432 // tear swapchain down and try again |
456 if (!this->createSwapchain(0, 0)) { | 433 if (!this->createSwapchain(0, 0)) { |
457 return nullptr; | 434 return nullptr; |
458 } | 435 } |
459 | 436 |
460 // acquire the image | 437 // acquire the image |
461 res = GR_VK_CALL(fBackendContext->fInterface, | 438 res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64
_MAX, |
462 AcquireNextImageKHR(fBackendContext->fDevice, | 439 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE
, |
463 fSwapchain, | 440 &backbuffer->fImageIndex); |
464 UINT64_MAX, | |
465 backbuffer->fAcquireSemaphore, | |
466 VK_NULL_HANDLE, | |
467 &backbuffer->fImageIndex)); | |
468 | 441 |
469 if (VK_SUCCESS != res) { | 442 if (VK_SUCCESS != res) { |
470 return nullptr; | 443 return nullptr; |
471 } | 444 } |
472 } | 445 } |
473 | 446 |
474 // set up layout transfer from initial to color attachment | 447 // set up layout transfer from initial to color attachment |
475 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; | 448 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; |
476 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 449 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
477 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : | 450 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : |
478 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 451 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
479 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 452 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
480 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 453 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
481 0 : VK_ACCESS_MEMORY_READ_BIT; | 454 0 : VK_ACCESS_MEMORY_READ_BIT; |
482 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 455 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
483 | 456 |
484 VkImageMemoryBarrier imageMemoryBarrier = { | 457 VkImageMemoryBarrier imageMemoryBarrier = { |
485 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 458 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
486 NULL, // pNext | 459 NULL, // pNext |
487 srcAccessMask, // outputMask | 460 srcAccessMask, // outputMask |
488 dstAccessMask, // inputMask | 461 dstAccessMask, // inputMask |
489 layout, // oldLayout | 462 layout, // oldLayout |
490 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout | 463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout |
491 fPresentQueueIndex, // srcQueueFamilyIndex | 464 fPresentQueueIndex, // srcQueueFamilyIndex |
492 fBackendContext->fQueueFamilyIndex, // dstQueueFamilyIndex | 465 fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex |
493 fImages[backbuffer->fImageIndex], // image | 466 fImages[backbuffer->fImageIndex], // image |
494 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange | 467 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
495 }; | 468 }; |
496 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 469 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
497 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0],
0)); | 470 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0],
0)); |
498 VkCommandBufferBeginInfo info; | 471 VkCommandBufferBeginInfo info; |
499 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); | 472 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
500 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | 473 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
501 info.flags = 0; | 474 info.flags = 0; |
502 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 475 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 515 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
543 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; | 516 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
544 | 517 |
545 VkImageMemoryBarrier imageMemoryBarrier = { | 518 VkImageMemoryBarrier imageMemoryBarrier = { |
546 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 519 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
547 NULL, // pNext | 520 NULL, // pNext |
548 srcAccessMask, // outputMask | 521 srcAccessMask, // outputMask |
549 dstAccessMask, // inputMask | 522 dstAccessMask, // inputMask |
550 layout, // oldLayout | 523 layout, // oldLayout |
551 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout | 524 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout |
552 fBackendContext->fQueueFamilyIndex, // srcQueueFamilyIndex | 525 fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex |
553 fPresentQueueIndex, // dstQueueFamilyIndex | 526 fPresentQueueIndex, // dstQueueFamilyIndex |
554 fImages[backbuffer->fImageIndex], // image | 527 fImages[backbuffer->fImageIndex], // image |
555 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange | 528 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
556 }; | 529 }; |
557 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 530 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
558 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1],
0)); | 531 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1],
0)); |
559 VkCommandBufferBeginInfo info; | 532 VkCommandBufferBeginInfo info; |
560 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); | 533 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
561 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | 534 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
562 info.flags = 0; | 535 info.flags = 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType | 567 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType |
595 NULL, // pNext | 568 NULL, // pNext |
596 1, // waitSemaphoreCount | 569 1, // waitSemaphoreCount |
597 &backbuffer->fRenderSemaphore, // pWaitSemaphores | 570 &backbuffer->fRenderSemaphore, // pWaitSemaphores |
598 1, // swapchainCount | 571 1, // swapchainCount |
599 &fSwapchain, // pSwapchains | 572 &fSwapchain, // pSwapchains |
600 &backbuffer->fImageIndex, // pImageIndices | 573 &backbuffer->fImageIndex, // pImageIndices |
601 NULL // pResults | 574 NULL // pResults |
602 }; | 575 }; |
603 | 576 |
604 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 577 fQueuePresentKHR(fPresentQueue, &presentInfo); |
605 QueuePresentKHR(fPresentQueue, &presentInfo)); | |
606 | 578 |
607 } | 579 } |
OLD | NEW |