7 changed files with 150 additions and 46 deletions
@ -0,0 +1,65 @@ |
|||
// Copyright 2022 Simon Boyé
|
|||
|
|||
#include <vk/Semaphore.h> |
|||
#include <vk/Context.h> |
|||
|
|||
#include <cassert> |
|||
|
|||
|
|||
namespace vk { |
|||
|
|||
|
|||
Semaphore::Semaphore() noexcept { |
|||
} |
|||
|
|||
Semaphore::Semaphore(Context& context) |
|||
: m_context(&context) |
|||
{ |
|||
assert(m_context); |
|||
|
|||
VkSemaphoreCreateInfo create_info { |
|||
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, |
|||
}; |
|||
if(vkCreateSemaphore( |
|||
context.device(), |
|||
&create_info, |
|||
nullptr, |
|||
&m_semaphore |
|||
) != VK_SUCCESS) |
|||
throw std::runtime_error("failed to create semaphore"); |
|||
} |
|||
|
|||
Semaphore::Semaphore(Semaphore&& other) noexcept |
|||
{ |
|||
swap(*this, other); |
|||
} |
|||
|
|||
Semaphore::~Semaphore() noexcept { |
|||
if(!is_null()) |
|||
destroy(); |
|||
} |
|||
|
|||
|
|||
Semaphore& Semaphore::operator=(Semaphore&& other) noexcept { |
|||
swap(*this, other); |
|||
if(other) |
|||
other.destroy(); |
|||
return *this; |
|||
} |
|||
|
|||
|
|||
void Semaphore::destroy() noexcept { |
|||
assert(!is_null()); |
|||
assert(m_context); |
|||
|
|||
vkDestroySemaphore( |
|||
m_context->device(), |
|||
m_semaphore, |
|||
nullptr |
|||
); |
|||
|
|||
m_semaphore = nullptr; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// Copyright 2022 Simon Boyé
|
|||
#pragma once |
|||
|
|||
#include <vk/forward.h> |
|||
|
|||
#include <vulkan/vulkan.h> |
|||
|
|||
|
|||
namespace vk { |
|||
|
|||
|
|||
class Semaphore { |
|||
public: |
|||
Semaphore() noexcept; |
|||
Semaphore(Context& context); |
|||
Semaphore(const Semaphore&) = delete; |
|||
Semaphore(Semaphore&& other) noexcept; |
|||
~Semaphore() noexcept; |
|||
|
|||
Semaphore& operator=(const Semaphore&) = delete; |
|||
Semaphore& operator=(Semaphore&& other) noexcept; |
|||
|
|||
explicit inline operator bool() const noexcept { |
|||
return !is_null(); |
|||
} |
|||
|
|||
inline bool is_null() const noexcept { |
|||
return m_semaphore == VK_NULL_HANDLE; |
|||
} |
|||
|
|||
inline const Context* context() const noexcept { |
|||
return m_context; |
|||
} |
|||
|
|||
inline Context* context() noexcept { |
|||
return m_context; |
|||
} |
|||
|
|||
inline operator VkSemaphore() noexcept { |
|||
return m_semaphore; |
|||
} |
|||
|
|||
inline VkSemaphore semaphore() noexcept { |
|||
return m_semaphore; |
|||
} |
|||
|
|||
friend inline void swap(Semaphore& semaphore_0, Semaphore& semaphore_1) noexcept { |
|||
using std::swap; |
|||
swap(semaphore_0.m_context, semaphore_1.m_context); |
|||
swap(semaphore_0.m_semaphore, semaphore_1.m_semaphore); |
|||
} |
|||
|
|||
void destroy() noexcept; |
|||
|
|||
private: |
|||
Context* m_context = nullptr; |
|||
VkSemaphore m_semaphore = VK_NULL_HANDLE; |
|||
}; |
|||
|
|||
|
|||
} |
|||
Loading…
Reference in new issue