Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 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 | #ifndef GrVkSemaphore_DEFINED |
| 9 | #define GrVkSemaphore_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrSemaphore.h" |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/gpu/vk/GrVkTypes.h" |
| 14 | #include "src/gpu/GrResourceProvider.h" |
| 15 | #include "src/gpu/vk/GrVkResource.h" |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 16 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 17 | class GrBackendSemaphore; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 18 | class GrVkGpu; |
| 19 | |
| 20 | class GrVkSemaphore : public GrSemaphore { |
| 21 | public: |
Brian Salomon | 62db8d5 | 2018-08-30 10:37:47 -0400 | [diff] [blame] | 22 | static sk_sp<GrVkSemaphore> Make(GrVkGpu* gpu, bool isOwned); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 23 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 24 | using WrapType = GrResourceProvider::SemaphoreWrapType; |
| 25 | |
Brian Salomon | 62db8d5 | 2018-08-30 10:37:47 -0400 | [diff] [blame] | 26 | static sk_sp<GrVkSemaphore> MakeWrapped(GrVkGpu* gpu, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 27 | VkSemaphore semaphore, |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 28 | WrapType wrapType, |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 29 | GrWrapOwnership); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 30 | |
Brian Salomon | 1e576e7 | 2018-08-30 10:20:38 -0400 | [diff] [blame] | 31 | GrBackendSemaphore backendSemaphore() const override; |
| 32 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 33 | class Resource : public GrVkResource { |
| 34 | public: |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 35 | Resource(VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait, bool isOwned) |
| 36 | : INHERITED() |
| 37 | , fSemaphore(semaphore) |
| 38 | , fHasBeenSubmittedToQueueForSignal(prohibitSignal) |
| 39 | , fHasBeenSubmittedToQueueForWait(prohibitWait) |
| 40 | , fIsOwned(isOwned) {} |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 41 | |
| 42 | ~Resource() override {} |
| 43 | |
| 44 | VkSemaphore semaphore() const { return fSemaphore; } |
| 45 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 46 | bool shouldSignal() const { |
| 47 | return !fHasBeenSubmittedToQueueForSignal; |
| 48 | } |
| 49 | bool shouldWait() const { |
| 50 | return !fHasBeenSubmittedToQueueForWait; |
| 51 | } |
| 52 | |
| 53 | void markAsSignaled() { |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 54 | fHasBeenSubmittedToQueueForSignal = true; |
| 55 | } |
| 56 | void markAsWaited() { |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 57 | fHasBeenSubmittedToQueueForWait = true; |
| 58 | } |
| 59 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 60 | #ifdef SK_TRACE_VK_RESOURCES |
| 61 | void dumpInfo() const override { |
| 62 | SkDebugf("GrVkSemaphore: %d (%d refs)\n", fSemaphore, this->getRefCnt()); |
| 63 | } |
| 64 | #endif |
| 65 | private: |
Ethan Nicholas | 8e265a7 | 2018-12-12 16:22:40 -0500 | [diff] [blame] | 66 | void freeGPUData(GrVkGpu* gpu) const override; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 67 | |
| 68 | VkSemaphore fSemaphore; |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 69 | bool fHasBeenSubmittedToQueueForSignal; |
| 70 | bool fHasBeenSubmittedToQueueForWait; |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 71 | bool fIsOwned; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 72 | |
| 73 | typedef GrVkResource INHERITED; |
| 74 | }; |
| 75 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 76 | Resource* getResource() { return fResource; } |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 77 | |
| 78 | private: |
Brian Salomon | 62db8d5 | 2018-08-30 10:37:47 -0400 | [diff] [blame] | 79 | GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait, |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 80 | bool isOwned); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 81 | |
Brian Salomon | 62db8d5 | 2018-08-30 10:37:47 -0400 | [diff] [blame] | 82 | void onRelease() override; |
| 83 | void onAbandon() override; |
| 84 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 85 | Resource* fResource; |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 86 | |
| 87 | typedef GrSemaphore INHERITED; |
| 88 | }; |
| 89 | |
| 90 | #endif |