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 target_sources(Engine
PRIVATE PRIVATE
Buffer.h
Buffer.mm
Command.h Command.h
Command.mm Command.mm
Descriptor.h Descriptor.h
+22
View File
@@ -2,6 +2,7 @@
#include "Graphics/Command.h" #include "Graphics/Command.h"
#include "Metal/MTLComputeCommandEncoder.hpp" #include "Metal/MTLComputeCommandEncoder.hpp"
#include "Metal/MTLDrawable.hpp" #include "Metal/MTLDrawable.hpp"
#include "Metal/MTLIOCommandQueue.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp" #include "Metal/MTLRenderCommandEncoder.hpp"
#include "MinimalEngine.h" #include "MinimalEngine.h"
#include "RenderPass.h" #include "RenderPass.h"
@@ -30,6 +31,10 @@ public:
MTL::RenderCommandEncoder* createRenderEncoder() { return renderEncoder->renderCommandEncoder(); } MTL::RenderCommandEncoder* createRenderEncoder() { return renderEncoder->renderCommandEncoder(); }
MTL::ComputeCommandEncoder* createComputeEncoder() { return cmdBuffer->computeCommandEncoder(); } MTL::ComputeCommandEncoder* createComputeEncoder() { return cmdBuffer->computeCommandEncoder(); }
PEvent getCompletedEvent() const { return completed; } PEvent getCompletedEvent() const { return completed; }
constexpr MTL::CommandBuffer* getHandle() const
{
return cmdBuffer;
}
private: private:
PGraphics graphics; PGraphics graphics;
PCommandQueue owner; PCommandQueue owner;
@@ -91,5 +96,22 @@ private:
MTL::CommandQueue* queue; MTL::CommandQueue* queue;
OCommand activeCommand; 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)
} }
} }
+21 -3
View File
@@ -1,6 +1,7 @@
#include "Command.h" #include "Command.h"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
#include "Graphics/Metal/Resources.h" #include "Graphics/Metal/Resources.h"
#include "Metal/MTLIOCommandQueue.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp" #include "Metal/MTLRenderCommandEncoder.hpp"
#include "Window.h" #include "Window.h"
@@ -46,9 +47,7 @@ void Command::executeCommands(Array<Gfx::OComputeCommand> commands) {
} }
} }
void Command::waitDeviceIdle() { void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
cmdBuffer->waitUntilCompleted();
}
void Command::signalEvent(PEvent event) { void Command::signalEvent(PEvent event) {
cmdBuffer->encodeSignalEvent(event->getHandle(), 1); cmdBuffer->encodeSignalEvent(event->getHandle(), 1);
@@ -171,3 +170,22 @@ void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand = new Command(graphics, this); activeCommand = new Command(graphics, this);
activeCommand->waitForEvent(prevCmdEvent); 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 #pragma once
#include "Graphics/Descriptor.h" #include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h"
#include "MinimalEngine.h"
namespace Seele { namespace Seele {
namespace Metal { namespace Metal {
DECLARE_REF(Graphics) DECLARE_REF(Graphics)
DECLARE_REF(DescriptorPool)
class DescriptorLayout : public Gfx::DescriptorLayout class DescriptorLayout : public Gfx::DescriptorLayout
{ {
public: public:
DescriptorLayout(PGraphics graphics, const std::string& name); DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create(); virtual void create() override;
private: private:
PGraphics graphics; PGraphics graphics;
}; };
class PipelineLayout : public Gfx::PipelineLayout class PipelineLayout : public Gfx::PipelineLayout
{ {
public: public:
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout)
, graphics(graphics)
{}
private: 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 #pragma once
#include "Graphics/Metal/Command.h"
#include "Metal/Metal.hpp" #include "Metal/Metal.hpp"
#include "Graphics/Graphics.h" #include "Graphics/Graphics.h"
@@ -55,10 +56,12 @@ public:
MTL::Device* getDevice() const { return device; } MTL::Device* getDevice() const { return device; }
PCommandQueue getQueue() const { return queue; } PCommandQueue getQueue() const { return queue; }
PIOCommandQueue getIOQueue() const { return ioQueue; }
protected: protected:
MTL::Device* device; MTL::Device* device;
MTL::Library* library; MTL::Library* library;
OCommandQueue queue; OCommandQueue queue;
OIOCommandQueue ioQueue;
}; };
DEFINE_REF(Graphics) DEFINE_REF(Graphics)
} // namespace Metal } // namespace Metal
+1
View File
@@ -22,6 +22,7 @@ void Graphics::init(GraphicsInitializer)
library = device->newDefaultLibrary(); library = device->newDefaultLibrary();
assert(library); assert(library);
queue = new CommandQueue(this); queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this);
} }
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
+10 -1
View File
@@ -3,6 +3,7 @@
#include "Graphics/Enums.h" #include "Graphics/Enums.h"
#include "Graphics/Initializer.h" #include "Graphics/Initializer.h"
#include "Graphics/Metal/Graphics.h" #include "Graphics/Metal/Graphics.h"
#include "Metal/MTLTypes.hpp"
using namespace Seele; using namespace Seele;
using namespace Seele::Metal; using namespace Seele::Metal;
@@ -44,6 +45,11 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
descriptor->release(); 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() { TextureBase::~TextureBase() {
@@ -55,7 +61,10 @@ TextureBase::~TextureBase() {
void TextureBase::executePipelineBarrier(Gfx::SeAccessFlags, void TextureBase::executePipelineBarrier(Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags, Gfx::SePipelineStageFlags,
Gfx::SeAccessFlags, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags) {} Gfx::SePipelineStageFlags) {
}
void TextureBase::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags, void TextureBase::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags, Gfx::SeAccessFlags, Gfx::SePipelineStageFlags, Gfx::SeAccessFlags,
+1 -1
View File
@@ -14,7 +14,7 @@ class DescriptorLayout : public Gfx::DescriptorLayout
public: public:
DescriptorLayout(PGraphics graphics, const std::string& name); DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create(); virtual void create() override;
constexpr VkDescriptorSetLayout getHandle() const constexpr VkDescriptorSetLayout getHandle() const
{ {
return layoutHandle; return layoutHandle;