• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "src/gpu/ganesh/vk/GrVkSemaphore.h"
9 
10 #include "include/gpu/GrBackendSemaphore.h"
11 #include "include/gpu/ganesh/vk/GrVkBackendSemaphore.h"
12 #include "src/gpu/ganesh/vk/GrVkGpu.h"
13 #include "src/gpu/ganesh/vk/GrVkUtil.h"
14 
15 #ifdef VK_USE_PLATFORM_WIN32_KHR
16 // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW
17 #undef CreateSemaphore
18 #endif
19 
Make(GrVkGpu * gpu,bool isOwned)20 std::unique_ptr<GrVkSemaphore> GrVkSemaphore::Make(GrVkGpu* gpu, bool isOwned) {
21     VkSemaphoreCreateInfo createInfo;
22     memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo));
23     createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
24     createInfo.pNext = nullptr;
25     createInfo.flags = 0;
26     VkSemaphore semaphore = VK_NULL_HANDLE;
27     VkResult result;
28     GR_VK_CALL_RESULT(gpu, result, CreateSemaphore(gpu->device(), &createInfo, nullptr,
29                                                    &semaphore));
30     if (result != VK_SUCCESS) {
31         return nullptr;
32     }
33 
34     return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned));
35 }
36 
MakeWrapped(GrVkGpu * gpu,VkSemaphore semaphore,GrSemaphoreWrapType wrapType,GrWrapOwnership ownership)37 std::unique_ptr<GrVkSemaphore> GrVkSemaphore::MakeWrapped(GrVkGpu* gpu,
38                                                           VkSemaphore semaphore,
39                                                           GrSemaphoreWrapType wrapType,
40                                                           GrWrapOwnership ownership) {
41     if (VK_NULL_HANDLE == semaphore) {
42         SkDEBUGFAIL("Trying to wrap an invalid VkSemaphore");
43         return nullptr;
44     }
45     bool prohibitSignal = GrSemaphoreWrapType::kWillWait == wrapType;
46     bool prohibitWait = GrSemaphoreWrapType::kWillSignal == wrapType;
47     return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, prohibitSignal,
48                                                             prohibitWait,
49                                                             kBorrow_GrWrapOwnership != ownership));
50 }
51 
GrVkSemaphore(GrVkGpu * gpu,VkSemaphore semaphore,bool prohibitSignal,bool prohibitWait,bool isOwned)52 GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
53                              bool prohibitWait, bool isOwned) {
54     fResource = new Resource(gpu, semaphore, prohibitSignal, prohibitWait, isOwned);
55 }
56 
~GrVkSemaphore()57 GrVkSemaphore::~GrVkSemaphore() {
58     if (fResource) {
59         fResource->unref();
60     }
61 }
62 
freeGPUData() const63 void GrVkSemaphore::Resource::freeGPUData() const {
64     if (fIsOwned) {
65         GR_VK_CALL(fGpu->vkInterface(),
66                    DestroySemaphore(fGpu->device(), fSemaphore, nullptr));
67     }
68 }
69 
backendSemaphore() const70 GrBackendSemaphore GrVkSemaphore::backendSemaphore() const {
71     return GrBackendSemaphores::MakeVk(fResource->semaphore());
72 }
73