Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 1 | // Copyright 2018 The SwiftShader Authors. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef VK_SEMAPHORE_HPP_ |
| 16 | #define VK_SEMAPHORE_HPP_ |
| 17 | |
David 'Digit' Turner | 7c4d0a0 | 2019-09-03 17:00:02 +0200 | [diff] [blame] | 18 | #include "VkConfig.h" |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 19 | #include "VkObject.hpp" |
| 20 | |
David 'Digit' Turner | fda994c | 2019-09-04 16:36:36 +0200 | [diff] [blame] | 21 | #if SWIFTSHADER_EXTERNAL_SEMAPHORE_ZIRCON_EVENT |
| 22 | #include <zircon/types.h> |
| 23 | #endif |
| 24 | |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 25 | namespace vk |
| 26 | { |
| 27 | |
| 28 | class Semaphore : public Object<Semaphore, VkSemaphore> |
| 29 | { |
| 30 | public: |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 31 | Semaphore(const VkSemaphoreCreateInfo* pCreateInfo, void* mem); |
| 32 | void destroy(const VkAllocationCallbacks* pAllocator); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 33 | |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 34 | static size_t ComputeRequiredAllocationSize(const VkSemaphoreCreateInfo* pCreateInfo); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 35 | |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 36 | void wait(); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 37 | |
| 38 | void wait(const VkPipelineStageFlags& flag) |
| 39 | { |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 40 | // NOTE: not sure what else to do here? |
| 41 | wait(); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 42 | } |
| 43 | |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 44 | void signal(); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 45 | |
David 'Digit' Turner | 7c4d0a0 | 2019-09-03 17:00:02 +0200 | [diff] [blame] | 46 | #if SWIFTSHADER_EXTERNAL_SEMAPHORE_LINUX_MEMFD |
| 47 | VkResult importFd(int fd, bool temporaryImport); |
| 48 | VkResult exportFd(int* pFd) const; |
| 49 | #endif |
| 50 | |
David 'Digit' Turner | fda994c | 2019-09-04 16:36:36 +0200 | [diff] [blame] | 51 | #if SWIFTSHADER_EXTERNAL_SEMAPHORE_ZIRCON_EVENT |
| 52 | VkResult importHandle(zx_handle_t handle, bool temporaryImport); |
| 53 | VkResult exportHandle(zx_handle_t *pHandle) const; |
| 54 | #endif |
| 55 | |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 56 | private: |
David 'Digit' Turner | 7c4d0a0 | 2019-09-03 17:00:02 +0200 | [diff] [blame] | 57 | class External; |
David 'Digit' Turner | 99938ea | 2019-09-03 15:11:17 +0200 | [diff] [blame] | 58 | class Impl; |
| 59 | Impl* impl = nullptr; |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static inline Semaphore* Cast(VkSemaphore object) |
| 63 | { |
Alexis Hetu | bd4cf81 | 2019-06-14 15:14:07 -0400 | [diff] [blame] | 64 | return Semaphore::Cast(object); |
Alexis Hetu | 1f23d8c | 2018-10-16 14:40:19 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } // namespace vk |
| 68 | |
| 69 | #endif // VK_SEMAPHORE_HPP_ |