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 "GrRenderTarget.h" | 10 #include "GrRenderTarget.h" |
11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
12 #include "VulkanWindowContext.h" | 12 #include "VulkanWindowContext.h" |
13 | 13 |
14 #include "vk/GrVkInterface.h" | 14 #include "vk/GrVkInterface.h" |
| 15 #include "vk/GrVkMemory.h" |
15 #include "vk/GrVkUtil.h" | 16 #include "vk/GrVkUtil.h" |
16 #include "vk/GrVkTypes.h" | 17 #include "vk/GrVkTypes.h" |
17 | 18 |
18 #ifdef VK_USE_PLATFORM_WIN32_KHR | 19 #ifdef VK_USE_PLATFORM_WIN32_KHR |
19 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW | 20 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
20 #undef CreateSemaphore | 21 #undef CreateSemaphore |
21 #endif | 22 #endif |
22 | 23 |
23 #define GET_PROC(F) f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk"
#F) | 24 #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 #define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk"
#F) |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // set up initial image layouts and create surfaces | 256 // set up initial image layouts and create surfaces |
256 fImageLayouts = new VkImageLayout[fImageCount]; | 257 fImageLayouts = new VkImageLayout[fImageCount]; |
257 fSurfaces = new sk_sp<SkSurface>[fImageCount]; | 258 fSurfaces = new sk_sp<SkSurface>[fImageCount]; |
258 for (uint32_t i = 0; i < fImageCount; ++i) { | 259 for (uint32_t i = 0; i < fImageCount; ++i) { |
259 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; | 260 fImageLayouts[i] = VK_IMAGE_LAYOUT_UNDEFINED; |
260 | 261 |
261 GrBackendRenderTargetDesc desc; | 262 GrBackendRenderTargetDesc desc; |
262 GrVkImageInfo info; | 263 GrVkImageInfo info; |
263 info.fImage = fImages[i]; | 264 info.fImage = fImages[i]; |
264 info.fAlloc = { VK_NULL_HANDLE, 0, 0 }; | 265 info.fAlloc = { VK_NULL_HANDLE, 0, 0 }; |
265 info.fImageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | 266 info.fImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
266 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | 267 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
267 info.fFormat = format; | 268 info.fFormat = format; |
268 info.fLevelCount = 1; | 269 info.fLevelCount = 1; |
269 desc.fWidth = fWidth; | 270 desc.fWidth = fWidth; |
270 desc.fHeight = fHeight; | 271 desc.fHeight = fHeight; |
271 desc.fConfig = fPixelConfig; | 272 desc.fConfig = fPixelConfig; |
272 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 273 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
273 desc.fSampleCnt = 0; | 274 desc.fSampleCnt = 0; |
274 desc.fStencilBits = 0; | 275 desc.fStencilBits = 0; |
275 desc.fRenderTargetHandle = (GrBackendObject) &info; | 276 desc.fRenderTargetHandle = (GrBackendObject) &info; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE
, | 453 backbuffer->fAcquireSemaphore, VK_NULL_HANDLE
, |
453 &backbuffer->fImageIndex); | 454 &backbuffer->fImageIndex); |
454 | 455 |
455 if (VK_SUCCESS != res) { | 456 if (VK_SUCCESS != res) { |
456 return nullptr; | 457 return nullptr; |
457 } | 458 } |
458 } | 459 } |
459 | 460 |
460 // set up layout transfer from initial to color attachment | 461 // set up layout transfer from initial to color attachment |
461 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; | 462 VkImageLayout layout = fImageLayouts[backbuffer->fImageIndex]; |
| 463 SkASSERT(VK_IMAGE_LAYOUT_UNDEFINED == layout || VK_IMAGE_LAYOUT_PRESENT_SRC_
KHR == layout); |
462 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 464 VkPipelineStageFlags srcStageMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
463 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : | 465 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT : |
464 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 466 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
465 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 467 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
466 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? | 468 VkAccessFlags srcAccessMask = (VK_IMAGE_LAYOUT_UNDEFINED == layout) ? |
467 0 : VK_ACCESS_MEMORY_READ_BIT; | 469 0 : VK_ACCESS_MEMORY_READ_BIT; |
468 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 470 VkAccessFlags dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
469 | 471 |
470 VkImageMemoryBarrier imageMemoryBarrier = { | 472 VkImageMemoryBarrier imageMemoryBarrier = { |
471 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 473 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; | 509 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; |
508 submitInfo.pWaitDstStageMask = &waitDstStageFlags; | 510 submitInfo.pWaitDstStageMask = &waitDstStageFlags; |
509 submitInfo.commandBufferCount = 1; | 511 submitInfo.commandBufferCount = 1; |
510 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; | 512 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; |
511 submitInfo.signalSemaphoreCount = 0; | 513 submitInfo.signalSemaphoreCount = 0; |
512 | 514 |
513 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 515 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
514 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, | 516 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
515 backbuffer->fUsageFences[0])); | 517 backbuffer->fUsageFences[0])); |
516 | 518 |
517 return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); | 519 GrVkImageInfo* imageInfo; |
| 520 SkSurface* surface = fSurfaces[backbuffer->fImageIndex].get(); |
| 521 surface->getRenderTargetHandle((GrBackendObject*)&imageInfo, |
| 522 SkSurface::kFlushRead_BackendHandleAccess); |
| 523 imageInfo->updateImageLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); |
| 524 |
| 525 return sk_ref_sp(surface); |
518 } | 526 } |
519 | 527 |
520 void VulkanWindowContext::swapBuffers() { | 528 void VulkanWindowContext::swapBuffers() { |
521 | 529 |
522 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; | 530 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 531 GrVkImageInfo* imageInfo; |
| 532 SkSurface* surface = fSurfaces[backbuffer->fImageIndex].get(); |
| 533 surface->getRenderTargetHandle((GrBackendObject*)&imageInfo, |
| 534 SkSurface::kFlushRead_BackendHandleAccess); |
| 535 // Check to make sure we never change the actually wrapped image |
| 536 SkASSERT(imageInfo->fImage == fImages[backbuffer->fImageIndex]); |
523 | 537 |
524 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | 538 VkImageLayout layout = imageInfo->fImageLayout; |
525 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 539 VkPipelineStageFlags srcStageMask = GrVkMemory::LayoutToPipelineStageFlags(l
ayout); |
526 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; | 540 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
527 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 541 VkAccessFlags srcAccessMask = GrVkMemory::LayoutToSrcAccessMask(layout); |
528 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; | 542 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
529 | 543 |
530 VkImageMemoryBarrier imageMemoryBarrier = { | 544 VkImageMemoryBarrier imageMemoryBarrier = { |
531 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType | 545 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // sType |
532 NULL, // pNext | 546 NULL, // pNext |
533 srcAccessMask, // outputMask | 547 srcAccessMask, // outputMask |
534 dstAccessMask, // inputMask | 548 dstAccessMask, // inputMask |
535 layout, // oldLayout | 549 layout, // oldLayout |
536 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout | 550 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, // newLayout |
537 fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex | 551 fBackendContext->fGraphicsQueueIndex, // srcQueueFamilyIndex |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 1, // swapchainCount | 597 1, // swapchainCount |
584 &fSwapchain, // pSwapchains | 598 &fSwapchain, // pSwapchains |
585 &backbuffer->fImageIndex, // pImageIndices | 599 &backbuffer->fImageIndex, // pImageIndices |
586 NULL // pResults | 600 NULL // pResults |
587 }; | 601 }; |
588 | 602 |
589 fQueuePresentKHR(fPresentQueue, &presentInfo); | 603 fQueuePresentKHR(fPresentQueue, &presentInfo); |
590 } | 604 } |
591 | 605 |
592 } //namespace sk_app | 606 } //namespace sk_app |
OLD | NEW |