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

200 lines
7.8 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-08-28 17:54:14 +02:00
#include "Graphics/Graphics.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"
2024-08-28 17:54:14 +02:00
#include "Graphics/Metal/Query.h"
2024-04-14 11:35:37 +02:00
#include "Graphics/Metal/Resources.h"
2024-08-28 17:54:14 +02:00
#include "Graphics/slang-compile.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-08-26 21:49:09 +02:00
#include <slang.h>
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-08-28 17:54:14 +02:00
glfwInit();
device = MTL::CreateSystemDefaultDevice();
queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this);
cache = new PipelineCache(this, "pipelines.metal");
meshShadingEnabled = true;
2024-03-18 15:28:56 +01:00
}
2024-08-28 17:54:14 +02:00
Gfx::OWindow Graphics::createWindow(const WindowCreateInfo& createInfo) { return new Window(this, createInfo); }
Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreateInfo& createInfo) {
return new Viewport(owner, createInfo);
2024-03-18 15:28:56 +01:00
}
2024-04-09 16:41:12 +02:00
2024-08-28 17:54:14 +02:00
Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array<Gfx::SubPassDependency> dependencies,
Gfx::PViewport renderArea, std::string name) {
return new RenderPass(this, layout, dependencies, renderArea, name);
2024-03-18 15:28:56 +01:00
}
2024-08-28 17:54:14 +02:00
void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { queue->getCommands()->beginRenderPass(renderPass.cast<RenderPass>()); }
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-08-28 17:54:14 +02:00
void Graphics::executeCommands(Array<Gfx::ORenderCommand> commands) { queue->executeCommands(std::move(commands)); }
void Graphics::executeCommands(Gfx::OComputeCommand commands) {
Array<Gfx::OComputeCommand> command;
command.add(std::move(commands));
queue->executeCommands(std::move(command));
2024-03-18 15:28:56 +01:00
}
2024-08-28 17:54:14 +02:00
void Graphics::executeCommands(Array<Gfx::OComputeCommand> commands) { queue->executeCommands(std::move(commands)); }
2024-06-09 12:20:04 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OTexture2D Graphics::createTexture2D(const TextureCreateInfo& createInfo) { return new Texture2D(this, createInfo); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OTexture3D Graphics::createTexture3D(const TextureCreateInfo& createInfo) { return new Texture3D(this, createInfo); }
2024-06-09 12:20:04 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OTextureCube Graphics::createTextureCube(const TextureCreateInfo& createInfo) { return new TextureCube(this, createInfo); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OUniformBuffer Graphics::createUniformBuffer(const UniformBufferCreateInfo& bulkData) { return new UniformBuffer(this, bulkData); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OShaderBuffer Graphics::createShaderBuffer(const ShaderBufferCreateInfo& bulkData) { return new ShaderBuffer(this, bulkData); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OVertexBuffer Graphics::createVertexBuffer(const VertexBufferCreateInfo& bulkData) { return new VertexBuffer(this, bulkData); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OIndexBuffer Graphics::createIndexBuffer(const IndexBufferCreateInfo& bulkData) { return new IndexBuffer(this, bulkData); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
Gfx::ORenderCommand Graphics::createRenderCommand(const std::string& name) { return queue->getRenderCommand(name); }
2024-03-18 15:28:56 +01:00
2024-08-28 17:54:14 +02:00
Gfx::OComputeCommand Graphics::createComputeCommand(const std::string& name) { return queue->getComputeCommand(name); }
2024-04-10 10:23:06 +02:00
2024-08-28 17:54:14 +02:00
void Graphics::beginShaderCompilation(const ShaderCompilationInfo& compileInfo) {
2024-08-26 21:49:09 +02:00
beginCompilation(compileInfo, SLANG_METAL, compileInfo.rootSignature);
}
2024-08-28 17:54:14 +02:00
Gfx::OVertexShader Graphics::createVertexShader(const ShaderCreateInfo& createInfo) {
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-08-28 17:54:14 +02:00
Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& createInfo) {
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-08-28 17:54:14 +02:00
Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo) {
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-08-28 17:54:14 +02:00
Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo) {
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-08-28 17:54:14 +02:00
Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo) {
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-08-28 17:54:14 +02:00
Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-04-13 23:51:38 +02:00
2024-08-28 17:54:14 +02:00
Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-04-14 11:35:37 +02:00
2024-08-28 17:54:14 +02:00
Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
return cache->createPipeline(std::move(createInfo));
2024-03-18 15:28:56 +01:00
}
2024-09-16 13:00:53 +02:00
Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo) { return nullptr; }
2024-08-28 17:54:14 +02:00
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); }
Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name) { return new DescriptorLayout(this, name); }
Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout) {
return new PipelineLayout(this, name, baseLayout);
2024-08-26 21:49:09 +02:00
}
2024-04-14 11:35:37 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo) { return new VertexInput(createInfo); }
2024-03-18 15:28:56 +01:00
2024-08-28 17:54:14 +02:00
Gfx::OOcclusionQuery Graphics::createOcclusionQuery(const std::string& name) { return new OcclusionQuery(this, name); }
2024-08-26 21:49:09 +02:00
Gfx::OPipelineStatisticsQuery Graphics::createPipelineStatisticsQuery(const std::string& name) {
2024-08-28 17:54:14 +02:00
return new PipelineStatisticsQuery(this, name);
2024-08-26 21:49:09 +02:00
}
Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const std::string& name) {
2024-08-28 17:54:14 +02:00
return new TimestampQuery(this, name, numTimestamps);
2024-08-26 21:49:09 +02:00
}
2024-11-01 21:04:06 +01:00
void Graphics::beginDebugRegion(const std::string& name) {
queue->getCommands()->getHandle()->pushDebugGroup(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
}
void Graphics::endDebugRegion() {
queue->getCommands()->getHandle()->popDebugGroup();
}
2024-09-16 13:00:53 +02:00
void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {}
2024-08-26 21:49:09 +02:00
2024-09-16 13:00:53 +02:00
void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {}
2024-08-26 21:49:09 +02:00
2024-11-01 21:04:06 +01:00
void Graphics::copyBuffer(Gfx::PShaderBuffer src, Gfx::PShaderBuffer dst)
{
// TODO blit commands
}
2024-08-26 21:49:09 +02:00
// Ray Tracing
2024-08-28 17:54:14 +02:00
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; }
2024-08-26 21:49:09 +02:00
2024-08-28 17:54:14 +02:00
Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; }
2024-08-26 21:49:09 +02:00
2024-09-16 13:00:53 +02:00
void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>) {}
2024-08-26 21:49:09 +02:00
Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) {
ORayGenShader shader = new RayGenShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OAnyHitShader Graphics::createAnyHitShader(const ShaderCreateInfo& createInfo) {
OAnyHitShader shader = new AnyHitShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OClosestHitShader Graphics::createClosestHitShader(const ShaderCreateInfo& createInfo) {
OClosestHitShader shader = new ClosestHitShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OMissShader Graphics::createMissShader(const ShaderCreateInfo& createInfo) {
OMissShader shader = new MissShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OIntersectionShader Graphics::createIntersectionShader(const ShaderCreateInfo& createInfo) {
OIntersectionShader shader = new IntersectionShader(this);
shader->create(createInfo);
return shader;
}
Gfx::OCallableShader Graphics::createCallableShader(const ShaderCreateInfo& createInfo) {
OCallableShader shader = new CallableShader(this);
shader->create(createInfo);
return shader;
}