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

119 lines
2.4 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
#include <vulkan/vulkan.h>
2024-01-17 19:34:38 +01:00
#include <vk_mem_alloc.h>
2023-11-12 16:11:27 +01:00
#include "Containers/List.h"
2023-10-26 18:37:29 +02:00
#include "Graphics/Resources.h"
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)
class Semaphore
{
public:
Semaphore(PGraphics graphics);
virtual ~Semaphore();
2023-11-15 00:06:00 +01:00
constexpr VkSemaphore getHandle() const
2023-10-26 18:37:29 +02:00
{
return handle;
}
private:
VkSemaphore handle;
PGraphics graphics;
};
DEFINE_REF(Semaphore)
class Fence
{
public:
Fence(PGraphics graphics);
~Fence();
void submit();
2023-10-26 18:37:29 +02:00
bool isSignaled();
void reset();
2023-11-15 00:06:00 +01:00
constexpr VkFence getHandle() const
2023-10-26 18:37:29 +02:00
{
return fence;
}
2024-05-30 16:56:22 +02:00
void wait(uint64 timeout);
2023-10-26 18:37:29 +02:00
bool operator<(const Fence &other) const
{
return fence < other.fence;
}
private:
PGraphics graphics;
enum class Status
{
Ready,
InUse,
Signalled,
};
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)
2023-11-12 16:11:27 +01:00
class DestructionManager
{
public:
DestructionManager(PGraphics graphics);
~DestructionManager();
2024-05-15 15:27:13 +02:00
void queueResourceForDestruction(OCommandBoundResource resource);
void notifyCommandComplete();
2023-11-12 16:11:27 +01:00
private:
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-05-15 15:27:13 +02:00
class CommandBoundResource
{
public:
CommandBoundResource(PGraphics graphics)
: graphics(graphics)
{
}
virtual ~CommandBoundResource()
{
if (isCurrentlyBound())
abort();
}
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
protected:
PGraphics graphics;
uint64 bindCount = 0;
};
DEFINE_REF(CommandBoundResource)
class SamplerHandle : public CommandBoundResource
{
public:
SamplerHandle(PGraphics graphics, VkSamplerCreateInfo createInfo);
virtual ~SamplerHandle();
VkSampler sampler;
};
DEFINE_REF(SamplerHandle)
2023-11-15 00:06:00 +01:00
class Sampler : public Gfx::Sampler
2023-10-26 18:37:29 +02:00
{
public:
Sampler(PGraphics graphics, VkSamplerCreateInfo createInfo);
virtual ~Sampler();
PSamplerHandle getHandle() const { return handle; }
VkSampler getSampler() const { return handle->sampler; }
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