Fix performance bug in Development/Release builds due to incorrect draw calls batching (uninitialized memory)
This commit is contained in:
@@ -401,10 +401,6 @@ void Mesh::Draw(const RenderContext& renderContext, MaterialBase* material, cons
|
||||
drawCall.Geometry.VertexBuffers[0] = _vertexBuffers[0];
|
||||
drawCall.Geometry.VertexBuffers[1] = _vertexBuffers[1];
|
||||
drawCall.Geometry.VertexBuffers[2] = _vertexBuffers[2];
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
drawCall.Draw.StartIndex = 0;
|
||||
drawCall.Draw.IndicesCount = _triangles * 3;
|
||||
drawCall.InstanceCount = 1;
|
||||
drawCall.Material = material;
|
||||
@@ -459,9 +455,6 @@ void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float
|
||||
drawCall.Geometry.VertexBuffers[0] = _vertexBuffers[0];
|
||||
drawCall.Geometry.VertexBuffers[1] = _vertexBuffers[1];
|
||||
drawCall.Geometry.VertexBuffers[2] = _vertexBuffers[2];
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
if (info.Deformation)
|
||||
{
|
||||
info.Deformation->RunDeformers(this, MeshBufferType::Vertex0, drawCall.Geometry.VertexBuffers[0]);
|
||||
@@ -476,7 +469,6 @@ void Mesh::Draw(const RenderContext& renderContext, const DrawInfo& info, float
|
||||
drawCall.Geometry.VertexBuffers[2] = info.VertexColors[_lodIndex];
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = vertexOffset * sizeof(VB2ElementType);
|
||||
}
|
||||
drawCall.Draw.StartIndex = 0;
|
||||
drawCall.Draw.IndicesCount = _triangles * 3;
|
||||
drawCall.InstanceCount = 1;
|
||||
drawCall.Material = material;
|
||||
@@ -525,9 +517,6 @@ void Mesh::Draw(const RenderContextBatch& renderContextBatch, const DrawInfo& in
|
||||
drawCall.Geometry.VertexBuffers[0] = _vertexBuffers[0];
|
||||
drawCall.Geometry.VertexBuffers[1] = _vertexBuffers[1];
|
||||
drawCall.Geometry.VertexBuffers[2] = _vertexBuffers[2];
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
if (info.Deformation)
|
||||
{
|
||||
info.Deformation->RunDeformers(this, MeshBufferType::Vertex0, drawCall.Geometry.VertexBuffers[0]);
|
||||
@@ -542,7 +531,6 @@ void Mesh::Draw(const RenderContextBatch& renderContextBatch, const DrawInfo& in
|
||||
drawCall.Geometry.VertexBuffers[2] = info.VertexColors[_lodIndex];
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = vertexOffset * sizeof(VB2ElementType);
|
||||
}
|
||||
drawCall.Draw.StartIndex = 0;
|
||||
drawCall.Draw.IndicesCount = _triangles * 3;
|
||||
drawCall.InstanceCount = 1;
|
||||
drawCall.Material = material;
|
||||
|
||||
@@ -175,11 +175,6 @@ void SkinnedMesh::Draw(const RenderContext& renderContext, const DrawInfo& info,
|
||||
DrawCall drawCall;
|
||||
drawCall.Geometry.IndexBuffer = _indexBuffer;
|
||||
drawCall.Geometry.VertexBuffers[0] = _vertexBuffer;
|
||||
drawCall.Geometry.VertexBuffers[1] = nullptr;
|
||||
drawCall.Geometry.VertexBuffers[2] = nullptr;
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
if (info.Deformation)
|
||||
info.Deformation->RunDeformers(this, MeshBufferType::Vertex0, drawCall.Geometry.VertexBuffers[0]);
|
||||
drawCall.Draw.StartIndex = 0;
|
||||
@@ -224,14 +219,8 @@ void SkinnedMesh::Draw(const RenderContextBatch& renderContextBatch, const DrawI
|
||||
DrawCall drawCall;
|
||||
drawCall.Geometry.IndexBuffer = _indexBuffer;
|
||||
drawCall.Geometry.VertexBuffers[0] = _vertexBuffer;
|
||||
drawCall.Geometry.VertexBuffers[1] = nullptr;
|
||||
drawCall.Geometry.VertexBuffers[2] = nullptr;
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
if (info.Deformation)
|
||||
info.Deformation->RunDeformers(this, MeshBufferType::Vertex0, drawCall.Geometry.VertexBuffers[0]);
|
||||
drawCall.Draw.StartIndex = 0;
|
||||
drawCall.Draw.IndicesCount = _triangles * 3;
|
||||
drawCall.InstanceCount = 1;
|
||||
drawCall.Material = material;
|
||||
|
||||
@@ -97,7 +97,6 @@ void Skybox::ApplySky(GPUContext* context, RenderContext& renderContext, const M
|
||||
{
|
||||
// Prepare mock draw call data
|
||||
DrawCall drawCall;
|
||||
Platform::MemoryClear(&drawCall, sizeof(DrawCall));
|
||||
drawCall.World = world;
|
||||
drawCall.ObjectPosition = drawCall.World.GetTranslation();
|
||||
drawCall.ObjectRadius = _sphere.Radius;
|
||||
|
||||
@@ -279,10 +279,11 @@ struct DrawCall
|
||||
uint64 SortKey;
|
||||
|
||||
/// <summary>
|
||||
/// Does nothing.
|
||||
/// Zero-init.
|
||||
/// </summary>
|
||||
DrawCall()
|
||||
FORCE_INLINE DrawCall()
|
||||
{
|
||||
Platform::MemoryClear(this, sizeof(DrawCall));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ void QuadOverdrawPass::Render(RenderContext& renderContext, GPUContext* context,
|
||||
context->BindUA(1, overdrawTexture->View());
|
||||
context->BindUA(2, liveCountTexture->View());
|
||||
DrawCall drawCall;
|
||||
Platform::MemoryClear(&drawCall, sizeof(DrawCall));
|
||||
drawCall.PerInstanceRandom = 1.0f;
|
||||
MaterialBase::BindParameters bindParams(context, renderContext, drawCall);
|
||||
bindParams.BindViewData();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -379,9 +379,6 @@ void TextRender::Draw(RenderContext& renderContext)
|
||||
drawCall.Geometry.VertexBuffers[0] = _vb0.GetBuffer();
|
||||
drawCall.Geometry.VertexBuffers[1] = _vb1.GetBuffer();
|
||||
drawCall.Geometry.VertexBuffers[2] = _vb2.GetBuffer();
|
||||
drawCall.Geometry.VertexBuffersOffsets[0] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[1] = 0;
|
||||
drawCall.Geometry.VertexBuffersOffsets[2] = 0;
|
||||
drawCall.InstanceCount = 1;
|
||||
|
||||
// Submit draw calls
|
||||
|
||||
Reference in New Issue
Block a user