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

91 lines
2.2 KiB
C++
Raw Normal View History

2020-03-24 21:05:32 +01:00
#pragma once
#include "VulkanGraphicsResources.h"
2020-03-24 21:05:32 +01:00
#include "VulkanQueue.h"
namespace Seele
{
namespace Vulkan
{
2020-03-24 21:05:32 +01:00
DECLARE_REF(RenderPass);
DECLARE_REF(Framebuffer);
class CmdBufferBase : public Gfx::RenderCommandBase
{
public:
2020-04-01 02:17:49 +02:00
CmdBufferBase(PGraphics graphics, VkCommandPool cmdPool);
2020-03-24 21:05:32 +01:00
virtual ~CmdBufferBase();
inline VkCommandBuffer getHandle()
{
return handle;
}
void reset();
VkViewport currentViewport;
VkRect2D currentScissor;
protected:
2020-04-01 02:17:49 +02:00
PGraphics graphics;
VkCommandBuffer handle;
2020-03-24 21:05:32 +01:00
VkCommandPool owner;
};
2020-03-24 21:05:32 +01:00
DEFINE_REF(CmdBufferBase);
2020-03-24 21:05:32 +01:00
DECLARE_REF(SecondaryCmdBuffer);
class CmdBuffer : public CmdBufferBase
{
2020-03-24 21:05:32 +01:00
public:
2020-04-01 02:17:49 +02:00
CmdBuffer(PGraphics graphics, VkCommandPool cmdPool);
2020-03-24 21:05:32 +01:00
virtual ~CmdBuffer();
void begin();
void end();
2020-04-01 02:17:49 +02:00
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
2020-03-24 21:05:32 +01:00
void endRenderPass();
2020-04-01 02:17:49 +02:00
void executeCommands(Array<PSecondaryCmdBuffer> secondaryCommands);
2020-03-24 21:05:32 +01:00
void addWaitSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
enum State
{
ReadyBegin,
InsideBegin,
RenderPassActive,
Ended,
Submitted,
};
2020-03-24 21:05:32 +01:00
private:
2020-04-01 02:17:49 +02:00
PRenderPass renderPass;
PFramebuffer framebuffer;
2020-03-24 21:05:32 +01:00
uint32 subpassIndex;
State state;
friend class SecondaryCmdBuffer;
2020-04-01 02:17:49 +02:00
friend class CommandBufferManager;
};
DEFINE_REF(CmdBuffer);
2020-03-24 21:05:32 +01:00
class SecondaryCmdBuffer : public CmdBufferBase
{
public:
2020-04-01 02:17:49 +02:00
SecondaryCmdBuffer(PGraphics graphics, VkCommandPool cmdPool);
2020-03-24 21:05:32 +01:00
virtual ~SecondaryCmdBuffer();
2020-04-01 02:17:49 +02:00
void begin(PCmdBuffer parent);
2020-03-24 21:05:32 +01:00
void end();
private:
};
DEFINE_REF(SecondaryCmdBuffer);
class CommandBufferManager
{
public:
2020-04-01 02:17:49 +02:00
CommandBufferManager(PGraphics graphics, PQueue queue);
virtual ~CommandBufferManager();
PCmdBuffer getCommands();
2020-03-24 21:05:32 +01:00
PSecondaryCmdBuffer createSecondaryCmdBuffer();
void submitCommands(PSemaphore signalSemaphore = nullptr);
2020-03-24 21:05:32 +01:00
void waitForCommands(PCmdBuffer cmdBuffer, float timeToWait = 1.0f);
private:
2020-04-01 02:17:49 +02:00
PGraphics graphics;
VkCommandPool commandPool;
2020-04-01 02:17:49 +02:00
PQueue queue;
uint32 queueFamilyIndex;
2020-03-24 21:05:32 +01:00
PCmdBuffer activeCmdBuffer;
Array<PCmdBuffer> allocatedBuffers;
};
2020-03-24 21:05:32 +01:00
DEFINE_REF(CommandBufferManager);
}
}