blob: 53ad4c2176c58e3dbff43afe0042f0bd9e38d7c0 [file] [log] [blame]
Alexis Hetu1f23d8c2018-10-16 14:40:19 -04001// 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' Turner7c4d0a02019-09-03 17:00:02 +020018#include "VkConfig.h"
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040019#include "VkObject.hpp"
20
David 'Digit' Turner3a7101b2019-11-22 11:55:53 +010021#if VK_USE_PLATFORM_FUCHSIA
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +020022#include <zircon/types.h>
23#endif
24
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040025namespace vk
26{
27
28class Semaphore : public Object<Semaphore, VkSemaphore>
29{
30public:
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020031 Semaphore(const VkSemaphoreCreateInfo* pCreateInfo, void* mem);
32 void destroy(const VkAllocationCallbacks* pAllocator);
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040033
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020034 static size_t ComputeRequiredAllocationSize(const VkSemaphoreCreateInfo* pCreateInfo);
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040035
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020036 void wait();
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040037
38 void wait(const VkPipelineStageFlags& flag)
39 {
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020040 // NOTE: not sure what else to do here?
41 wait();
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040042 }
43
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020044 void signal();
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040045
David 'Digit' Turner3a7101b2019-11-22 11:55:53 +010046#if SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +020047 VkResult importFd(int fd, bool temporaryImport);
48 VkResult exportFd(int* pFd) const;
49#endif
50
David 'Digit' Turner3a7101b2019-11-22 11:55:53 +010051#if VK_USE_PLATFORM_FUCHSIA
David 'Digit' Turnerfda994c2019-09-04 16:36:36 +020052 VkResult importHandle(zx_handle_t handle, bool temporaryImport);
53 VkResult exportHandle(zx_handle_t *pHandle) const;
54#endif
55
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040056private:
David 'Digit' Turner7c4d0a02019-09-03 17:00:02 +020057 class External;
David 'Digit' Turner99938ea2019-09-03 15:11:17 +020058 class Impl;
59 Impl* impl = nullptr;
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040060};
61
62static inline Semaphore* Cast(VkSemaphore object)
63{
Alexis Hetubd4cf812019-06-14 15:14:07 -040064 return Semaphore::Cast(object);
Alexis Hetu1f23d8c2018-10-16 14:40:19 -040065}
66
67} // namespace vk
68
69#endif // VK_SEMAPHORE_HPP_