Lot of changes

This commit is contained in:
Dynamitos
2024-05-16 19:47:35 +02:00
parent 7690434f2b
commit 5fd41b8388
20 changed files with 182 additions and 35 deletions
+2 -1
View File
@@ -24,5 +24,6 @@
"lldb.displayFormat": "auto", "lldb.displayFormat": "auto",
"lldb.showDisassembly": "auto", "lldb.showDisassembly": "auto",
"lldb.dereferencePointers": true, "lldb.dereferencePointers": true,
"lldb.consoleMode": "commands" "lldb.consoleMode": "commands",
"cmake.generator": "Ninja"
} }
+4 -2
View File
@@ -99,8 +99,8 @@ target_include_directories(AssetViewer PRIVATE src/AssetViewer)
if(MSVC) if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG /wd4505) 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 /DEBUG) target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /fsanitize=address)
target_sources(Engine INTERFACE target_sources(Engine INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele/Seele.natvis> $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele/Seele.natvis>
@@ -108,6 +108,8 @@ if(MSVC)
install(FILES install(FILES
Seele.natvis Seele.natvis
DESTINATION Seele/) DESTINATION Seele/)
target_link_options(Engine PUBLIC /fsanitize=address /DEBUG)
target_link_options(Editor PUBLIC /fsanitize=address /DEBUG)
else() 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(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) target_compile_options(Editor PUBLIC -g -Wall -Wextra -Wno-error -pedantic -std=c++20 -fsanitize=address)
+5
View File
@@ -3,6 +3,11 @@
"default": "debug", "default": "debug",
"description": "Configuration Type", "description": "Configuration Type",
"choices": { "choices": {
"asan": {
"short": "ASan",
"long": "Address Sanitizer",
"buildType": "Asan"
},
"debug": { "debug": {
"short": "Debug", "short": "Debug",
"long": "Enable debugging and validation", "long": "Enable debugging and validation",
+49
View File
@@ -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);
}
+5 -1
View File
@@ -3,7 +3,6 @@ import Scene;
import VertexData; import VertexData;
import MaterialParameter; import MaterialParameter;
struct PrimitiveAttributes struct PrimitiveAttributes
{ {
uint cull: SV_CullPrimitive; uint cull: SV_CullPrimitive;
@@ -38,7 +37,12 @@ void meshMain(
uint v = min(i, m.vertexCount - 1); uint v = min(i, m.vertexCount - 1);
{ {
uint vertexIndex = pScene.vertexIndices[m.vertexOffset + v]; 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); VertexAttributes attr = pVertexData.getAttributes(m.indicesOffset + vertexIndex);
#endif
attr.meshletId = -1; attr.meshletId = -1;
vertices[v] = attr.getParameter(inst.transformMatrix); vertices[v] = attr.getParameter(inst.transformMatrix);
} }
+1 -1
View File
@@ -37,7 +37,7 @@ void taskMain(
{ {
uint m = mesh.meshletOffset + i; uint m = mesh.meshletOffset + i;
MeshletDescription meshlet = pScene.meshletInfos[m]; MeshletDescription meshlet = pScene.meshletInfos[m];
//if(meshlet.bounding.insideFrustum(viewFrustum)) if(meshlet.bounding.insideFrustum(viewFrustum))
{ {
uint index; uint index;
InterlockedAdd(head, 1, index); InterlockedAdd(head, 1, index);
@@ -18,6 +18,20 @@ struct StaticMeshVertexData : IVertexData
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]); attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
return attributes; 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<float> positions; StructuredBuffer<float> positions;
StructuredBuffer<float> normals; StructuredBuffer<float> normals;
StructuredBuffer<float> tangents; StructuredBuffer<float> tangents;
+1
View File
@@ -9,6 +9,7 @@ struct VertexInput
interface IVertexData interface IVertexData
{ {
VertexAttributes getAttributes(uint index); VertexAttributes getAttributes(uint index);
VertexAttributes getPosition(uint index);
}; };
layout(set=1) layout(set=1)
+6
View File
@@ -355,6 +355,12 @@ public:
} }
destroyNode(pos.node); destroyNode(pos.node);
deallocateNode(pos.node); deallocateNode(pos.node);
if (_size == 0)
{
deallocateNode(tail);
root = nullptr;
tail = nullptr;
}
markIteratorDirty(); markIteratorDirty();
return Iterator(next); return Iterator(next);
} }
+3 -3
View File
@@ -40,11 +40,11 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
if (graphics->supportMeshShading()) 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 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() void BasePass::createRenderPass()
{ {
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH"); 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.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
@@ -25,11 +25,11 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
}); });
if (graphics->supportMeshShading()) 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 else
{ {
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass"); graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true);
} }
} }
@@ -48,6 +48,7 @@ void DepthPrepass::render()
Array<Gfx::ORenderCommand> commands; Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation; Gfx::ShaderPermutation permutation;
permutation.setPositionOnly();
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
permutation.setTaskFile("ViewCullingTask"); permutation.setTaskFile("ViewCullingTask");
@@ -22,11 +22,11 @@ StaticBasePass::StaticBasePass(Gfx::PGraphics graphics, PScene scene)
basePassLayout->addDescriptorLayout(lightCullingLayout); basePassLayout->addDescriptorLayout(lightCullingLayout);
if (graphics->supportMeshShading()) 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 else
{ {
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", true, true, "BasePass"); graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", false, true, true, "BasePass");
} }
} }
@@ -16,11 +16,11 @@ StaticDepthPrepass::StaticDepthPrepass(Gfx::PGraphics graphics, PScene scene)
depthPrepassLayout->addDescriptorLayout(meshletCullingLayout); depthPrepassLayout->addDescriptorLayout(meshletCullingLayout);
if (graphics->supportMeshShading()) if (graphics->supportMeshShading())
{ {
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true); graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", true, false, false, "", true);
} }
else else
{ {
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass"); graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true);
} }
} }
+22 -1
View File
@@ -34,7 +34,15 @@ void ShaderCompiler::registerVertexData(VertexData* vd)
compile(); 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{ passes[name] = PassConfig{
.baseLayout = layout, .baseLayout = layout,
@@ -45,6 +53,7 @@ void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string
.useMeshShading = useMeshShading, .useMeshShading = useMeshShading,
.hasTaskShader = hasTaskShader, .hasTaskShader = hasTaskShader,
.useMaterial = useMaterials, .useMaterial = useMaterials,
.positionOnly = positionOnly,
}; };
compile(); compile();
} }
@@ -63,6 +72,10 @@ void ShaderCompiler::compile()
{ {
work.add([=]() { work.add([=]() {
ShaderPermutation permutation; ShaderPermutation permutation;
if (pass.positionOnly)
{
permutation.setPositionOnly();
}
if (pass.useMeshShading) if (pass.useMeshShading)
{ {
permutation.setMeshFile(pass.mainFile); permutation.setMeshFile(pass.mainFile);
@@ -93,6 +106,10 @@ void ShaderCompiler::compile()
{ {
work.add([=]() { work.add([=]() {
ShaderPermutation permutation; ShaderPermutation permutation;
if (pass.positionOnly)
{
permutation.setPositionOnly();
}
if (pass.useMeshShading) if (pass.useMeshShading)
{ {
permutation.setMeshFile(pass.mainFile); permutation.setMeshFile(pass.mainFile);
@@ -139,6 +156,10 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
{ {
createInfo.additionalModules.add(permutation.materialName); createInfo.additionalModules.add(permutation.materialName);
createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName; createInfo.defines["MATERIAL_FILE_NAME"] = permutation.materialName;
}
if (permutation.positionOnly)
{
createInfo.defines["POS_ONLY"] = "1";
} }
createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) }); createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) });
createInfo.additionalModules.add(permutation.vertexDataName); createInfo.additionalModules.add(permutation.vertexDataName);
+7
View File
@@ -62,6 +62,7 @@ struct ShaderPermutation
uint8 useMeshShading; uint8 useMeshShading;
uint8 hasTaskShader; uint8 hasTaskShader;
uint8 useMaterial; uint8 useMaterial;
uint8 positionOnly;
//TODO: lightmapping etc //TODO: lightmapping etc
ShaderPermutation() ShaderPermutation()
{ {
@@ -102,6 +103,10 @@ struct ShaderPermutation
useMaterial = 1; useMaterial = 1;
strncpy(materialName, name.data(), sizeof(materialName)); strncpy(materialName, name.data(), sizeof(materialName));
} }
void setPositionOnly()
{
positionOnly = true;
}
}; };
//Hashed ShaderPermutation for fast lookup //Hashed ShaderPermutation for fast lookup
struct PermutationId struct PermutationId
@@ -141,6 +146,7 @@ public:
void registerRenderPass(Gfx::PPipelineLayout baseLayout, void registerRenderPass(Gfx::PPipelineLayout baseLayout,
std::string name, std::string name,
std::string mainFile, std::string mainFile,
bool positionOnly = true,
bool useMaterials = false, bool useMaterials = false,
bool hasFragmentShader = false, bool hasFragmentShader = false,
std::string fragmentFile = "", std::string fragmentFile = "",
@@ -164,6 +170,7 @@ private:
bool useMeshShading; bool useMeshShading;
bool hasTaskShader; bool hasTaskShader;
bool useMaterial; bool useMaterial;
bool positionOnly;
}; };
Map<std::string, PassConfig> passes; Map<std::string, PassConfig> passes;
Gfx::PGraphics graphics; Gfx::PGraphics graphics;
+5 -1
View File
@@ -18,12 +18,16 @@ void VertexData::resetMeshData()
std::unique_lock l(materialDataLock); std::unique_lock l(materialDataLock);
for (auto& mat : materialData) for (auto& mat : materialData)
{ {
for (auto inst : mat.instances)
{
inst.instanceData.clear();
inst.instanceMeshData.clear();
}
if (mat.material != nullptr) if (mat.material != nullptr)
{ {
mat.material->getDescriptorLayout()->reset(); mat.material->getDescriptorLayout()->reset();
} }
} }
materialData.clear();
if (dirty) if (dirty)
{ {
updateBuffers(); updateBuffers();
+3 -3
View File
@@ -280,10 +280,10 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint
assert(threadId == std::this_thread::get_id()); assert(threadId == std::this_thread::get_id());
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
assert(descriptor->writeDescriptors.size() == 0); assert(descriptor->writeDescriptors.size() == 0);
boundResources.add(descriptor.getHandle());
descriptor->boundResources.clear();
boundResources.addAll(descriptor->boundResources);
descriptor->bind(); descriptor->bind();
boundResources.add(descriptor.getHandle());
boundResources.addAll(descriptor->boundResources);
descriptor->boundResources.clear();
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data()); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), pipeline->getPipelineLayout()->findParameter(descriptorSet->getName()), 1, &setHandle, dynamicOffsets.size(), dynamicOffsets.data());
@@ -416,6 +416,7 @@ void PipelineLayout::create() {
std::unique_lock l(layoutLock); std::unique_lock l(layoutLock);
if (cachedLayouts.contains(layoutHash)) { if (cachedLayouts.contains(layoutHash)) {
std::cout << "New Layout" << std::endl;
layoutHandle = cachedLayouts[layoutHash]; layoutHandle = cachedLayouts[layoutHash];
return; return;
} }
+45 -15
View File
@@ -261,10 +261,16 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo gf
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxInfo) 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<PipelineLayout>(); PPipelineLayout layout = Gfx::PPipelineLayout(gfxInfo.pipelineLayout).cast<PipelineLayout>();
uint32 hash = layout->getHash(); //uint32 hash = layout->getHash();
uint32 stageCount = 0; uint32 stageCount = 0;
VkPipelineShaderStageCreateInfo stageInfos[3]; VkPipelineShaderStageCreateInfo stageInfos[3];
std::memset(stageInfos, 0, sizeof(stageInfos)); std::memset(stageInfos, 0, sizeof(stageInfos));
@@ -273,18 +279,24 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
PTaskShader taskShader = gfxInfo.taskShader.cast<TaskShader>(); PTaskShader taskShader = gfxInfo.taskShader.cast<TaskShader>();
stageInfos[stageCount++] = { stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.stage = VK_SHADER_STAGE_TASK_BIT_EXT, .stage = VK_SHADER_STAGE_TASK_BIT_EXT,
.module = taskShader->getModuleHandle(), .module = taskShader->getModuleHandle(),
.pName = taskShader->getEntryPointName(), .pName = taskShader->getEntryPointName(),
.pSpecializationInfo = nullptr,
}; };
} }
PMeshShader meshShader = gfxInfo.meshShader.cast<MeshShader>(); PMeshShader meshShader = gfxInfo.meshShader.cast<MeshShader>();
stageInfos[stageCount++] = { stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.stage = VK_SHADER_STAGE_MESH_BIT_EXT, .stage = VK_SHADER_STAGE_MESH_BIT_EXT,
.module = meshShader->getModuleHandle(), .module = meshShader->getModuleHandle(),
.pName = meshShader->getEntryPointName(), .pName = meshShader->getEntryPointName(),
.pSpecializationInfo = nullptr,
}; };
if (gfxInfo.fragmentShader != nullptr) if (gfxInfo.fragmentShader != nullptr)
@@ -293,21 +305,26 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
stageInfos[stageCount++] = { stageInfos[stageCount++] = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
.flags = 0,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT, .stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = fragment->getModuleHandle(), .module = fragment->getModuleHandle(),
.pName = fragment->getEntryPointName(), .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 = { VkPipelineViewportStateCreateInfo viewportInfo = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
.flags = 0, .flags = 0,
.viewportCount = 1, .viewportCount = 1,
.pViewports = nullptr,
.scissorCount = 1, .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 = { VkPipelineRasterizationStateCreateInfo rasterizationState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,
@@ -323,7 +340,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor, .depthBiasSlopeFactor = gfxInfo.rasterizationState.depthBiasSlopeFactor,
.lineWidth = 0, .lineWidth = 0,
}; };
hash = CRC::Calculate(&rasterizationState, sizeof(rasterizationState), CRC::CRC_32(), hash); //hash = CRC::Calculate(&rasterizationState, sizeof(VkPipelineRasterizationStateCreateInfo), CRC::CRC_32(), hash);
VkPipelineMultisampleStateCreateInfo multisampleState = { VkPipelineMultisampleStateCreateInfo multisampleState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
@@ -332,10 +349,11 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.rasterizationSamples = (VkSampleCountFlagBits)gfxInfo.multisampleState.samples, .rasterizationSamples = (VkSampleCountFlagBits)gfxInfo.multisampleState.samples,
.sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable, .sampleShadingEnable = gfxInfo.multisampleState.sampleShadingEnable,
.minSampleShading = gfxInfo.multisampleState.minSampleShading, .minSampleShading = gfxInfo.multisampleState.minSampleShading,
.pSampleMask = nullptr,
.alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable, .alphaToCoverageEnable = gfxInfo.multisampleState.alphaCoverageEnable,
.alphaToOneEnable = gfxInfo.multisampleState.alphaToOneEnable, .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 = { VkPipelineDepthStencilStateCreateInfo depthStencilState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
@@ -345,12 +363,29 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.depthWriteEnable = gfxInfo.depthStencilState.depthWriteEnable, .depthWriteEnable = gfxInfo.depthStencilState.depthWriteEnable,
.depthCompareOp = cast(gfxInfo.depthStencilState.depthCompareOp), .depthCompareOp = cast(gfxInfo.depthStencilState.depthCompareOp),
.depthBoundsTestEnable = gfxInfo.depthStencilState.depthBoundsTestEnable, .depthBoundsTestEnable = gfxInfo.depthStencilState.depthBoundsTestEnable,
.front = {(VkStencilOp)gfxInfo.depthStencilState.front}, .stencilTestEnable = gfxInfo.depthStencilState.stencilTestEnable,
.back = {(VkStencilOp)gfxInfo.depthStencilState.back}, .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, .minDepthBounds = gfxInfo.depthStencilState.minDepthBounds,
.maxDepthBounds = gfxInfo.depthStencilState.maxDepthBounds, .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<VkPipelineColorBlendAttachmentState> blendAttachments; Array<VkPipelineColorBlendAttachmentState> blendAttachments;
for (uint32 i = 0; i < gfxInfo.colorBlend.attachmentCount; ++i) for (uint32 i = 0; i < gfxInfo.colorBlend.attachmentCount; ++i)
@@ -367,7 +402,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.colorWriteMask = attachment.colorWriteMask, .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 = { VkPipelineColorBlendStateCreateInfo blendState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
@@ -384,7 +419,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
StaticArray<VkDynamicState, 2> dynamicEnabled; StaticArray<VkDynamicState, 2> dynamicEnabled;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT; dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_VIEWPORT;
dynamicEnabled[numDynamicEnabled++] = VK_DYNAMIC_STATE_SCISSOR; 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 = { VkPipelineDynamicStateCreateInfo dynamicState = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
@@ -392,11 +427,6 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo gfxI
.dynamicStateCount = (uint32)dynamicEnabled.size(), .dynamicStateCount = (uint32)dynamicEnabled.size(),
.pDynamicStates = dynamicEnabled.data(), .pDynamicStates = dynamicEnabled.data(),
}; };
if (graphicsPipelines.contains(hash))
{
return graphicsPipelines[hash];
}
VkPipeline pipelineHandle; VkPipeline pipelineHandle;
VkGraphicsPipelineCreateInfo createInfo = { VkGraphicsPipelineCreateInfo createInfo = {
+1
View File
@@ -57,6 +57,7 @@ void ThreadPool::work()
currentTask.numRemaining--; currentTask.numRemaining--;
if (currentTask.numRemaining == 0) if (currentTask.numRemaining == 0)
{ {
currentTask.functions.clear();
completedCV.notify_one(); completedCV.notify_one();
} }
} }