Formatted EVERYTHING

This commit is contained in:
Dynamitos
2024-06-09 12:20:53 +02:00
parent f18bf8acbe
commit d95dab850c
265 changed files with 8002 additions and 12310 deletions
+64 -64
View File
@@ -9,93 +9,93 @@
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
class BufferAllocation : public CommandBoundResource
{
public:
BufferAllocation(PGraphics graphics);
virtual ~BufferAllocation();
MTL::Buffer* buffer = nullptr;
uint64 size = 0;
class BufferAllocation : public CommandBoundResource {
public:
BufferAllocation(PGraphics graphics);
virtual ~BufferAllocation();
MTL::Buffer* buffer = nullptr;
uint64 size = 0;
};
DECLARE_REF(BufferAllocation)
class Buffer {
public:
Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic, const std::string& name);
virtual ~Buffer();
MTL::Buffer *getHandle() const { return buffers[currentBuffer]->buffer; }
PBufferAllocation getAlloc() const { return buffers[currentBuffer]; }
uint64 getSize() const { return buffers[currentBuffer]->size; }
void *map(bool writeOnly = true);
void *mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly);
void unmap();
public:
Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic, const std::string& name);
virtual ~Buffer();
MTL::Buffer* getHandle() const { return buffers[currentBuffer]->buffer; }
PBufferAllocation getAlloc() const { return buffers[currentBuffer]; }
uint64 getSize() const { return buffers[currentBuffer]->size; }
void* map(bool writeOnly = true);
void* mapRegion(uint64 regionOffset, uint64 regionSize, bool writeOnly);
void unmap();
protected:
PGraphics graphics;
uint32 currentBuffer = 0;
Array<OBufferAllocation> buffers;
bool dynamic;
std::string name;
void rotateBuffer(uint64 size);
void createBuffer(uint64 size, void* data);
protected:
PGraphics graphics;
uint32 currentBuffer = 0;
Array<OBufferAllocation> buffers;
bool dynamic;
std::string name;
void rotateBuffer(uint64 size);
void createBuffer(uint64 size, void* data);
};
DEFINE_REF(Buffer)
class VertexBuffer : public Gfx::VertexBuffer, public Buffer {
public:
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo &createInfo);
virtual ~VertexBuffer();
virtual void updateRegion(DataSource update) override;
virtual void download(Array<uint8> &buffer) override;
public:
VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo);
virtual ~VertexBuffer();
virtual void updateRegion(DataSource update) override;
virtual void download(Array<uint8>& buffer) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(VertexBuffer)
class IndexBuffer : public Gfx::IndexBuffer, public Buffer {
public:
IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo &createInfo);
virtual ~IndexBuffer();
public:
IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo);
virtual ~IndexBuffer();
virtual void download(Array<uint8> &buffer) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(Array<uint8>& buffer) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(IndexBuffer)
DEFINE_REF(IndexBuffer)
class UniformBuffer : public Gfx::UniformBuffer, public Buffer {
public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo &createInfo);
virtual ~UniformBuffer();
public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo);
virtual ~UniformBuffer();
virtual bool updateContents(const DataSource &sourceData) override;
virtual bool updateContents(const DataSource& sourceData) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(UniformBuffer)
class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo &createInfo);
virtual ~ShaderBuffer();
virtual void rotateBuffer(uint64 size) override;
virtual void updateContents(const ShaderBufferCreateInfo &sourceData) override;
virtual void *mapRegion(uint64 offset, uint64 size, bool writeOnly) override;
virtual void unmap() override;
public:
ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo);
virtual ~ShaderBuffer();
virtual void rotateBuffer(uint64 size) override;
virtual void updateContents(const ShaderBufferCreateInfo& sourceData) override;
virtual void* mapRegion(uint64 offset, uint64 size, bool writeOnly) override;
virtual void unmap() override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(ShaderBuffer)
} // namespace Metal
+96 -75
View File
@@ -11,49 +11,44 @@ using namespace Seele;
using namespace Seele::Metal;
BufferAllocation::BufferAllocation(PGraphics graphics)
: CommandBoundResource(graphics)
{}
: CommandBoundResource(graphics) {}
BufferAllocation::~BufferAllocation()
{
if(buffer != nullptr)
{
BufferAllocation::~BufferAllocation() {
if (buffer != nullptr) {
buffer->release();
}
}
Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic, const std::string& name)
: graphics(graphics)
, dynamic(dynamic)
, name(name) {
Buffer::Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic,
const std::string &name)
: graphics(graphics), dynamic(dynamic), name(name) {
createBuffer(size, data);
}
Buffer::~Buffer() {
for (size_t i = 0; i < buffers.size(); ++i) {
//TODO
// TODO
}
}
void* Buffer::map(bool) { return getHandle()->contents(); }
void *Buffer::map(bool) { return getHandle()->contents(); }
void* Buffer::mapRegion(uint64 regionOffset, uint64, bool) { return (char*)getHandle()->contents() + regionOffset; }
void *Buffer::mapRegion(uint64 regionOffset, uint64, bool) {
return (char *)getHandle()->contents() + regionOffset;
}
void Buffer::unmap() {}
void Buffer::rotateBuffer(uint64 size)
{
void Buffer::rotateBuffer(uint64 size) {
size = std::max(getSize(), size);
for(size_t i = 0; i < buffers.size(); ++i)
{
if(buffers[i]->isCurrentlyBound())
{
for (size_t i = 0; i < buffers.size(); ++i) {
if (buffers[i]->isCurrentlyBound()) {
continue;
}
if(buffers[i]->size < size)
{
if (buffers[i]->size < size) {
buffers[i]->buffer->release();
buffers[i]->buffer = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
buffers[i]->buffer =
graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
buffers[i]->size = size;
}
currentBuffer = i;
@@ -63,79 +58,106 @@ void Buffer::rotateBuffer(uint64 size)
currentBuffer = buffers.size() - 1;
}
void Buffer::createBuffer(uint64 size, void* data)
{
void Buffer::createBuffer(uint64 size, void *data) {
buffers.add(new BufferAllocation(graphics));
if (data != nullptr) {
buffers.back()->buffer = graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared);
buffers.back()->buffer =
graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared);
} else {
buffers.back()->buffer = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
buffers.back()->buffer =
graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
}
buffers.back()->buffer->setLabel(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
buffers.back()->buffer->setLabel(
NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
}
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize,
createInfo.sourceData.owner),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false, createInfo.name) {}
VertexBuffer::VertexBuffer(PGraphics graphics,
const VertexBufferCreateInfo &createInfo)
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices,
createInfo.vertexSize, createInfo.sourceData.owner),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size,
createInfo.sourceData.data, false, createInfo.name) {
}
VertexBuffer::~VertexBuffer() {}
void VertexBuffer::updateRegion(DataSource update) {
void* data = getHandle()->contents();
std::memcpy((char*)data + update.offset, update.data, update.size);
void *data = getHandle()->contents();
std::memcpy((char *)data + update.offset, update.data, update.size);
}
void VertexBuffer::download(Array<uint8>& buffer) {
void* data = getHandle()->contents();
void VertexBuffer::download(Array<uint8> &buffer) {
void *data = getHandle()->contents();
buffer.resize(getSize());
std::memcpy(buffer.data(), data, getSize());
}
void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {
void VertexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
currentOwner = newOwner;
}
IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo)
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo.sourceData.size, createInfo.indexType,
createInfo.sourceData.owner),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false, createInfo.name) {}
void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {}
IndexBuffer::IndexBuffer(PGraphics graphics,
const IndexBufferCreateInfo &createInfo)
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo.sourceData.size,
createInfo.indexType, createInfo.sourceData.owner),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size,
createInfo.sourceData.data, false, createInfo.name) {
}
IndexBuffer::~IndexBuffer() {}
void IndexBuffer::download(Array<uint8>& buffer) {
void* data = getHandle()->contents();
void IndexBuffer::download(Array<uint8> &buffer) {
void *data = getHandle()->contents();
buffer.resize(getSize());
std::memcpy(buffer.data(), data, getSize());
}
void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
void IndexBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
currentOwner = newOwner;
}
void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {}
UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo)
UniformBuffer::UniformBuffer(PGraphics graphics,
const UniformBufferCreateInfo &createInfo)
: Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo.sourceData),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic, createInfo.name) {}
Seele::Metal::Buffer(graphics, createInfo.sourceData.size,
createInfo.sourceData.data, createInfo.dynamic,
createInfo.name) {}
UniformBuffer::~UniformBuffer() {}
bool UniformBuffer::updateContents(const DataSource& sourceData) {
void* data = getHandle()->contents();
std::memcpy((char*)data + sourceData.offset, sourceData.data, sourceData.size);
bool UniformBuffer::updateContents(const DataSource &sourceData) {
void *data = getHandle()->contents();
std::memcpy((char *)data + sourceData.offset, sourceData.data,
sourceData.size);
return true;
}
void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
currentOwner = newOwner;
}
void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
}
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo.numElements, createInfo.sourceData),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic, createInfo.name) {}
ShaderBuffer::ShaderBuffer(PGraphics graphics,
const ShaderBufferCreateInfo &createInfo)
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo.numElements,
createInfo.sourceData),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size,
createInfo.sourceData.data, createInfo.dynamic,
createInfo.name) {}
ShaderBuffer::~ShaderBuffer() {}
@@ -143,29 +165,28 @@ void ShaderBuffer::rotateBuffer(uint64 size) {
Metal::Buffer::rotateBuffer(size);
}
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo& createInfo) {
void ShaderBuffer::updateContents(const ShaderBufferCreateInfo &createInfo) {
Gfx::ShaderBuffer::updateContents(createInfo);
if(createInfo.sourceData.data == nullptr)
{
if (createInfo.sourceData.data == nullptr) {
return;
}
void* data = map();
std::memcpy((char*)data + createInfo.sourceData.offset, createInfo.sourceData.data, createInfo.sourceData.size);
void *data = map();
std::memcpy((char *)data + createInfo.sourceData.offset,
createInfo.sourceData.data, createInfo.sourceData.size);
unmap();
}
void* ShaderBuffer::mapRegion(uint64 offset, uint64 size, bool writeOnly)
{
void *ShaderBuffer::mapRegion(uint64 offset, uint64 size, bool writeOnly) {
return Metal::Buffer::mapRegion(offset, size, writeOnly);
}
void ShaderBuffer::unmap()
{
Metal::Buffer::unmap();
void ShaderBuffer::unmap() { Metal::Buffer::unmap(); }
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) {
currentOwner = newOwner;
}
void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {}
+82 -86
View File
@@ -19,113 +19,109 @@ DECLARE_REF(IndexBuffer)
DECLARE_REF(GraphicsPipeline)
DECLARE_REF(ComputePipeline)
class Command {
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();
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;
}
return blitEncoder;
}
PEvent getCompletedEvent() const { return completed; }
constexpr MTL::CommandBuffer* getHandle() const { return cmdBuffer; }
PEvent getCompletedEvent() const { return completed; }
constexpr MTL::CommandBuffer* getHandle() const { return cmdBuffer; }
private:
PGraphics graphics;
OEvent completed;
MTL::CommandBuffer* cmdBuffer;
MTL::ParallelRenderCommandEncoder* parallelEncoder = nullptr;
MTL::BlitCommandEncoder* blitEncoder = nullptr;
private:
PGraphics graphics;
OEvent completed;
MTL::CommandBuffer* cmdBuffer;
MTL::ParallelRenderCommandEncoder* parallelEncoder = nullptr;
MTL::BlitCommandEncoder* blitEncoder = nullptr;
};
DEFINE_REF(Command)
class RenderCommand : public Gfx::RenderCommand {
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;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
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;
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;
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;
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
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;
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;
private:
private:
PGraphicsPipeline boundPipeline;
PIndexBuffer boundIndexBuffer;
MTL::Buffer* argumentBuffer;
MTL::RenderCommandEncoder* encoder;
std::string name;
MTL::RenderCommandEncoder* encoder;
std::string name;
};
DEFINE_REF(RenderCommand)
class ComputeCommand : public Gfx::ComputeCommand {
public:
ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name);
virtual ~ComputeCommand();
void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size,
const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
public:
ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name);
virtual ~ComputeCommand();
void end();
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
private:
PComputePipeline boundPipeline;
MTL::CommandBuffer* commandBuffer;
MTL::ComputeCommandEncoder* encoder;
private:
PComputePipeline boundPipeline;
MTL::CommandBuffer* commandBuffer;
MTL::ComputeCommandEncoder* encoder;
MTL::Buffer* argumentBuffer;
std::string name;
std::string name;
};
DEFINE_REF(ComputeCommand)
class CommandQueue {
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);
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);
private:
PGraphics graphics;
MTL::CommandQueue* queue;
OCommand activeCommand;
Array<OCommand> pendingCommands;
private:
PGraphics graphics;
MTL::CommandQueue* queue;
OCommand activeCommand;
Array<OCommand> pendingCommands;
};
class IOCommandQueue {
public:
IOCommandQueue(PGraphics graphics);
~IOCommandQueue();
constexpr MTL::IOCommandQueue* getHandle() { return queue; }
PCommand getCommands() { return activeCommand; } // TODO
void submitCommands(PEvent signal = nullptr);
public:
IOCommandQueue(PGraphics graphics);
~IOCommandQueue();
constexpr MTL::IOCommandQueue* getHandle() { return queue; }
PCommand getCommands() { return activeCommand; } // TODO
void submitCommands(PEvent signal = nullptr);
private:
PGraphics graphics;
MTL::IOCommandQueue* queue;
OCommand activeCommand;
private:
PGraphics graphics;
MTL::IOCommandQueue* queue;
OCommand activeCommand;
};
DEFINE_REF(IOCommandQueue)
} // namespace Metal
+93 -56
View File
@@ -16,8 +16,9 @@
using namespace Seele;
using namespace Seele::Metal;
Command::Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer)
: graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) {}
Command::Command(PGraphics graphics, MTL::CommandBuffer *cmdBuffer)
: graphics(graphics), completed(new Event(graphics)), cmdBuffer(cmdBuffer) {
}
Command::~Command() {}
@@ -27,7 +28,8 @@ void Command::beginRenderPass(PRenderPass renderPass) {
blitEncoder = nullptr;
}
renderPass->updateRenderPass();
parallelEncoder = cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
parallelEncoder =
cmdBuffer->parallelRenderCommandEncoder(renderPass->getDescriptor());
}
void Command::endRenderPass() {
@@ -35,7 +37,9 @@ void Command::endRenderPass() {
parallelEncoder = nullptr;
}
void Command::present(MTL::Drawable* drawable) { cmdBuffer->presentDrawable(drawable); }
void Command::present(MTL::Drawable *drawable) {
cmdBuffer->presentDrawable(drawable);
}
void Command::end(PEvent signal) {
assert(!parallelEncoder);
@@ -49,11 +53,16 @@ void Command::end(PEvent signal) {
void Command::waitDeviceIdle() { cmdBuffer->waitUntilCompleted(); }
void Command::signalEvent(PEvent event) { cmdBuffer->encodeSignalEvent(event->getHandle(), 1); }
void Command::signalEvent(PEvent event) {
cmdBuffer->encodeSignalEvent(event->getHandle(), 1);
}
void Command::waitForEvent(PEvent event) { cmdBuffer->encodeWait(event->getHandle(), 1); }
void Command::waitForEvent(PEvent event) {
cmdBuffer->encodeWait(event->getHandle(), 1);
}
RenderCommand::RenderCommand(MTL::RenderCommandEncoder* encoder, const std::string& name)
RenderCommand::RenderCommand(MTL::RenderCommandEncoder *encoder,
const std::string &name)
: encoder(encoder), name(name) {}
RenderCommand::~RenderCommand() {}
@@ -79,15 +88,19 @@ void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
for (auto [_, layout] : boundPipeline->getPipelineLayout()->getLayouts()) {
argBufferSize += 3 * sizeof(uint64) * layout->getBindings().size();
}
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(argBufferSize, MTL::ResourceStorageModeShared);
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(
argBufferSize, MTL::ResourceStorageModeShared);
argumentBuffer->setLabel(
NS::String::string(boundPipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
NS::String::string(boundPipeline->getPipelineLayout()->getName().c_str(),
NS::ASCIIStringEncoding));
}
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> offsets) {
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet,
Array<uint32> offsets) {
auto metalSet = descriptorSet.cast<DescriptorSet>();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(
descriptorSet->getLayout()->getName());
uint64 *topLevelTable = (uint64 *)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
auto bindings = metalSet->getLayout()->getBindings();
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
@@ -117,15 +130,17 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint
}
}
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> offsets) {
void RenderCommand::bindDescriptor(
const Array<Gfx::PDescriptorSet> &descriptorSets, Array<uint32> offsets) {
for (auto set : descriptorSets) {
bindDescriptor(set, offsets);
}
}
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) {
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer> &buffers) {
uint32 i = 0;
for (auto buffer : buffers) {
encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++);
encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0,
METAL_VERTEXBUFFER_OFFSET + i++);
}
}
@@ -133,24 +148,29 @@ void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) {
boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>();
}
void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size,
const void* data) {
void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset,
uint32 size, const void *data) {
if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) {
encoder->setVertexBytes((char*)data + offset, size, 0);
encoder->setVertexBytes((char *)data + offset, size, 0);
}
if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) {
encoder->setFragmentBytes((char*)data + offset, size, 0);
encoder->setFragmentBytes((char *)data + offset, size, 0);
}
}
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) {
encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, vertexCount, instanceCount, firstInstance);
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount,
int32 firstVertex, uint32 firstInstance) {
encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex,
vertexCount, instanceCount, firstInstance);
}
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset,
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount,
int32 firstIndex, uint32 vertexOffset,
uint32 firstInstance) {
encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, cast(boundIndexBuffer->getIndexType()),
boundIndexBuffer->getHandle(), firstIndex, instanceCount, vertexOffset, firstInstance);
encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount,
cast(boundIndexBuffer->getIndexType()),
boundIndexBuffer->getHandle(), firstIndex,
instanceCount, vertexOffset, firstInstance);
}
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
@@ -159,15 +179,19 @@ void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
encoder->setFragmentBuffer(argumentBuffer, 0, 2);
encoder->setMeshBuffer(argumentBuffer, 0, 2);
encoder->setObjectBuffer(argumentBuffer, 0, 2);
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ),
MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
}
void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) {
//encoder->drawMeshThreadgroups()
void RenderCommand::drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset,
uint32 drawCount, uint32 stride) {
// encoder->drawMeshThreadgroups()
}
ComputeCommand::ComputeCommand(MTL::CommandBuffer* cmdBuffer, const std::string& name)
: commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()), name(name) {}
ComputeCommand::ComputeCommand(MTL::CommandBuffer *cmdBuffer,
const std::string &name)
: commandBuffer(cmdBuffer), encoder(cmdBuffer->computeCommandEncoder()),
name(name) {}
ComputeCommand::~ComputeCommand() {}
@@ -180,16 +204,21 @@ void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
boundPipeline = pipeline.cast<ComputePipeline>();
encoder->setComputePipelineState(boundPipeline->getHandle());
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(
sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared);
sizeof(uint64) *
(boundPipeline->getPipelineLayout()->getLayouts().size() + 1),
MTL::ResourceStorageModeShared);
argumentBuffer->setLabel(
NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
NS::String::string(pipeline->getPipelineLayout()->getName().c_str(),
NS::ASCIIStringEncoding));
}
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) {
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set,
Array<uint32> offsets) {
auto metalSet = set.cast<DescriptorSet>();
metalSet->bind();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(
set->getLayout()->getName());
uint64 *topLevelTable = (uint64 *)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
auto bindings = metalSet->getLayout()->getBindings();
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
@@ -219,42 +248,45 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offse
}
}
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> offsets) {
for (auto& set : sets) {
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet> &sets,
Array<uint32> offsets) {
for (auto &set : sets) {
bindDescriptor(set, offsets);
}
}
void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size,
const void* data) {
encoder->setBytes((char*)data + offset, size, 0);
void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset,
uint32 size, const void *data) {
encoder->setBytes((char *)data + offset, size, 0);
}
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
// TODO
encoder->setBuffer(argumentBuffer, 0, 2);
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ),
MTL::Size(32, 32, 1));
}
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue();
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
MTL::CommandBufferDescriptor *descriptor =
MTL::CommandBufferDescriptor::alloc()->init();
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
descriptor->release();
}
CommandQueue::~CommandQueue() { queue->release(); }
ORenderCommand CommandQueue::getRenderCommand(const std::string& name) {
ORenderCommand CommandQueue::getRenderCommand(const std::string &name) {
return new RenderCommand(activeCommand->createRenderEncoder(), name);
}
OComputeCommand CommandQueue::getComputeCommand(const std::string& name) {
OComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
return new ComputeCommand(queue->commandBuffer(), name);
}
void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) {
for (auto& command : commands) {
for (auto &command : commands) {
auto metalCmd = Gfx::PRenderCommand(command).cast<RenderCommand>();
metalCmd->end();
}
@@ -262,33 +294,38 @@ void CommandQueue::executeCommands(Array<Gfx::ORenderCommand> commands) {
void CommandQueue::executeCommands(Array<Gfx::OComputeCommand> commands) {
submitCommands();
for (auto& command : commands) {
for (auto &command : commands) {
auto metalCmd = Gfx::PComputeCommand(command).cast<ComputeCommand>();
metalCmd->end();
}
}
void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) {
for (auto it = pendingCommands.begin(); it != pendingCommands.end(); it++) {
if ((*it)->getHandle() == cmdBuffer) {
pendingCommands.remove(it);
return;
}
}
}));
activeCommand->getHandle()->addCompletedHandler(
MTL::CommandBufferHandler([&](MTL::CommandBuffer *cmdBuffer) {
for (auto it = pendingCommands.begin(); it != pendingCommands.end();
it++) {
if ((*it)->getHandle() == cmdBuffer) {
pendingCommands.remove(it);
return;
}
}
}));
activeCommand->end(signalSemaphore);
activeCommand->waitDeviceIdle();
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
pendingCommands.add(std::move(activeCommand));
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
MTL::CommandBufferDescriptor *descriptor =
MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(
MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
activeCommand->waitForEvent(prevCmdEvent);
}
IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
MTL::IOCommandQueueDescriptor* desc = MTL::IOCommandQueueDescriptor::alloc()->init();
MTL::IOCommandQueueDescriptor *desc =
MTL::IOCommandQueueDescriptor::alloc()->init();
desc->setType(MTL::IOCommandQueueTypeConcurrent);
desc->setPriority(MTL::IOPriorityNormal);
queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr);
+44 -50
View File
@@ -9,75 +9,69 @@ namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
class DescriptorLayout : public Gfx::DescriptorLayout {
public:
DescriptorLayout(PGraphics graphics, const std::string &name);
virtual ~DescriptorLayout();
virtual void create() override;
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
virtual ~DescriptorLayout();
virtual void create() override;
private:
PGraphics graphics;
private:
PGraphics graphics;
};
DEFINE_REF(DescriptorLayout)
DECLARE_REF(DescriptorSet)
class DescriptorPool : public Gfx::DescriptorPool {
public:
DescriptorPool(PGraphics graphics, PDescriptorLayout layout);
virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
virtual void reset() override;
constexpr PDescriptorLayout getLayout() const { return layout; }
public:
DescriptorPool(PGraphics graphics, PDescriptorLayout layout);
virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
virtual void reset() override;
constexpr PDescriptorLayout getLayout() const { return layout; }
private:
PGraphics graphics;
PDescriptorLayout layout;
Array<ODescriptorSet> allocatedSets;
private:
PGraphics graphics;
PDescriptorLayout layout;
Array<ODescriptorSet> allocatedSets;
};
DEFINE_REF(DescriptorPool)
class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void writeChanges() override;
virtual void updateBuffer(uint32_t binding,
Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture,
Gfx::PSampler sampler = nullptr) override;
virtual void updateTextureArray(uint32_t binding,
Array<Gfx::PTexture> texture) override;
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void writeChanges() override;
virtual void updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState) override;
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture) override;
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
constexpr void allocate() { currentlyInUse = true; }
constexpr void free() { currentlyInUse = false; }
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
constexpr void allocate() { currentlyInUse = true; }
constexpr void free() { currentlyInUse = false; }
constexpr MTL::Buffer *getBuffer() const { return buffer; }
constexpr const Array<MTL::Resource *> &getBoundResources() const {
return boundResources;
}
constexpr MTL::Buffer* getBuffer() const { return buffer; }
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
private:
PGraphics graphics;
PDescriptorPool owner;
MTL::Buffer *buffer = nullptr;
uint64 *argumentBuffer = nullptr;
Array<MTL::Resource *> boundResources;
bool currentlyInUse;
private:
PGraphics graphics;
PDescriptorPool owner;
MTL::Buffer* buffer = nullptr;
uint64* argumentBuffer = nullptr;
Array<MTL::Resource*> boundResources;
bool currentlyInUse;
};
DEFINE_REF(DescriptorSet)
class PipelineLayout : public Gfx::PipelineLayout {
public:
PipelineLayout(PGraphics graphics, const std::string &name,
Gfx::PPipelineLayout baseLayout);
virtual ~PipelineLayout();
virtual void create() override;
public:
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
virtual ~PipelineLayout();
virtual void create() override;
private:
PGraphics graphics;
private:
PGraphics graphics;
};
DEFINE_REF(PipelineLayout)
} // namespace Metal
+2 -5
View File
@@ -94,11 +94,8 @@ void DescriptorSet::updateBuffer(uint32_t binding,
boundResources[binding] = metalBuffer->getHandle();
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer)
{
}
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index,
Gfx::PShaderBuffer uniformBuffer) {}
void DescriptorSet::updateSampler(uint32_t binding,
Gfx::PSampler samplerState) {
+5 -7
View File
@@ -3,11 +3,9 @@
#include "Metal/MTLStageInputOutputDescriptor.hpp"
#include "Resources.h"
namespace Seele
{
namespace Metal
{
constexpr uint64 METAL_VERTEXBUFFER_OFFSET = 6;// something about metal vertex fetch
namespace Seele {
namespace Metal {
constexpr uint64 METAL_VERTEXBUFFER_OFFSET = 6; // something about metal vertex fetch
constexpr uint64 METAL_VERTEXATTRIBUTE_OFFSET = 11;
MTL::PixelFormat cast(Gfx::SeFormat format);
@@ -32,5 +30,5 @@ MTL::PrimitiveTopologyClass cast(Gfx::SePrimitiveTopology topology);
Gfx::SePrimitiveTopology cast(MTL::PrimitiveTopologyClass topology);
MTL::IndexType cast(Gfx::SeIndexType indexType);
Gfx::SeIndexType cast(MTL::IndexType indexType);
}
}
} // namespace Metal
} // namespace Seele
+2 -1
View File
@@ -767,7 +767,8 @@ Gfx::SeSamplerAddressMode Seele::Metal::cast(MTL::SamplerAddressMode mode) {
}
}
MTL::PrimitiveTopologyClass Seele::Metal::cast(Gfx::SePrimitiveTopology topology) {
MTL::PrimitiveTopologyClass
Seele::Metal::cast(Gfx::SePrimitiveTopology topology) {
switch (topology) {
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
return MTL::PrimitiveTopologyClassPoint;
+26 -26
View File
@@ -1,25 +1,24 @@
#pragma once
#include "Metal/Metal.hpp"
#include "Graphics/Graphics.h"
#include "Metal/Metal.hpp"
namespace Seele
{
namespace Metal
{
namespace Seele {
namespace Metal {
DECLARE_REF(CommandQueue)
DECLARE_REF(IOCommandQueue)
DECLARE_REF(PipelineCache)
class Graphics : public Gfx::Graphics
{
public:
class Graphics : public Gfx::Graphics {
public:
Graphics();
virtual ~Graphics();
virtual void init(GraphicsInitializer initializer) override;
virtual Gfx::OWindow createWindow(const WindowCreateInfo &createInfo) override;
virtual Gfx::OViewport createViewport(Gfx::PWindow owner, const ViewportCreateInfo &createInfo) override;
virtual Gfx::ORenderPass createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport renderArea) override;
virtual Gfx::OWindow createWindow(const WindowCreateInfo& createInfo) override;
virtual Gfx::OViewport createViewport(Gfx::PWindow owner, const ViewportCreateInfo& createInfo) override;
virtual Gfx::ORenderPass createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport renderArea) override;
virtual void beginRenderPass(Gfx::PRenderPass renderPass) override;
virtual void endRenderPass() override;
virtual void waitDeviceIdle() override;
@@ -27,17 +26,17 @@ public:
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;
virtual Gfx::OTextureCube createTextureCube(const TextureCreateInfo &createInfo) override;
virtual Gfx::OUniformBuffer createUniformBuffer(const UniformBufferCreateInfo &bulkData) override;
virtual Gfx::OShaderBuffer createShaderBuffer(const ShaderBufferCreateInfo &bulkData) override;
virtual Gfx::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo &bulkData) override;
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo &bulkData) override;
virtual Gfx::OTexture2D createTexture2D(const TextureCreateInfo& createInfo) override;
virtual Gfx::OTexture3D createTexture3D(const TextureCreateInfo& createInfo) override;
virtual Gfx::OTextureCube createTextureCube(const TextureCreateInfo& createInfo) override;
virtual Gfx::OUniformBuffer createUniformBuffer(const UniformBufferCreateInfo& bulkData) override;
virtual Gfx::OShaderBuffer createShaderBuffer(const ShaderBufferCreateInfo& bulkData) override;
virtual Gfx::OVertexBuffer createVertexBuffer(const VertexBufferCreateInfo& bulkData) override;
virtual Gfx::OIndexBuffer createIndexBuffer(const IndexBufferCreateInfo& bulkData) 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;
virtual Gfx::OComputeShader createComputeShader(const ShaderCreateInfo& createInfo) override;
@@ -48,22 +47,23 @@ public:
virtual Gfx::PComputePipeline createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) override;
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
virtual Gfx::OPipelineLayout createPipelineLayout(const std::string& name = "", Gfx::PPipelineLayout baseLayout = nullptr) override;
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
virtual Gfx::OPipelineLayout createPipelineLayout(const std::string& name = "", Gfx::PPipelineLayout baseLayout = nullptr) override;
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
MTL::Device* getDevice() const { return device; }
PCommandQueue getQueue() const { return queue; }
PIOCommandQueue getIOQueue() const { return ioQueue; }
protected:
protected:
MTL::Device* device;
OCommandQueue queue;
OIOCommandQueue ioQueue;
OPipelineCache cache;
};
DEFINE_REF(Graphics)
} // namespace Metal
} // namespace Metal
} // namespace Seele
+62 -83
View File
@@ -1,31 +1,25 @@
#include "Graphics.h"
#include "Buffer.h"
#include "Command.h"
#include "Graphics/Initializer.h"
#include "Graphics/Metal/Descriptor.h"
#include "Graphics/Metal/Pipeline.h"
#include "Graphics/Metal/PipelineCache.h"
#include "Graphics/Metal/Resources.h"
#include "Shader.h"
#include "RenderPass.h"
#include "Resources.h"
#include "Command.h"
#include "Shader.h"
#include "Window.h"
#include "Buffer.h"
using namespace Seele;
using namespace Seele::Metal;
Graphics::Graphics()
{
}
Graphics::Graphics() {}
Graphics::~Graphics()
{
}
Graphics::~Graphics() {}
void Graphics::init(GraphicsInitializer)
{
void Graphics::init(GraphicsInitializer) {
glfwInit();
device = MTL::CreateSystemDefaultDevice();
queue = new CommandQueue(this);
@@ -34,164 +28,149 @@ void Graphics::init(GraphicsInitializer)
meshShadingEnabled = false;
}
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo)
{
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) {
return new Window(this, createInfo);
}
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo &createInfo)
{
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner,
const ViewportCreateInfo &createInfo) {
return new Viewport(owner, createInfo);
}
Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport renderArea)
{
Gfx::ORenderPass
Graphics::createRenderPass(Gfx::RenderTargetLayout layout,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport renderArea) {
return new RenderPass(this, layout, dependencies, renderArea);
}
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass)
{
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
queue->getCommands()->beginRenderPass(renderPass.cast<RenderPass>());
}
void Graphics::endRenderPass()
{
queue->getCommands()->endRenderPass();
}
void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); }
void Graphics::waitDeviceIdle()
{
queue->getCommands()->waitDeviceIdle();
}
void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); }
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands)
{
queue->executeCommands(std::move(commands));
}
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands)
{
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) {
queue->executeCommands(std::move(commands));
}
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo)
{
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) {
queue->executeCommands(std::move(commands));
}
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &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);
}
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo &createInfo)
{
Gfx::OTextureCube
Graphics::createTextureCube(const TextureCreateInfo &createInfo) {
return new TextureCube(this, createInfo);
}
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData)
{
Gfx::OUniformBuffer
Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData) {
return new UniformBuffer(this, bulkData);
}
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData)
{
Gfx::OShaderBuffer
Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData) {
return new ShaderBuffer(this, bulkData);
}
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData)
{
Gfx::OVertexBuffer
Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData) {
return new VertexBuffer(this, bulkData);
}
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData)
{
Gfx::OIndexBuffer
Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData) {
return new IndexBuffer(this, bulkData);
}
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name)
{
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string &name) {
return queue->getRenderCommand(name);
}
Gfx::OComputeCommand 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) {
OVertexShader result = new VertexShader(this);
result->create(createInfo);
return result;
}
Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo)
{
Gfx::OFragmentShader
Graphics::createFragmentShader(const ShaderCreateInfo &createInfo) {
OFragmentShader result = new FragmentShader(this);
result->create(createInfo);
return result;
}
Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo)
{
Gfx::OComputeShader
Graphics::createComputeShader(const ShaderCreateInfo &createInfo) {
OComputeShader result = new ComputeShader(this);
result->create(createInfo);
return result;
}
Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo)
{
Gfx::OMeshShader
Graphics::createMeshShader(const ShaderCreateInfo &createInfo) {
OMeshShader result = new MeshShader(this);
result->create(createInfo);
return result;
}
Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo)
{
Gfx::OTaskShader
Graphics::createTaskShader(const ShaderCreateInfo &createInfo) {
OTaskShader result = new TaskShader(this);
result->create(createInfo);
return result;
}
Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo)
{
Gfx::PGraphicsPipeline
Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
}
Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo)
{
Gfx::PGraphicsPipeline
Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
}
Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo)
{
Gfx::PComputePipeline
Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
}
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo)
{
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo &createInfo) {
return new Sampler(this, createInfo);
}
Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
{
Gfx::ODescriptorLayout
Graphics::createDescriptorLayout(const std::string &name) {
return new DescriptorLayout(this, name);
}
Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout)
{
Gfx::OPipelineLayout
Graphics::createPipelineLayout(const std::string &name,
Gfx::PPipelineLayout baseLayout) {
return new PipelineLayout(this, name, baseLayout);
}
Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo)
{
Gfx::OVertexInput
Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) {
return new VertexInput(createInfo);
}
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination)
{
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {
}
+21 -19
View File
@@ -7,33 +7,35 @@
namespace Seele {
namespace Metal {
class VertexInput : public Gfx::VertexInput {
public:
VertexInput(VertexInputStateCreateInfo createInfo);
virtual ~VertexInput();
public:
VertexInput(VertexInputStateCreateInfo createInfo);
virtual ~VertexInput();
};
DECLARE_REF(PipelineLayout)
DECLARE_REF(Graphics)
class GraphicsPipeline : public Gfx::GraphicsPipeline {
public:
GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline, Gfx::PPipelineLayout createInfo);
virtual ~GraphicsPipeline();
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
PGraphics graphics;
MTL::RenderPipelineState* state;
MTL::PrimitiveType primitiveType;
private:
public:
GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline, Gfx::PPipelineLayout createInfo);
virtual ~GraphicsPipeline();
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
PGraphics graphics;
MTL::RenderPipelineState* state;
MTL::PrimitiveType primitiveType;
private:
};
DEFINE_REF(GraphicsPipeline)
class ComputePipeline : public Gfx::ComputePipeline {
public:
ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::PPipelineLayout);
virtual ~ComputePipeline();
constexpr MTL::ComputePipelineState* getHandle() const { return state; }
public:
ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::PPipelineLayout);
virtual ~ComputePipeline();
constexpr MTL::ComputePipelineState* getHandle() const { return state; }
PGraphics graphics;
private:
MTL::ComputePipelineState* state;
PGraphics graphics;
private:
MTL::ComputePipelineState* state;
};
DEFINE_REF(ComputePipeline)
} // namespace Metal
+9 -4
View File
@@ -7,17 +7,22 @@
using namespace Seele;
using namespace Seele::Metal;
VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) : Gfx::VertexInput(createInfo) {}
VertexInput::VertexInput(VertexInputStateCreateInfo createInfo)
: Gfx::VertexInput(createInfo) {}
VertexInput::~VertexInput() {}
GraphicsPipeline::GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline,
GraphicsPipeline::GraphicsPipeline(PGraphics graphics,
MTL::PrimitiveType primitive,
MTL::RenderPipelineState *pipeline,
Gfx::PPipelineLayout layout)
: Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), primitiveType(primitive) {}
: Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline),
primitiveType(primitive) {}
GraphicsPipeline::~GraphicsPipeline() {}
ComputePipeline::ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline,
ComputePipeline::ComputePipeline(PGraphics graphics,
MTL::ComputePipelineState *pipeline,
Gfx::PPipelineLayout layout)
: Gfx::ComputePipeline(layout), graphics(graphics), state(pipeline) {}
+15 -15
View File
@@ -4,20 +4,20 @@
namespace Seele {
namespace Metal {
class PipelineCache
{
public:
PipelineCache(PGraphics graphics, const std::string& cacheFilePath);
~PipelineCache();
PGraphicsPipeline createPipeline(Gfx::LegacyPipelineCreateInfo createInfo);
PGraphicsPipeline createPipeline(Gfx::MeshPipelineCreateInfo createInfo);
PComputePipeline createPipeline(Gfx::ComputePipelineCreateInfo createInfo);
private:
PGraphics graphics;
Map<uint32, OGraphicsPipeline> graphicsPipelines;
Map<uint32, OComputePipeline> computePipelines;
std::string cacheFile;
class PipelineCache {
public:
PipelineCache(PGraphics graphics, const std::string& cacheFilePath);
~PipelineCache();
PGraphicsPipeline createPipeline(Gfx::LegacyPipelineCreateInfo createInfo);
PGraphicsPipeline createPipeline(Gfx::MeshPipelineCreateInfo createInfo);
PComputePipeline createPipeline(Gfx::ComputePipelineCreateInfo createInfo);
private:
PGraphics graphics;
Map<uint32, OGraphicsPipeline> graphicsPipelines;
Map<uint32, OComputePipeline> computePipelines;
std::string cacheFile;
};
DEFINE_REF(PipelineCache)
}
}
} // namespace Metal
} // namespace Seele
+75 -38
View File
@@ -19,22 +19,30 @@
using namespace Seele;
using namespace Seele::Metal;
PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : graphics(graphics), cacheFile(name) {}
PipelineCache::PipelineCache(PGraphics graphics, const std::string &name)
: graphics(graphics), cacheFile(name) {}
PipelineCache::~PipelineCache() {}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
PGraphicsPipeline
PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PPipelineLayout layout =
Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
MTL::RenderPipelineDescriptor *pipelineDescriptor =
MTL::RenderPipelineDescriptor::alloc()->init();
MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes()->init();
MTL::VertexDescriptor *vertexDescriptor =
pipelineDescriptor->vertexDescriptor()->init();
MTL::VertexAttributeDescriptorArray *attributes =
vertexDescriptor->attributes()->init();
if (createInfo.vertexInput != nullptr) {
const auto& vertexInfo = createInfo.vertexInput->getInfo();
const auto &vertexInfo = createInfo.vertexInput->getInfo();
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
MTL::VertexAttributeDescriptor* attribute = attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init();
attribute->setBufferIndex(vertexInfo.attributes[attr].binding + METAL_VERTEXBUFFER_OFFSET);
MTL::VertexAttributeDescriptor *attribute =
attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init();
attribute->setBufferIndex(vertexInfo.attributes[attr].binding +
METAL_VERTEXBUFFER_OFFSET);
switch (vertexInfo.attributes[attr].format) {
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
attribute->setFormat(MTL::VertexFormatFloat3);
@@ -45,9 +53,11 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
attribute->setOffset(vertexInfo.attributes[attr].offset);
}
MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts()->init();
MTL::VertexBufferLayoutDescriptorArray *bufferLayout =
vertexDescriptor->layouts()->init();
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
MTL::VertexBufferLayoutDescriptor* buffer = bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init();
MTL::VertexBufferLayoutDescriptor *buffer =
bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init();
buffer->setStride(vertexInfo.bindings[binding].stride);
buffer->setStepRate(1);
switch (vertexInfo.bindings[binding].inputRate) {
@@ -62,19 +72,28 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
}
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast<VertexShader>()->getFunction());
pipelineDescriptor->setVertexFunction(
createInfo.vertexShader.cast<VertexShader>()->getFunction());
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
pipelineDescriptor->setFragmentFunction(
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
cast(createInfo.renderPass->getLayout()
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setAlphaToCoverageEnabled(
createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
pipelineDescriptor->setRasterizationEnabled(
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash();
@@ -117,12 +136,14 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
type = MTL::PrimitiveTypeTriangle;
break;
}
NS::Error* error;
graphicsPipelines[hash] =
new GraphicsPipeline(graphics, type, graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error),
std::move(createInfo.pipelineLayout));
NS::Error *error;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, type,
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error),
std::move(createInfo.pipelineLayout));
if (error) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
<< std::endl;
assert(false);
}
@@ -130,51 +151,67 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
return graphicsPipelines[hash];
}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
PGraphicsPipeline
PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
MTL::MeshRenderPipelineDescriptor *pipelineDescriptor =
MTL::MeshRenderPipelineDescriptor::alloc()->init();
pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
pipelineDescriptor->setMeshFunction(
createInfo.meshShader.cast<MeshShader>()->getFunction());
if (createInfo.taskShader != nullptr) {
pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast<TaskShader>()->getFunction());
pipelineDescriptor->setObjectFunction(
createInfo.taskShader.cast<TaskShader>()->getFunction());
}
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
pipelineDescriptor->setFragmentFunction(
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
cast(createInfo.renderPass->getLayout()
.depthAttachment.getTexture()
.cast<Texture2D>()
->getFormat()));
}
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setAlphaToCoverageEnabled(
createInfo.multisampleState.alphaCoverageEnable);
pipelineDescriptor->setAlphaToOneEnabled(
createInfo.multisampleState.alphaToOneEnable);
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
pipelineDescriptor->setRasterizationEnabled(
!createInfo.rasterizationState.rasterizerDiscardEnable);
uint32 hash = pipelineDescriptor->hash();
if (graphicsPipelines.contains(hash)) {
return graphicsPipelines[hash];
}
NS::Error* error = nullptr;
NS::Error *error = nullptr;
MTL::AutoreleasedRenderPipelineReflection reflection;
graphicsPipelines[hash] = new GraphicsPipeline(
graphics, MTL::PrimitiveTypeTriangle,
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
graphics->getDevice()->newRenderPipelineState(
pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
std::move(createInfo.pipelineLayout));
pipelineDescriptor->release();
return graphicsPipelines[hash];
}
PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PComputePipeline
PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
uint32 hash = shader->getShaderHash();
if (computePipelines.contains(hash)) {
return computePipelines[hash];
}
NS::Error* error;
NS::Error *error;
computePipelines[hash] =
new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error),
new ComputePipeline(graphics,
graphics->getDevice()->newComputePipelineState(
shader->getFunction(), &error),
std::move(createInfo.pipelineLayout));
assert(!error);
return computePipelines[hash];
+7 -12
View File
@@ -2,22 +2,17 @@
#include "Graphics/RenderTarget.h"
#include "Resources.h"
namespace Seele
{
namespace Metal
{
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
class RenderPass : public Gfx::RenderPass
{
public:
class RenderPass : public Gfx::RenderPass {
public:
RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies, Gfx::PViewport viewport);
virtual ~RenderPass();
void updateRenderPass();
MTL::RenderPassDescriptor* getDescriptor() const
{
return renderPass;
}
private:
MTL::RenderPassDescriptor* getDescriptor() const { return renderPass; }
private:
PGraphics graphics;
Gfx::PViewport viewport;
MTL::RenderPassDescriptor* renderPass;
+19 -11
View File
@@ -7,9 +7,11 @@
using namespace Seele;
using namespace Seele::Metal;
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport viewport)
: Gfx::RenderPass(layout, dependencies), graphics(graphics), viewport(viewport) {
: Gfx::RenderPass(layout, dependencies), graphics(graphics),
viewport(viewport) {
renderPass = MTL::RenderPassDescriptor::renderPassDescriptor();
renderPass->setRenderTargetArrayLength(1);
renderPass->setRenderTargetWidth(viewport->getWidth());
@@ -17,18 +19,21 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array
renderPass->setDefaultRasterSampleCount(viewport->getSamples());
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
const auto& color = layout.colorAttachments[i];
MTL::RenderPassColorAttachmentDescriptor* desc = renderPass->colorAttachments()->object(i);
desc->setClearColor(MTL::ClearColor(color.clear.color.float32[0], color.clear.color.float32[1],
color.clear.color.float32[2], color.clear.color.float32[3]));
const auto &color = layout.colorAttachments[i];
MTL::RenderPassColorAttachmentDescriptor *desc =
renderPass->colorAttachments()->object(i);
desc->setClearColor(MTL::ClearColor(
color.clear.color.float32[0], color.clear.color.float32[1],
color.clear.color.float32[2], color.clear.color.float32[3]));
desc->setLoadAction(cast(color.getLoadOp()));
desc->setStoreAction(cast(color.getStoreOp()));
desc->setLevel(0);
if (!layout.resolveAttachments.empty()) {
const auto& resolve = layout.resolveAttachments[i];
const auto &resolve = layout.resolveAttachments[i];
desc->setResolveLevel(0);
desc->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
desc->setResolveTexture(resolve.getTexture().cast<TextureBase>()->getTexture());
desc->setResolveTexture(
resolve.getTexture().cast<TextureBase>()->getTexture());
}
}
if (layout.depthAttachment.getTexture() != nullptr) {
@@ -38,7 +43,9 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array
depth->setStoreAction(cast(layout.depthAttachment.getStoreOp()));
if (layout.depthResolveAttachment.getTexture() != nullptr) {
depth->setResolveTexture(layout.depthResolveAttachment.getTexture().cast<TextureBase>()->getTexture());
depth->setResolveTexture(layout.depthResolveAttachment.getTexture()
.cast<TextureBase>()
->getTexture());
depth->setStoreAction(MTL::StoreActionStoreAndMultisampleResolve);
}
}
@@ -48,12 +55,13 @@ RenderPass::~RenderPass() {}
void RenderPass::updateRenderPass() {
for (size_t i = 0; i < layout.colorAttachments.size(); ++i) {
const auto& color = layout.colorAttachments[i];
const auto &color = layout.colorAttachments[i];
auto desc = renderPass->colorAttachments()->object(i);
desc->setTexture(color.getTexture().cast<TextureBase>()->getTexture());
}
if (layout.depthAttachment.getTexture() != nullptr) {
auto depth = renderPass->depthAttachment();
depth->setTexture(layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
depth->setTexture(
layout.depthAttachment.getTexture().cast<TextureBase>()->getTexture());
}
}
+26 -33
View File
@@ -10,58 +10,51 @@
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics);
class CommandBoundResource
{
public:
CommandBoundResource(PGraphics graphics)
: graphics(graphics)
{
}
virtual ~CommandBoundResource()
{
class CommandBoundResource {
public:
CommandBoundResource(PGraphics graphics) : graphics(graphics) {}
virtual ~CommandBoundResource() {
if (isCurrentlyBound())
abort();
}
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
constexpr void bind() { bindCount++; }
constexpr void unbind() { bindCount--; }
protected:
protected:
PGraphics graphics;
uint64 bindCount = 0;
};
DEFINE_REF(CommandBoundResource)
class Fence {
public:
Fence(PGraphics graphics);
~Fence();
MTL::Fence *getHandle() const { return handle; }
public:
Fence(PGraphics graphics);
~Fence();
MTL::Fence* getHandle() const { return handle; }
private:
MTL::Fence *handle;
private:
MTL::Fence* handle;
};
DEFINE_REF(Fence);
class Event {
public:
Event(PGraphics graphics);
~Event();
MTL::Event *getHandle() const { return handle; }
public:
Event(PGraphics graphics);
~Event();
MTL::Event* getHandle() const { return handle; }
private:
MTL::Event *handle;
private:
MTL::Event* handle;
};
DEFINE_REF(Event)
class Sampler : public Gfx::Sampler
{
public:
Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo);
virtual ~Sampler();
MTL::SamplerState* getHandle() const
{
return sampler;
}
private:
MTL::SamplerState* sampler;
class Sampler : public Gfx::Sampler {
public:
Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo);
virtual ~Sampler();
MTL::SamplerState* getHandle() const { return sampler; }
private:
MTL::SamplerState* sampler;
};
DEFINE_REF(Sampler)
} // namespace Metal
+5 -8
View File
@@ -1,7 +1,8 @@
#include "Resources.h"
#include "Enums.h"
#include "Graphics.h"
#include "Metal/MTLSampler.hpp"
#include "Enums.h"
using namespace Seele;
using namespace Seele::Metal;
@@ -14,9 +15,8 @@ Event::Event(PGraphics graphics) : handle(graphics->getDevice()->newEvent()) {}
Event::~Event() { handle->release(); }
Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo)
{
MTL::SamplerDescriptor* desc = MTL::SamplerDescriptor::alloc()->init();
Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo &createInfo) {
MTL::SamplerDescriptor *desc = MTL::SamplerDescriptor::alloc()->init();
desc->setBorderColor(cast(createInfo.borderColor));
desc->setCompareFunction(cast(createInfo.compareOp));
desc->setLodAverage(createInfo.mipLodBias);
@@ -35,7 +35,4 @@ Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo)
desc->release();
}
Sampler::~Sampler()
{
sampler->release();
}
Sampler::~Sampler() { sampler->release(); }
+19 -19
View File
@@ -7,32 +7,32 @@ namespace Seele {
namespace Metal {
class Shader {
public:
Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage);
virtual ~Shader();
public:
Shader(PGraphics graphics, Gfx::SeShaderStageFlags stage);
virtual ~Shader();
void create(const ShaderCreateInfo &createInfo);
void create(const ShaderCreateInfo& createInfo);
constexpr MTL::Function *getFunction() const { return function; }
constexpr const char *getEntryPointName() const {
// SLang renames all entry points to main, so we dont need that
return "main"; // entryPointName.c_str();
}
uint32 getShaderHash() const;
constexpr MTL::Function* getFunction() const { return function; }
constexpr const char* getEntryPointName() const {
// SLang renames all entry points to main, so we dont need that
return "main"; // entryPointName.c_str();
}
uint32 getShaderHash() const;
private:
Gfx::SeShaderStageFlags stage;
PGraphics graphics;
MTL::Library* library;
MTL::Function *function;
uint32 hash;
private:
Gfx::SeShaderStageFlags stage;
PGraphics graphics;
MTL::Library* library;
MTL::Function* function;
uint32 hash;
};
DEFINE_REF(Shader)
template <typename Base, Gfx::SeShaderStageFlags flags> class ShaderBase : public Base, public Shader {
public:
ShaderBase(PGraphics graphics) : Shader(graphics, flags) {}
virtual ~ShaderBase() {}
public:
ShaderBase(PGraphics graphics) : Shader(graphics, flags) {}
virtual ~ShaderBase() {}
};
using VertexShader = ShaderBase<Gfx::VertexShader, Gfx::SE_SHADER_STAGE_VERTEX_BIT>;
using FragmentShader = ShaderBase<Gfx::FragmentShader, Gfx::SE_SHADER_STAGE_FRAGMENT_BIT>;
+3 -3
View File
@@ -29,7 +29,7 @@ void Shader::create(const ShaderCreateInfo &createInfo) {
Map<std::string, uint32> paramMapping;
Slang::ComPtr<slang::IBlob> kernelBlob =
generateShader(createInfo, SLANG_METAL, paramMapping);
std::cout << (char*)kernelBlob->getBufferPointer() << std::endl;
std::cout << (char *)kernelBlob->getBufferPointer() << std::endl;
hash = CRC::Calculate(kernelBlob->getBufferPointer(),
kernelBlob->getBufferSize(), CRC::CRC_32());
NS::Error *error;
@@ -43,8 +43,8 @@ void Shader::create(const ShaderCreateInfo &createInfo) {
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
<< std::endl;
}
function =
library->newFunction(NS::String::string(createInfo.entryPoint.c_str(), NS::ASCIIStringEncoding));
function = library->newFunction(NS::String::string(
createInfo.entryPoint.c_str(), NS::ASCIIStringEncoding));
if (!function) {
assert(false);
}
+65 -154
View File
@@ -1,62 +1,33 @@
#pragma once
#include "Graphics/Texture.h"
#include "Graphics.h"
#include "Graphics/Texture.h"
namespace Seele
{
namespace Metal
{
class TextureBase
{
public:
TextureBase(PGraphics graphics, MTL::TextureType type, const TextureCreateInfo& createInfo, Gfx::QueueType& owner, MTL::Texture* existingImage = nullptr);
namespace Seele {
namespace Metal {
class TextureBase {
public:
TextureBase(PGraphics graphics, MTL::TextureType type, const TextureCreateInfo& createInfo, Gfx::QueueType& owner,
MTL::Texture* existingImage = nullptr);
virtual ~TextureBase();
uint32 getWidth() const
{
return width;
}
uint32 getHeight() const
{
return height;
}
uint32 getDepth() const
{
return depth;
}
constexpr MTL::Texture* getTexture() const
{
return texture;
}
constexpr Gfx::SeImageLayout getLayout() const
{
return layout;
}
void setLayout(Gfx::SeImageLayout val)
{
layout = val;
}
constexpr Gfx::SeFormat getFormat() const
{
return format;
}
constexpr Gfx::SeSampleCountFlags getNumSamples() const
{
return samples;
}
constexpr uint32 getMipLevels() const
{
return mipLevels;
}
uint32 getWidth() const { return width; }
uint32 getHeight() const { return height; }
uint32 getDepth() const { return depth; }
constexpr MTL::Texture* getTexture() const { return texture; }
constexpr Gfx::SeImageLayout getLayout() const { return layout; }
void setLayout(Gfx::SeImageLayout val) { layout = val; }
constexpr Gfx::SeFormat getFormat() const { return format; }
constexpr Gfx::SeSampleCountFlags getNumSamples() const { return samples; }
constexpr uint32 getMipLevels() const { return mipLevels; }
void executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwner = newOwner; }
void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage);
void changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage);
void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage);
void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage);
void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer);
protected:
//Updates via reference
protected:
// Updates via reference
Gfx::QueueType& currentOwner;
PGraphics graphics;
uint32 width;
@@ -75,128 +46,68 @@ protected:
friend class Graphics;
};
DEFINE_REF(TextureBase)
class Texture2D : public Gfx::Texture2D, public TextureBase
{
public:
class Texture2D : public Gfx::Texture2D, public TextureBase {
public:
Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, MTL::Texture* exisitingTexture = nullptr);
virtual ~Texture2D();
virtual uint32 getWidth() const override
{
return width;
}
virtual uint32 getHeight() const override
{
return height;
}
virtual uint32 getDepth() const override
{
return depth;
}
virtual Gfx::SeFormat getFormat() const override
{
return format;
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
return samples;
}
virtual uint32 getMipLevels() const override
{
return mipLevels;
}
virtual void changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual uint32 getWidth() const override { return width; }
virtual uint32 getHeight() const override { return height; }
virtual uint32 getDepth() const override { return depth; }
virtual Gfx::SeFormat getFormat() const override { return format; }
virtual Gfx::SeSampleCountFlags getNumSamples() const override { return samples; }
virtual uint32 getMipLevels() const override { return mipLevels; }
virtual void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
protected:
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(Texture2D)
class Texture3D : public Gfx::Texture3D, public TextureBase
{
public:
class Texture3D : public Gfx::Texture3D, public TextureBase {
public:
Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo);
virtual ~Texture3D();
virtual uint32 getWidth() const override
{
return width;
}
virtual uint32 getHeight() const override
{
return height;
}
virtual uint32 getDepth() const override
{
return depth;
}
virtual Gfx::SeFormat getFormat() const override
{
return format;
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
return samples;
}
virtual uint32 getMipLevels() const override
{
return mipLevels;
}
virtual void changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual uint32 getWidth() const override { return width; }
virtual uint32 getHeight() const override { return height; }
virtual uint32 getDepth() const override { return depth; }
virtual Gfx::SeFormat getFormat() const override { return format; }
virtual Gfx::SeSampleCountFlags getNumSamples() const override { return samples; }
virtual uint32 getMipLevels() const override { return mipLevels; }
virtual void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
protected:
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(Texture3D)
class TextureCube : public Gfx::TextureCube, TextureBase
{
public:
class TextureCube : public Gfx::TextureCube, TextureBase {
public:
TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo);
virtual ~TextureCube();
virtual uint32 getWidth() const override
{
return width;
}
virtual uint32 getHeight() const override
{
return height;
}
virtual uint32 getDepth() const override
{
return depth;
}
virtual Gfx::SeFormat getFormat() const override
{
return format;
}
virtual Gfx::SeSampleCountFlags getNumSamples() const override
{
return samples;
}
virtual uint32 getMipLevels() const override
{
return mipLevels;
}
virtual void changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual uint32 getWidth() const override { return width; }
virtual uint32 getHeight() const override { return height; }
virtual uint32 getDepth() const override { return depth; }
virtual Gfx::SeFormat getFormat() const override { return format; }
virtual Gfx::SeSampleCountFlags getNumSamples() const override { return samples; }
virtual uint32 getMipLevels() const override { return mipLevels; }
virtual void changeLayout(Gfx::SeImageLayout newLayout, Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer) override;
protected:
protected:
// Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override;
};
DEFINE_REF(TextureCube)
}
}
} // namespace Metal
} // namespace Seele
+89 -89
View File
@@ -21,18 +21,16 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
ownsImage(existingImage == nullptr) {
if (existingImage == nullptr) {
MTL::TextureUsage mtlUsage = 0;
if(usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
{
mtlUsage |= MTL::TextureUsageRenderTarget;
if (usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT ||
usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
mtlUsage |= MTL::TextureUsageRenderTarget;
}
if(usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT)
{
mtlUsage |= MTL::TextureUsageShaderRead;
if (usage & Gfx::SE_IMAGE_USAGE_SAMPLED_BIT) {
mtlUsage |= MTL::TextureUsageShaderRead;
}
if (usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT) {
mtlUsage |= MTL::TextureUsageShaderWrite;
}
if(usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT)
{
mtlUsage |= MTL::TextureUsageShaderWrite;
}
MTL::TextureDescriptor *descriptor =
MTL::TextureDescriptor::alloc()->init();
descriptor->setPixelFormat(cast(format));
@@ -44,16 +42,17 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
descriptor->setTextureType(type);
descriptor->setSampleCount(samples);
descriptor->setUsage(mtlUsage);
texture = graphics->getDevice()->newTexture(descriptor);
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));
// }
// 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() {
@@ -71,8 +70,7 @@ void TextureBase::changeLayout(Gfx::SeImageLayout, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags, Gfx::SeAccessFlags,
Gfx::SePipelineStageFlags) {}
void TextureBase::download(uint32, uint32, uint32, Array<uint8>&)
{}
void TextureBase::download(uint32, uint32, uint32, Array<uint8> &) {}
Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo &createInfo,
MTL::Texture *exisitingTexture)
@@ -86,93 +84,95 @@ Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo &createInfo,
: MTL::TextureType2D),
createInfo, Gfx::Texture2D::currentOwner, exisitingTexture) {}
Texture2D::~Texture2D()
{
Texture2D::~Texture2D() {}
void Texture2D::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess,
dstStage);
}
void Texture2D::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess, dstStage);
void Texture2D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face,
Array<uint8> &buffer) {
TextureBase::download(mipLevel, arrayLayer, face, buffer);
}
void Texture2D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{
TextureBase::download(mipLevel, arrayLayer, face, buffer);
void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner) {
TextureBase::executeOwnershipBarrier(newOwner);
}
void Texture2D::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
TextureBase::executeOwnershipBarrier(newOwner);
void Texture2D::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
void Texture2D::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
Texture3D::Texture3D(PGraphics graphics, const TextureCreateInfo &createInfo)
: Gfx::Texture3D(graphics->getFamilyMapping(), createInfo.sourceData.owner),
TextureBase(graphics, MTL::TextureType3D, createInfo,
Gfx::Texture3D::currentOwner) {}
Texture3D::~Texture3D() {}
void Texture3D::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess,
dstStage);
}
Texture3D::Texture3D(PGraphics graphics, const TextureCreateInfo& createInfo)
: Gfx::Texture3D(graphics->getFamilyMapping(), createInfo.sourceData.owner)
, TextureBase(graphics, MTL::TextureType3D, createInfo, Gfx::Texture3D::currentOwner) {}
Texture3D::~Texture3D()
{
void Texture3D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face,
Array<uint8> &buffer) {
TextureBase::download(mipLevel, arrayLayer, face, buffer);
}
void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner) {
TextureBase::executeOwnershipBarrier(newOwner);
}
void Texture3D::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess, dstStage);
void Texture3D::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
void Texture3D::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{
TextureBase::download(mipLevel, arrayLayer, face, buffer);
}
void Texture3D::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
TextureBase::executeOwnershipBarrier(newOwner);
TextureCube::TextureCube(PGraphics graphics,
const TextureCreateInfo &createInfo)
: Gfx::TextureCube(graphics->getFamilyMapping(),
createInfo.sourceData.owner),
TextureBase(graphics,
createInfo.elements > 1 ? MTL::TextureTypeCubeArray
: MTL::TextureTypeCube,
createInfo, Gfx::TextureCube::currentOwner) {}
TextureCube::~TextureCube() {}
void TextureCube::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess,
dstStage);
}
void Texture3D::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
void TextureCube::download(uint32 mipLevel, uint32 arrayLayer, uint32 face,
Array<uint8> &buffer) {
TextureBase::download(mipLevel, arrayLayer, face, buffer);
}
void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner) {
TextureBase::executeOwnershipBarrier(newOwner);
}
TextureCube::TextureCube(PGraphics graphics, const TextureCreateInfo& createInfo)
: Gfx::TextureCube(graphics->getFamilyMapping(), createInfo.sourceData.owner)
, TextureBase(graphics, createInfo.elements > 1 ? MTL::TextureTypeCubeArray : MTL::TextureTypeCube,
createInfo, Gfx::TextureCube::currentOwner)
{
}
TextureCube::~TextureCube()
{
}
void TextureCube::changeLayout(Gfx::SeImageLayout newLayout,
Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::changeLayout(newLayout, srcAccess, srcStage, dstAccess, dstStage);
}
void TextureCube::download(uint32 mipLevel, uint32 arrayLayer, uint32 face, Array<uint8>& buffer)
{
TextureBase::download(mipLevel, arrayLayer, face, buffer);
}
void TextureCube::executeOwnershipBarrier(Gfx::QueueType newOwner)
{
TextureBase::executeOwnershipBarrier(newOwner);
}
void TextureCube::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage)
{
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
void TextureCube::executePipelineBarrier(Gfx::SeAccessFlags srcAccess,
Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) {
TextureBase::executePipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
}
+46 -46
View File
@@ -17,60 +17,60 @@
namespace Seele {
namespace Metal {
class Window : public Gfx::Window {
public:
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
virtual ~Window();
virtual void pollInput() override;
virtual void beginFrame() override;
virtual void endFrame() override;
virtual Gfx::PTexture2D getBackBuffer() const override;
virtual void onWindowCloseEvent() override;
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
virtual void setCloseCallback(std::function<void()> callback) override;
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
public:
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
virtual ~Window();
virtual void pollInput() override;
virtual void beginFrame() override;
virtual void endFrame() override;
virtual Gfx::PTexture2D getBackBuffer() const override;
virtual void onWindowCloseEvent() override;
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
virtual void setScrollCallback(std::function<void(double, double)> callback) override;
virtual void setFileCallback(std::function<void(int, const char**)> callback) override;
virtual void setCloseCallback(std::function<void()> callback) override;
virtual void setResizeCallback(std::function<void(uint32, uint32)> callback) override;
void keyPress(KeyCode code, InputAction action, KeyModifier modifier);
void mouseMove(double x, double y);
void mouseButton(MouseButton button, InputAction action, KeyModifier modifier);
void scroll(double x, double y);
void fileDrop(int num, const char** files);
void close();
void resize(int width, int height);
void keyPress(KeyCode code, InputAction action, KeyModifier modifier);
void mouseMove(double x, double y);
void mouseButton(MouseButton button, InputAction action, KeyModifier modifier);
void scroll(double x, double y);
void fileDrop(int num, const char** files);
void close();
void resize(int width, int height);
private:
void createBackBuffer();
private:
void createBackBuffer();
PGraphics graphics;
WindowCreateInfo preferences;
GLFWwindow* windowHandle;
NSWindow* metalWindow;
CAMetalLayer* metalLayer;
CA::MetalDrawable* drawable;
OTexture2D backBuffer;
PGraphics graphics;
WindowCreateInfo preferences;
GLFWwindow* windowHandle;
NSWindow* metalWindow;
CAMetalLayer* metalLayer;
CA::MetalDrawable* drawable;
OTexture2D backBuffer;
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
std::function<void(double, double)> mouseMoveCallback;
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
std::function<void(double, double)> scrollCallback;
std::function<void(int, const char**)> fileCallback;
std::function<void()> closeCallback;
std::function<void(uint32, uint32)> resizeCallback;
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
std::function<void(double, double)> mouseMoveCallback;
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
std::function<void(double, double)> scrollCallback;
std::function<void(int, const char**)> fileCallback;
std::function<void()> closeCallback;
std::function<void(uint32, uint32)> resizeCallback;
};
DEFINE_REF(Window);
class Viewport : public Gfx::Viewport {
public:
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
virtual ~Viewport();
constexpr MTL::Viewport getHandle() const { return viewport; }
virtual void resize(uint32 newX, uint32 newY);
virtual void move(uint32 newOffset, uint32 newOffsetY);
public:
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
virtual ~Viewport();
constexpr MTL::Viewport getHandle() const { return viewport; }
virtual void resize(uint32 newX, uint32 newY);
virtual void move(uint32 newOffset, uint32 newOffsetY);
private:
MTL::Viewport viewport;
private:
MTL::Viewport viewport;
};
} // namespace Metal
} // namespace Seele
+76 -46
View File
@@ -20,51 +20,58 @@ double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
uint32 currentFrameIndex = 0;
uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; }
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
void glfwKeyCallback(GLFWwindow *handle, int key, int, int action,
int modifier) {
if (key == -1) {
return;
}
Window* window = (Window*)glfwGetWindowUserPointer(handle);
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
}
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
void glfwMouseMoveCallback(GLFWwindow *handle, double xpos, double ypos) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->mouseMove(xpos, ypos);
}
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
void glfwMouseButtonCallback(GLFWwindow *handle, int button, int action,
int modifier) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->mouseButton((MouseButton)button, (InputAction)action,
(KeyModifier)modifier);
}
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
void glfwScrollCallback(GLFWwindow *handle, double xoffset, double yoffset) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->scroll(xoffset, yoffset);
}
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
void glfwFileCallback(GLFWwindow *handle, int count, const char **paths) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->fileDrop(count, paths);
}
void glfwCloseCallback(GLFWwindow* handle) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
void glfwCloseCallback(GLFWwindow *handle) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->close();
}
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height) {
Window* window = (Window*)glfwGetWindowUserPointer(handle);
void glfwFramebufferResizeCallback(GLFWwindow *handle, int width, int height) {
Window *window = (Window *)glfwGetWindowUserPointer(handle);
window->resize(width, height);
}
Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphics(graphics), preferences(createInfo) {
glfwSetErrorCallback([](int, const char* description) { std::cout << description << std::endl; });
Window::Window(PGraphics graphics, const WindowCreateInfo &createInfo)
: graphics(graphics), preferences(createInfo) {
glfwSetErrorCallback([](int, const char *description) {
std::cout << description << std::endl;
});
float xscale = 1, yscale = 1;
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* handle =
glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
GLFWwindow *handle =
glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale,
createInfo.title, nullptr, nullptr);
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
@@ -89,12 +96,14 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
metalWindow.contentView.wantsLayer = YES;
}
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
Window::~Window() {
glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle));
}
void Window::pollInput() { glfwPollEvents(); }
void Window::beginFrame() {
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
drawable = (__bridge CA::MetalDrawable *)[metalLayer nextDrawable];
createBackBuffer();
}
@@ -108,33 +117,51 @@ void Window::onWindowCloseEvent() {}
Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); }
void Window::setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) { keyCallback = callback; }
void Window::setKeyCallback(
std::function<void(KeyCode, InputAction, KeyModifier)> callback) {
keyCallback = callback;
}
void Window::setMouseMoveCallback(std::function<void(double, double)> callback) { mouseMoveCallback = callback; }
void Window::setMouseMoveCallback(
std::function<void(double, double)> callback) {
mouseMoveCallback = callback;
}
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) {
void Window::setMouseButtonCallback(
std::function<void(MouseButton, InputAction, KeyModifier)> callback) {
mouseButtonCallback = callback;
}
void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
void Window::setScrollCallback(std::function<void(double, double)> callback) {
scrollCallback = callback;
}
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
void Window::setFileCallback(std::function<void(int, const char **)> callback) {
fileCallback = callback;
}
void Window::setCloseCallback(std::function<void()> callback) { closeCallback = callback; }
void Window::setCloseCallback(std::function<void()> callback) {
closeCallback = callback;
}
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) { resizeCallback = callback; }
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) {
resizeCallback = callback;
}
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { keyCallback(code, action, modifier); }
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) {
keyCallback(code, action, modifier);
}
void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); }
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) {
void Window::mouseButton(MouseButton button, InputAction action,
KeyModifier modifier) {
mouseButtonCallback(button, action, modifier);
}
void Window::scroll(double x, double y) { scrollCallback(x, y); }
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
void Window::fileDrop(int num, const char **files) { fileCallback(num, files); }
void Window::close() { closeCallback(); }
@@ -149,28 +176,31 @@ void Window::resize(int width, int height) {
framebufferWidth = width;
framebufferHeight = height;
// Deallocate the textures if they have been created
drawable = (__bridge CA::MetalDrawable*)[[metalLayer nextDrawable] autorelease];
drawable =
(__bridge CA::MetalDrawable *)[[metalLayer nextDrawable] autorelease];
createBackBuffer();
resizeCallback(width, height);
}
void Window::createBackBuffer() {
MTL::Texture* buf = drawable->texture();
backBuffer = new Texture2D(graphics,
TextureCreateInfo{
.width = static_cast<uint32>(buf->width()),
.height = static_cast<uint32>(buf->height()),
.depth = static_cast<uint32>(buf->depth()),
.elements = static_cast<uint32>(buf->arrayLength()),
.mipLevels = static_cast<uint32>(buf->mipmapLevelCount()),
.format = cast(buf->pixelFormat()),
.usage = MTL::TextureUsageRenderTarget,
.samples = static_cast<uint32>(buf->sampleCount()),
},
buf);
MTL::Texture *buf = drawable->texture();
backBuffer = new Texture2D(
graphics,
TextureCreateInfo{
.width = static_cast<uint32>(buf->width()),
.height = static_cast<uint32>(buf->height()),
.depth = static_cast<uint32>(buf->depth()),
.elements = static_cast<uint32>(buf->arrayLength()),
.mipLevels = static_cast<uint32>(buf->mipmapLevelCount()),
.format = cast(buf->pixelFormat()),
.usage = MTL::TextureUsageRenderTarget,
.samples = static_cast<uint32>(buf->sampleCount()),
},
buf);
}
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) {
Viewport::Viewport(PWindow owner, const ViewportCreateInfo &createInfo)
: Gfx::Viewport(owner, createInfo) {
viewport.width = sizeX;
viewport.height = sizeY;
viewport.originX = offsetX;