Changes to command ownership
This commit is contained in:
@@ -377,9 +377,16 @@ public:
|
|||||||
{
|
{
|
||||||
return addInternal(std::forward<T>(item));
|
return addInternal(std::forward<T>(item));
|
||||||
}
|
}
|
||||||
constexpr void addAll(Array other)
|
constexpr void addAll(const Array& other)
|
||||||
{
|
{
|
||||||
for(auto value : other)
|
for(const auto& value : other)
|
||||||
|
{
|
||||||
|
addInternal(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
constexpr void addAll(Array&& other)
|
||||||
|
{
|
||||||
|
for(auto&& value : other)
|
||||||
{
|
{
|
||||||
addInternal(value);
|
addInternal(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ public:
|
|||||||
virtual void endRenderPass() = 0;
|
virtual void endRenderPass() = 0;
|
||||||
virtual void waitDeviceIdle() = 0;
|
virtual void waitDeviceIdle() = 0;
|
||||||
|
|
||||||
virtual void executeCommands(const Array<PRenderCommand>& commands) = 0;
|
virtual void executeCommands(Array<ORenderCommand> commands) = 0;
|
||||||
virtual void executeCommands(const Array<PComputeCommand>& commands) = 0;
|
virtual void executeCommands(Array<OComputeCommand> commands) = 0;
|
||||||
|
|
||||||
virtual OTexture2D createTexture2D(const TextureCreateInfo &createInfo) = 0;
|
virtual OTexture2D createTexture2D(const TextureCreateInfo &createInfo) = 0;
|
||||||
virtual OTexture3D createTexture3D(const TextureCreateInfo &createInfo) = 0;
|
virtual OTexture3D createTexture3D(const TextureCreateInfo &createInfo) = 0;
|
||||||
@@ -67,8 +67,8 @@ public:
|
|||||||
virtual OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) = 0;
|
virtual OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) = 0;
|
||||||
virtual OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) = 0;
|
virtual OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) = 0;
|
||||||
|
|
||||||
virtual PRenderCommand createRenderCommand(const std::string& name = "") = 0;
|
virtual ORenderCommand createRenderCommand(const std::string& name = "") = 0;
|
||||||
virtual PComputeCommand createComputeCommand(const std::string& name = "") = 0;
|
virtual OComputeCommand createComputeCommand(const std::string& name = "") = 0;
|
||||||
|
|
||||||
virtual OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) = 0;
|
virtual OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) = 0;
|
||||||
virtual OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) = 0;
|
virtual OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) = 0;
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public:
|
|||||||
void endRenderPass();
|
void endRenderPass();
|
||||||
void present(MTL::Drawable* drawable);
|
void present(MTL::Drawable* drawable);
|
||||||
void end(PEvent signal);
|
void end(PEvent signal);
|
||||||
void executeCommands(const Array<Gfx::PRenderCommand>& commands);
|
void executeCommands(Array<Gfx::ORenderCommand> commands);
|
||||||
void executeCommands(const Array<Gfx::PComputeCommand>& commands);
|
void executeCommands(Array<Gfx::OComputeCommand> commands);
|
||||||
void waitDeviceIdle();
|
void waitDeviceIdle();
|
||||||
void signalEvent(PEvent event);
|
void signalEvent(PEvent event);
|
||||||
void waitForEvent(PEvent event);
|
void waitForEvent(PEvent event);
|
||||||
@@ -83,8 +83,8 @@ public:
|
|||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
PCommand getCommands();
|
PCommand getCommands();
|
||||||
PRenderCommand getRenderCommand(const std::string& name);
|
ORenderCommand getRenderCommand(const std::string& name);
|
||||||
PComputeCommand getComputeCommand(const std::string& name);
|
OComputeCommand getComputeCommand(const std::string& name);
|
||||||
void submitCommands(PEvent signal = nullptr);
|
void submitCommands(PEvent signal = nullptr);
|
||||||
private:
|
private:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/Metal/Resources.h"
|
#include "Graphics/Metal/Resources.h"
|
||||||
#include "Metal/MTLRenderCommandEncoder.hpp"
|
#include "Metal/MTLRenderCommandEncoder.hpp"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
@@ -7,7 +8,7 @@ using namespace Seele;
|
|||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
|
|
||||||
Command::Command(PGraphics graphics, PCommandQueue owner)
|
Command::Command(PGraphics graphics, PCommandQueue owner)
|
||||||
: graphics(graphics), owner(owner), signalEvent(new Event(graphics)),
|
: graphics(graphics), owner(owner), completed(new Event(graphics)),
|
||||||
cmdBuffer(owner->getHandle()->commandBuffer()), renderEncoder(nullptr) {}
|
cmdBuffer(owner->getHandle()->commandBuffer()), renderEncoder(nullptr) {}
|
||||||
|
|
||||||
Command::~Command() { cmdBuffer->release(); }
|
Command::~Command() { cmdBuffer->release(); }
|
||||||
@@ -31,16 +32,16 @@ void Command::end(PEvent signal) {
|
|||||||
cmdBuffer->commit();
|
cmdBuffer->commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::executeCommands(const Array<Gfx::PRenderCommand> &commands) {
|
void Command::executeCommands(Array<Gfx::ORenderCommand> commands) {
|
||||||
for (auto command : commands) {
|
for (auto& command : commands) {
|
||||||
auto cmd = command.cast<RenderCommand>();
|
auto cmd = Gfx::PRenderCommand(command).cast<RenderCommand>();
|
||||||
cmd->end();
|
cmd->end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::executeCommands(const Array<Gfx::PComputeCommand> &commands) {
|
void Command::executeCommands(Array<Gfx::OComputeCommand> commands) {
|
||||||
for (auto command : commands) {
|
for (auto& command : commands) {
|
||||||
auto cmd = command.cast<ComputeCommand>();
|
auto cmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
|
||||||
cmd->end();
|
cmd->end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,11 +157,11 @@ CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
|
|||||||
|
|
||||||
CommandQueue::~CommandQueue() { queue->release(); }
|
CommandQueue::~CommandQueue() { queue->release(); }
|
||||||
|
|
||||||
PRenderCommand CommandQueue::getRenderCommand(const std::string &name) {
|
ORenderCommand CommandQueue::getRenderCommand(const std::string &name) {
|
||||||
return new RenderCommand(activeCommand->createRenderEncoder());
|
return new RenderCommand(activeCommand->createRenderEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
PComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
|
OComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
|
||||||
return new ComputeCommand(activeCommand->createComputeEncoder());
|
return new ComputeCommand(activeCommand->createComputeEncoder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public:
|
|||||||
virtual void endRenderPass() override;
|
virtual void endRenderPass() override;
|
||||||
virtual void waitDeviceIdle() override;
|
virtual void waitDeviceIdle() override;
|
||||||
|
|
||||||
virtual void executeCommands(const Array<Gfx::PRenderCommand>& commands) override;
|
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||||
virtual void executeCommands(const Array<Gfx::PComputeCommand>& commands) override;
|
virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override;
|
||||||
|
|
||||||
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
|
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
|
||||||
virtual Gfx::OTexture3D createTexture3D(const TextureCreateInfo &createInfo) override;
|
virtual Gfx::OTexture3D createTexture3D(const TextureCreateInfo &createInfo) override;
|
||||||
@@ -33,8 +33,8 @@ public:
|
|||||||
virtual Gfx::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
|
virtual Gfx::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
|
||||||
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
|
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
|
||||||
|
|
||||||
virtual Gfx::PRenderCommand createRenderCommand(const std::string& name = "") override;
|
virtual Gfx::ORenderCommand createRenderCommand(const std::string& name = "") override;
|
||||||
virtual Gfx::PComputeCommand createComputeCommand(const std::string& name = "") override;
|
virtual Gfx::OComputeCommand createComputeCommand(const std::string& name = "") override;
|
||||||
|
|
||||||
virtual Gfx::OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) override;
|
virtual Gfx::OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) override;
|
||||||
virtual Gfx::OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
virtual Gfx::OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
||||||
|
|||||||
@@ -54,53 +54,60 @@ void Graphics::waitDeviceIdle()
|
|||||||
queue->getCommands()->waitDeviceIdle();
|
queue->getCommands()->waitDeviceIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands)
|
||||||
{
|
{
|
||||||
queue->getCommands()->executeCommands(commands);
|
queue->getCommands()->executeCommands(std::move(commands));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands)
|
||||||
{
|
{
|
||||||
queue->getCommands()->executeCommands(commands);
|
queue->getCommands()->executeCommands(std::move(commands));
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
|
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
return new Texture2D(this, createInfo);
|
return new Texture2D(this, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
|
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
return new Texture3D(this, createInfo);
|
return new Texture3D(this, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
|
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
|
||||||
{
|
{
|
||||||
return new TextureCube(this, createInfo);
|
return new TextureCube(this, createInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
|
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
|
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData)
|
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData)
|
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::PRenderCommand Graphics::createRenderCommand(const std::string& name)
|
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name)
|
||||||
{
|
{
|
||||||
|
return queue->getRenderCommand(name);
|
||||||
}
|
}
|
||||||
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name)
|
||||||
|
{
|
||||||
|
return queue->getComputeCommand(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo)
|
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo)
|
||||||
|
|||||||
@@ -48,13 +48,13 @@ void DebugPass::beginFrame(const Component::Camera& cam)
|
|||||||
void DebugPass::render()
|
void DebugPass::render()
|
||||||
{
|
{
|
||||||
graphics->beginRenderPass(renderPass);
|
graphics->beginRenderPass(renderPass);
|
||||||
Gfx::PRenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
|
Gfx::ORenderCommand renderCommand = graphics->createRenderCommand("DebugRender");
|
||||||
renderCommand->setViewport(viewport);
|
renderCommand->setViewport(viewport);
|
||||||
renderCommand->bindPipeline(pipeline);
|
renderCommand->bindPipeline(pipeline);
|
||||||
renderCommand->bindDescriptor(viewParamsSet);
|
renderCommand->bindDescriptor(viewParamsSet);
|
||||||
renderCommand->bindVertexBuffer({ debugVertices });
|
renderCommand->bindVertexBuffer({ debugVertices });
|
||||||
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
renderCommand->draw((uint32)gDebugVertices.size(), 1, 0, 0);
|
||||||
graphics->executeCommands(Array{renderCommand});
|
graphics->executeCommands(Array{std::move(renderCommand)});
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
gDebugVertices.clear();
|
gDebugVertices.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ void DepthPrepass::render()
|
|||||||
permutation.setVertexFile("LegacyBasePass");
|
permutation.setVertexFile("LegacyBasePass");
|
||||||
}
|
}
|
||||||
graphics->beginRenderPass(renderPass);
|
graphics->beginRenderPass(renderPass);
|
||||||
Array<Gfx::PRenderCommand> commands;
|
Array<Gfx::ORenderCommand> commands;
|
||||||
for (VertexData* vertexData : VertexData::getList())
|
for (VertexData* vertexData : VertexData::getList())
|
||||||
{
|
{
|
||||||
permutation.setVertexData(vertexData->getTypeName());
|
permutation.setVertexData(vertexData->getTypeName());
|
||||||
@@ -66,7 +66,7 @@ void DepthPrepass::render()
|
|||||||
// SceneData => per material instance
|
// SceneData => per material instance
|
||||||
Gfx::PermutationId id(permutation);
|
Gfx::PermutationId id(permutation);
|
||||||
|
|
||||||
Gfx::PRenderCommand command = graphics->createRenderCommand("DepthRender");
|
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||||
command->setViewport(viewport);
|
command->setViewport(viewport);
|
||||||
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
||||||
//layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
//layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
||||||
@@ -126,10 +126,10 @@ void DepthPrepass::render()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commands.add(command);
|
commands.add(std::move(command));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
graphics->executeCommands(commands);
|
graphics->executeCommands(std::move(commands));
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,13 +42,13 @@ void UIPass::beginFrame(const Component::Camera& cam)
|
|||||||
void UIPass::render()
|
void UIPass::render()
|
||||||
{
|
{
|
||||||
graphics->beginRenderPass(renderPass);
|
graphics->beginRenderPass(renderPass);
|
||||||
Gfx::PRenderCommand command = graphics->createRenderCommand("UIPassCommand");
|
Gfx::ORenderCommand command = graphics->createRenderCommand("UIPassCommand");
|
||||||
command->setViewport(viewport);
|
command->setViewport(viewport);
|
||||||
command->bindPipeline(pipeline);
|
command->bindPipeline(pipeline);
|
||||||
command->bindVertexBuffer({elementBuffer});
|
command->bindVertexBuffer({elementBuffer});
|
||||||
command->bindDescriptor(descriptorSet);
|
command->bindDescriptor(descriptorSet);
|
||||||
command->draw(4, static_cast<uint32>(renderElements.size()), 0, 0);
|
command->draw(4, static_cast<uint32>(renderElements.size()), 0, 0);
|
||||||
graphics->executeCommands(Array<Gfx::PRenderCommand>({command}));
|
graphics->executeCommands(Array{std::move(command)});
|
||||||
graphics->endRenderPass();
|
graphics->endRenderPass();
|
||||||
|
|
||||||
//co_return;
|
//co_return;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void Command::endRenderPass()
|
|||||||
state = State::Begin;
|
state = State::Begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
void Command::executeCommands(const Array<Gfx::ORenderCommand>& commands)
|
||||||
{
|
{
|
||||||
assert(state == State::RenderPass);
|
assert(state == State::RenderPass);
|
||||||
if(commands.size() == 0)
|
if(commands.size() == 0)
|
||||||
@@ -93,7 +93,7 @@ void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
|||||||
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
||||||
for (uint32 i = 0; i < commands.size(); ++i)
|
for (uint32 i = 0; i < commands.size(); ++i)
|
||||||
{
|
{
|
||||||
auto command = commands[i].cast<RenderCommand>();
|
auto command = Gfx::PRenderCommand(commands[i]).cast<RenderCommand>();
|
||||||
command->end();
|
command->end();
|
||||||
executingRenders.add(command);
|
executingRenders.add(command);
|
||||||
for(auto& descriptor : command->boundDescriptors)
|
for(auto& descriptor : command->boundDescriptors)
|
||||||
@@ -106,7 +106,7 @@ void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
|||||||
vkCmdExecuteCommands(handle, (uint32)cmdBuffers.size(), cmdBuffers.data());
|
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)
|
if(commands.size() == 0)
|
||||||
{
|
{
|
||||||
@@ -115,7 +115,7 @@ void Command::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
|||||||
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
Array<VkCommandBuffer> cmdBuffers(commands.size());
|
||||||
for (uint32 i = 0; i < commands.size(); ++i)
|
for (uint32 i = 0; i < commands.size(); ++i)
|
||||||
{
|
{
|
||||||
auto command = commands[i].cast<ComputeCommand>();
|
auto command = Gfx::PComputeCommand(commands[i]).cast<ComputeCommand>();
|
||||||
command->end();
|
command->end();
|
||||||
executingComputes.add(command);
|
executingComputes.add(command);
|
||||||
for(auto& descriptor : command->boundDescriptors)
|
for(auto& descriptor : command->boundDescriptors)
|
||||||
@@ -485,40 +485,49 @@ PCommand CommandPool::getCommands()
|
|||||||
{
|
{
|
||||||
return command;
|
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)
|
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
|
||||||
{
|
{
|
||||||
PRenderCommand cmdBuffer = allocatedRenderCommands[i];
|
if (allocatedRenderCommands[i]->isReady())
|
||||||
if (cmdBuffer->isReady())
|
|
||||||
{
|
{
|
||||||
|
ORenderCommand cmdBuffer = std::move(allocatedRenderCommands[i]);
|
||||||
|
allocatedRenderCommands.removeAt(i, false);
|
||||||
cmdBuffer->name = name;
|
cmdBuffer->name = name;
|
||||||
cmdBuffer->begin(command->boundRenderPass, command->boundFramebuffer);
|
cmdBuffer->begin(command->boundRenderPass, command->boundFramebuffer);
|
||||||
return cmdBuffer;
|
return cmdBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocatedRenderCommands.add(new RenderCommand(graphics, commandPool));
|
ORenderCommand result = new RenderCommand(graphics, commandPool);
|
||||||
PRenderCommand result = allocatedRenderCommands.back();
|
|
||||||
result->name = name;
|
result->name = name;
|
||||||
result->begin(command->boundRenderPass, command->boundFramebuffer);
|
result->begin(command->boundRenderPass, command->boundFramebuffer);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PComputeCommand CommandPool::createComputeCommand(const std::string& name)
|
OComputeCommand CommandPool::createComputeCommand(const std::string& name)
|
||||||
{
|
{
|
||||||
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
|
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
|
||||||
{
|
{
|
||||||
PComputeCommand cmdBuffer = allocatedComputeCommands[i];
|
if (allocatedComputeCommands[i]->isReady())
|
||||||
if (cmdBuffer->isReady())
|
|
||||||
{
|
{
|
||||||
|
OComputeCommand cmdBuffer = std::move(allocatedComputeCommands[i]);
|
||||||
|
allocatedComputeCommands.removeAt(i, false);
|
||||||
cmdBuffer->name = name;
|
cmdBuffer->name = name;
|
||||||
cmdBuffer->begin();
|
cmdBuffer->begin();
|
||||||
return cmdBuffer;
|
return cmdBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocatedComputeCommands.add(new ComputeCommand(graphics, commandPool));
|
OComputeCommand result = new ComputeCommand(graphics, commandPool);
|
||||||
PComputeCommand result = allocatedComputeCommands.back();
|
|
||||||
result->name = name;
|
result->name = name;
|
||||||
result->begin();
|
result->begin();
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,42 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Queue.h"
|
|
||||||
#include "Graphics/Command.h"
|
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
#include "Graphics/Command.h"
|
||||||
|
#include "Queue.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele {
|
||||||
{
|
namespace Vulkan {
|
||||||
namespace Vulkan
|
|
||||||
{
|
|
||||||
DECLARE_REF(RenderPass)
|
DECLARE_REF(RenderPass)
|
||||||
DECLARE_REF(Framebuffer)
|
DECLARE_REF(Framebuffer)
|
||||||
DECLARE_REF(RenderCommand)
|
DECLARE_REF(RenderCommand)
|
||||||
DECLARE_REF(ComputeCommand)
|
DECLARE_REF(ComputeCommand)
|
||||||
DECLARE_REF(DescriptorSet)
|
DECLARE_REF(DescriptorSet)
|
||||||
DECLARE_REF(CommandPool)
|
DECLARE_REF(CommandPool)
|
||||||
class Command
|
class Command {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Command(PGraphics graphics, PCommandPool pool);
|
Command(PGraphics graphics, PCommandPool pool);
|
||||||
~Command();
|
~Command();
|
||||||
constexpr VkCommandBuffer getHandle()
|
constexpr VkCommandBuffer getHandle() { return handle; }
|
||||||
{
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
void reset();
|
void reset();
|
||||||
void begin();
|
void begin();
|
||||||
void end();
|
void end();
|
||||||
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
|
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||||
void endRenderPass();
|
void endRenderPass();
|
||||||
void executeCommands(const Array<Gfx::PRenderCommand>& secondaryCommands);
|
void executeCommands(const Array<Gfx::ORenderCommand> &secondaryCommands);
|
||||||
void executeCommands(const Array<Gfx::PComputeCommand>& secondaryCommands);
|
void executeCommands(const Array<Gfx::OComputeCommand> &secondaryCommands);
|
||||||
void waitForSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
|
void waitForSemaphore(VkPipelineStageFlags stages, PSemaphore waitSemaphore);
|
||||||
void checkFence();
|
void checkFence();
|
||||||
void waitForCommand(uint32 timeToWait = 1000000u);
|
void waitForCommand(uint32 timeToWait = 1000000u);
|
||||||
PFence getFence();
|
PFence getFence();
|
||||||
PCommandPool getPool();
|
PCommandPool getPool();
|
||||||
enum State
|
enum State {
|
||||||
{
|
|
||||||
Init,
|
Init,
|
||||||
Begin,
|
Begin,
|
||||||
RenderPass,
|
RenderPass,
|
||||||
@@ -68,15 +61,11 @@ DEFINE_REF(Command)
|
|||||||
|
|
||||||
DECLARE_REF(GraphicsPipeline)
|
DECLARE_REF(GraphicsPipeline)
|
||||||
DECLARE_REF(ComputePipeline)
|
DECLARE_REF(ComputePipeline)
|
||||||
class RenderCommand : public Gfx::RenderCommand
|
class RenderCommand : public Gfx::RenderCommand {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
|
RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||||
virtual ~RenderCommand();
|
virtual ~RenderCommand();
|
||||||
constexpr VkCommandBuffer getHandle()
|
constexpr VkCommandBuffer getHandle() { return handle; }
|
||||||
{
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
|
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||||
void end();
|
void end();
|
||||||
void reset();
|
void reset();
|
||||||
@@ -84,13 +73,21 @@ public:
|
|||||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
|
virtual void
|
||||||
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
|
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 bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
virtual void pushConstants(Gfx::PPipelineLayout layout,
|
||||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
|
Gfx::SeShaderStageFlags stage, uint32 offset,
|
||||||
virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override;
|
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;
|
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PGraphicsPipeline pipeline;
|
PGraphicsPipeline pipeline;
|
||||||
bool ready;
|
bool ready;
|
||||||
@@ -105,15 +102,11 @@ private:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(RenderCommand)
|
DEFINE_REF(RenderCommand)
|
||||||
|
|
||||||
class ComputeCommand : public Gfx::ComputeCommand
|
class ComputeCommand : public Gfx::ComputeCommand {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
|
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
|
||||||
virtual ~ComputeCommand();
|
virtual ~ComputeCommand();
|
||||||
inline VkCommandBuffer getHandle()
|
inline VkCommandBuffer getHandle() { return handle; }
|
||||||
{
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
void begin();
|
void begin();
|
||||||
void end();
|
void end();
|
||||||
void reset();
|
void reset();
|
||||||
@@ -121,8 +114,12 @@ public:
|
|||||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet> &sets) 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 pushConstants(Gfx::PPipelineLayout layout,
|
||||||
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
|
Gfx::SeShaderStageFlags stage, uint32 offset,
|
||||||
|
uint32 size, const void *data) override;
|
||||||
|
virtual void dispatch(uint32 threadX, uint32 threadY,
|
||||||
|
uint32 threadZ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PComputePipeline pipeline;
|
PComputePipeline pipeline;
|
||||||
bool ready;
|
bool ready;
|
||||||
@@ -136,22 +133,17 @@ private:
|
|||||||
friend class Command;
|
friend class Command;
|
||||||
};
|
};
|
||||||
DEFINE_REF(ComputeCommand)
|
DEFINE_REF(ComputeCommand)
|
||||||
class CommandPool
|
class CommandPool {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
CommandPool(PGraphics graphics, PQueue queue);
|
CommandPool(PGraphics graphics, PQueue queue);
|
||||||
virtual ~CommandPool();
|
virtual ~CommandPool();
|
||||||
constexpr PQueue getQueue() const
|
constexpr PQueue getQueue() const { return queue; }
|
||||||
{
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
PCommand getCommands();
|
PCommand getCommands();
|
||||||
PRenderCommand createRenderCommand(const std::string& name);
|
void cacheCommands(Array<ORenderCommand> commands);
|
||||||
PComputeCommand createComputeCommand(const std::string& name);
|
void cacheCommands(Array<OComputeCommand> commands);
|
||||||
constexpr VkCommandPool getHandle() const
|
ORenderCommand createRenderCommand(const std::string &name);
|
||||||
{
|
OComputeCommand createComputeCommand(const std::string &name);
|
||||||
return commandPool;
|
constexpr VkCommandPool getHandle() const { return commandPool; }
|
||||||
}
|
|
||||||
void submitCommands(PSemaphore signalSemaphore = nullptr);
|
void submitCommands(PSemaphore signalSemaphore = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -116,12 +116,12 @@ void Graphics::waitDeviceIdle()
|
|||||||
vkDeviceWaitIdle(handle);
|
vkDeviceWaitIdle(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::executeCommands(const Array<Gfx::PRenderCommand>& commands)
|
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands)
|
||||||
{
|
{
|
||||||
getGraphicsCommands()->getCommands()->executeCommands(commands);
|
getGraphicsCommands()->getCommands()->executeCommands(commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::executeCommands(const Array<Gfx::PComputeCommand>& commands)
|
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands)
|
||||||
{
|
{
|
||||||
getComputeCommands()->getCommands()->executeCommands(commands);
|
getComputeCommands()->getCommands()->executeCommands(commands);
|
||||||
}
|
}
|
||||||
@@ -159,12 +159,12 @@ Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkD
|
|||||||
{
|
{
|
||||||
return new IndexBuffer(this, bulkData);
|
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);
|
return getGraphicsCommands()->createRenderCommand(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::PComputeCommand Graphics::createComputeCommand(const std::string& name)
|
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name)
|
||||||
{
|
{
|
||||||
return getComputeCommands()->createComputeCommand(name);
|
return getComputeCommands()->createComputeCommand(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ public:
|
|||||||
virtual void endRenderPass() override;
|
virtual void endRenderPass() override;
|
||||||
virtual void waitDeviceIdle() override;
|
virtual void waitDeviceIdle() override;
|
||||||
|
|
||||||
virtual void executeCommands(const Array<Gfx::PRenderCommand>& commands) override;
|
virtual void executeCommands(Array<Gfx::ORenderCommand> commands) override;
|
||||||
virtual void executeCommands(const Array<Gfx::PComputeCommand>& commands) override;
|
virtual void executeCommands(Array<Gfx::OComputeCommand> commands) override;
|
||||||
|
|
||||||
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
|
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo &createInfo) override;
|
||||||
virtual Gfx::OTexture3D createTexture3D(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::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
|
||||||
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
|
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
|
||||||
|
|
||||||
virtual Gfx::PRenderCommand createRenderCommand(const std::string& name) override;
|
virtual Gfx::ORenderCommand createRenderCommand(const std::string& name) override;
|
||||||
virtual Gfx::PComputeCommand createComputeCommand(const std::string& name) override;
|
virtual Gfx::OComputeCommand createComputeCommand(const std::string& name) override;
|
||||||
|
|
||||||
virtual Gfx::OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) override;
|
virtual Gfx::OVertexShader createVertexShader(const ShaderCreateInfo& createInfo) override;
|
||||||
virtual Gfx::OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
virtual Gfx::OFragmentShader createFragmentShader(const ShaderCreateInfo& createInfo) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user