diff --git a/.vscode/settings.json b/.vscode/settings.json index fdd9d93..6d5f35d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,5 +24,6 @@ "lldb.displayFormat": "auto", "lldb.showDisassembly": "auto", "lldb.dereferencePointers": true, - "lldb.consoleMode": "commands" + "lldb.consoleMode": "commands", + "cmake.generator": "Ninja" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b259f1d..60b321e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,8 +99,8 @@ target_include_directories(AssetViewer PRIVATE src/AssetViewer) if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) - target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG /wd4505) - target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG) + target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /wd4505 /fsanitize=address) + target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /fsanitize=address) target_sources(Engine INTERFACE $ $ @@ -108,6 +108,8 @@ if(MSVC) install(FILES Seele.natvis DESTINATION Seele/) + target_link_options(Engine PUBLIC /fsanitize=address /DEBUG) + target_link_options(Editor PUBLIC /fsanitize=address /DEBUG) else() target_compile_options(Engine PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -Wno-missing-field-initializers -Wno-unused-function -fsanitize=address) target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -fsanitize=address) diff --git a/cmake-variants.json b/cmake-variants.json index 1c67b3c..17db80a 100644 --- a/cmake-variants.json +++ b/cmake-variants.json @@ -3,6 +3,11 @@ "default": "debug", "description": "Configuration Type", "choices": { + "asan": { + "short": "ASan", + "long": "Address Sanitizer", + "buildType": "Asan" + }, "debug": { "short": "Debug", "long": "Enable debugging and validation", diff --git a/res/shaders/DepthCullingTask.slang b/res/shaders/DepthCullingTask.slang new file mode 100644 index 0000000..ddb7f4d --- /dev/null +++ b/res/shaders/DepthCullingTask.slang @@ -0,0 +1,49 @@ +import Common; +import Scene; + +groupshared MeshPayload p; +groupshared uint head; +groupshared Frustum viewFrustum; + +[numthreads(TASK_GROUP_SIZE, 1, 1)] +[outputtopology("triangle")] +[shader("amplification")] +void taskMain( + uint threadID: SV_GroupIndex, + uint groupID: SV_GroupID +){ + InstanceData instance = pScene.instances[pOffsets.instanceOffset + groupID]; + MeshData mesh = pScene.meshData[pOffsets.instanceOffset + groupID]; + if(threadID == 0) + { + head = 0; + float3 origin = viewToModel(instance.inverseTransformMatrix, float4(0, 0, 0, 1)).xyz; + const float offset = 0.0f; + float3 corners[4] = { + screenToModel(instance.inverseTransformMatrix, float4(offset, offset, -1.0f, 1.0f)).xyz, + screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions.x - offset, offset, -1.0f, 1.0f)).xyz, + screenToModel(instance.inverseTransformMatrix, float4(offset, pViewParams.screenDimensions.y - offset, -1.0f, 1.0f)).xyz, + screenToModel(instance.inverseTransformMatrix, float4(pViewParams.screenDimensions - float2(offset, offset), -1.0f, 1.0f)).xyz + }; + viewFrustum.sides[0] = computePlane(origin, corners[2], corners[0]); + viewFrustum.sides[1] = computePlane(origin, corners[1], corners[3]); + viewFrustum.sides[2] = computePlane(origin, corners[0], corners[1]); + viewFrustum.sides[3] = computePlane(origin, corners[3], corners[2]); + p.instanceId = pOffsets.instanceOffset + groupID; + p.cullingOffset = pScene.cullingOffsets[pOffsets.cullingCounterOffset + groupID]; + } + GroupMemoryBarrierWithGroupSync(); + for(uint i = threadID; i < mesh.numMeshlets; i += TASK_GROUP_SIZE) + { + uint m = mesh.meshletOffset + i; + MeshletDescription meshlet = pScene.meshletInfos[m]; + if(meshlet.bounding.insideFrustum(viewFrustum)) + { + uint index; + InterlockedAdd(head, 1, index); + pScene.culledMeshlets[p.cullingOffset + index] = m; + } + } + GroupMemoryBarrierWithGroupSync(); + DispatchMesh(head, 1, 1, p); +} \ No newline at end of file diff --git a/res/shaders/MeshletPass.slang b/res/shaders/MeshletPass.slang index 70632d3..2914226 100644 --- a/res/shaders/MeshletPass.slang +++ b/res/shaders/MeshletPass.slang @@ -3,7 +3,6 @@ import Scene; import VertexData; import MaterialParameter; - struct PrimitiveAttributes { uint cull: SV_CullPrimitive; @@ -38,7 +37,12 @@ void meshMain( uint v = min(i, m.vertexCount - 1); { uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v]; +#ifdef POS_ONLY + VertexAttributes attr = pVertexData.getPosition(m.indicesOffset + vertexIndex); +#else VertexAttributes attr = pVertexData.getAttributes(m.indicesOffset + vertexIndex); +#endif + attr.meshletId = -1; vertices[v] = attr.getParameter(inst.transformMatrix); } diff --git a/res/shaders/ViewCullingTask.slang b/res/shaders/ViewCullingTask.slang index 0f6133f..ddb7f4d 100644 --- a/res/shaders/ViewCullingTask.slang +++ b/res/shaders/ViewCullingTask.slang @@ -37,7 +37,7 @@ void taskMain( { uint m = mesh.meshletOffset + i; MeshletDescription meshlet = pScene.meshletInfos[m]; - //if(meshlet.bounding.insideFrustum(viewFrustum)) + if(meshlet.bounding.insideFrustum(viewFrustum)) { uint index; InterlockedAdd(head, 1, index); diff --git a/res/shaders/lib/StaticMeshVertexData.slang b/res/shaders/lib/StaticMeshVertexData.slang index 7645dda..3764fca 100644 --- a/res/shaders/lib/StaticMeshVertexData.slang +++ b/res/shaders/lib/StaticMeshVertexData.slang @@ -18,6 +18,20 @@ struct StaticMeshVertexData : IVertexData attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]); return attributes; } + VertexAttributes getPosition(uint index) + { + VertexAttributes attributes; + attributes.position_MS = float3(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2]); + attributes.normal_MS = float3(0, 0, 0); + attributes.tangent_MS = float3(0, 0, 0); + attributes.biTangent_MS = float3(0, 0, 0); + for (uint i = 0; i < MAX_TEXCOORDS; ++i) + { + attributes.texCoords[i] = float2(0, 0); + } + attributes.vertexColor = float3(0, 0, 0); + return attributes; + } StructuredBuffer positions; StructuredBuffer normals; StructuredBuffer tangents; diff --git a/res/shaders/lib/VertexData.slang b/res/shaders/lib/VertexData.slang index 0d41e67..84b4a7e 100644 --- a/res/shaders/lib/VertexData.slang +++ b/res/shaders/lib/VertexData.slang @@ -8,7 +8,8 @@ struct VertexInput interface IVertexData { - VertexAttributes getAttributes(uint index); + VertexAttributes getAttributes(uint index); + VertexAttributes getPosition(uint index); }; layout(set=1) diff --git a/src/Engine/Containers/List.h b/src/Engine/Containers/List.h index eba6e24..79d2cf3 100644 --- a/src/Engine/Containers/List.h +++ b/src/Engine/Containers/List.h @@ -355,6 +355,12 @@ public: } destroyNode(pos.node); deallocateNode(pos.node); + if (_size == 0) + { + deallocateNode(tail); + root = nullptr; + tail = nullptr; + } markIteratorDirty(); return Iterator(next); } diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index e69985c..6bf33cf 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -40,11 +40,11 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) if (graphics->supportMeshShading()) { - graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", true, true, "BasePass", true, true, "ViewCullingTask"); + graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", false, true, true, "BasePass", true, true, "ViewCullingTask"); } else { - graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "LegacyPass", true, true, "BasePass"); + graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "LegacyPass", false, true, true, "BasePass"); } } @@ -210,7 +210,7 @@ void BasePass::publishOutputs() void BasePass::createRenderPass() { depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); - depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD); + depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR); depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL); depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index abf0ba0..9ecaae1 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -25,11 +25,11 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene) }); if (graphics->supportMeshShading()) { - graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true, true, "ViewCullingTask"); + graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", true, false, false, "", true, true, "ViewCullingTask"); } else { - graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass"); + graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true); } } @@ -48,6 +48,7 @@ void DepthPrepass::render() Array commands; Gfx::ShaderPermutation permutation; + permutation.setPositionOnly(); if (graphics->supportMeshShading()) { permutation.setTaskFile("ViewCullingTask"); diff --git a/src/Engine/Graphics/RenderPass/StaticBasePass.cpp b/src/Engine/Graphics/RenderPass/StaticBasePass.cpp index 3b8283a..7d99e60 100644 --- a/src/Engine/Graphics/RenderPass/StaticBasePass.cpp +++ b/src/Engine/Graphics/RenderPass/StaticBasePass.cpp @@ -22,11 +22,11 @@ StaticBasePass::StaticBasePass(Gfx::PGraphics graphics, PScene scene) basePassLayout->addDescriptorLayout(lightCullingLayout); if (graphics->supportMeshShading()) { - graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "StaticMeshletPass", true, true, "BasePass", true); + graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "StaticMeshletPass", false, true, true, "BasePass", true); } else { - graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", true, true, "BasePass"); + graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", false, true, true, "BasePass"); } } diff --git a/src/Engine/Graphics/RenderPass/StaticDepthPrepass.cpp b/src/Engine/Graphics/RenderPass/StaticDepthPrepass.cpp index a875e6e..7743b92 100644 --- a/src/Engine/Graphics/RenderPass/StaticDepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/StaticDepthPrepass.cpp @@ -16,11 +16,11 @@ StaticDepthPrepass::StaticDepthPrepass(Gfx::PGraphics graphics, PScene scene) depthPrepassLayout->addDescriptorLayout(meshletCullingLayout); if (graphics->supportMeshShading()) { - graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true); + graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", true, false, false, "", true); } else { - graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass"); + graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true); } } diff --git a/src/Engine/Graphics/Shader.cpp b/src/Engine/Graphics/Shader.cpp index 727a525..1db9eda 100644 --- a/src/Engine/Graphics/Shader.cpp +++ b/src/Engine/Graphics/Shader.cpp @@ -34,7 +34,15 @@ void ShaderCompiler::registerVertexData(VertexData* vd) compile(); } -void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string name, std::string mainFile, bool useMaterials, bool hasFragmentShader, std::string fragmentFile, bool useMeshShading, bool hasTaskShader, std::string taskFile) +void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, + std::string name, std::string mainFile, + bool positionOnly, + bool useMaterials, + bool hasFragmentShader, + std::string fragmentFile, + bool useMeshShading, + bool hasTaskShader, + std::string taskFile) { passes[name] = PassConfig{ .baseLayout = layout, @@ -45,6 +53,7 @@ void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string .useMeshShading = useMeshShading, .hasTaskShader = hasTaskShader, .useMaterial = useMaterials, + .positionOnly = positionOnly, }; compile(); } @@ -63,6 +72,10 @@ void ShaderCompiler::compile() { work.add([=]() { ShaderPermutation permutation; + if (pass.positionOnly) + { + permutation.setPositionOnly(); + } if (pass.useMeshShading) { permutation.setMeshFile(pass.mainFile); @@ -93,6 +106,10 @@ void ShaderCompiler::compile() { work.add([=]() { ShaderPermutation permutation; + if (pass.positionOnly) + { + permutation.setPositionOnly(); + } if (pass.useMeshShading) { permutation.setMeshFile(pass.mainFile); @@ -140,6 +157,10 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline createInfo.additionalModules.add(permutation.materialName); createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName; } + if (permutation.positionOnly) + { + createInfo.defines["POS_ONLY"] = "1"; + } createInfo.typeParameter.add({ Pair("IVertexData", permutation.vertexDataName) }); createInfo.additionalModules.add(permutation.vertexDataName); diff --git a/src/Engine/Graphics/Shader.h b/src/Engine/Graphics/Shader.h index f2b8406..d112f73 100644 --- a/src/Engine/Graphics/Shader.h +++ b/src/Engine/Graphics/Shader.h @@ -62,6 +62,7 @@ struct ShaderPermutation uint8 useMeshShading; uint8 hasTaskShader; uint8 useMaterial; + uint8 positionOnly; //TODO: lightmapping etc ShaderPermutation() { @@ -102,6 +103,10 @@ struct ShaderPermutation useMaterial = 1; strncpy(materialName, name.data(), sizeof(materialName)); } + void setPositionOnly() + { + positionOnly = true; + } }; //Hashed ShaderPermutation for fast lookup struct PermutationId @@ -141,6 +146,7 @@ public: void registerRenderPass(Gfx::PPipelineLayout baseLayout, std::string name, std::string mainFile, + bool positionOnly = true, bool useMaterials = false, bool hasFragmentShader = false, std::string fragmentFile = "", @@ -164,6 +170,7 @@ private: bool useMeshShading; bool hasTaskShader; bool useMaterial; + bool positionOnly; }; Map passes; Gfx::PGraphics graphics; diff --git a/src/Engine/Graphics/VertexData.cpp b/src/Engine/Graphics/VertexData.cpp index a1cb878..939a0a0 100644 --- a/src/Engine/Graphics/VertexData.cpp +++ b/src/Engine/Graphics/VertexData.cpp @@ -18,12 +18,16 @@ void VertexData::resetMeshData() std::unique_lock l(materialDataLock); for (auto& mat : materialData) { + for (auto inst : mat.instances) + { + inst.instanceData.clear(); + inst.instanceMeshData.clear(); + } if (mat.material != nullptr) { mat.material->getDescriptorLayout()->reset(); } } - materialData.clear(); if (dirty) { updateBuffers(); diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index c9a2a73..31dd51a 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -280,10 +280,10 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array(); assert(descriptor->writeDescriptors.size() == 0); - boundResources.add(descriptor.getHandle()); - descriptor->boundResources.clear(); - boundResources.addAll(descriptor->boundResources); descriptor->bind(); + boundResources.add(descriptor.getHandle()); + boundResources.addAll(descriptor->boundResources); + descriptor->boundResources.clear(); VkDescriptorSet setHandle = descriptor->getHandle(); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 9c1b727..8f3b06b 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -416,6 +416,7 @@ void PipelineLayout::create() { std::unique_lock l(layoutLock); if (cachedLayouts.contains(layoutHash)) { + std::cout << "New Layout" << std::endl; layoutHandle = cachedLayouts[layoutHash]; return; } diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index 9915f1b..8af581f 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -261,10 +261,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxInfo) { + uint32 hash = CRC::Calculate(&gfxInfo, sizeof(Gfx::MeshPipelineCreateInfo), CRC::CRC_32()); + if (graphicsPipelines.contains(hash)) + { + return graphicsPipelines[hash]; + } PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast(); - uint32 hash = layout->getHash(); + //uint32 hash = layout->getHash(); uint32 stageCount = 0; + VkPipelineShaderStageCreateInfo stageInfos[3]; std::memset(stageInfos, 0, sizeof(stageInfos)); @@ -273,18 +279,24 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI PTaskShader taskShader = gfxInfo.taskShader.cast(); stageInfos[stageCount++] = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .pNext = nullptr, + .flags = 0, .stage = VK_SHADER_STAGE_TASK_BIT_EXT, .module = taskShader->getModuleHandle(), .pName = taskShader->getEntryPointName(), + .pSpecializationInfo = nullptr, }; } PMeshShader meshShader = gfxInfo.meshShader.cast(); stageInfos[stageCount++] = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .pNext = nullptr, + .flags = 0, .stage = VK_SHADER_STAGE_MESH_BIT_EXT, .module = meshShader->getModuleHandle(), .pName = meshShader->getEntryPointName(), + .pSpecializationInfo = nullptr, }; if (gfxInfo.fragmentShader != nullptr) @@ -293,21 +305,26 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI stageInfos[stageCount++] = { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .pNext = nullptr, + .flags = 0, .stage = VK_SHADER_STAGE_FRAGMENT_BIT, .module = fragment->getModuleHandle(), .pName = fragment->getEntryPointName(), + .pSpecializationInfo = nullptr, }; } - hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash); + //hash = CRC::Calculate(stageInfos, sizeof(stageInfos), CRC::CRC_32(), hash); VkPipelineViewportStateCreateInfo viewportInfo = { .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, .pNext = nullptr, .flags = 0, .viewportCount = 1, + .pViewports = nullptr, .scissorCount = 1, + .pScissors = nullptr, }; - hash = CRC::Calculate(&viewportInfo, sizeof(viewportInfo), CRC::CRC_32(), hash); + //hash = CRC::Calculate(&viewportInfo, sizeof(VkPipelineViewportStateCreateInfo), CRC::CRC_32(), hash); VkPipelineRasterizationStateCreateInfo rasterizationState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, .pNext = nullptr, @@ -323,7 +340,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI .depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor, .lineWidth = 0, }; - hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash); + //hash = CRC::Calculate(&rasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo), CRC::CRC_32(), hash); VkPipelineMultisampleStateCreateInfo multisampleState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, @@ -332,10 +349,11 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI .rasterizationSamples = (VkSampleCountFlagBits)gfxInfo.multisampleState.samples, .sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable, .minSampleShading = gfxInfo.multisampleState.minSampleShading, + .pSampleMask = nullptr, .alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable, .alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable, }; - hash = CRC::Calculate(&multisampleState, sizeof(multisampleState), CRC::CRC_32(), hash); + //hash = CRC::Calculate(&multisampleState, sizeof(VkPipelineMultisampleStateCreateInfo), CRC::CRC_32(), hash); VkPipelineDepthStencilStateCreateInfo depthStencilState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, @@ -345,12 +363,29 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI .depthWriteEnable = gfxInfo.depthStencilState.depthWriteEnable, .depthCompareOp = cast(gfxInfo.depthStencilState.depthCompareOp), .depthBoundsTestEnable = gfxInfo.depthStencilState.depthBoundsTestEnable, - .front = {(VkStencilOp)gfxInfo.depthStencilState.front}, - .back = {(VkStencilOp)gfxInfo.depthStencilState.back}, + .stencilTestEnable = gfxInfo.depthStencilState.stencilTestEnable, + .front = VkStencilOpState{ + .failOp = VK_STENCIL_OP_ZERO, + .passOp = (VkStencilOp)gfxInfo.depthStencilState.front, + .depthFailOp = VK_STENCIL_OP_ZERO, + .compareOp = VK_COMPARE_OP_ALWAYS, + .compareMask = 0, + .writeMask = 0, + .reference = 0, + }, + .back = VkStencilOpState{ + .failOp = VK_STENCIL_OP_ZERO, + .passOp = (VkStencilOp)gfxInfo.depthStencilState.back, + .depthFailOp = VK_STENCIL_OP_ZERO, + .compareOp = VK_COMPARE_OP_ALWAYS, + .compareMask = 0, + .writeMask = 0, + .reference = 0, + }, .minDepthBounds = gfxInfo.depthStencilState.minDepthBounds, .maxDepthBounds = gfxInfo.depthStencilState.maxDepthBounds, }; - hash = CRC::Calculate(&depthStencilState, sizeof(depthStencilState), CRC::CRC_32(), hash); + //hash = CRC::Calculate(&depthStencilState, sizeof(VkPipelineDepthStencilStateCreateInfo), CRC::CRC_32(), hash); Array blendAttachments; for (uint32 i = 0; i < gfxInfo.colorBlend.attachmentCount; ++i) @@ -367,7 +402,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI .colorWriteMask = attachment.colorWriteMask, }; } - hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash); + //hash = CRC::Calculate(blendAttachments.data(), blendAttachments.size() * sizeof(VkPipelineColorBlendAttachmentState), CRC::CRC_32(), hash); VkPipelineColorBlendStateCreateInfo blendState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, @@ -384,7 +419,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI StaticArray dynamicEnabled; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; - hash = CRC::Calculate(dynamicEnabled.data(), dynamicEnabled.size() * sizeof(VkDynamicState), CRC::CRC_32(), hash); + //hash = CRC::Calculate(dynamicEnabled.data(), sizeof(dynamicEnabled), CRC::CRC_32(), hash); VkPipelineDynamicStateCreateInfo dynamicState = { .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, @@ -392,11 +427,6 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI .dynamicStateCount = (uint32)dynamicEnabled.size(), .pDynamicStates = dynamicEnabled.data(), }; - - if (graphicsPipelines.contains(hash)) - { - return graphicsPipelines[hash]; - } VkPipeline pipelineHandle; VkGraphicsPipelineCreateInfo createInfo = { diff --git a/src/Engine/ThreadPool.cpp b/src/Engine/ThreadPool.cpp index 6578445..52cd6ab 100644 --- a/src/Engine/ThreadPool.cpp +++ b/src/Engine/ThreadPool.cpp @@ -57,6 +57,7 @@ void ThreadPool::work() currentTask.numRemaining--; if (currentTask.numRemaining == 0) { + currentTask.functions.clear(); completedCV.notify_one(); } }