Lot of changes
This commit is contained in:
@@ -355,6 +355,12 @@ public:
|
||||
}
|
||||
destroyNode(pos.node);
|
||||
deallocateNode(pos.node);
|
||||
if (_size == 0)
|
||||
{
|
||||
deallocateNode(tail);
|
||||
root = nullptr;
|
||||
tail = nullptr;
|
||||
}
|
||||
markIteratorDirty();
|
||||
return Iterator(next);
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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<Gfx::ORenderCommand> commands;
|
||||
|
||||
Gfx::ShaderPermutation permutation;
|
||||
permutation.setPositionOnly();
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
permutation.setTaskFile("ViewCullingTask");
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<const char*, const char*>("IVertexData", permutation.vertexDataName) });
|
||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||
|
||||
|
||||
@@ -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<std::string, PassConfig> passes;
|
||||
Gfx::PGraphics graphics;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -280,10 +280,10 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
auto descriptor = descriptorSet.cast<DescriptorSet>();
|
||||
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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<PipelineLayout>();
|
||||
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<TaskShader>();
|
||||
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<MeshShader>();
|
||||
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<VkPipelineColorBlendAttachmentState> 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<VkDynamicState, 2> 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 = {
|
||||
|
||||
@@ -57,6 +57,7 @@ void ThreadPool::work()
|
||||
currentTask.numRemaining--;
|
||||
if (currentTask.numRemaining == 0)
|
||||
{
|
||||
currentTask.functions.clear();
|
||||
completedCV.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user