More metal changes

This commit is contained in:
Dynamitos
2024-11-02 22:19:08 +01:00
parent 32d3bd8ad8
commit 3c9465de49
10 changed files with 50 additions and 30 deletions
+23 -2
View File
@@ -1,6 +1,7 @@
#include "PipelineCache.h"
#include "Descriptor.h"
#include "Enums.h"
#include "RenderPass.h"
#include "Foundation/NSError.hpp"
#include "Foundation/NSString.hpp"
#include "Graphics.h"
@@ -25,8 +26,7 @@ PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : grap
PipelineCache::~PipelineCache() {}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
PRenderPass renderPass = createInfo.renderPass.cast<RenderPass>();
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
@@ -68,6 +68,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) {
const auto& color = renderPass->getLayout().colorAttachments[c];
MTL::RenderPipelineColorAttachmentDescriptor* desc = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
desc->setWriteMask(MTL::ColorWriteMaskAll);
desc->setPixelFormat(cast(color.getFormat()));
desc->setAlphaBlendOperation(MTL::BlendOperationAdd);
desc->setDestinationAlphaBlendFactor(MTL::BlendFactorDestinationAlpha);
desc->setBlendingEnabled(false);
pipelineDescriptor->colorAttachments()->setObject(desc, c);
}
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
@@ -131,6 +141,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
}
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
PRenderPass renderPass = createInfo.renderPass.cast<RenderPass>();
MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
@@ -140,6 +151,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea
if (createInfo.fragmentShader != nullptr) {
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
}
for(uint c = 0; c < renderPass->getLayout().colorAttachments.size(); ++c) {
const auto& color = renderPass->getLayout().colorAttachments[c];
MTL::RenderPipelineColorAttachmentDescriptor* desc = MTL::RenderPipelineColorAttachmentDescriptor::alloc()->init();
desc->setWriteMask(MTL::ColorWriteMaskAll);
desc->setPixelFormat(cast(color.getFormat()));
desc->setAlphaBlendOperation(MTL::BlendOperationAdd);
desc->setDestinationAlphaBlendFactor(MTL::BlendFactorDestinationAlpha);
desc->setBlendingEnabled(false);
pipelineDescriptor->colorAttachments()->setObject(desc, c);
}
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
pipelineDescriptor->setDepthAttachmentPixelFormat(
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));