Files
Seele/src/Engine/Graphics/Metal/Graphics.mm
T

177 lines
4.9 KiB
Plaintext
Raw Normal View History

2024-03-18 15:28:56 +01:00
#include "Graphics.h"
2024-06-09 12:20:04 +02:00
#include "Buffer.h"
#include "Command.h"
2024-04-13 23:51:38 +02:00
#include "Graphics/Initializer.h"
2024-04-14 11:35:37 +02:00
#include "Graphics/Metal/Descriptor.h"
#include "Graphics/Metal/Pipeline.h"
#include "Graphics/Metal/PipelineCache.h"
#include "Graphics/Metal/Resources.h"
2024-04-10 09:58:39 +02:00
#include "RenderPass.h"
2024-04-14 11:35:37 +02:00
#include "Resources.h"
2024-06-09 12:20:04 +02:00
#include "Shader.h"
2024-04-09 16:41:12 +02:00
#include "Window.h"
2024-06-09 12:20:04 +02:00
2024-03-18 15:28:56 +01:00
using namespace Seele;
using namespace Seele::Metal;
2024-06-09 12:20:04 +02:00
Graphics::Graphics() {}
2024-04-09 16:41:12 +02:00
2024-06-09 12:20:04 +02:00
Graphics::~Graphics() {}
2024-04-09 16:41:12 +02:00
2024-06-09 12:20:04 +02:00
void Graphics::init(GraphicsInitializer) {
2024-04-15 13:48:34 +02:00
glfwInit();
2024-03-26 20:34:40 +01:00
device = MTL::CreateSystemDefaultDevice();
2024-04-10 09:58:39 +02:00
queue = new CommandQueue(this);
2024-04-10 15:50:20 +02:00
ioQueue = new IOCommandQueue(this);
2024-04-14 11:35:37 +02:00
cache = new PipelineCache(this, "pipelines.metal");
2024-05-17 18:08:11 +02:00
meshShadingEnabled = false;
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo &createInfo) {
2024-04-09 16:41:12 +02:00
return new Window(this, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-04-09 16:41:12 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner,
const ViewportCreateInfo &createInfo) {
2024-04-09 16:41:12 +02:00
return new Viewport(owner, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::ORenderPass
Graphics::createRenderPass(Gfx::RenderTargetLayout layout,
Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport renderArea) {
2024-04-10 08:43:56 +02:00
return new RenderPass(this, layout, dependencies, renderArea);
2024-03-18 15:28:56 +01:00
}
2024-04-09 16:41:12 +02:00
2024-06-09 12:20:04 +02:00
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) {
2024-04-10 09:58:39 +02:00
queue->getCommands()->beginRenderPass(renderPass.cast<RenderPass>());
2024-03-18 15:28:56 +01:00
}
2024-04-10 08:43:56 +02:00
2024-06-09 12:20:04 +02:00
void Graphics::endRenderPass() { queue->getCommands()->endRenderPass(); }
2024-04-10 09:58:39 +02:00
2024-06-09 12:20:04 +02:00
void Graphics::waitDeviceIdle() { queue->getCommands()->waitDeviceIdle(); }
2024-03-18 15:28:56 +01:00
2024-06-09 12:20:04 +02:00
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) {
2024-04-17 14:33:06 +02:00
queue->executeCommands(std::move(commands));
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) {
queue->executeCommands(std::move(commands));
}
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo &createInfo) {
2024-04-10 09:58:39 +02:00
return new Texture2D(this, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo &createInfo) {
2024-04-10 09:58:39 +02:00
return new Texture3D(this, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OTextureCube
Graphics::createTextureCube(const TextureCreateInfo &createInfo) {
2024-04-10 09:58:39 +02:00
return new TextureCube(this, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OUniformBuffer
Graphics::createUniformBuffer(const UniformBufferCreateInfo &bulkData) {
2024-04-13 23:51:38 +02:00
return new UniformBuffer(this, bulkData);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OShaderBuffer
Graphics::createShaderBuffer(const ShaderBufferCreateInfo &bulkData) {
2024-04-13 23:51:38 +02:00
return new ShaderBuffer(this, bulkData);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OVertexBuffer
Graphics::createVertexBuffer(const VertexBufferCreateInfo &bulkData) {
2024-04-13 23:51:38 +02:00
return new VertexBuffer(this, bulkData);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OIndexBuffer
Graphics::createIndexBuffer(const IndexBufferCreateInfo &bulkData) {
2024-04-13 23:51:38 +02:00
return new IndexBuffer(this, bulkData);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string &name) {
2024-04-10 10:23:06 +02:00
return queue->getRenderCommand(name);
2024-03-18 15:28:56 +01:00
}
2024-04-10 10:23:06 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string &name) {
2024-04-10 10:23:06 +02:00
return queue->getComputeCommand(name);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::OVertexShader
Graphics::createVertexShader(const ShaderCreateInfo &createInfo) {
2024-04-13 23:51:38 +02:00
OVertexShader result = new VertexShader(this);
result->create(createInfo);
return result;
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OFragmentShader
Graphics::createFragmentShader(const ShaderCreateInfo &createInfo) {
2024-04-13 23:51:38 +02:00
OFragmentShader result = new FragmentShader(this);
result->create(createInfo);
return result;
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OComputeShader
Graphics::createComputeShader(const ShaderCreateInfo &createInfo) {
2024-04-12 09:27:30 +02:00
OComputeShader result = new ComputeShader(this);
result->create(createInfo);
return result;
2024-03-18 15:28:56 +01:00
}
2024-04-12 09:27:30 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OMeshShader
Graphics::createMeshShader(const ShaderCreateInfo &createInfo) {
2024-04-12 09:27:30 +02:00
OMeshShader result = new MeshShader(this);
result->create(createInfo);
return result;
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OTaskShader
Graphics::createTaskShader(const ShaderCreateInfo &createInfo) {
2024-04-13 23:51:38 +02:00
OTaskShader result = new TaskShader(this);
result->create(createInfo);
return result;
2024-03-18 15:28:56 +01:00
}
2024-04-13 23:51:38 +02:00
2024-06-09 12:20:04 +02:00
Gfx::PGraphicsPipeline
Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
2024-04-14 11:35:37 +02:00
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-04-13 23:51:38 +02:00
2024-06-09 12:20:04 +02:00
Gfx::PGraphicsPipeline
Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
2024-04-14 11:35:37 +02:00
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::PComputePipeline
Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
2024-04-14 11:35:37 +02:00
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo &createInfo) {
2024-04-14 11:35:37 +02:00
return new Sampler(this, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::ODescriptorLayout
Graphics::createDescriptorLayout(const std::string &name) {
2024-04-14 11:35:37 +02:00
return new DescriptorLayout(this, name);
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-06-09 12:20:04 +02:00
Gfx::OPipelineLayout
Graphics::createPipelineLayout(const std::string &name,
Gfx::PPipelineLayout baseLayout) {
2024-04-20 21:35:43 +02:00
return new PipelineLayout(this, name, baseLayout);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
Gfx::OVertexInput
Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) {
2024-04-14 11:35:37 +02:00
return new VertexInput(createInfo);
2024-03-18 15:28:56 +01:00
}
2024-06-09 12:20:04 +02:00
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {
2024-03-18 15:28:56 +01:00
}