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 GrVkFormatToPixelConfig(swapchainCreateInfo.imageFormat, &fPixelConfig); | 232 GrVkFormatToPixelConfig(swapchainCreateInfo.imageFormat, &fPixelConfig); |
244 | 233 |
245 this->createBuffers(); | 234 this->createBuffers(); |
246 | 235 |
247 return true; | 236 return true; |
248 } | 237 } |
249 | 238 |
250 void VulkanTestContext::createBuffers() { | 239 void VulkanTestContext::createBuffers() { |
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 10 matching lines...) Expand all Loading... |
281 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 264 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
282 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); | 265 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); |
283 } | 266 } |
284 | 267 |
285 // create the command pool for the command buffers | 268 // create the command pool for the command buffers |
286 if (VK_NULL_HANDLE == fCommandPool) { | 269 if (VK_NULL_HANDLE == fCommandPool) { |
287 VkCommandPoolCreateInfo commandPoolInfo; | 270 VkCommandPoolCreateInfo commandPoolInfo; |
288 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); | 271 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); |
289 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; | 272 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
290 // this needs to be on the render queue | 273 // this needs to be on the render queue |
291 commandPoolInfo.queueFamilyIndex = fBackendContext->fQueueFamilyIndex; | 274 commandPoolInfo.queueFamilyIndex = fBackendContext->fGraphicsQueueIndex; |
292 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; | 275 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
293 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 276 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
294 CreateCommandPool(fBackendContext->fDevice, &command
PoolInfo, | 277 CreateCommandPool(fBackendContext->fDevice, &command
PoolInfo, |
295 nullptr, &fCommandPool)); | 278 nullptr, &fCommandPool)); |
296 } | 279 } |
297 | 280 |
298 // set up the backbuffers | 281 // set up the backbuffers |
299 VkSemaphoreCreateInfo semaphoreInfo; | 282 VkSemaphoreCreateInfo semaphoreInfo; |
300 memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); | 283 memset(&semaphoreInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
301 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; | 284 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 372 |
390 this->destroyBuffers(); | 373 this->destroyBuffers(); |
391 | 374 |
392 if (VK_NULL_HANDLE != fCommandPool) { | 375 if (VK_NULL_HANDLE != fCommandPool) { |
393 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte
xt->fDevice, | 376 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte
xt->fDevice, |
394 fCommandPool,
nullptr)); | 377 fCommandPool,
nullptr)); |
395 fCommandPool = VK_NULL_HANDLE; | 378 fCommandPool = VK_NULL_HANDLE; |
396 } | 379 } |
397 | 380 |
398 if (VK_NULL_HANDLE != fSwapchain) { | 381 if (VK_NULL_HANDLE != fSwapchain) { |
399 GR_VK_CALL(fBackendContext->fInterface, DestroySwapchainKHR(fBackendCont
ext->fDevice, | 382 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); |
400 fSwapchain,
nullptr)); | |
401 fSwapchain = VK_NULL_HANDLE; | 383 fSwapchain = VK_NULL_HANDLE; |
402 } | 384 } |
403 | 385 |
404 if (VK_NULL_HANDLE != fSurface) { | 386 if (VK_NULL_HANDLE != fSurface) { |
405 GR_VK_CALL(fBackendContext->fInterface, DestroySurfaceKHR(fBackendContex
t->fInstance, | 387 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); |
406 fSurface, null
ptr)); | |
407 fSurface = VK_NULL_HANDLE; | 388 fSurface = VK_NULL_HANDLE; |
408 } | 389 } |
409 | 390 |
410 delete fContext; | 391 delete fContext; |
411 | 392 |
412 fBackendContext.reset(nullptr); | 393 fBackendContext.reset(nullptr); |
413 } | 394 } |
414 | 395 |
415 VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { | 396 VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { |
416 SkASSERT(fBackbuffers); | 397 SkASSERT(fBackbuffers); |
(...skipping 14 matching lines...) Expand all Loading... |
431 SkSurface* VulkanTestContext::getBackbufferSurface() { | 412 SkSurface* VulkanTestContext::getBackbufferSurface() { |
432 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); | 413 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
433 SkASSERT(backbuffer); | 414 SkASSERT(backbuffer); |
434 | 415 |
435 // reset the fence | 416 // reset the fence |
436 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 417 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
437 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); | 418 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); |
438 // semaphores should be in unsignaled state | 419 // semaphores should be in unsignaled state |
439 | 420 |
440 // acquire the image | 421 // acquire the image |
441 VkResult res = GR_VK_CALL(fBackendContext->fInterface, | 422 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI
NT64_MAX, |
442 AcquireNextImageKHR(fBackendContext->fDevice, | 423 backbuffer->fAcquireSemaphore, VK_NULL_H
ANDLE, |
443 fSwapchain, | 424 &backbuffer->fImageIndex); |
444 UINT64_MAX, | |
445 backbuffer->fAcquireSemaphore, | |
446 VK_NULL_HANDLE, | |
447 &backbuffer->fImageIndex)); | |
448 if (VK_ERROR_SURFACE_LOST_KHR == res) { | 425 if (VK_ERROR_SURFACE_LOST_KHR == res) { |
449 // need to figure out how to create a new vkSurface without the platform
Data* | 426 // need to figure out how to create a new vkSurface without the platform
Data* |
450 // maybe use attach somehow? but need a Window | 427 // maybe use attach somehow? but need a Window |
451 return nullptr; | 428 return nullptr; |
452 } | 429 } |
453 if (VK_ERROR_OUT_OF_DATE_KHR == res) { | 430 if (VK_ERROR_OUT_OF_DATE_KHR == res) { |
454 // tear swapchain down and try again | 431 // tear swapchain down and try again |
455 if (!this->createSwapchain(0, 0)) { | 432 if (!this->createSwapchain(0, 0)) { |
456 return nullptr; | 433 return nullptr; |
457 } | 434 } |
458 | 435 |
459 // acquire the image | 436 // acquire the image |
460 res = GR_VK_CALL(fBackendContext->fInterface, | 437 res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64
_MAX, |
461 AcquireNextImageKHR(fBackendContext->fDevice, | 438 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE
, |
462 fSwapchain, | 439 &backbuffer->fImageIndex); |
463 UINT64_MAX, | |
464 backbuffer->fAcquireSemaphore, | |
465 VK_NULL_HANDLE, | |
466 &backbuffer->fImageIndex)); | |
467 | 440 |
468 if (VK_SUCCESS != res) { | 441 if (VK_SUCCESS != res) { |
469 return nullptr; | 442 return nullptr; |
470 } | 443 } |
471 } | 444 } |
472 | 445 |
473 // set up layout transfer from initial to color attachment | 446 // set up layout transfer from initial to color attachment |
474 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; | 447 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; |
475 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 448 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
476 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : | 449 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : |
477 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 450 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
478 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 451 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
479 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 452 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
480 0 : VK_ACCESS_MEMORY_READ_BIT; | 453 0 : VK_ACCESS_MEMORY_READ_BIT; |
481 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 454 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
482 | 455 |
483 VkImageMemoryBarrier imageMemoryBarrier = { | 456 VkImageMemoryBarrier imageMemoryBarrier = { |
484 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 457 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
485 NULL, // pNext | 458 NULL, // pNext |
486 srcAccessMask, // outputMask | 459 srcAccessMask, // outputMask |
487 dstAccessMask, // inputMask | 460 dstAccessMask, // inputMask |
488 layout, // oldLayout | 461 layout, // oldLayout |
489 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout | 462 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout |
490 fPresentQueueIndex, // srcQueueFamilyIndex | 463 fPresentQueueIndex, // srcQueueFamilyIndex |
491 fBackendContext->fQueueFamilyIndex, // dstQueueFamilyIndex | 464 fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex |
492 fImages[backbuffer->fImageIndex], // image | 465 fImages[backbuffer->fImageIndex], // image |
493 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange | 466 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
494 }; | 467 }; |
495 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 468 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
496 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0],
0)); | 469 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0],
0)); |
497 VkCommandBufferBeginInfo info; | 470 VkCommandBufferBeginInfo info; |
498 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); | 471 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
499 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | 472 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
500 info.flags = 0; | 473 info.flags = 0; |
501 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 474 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 513 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
541 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; | 514 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
542 | 515 |
543 VkImageMemoryBarrier imageMemoryBarrier = { | 516 VkImageMemoryBarrier imageMemoryBarrier = { |
544 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 517 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
545 NULL, // pNext | 518 NULL, // pNext |
546 srcAccessMask, // outputMask | 519 srcAccessMask, // outputMask |
547 dstAccessMask, // inputMask | 520 dstAccessMask, // inputMask |
548 layout, // oldLayout | 521 layout, // oldLayout |
549 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout | 522 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout |
550 fBackendContext->fQueueFamilyIndex, // srcQueueFamilyIndex | 523 fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex |
551 fPresentQueueIndex, // dstQueueFamilyIndex | 524 fPresentQueueIndex, // dstQueueFamilyIndex |
552 fImages[backbuffer->fImageIndex], // image | 525 fImages[backbuffer->fImageIndex], // image |
553 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange | 526 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange |
554 }; | 527 }; |
555 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 528 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
556 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1],
0)); | 529 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1],
0)); |
557 VkCommandBufferBeginInfo info; | 530 VkCommandBufferBeginInfo info; |
558 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); | 531 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); |
559 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; | 532 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
560 info.flags = 0; | 533 info.flags = 0; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType | 565 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType |
593 NULL, // pNext | 566 NULL, // pNext |
594 1, // waitSemaphoreCount | 567 1, // waitSemaphoreCount |
595 &backbuffer->fRenderSemaphore, // pWaitSemaphores | 568 &backbuffer->fRenderSemaphore, // pWaitSemaphores |
596 1, // swapchainCount | 569 1, // swapchainCount |
597 &fSwapchain, // pSwapchains | 570 &fSwapchain, // pSwapchains |
598 &backbuffer->fImageIndex, // pImageIndices | 571 &backbuffer->fImageIndex, // pImageIndices |
599 NULL // pResults | 572 NULL // pResults |
600 }; | 573 }; |
601 | 574 |
602 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 575 fQueuePresentKHR(fPresentQueue, &presentInfo); |
603 QueuePresentKHR(fPresentQueue, &presentInfo)); | |
604 | 576 |
605 } | 577 } |
OLD | NEW |