| 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 "VulkanWindowContext.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 namespace sk_app { | 25 namespace sk_app { |
| 26 | 26 |
| 27 VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams
& params) | 27 VulkanWindowContext::VulkanWindowContext(void* platformData, const DisplayParams
& params) |
| 28 : fSurface(VK_NULL_HANDLE) | 28 : WindowContext() |
| 29 , fSurface(VK_NULL_HANDLE) |
| 29 , fSwapchain(VK_NULL_HANDLE) | 30 , fSwapchain(VK_NULL_HANDLE) |
| 31 , fImages(nullptr) |
| 32 , fImageLayouts(nullptr) |
| 33 , fSurfaces(nullptr) |
| 30 , fCommandPool(VK_NULL_HANDLE) | 34 , fCommandPool(VK_NULL_HANDLE) |
| 31 , fBackbuffers(nullptr) { | 35 , fBackbuffers(nullptr) { |
| 32 | 36 |
| 33 // any config code here (particularly for msaa)? | 37 // any config code here (particularly for msaa)? |
| 34 | 38 |
| 35 this->initializeContext(platformData, params); | 39 this->initializeContext(platformData, params); |
| 36 } | 40 } |
| 37 | 41 |
| 38 void VulkanWindowContext::initializeContext(void* platformData, const DisplayPar
ams& params) { | 42 void VulkanWindowContext::initializeContext(void* platformData, const DisplayPar
ams& params) { |
| 39 | 43 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; | 266 info.fImageTiling = VK_IMAGE_TILING_OPTIMAL; |
| 263 info.fFormat = format; | 267 info.fFormat = format; |
| 264 info.fLevelCount = 1; | 268 info.fLevelCount = 1; |
| 265 desc.fWidth = fWidth; | 269 desc.fWidth = fWidth; |
| 266 desc.fHeight = fHeight; | 270 desc.fHeight = fHeight; |
| 267 desc.fConfig = fPixelConfig; | 271 desc.fConfig = fPixelConfig; |
| 268 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 272 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 269 desc.fSampleCnt = 0; | 273 desc.fSampleCnt = 0; |
| 270 desc.fStencilBits = 0; | 274 desc.fStencilBits = 0; |
| 271 desc.fRenderTargetHandle = (GrBackendObject) &info; | 275 desc.fRenderTargetHandle = (GrBackendObject) &info; |
| 276 // TODO: base this on fSurfaceProps |
| 272 SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig) | 277 SkSurfaceProps props(GrPixelConfigIsSRGB(fPixelConfig) |
| 273 ? SkSurfaceProps::kGammaCorrect_Flag : 0, | 278 ? SkSurfaceProps::kGammaCorrect_Flag : 0, |
| 274 kUnknown_SkPixelGeometry); | 279 kUnknown_SkPixelGeometry); |
| 275 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); | 280 fSurfaces[i] = SkSurface::MakeFromBackendRenderTarget(fContext, desc, &p
rops); |
| 276 } | 281 } |
| 277 | 282 |
| 278 // create the command pool for the command buffers | 283 // create the command pool for the command buffers |
| 279 if (VK_NULL_HANDLE == fCommandPool) { | 284 if (VK_NULL_HANDLE == fCommandPool) { |
| 280 VkCommandPoolCreateInfo commandPoolInfo; | 285 VkCommandPoolCreateInfo commandPoolInfo; |
| 281 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); | 286 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (VK_NULL_HANDLE != fSwapchain) { | 396 if (VK_NULL_HANDLE != fSwapchain) { |
| 392 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); | 397 fDestroySwapchainKHR(fBackendContext->fDevice, fSwapchain, nullptr); |
| 393 fSwapchain = VK_NULL_HANDLE; | 398 fSwapchain = VK_NULL_HANDLE; |
| 394 } | 399 } |
| 395 | 400 |
| 396 if (VK_NULL_HANDLE != fSurface) { | 401 if (VK_NULL_HANDLE != fSurface) { |
| 397 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); | 402 fDestroySurfaceKHR(fBackendContext->fInstance, fSurface, nullptr); |
| 398 fSurface = VK_NULL_HANDLE; | 403 fSurface = VK_NULL_HANDLE; |
| 399 } | 404 } |
| 400 | 405 |
| 401 delete fContext; | 406 fContext->abandonContext(); |
| 407 fContext->unref(); |
| 402 | 408 |
| 403 fBackendContext.reset(nullptr); | 409 fBackendContext.reset(nullptr); |
| 404 } | 410 } |
| 405 | 411 |
| 406 VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer
() { | 412 VulkanWindowContext::BackbufferInfo* VulkanWindowContext::getAvailableBackbuffer
() { |
| 407 SkASSERT(fBackbuffers); | 413 SkASSERT(fBackbuffers); |
| 408 | 414 |
| 409 ++fCurrentBackbufferIndex; | 415 ++fCurrentBackbufferIndex; |
| 410 if (fCurrentBackbufferIndex > fImageCount) { | 416 if (fCurrentBackbufferIndex > fImageCount) { |
| 411 fCurrentBackbufferIndex = 0; | 417 fCurrentBackbufferIndex = 0; |
| 412 } | 418 } |
| 413 | 419 |
| 414 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; | 420 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 415 | 421 |
| 416 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 422 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 417 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f
UsageFences, | 423 WaitForFences(fBackendContext->fDevice, 2, backbuffer->f
UsageFences, |
| 418 true, UINT64_MAX)); | 424 true, UINT64_MAX)); |
| 419 return backbuffer; | 425 return backbuffer; |
| 420 } | 426 } |
| 421 | 427 |
| 422 SkSurface* VulkanWindowContext::getBackbufferSurface() { | 428 sk_sp<SkSurface> VulkanWindowContext::getBackbufferSurface() { |
| 423 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); | 429 BackbufferInfo* backbuffer = this->getAvailableBackbuffer(); |
| 424 SkASSERT(backbuffer); | 430 SkASSERT(backbuffer); |
| 425 | 431 |
| 426 // reset the fence | 432 // reset the fence |
| 427 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 433 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 428 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); | 434 ResetFences(fBackendContext->fDevice, 2, backbuffer->fUs
ageFences)); |
| 429 // semaphores should be in unsignaled state | 435 // semaphores should be in unsignaled state |
| 430 | 436 |
| 431 // acquire the image | 437 // acquire the image |
| 432 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI
NT64_MAX, | 438 VkResult res = fAcquireNextImageKHR(fBackendContext->fDevice, fSwapchain, UI
NT64_MAX, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; | 509 submitInfo.pWaitSemaphores = &backbuffer->fAcquireSemaphore; |
| 504 submitInfo.pWaitDstStageMask = &waitDstStageFlags; | 510 submitInfo.pWaitDstStageMask = &waitDstStageFlags; |
| 505 submitInfo.commandBufferCount = 1; | 511 submitInfo.commandBufferCount = 1; |
| 506 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; | 512 submitInfo.pCommandBuffers = &backbuffer->fTransitionCmdBuffers[0]; |
| 507 submitInfo.signalSemaphoreCount = 0; | 513 submitInfo.signalSemaphoreCount = 0; |
| 508 | 514 |
| 509 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, | 515 GR_VK_CALL_ERRCHECK(fBackendContext->fInterface, |
| 510 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, | 516 QueueSubmit(fBackendContext->fQueue, 1, &submitInfo, |
| 511 backbuffer->fUsageFences[0])); | 517 backbuffer->fUsageFences[0])); |
| 512 | 518 |
| 513 return fSurfaces[backbuffer->fImageIndex].get(); | 519 return sk_ref_sp(fSurfaces[backbuffer->fImageIndex].get()); |
| 514 } | 520 } |
| 515 | 521 |
| 516 | |
| 517 void VulkanWindowContext::swapBuffers() { | 522 void VulkanWindowContext::swapBuffers() { |
| 518 | 523 |
| 519 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; | 524 BackbufferInfo* backbuffer = fBackbuffers + fCurrentBackbufferIndex; |
| 520 | 525 |
| 521 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; | 526 VkImageLayout layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; |
| 522 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; | 527 VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPU
T_BIT; |
| 523 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; | 528 VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; |
| 524 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | 529 VkAccessFlags srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; |
| 525 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; | 530 VkAccessFlags dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; |
| 526 | 531 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 &fSwapchain, // pSwapchains | 586 &fSwapchain, // pSwapchains |
| 582 &backbuffer->fImageIndex, // pImageIndices | 587 &backbuffer->fImageIndex, // pImageIndices |
| 583 NULL // pResults | 588 NULL // pResults |
| 584 }; | 589 }; |
| 585 | 590 |
| 586 fQueuePresentKHR(fPresentQueue, &presentInfo); | 591 fQueuePresentKHR(fPresentQueue, &presentInfo); |
| 587 | 592 |
| 588 } | 593 } |
| 589 | 594 |
| 590 } //namespace sk_app | 595 } //namespace sk_app |
| OLD | NEW |