Jobify the draw item list sort in View::FinalizeDrawLists (#6176)

Jobification of the sort saves 0.7ms/frame on the HighInstanceTest on my pc.
Make MeshFeatureProcessor update of the mesh cull bounds part of the job work rather than part of the simulate work. This saves 0.1ms/frame on the HighInstanceTest

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
This commit is contained in:
rgba16f
2021-12-07 10:44:12 -06:00
committed by GitHub
parent 201777c1d1
commit aad16acf1f
13 changed files with 92 additions and 50 deletions
@@ -77,8 +77,8 @@ namespace AZ
void MeshFeatureProcessor::Simulate(const FeatureProcessor::SimulatePacket& packet)
{
AZ_PROFILE_SCOPE(RPI, "MeshFeatureProcessor: Simulate");
AZ_UNUSED(packet);
AZ::Job* parentJob = packet.m_parentJob;
AZStd::concurrency_check_scope scopeCheck(m_meshDataChecker);
const auto iteratorRanges = m_modelData.GetParallelRanges();
@@ -87,6 +87,8 @@ namespace AZ
{
const auto jobLambda = [&]() -> void
{
AZ_PROFILE_SCOPE(AzRender, "MeshFeatureProcessor: Simulate: Job");
for (auto meshDataIter = iteratorRange.first; meshDataIter != iteratorRange.second; ++meshDataIter)
{
if (!meshDataIter->m_model)
@@ -114,24 +116,22 @@ namespace AZ
{
meshDataIter->BuildCullable();
}
if (meshDataIter->m_cullBoundsNeedsUpdate)
{
meshDataIter->UpdateCullBounds(m_transformService);
}
}
};
Job* executeGroupJob = aznew JobFunction<decltype(jobLambda)>(jobLambda, true, nullptr); // Auto-deletes
executeGroupJob->SetDependent(&jobCompletion);
executeGroupJob->Start();
parentJob->StartAsChild(executeGroupJob);
}
{
AZ_PROFILE_SCOPE(AzRender, "MeshFeatureProcessor: Simulate: WaitForChildren");
parentJob->WaitForChildren();
}
jobCompletion.StartAndWaitForCompletion();
m_forceRebuildDrawPackets = false;
// CullingSystem::RegisterOrUpdateCullable() is not threadsafe, so need to do those updates in a single thread
for (ModelDataInstance& modelDataInstance : m_modelData)
{
if (modelDataInstance.m_model && modelDataInstance.m_cullBoundsNeedsUpdate)
{
modelDataInstance.UpdateCullBounds(m_transformService);
}
}
}
void MeshFeatureProcessor::OnBeginPrepareRender()
@@ -1038,7 +1038,6 @@ namespace AZ
void ModelDataInstance::UpdateDrawPackets(bool forceUpdate /*= false*/)
{
AZ_PROFILE_SCOPE(AzRender, "ModelDataInstance:: UpdateDrawPackets");
for (auto& drawPacketList : m_drawPacketListsByLod)
{
for (auto& drawPacket : drawPacketList)
@@ -1053,7 +1052,6 @@ namespace AZ
void ModelDataInstance::BuildCullable()
{
AZ_PROFILE_SCOPE(AzRender, "ModelDataInstance: BuildCullable");
AZ_Assert(m_cullableNeedsRebuild, "This function only needs to be called if the cullable to be rebuilt");
AZ_Assert(m_model, "The model has not finished loading yet");
@@ -1130,7 +1128,6 @@ namespace AZ
void ModelDataInstance::UpdateCullBounds(const TransformServiceFeatureProcessor* transformService)
{
AZ_PROFILE_SCOPE(AzRender, "ModelDataInstance: UpdateCullBounds");
AZ_Assert(m_cullBoundsNeedsUpdate, "This function only needs to be called if the culling bounds need to be rebuilt");
AZ_Assert(m_model, "The model has not finished loading yet");