Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: tools/viewer/sk_app/VulkanWindowContext.cpp

Issue 1944413005: More refactoring for Viewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix up Android Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/viewer/sk_app/VulkanWindowContext.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "VulkanWindowContext.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) 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) 23 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F)
24 24
25 VulkanTestContext::VulkanTestContext(void* platformData, int msaaSampleCount) 25 namespace sk_app {
26 : fSurface(VK_NULL_HANDLE) 26
27 , fSwapchain(VK_NULL_HANDLE) 27 VulkanWindowContext::VulkanWindowContext(void* platformData, int msaaSampleCount )
28 , fCommandPool(VK_NULL_HANDLE) 28 : fSurface(VK_NULL_HANDLE)
29 , fBackbuffers(nullptr) { 29 , fSwapchain(VK_NULL_HANDLE)
30 , fCommandPool(VK_NULL_HANDLE)
31 , fBackbuffers(nullptr) {
30 32
31 // any config code here (particularly for msaa)? 33 // any config code here (particularly for msaa)?
32 34
33 this->initializeContext(platformData); 35 this->initializeContext(platformData);
34 } 36 }
35 37
36 void VulkanTestContext::initializeContext(void* platformData) { 38 void VulkanWindowContext::initializeContext(void* platformData) {
37 39
38 fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPre sent)); 40 fBackendContext.reset(GrVkBackendContext::Create(&fPresentQueueIndex, canPre sent));
39 if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) || 41 if (!(fBackendContext->fExtensions & kKHR_surface_GrVkExtensionFlag) ||
40 !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) { 42 !(fBackendContext->fExtensions & kKHR_swapchain_GrVkExtensionFlag)) {
41 fBackendContext.reset(nullptr); 43 fBackendContext.reset(nullptr);
42 return; 44 return;
43 } 45 }
44 46
45 VkInstance instance = fBackendContext->fInstance; 47 VkInstance instance = fBackendContext->fInstance;
46 VkDevice device = fBackendContext->fDevice; 48 VkDevice device = fBackendContext->fDevice;
47 GET_PROC(DestroySurfaceKHR); 49 GET_PROC(DestroySurfaceKHR);
48 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR); 50 GET_PROC(GetPhysicalDeviceSurfaceSupportKHR);
49 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); 51 GET_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR);
50 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR); 52 GET_PROC(GetPhysicalDeviceSurfaceFormatsKHR);
51 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR); 53 GET_PROC(GetPhysicalDeviceSurfacePresentModesKHR);
52 GET_DEV_PROC(CreateSwapchainKHR); 54 GET_DEV_PROC(CreateSwapchainKHR);
53 GET_DEV_PROC(DestroySwapchainKHR); 55 GET_DEV_PROC(DestroySwapchainKHR);
54 GET_DEV_PROC(GetSwapchainImagesKHR); 56 GET_DEV_PROC(GetSwapchainImagesKHR);
55 GET_DEV_PROC(AcquireNextImageKHR); 57 GET_DEV_PROC(AcquireNextImageKHR);
56 GET_DEV_PROC(QueuePresentKHR); 58 GET_DEV_PROC(QueuePresentKHR);
57 59
58 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext)fBackendCo ntext.get()); 60 fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendC ontext.get());
59 61
60 fSurface = createVkSurface(instance, platformData); 62 fSurface = createVkSurface(instance, platformData);
61 if (VK_NULL_HANDLE == fSurface) { 63 if (VK_NULL_HANDLE == fSurface) {
62 fBackendContext.reset(nullptr); 64 fBackendContext.reset(nullptr);
63 return; 65 return;
64 } 66 }
65 67
66 VkBool32 supported; 68 VkBool32 supported;
67 VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysica lDevice, 69 VkResult res = fGetPhysicalDeviceSurfaceSupportKHR(fBackendContext->fPhysica lDevice,
68 fPresentQueueIndex, fSurf ace, 70 fPresentQueueIndex, fSurf ace,
69 &supported); 71 &supported);
70 if (VK_SUCCESS != res) { 72 if (VK_SUCCESS != res) {
71 this->destroyContext(); 73 this->destroyContext();
72 return; 74 return;
73 } 75 }
74 76
75 if (!this->createSwapchain(-1, -1)) { 77 if (!this->createSwapchain(-1, -1)) {
76 this->destroyContext(); 78 this->destroyContext();
77 return; 79 return;
78 } 80 }
79 81
80 // create presentQueue 82 // create presentQueue
81 vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQ ueue); 83 vkGetDeviceQueue(fBackendContext->fDevice, fPresentQueueIndex, 0, &fPresentQ ueue);
82 } 84 }
83 85
84 bool VulkanTestContext::createSwapchain(uint32_t width, uint32_t height) 86 bool VulkanWindowContext::createSwapchain(uint32_t width, uint32_t height) {
85 {
86 // check for capabilities 87 // check for capabilities
87 VkSurfaceCapabilitiesKHR caps; 88 VkSurfaceCapabilitiesKHR caps;
88 VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPh ysicalDevice, 89 VkResult res = fGetPhysicalDeviceSurfaceCapabilitiesKHR(fBackendContext->fPh ysicalDevice,
89 fSurface, &caps); 90 fSurface, &caps);
90 if (VK_SUCCESS != res) { 91 if (VK_SUCCESS != res) {
91 return false; 92 return false;
92 } 93 }
93 94
94 uint32_t surfaceFormatCount; 95 uint32_t surfaceFormatCount;
95 res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface, 96 res = fGetPhysicalDeviceSurfaceFormatsKHR(fBackendContext->fPhysicalDevice, fSurface,
(...skipping 13 matching lines...) Expand all
109 uint32_t presentModeCount; 110 uint32_t presentModeCount;
110 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev ice, fSurface, 111 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev ice, fSurface,
111 &presentModeCount, nullptr); 112 &presentModeCount, nullptr);
112 if (VK_SUCCESS != res) { 113 if (VK_SUCCESS != res) {
113 return false; 114 return false;
114 } 115 }
115 116
116 SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR)); 117 SkAutoMalloc presentModeAlloc(presentModeCount * sizeof(VkPresentModeKHR));
117 VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get(); 118 VkPresentModeKHR* presentModes = (VkPresentModeKHR*)presentModeAlloc.get();
118 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev ice, fSurface, 119 res = fGetPhysicalDeviceSurfacePresentModesKHR(fBackendContext->fPhysicalDev ice, fSurface,
119 &presentModeCount, presentMo des); 120 &presentModeCount, presentMod es);
120 if (VK_SUCCESS != res) { 121 if (VK_SUCCESS != res) {
121 return false; 122 return false;
122 } 123 }
123 124
124 VkExtent2D extent = caps.currentExtent; 125 VkExtent2D extent = caps.currentExtent;
125 // use the hints 126 // use the hints
126 if (extent.width == (uint32_t)-1) { 127 if (extent.width == (uint32_t)-1) {
127 extent.width = width; 128 extent.width = width;
128 extent.height = height; 129 extent.height = height;
129 } 130 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 this->destroyBuffers(); 217 this->destroyBuffers();
217 218
218 fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSw apchain, nullptr); 219 fDestroySwapchainKHR(fBackendContext->fDevice, swapchainCreateInfo.oldSw apchain, nullptr);
219 } 220 }
220 221
221 this->createBuffers(swapchainCreateInfo.imageFormat); 222 this->createBuffers(swapchainCreateInfo.imageFormat);
222 223
223 return true; 224 return true;
224 } 225 }
225 226
226 void VulkanTestContext::createBuffers(VkFormat format) { 227 void VulkanWindowContext::createBuffers(VkFormat format) {
227 GrVkFormatToPixelConfig(format, &fPixelConfig); 228 GrVkFormatToPixelConfig(format, &fPixelConfig);
228 229
229 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, n ullptr); 230 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, n ullptr);
230 SkASSERT(fImageCount); 231 SkASSERT(fImageCount);
231 fImages = new VkImage[fImageCount]; 232 fImages = new VkImage[fImageCount];
232 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, f Images); 233 fGetSwapchainImagesKHR(fBackendContext->fDevice, fSwapchain, &fImageCount, f Images);
233 234
234 // set up initial image layouts and create surfaces 235 // set up initial image layouts and create surfaces
235 fImageLayouts = new VkImageLayout[fImageCount]; 236 fImageLayouts = new VkImageLayout[fImageCount];
236 fSurfaces = new sk_sp<SkSurface>[fImageCount]; 237 fSurfaces = new sk_sp<SkSurface>[fImageCount];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 305 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
305 CreateFence(fBackendContext->fDevice, &fenceInfo, nu llptr, 306 CreateFence(fBackendContext->fDevice, &fenceInfo, nu llptr,
306 &fBackbuffers[i].fUsageFences[0])); 307 &fBackbuffers[i].fUsageFences[0]));
307 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 308 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
308 CreateFence(fBackendContext->fDevice, &fenceInfo, nu llptr, 309 CreateFence(fBackendContext->fDevice, &fenceInfo, nu llptr,
309 &fBackbuffers[i].fUsageFences[1])); 310 &fBackbuffers[i].fUsageFences[1]));
310 } 311 }
311 fCurrentBackbufferIndex = fImageCount; 312 fCurrentBackbufferIndex = fImageCount;
312 } 313 }
313 314
314 void VulkanTestContext::destroyBuffers() { 315 void VulkanWindowContext::destroyBuffers() {
315 316
316 if (fBackbuffers) { 317 if (fBackbuffers) {
317 for (uint32_t i = 0; i < fImageCount + 1; ++i) { 318 for (uint32_t i = 0; i < fImageCount + 1; ++i) {
318 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 319 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
319 WaitForFences(fBackendContext->fDevice, 2, 320 WaitForFences(fBackendContext->fDevice, 2,
320 fBackbuffers[i].fUsageFences, 321 fBackbuffers[i].fUsageFences,
321 true, UINT64_MAX)); 322 true, UINT64_MAX));
322 fBackbuffers[i].fImageIndex = -1; 323 fBackbuffers[i].fImageIndex = -1;
323 GR_VK_CALL(fBackendContext->fInterface, 324 GR_VK_CALL(fBackendContext->fInterface,
324 DestroySemaphore(fBackendContext->fDevice, 325 DestroySemaphore(fBackendContext->fDevice,
325 fBackbuffers[i].fAcquireSemaphore, 326 fBackbuffers[i].fAcquireSemaphore,
326 nullptr)); 327 nullptr));
327 GR_VK_CALL(fBackendContext->fInterface, 328 GR_VK_CALL(fBackendContext->fInterface,
328 DestroySemaphore(fBackendContext->fDevice, 329 DestroySemaphore(fBackendContext->fDevice,
329 fBackbuffers[i].fRenderSemaphore, 330 fBackbuffers[i].fRenderSemaphore,
330 nullptr)); 331 nullptr));
331 GR_VK_CALL(fBackendContext->fInterface, 332 GR_VK_CALL(fBackendContext->fInterface,
(...skipping 10 matching lines...) Expand all
342 fBackbuffers = nullptr; 343 fBackbuffers = nullptr;
343 344
344 delete[] fSurfaces; 345 delete[] fSurfaces;
345 fSurfaces = nullptr; 346 fSurfaces = nullptr;
346 delete[] fImageLayouts; 347 delete[] fImageLayouts;
347 fImageLayouts = nullptr; 348 fImageLayouts = nullptr;
348 delete[] fImages; 349 delete[] fImages;
349 fImages = nullptr; 350 fImages = nullptr;
350 } 351 }
351 352
352 VulkanTestContext::~VulkanTestContext() { 353 VulkanWindowContext::~VulkanWindowContext() {
353 this->destroyContext(); 354 this->destroyContext();
354 } 355 }
355 356
356 void VulkanTestContext::destroyContext() { 357 void VulkanWindowContext::destroyContext() {
357 if (!fBackendContext.get()) { 358 if (!fBackendContext.get()) {
358 return; 359 return;
359 } 360 }
360 361
361 GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDev ice)); 362 GR_VK_CALL(fBackendContext->fInterface, DeviceWaitIdle(fBackendContext->fDev ice));
362 363
363 this->destroyBuffers(); 364 this->destroyBuffers();
364 365
365 if (VK_NULL_HANDLE != fCommandPool) { 366 if (VK_NULL_HANDLE != fCommandPool) {
366 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte xt->fDevice, 367 GR_VK_CALL(fBackendContext->fInterface, DestroyCommandPool(fBackendConte xt->fDevice,
367 fCommandPool, nullptr)); 368 fCommandPool, nullptr));
368 fCommandPool = VK_NULL_HANDLE; 369 fCommandPool = VK_NULL_HANDLE;
369 } 370 }
370 371
371 if (VK_NULL_HANDLE != fSwapchain) { 372 if (VK_NULL_HANDLE != fSwapchain) {
372 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); 373 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr);
373 fSwapchain = VK_NULL_HANDLE; 374 fSwapchain = VK_NULL_HANDLE;
374 } 375 }
375 376
376 if (VK_NULL_HANDLE != fSurface) { 377 if (VK_NULL_HANDLE != fSurface) {
377 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); 378 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr);
378 fSurface = VK_NULL_HANDLE; 379 fSurface = VK_NULL_HANDLE;
379 } 380 }
380 381
381 delete fContext; 382 delete fContext;
382 383
383 fBackendContext.reset(nullptr); 384 fBackendContext.reset(nullptr);
384 } 385 }
385 386
386 VulkanTestContext::BackbufferInfo* VulkanTestContext::getAvailableBackbuffer() { 387 VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer () {
387 SkASSERT(fBackbuffers); 388 SkASSERT(fBackbuffers);
388 389
389 ++fCurrentBackbufferIndex; 390 ++fCurrentBackbufferIndex;
390 if (fCurrentBackbufferIndex > fImageCount) { 391 if (fCurrentBackbufferIndex > fImageCount) {
391 fCurrentBackbufferIndex = 0; 392 fCurrentBackbufferIndex = 0;
392 } 393 }
393 394
394 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; 395 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex;
395 396
396 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 397 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
397 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f UsageFences, 398 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f UsageFences,
398 true, UINT64_MAX)); 399 true, UINT64_MAX));
399 return backbuffer; 400 return backbuffer;
400 } 401 }
401 402
402 SkSurface* VulkanTestContext::getBackbufferSurface() { 403 SkSurface* VulkanWindowContext::getBackbufferSurface() {
403 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); 404 BackbufferInfo* backbuffer = this->getAvailableBackbuffer();
404 SkASSERT(backbuffer); 405 SkASSERT(backbuffer);
405 406
406 // reset the fence 407 // reset the fence
407 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 408 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
408 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs ageFences)); 409 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs ageFences));
409 // semaphores should be in unsignaled state 410 // semaphores should be in unsignaled state
410 411
411 // acquire the image 412 // acquire the image
412 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI NT64_MAX, 413 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI NT64_MAX,
413 backbuffer->fAcquireSemaphore, VK_NULL_H ANDLE, 414 backbuffer->fAcquireSemaphore, VK_NULL_H ANDLE,
414 &backbuffer->fImageIndex); 415 &backbuffer->fImageIndex);
415 if (VK_ERROR_SURFACE_LOST_KHR == res) { 416 if (VK_ERROR_SURFACE_LOST_KHR == res) {
416 // need to figure out how to create a new vkSurface without the platform Data* 417 // need to figure out how to create a new vkSurface without the platform Data*
417 // maybe use attach somehow? but need a Window 418 // maybe use attach somehow? but need a Window
418 return nullptr; 419 return nullptr;
419 } 420 }
420 if (VK_ERROR_OUT_OF_DATE_KHR == res) { 421 if (VK_ERROR_OUT_OF_DATE_KHR == res) {
421 // tear swapchain down and try again 422 // tear swapchain down and try again
422 if (!this->createSwapchain(0, 0)) { 423 if (!this->createSwapchain(0, 0)) {
423 return nullptr; 424 return nullptr;
424 } 425 }
425 426
426 // acquire the image 427 // acquire the image
427 res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64 _MAX, 428 res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UINT64_ MAX,
428 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE , 429 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE ,
429 &backbuffer->fImageIndex); 430 &backbuffer->fImageIndex);
430 431
431 if (VK_SUCCESS != res) { 432 if (VK_SUCCESS != res) {
432 return nullptr; 433 return nullptr;
433 } 434 }
434 } 435 }
435 436
436 // set up layout transfer from initial to color attachment 437 // set up layout transfer from initial to color attachment
437 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; 438 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex];
438 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? 439 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ?
439 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : 440 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT :
440 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT; 441 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT;
441 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT; 442 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT;
442 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? 443 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ?
443 0 : VK_ACCESS_MEMORY_READ_BIT; 444 0 : VK_ACCESS_MEMORY_READ_BIT;
444 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; 445 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
445 446
446 VkImageMemoryBarrier imageMemoryBarrier = { 447 VkImageMemoryBarrier imageMemoryBarrier = {
447 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType 448 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType
448 NULL, // pNext 449 NULL, // pNext
449 srcAccessMask, // outputMask 450 srcAccessMask, // outputMask
450 dstAccessMask, // inputMask 451 dstAccessMask, // inputMask
451 layout, // oldLayout 452 layout, // oldLayout
452 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout 453 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // newLayout
453 fPresentQueueIndex, // srcQueueFamilyIndex 454 fPresentQueueIndex, // srcQueueFamilyIndex
454 fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex 455 fBackendContext->fGraphicsQueueIndex, // dstQueueFamilyIndex
455 fImages[backbuffer->fImageIndex], // image 456 fImages[backbuffer->fImageIndex], // image
456 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange 457 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 } // subresourceRange
457 }; 458 };
458 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 459 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
459 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0], 0)); 460 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[0], 0));
460 VkCommandBufferBeginInfo info; 461 VkCommandBufferBeginInfo info;
461 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); 462 memset(&info, 0, sizeof(VkCommandBufferBeginInfo));
462 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; 463 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
463 info.flags = 0; 464 info.flags = 0;
464 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 465 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
465 BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[0], &info)); 466 BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[0], &info));
466 467
467 GR_VK_CALL(fBackendContext->fInterface, 468 GR_VK_CALL(fBackendContext->fInterface,
468 CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0], 469 CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[0],
469 srcStageMask, dstStageMask, 0, 470 srcStageMask, dstStageMask, 0,
470 0, nullptr, 471 0, nullptr,
471 0, nullptr, 472 0, nullptr,
472 1, &imageMemoryBarrier)); 473 1, &imageMemoryBarrier));
473 474
474 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 475 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
475 EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0])); 476 EndCommandBuffer(backbuffer->fTransitionCmdBuffers[0]));
476 477
477 VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_ OUTPUT_BIT; 478 VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_ OUTPUT_BIT;
478 // insert the layout transfer into the queue and wait on the acquire 479 // insert the layout transfer into the queue and wait on the acquire
479 VkSubmitInfo submitInfo; 480 VkSubmitInfo submitInfo;
480 memset(&submitInfo, 0, sizeof(VkSubmitInfo)); 481 memset(&submitInfo, 0, sizeof(VkSubmitInfo));
481 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; 482 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
482 submitInfo.waitSemaphoreCount = 1; 483 submitInfo.waitSemaphoreCount = 1;
483 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; 484 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore;
484 submitInfo.pWaitDstStageMask = &waitDstStageFlags; 485 submitInfo.pWaitDstStageMask = &waitDstStageFlags;
485 submitInfo.commandBufferCount = 1; 486 submitInfo.commandBufferCount = 1;
486 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; 487 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0];
487 submitInfo.signalSemaphoreCount = 0; 488 submitInfo.signalSemaphoreCount = 0;
488 489
489 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 490 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
490 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, 491 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo,
491 backbuffer->fUsageFences[0])); 492 backbuffer->fUsageFences[0]));
492 493
493 return fSurfaces[backbuffer->fImageIndex].get(); 494 return fSurfaces[backbuffer->fImageIndex].get();
494 } 495 }
495 496
496 497
497 void VulkanTestContext::swapBuffers() { 498 void VulkanWindowContext::swapBuffers() {
498 499
499 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; 500 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex;
500 501
501 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 502 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
502 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT; 503 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU T_BIT;
503 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; 504 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
504 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; 505 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
505 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; 506 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
506 507
507 VkImageMemoryBarrier imageMemoryBarrier = { 508 VkImageMemoryBarrier imageMemoryBarrier = {
(...skipping 10 matching lines...) Expand all
518 }; 519 };
519 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 520 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
520 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1], 0)); 521 ResetCommandBuffer(backbuffer->fTransitionCmdBuffers[1], 0));
521 VkCommandBufferBeginInfo info; 522 VkCommandBufferBeginInfo info;
522 memset(&info, 0, sizeof(VkCommandBufferBeginInfo)); 523 memset(&info, 0, sizeof(VkCommandBufferBeginInfo));
523 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; 524 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
524 info.flags = 0; 525 info.flags = 0;
525 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 526 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
526 BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[1], &info)); 527 BeginCommandBuffer(backbuffer->fTransitionCmdBuffers[1], &info));
527 GR_VK_CALL(fBackendContext->fInterface, 528 GR_VK_CALL(fBackendContext->fInterface,
528 CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1], 529 CmdPipelineBarrier(backbuffer->fTransitionCmdBuffers[1],
529 srcStageMask, dstStageMask, 0, 530 srcStageMask, dstStageMask, 0,
530 0, nullptr, 531 0, nullptr,
531 0, nullptr, 532 0, nullptr,
532 1, &imageMemoryBarrier)); 533 1, &imageMemoryBarrier));
533 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 534 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
534 EndCommandBuffer(backbuffer->fTransitionCmdBuffers[1])); 535 EndCommandBuffer(backbuffer->fTransitionCmdBuffers[1]));
535 536
536 fImageLayouts[backbuffer->fImageIndex] = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; 537 fImageLayouts[backbuffer->fImageIndex] = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
537 538
538 // insert the layout transfer into the queue and wait on the acquire 539 // insert the layout transfer into the queue and wait on the acquire
539 VkSubmitInfo submitInfo; 540 VkSubmitInfo submitInfo;
540 memset(&submitInfo, 0, sizeof(VkSubmitInfo)); 541 memset(&submitInfo, 0, sizeof(VkSubmitInfo));
541 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; 542 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
542 submitInfo.waitSemaphoreCount = 0; 543 submitInfo.waitSemaphoreCount = 0;
543 submitInfo.pWaitDstStageMask = 0; 544 submitInfo.pWaitDstStageMask = 0;
544 submitInfo.commandBufferCount = 1; 545 submitInfo.commandBufferCount = 1;
545 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[1]; 546 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[1];
546 submitInfo.signalSemaphoreCount = 1; 547 submitInfo.signalSemaphoreCount = 1;
547 submitInfo.pSignalSemaphores = &backbuffer->fRenderSemaphore; 548 submitInfo.pSignalSemaphores = &backbuffer->fRenderSemaphore;
548 549
549 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, 550 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface,
550 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, 551 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo,
551 backbuffer->fUsageFences[1])); 552 backbuffer->fUsageFences[1]));
552 553
553 // Submit present operation to present queue 554 // Submit present operation to present queue
554 const VkPresentInfoKHR presentInfo = 555 const VkPresentInfoKHR presentInfo =
555 { 556 {
556 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType 557 VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType
557 NULL, // pNext 558 NULL, // pNext
558 1, // waitSemaphoreCount 559 1, // waitSemaphoreCount
559 &backbuffer->fRenderSemaphore, // pWaitSemaphores 560 &backbuffer->fRenderSemaphore, // pWaitSemaphores
560 1, // swapchainCount 561 1, // swapchainCount
561 &fSwapchain, // pSwapchains 562 &fSwapchain, // pSwapchains
562 &backbuffer->fImageIndex, // pImageIndices 563 &backbuffer->fImageIndex, // pImageIndices
563 NULL // pResults 564 NULL // pResults
564 }; 565 };
565 566
566 fQueuePresentKHR(fPresentQueue, &presentInfo); 567 fQueuePresentKHR(fPresentQueue, &presentInfo);
567 568
568 } 569 }
570
571 } //namespace sk_app
OLDNEW
« no previous file with comments | « tools/viewer/sk_app/VulkanWindowContext.h ('k') | tools/viewer/sk_app/Window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698