Fix performance bug in Development/Release builds due to incorrect draw calls batching (uninitialized memory)

This commit is contained in:
Wojtek Figat
2023-09-28 10:59:09 +02:00
parent b7e871ecfd
commit 98d5769558
7 changed files with 7 additions and 34 deletions

View File

@@ -13,6 +13,7 @@
#include "Engine/Graphics/PostProcessEffect.h"
#include "Engine/Profiler/Profiler.h"
#include "Engine/Content/Assets/CubeTexture.h"
#include "Engine/Core/Log.h"
#include "Engine/Level/Scene/Lightmap.h"
#include "Engine/Level/Actors/PostFxVolume.h"
@@ -434,11 +435,11 @@ FORCE_INLINE void CalculateSortKey(const RenderContext& renderContext, DrawCall&
const float distance = Float3::Dot(planeNormal, drawCall.ObjectPosition) - planePoint;
PackedSortKey key;
key.DistanceKey = RenderTools::ComputeDistanceSortKey(distance);
uint32 batchKey = GetHash(drawCall.Geometry.IndexBuffer);
uint32 batchKey = GetHash(drawCall.Material);
batchKey = (batchKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[0]);
batchKey = (batchKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[1]);
batchKey = (batchKey * 397) ^ GetHash(drawCall.Geometry.VertexBuffers[2]);
batchKey = (batchKey * 397) ^ GetHash(drawCall.Material);
batchKey = (batchKey * 397) ^ GetHash(drawCall.Geometry.IndexBuffer);
IMaterial::InstancingHandler handler;
if (drawCall.Material->CanUseInstancing(handler))
handler.GetHash(drawCall, batchKey);
@@ -557,7 +558,7 @@ namespace
a.InstanceCount != 0 &&
b.InstanceCount != 0 &&
handler.CanBatch(a, b) &&
a.WorldDeterminantSign == b.WorldDeterminantSign;
a.WorldDeterminantSign * b.WorldDeterminantSign > 0;
}
}
@@ -618,7 +619,6 @@ void RenderList::SortDrawCalls(const RenderContext& renderContext, bool reverseD
const DrawCall& other = drawCallsData[listData[j]];
if (!CanBatchWith(drawCall, other))
break;
batchSize++;
instanceCount += other.InstanceCount;
}