Basic metal backend
This commit is contained in:
@@ -48,12 +48,6 @@ int main()
|
|||||||
#endif
|
#endif
|
||||||
GraphicsInitializer initializer;
|
GraphicsInitializer initializer;
|
||||||
graphics->init(initializer);
|
graphics->init(initializer);
|
||||||
graphics->createVertexShader(ShaderCreateInfo {
|
|
||||||
.entryPoint = "fragmentMain",
|
|
||||||
.mainModule = "TextPass",
|
|
||||||
.additionalModules = {"TextPass"},
|
|
||||||
.name = "Test",
|
|
||||||
});
|
|
||||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||||
vd->init(graphics);
|
vd->init(graphics);
|
||||||
OWindowManager windowManager = new WindowManager();
|
OWindowManager windowManager = new WindowManager();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ DescriptorLayout& DescriptorLayout::operator=(const DescriptorLayout& other) {
|
|||||||
|
|
||||||
DescriptorLayout::~DescriptorLayout() {}
|
DescriptorLayout::~DescriptorLayout() {}
|
||||||
|
|
||||||
void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorType type, uint32 arrayCount,
|
void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorType type, SeImageViewType textureType, uint32 arrayCount,
|
||||||
SeDescriptorBindingFlags bindingFlags, SeShaderStageFlags shaderStages) {
|
SeDescriptorBindingFlags bindingFlags, SeShaderStageFlags shaderStages) {
|
||||||
if (descriptorBindings.size() <= bindingIndex) {
|
if (descriptorBindings.size() <= bindingIndex) {
|
||||||
descriptorBindings.resize(bindingIndex + 1);
|
descriptorBindings.resize(bindingIndex + 1);
|
||||||
@@ -32,6 +32,7 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
|
|||||||
descriptorBindings[bindingIndex] = DescriptorBinding{
|
descriptorBindings[bindingIndex] = DescriptorBinding{
|
||||||
.binding = bindingIndex,
|
.binding = bindingIndex,
|
||||||
.descriptorType = type,
|
.descriptorType = type,
|
||||||
|
.textureType = textureType,
|
||||||
.descriptorCount = arrayCount,
|
.descriptorCount = arrayCount,
|
||||||
.bindingFlags = bindingFlags,
|
.bindingFlags = bindingFlags,
|
||||||
.shaderStages = shaderStages,
|
.shaderStages = shaderStages,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Gfx {
|
|||||||
struct DescriptorBinding {
|
struct DescriptorBinding {
|
||||||
uint32 binding = 0;
|
uint32 binding = 0;
|
||||||
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||||
|
SeImageViewType textureType;
|
||||||
uint32 descriptorCount = 0x7fff;
|
uint32 descriptorCount = 0x7fff;
|
||||||
SeDescriptorBindingFlags bindingFlags = 0;
|
SeDescriptorBindingFlags bindingFlags = 0;
|
||||||
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
|
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
|
||||||
@@ -22,7 +23,8 @@ public:
|
|||||||
DescriptorLayout(const DescriptorLayout& other);
|
DescriptorLayout(const DescriptorLayout& other);
|
||||||
DescriptorLayout& operator=(const DescriptorLayout& other);
|
DescriptorLayout& operator=(const DescriptorLayout& other);
|
||||||
virtual ~DescriptorLayout();
|
virtual ~DescriptorLayout();
|
||||||
void addDescriptorBinding(uint32 binding, SeDescriptorType type, uint32 arrayCount = 1,
|
void addDescriptorBinding(uint32 binding, SeDescriptorType type,
|
||||||
|
SeImageViewType textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D, uint32 arrayCount = 1,
|
||||||
SeDescriptorBindingFlags bindingFlags = 0,
|
SeDescriptorBindingFlags bindingFlags = 0,
|
||||||
SeShaderStageFlags shaderStages = SeShaderStageFlagBits::SE_SHADER_STAGE_ALL);
|
SeShaderStageFlags shaderStages = SeShaderStageFlagBits::SE_SHADER_STAGE_ALL);
|
||||||
void reset();
|
void reset();
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
uint32 currentBuffer;
|
uint32 currentBuffer = 0;
|
||||||
uint64 size;
|
uint64 size;
|
||||||
MTL::Buffer *buffers[Gfx::numFramesBuffered];
|
MTL::Buffer *buffers[Gfx::numFramesBuffered];
|
||||||
uint32 numBuffers;
|
uint32 numBuffers;
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ private:
|
|||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
MTL::CommandQueue* queue;
|
MTL::CommandQueue* queue;
|
||||||
OCommand activeCommand;
|
OCommand activeCommand;
|
||||||
|
Array<OCommand> pendingCommands;
|
||||||
};
|
};
|
||||||
class IOCommandQueue
|
class IOCommandQueue
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
#include "Graphics/Enums.h"
|
#include "Graphics/Enums.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
|
#include "Metal/MTLCommandBuffer.hpp"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
@@ -120,7 +121,7 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
|
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
|
||||||
//TODO:
|
// TODO:
|
||||||
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 128, 128), MTL::Size(32, 32, 32));
|
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 128, 128), MTL::Size(32, 32, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +136,9 @@ void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
||||||
encoder->setBuffer(set.cast<DescriptorSet>()->getBuffer(), 0, set->getSetIndex());
|
auto metalSet = set.cast<DescriptorSet>();
|
||||||
|
metalSet->bind();
|
||||||
|
encoder->setBuffer(metalSet->getBuffer(), 0, set->getSetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||||
@@ -144,13 +147,13 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags, uint32 offset,
|
void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags, uint32 offset, uint32 size,
|
||||||
uint32 size, const void* data) {
|
const void* data) {
|
||||||
encoder->setBytes((char*)data + offset, size, 0);
|
encoder->setBytes((char*)data + offset, size, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
||||||
//TODO
|
// TODO
|
||||||
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 32));
|
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,8 +173,19 @@ OComputeCommand CommandQueue::getComputeCommand(const std::string& name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CommandQueue::submitCommands(PEvent signalSemaphore) {
|
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->end(signalSemaphore);
|
activeCommand->end(signalSemaphore);
|
||||||
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
|
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
|
||||||
|
pendingCommands.add(std::move(activeCommand));
|
||||||
activeCommand = new Command(graphics, queue->commandBuffer());
|
activeCommand = new Command(graphics, queue->commandBuffer());
|
||||||
activeCommand->waitForEvent(prevCmdEvent);
|
activeCommand->waitForEvent(prevCmdEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,28 @@
|
|||||||
#include "Descriptor.h"
|
#include "Descriptor.h"
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include "Graphics/Descriptor.h"
|
||||||
#include "Graphics/Initializer.h"
|
#include "Graphics/Initializer.h"
|
||||||
|
#include "Metal/MTLArgument.hpp"
|
||||||
|
#include "Metal/MTLDevice.hpp"
|
||||||
|
#include "Metal/MTLResource.hpp"
|
||||||
|
#include "Metal/MTLTexture.hpp"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
#include <Foundation/Foundation.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
|
|
||||||
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
||||||
: Gfx::DescriptorLayout(name), graphics(graphics) {}
|
: Gfx::DescriptorLayout(name), graphics(graphics), arguments(nullptr) {}
|
||||||
|
|
||||||
DescriptorLayout::~DescriptorLayout() {}
|
DescriptorLayout::~DescriptorLayout() {}
|
||||||
|
|
||||||
void DescriptorLayout::create() {
|
void DescriptorLayout::create() {
|
||||||
|
if (arguments != nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Array<NS::Object*> descriptors;
|
Array<NS::Object*> descriptors;
|
||||||
for (size_t i = 0; i < descriptorBindings.size(); ++i) {
|
for (size_t i = 0; i < descriptorBindings.size(); ++i) {
|
||||||
const auto& binding = descriptorBindings[i];
|
const auto& binding = descriptorBindings[i];
|
||||||
@@ -35,7 +45,7 @@ void DescriptorLayout::create() {
|
|||||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
||||||
dataType = MTL::DataTypeStruct;
|
dataType = MTL::DataTypePointer;
|
||||||
break;
|
break;
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
|
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
|
||||||
dataType = MTL::DataTypePrimitiveAccelerationStructure;
|
dataType = MTL::DataTypePrimitiveAccelerationStructure;
|
||||||
@@ -44,10 +54,38 @@ void DescriptorLayout::create() {
|
|||||||
throw std::logic_error("Nooo");
|
throw std::logic_error("Nooo");
|
||||||
}
|
}
|
||||||
desc->setDataType(dataType);
|
desc->setDataType(dataType);
|
||||||
|
desc->setIndex(i);
|
||||||
|
if (dataType == MTL::DataTypeTexture) {
|
||||||
|
switch (binding.textureType) {
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_1D:
|
||||||
|
desc->setTextureType(MTL::TextureType1D);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_2D:
|
||||||
|
desc->setTextureType(MTL::TextureType2D);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_3D:
|
||||||
|
desc->setTextureType(MTL::TextureType3D);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE:
|
||||||
|
desc->setTextureType(MTL::TextureTypeCube);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY:
|
||||||
|
desc->setTextureType(MTL::TextureType1DArray);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY:
|
||||||
|
desc->setTextureType(MTL::TextureType2DArray);
|
||||||
|
break;
|
||||||
|
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||||
|
desc->setTextureType(MTL::TextureTypeCubeArray);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
descriptors.add(desc);
|
descriptors.add(desc);
|
||||||
}
|
}
|
||||||
arguments = NS::Array::array(descriptors.data(), descriptors.size());
|
arguments = NS::Array::array(descriptors.data(), descriptors.size());
|
||||||
pool = new DescriptorPool(graphics, this);
|
pool = new DescriptorPool(graphics, this);
|
||||||
|
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
|
||||||
|
CRC::CRC_32());
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
|
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
|
||||||
@@ -66,6 +104,7 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
|
|||||||
return PDescriptorSet(allocatedSets[setIndex]);
|
return PDescriptorSet(allocatedSets[setIndex]);
|
||||||
}
|
}
|
||||||
allocatedSets.add(new DescriptorSet(graphics, this));
|
allocatedSets.add(new DescriptorSet(graphics, this));
|
||||||
|
allocatedSets.back()->allocate();
|
||||||
return PDescriptorSet(allocatedSets.back());
|
return PDescriptorSet(allocatedSets.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +116,16 @@ void DescriptorPool::reset() {
|
|||||||
|
|
||||||
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||||
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
|
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
|
||||||
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
// auto desc = (MTL::ArgumentDescriptor*)owner->getArguments()->object(0);
|
||||||
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
// std::cout << desc->access() << " " << desc->arrayLength() << " " << desc->index() << " " << desc->textureType() <<
|
||||||
encoder->setArgumentBuffer(buffer, 0);
|
// " " << desc->dataType() << std::endl;
|
||||||
|
if (owner->getArguments()->count() == 0) {
|
||||||
|
buffer = graphics->getDevice()->newBuffer(0, MTL::ResourceOptionCPUCacheModeDefault);
|
||||||
|
} else {
|
||||||
|
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
||||||
|
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
||||||
|
encoder->setArgumentBuffer(buffer, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorSet::~DescriptorSet() {}
|
DescriptorSet::~DescriptorSet() {}
|
||||||
@@ -100,9 +146,11 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
|
|||||||
}
|
}
|
||||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||||
PTextureBase base = texture.cast<TextureBase>();
|
PTextureBase base = texture.cast<TextureBase>();
|
||||||
PSampler sampler = samplerState.cast<Sampler>();
|
|
||||||
encoder->setTexture(base->getTexture(), binding);
|
encoder->setTexture(base->getTexture(), binding);
|
||||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
if (samplerState != nullptr) {
|
||||||
|
PSampler sampler = samplerState.cast<Sampler>();
|
||||||
|
encoder->setSamplerState(sampler->getHandle(), binding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
||||||
@@ -115,14 +163,13 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> ar
|
|||||||
bool DescriptorSet::operator<(Gfx::PDescriptorSet other) { return this < other.getHandle(); }
|
bool DescriptorSet::operator<(Gfx::PDescriptorSet other) { return this < other.getHandle(); }
|
||||||
|
|
||||||
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
|
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
|
||||||
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
|
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
|
||||||
|
|
||||||
PipelineLayout::~PipelineLayout(){}
|
PipelineLayout::~PipelineLayout() {}
|
||||||
|
|
||||||
void PipelineLayout::create()
|
void PipelineLayout::create() {
|
||||||
{
|
for (auto& set : descriptorSetLayouts) {
|
||||||
for(auto& set : descriptorSetLayouts)
|
set->create();
|
||||||
{
|
|
||||||
uint32 setHash = set->getHash();
|
uint32 setHash = set->getHash();
|
||||||
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Graphics::~Graphics()
|
|||||||
|
|
||||||
void Graphics::init(GraphicsInitializer)
|
void Graphics::init(GraphicsInitializer)
|
||||||
{
|
{
|
||||||
|
glfwInit();
|
||||||
device = MTL::CreateSystemDefaultDevice();
|
device = MTL::CreateSystemDefaultDevice();
|
||||||
queue = new CommandQueue(this);
|
queue = new CommandQueue(this);
|
||||||
ioQueue = new IOCommandQueue(this);
|
ioQueue = new IOCommandQueue(this);
|
||||||
|
|||||||
@@ -28,35 +28,38 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
|
|||||||
|
|
||||||
MTL::VertexDescriptor* vertexDescriptor = MTL::VertexDescriptor::alloc()->init();
|
MTL::VertexDescriptor* vertexDescriptor = MTL::VertexDescriptor::alloc()->init();
|
||||||
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes();
|
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes();
|
||||||
const auto& vertexInfo = createInfo.vertexInput->getInfo();
|
if(createInfo.vertexInput != nullptr)
|
||||||
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
|
{
|
||||||
MTL::VertexAttributeDescriptor* attribute = MTL::VertexAttributeDescriptor::alloc()->init();
|
const auto& vertexInfo = createInfo.vertexInput->getInfo();
|
||||||
attribute->setBufferIndex(vertexInfo.attributes[attr].binding);
|
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
|
||||||
switch (vertexInfo.attributes[attr].format) {
|
MTL::VertexAttributeDescriptor* attribute = MTL::VertexAttributeDescriptor::alloc()->init();
|
||||||
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
|
attribute->setBufferIndex(vertexInfo.attributes[attr].binding);
|
||||||
attribute->setFormat(MTL::VertexFormatFloat3);
|
switch (vertexInfo.attributes[attr].format) {
|
||||||
break;
|
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
|
||||||
default:
|
attribute->setFormat(MTL::VertexFormatFloat3);
|
||||||
throw std::logic_error("TODO");
|
break;
|
||||||
|
default:
|
||||||
|
throw std::logic_error("TODO");
|
||||||
|
}
|
||||||
|
attribute->setOffset(vertexInfo.attributes[attr].offset);
|
||||||
|
attributes->setObject(attribute, attr);
|
||||||
}
|
}
|
||||||
attribute->setOffset(vertexInfo.attributes[attr].offset);
|
|
||||||
attributes->setObject(attribute, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts();
|
MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts();
|
||||||
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
|
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
|
||||||
MTL::VertexBufferLayoutDescriptor* buffer = MTL::VertexBufferLayoutDescriptor::alloc()->init();
|
MTL::VertexBufferLayoutDescriptor* buffer = MTL::VertexBufferLayoutDescriptor::alloc()->init();
|
||||||
buffer->setStride(vertexInfo.bindings[binding].stride);
|
buffer->setStride(vertexInfo.bindings[binding].stride);
|
||||||
buffer->setStepRate(1);
|
buffer->setStepRate(1);
|
||||||
switch (vertexInfo.bindings[binding].inputRate) {
|
switch (vertexInfo.bindings[binding].inputRate) {
|
||||||
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
|
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
|
||||||
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
||||||
break;
|
break;
|
||||||
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
|
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
|
||||||
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
|
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
bufferLayout->setObject(buffer, binding);
|
||||||
}
|
}
|
||||||
bufferLayout->setObject(buffer, binding);
|
|
||||||
}
|
}
|
||||||
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
|
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Graphics/slang-compile.h"
|
#include "Graphics/slang-compile.h"
|
||||||
#include "Metal/MTLDevice.hpp"
|
#include "Metal/MTLDevice.hpp"
|
||||||
#include "Metal/MTLLibrary.hpp"
|
#include "Metal/MTLLibrary.hpp"
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <slang.h>
|
#include <slang.h>
|
||||||
#include <spirv_cross.hpp>
|
#include <spirv_cross.hpp>
|
||||||
@@ -42,7 +43,14 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
|||||||
std::cout << error->debugDescription() << std::endl;
|
std::cout << error->debugDescription() << std::endl;
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
|
function = library->newFunction(NS::String::string("main0", NS::ASCIIStringEncoding));
|
||||||
|
if(!function)
|
||||||
|
{
|
||||||
|
std::ofstream shaderFile("error.metal");
|
||||||
|
shaderFile << metalCode;
|
||||||
|
shaderFile.close();
|
||||||
|
assert(!function);
|
||||||
|
}
|
||||||
mtlOptions->release();
|
mtlOptions->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,66 +13,63 @@
|
|||||||
#include <QuartzCore/CAMetalLayer.hpp>
|
#include <QuartzCore/CAMetalLayer.hpp>
|
||||||
#include <QuartzCore/QuartzCore.hpp>
|
#include <QuartzCore/QuartzCore.hpp>
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele {
|
||||||
{
|
namespace Metal {
|
||||||
namespace Metal
|
class Window : public Gfx::Window {
|
||||||
{
|
|
||||||
class Window : public Gfx::Window
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
|
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
|
||||||
virtual ~Window();
|
virtual ~Window();
|
||||||
virtual void pollInput() override;
|
virtual void pollInput() override;
|
||||||
virtual void beginFrame() override;
|
virtual void beginFrame() override;
|
||||||
virtual void endFrame() override;
|
virtual void endFrame() override;
|
||||||
virtual Gfx::PTexture2D getBackBuffer() const override;
|
virtual Gfx::PTexture2D getBackBuffer() const override;
|
||||||
virtual void onWindowCloseEvent() override;
|
virtual void onWindowCloseEvent() override;
|
||||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
||||||
virtual void setMouseMoveCallback(std::function<void(double, double)> 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 setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) override;
|
||||||
virtual void setScrollCallback(std::function<void(double, double)> 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 setFileCallback(std::function<void(int, const char**)> callback) override;
|
||||||
virtual void setCloseCallback(std::function<void()> callback) override;
|
virtual void setCloseCallback(std::function<void()> callback) override;
|
||||||
virtual void setResizeCallback(std::function<void(uint32, uint32)> 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);
|
|
||||||
private:
|
|
||||||
PGraphics graphics;
|
|
||||||
WindowCreateInfo preferences;
|
|
||||||
GLFWwindow* windowHandle;
|
|
||||||
NSWindow* metalWindow;
|
|
||||||
CAMetalLayer* metalLayer;
|
|
||||||
CA::MetalDrawable* drawable;
|
|
||||||
OTexture2D backBuffer;
|
|
||||||
|
|
||||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
void keyPress(KeyCode code, InputAction action, KeyModifier modifier);
|
||||||
std::function<void(double, double)> mouseMoveCallback;
|
void mouseMove(double x, double y);
|
||||||
std::function<void(MouseButton, InputAction, KeyModifier)> mouseButtonCallback;
|
void mouseButton(MouseButton button, InputAction action, KeyModifier modifier);
|
||||||
std::function<void(double, double)> scrollCallback;
|
void scroll(double x, double y);
|
||||||
std::function<void(int, const char**)> fileCallback;
|
void fileDrop(int num, const char** files);
|
||||||
std::function<void()> closeCallback;
|
void close();
|
||||||
std::function<void(uint32, uint32)> resizeCallback;
|
void resize(int width, int height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void createBackBuffer();
|
||||||
|
|
||||||
|
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;
|
||||||
};
|
};
|
||||||
DEFINE_REF(Window);
|
DEFINE_REF(Window);
|
||||||
class Viewport : public Gfx::Viewport
|
class Viewport : public Gfx::Viewport {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
|
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
|
||||||
virtual ~Viewport();
|
virtual ~Viewport();
|
||||||
constexpr MTL::Viewport getHandle() const
|
constexpr MTL::Viewport getHandle() const { return viewport; }
|
||||||
{
|
virtual void resize(uint32 newX, uint32 newY);
|
||||||
return viewport;
|
virtual void move(uint32 newOffset, uint32 newOffsetY);
|
||||||
}
|
|
||||||
virtual void resize(uint32 newX, uint32 newY);
|
|
||||||
virtual void move(uint32 newOffset, uint32 newOffsetY);
|
|
||||||
private:
|
private:
|
||||||
MTL::Viewport viewport;
|
MTL::Viewport viewport;
|
||||||
};
|
};
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
+141
-186
@@ -1,234 +1,189 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
#include "Command.h"
|
||||||
#include "Graphics/Initializer.h"
|
#include "Graphics/Initializer.h"
|
||||||
#include "Graphics/Metal/Enums.h"
|
#include "Graphics/Metal/Enums.h"
|
||||||
#include "Graphics/Texture.h"
|
#include "Graphics/Texture.h"
|
||||||
#include "Command.h"
|
|
||||||
#include "Metal/MTLTexture.hpp"
|
#include "Metal/MTLTexture.hpp"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
|
|
||||||
double currentFrameDelta = 0;
|
double currentFrameDelta = 0;
|
||||||
double Gfx::getCurrentFrameDelta()
|
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
|
||||||
{
|
|
||||||
return currentFrameDelta;
|
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
|
||||||
|
if (key == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
|
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
if (key == -1)
|
window->mouseMove(xpos, ypos);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
|
||||||
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos)
|
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
|
||||||
window->mouseMove(xpos, ypos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier)
|
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
window->scroll(xoffset, yoffset);
|
||||||
window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset)
|
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
window->fileDrop(count, paths);
|
||||||
window->scroll(xoffset, yoffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
|
void glfwCloseCallback(GLFWwindow* handle) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
window->close();
|
||||||
window->fileDrop(count, paths);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwCloseCallback(GLFWwindow* handle)
|
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height) {
|
||||||
{
|
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
window->resize(width, height);
|
||||||
window->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height)
|
Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphics(graphics), preferences(createInfo) {
|
||||||
{
|
glfwSetErrorCallback([](int, const char* description) { std::cout << description << std::endl; });
|
||||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
float xscale = 1, yscale = 1;
|
||||||
window->resize(width, height);
|
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
GLFWwindow* handle =
|
||||||
|
glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
|
||||||
|
windowHandle = handle;
|
||||||
|
glfwSetWindowUserPointer(handle, this);
|
||||||
|
|
||||||
|
glfwSetKeyCallback(handle, &glfwKeyCallback);
|
||||||
|
glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback);
|
||||||
|
glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback);
|
||||||
|
glfwSetScrollCallback(handle, &glfwScrollCallback);
|
||||||
|
glfwSetDropCallback(handle, &glfwFileCallback);
|
||||||
|
glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
|
||||||
|
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
|
||||||
|
int width, height;
|
||||||
|
glfwGetFramebufferSize(handle, &width, &height);
|
||||||
|
framebufferWidth = width;
|
||||||
|
framebufferHeight = height;
|
||||||
|
|
||||||
|
metalWindow = glfwGetCocoaWindow(handle);
|
||||||
|
metalLayer = [CAMetalLayer layer];
|
||||||
|
metalLayer.device = (__bridge id<MTLDevice>)graphics->getDevice();
|
||||||
|
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||||
|
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
||||||
|
metalWindow.contentView.layer = metalLayer;
|
||||||
|
metalWindow.contentView.wantsLayer = YES;
|
||||||
|
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||||
|
createBackBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
|
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
||||||
: graphics(graphics)
|
|
||||||
, preferences(createInfo)
|
|
||||||
{
|
|
||||||
float xscale, yscale;
|
|
||||||
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
|
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
|
||||||
GLFWwindow *handle = glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
|
|
||||||
windowHandle = handle;
|
|
||||||
glfwSetWindowUserPointer(handle, this);
|
|
||||||
|
|
||||||
glfwSetKeyCallback(handle, &glfwKeyCallback);
|
void Window::pollInput() { glfwPollEvents(); }
|
||||||
glfwSetCursorPosCallback(handle, &glfwMouseMoveCallback);
|
|
||||||
glfwSetMouseButtonCallback(handle, &glfwMouseButtonCallback);
|
|
||||||
glfwSetScrollCallback(handle, &glfwScrollCallback);
|
|
||||||
glfwSetDropCallback(handle, &glfwFileCallback);
|
|
||||||
glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
|
|
||||||
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
|
|
||||||
|
|
||||||
metalWindow = glfwGetCocoaWindow(handle);
|
void Window::beginFrame() {
|
||||||
metalLayer = [CAMetalLayer layer];
|
if (drawable) {
|
||||||
metalLayer.device = (__bridge id<MTLDevice>)graphics->getDevice();
|
drawable->release();
|
||||||
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
}
|
||||||
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||||
metalWindow.contentView.layer = metalLayer;
|
createBackBuffer();
|
||||||
metalWindow.contentView.wantsLayer = YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::~Window()
|
void Window::endFrame() {
|
||||||
{
|
graphics->getQueue()->getCommands()->present(drawable);
|
||||||
glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle));
|
graphics->getQueue()->submitCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::pollInput()
|
void Window::onWindowCloseEvent() {}
|
||||||
{
|
|
||||||
glfwPollEvents();
|
Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); }
|
||||||
|
|
||||||
|
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::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) {
|
||||||
|
mouseButtonCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::beginFrame()
|
void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
||||||
{
|
|
||||||
@autoreleasepool {
|
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
|
||||||
MTL::Texture* buf = drawable->texture();
|
void Window::setCloseCallback(std::function<void()> callback) { closeCallback = callback; }
|
||||||
backBuffer = new Texture2D(graphics, TextureCreateInfo {
|
|
||||||
.width = static_cast<uint32>(buf->width()),
|
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) { resizeCallback = callback; }
|
||||||
.height = static_cast<uint32>(buf->height()),
|
|
||||||
.depth = static_cast<uint32>(buf->depth()),
|
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { keyCallback(code, action, modifier); }
|
||||||
.elements = static_cast<uint32>(buf->arrayLength()),
|
|
||||||
.mipLevels = static_cast<uint32>(buf->mipmapLevelCount()),
|
void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); }
|
||||||
.format = cast(buf->pixelFormat()),
|
|
||||||
.usage = MTL::TextureUsageRenderTarget,
|
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) {
|
||||||
.samples = static_cast<uint32>(buf->sampleCount()),
|
mouseButtonCallback(button, action, modifier);
|
||||||
}, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::endFrame()
|
void Window::scroll(double x, double y) { scrollCallback(x, y); }
|
||||||
{
|
|
||||||
graphics->getQueue()->getCommands()->present(drawable);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::onWindowCloseEvent()
|
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Gfx::PTexture2D Window::getBackBuffer() const
|
void Window::close() { closeCallback(); }
|
||||||
{
|
|
||||||
return PTexture2D(backBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback)
|
void Window::resize(int width, int height) {
|
||||||
{
|
if (width == 0 || height == 0) {
|
||||||
keyCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::setMouseMoveCallback(std::function<void(double, double)> callback)
|
|
||||||
{
|
|
||||||
mouseMoveCallback = 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::setFileCallback(std::function<void(int, const char**)> callback)
|
|
||||||
{
|
|
||||||
fileCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::setCloseCallback(std::function<void()> callback)
|
|
||||||
{
|
|
||||||
closeCallback = 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::mouseMove(double x, double y)
|
|
||||||
{
|
|
||||||
mouseMoveCallback(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
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::close()
|
|
||||||
{
|
|
||||||
closeCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::resize(int width, int height)
|
|
||||||
{
|
|
||||||
if(width == 0 || height == 0)
|
|
||||||
{
|
|
||||||
paused = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
paused = true;
|
paused = true;
|
||||||
resizeCallback(width, height);
|
return;
|
||||||
|
}
|
||||||
|
paused = true;
|
||||||
|
metalLayer.drawableSize = CGSizeMake(width, height);
|
||||||
|
drawable->release();
|
||||||
|
framebufferWidth = width;
|
||||||
|
framebufferHeight = height;
|
||||||
|
// Deallocate the textures if they have been created
|
||||||
|
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||||
|
createBackBuffer();
|
||||||
|
resizeCallback(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo)
|
void Window::createBackBuffer() {
|
||||||
: Gfx::Viewport(owner, createInfo)
|
MTL::Texture* buf = drawable->texture();
|
||||||
{
|
backBuffer = new Texture2D(graphics,
|
||||||
viewport.width = sizeX;
|
TextureCreateInfo{
|
||||||
viewport.height = sizeY;
|
.width = static_cast<uint32>(buf->width()),
|
||||||
viewport.originX = offsetX;
|
.height = static_cast<uint32>(buf->height()),
|
||||||
viewport.originY = offsetY;
|
.depth = static_cast<uint32>(buf->depth()),
|
||||||
viewport.znear = 0.0f;
|
.elements = static_cast<uint32>(buf->arrayLength()),
|
||||||
viewport.zfar = 1.0f;
|
.mipLevels = static_cast<uint32>(buf->mipmapLevelCount()),
|
||||||
|
.format = cast(buf->pixelFormat()),
|
||||||
|
.usage = MTL::TextureUsageRenderTarget,
|
||||||
|
.samples = static_cast<uint32>(buf->sampleCount()),
|
||||||
|
},
|
||||||
|
buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewport::~Viewport()
|
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) {
|
||||||
{
|
viewport.width = sizeX;
|
||||||
|
viewport.height = sizeY;
|
||||||
|
viewport.originX = offsetX;
|
||||||
|
viewport.originY = offsetY;
|
||||||
|
viewport.znear = 0.0f;
|
||||||
|
viewport.zfar = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewport::resize(uint32 newX, uint32 newY)
|
Viewport::~Viewport() {}
|
||||||
{
|
|
||||||
viewport.width = newX;
|
void Viewport::resize(uint32 newX, uint32 newY) {
|
||||||
viewport.height = newY;
|
viewport.width = newX;
|
||||||
|
viewport.height = newY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewport::move(uint32 newOffset, uint32 newOffsetY)
|
void Viewport::move(uint32 newOffset, uint32 newOffsetY) {
|
||||||
{
|
viewport.originX = newOffset;
|
||||||
viewport.originX = newOffset;
|
viewport.originY = newOffsetY;
|
||||||
viewport.originY = newOffsetY;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "TextPass.h"
|
#include "TextPass.h"
|
||||||
|
#include "Graphics/Enums.h"
|
||||||
#include "RenderGraph.h"
|
#include "RenderGraph.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/RenderTarget.h"
|
#include "Graphics/RenderTarget.h"
|
||||||
@@ -125,7 +126,7 @@ void TextPass::createRenderPass()
|
|||||||
generalLayout->create();
|
generalLayout->create();
|
||||||
|
|
||||||
textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray");
|
textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray");
|
||||||
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
||||||
textureArrayLayout->create();
|
textureArrayLayout->create();
|
||||||
|
|
||||||
projectionBuffer = graphics->createUniformBuffer({
|
projectionBuffer = graphics->createUniformBuffer({
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "UIPass.h"
|
#include "UIPass.h"
|
||||||
|
#include "Graphics/Enums.h"
|
||||||
#include "RenderGraph.h"
|
#include "RenderGraph.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/RenderTarget.h"
|
#include "Graphics/RenderTarget.h"
|
||||||
@@ -109,7 +110,7 @@ void UIPass::createRenderPass()
|
|||||||
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
||||||
descriptorLayout->create();
|
descriptorLayout->create();
|
||||||
|
|
||||||
Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
|
Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
#include "Graphics/Enums.h"
|
||||||
|
#include "Serialization/Serialization.h"
|
||||||
#include "Window/WindowManager.h"
|
#include "Window/WindowManager.h"
|
||||||
#include "MaterialInstance.h"
|
#include "MaterialInstance.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
@@ -61,9 +63,10 @@ void Material::save(ArchiveBuffer& buffer) const
|
|||||||
for (const auto& binding : bindings)
|
for (const auto& binding : bindings)
|
||||||
{
|
{
|
||||||
Serialization::save(buffer, binding.binding);
|
Serialization::save(buffer, binding.binding);
|
||||||
Serialization::save(buffer, binding.bindingFlags);
|
|
||||||
Serialization::save(buffer, binding.descriptorCount);
|
|
||||||
Serialization::save(buffer, binding.descriptorType);
|
Serialization::save(buffer, binding.descriptorType);
|
||||||
|
Serialization::save(buffer, binding.textureType);
|
||||||
|
Serialization::save(buffer, binding.descriptorCount);
|
||||||
|
Serialization::save(buffer, binding.bindingFlags);
|
||||||
Serialization::save(buffer, binding.shaderStages);
|
Serialization::save(buffer, binding.shaderStages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,19 +91,22 @@ void Material::load(ArchiveBuffer& buffer)
|
|||||||
uint32 binding;
|
uint32 binding;
|
||||||
Serialization::load(buffer, binding);
|
Serialization::load(buffer, binding);
|
||||||
|
|
||||||
Gfx::SeDescriptorBindingFlags bindingFlags;
|
Gfx::SeDescriptorType descriptorType;
|
||||||
Serialization::load(buffer, bindingFlags);
|
Serialization::load(buffer, descriptorType);
|
||||||
|
|
||||||
|
Gfx::SeImageViewType textureType;
|
||||||
|
Serialization::load(buffer, textureType);
|
||||||
|
|
||||||
uint32 descriptorCount;
|
uint32 descriptorCount;
|
||||||
Serialization::load(buffer, descriptorCount);
|
Serialization::load(buffer, descriptorCount);
|
||||||
|
|
||||||
Gfx::SeDescriptorType descriptorType;
|
Gfx::SeDescriptorBindingFlags bindingFlags;
|
||||||
Serialization::load(buffer, descriptorType);
|
Serialization::load(buffer, bindingFlags);
|
||||||
|
|
||||||
Gfx::SeShaderStageFlags shaderStages;
|
Gfx::SeShaderStageFlags shaderStages;
|
||||||
Serialization::load(buffer, shaderStages);
|
Serialization::load(buffer, shaderStages);
|
||||||
|
|
||||||
layout->addDescriptorBinding(binding, descriptorType, descriptorCount, bindingFlags, shaderStages);
|
layout->addDescriptorBinding(binding, descriptorType, textureType, descriptorCount, bindingFlags, shaderStages);
|
||||||
}
|
}
|
||||||
layout->create();
|
layout->create();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user