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

133 lines
5.2 KiB
C++
Raw Normal View History

2024-04-10 08:43:56 +02:00
#pragma once
2024-04-14 11:35:37 +02:00
#include "Buffer.h"
2024-04-17 14:33:06 +02:00
#include "Graphics/Command.h"
2024-08-26 21:49:09 +02:00
#include "Metal/MTLArgumentEncoder.hpp"
2024-04-17 14:33:06 +02:00
#include "Metal/MTLBlitCommandEncoder.hpp"
2024-04-19 18:23:36 +02:00
#include "Metal/MTLCaptureManager.hpp"
2024-04-17 14:33:06 +02:00
#include "Metal/MTLCommandBuffer.hpp"
#include "Metal/MTLComputeCommandEncoder.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
2024-04-10 08:43:56 +02:00
#include "RenderPass.h"
#include "Resources.h"
namespace Seele {
namespace Metal {
DECLARE_REF(CommandQueue)
DECLARE_REF(ComputeCommand)
DECLARE_REF(RenderCommand)
2024-04-11 12:38:42 +02:00
DECLARE_REF(Graphics)
2024-04-14 11:35:37 +02:00
DECLARE_REF(IndexBuffer)
DECLARE_REF(GraphicsPipeline)
2024-04-19 18:23:36 +02:00
DECLARE_REF(ComputePipeline)
2024-04-17 14:33:06 +02:00
class Command {
2024-06-09 12:20:04 +02:00
public:
Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer);
~Command();
void beginRenderPass(PRenderPass renderPass);
void endRenderPass();
void present(MTL::Drawable* drawable);
void end(PEvent signal);
void waitDeviceIdle();
void signalEvent(PEvent event);
void waitForEvent(PEvent event);
MTL::RenderCommandEncoder* createRenderEncoder() { return parallelEncoder->renderCommandEncoder(); }
MTL::BlitCommandEncoder* getBlitEncoder() {
assert(!parallelEncoder);
if (blitEncoder == nullptr) {
blitEncoder = cmdBuffer->blitCommandEncoder();
}
return blitEncoder;
2024-04-10 15:50:20 +02:00
}
2024-06-09 12:20:04 +02:00
PEvent getCompletedEvent() const { return completed; }
constexpr MTL::CommandBuffer* getHandle() const { return cmdBuffer; }
2024-04-17 14:33:06 +02:00
2024-06-09 12:20:04 +02:00
private:
PGraphics graphics;
OEvent completed;
MTL::CommandBuffer* cmdBuffer;
MTL::ParallelRenderCommandEncoder* parallelEncoder = nullptr;
MTL::BlitCommandEncoder* blitEncoder = nullptr;
2024-04-10 08:43:56 +02:00
};
DEFINE_REF(Command)
2024-04-17 14:33:06 +02:00
class RenderCommand : public Gfx::RenderCommand {
2024-06-09 12:20:04 +02:00
public:
RenderCommand(MTL::RenderCommandEncoder* encode, const std::string& name);
virtual ~RenderCommand();
void end();
virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
2024-08-26 21:49:09 +02:00
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
2024-09-16 13:00:53 +02:00
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
2024-06-09 12:20:04 +02:00
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
2025-03-04 19:38:03 +09:00
virtual void drawIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override;
2024-06-09 12:20:04 +02:00
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 drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override;
2024-08-26 21:49:09 +02:00
virtual void traceRays(uint32 width, uint32 height, uint32 depth) override;
2024-04-17 14:33:06 +02:00
2024-06-09 12:20:04 +02:00
private:
2024-04-19 22:44:00 +02:00
PGraphicsPipeline boundPipeline;
PIndexBuffer boundIndexBuffer;
2024-06-09 12:20:04 +02:00
MTL::RenderCommandEncoder* encoder;
std::string name;
2024-04-10 08:43:56 +02:00
};
DEFINE_REF(RenderCommand)
2024-04-17 14:33:06 +02:00
class ComputeCommand : public Gfx::ComputeCommand {
2024-06-09 12:20:04 +02:00
public:
ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name);
virtual ~ComputeCommand();
void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
2024-09-16 13:00:53 +02:00
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
2024-06-09 12:20:04 +02:00
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
2024-11-01 21:04:06 +01:00
virtual void dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset) override;
2024-04-17 14:33:06 +02:00
2024-06-09 12:20:04 +02:00
private:
PComputePipeline boundPipeline;
MTL::CommandBuffer* commandBuffer;
MTL::ComputeCommandEncoder* encoder;
std::string name;
2024-04-10 08:43:56 +02:00
};
DEFINE_REF(ComputeCommand)
2024-04-17 14:33:06 +02:00
class CommandQueue {
2024-06-09 12:20:04 +02:00
public:
CommandQueue(PGraphics graphics);
~CommandQueue();
constexpr MTL::CommandQueue* getHandle() { return queue; }
PCommand getCommands() { return activeCommand; }
ORenderCommand getRenderCommand(const std::string& name);
OComputeCommand getComputeCommand(const std::string& name);
void executeCommands(Array<Gfx::ORenderCommand> commands);
void executeCommands(Array<Gfx::OComputeCommand> commands);
void submitCommands(PEvent signal = nullptr);
2024-04-17 14:33:06 +02:00
2024-06-09 12:20:04 +02:00
private:
PGraphics graphics;
MTL::CommandQueue* queue;
OCommand activeCommand;
Array<OCommand> pendingCommands;
2025-02-02 09:39:01 +01:00
Array<OCommand> readyCommands;
2024-04-10 08:43:56 +02:00
};
2024-04-17 14:33:06 +02:00
class IOCommandQueue {
2024-06-09 12:20:04 +02:00
public:
IOCommandQueue(PGraphics graphics);
~IOCommandQueue();
constexpr MTL::IOCommandQueue* getHandle() { return queue; }
PCommand getCommands() { return activeCommand; } // TODO
void submitCommands(PEvent signal = nullptr);
2024-04-17 14:33:06 +02:00
2024-06-09 12:20:04 +02:00
private:
PGraphics graphics;
MTL::IOCommandQueue* queue;
OCommand activeCommand;
2024-04-10 15:50:20 +02:00
};
DEFINE_REF(IOCommandQueue)
2024-04-17 14:33:06 +02:00
} // namespace Metal
2024-04-19 18:23:36 +02:00
} // namespace Seele