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
+2 -2
View File
@@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false;
static constexpr bool useMeshShading = true;
static constexpr uint32 numFramesBuffered = 3;
static constexpr uint32 numVerticesPerMeshlet = 256;
static constexpr uint32 numPrimitivesPerMeshlet = 256;
static constexpr uint32 numVerticesPerMeshlet = 64;
static constexpr uint32 numPrimitivesPerMeshlet = 126;
double getCurrentFrameDelta();
double getCurrentFrameTime();
uint32 getCurrentFrameIndex();
+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()));
+1 -1
View File
@@ -90,7 +90,7 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
metalWindow.contentView.layer = metalLayer;
metalWindow.contentView.wantsLayer = YES;
framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM;
framebufferFormat = Gfx::SE_FORMAT_B8G8R8A8_UNORM;
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
createBackBuffer();
@@ -176,9 +176,14 @@ void DepthCullingPass::render() {
command->bindPipeline(pipeline);
}
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet(), set});
uint32 offset = 0;
VertexData::DrawCallOffsets offsets = {
.instanceOffset = 0,
.floatOffset = 0,
.samplerOffset = 0,
.textureOffset = 0,
};
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offset);
&offsets);
if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1);
} else {
@@ -248,7 +248,7 @@ void LightCullingPass::setupFrustums() {
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(DispatchParams),
.uniformLength = 56,//sizeof(DispatchParams),
});
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
@@ -264,6 +264,7 @@ void LightCullingPass::setupFrustums() {
.modules = {"ComputeFrustums"},
.entryPoints = {{"computeFrustums", "ComputeFrustums"}},
.rootSignature = frustumLayout,
.dumpIntermediate = true,
};
graphics->beginShaderCompilation(createInfo);
frustumShader = graphics->createComputeShader({0});
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene) : graphics(graphic
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(ViewParameter),
.uniformLength = 576,//sizeof(ViewParameter),
});
UniformBufferCreateInfo uniformInitializer = {
.sourceData =