Fixing some semaphore things

This commit is contained in:
Dynamitos
2025-03-07 21:48:27 +01:00
parent 4d7c5db2c3
commit 913b8391f8
25 changed files with 236 additions and 139 deletions
+50 -23
View File
@@ -4,21 +4,67 @@
#include <vk_mem_alloc.h>
#include <vulkan/vulkan.h>
namespace Seele {
namespace Vulkan {
DECLARE_REF(DescriptorPool)
DECLARE_REF(CommandPool)
DECLARE_REF(Command)
DECLARE_REF(Graphics)
class Semaphore {
class CommandBoundResource {
public:
Semaphore(PGraphics graphics);
virtual ~Semaphore();
CommandBoundResource(PGraphics graphics, const std::string& name) : graphics(graphics), name(name) {}
virtual ~CommandBoundResource() {
if (isCurrentlyBound())
abort();
}
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
protected:
PGraphics graphics;
std::string name;
uint64 bindCount = 0;
};
DEFINE_REF(CommandBoundResource)
class SemaphoreHandle : public CommandBoundResource {
public:
SemaphoreHandle(PGraphics graphics, const std::string& name);
virtual ~SemaphoreHandle();
constexpr VkSemaphore getHandle() const { return handle; }
private:
VkSemaphore handle;
};
DEFINE_REF(SemaphoreHandle)
class Semaphore {
public:
Semaphore(PGraphics graphics);
virtual ~Semaphore();
// call when you need a new semaphore
void rotateSemaphore();
// call when the semaphore is to signal something, for example after using it in vkAcquireImage
void encodeSignal() {
if (handles.size() == 0)
return;
handles[currentHandle]->bind();
}
// call when the semaphore has been signalled
void resolveSignal() {
if (handles.size() == 0)
return;
handles[currentHandle]->unbind();
}
constexpr VkSemaphore getHandle() const { return handles[currentHandle]->getHandle(); }
PSemaphoreHandle getCurrentSemaphore() const { return handles[currentHandle]; }
private:
Array<OSemaphoreHandle> handles;
uint32 currentHandle = 0;
PGraphics graphics;
};
DEFINE_REF(Semaphore)
@@ -45,7 +91,6 @@ class Fence {
VkFence fence;
};
DEFINE_REF(Fence)
DECLARE_REF(CommandBoundResource)
class DestructionManager {
public:
DestructionManager(PGraphics graphics);
@@ -59,24 +104,6 @@ class DestructionManager {
};
DEFINE_REF(DestructionManager)
class CommandBoundResource {
public:
CommandBoundResource(PGraphics graphics, const std::string& name) : graphics(graphics), name(name) {}
virtual ~CommandBoundResource() {
if (isCurrentlyBound())
abort();
}
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
protected:
PGraphics graphics;
std::string name;
uint64 bindCount = 0;
};
DEFINE_REF(CommandBoundResource)
class SamplerHandle : public CommandBoundResource {
public:
SamplerHandle(PGraphics graphics, VkSamplerCreateInfo createInfo);