More skeleton

This commit is contained in:
Dynamitos
2024-04-10 15:50:20 +02:00
parent e9e483d9d1
commit c3be0e23e7
10 changed files with 141 additions and 9 deletions
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include "Graphics/Buffer.h"
#include "Graphics/Initializer.h"
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
class Buffer
{
};
DEFINE_REF(Buffer)
class VertexBuffer : public Gfx::VertexBuffer, public Buffer
{
public:
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo);
virtual ~VertexBuffer();
private:
};
DEFINE_REF(VertexBuffer)
class IndexBuffer : public Gfx::IndexBuffer, public Buffer
{
public:
IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo);
virtual ~IndexBuffer();
private:
};
DEFINE_REF(IndexBuffer)
class UniformBuffer : public Gfx::UniformBuffer, public Buffer
{
public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo);
virtual ~UniformBuffer();
private:
};
DEFINE_REF(UniformBuffer)
class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer
{
public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo);
virtual ~ShaderBuffer();
private:
};
DEFINE_REF(ShaderBuffer)
}
}
+1
View File
@@ -0,0 +1 @@
#include "Buffer.h"
+2
View File
@@ -1,5 +1,7 @@
target_sources(Engine
PRIVATE
Buffer.h
Buffer.mm
Command.h
Command.mm
Descriptor.h
+22
View File
@@ -2,6 +2,7 @@
#include "Graphics/Command.h"
#include "Metal/MTLComputeCommandEncoder.hpp"
#include "Metal/MTLDrawable.hpp"
#include "Metal/MTLIOCommandQueue.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "MinimalEngine.h"
#include "RenderPass.h"
@@ -30,6 +31,10 @@ public:
MTL::RenderCommandEncoder* createRenderEncoder() { return renderEncoder->renderCommandEncoder(); }
MTL::ComputeCommandEncoder* createComputeEncoder() { return cmdBuffer->computeCommandEncoder(); }
PEvent getCompletedEvent() const { return completed; }
constexpr MTL::CommandBuffer* getHandle() const
{
return cmdBuffer;
}
private:
PGraphics graphics;
PCommandQueue owner;
@@ -91,5 +96,22 @@ private:
MTL::CommandQueue* queue;
OCommand activeCommand;
};
class IOCommandQueue
{
public:
IOCommandQueue(PGraphics graphics);
~IOCommandQueue();
constexpr MTL::IOCommandQueue* getHandle()
{
return queue;
}
PCommand getCommands();
void submitCommands(PEvent signal = nullptr);
private:
PGraphics graphics;
MTL::IOCommandQueue* queue;
OCommand activeCommand;
};
DEFINE_REF(IOCommandQueue)
}
}
+24 -6
View File
@@ -1,6 +1,7 @@
#include "Command.h"
#include "Graphics/Graphics.h"
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLIOCommandQueue.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "Window.h"
@@ -33,22 +34,20 @@ void Command::end(PEvent signal) {
}
void Command::executeCommands(Array<Gfx::ORenderCommand> commands) {
for (auto& command : commands) {
for (auto &command : commands) {
auto cmd = Gfx::PRenderCommand(command).cast<RenderCommand>();
cmd->end();
}
}
void Command::executeCommands(Array<Gfx::OComputeCommand> commands) {
for (auto& command : commands) {
for (auto &command : commands) {
auto cmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
cmd->end();
}
}
void Command::waitDeviceIdle() {
cmdBuffer->waitUntilCompleted();
}
void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
void Command::signalEvent(PEvent event) {
cmdBuffer->encodeSignalEvent(event->getHandle(), 1);
@@ -167,7 +166,26 @@ OComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->end(signalSemaphore);
MTL::Event* prevCmdEvent = activeCommand->getCompletedEvent();
MTL::Event *prevCmdEvent = activeCommand->getCompletedEvent();
activeCommand = new Command(graphics, this);
activeCommand->waitForEvent(prevCmdEvent);
}
IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
MTL::IOCommandQueueDescriptor* desc = MTL::IOCommandQueueDescriptor::alloc()->init();
desc->setType(MTL::IOCommandQueueTypeConcurrent);
desc->setPriority(MTL::IOPriorityNormal);
queue = graphics->getDevice()->newIOCommandQueue(desc);
activeCommand = new Command(graphics, this);
desc->release();
}
IOCommandQueue::~IOCommandQueue() { queue->release(); }
void IOCommandQueue::submitCommands(PEvent signalSemaphore) {
//TODO: scratch buffer
activeCommand->end(signalSemaphore);
MTL::Event *prevCmdEvent = activeCommand->getCompletedEvent();
activeCommand = new Command(graphics, this);
activeCommand->waitForEvent(prevCmdEvent);
}
+31 -1
View File
@@ -1,23 +1,53 @@
#pragma once
#include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h"
#include "MinimalEngine.h"
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
DECLARE_REF(DescriptorPool)
class DescriptorLayout : public Gfx::DescriptorLayout
{
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create();
virtual void create() override;
private:
PGraphics graphics;
};
class PipelineLayout : public Gfx::PipelineLayout
{
public:
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout)
, graphics(graphics)
{}
private:
PGraphics graphics;
};
DEFINE_REF(PipelineLayout)
class DescriptorSet : public Gfx::DescriptorSet
{
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: graphics(graphics)
, owner(owner)
{}
virtual ~DescriptorSet();
private:
PGraphics graphics;
PDescriptorPool owner;
};
DEFINE_REF(DescriptorSet)
class DescriptorPool : public Gfx::DescriptorPool
{
public:
DescriptorPool(PGraphics graphics);
private:
PGraphics graphics;
};
}
}
+3
View File
@@ -1,4 +1,5 @@
#pragma once
#include "Graphics/Metal/Command.h"
#include "Metal/Metal.hpp"
#include "Graphics/Graphics.h"
@@ -55,10 +56,12 @@ public:
MTL::Device* getDevice() const { return device; }
PCommandQueue getQueue() const { return queue; }
PIOCommandQueue getIOQueue() const { return ioQueue; }
protected:
MTL::Device* device;
MTL::Library* library;
OCommandQueue queue;
OIOCommandQueue ioQueue;
};
DEFINE_REF(Graphics)
} // namespace Metal
+1
View File
@@ -22,6 +22,7 @@ void Graphics::init(GraphicsInitializer)
library = device->newDefaultLibrary();
assert(library);
queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this);
}
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
+10 -1
View File
@@ -3,6 +3,7 @@
#include "Graphics/Enums.h"
#include "Graphics/Initializer.h"
#include "Graphics/Metal/Graphics.h"
#include "Metal/MTLTypes.hpp"
using namespace Seele;
using namespace Seele::Metal;
@@ -44,6 +45,11 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
descriptor->release();
}
if(createInfo.sourceData.data != nullptr)
{
MTL::Region region(0, 0, 0, width, height, depth);
texture->replaceRegion(region, 0, createInfo.sourceData.data, createInfo.sourceData.size / (depth / height));
}
}
TextureBase::~TextureBase() {
@@ -55,7 +61,10 @@ TextureBase::~TextureBase() {
void TextureBase::executePipelineBarrier(Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags,
Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags) {}
Gfx::SePipelineStageFlags) {
}
void TextureBase::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags, Gfx::SeAccessFlags,
+1 -1
View File
@@ -14,7 +14,7 @@ class DescriptorLayout : public Gfx::DescriptorLayout
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create();
virtual void create() override;
constexpr VkDescriptorSetLayout getHandle() const
{
return layoutHandle;