diff --git a/.vscode/settings.json b/.vscode/settings.json index 241188a..addf36c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,7 +22,7 @@ "lldb.showDisassembly": "auto", "lldb.dereferencePointers": true, "lldb.consoleMode": "commands", - "cmake.generator": "Unix Makefiles", + "cmake.generator": "Xcode", "editor.tabSize": 4, "slang.additionalSearchPaths": [ "res/shaders/", diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 6dbfa5d..03359db 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -27,8 +27,8 @@ struct MeshData PoolRange indicesRange; }; -static const uint32_t MAX_VERTICES = 256; -static const uint32_t MAX_PRIMITIVES = 256; +static const uint32_t MAX_VERTICES = 128; +static const uint32_t MAX_PRIMITIVES = 128; struct InstanceData { diff --git a/res/shaders/lib/StaticMeshVertexData.slang b/res/shaders/lib/StaticMeshVertexData.slang index 5327398..0fee1cc 100644 --- a/res/shaders/lib/StaticMeshVertexData.slang +++ b/res/shaders/lib/StaticMeshVertexData.slang @@ -3,7 +3,7 @@ import VertexData; import MaterialParameter; import Scene; -struct StaticMeshVertexData : IVertexData +struct StaticMeshVertexData { float uint16ToFloat(uint16_t value) { @@ -34,3 +34,5 @@ struct StaticMeshVertexData : IVertexData StructuredBuffer color; StructuredBuffer texCoords[MAX_TEXCOORDS]; }; +layout(set = 1) +ParameterBlock pVertexData; \ No newline at end of file diff --git a/res/shaders/lib/VertexData.slang b/res/shaders/lib/VertexData.slang index 1fddec4..cb72220 100644 --- a/res/shaders/lib/VertexData.slang +++ b/res/shaders/lib/VertexData.slang @@ -6,9 +6,9 @@ struct VertexInput uint instanceId: SV_InstanceID; } -interface IVertexData -{ - VertexAttributes getAttributes(uint index); -}; -layout(set = 1) -ParameterBlock pVertexData; \ No newline at end of file +//interface IVertexData +//{ +// VertexAttributes getAttributes(uint index); +//}; +//layout(set = 1) +//ParameterBlock pVertexData; \ No newline at end of file diff --git a/src/Editor/Asset/EnvironmentLoader.cpp b/src/Editor/Asset/EnvironmentLoader.cpp index 3e64686..26b644c 100644 --- a/src/Editor/Asset/EnvironmentLoader.cpp +++ b/src/Editor/Asset/EnvironmentLoader.cpp @@ -38,10 +38,12 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic cubeRenderLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = "view", .uniformLength = sizeof(Matrix4) * 6, + .descriptorCount = 24, }); cubeRenderLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = "projection", .uniformLength = sizeof(Matrix4), + .descriptorCount = 4, }); cubeRenderLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = "equirectangularMap", diff --git a/src/Engine/Graphics/Enums.h b/src/Engine/Graphics/Enums.h index fe396ef..1031839 100644 --- a/src/Engine/Graphics/Enums.h +++ b/src/Engine/Graphics/Enums.h @@ -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 = 128; +static constexpr uint32 numPrimitivesPerMeshlet = 128; static constexpr uint32 numMeshletsPerTask = 256; double getCurrentFrameDelta(); double getCurrentFrameTime(); diff --git a/src/Engine/Graphics/Metal/PipelineCache.mm b/src/Engine/Graphics/Metal/PipelineCache.mm index 4e70fbf..37b33cb 100644 --- a/src/Engine/Graphics/Metal/PipelineCache.mm +++ b/src/Engine/Graphics/Metal/PipelineCache.mm @@ -195,6 +195,20 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea desc->setBlendingEnabled(false); pipelineDescriptor->colorAttachments()->setObject(desc, c); } + MTL::DepthStencilDescriptor* depthDescriptor = MTL::DepthStencilDescriptor::alloc()->init(); + if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) { + depthDescriptor->setDepthWriteEnabled(createInfo.depthStencilState.depthWriteEnable); + depthDescriptor->setDepthCompareFunction(cast(createInfo.depthStencilState.depthCompareOp)); + pipelineDescriptor->setDepthAttachmentPixelFormat( + cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast()->getFormat())); + } + pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable); + pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable); + pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples); + pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable); + + MTL::DepthStencilState* depthState = graphics->getDevice()->newDepthStencilState(depthDescriptor); + depthDescriptor->release(); if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) { pipelineDescriptor->setDepthAttachmentPixelFormat( cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast()->getFormat())); @@ -228,6 +242,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo crea graphicsPipelines[hash]->meshFunction = meshFunction; graphicsPipelines[hash]->fragmentSets = fragmentSets; graphicsPipelines[hash]->fragmentFunction = fragmentFunction; + graphicsPipelines[hash]->depth = depthState; return graphicsPipelines[hash]; } diff --git a/src/Engine/Graphics/Metal/Resources.mm b/src/Engine/Graphics/Metal/Resources.mm index 91885e5..0f42871 100644 --- a/src/Engine/Graphics/Metal/Resources.mm +++ b/src/Engine/Graphics/Metal/Resources.mm @@ -35,7 +35,7 @@ Event::Event(PGraphics graphics) : handle(graphics->getDevice()->newEvent()) {} Event::~Event() { handle->release(); } -Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo) { +Sampler::Sampler(PGraphics graphics, const SamplerCreateInfo& createInfo) : Gfx::Sampler(createInfo) { MTL::SamplerDescriptor* desc = MTL::SamplerDescriptor::alloc()->init(); desc->setBorderColor(cast(createInfo.borderColor)); desc->setCompareFunction(cast(createInfo.compareOp)); diff --git a/src/Engine/Graphics/Metal/Texture.h b/src/Engine/Graphics/Metal/Texture.h index 752dc3e..ba78f37 100644 --- a/src/Engine/Graphics/Metal/Texture.h +++ b/src/Engine/Graphics/Metal/Texture.h @@ -43,6 +43,7 @@ class TextureBase { uint32 getWidth() const { return handle->width; } uint32 getHeight() const { return handle->height; } uint32 getDepth() const { return handle->depth; } + uint32 getNumLayers() const { return handle->arrayCount; } PTextureHandle getHandle() const { return handle; } MTL::Texture* getImage() const { return handle->texture; }; constexpr Gfx::SeImageLayout getLayout() const { return handle->layout; } @@ -78,6 +79,7 @@ class Texture2D : public Gfx::Texture2D, public TextureBase { virtual uint32 getWidth() const override { return handle->width; } virtual uint32 getHeight() const override { return handle->height; } virtual uint32 getDepth() const override { return handle->depth; } + virtual uint32 getNumLayers() const override { return handle->arrayCount; } virtual Gfx::SeFormat getFormat() const override { return handle->format; } virtual Gfx::SeSampleCountFlags getNumSamples() const override { return handle->samples; } virtual uint32 getMipLevels() const override { return handle->mipLevels; } @@ -101,6 +103,7 @@ class Texture3D : public Gfx::Texture3D, public TextureBase { virtual uint32 getWidth() const override { return handle->width; } virtual uint32 getHeight() const override { return handle->height; } virtual uint32 getDepth() const override { return handle->depth; } + virtual uint32 getNumLayers() const override { return handle->arrayCount; } virtual Gfx::SeFormat getFormat() const override { return handle->format; } virtual Gfx::SeSampleCountFlags getNumSamples() const override { return handle->samples; } virtual uint32 getMipLevels() const override { return handle->mipLevels; } @@ -124,6 +127,7 @@ class TextureCube : public Gfx::TextureCube, public TextureBase { virtual uint32 getWidth() const override { return handle->width; } virtual uint32 getHeight() const override { return handle->height; } virtual uint32 getDepth() const override { return handle->depth; } + virtual uint32 getNumLayers() const override { return handle->arrayCount; } virtual Gfx::SeFormat getFormat() const override { return handle->format; } virtual Gfx::SeSampleCountFlags getNumSamples() const override { return handle->samples; } virtual uint32 getMipLevels() const override { return handle->mipLevels; } diff --git a/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp b/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp index 1a24d88..9095f31 100644 --- a/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp +++ b/src/Engine/Graphics/RenderPass/ToneMappingPass.cpp @@ -3,7 +3,7 @@ using namespace Seele; ToneMappingPass::ToneMappingPass(Gfx::PGraphics graphics) : RenderPass(graphics) { - tonemappingLayout = graphics->createDescriptorLayout("ToneMappingDescriptor"); + tonemappingLayout = graphics->createDescriptorLayout("pToneMappingParams"); tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{ .name = "offset", .uniformLength = sizeof(Vector4), diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index cccc76e..7dd4ba7 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -124,7 +124,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline { createInfo.dumpIntermediate = true; } - createInfo.typeParameter.add({Pair("IVertexData", permutation.vertexDataName)}); + //createInfo.typeParameter.add({Pair("IVertexData", permutation.vertexDataName)}); createInfo.modules.add(permutation.vertexDataName); //createInfo.dumpIntermediate = true;