2020-03-24 21:05:32 +01:00
|
|
|
#pragma once
|
2020-03-20 01:27:40 +01:00
|
|
|
#include "VulkanGraphicsResources.h"
|
2020-03-24 21:05:32 +01:00
|
|
|
#include "VulkanQueue.h"
|
2020-03-20 01:27:40 +01:00
|
|
|
|
|
|
|
|
namespace Seele
|
|
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
namespace Vulkan
|
|
|
|
|
{
|
|
|
|
|
DECLARE_REF(RenderPass);
|
|
|
|
|
DECLARE_REF(Framebuffer);
|
2020-05-05 01:51:13 +02:00
|
|
|
class CmdBufferBase
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CmdBufferBase(PGraphics graphics, VkCommandPool cmdPool);
|
|
|
|
|
virtual ~CmdBufferBase();
|
|
|
|
|
inline VkCommandBuffer getHandle()
|
2020-03-20 01:27:40 +01:00
|
|
|
{
|
2020-04-12 15:47:19 +02:00
|
|
|
return handle;
|
2020-03-20 01:27:40 +01:00
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
void reset();
|
|
|
|
|
VkViewport currentViewport;
|
|
|
|
|
VkRect2D currentScissor;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
PGraphics graphics;
|
|
|
|
|
VkCommandBuffer handle;
|
|
|
|
|
VkCommandPool owner;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(CmdBufferBase);
|
|
|
|
|
|
|
|
|
|
DECLARE_REF(SecondaryCmdBuffer);
|
|
|
|
|
class CmdBuffer : public CmdBufferBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CmdBuffer(PGraphics graphics, VkCommandPool cmdPool);
|
|
|
|
|
virtual ~CmdBuffer();
|
|
|
|
|
void begin();
|
|
|
|
|
void end();
|
|
|
|
|
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
|
|
|
|
|
void endRenderPass();
|
|
|
|
|
void executeCommands(Array<PSecondaryCmdBuffer> secondaryCommands);
|
|
|
|
|
void addWaitSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
|
|
|
|
|
void refreshFence();
|
2020-05-05 01:51:13 +02:00
|
|
|
PFence getFence();
|
2020-04-12 15:47:19 +02:00
|
|
|
enum State
|
|
|
|
|
{
|
|
|
|
|
ReadyBegin,
|
|
|
|
|
InsideBegin,
|
|
|
|
|
RenderPassActive,
|
|
|
|
|
Ended,
|
|
|
|
|
Submitted,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PRenderPass renderPass;
|
|
|
|
|
PFramebuffer framebuffer;
|
|
|
|
|
PFence fence;
|
|
|
|
|
uint32 subpassIndex;
|
|
|
|
|
State state;
|
|
|
|
|
Array<PSemaphore> waitSemaphores;
|
|
|
|
|
Array<VkPipelineStageFlags> waitFlags;
|
|
|
|
|
friend class SecondaryCmdBuffer;
|
|
|
|
|
friend class CommandBufferManager;
|
|
|
|
|
friend class Queue;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(CmdBuffer);
|
|
|
|
|
|
2020-05-05 01:51:13 +02:00
|
|
|
DECLARE_REF(GraphicsPipeline);
|
|
|
|
|
class SecondaryCmdBuffer : public CmdBufferBase, public Gfx::RenderCommand
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SecondaryCmdBuffer(PGraphics graphics, VkCommandPool cmdPool);
|
|
|
|
|
virtual ~SecondaryCmdBuffer();
|
|
|
|
|
void begin(PCmdBuffer parent);
|
|
|
|
|
void end();
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
|
|
|
|
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
|
|
|
|
virtual void bindVertexBuffer(Gfx::PVertexBuffer vertexBuffer) override;
|
|
|
|
|
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
2020-06-02 11:46:18 +02:00
|
|
|
virtual void draw(const MeshBatchElement& data) override;
|
2020-04-12 15:47:19 +02:00
|
|
|
|
|
|
|
|
private:
|
2020-05-05 01:51:13 +02:00
|
|
|
PGraphicsPipeline pipeline;
|
2020-04-12 15:47:19 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(SecondaryCmdBuffer);
|
|
|
|
|
|
|
|
|
|
class CommandBufferManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CommandBufferManager(PGraphics graphics, PQueue queue);
|
|
|
|
|
virtual ~CommandBufferManager();
|
|
|
|
|
inline PQueue getQueue() const
|
|
|
|
|
{
|
|
|
|
|
return queue;
|
|
|
|
|
}
|
|
|
|
|
PCmdBuffer getCommands();
|
|
|
|
|
PSecondaryCmdBuffer createSecondaryCmdBuffer();
|
|
|
|
|
void submitCommands(PSemaphore signalSemaphore = nullptr);
|
|
|
|
|
void waitForCommands(PCmdBuffer cmdBuffer, uint32 timeToWait = 1000000u);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
PGraphics graphics;
|
|
|
|
|
VkCommandPool commandPool;
|
|
|
|
|
PQueue queue;
|
|
|
|
|
uint32 queueFamilyIndex;
|
|
|
|
|
PCmdBuffer activeCmdBuffer;
|
|
|
|
|
Array<PCmdBuffer> allocatedBuffers;
|
|
|
|
|
};
|
|
|
|
|
DEFINE_REF(CommandBufferManager);
|
|
|
|
|
} // namespace Vulkan
|
|
|
|
|
} // namespace Seele
|