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

169 lines
4.8 KiB
C++
Raw Normal View History

2020-03-24 21:05:32 +01:00
#pragma once
2023-10-26 18:37:29 +02:00
#include "Queue.h"
2023-11-15 17:42:57 +01:00
#include "Graphics/Command.h"
2023-10-26 18:37:29 +02:00
#include "Buffer.h"
namespace Seele
{
2020-06-08 01:44:47 +02:00
struct VertexInputStream;
2020-04-12 15:47:19 +02:00
namespace Vulkan
{
2021-04-01 16:40:14 +02:00
DECLARE_REF(RenderPass)
DECLARE_REF(Framebuffer)
DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand)
DECLARE_REF(DescriptorSet)
2023-11-15 00:06:00 +01:00
DECLARE_REF(CommandPool)
class Command
2020-04-12 15:47:19 +02:00
{
public:
2023-11-15 17:42:57 +01:00
Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool);
2023-11-15 00:06:00 +01:00
virtual ~Command();
constexpr VkCommandBuffer getHandle()
{
2020-04-12 15:47:19 +02:00
return handle;
}
2020-04-12 15:47:19 +02:00
void reset();
void begin();
void end();
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
void endRenderPass();
2021-05-10 23:57:55 +02:00
void executeCommands(const Array<Gfx::PRenderCommand>& secondaryCommands);
void executeCommands(const Array<Gfx::PComputeCommand>& secondaryCommands);
2023-11-15 00:06:00 +01:00
void waitForSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
void checkFence();
2021-05-10 23:57:55 +02:00
void waitForCommand(uint32 timeToWait = 1000000u);
2020-05-05 01:51:13 +02:00
PFence getFence();
2023-11-15 17:42:57 +01:00
PCommandPool getPool();
2020-04-12 15:47:19 +02:00
enum State
{
2023-11-15 00:06:00 +01:00
Init,
Begin,
RenderPass,
End,
Submit,
2020-04-12 15:47:19 +02:00
};
private:
PGraphics graphics;
2023-11-15 17:42:57 +01:00
PCommandPool pool;
2023-11-01 23:12:30 +01:00
OFence fence;
2020-04-12 15:47:19 +02:00
State state;
VkViewport currentViewport;
VkRect2D currentScissor;
VkCommandBuffer handle;
VkCommandPool owner;
2023-11-15 17:42:57 +01:00
PRenderPass boundRenderPass;
PFramebuffer boundFramebuffer;
2020-04-12 15:47:19 +02:00
Array<PSemaphore> waitSemaphores;
Array<VkPipelineStageFlags> waitFlags;
2021-05-10 23:57:55 +02:00
Array<PRenderCommand> executingRenders;
Array<PComputeCommand> executingComputes;
2023-11-01 23:12:30 +01:00
Array<PDescriptorSet> boundDescriptors;
2021-05-10 23:57:55 +02:00
friend class RenderCommand;
2023-11-15 00:06:00 +01:00
friend class CommandPool;
2020-04-12 15:47:19 +02:00
friend class Queue;
};
2023-11-15 00:06:00 +01:00
DEFINE_REF(Command)
2020-04-12 15:47:19 +02:00
2021-04-01 16:40:14 +02:00
DECLARE_REF(GraphicsPipeline)
2021-05-10 23:57:55 +02:00
DECLARE_REF(ComputePipeline)
class RenderCommand : public Gfx::RenderCommand
2021-05-10 23:57:55 +02:00
{
public:
RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
virtual ~RenderCommand();
2023-11-15 00:06:00 +01:00
constexpr VkCommandBuffer getHandle()
{
return handle;
}
2022-01-12 14:40:26 +01:00
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
void end();
void reset();
2021-04-13 23:09:16 +02:00
virtual bool isReady() override;
2020-10-03 11:00:10 +02:00
virtual void setViewport(Gfx::PViewport viewport) override;
2020-05-05 01:51:13 +02:00
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
2020-10-14 01:49:43 +02:00
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
2023-11-01 23:12:30 +01:00
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
2020-05-05 01:51:13 +02:00
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
2022-04-15 11:19:30 +02:00
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
2021-09-23 10:10:39 +02:00
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override;
2023-10-24 15:01:09 +02:00
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ) override;
2020-04-12 15:47:19 +02:00
private:
2020-05-05 01:51:13 +02:00
PGraphicsPipeline pipeline;
bool ready;
2023-11-01 23:12:30 +01:00
Array<PDescriptorSet> boundDescriptors;
VkViewport currentViewport;
VkRect2D currentScissor;
PGraphics graphics;
std::thread::id threadId;
VkCommandBuffer handle;
VkCommandPool owner;
2023-11-15 00:06:00 +01:00
friend class Command;
2020-04-12 15:47:19 +02:00
};
2021-05-10 23:57:55 +02:00
DEFINE_REF(RenderCommand)
2020-04-12 15:47:19 +02:00
class ComputeCommand : public Gfx::ComputeCommand
2021-05-10 23:57:55 +02:00
{
public:
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
virtual ~ComputeCommand();
inline VkCommandBuffer getHandle()
{
return handle;
}
2023-11-15 17:42:57 +01:00
void begin();
void end();
void reset();
2021-05-10 23:57:55 +02:00
virtual bool isReady() override;
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
2022-04-15 11:19:30 +02:00
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
2021-05-10 23:57:55 +02:00
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
private:
PComputePipeline pipeline;
bool ready;
Array<DescriptorSet*> boundDescriptors;
VkViewport currentViewport;
VkRect2D currentScissor;
PGraphics graphics;
std::thread::id threadId;
VkCommandBuffer handle;
VkCommandPool owner;
2023-11-15 00:06:00 +01:00
friend class Command;
2021-05-10 23:57:55 +02:00
};
DEFINE_REF(ComputeCommand)
2023-11-15 00:06:00 +01:00
class CommandPool
2020-04-12 15:47:19 +02:00
{
public:
2023-11-15 00:06:00 +01:00
CommandPool(PGraphics graphics, PQueue queue);
virtual ~CommandPool();
constexpr PQueue getQueue() const
2020-04-12 15:47:19 +02:00
{
return queue;
}
2023-11-15 00:06:00 +01:00
PCommand getCommands();
2023-11-15 17:42:57 +01:00
PRenderCommand createRenderCommand(const std::string& name);
2021-05-10 23:57:55 +02:00
PComputeCommand createComputeCommand(const std::string& name);
2023-11-15 00:06:00 +01:00
constexpr VkCommandPool getHandle() const
2021-08-22 23:07:38 +02:00
{
return commandPool;
}
2020-04-12 15:47:19 +02:00
void submitCommands(PSemaphore signalSemaphore = nullptr);
private:
PGraphics graphics;
VkCommandPool commandPool;
PQueue queue;
uint32 queueFamilyIndex;
2023-11-15 00:06:00 +01:00
PCommand command;
2023-11-15 17:42:57 +01:00
Array<OCommand> allocatedBuffers;
2023-11-01 23:12:30 +01:00
Array<ORenderCommand> allocatedRenderCommands;
Array<OComputeCommand> allocatedComputeCommands;
2020-04-12 15:47:19 +02:00
};
2023-11-15 00:06:00 +01:00
DEFINE_REF(CommandPool)
2020-04-12 15:47:19 +02:00
} // namespace Vulkan
} // namespace Seele