Files
Seele/src/Engine/Graphics/Vulkan/Resources.h
T

130 lines
3.3 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
2023-11-12 16:11:27 +01:00
#include "Containers/List.h"
2023-10-26 18:37:29 +02:00
#include "Graphics/Resources.h"
2024-06-09 12:20:04 +02:00
#include <vk_mem_alloc.h>
#include <vulkan/vulkan.h>
2023-10-26 18:37:29 +02:00
2024-06-09 12:20:04 +02:00
namespace Seele {
namespace Vulkan {
2023-11-15 17:42:57 +01:00
DECLARE_REF(DescriptorPool)
2023-11-15 00:06:00 +01:00
DECLARE_REF(CommandPool)
DECLARE_REF(Command)
2023-10-26 18:37:29 +02:00
DECLARE_REF(Graphics)
2025-03-07 21:48:27 +01:00
class CommandBoundResource {
2024-06-09 12:20:04 +02:00
public:
2025-03-07 21:48:27 +01:00
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();
2024-06-09 12:20:04 +02:00
constexpr VkSemaphore getHandle() const { return handle; }
private:
2023-10-26 18:37:29 +02:00
VkSemaphore handle;
2025-03-07 21:48:27 +01:00
};
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;
2023-10-26 18:37:29 +02:00
PGraphics graphics;
};
DEFINE_REF(Semaphore)
2024-06-09 12:20:04 +02:00
class Fence {
public:
2023-10-26 18:37:29 +02:00
Fence(PGraphics graphics);
~Fence();
void submit();
2023-10-26 18:37:29 +02:00
bool isSignaled();
void reset();
2024-06-09 12:20:04 +02:00
constexpr VkFence getHandle() const { return fence; }
2024-05-30 16:56:22 +02:00
void wait(uint64 timeout);
2024-06-09 12:20:04 +02:00
bool operator<(const Fence& other) const { return fence < other.fence; }
2023-10-26 18:37:29 +02:00
2024-06-09 12:20:04 +02:00
private:
2023-10-26 18:37:29 +02:00
PGraphics graphics;
2024-06-09 12:20:04 +02:00
enum class Status {
Ready,
InUse,
Signalled,
};
Status status;
2023-10-26 18:37:29 +02:00
VkFence fence;
};
DEFINE_REF(Fence)
2024-06-09 12:20:04 +02:00
class DestructionManager {
public:
2023-11-12 16:11:27 +01:00
DestructionManager(PGraphics graphics);
~DestructionManager();
2024-05-15 15:27:13 +02:00
void queueResourceForDestruction(OCommandBoundResource resource);
void notifyCommandComplete();
2024-06-09 12:20:04 +02:00
private:
2023-11-12 16:11:27 +01:00
PGraphics graphics;
2024-05-15 15:27:13 +02:00
Array<OCommandBoundResource> resources;
2023-11-12 16:11:27 +01:00
};
DEFINE_REF(DestructionManager)
2024-06-09 12:20:04 +02:00
class SamplerHandle : public CommandBoundResource {
public:
SamplerHandle(PGraphics graphics, VkSamplerCreateInfo createInfo);
virtual ~SamplerHandle();
VkSampler sampler;
};
DEFINE_REF(SamplerHandle)
2024-06-09 12:20:04 +02:00
class Sampler : public Gfx::Sampler {
public:
Sampler(PGraphics graphics, VkSamplerCreateInfo createInfo);
virtual ~Sampler();
PSamplerHandle getHandle() const { return handle; }
VkSampler getSampler() const { return handle->sampler; }
2024-06-09 12:20:04 +02:00
private:
PGraphics graphics;
OSamplerHandle handle;
2023-10-26 18:37:29 +02:00
};
2023-11-15 00:06:00 +01:00
DEFINE_REF(Sampler)
2023-10-26 18:37:29 +02:00
} // namespace Vulkan
} // namespace Seele