| 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/ganesh/GrBackendSemaphore.h" |
| 11 |
#include "include/gpu/ganesh/vk/GrVkBackendSemaphore.h" |
| 12 |
#include "include/private/base/SkAssert.h" |
| 13 |
#include "src/gpu/ganesh/vk/GrVkGpu.h" |
| 14 |
#include "src/gpu/ganesh/vk/GrVkUtil.h" |
| 15 |
|
| 16 |
#include <string.h> |
| 17 |
|
| 18 |
#ifdef VK_USE_PLATFORM_WIN32_KHR |
| 19 |
// windows wants to define this as CreateSemaphoreA or CreateSemaphoreW |
| 20 |
#undef CreateSemaphore |
| 21 |
#endif |
| 22 |
|
| 23 |
std::unique_ptr<GrVkSemaphore> GrVkSemaphore::Make(GrVkGpu* gpu, bool isOwned) { |
| 24 |
VkSemaphoreCreateInfo createInfo; |
| 25 |
memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo)); |
| 26 |
createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 27 |
createInfo.pNext = nullptr; |
| 28 |
createInfo.flags = 0; |
| 29 |
VkSemaphore semaphore = VK_NULL_HANDLE; |
| 30 |
VkResult result; |
| 31 |
GR_VK_CALL_RESULT(gpu, result, CreateSemaphore(gpu->device(), &createInfo, nullptr, |
| 32 |
&semaphore)); |
| 33 |
if (result != VK_SUCCESS) { |
| 34 |
return nullptr; |
| 35 |
} |
| 36 |
|
| 37 |
return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned)); |
| 38 |
} |
| 39 |
|
| 40 |
std::unique_ptr<GrVkSemaphore> GrVkSemaphore::MakeWrapped(GrVkGpu* gpu, |
| 41 |
VkSemaphore semaphore, |
| 42 |
GrSemaphoreWrapType wrapType, |
| 43 |
GrWrapOwnership ownership) { |
| 44 |
if (VK_NULL_HANDLE == semaphore) { |
| 45 |
SkDEBUGFAIL("Trying to wrap an invalid VkSemaphore"); |
| 46 |
return nullptr; |
| 47 |
} |
| 48 |
bool prohibitSignal = GrSemaphoreWrapType::kWillWait == wrapType; |
| 49 |
bool prohibitWait = GrSemaphoreWrapType::kWillSignal == wrapType; |
| 50 |
return std::unique_ptr<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, prohibitSignal, |
| 51 |
prohibitWait, |
| 52 |
kBorrow_GrWrapOwnership != ownership)); |
| 53 |
} |
| 54 |
|
| 55 |
GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal, |
| 56 |
bool prohibitWait, bool isOwned) { |
| 57 |
fResource = new Resource(gpu, semaphore, prohibitSignal, prohibitWait, isOwned); |
| 58 |
} |
| 59 |
|
| 60 |
GrVkSemaphore::~GrVkSemaphore() { |
| 61 |
if (fResource) { |
| 62 |
fResource->unref(); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
void GrVkSemaphore::Resource::freeGPUData() const { |
| 67 |
if (fIsOwned) { |
| 68 |
GR_VK_CALL(fGpu->vkInterface(), |
| 69 |
DestroySemaphore(fGpu->device(), fSemaphore, nullptr)); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
GrBackendSemaphore GrVkSemaphore::backendSemaphore() const { |
| 74 |
return GrBackendSemaphores::MakeVk(fResource->semaphore()); |
| 75 |
} |