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)
|
2024-06-09 12:20:04 +02:00
|
|
|
class Semaphore {
|
|
|
|
|
public:
|
2023-10-26 18:37:29 +02:00
|
|
|
Semaphore(PGraphics graphics);
|
|
|
|
|
virtual ~Semaphore();
|
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;
|
|
|
|
|
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();
|
2024-05-30 21:24:21 +02:00
|
|
|
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,
|
2024-05-30 21:24:21 +02:00
|
|
|
};
|
|
|
|
|
Status status;
|
2023-10-26 18:37:29 +02:00
|
|
|
VkFence fence;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(Fence)
|
2024-05-15 15:27:13 +02:00
|
|
|
DECLARE_REF(CommandBoundResource)
|
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 CommandBoundResource {
|
|
|
|
|
public:
|
2024-08-07 21:19:33 +02:00
|
|
|
CommandBoundResource(PGraphics graphics, const std::string& name) : graphics(graphics), name(name) {}
|
2024-06-09 12:20:04 +02:00
|
|
|
virtual ~CommandBoundResource() {
|
2024-05-15 15:27:13 +02:00
|
|
|
if (isCurrentlyBound())
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
|
|
|
|
|
constexpr void bind() { bindCount++; }
|
|
|
|
|
constexpr void unbind() { bindCount--; }
|
2024-06-09 12:20:04 +02:00
|
|
|
|
|
|
|
|
protected:
|
2024-05-15 15:27:13 +02:00
|
|
|
PGraphics graphics;
|
2024-08-07 21:19:33 +02:00
|
|
|
std::string name;
|
2024-05-15 15:27:13 +02:00
|
|
|
uint64 bindCount = 0;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(CommandBoundResource)
|
|
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
class SamplerHandle : public CommandBoundResource {
|
|
|
|
|
public:
|
2024-05-18 21:23:59 +02:00
|
|
|
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:
|
2024-05-18 21:23:59 +02:00
|
|
|
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:
|
2024-05-18 21:23:59 +02:00
|
|
|
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
|