Changes to command ownership

This commit is contained in:
Dynamitos
2024-04-10 10:23:06 +02:00
parent 2a7643ddf3
commit b830fd378c
13 changed files with 216 additions and 200 deletions
+4 -4
View File
@@ -22,8 +22,8 @@ public:
void endRenderPass();
void present(MTL::Drawable* drawable);
void end(PEvent signal);
void executeCommands(const Array<Gfx::PRenderCommand>& commands);
void executeCommands(const Array<Gfx::PComputeCommand>& commands);
void executeCommands(Array<Gfx::ORenderCommand> commands);
void executeCommands(Array<Gfx::OComputeCommand> commands);
void waitDeviceIdle();
void signalEvent(PEvent event);
void waitForEvent(PEvent event);
@@ -83,8 +83,8 @@ public:
return queue;
}
PCommand getCommands();
PRenderCommand getRenderCommand(const std::string& name);
PComputeCommand getComputeCommand(const std::string& name);
ORenderCommand getRenderCommand(const std::string& name);
OComputeCommand getComputeCommand(const std::string& name);
void submitCommands(PEvent signal = nullptr);
private:
PGraphics graphics;
+10 -9
View File
@@ -1,4 +1,5 @@
#include "Command.h"
#include "Graphics/Graphics.h"
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "Window.h"
@@ -7,7 +8,7 @@ using namespace Seele;
using namespace Seele::Metal;
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) {}
Command::~Command() { cmdBuffer->release(); }
@@ -31,16 +32,16 @@ void Command::end(PEvent signal) {
cmdBuffer->commit();
}
void Command::executeCommands(const Array<Gfx::PRenderCommand> &commands) {
for (auto command : commands) {
auto cmd = command.cast<RenderCommand>();
void Command::executeCommands(Array<Gfx::ORenderCommand> commands) {
for (auto& command : commands) {
auto cmd = Gfx::PRenderCommand(command).cast<RenderCommand>();
cmd->end();
}
}
void Command::executeCommands(const Array<Gfx::PComputeCommand> &commands) {
for (auto command : commands) {
auto cmd = command.cast<ComputeCommand>();
void Command::executeCommands(Array<Gfx::OComputeCommand> commands) {
for (auto& command : commands) {
auto cmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
cmd->end();
}
}
@@ -156,11 +157,11 @@ CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
CommandQueue::~CommandQueue() { queue->release(); }
PRenderCommand CommandQueue::getRenderCommand(const std::string &name) {
ORenderCommand CommandQueue::getRenderCommand(const std::string &name) {
return new RenderCommand(activeCommand->createRenderEncoder());
}
PComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
OComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
return new ComputeCommand(activeCommand->createComputeEncoder());
}
+4 -4
View File
@@ -22,8 +22,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;
@@ -33,8 +33,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;
+15 -8
View File
@@ -54,53 +54,60 @@ void Graphics::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)
{
return new Texture2D(this, createInfo);
}
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo)
{
return new Texture3D(this, createInfo);
}
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
{
return new TextureCube(this, createInfo);
}
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
{
}
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
{
}
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &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)