GrVkSemaphore.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include "src/gpu/vk/GrVkSemaphore.h"
  8. #include "include/gpu/GrBackendSemaphore.h"
  9. #include "src/gpu/vk/GrVkGpu.h"
  10. #include "src/gpu/vk/GrVkUtil.h"
  11. #ifdef VK_USE_PLATFORM_WIN32_KHR
  12. // windows wants to define this as CreateSemaphoreA or CreateSemaphoreW
  13. #undef CreateSemaphore
  14. #endif
  15. sk_sp<GrVkSemaphore> GrVkSemaphore::Make(GrVkGpu* gpu, bool isOwned) {
  16. VkSemaphoreCreateInfo createInfo;
  17. memset(&createInfo, 0, sizeof(VkSemaphoreCreateInfo));
  18. createInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
  19. createInfo.pNext = nullptr;
  20. createInfo.flags = 0;
  21. VkSemaphore semaphore = VK_NULL_HANDLE;
  22. GR_VK_CALL_ERRCHECK(gpu->vkInterface(),
  23. CreateSemaphore(gpu->device(), &createInfo, nullptr, &semaphore));
  24. return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, false, false, isOwned));
  25. }
  26. sk_sp<GrVkSemaphore> GrVkSemaphore::MakeWrapped(GrVkGpu* gpu,
  27. VkSemaphore semaphore,
  28. WrapType wrapType,
  29. GrWrapOwnership ownership) {
  30. if (VK_NULL_HANDLE == semaphore) {
  31. return nullptr;
  32. }
  33. bool prohibitSignal = WrapType::kWillWait == wrapType;
  34. bool prohibitWait = WrapType::kWillSignal == wrapType;
  35. return sk_sp<GrVkSemaphore>(new GrVkSemaphore(gpu, semaphore, prohibitSignal, prohibitWait,
  36. kBorrow_GrWrapOwnership != ownership));
  37. }
  38. GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal,
  39. bool prohibitWait, bool isOwned)
  40. : INHERITED(gpu) {
  41. fResource = new Resource(semaphore, prohibitSignal, prohibitWait, isOwned);
  42. isOwned ? this->registerWithCache(SkBudgeted::kNo)
  43. : this->registerWithCacheWrapped(GrWrapCacheable::kNo);
  44. }
  45. void GrVkSemaphore::onRelease() {
  46. if (fResource) {
  47. fResource->unref(static_cast<GrVkGpu*>(this->getGpu()));
  48. fResource = nullptr;
  49. }
  50. INHERITED::onRelease();
  51. }
  52. void GrVkSemaphore::onAbandon() {
  53. if (fResource) {
  54. fResource->unrefAndAbandon();
  55. fResource = nullptr;
  56. }
  57. INHERITED::onAbandon();
  58. }
  59. void GrVkSemaphore::Resource::freeGPUData(GrVkGpu* gpu) const {
  60. if (fIsOwned) {
  61. GR_VK_CALL(gpu->vkInterface(),
  62. DestroySemaphore(gpu->device(), fSemaphore, nullptr));
  63. }
  64. }
  65. GrBackendSemaphore GrVkSemaphore::backendSemaphore() const {
  66. GrBackendSemaphore backendSemaphore;
  67. backendSemaphore.initVulkan(fResource->semaphore());
  68. return backendSemaphore;
  69. }