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 18 #include "VkConfig.h" 19 #include "VkObject.hpp" 20 21 #include "marl/event.h" 22 #include <mutex> 23 24 #if VK_USE_PLATFORM_FUCHSIA 25 # include <zircon/types.h> 26 #endif 27 28 namespace vk { 29 30 class Semaphore : public Object<Semaphore, VkSemaphore> 31 { 32 public: 33 Semaphore(const VkSemaphoreCreateInfo *pCreateInfo, void *mem, const VkAllocationCallbacks *pAllocator); 34 void destroy(const VkAllocationCallbacks *pAllocator); 35 36 static size_t ComputeRequiredAllocationSize(const VkSemaphoreCreateInfo *pCreateInfo); 37 38 void wait(); 39 wait(const VkPipelineStageFlags & flag)40 void wait(const VkPipelineStageFlags &flag) 41 { 42 // NOTE: not sure what else to do here? 43 wait(); 44 } 45 46 void signal(); 47 48 #if SWIFTSHADER_EXTERNAL_SEMAPHORE_OPAQUE_FD 49 VkResult importFd(int fd, bool temporaryImport); 50 VkResult exportFd(int *pFd); 51 #endif 52 53 #if VK_USE_PLATFORM_FUCHSIA 54 VkResult importHandle(zx_handle_t handle, bool temporaryImport); 55 VkResult exportHandle(zx_handle_t *pHandle); 56 #endif 57 58 class External; 59 60 private: 61 void allocateExternal(); 62 void deallocateExternal(); 63 64 const VkAllocationCallbacks *allocator = nullptr; 65 marl::Event internal; 66 std::mutex mutex; 67 External *external = nullptr; 68 bool temporaryImport = false; 69 }; 70 Cast(VkSemaphore object)71static inline Semaphore *Cast(VkSemaphore object) 72 { 73 return Semaphore::Cast(object); 74 } 75 76 } // namespace vk 77 78 #endif // VK_SEMAPHORE_HPP_ 79