Changes to command ownership
This commit is contained in:
@@ -82,7 +82,7 @@ void Command::endRenderPass()
|
||||
state = State::Begin;
|
||||
}
|
||||
|
||||
void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
||||
void Command::executeCommands(const Array<Gfx::ORenderCommand>& commands)
|
||||
{
|
||||
assert(state == State::RenderPass);
|
||||
if(commands.size() == 0)
|
||||
@@ -93,7 +93,7 @@ void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
||||
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
||||
for (uint32 i = 0; i < commands.size(); ++i)
|
||||
{
|
||||
auto command = commands[i].cast<RenderCommand>();
|
||||
auto command = Gfx::PRenderCommand(commands[i]).cast<RenderCommand>();
|
||||
command->end();
|
||||
executingRenders.add(command);
|
||||
for(auto& descriptor : command->boundDescriptors)
|
||||
@@ -106,7 +106,7 @@ void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
||||
vkCmdExecuteCommands(handle, (uint32)cmdBuffers.size(), cmdBuffers.data());
|
||||
}
|
||||
|
||||
void Command::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
||||
void Command::executeCommands(const Array<Gfx::OComputeCommand>& commands)
|
||||
{
|
||||
if(commands.size() == 0)
|
||||
{
|
||||
@@ -115,7 +115,7 @@ void Command::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
||||
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
||||
for (uint32 i = 0; i < commands.size(); ++i)
|
||||
{
|
||||
auto command = commands[i].cast<ComputeCommand>();
|
||||
auto command = Gfx::PComputeCommand(commands[i]).cast<ComputeCommand>();
|
||||
command->end();
|
||||
executingComputes.add(command);
|
||||
for(auto& descriptor : command->boundDescriptors)
|
||||
@@ -485,40 +485,49 @@ PCommand CommandPool::getCommands()
|
||||
{
|
||||
return command;
|
||||
}
|
||||
void CommandPool::cacheCommands(Array<ORenderCommand> commands)
|
||||
{
|
||||
allocatedRenderCommands.addAll(commands);
|
||||
}
|
||||
|
||||
PRenderCommand CommandPool::createRenderCommand(const std::string& name)
|
||||
void CommandPool::cacheCommands(Array<OComputeCommand> commands)
|
||||
{
|
||||
allocatedComputeCommands.addAll(commands);
|
||||
}
|
||||
|
||||
ORenderCommand CommandPool::createRenderCommand(const std::string& name)
|
||||
{
|
||||
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
|
||||
{
|
||||
PRenderCommand cmdBuffer = allocatedRenderCommands[i];
|
||||
if (cmdBuffer->isReady())
|
||||
if (allocatedRenderCommands[i]->isReady())
|
||||
{
|
||||
ORenderCommand cmdBuffer = std::move(allocatedRenderCommands[i]);
|
||||
allocatedRenderCommands.removeAt(i, false);
|
||||
cmdBuffer->name = name;
|
||||
cmdBuffer->begin(command->boundRenderPass, command->boundFramebuffer);
|
||||
return cmdBuffer;
|
||||
}
|
||||
}
|
||||
allocatedRenderCommands.add(new RenderCommand(graphics, commandPool));
|
||||
PRenderCommand result = allocatedRenderCommands.back();
|
||||
ORenderCommand result = new RenderCommand(graphics, commandPool);
|
||||
result->name = name;
|
||||
result->begin(command->boundRenderPass, command->boundFramebuffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
PComputeCommand CommandPool::createComputeCommand(const std::string& name)
|
||||
OComputeCommand CommandPool::createComputeCommand(const std::string& name)
|
||||
{
|
||||
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
|
||||
{
|
||||
PComputeCommand cmdBuffer = allocatedComputeCommands[i];
|
||||
if (cmdBuffer->isReady())
|
||||
if (allocatedComputeCommands[i]->isReady())
|
||||
{
|
||||
OComputeCommand cmdBuffer = std::move(allocatedComputeCommands[i]);
|
||||
allocatedComputeCommands.removeAt(i, false);
|
||||
cmdBuffer->name = name;
|
||||
cmdBuffer->begin();
|
||||
return cmdBuffer;
|
||||
}
|
||||
}
|
||||
allocatedComputeCommands.add(new ComputeCommand(graphics, commandPool));
|
||||
PComputeCommand result = allocatedComputeCommands.back();
|
||||
OComputeCommand result = new ComputeCommand(graphics, commandPool);
|
||||
result->name = name;
|
||||
result->begin();
|
||||
return result;
|
||||
|
||||
@@ -1,168 +1,160 @@
|
||||
#pragma once
|
||||
#include "Queue.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Buffer.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Queue.h"
|
||||
#include <thread>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Vulkan
|
||||
{
|
||||
namespace Seele {
|
||||
namespace Vulkan {
|
||||
DECLARE_REF(RenderPass)
|
||||
DECLARE_REF(Framebuffer)
|
||||
DECLARE_REF(RenderCommand)
|
||||
DECLARE_REF(ComputeCommand)
|
||||
DECLARE_REF(DescriptorSet)
|
||||
DECLARE_REF(CommandPool)
|
||||
class Command
|
||||
{
|
||||
class Command {
|
||||
public:
|
||||
Command(PGraphics graphics, PCommandPool pool);
|
||||
~Command();
|
||||
constexpr VkCommandBuffer getHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
void reset();
|
||||
void begin();
|
||||
void end();
|
||||
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||
void endRenderPass();
|
||||
void executeCommands(const Array<Gfx::PRenderCommand>& secondaryCommands);
|
||||
void executeCommands(const Array<Gfx::PComputeCommand>& secondaryCommands);
|
||||
void waitForSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
|
||||
void checkFence();
|
||||
void waitForCommand(uint32 timeToWait = 1000000u);
|
||||
PFence getFence();
|
||||
PCommandPool getPool();
|
||||
enum State
|
||||
{
|
||||
Init,
|
||||
Begin,
|
||||
RenderPass,
|
||||
End,
|
||||
Submit,
|
||||
};
|
||||
Command(PGraphics graphics, PCommandPool pool);
|
||||
~Command();
|
||||
constexpr VkCommandBuffer getHandle() { return handle; }
|
||||
void reset();
|
||||
void begin();
|
||||
void end();
|
||||
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||
void endRenderPass();
|
||||
void executeCommands(const Array<Gfx::ORenderCommand> &secondaryCommands);
|
||||
void executeCommands(const Array<Gfx::OComputeCommand> &secondaryCommands);
|
||||
void waitForSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
|
||||
void checkFence();
|
||||
void waitForCommand(uint32 timeToWait = 1000000u);
|
||||
PFence getFence();
|
||||
PCommandPool getPool();
|
||||
enum State {
|
||||
Init,
|
||||
Begin,
|
||||
RenderPass,
|
||||
End,
|
||||
Submit,
|
||||
};
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
PCommandPool pool;
|
||||
OFence fence;
|
||||
OSemaphore signalSemaphore;
|
||||
State state;
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
VkCommandBuffer handle;
|
||||
PRenderPass boundRenderPass;
|
||||
PFramebuffer boundFramebuffer;
|
||||
Array<PSemaphore> waitSemaphores;
|
||||
Array<VkPipelineStageFlags> waitFlags;
|
||||
Array<PRenderCommand> executingRenders;
|
||||
Array<PComputeCommand> executingComputes;
|
||||
Array<PDescriptorSet> boundDescriptors;
|
||||
friend class RenderCommand;
|
||||
friend class CommandPool;
|
||||
friend class Queue;
|
||||
PGraphics graphics;
|
||||
PCommandPool pool;
|
||||
OFence fence;
|
||||
OSemaphore signalSemaphore;
|
||||
State state;
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
VkCommandBuffer handle;
|
||||
PRenderPass boundRenderPass;
|
||||
PFramebuffer boundFramebuffer;
|
||||
Array<PSemaphore> waitSemaphores;
|
||||
Array<VkPipelineStageFlags> waitFlags;
|
||||
Array<PRenderCommand> executingRenders;
|
||||
Array<PComputeCommand> executingComputes;
|
||||
Array<PDescriptorSet> boundDescriptors;
|
||||
friend class RenderCommand;
|
||||
friend class CommandPool;
|
||||
friend class Queue;
|
||||
};
|
||||
DEFINE_REF(Command)
|
||||
|
||||
DECLARE_REF(GraphicsPipeline)
|
||||
DECLARE_REF(ComputePipeline)
|
||||
class RenderCommand : public Gfx::RenderCommand
|
||||
{
|
||||
class RenderCommand : public Gfx::RenderCommand {
|
||||
public:
|
||||
RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||
virtual ~RenderCommand();
|
||||
constexpr VkCommandBuffer getHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||
void end();
|
||||
void reset();
|
||||
bool isReady();
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
|
||||
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
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;
|
||||
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||
virtual ~RenderCommand();
|
||||
constexpr VkCommandBuffer getHandle() { return handle; }
|
||||
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||
void end();
|
||||
void reset();
|
||||
bool isReady();
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
virtual void
|
||||
bindDescriptor(const Array<Gfx::PDescriptorSet> &descriptorSets) override;
|
||||
virtual void
|
||||
bindVertexBuffer(const Array<Gfx::PVertexBuffer> &buffers) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout,
|
||||
Gfx::SeShaderStageFlags stage, uint32 offset,
|
||||
uint32 size, const void *data) override;
|
||||
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;
|
||||
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
|
||||
private:
|
||||
PGraphicsPipeline pipeline;
|
||||
bool ready;
|
||||
Array<PDescriptorSet> boundDescriptors;
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
PGraphics graphics;
|
||||
std::thread::id threadId;
|
||||
VkCommandBuffer handle;
|
||||
VkCommandPool owner;
|
||||
friend class Command;
|
||||
PGraphicsPipeline pipeline;
|
||||
bool ready;
|
||||
Array<PDescriptorSet> boundDescriptors;
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
PGraphics graphics;
|
||||
std::thread::id threadId;
|
||||
VkCommandBuffer handle;
|
||||
VkCommandPool owner;
|
||||
friend class Command;
|
||||
};
|
||||
DEFINE_REF(RenderCommand)
|
||||
|
||||
class ComputeCommand : public Gfx::ComputeCommand
|
||||
{
|
||||
class ComputeCommand : public Gfx::ComputeCommand {
|
||||
public:
|
||||
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||
virtual ~ComputeCommand();
|
||||
inline VkCommandBuffer getHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
void begin();
|
||||
void end();
|
||||
void reset();
|
||||
bool isReady();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
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;
|
||||
friend class Command;
|
||||
};
|
||||
DEFINE_REF(ComputeCommand)
|
||||
class CommandPool
|
||||
{
|
||||
public:
|
||||
CommandPool(PGraphics graphics, PQueue queue);
|
||||
virtual ~CommandPool();
|
||||
constexpr PQueue getQueue() const
|
||||
{
|
||||
return queue;
|
||||
}
|
||||
PCommand getCommands();
|
||||
PRenderCommand createRenderCommand(const std::string& name);
|
||||
PComputeCommand createComputeCommand(const std::string& name);
|
||||
constexpr VkCommandPool getHandle() const
|
||||
{
|
||||
return commandPool;
|
||||
}
|
||||
void submitCommands(PSemaphore signalSemaphore = nullptr);
|
||||
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||
virtual ~ComputeCommand();
|
||||
inline VkCommandBuffer getHandle() { return handle; }
|
||||
void begin();
|
||||
void end();
|
||||
void reset();
|
||||
bool isReady();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet> &sets) override;
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout,
|
||||
Gfx::SeShaderStageFlags stage, uint32 offset,
|
||||
uint32 size, const void *data) override;
|
||||
virtual void dispatch(uint32 threadX, uint32 threadY,
|
||||
uint32 threadZ) override;
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
VkCommandPool commandPool;
|
||||
PQueue queue;
|
||||
uint32 queueFamilyIndex;
|
||||
PCommand command;
|
||||
Array<OCommand> allocatedBuffers;
|
||||
Array<ORenderCommand> allocatedRenderCommands;
|
||||
Array<OComputeCommand> allocatedComputeCommands;
|
||||
PComputePipeline pipeline;
|
||||
bool ready;
|
||||
Array<DescriptorSet *> boundDescriptors;
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
PGraphics graphics;
|
||||
std::thread::id threadId;
|
||||
VkCommandBuffer handle;
|
||||
VkCommandPool owner;
|
||||
friend class Command;
|
||||
};
|
||||
DEFINE_REF(ComputeCommand)
|
||||
class CommandPool {
|
||||
public:
|
||||
CommandPool(PGraphics graphics, PQueue queue);
|
||||
virtual ~CommandPool();
|
||||
constexpr PQueue getQueue() const { return queue; }
|
||||
PCommand getCommands();
|
||||
void cacheCommands(Array<ORenderCommand> commands);
|
||||
void cacheCommands(Array<OComputeCommand> commands);
|
||||
ORenderCommand createRenderCommand(const std::string &name);
|
||||
OComputeCommand createComputeCommand(const std::string &name);
|
||||
constexpr VkCommandPool getHandle() const { return commandPool; }
|
||||
void submitCommands(PSemaphore signalSemaphore = nullptr);
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
VkCommandPool commandPool;
|
||||
PQueue queue;
|
||||
uint32 queueFamilyIndex;
|
||||
PCommand command;
|
||||
Array<OCommand> allocatedBuffers;
|
||||
Array<ORenderCommand> allocatedRenderCommands;
|
||||
Array<OComputeCommand> allocatedComputeCommands;
|
||||
};
|
||||
DEFINE_REF(CommandPool)
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -116,12 +116,12 @@ void Graphics::waitDeviceIdle()
|
||||
vkDeviceWaitIdle(handle);
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
||||
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands)
|
||||
{
|
||||
getGraphicsCommands()->getCommands()->executeCommands(commands);
|
||||
}
|
||||
|
||||
void Graphics::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
||||
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands)
|
||||
{
|
||||
getComputeCommands()->getCommands()->executeCommands(commands);
|
||||
}
|
||||
@@ -159,12 +159,12 @@ Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkD
|
||||
{
|
||||
return new IndexBuffer(this, bulkData);
|
||||
}
|
||||
Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name)
|
||||
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name)
|
||||
{
|
||||
return getGraphicsCommands()->createRenderCommand(name);
|
||||
}
|
||||
|
||||
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
|
||||
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name)
|
||||
{
|
||||
return getComputeCommands()->createComputeCommand(name);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public:
|
||||
virtual void endRenderPass() override;
|
||||
virtual void waitDeviceIdle() override;
|
||||
|
||||
virtual void executeCommands(const Array<Gfx::PRenderCommand>& commands) override;
|
||||
virtual void executeCommands(const Array<Gfx::PComputeCommand>& commands) override;
|
||||
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||
virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override;
|
||||
|
||||
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
|
||||
virtual Gfx::OTexture3D createTexture3D(const TextureCreateInfo &createInfo) override;
|
||||
@@ -50,8 +50,8 @@ public:
|
||||
virtual Gfx::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
|
||||
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
|
||||
|
||||
virtual Gfx::PRenderCommand createRenderCommand(const std::string& name) override;
|
||||
virtual Gfx::PComputeCommand createComputeCommand(const std::string& name) override;
|
||||
virtual Gfx::ORenderCommand createRenderCommand(const std::string& name) override;
|
||||
virtual Gfx::OComputeCommand createComputeCommand(const std::string& name) override;
|
||||
|
||||
virtual Gfx::OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) override;
|
||||
virtual Gfx::OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
||||
|
||||
Reference in New Issue
Block a user