Misc SurfaceData Optimizations (#7299)

* Misc SurfaceData Optimizations.
This includes a few different optimizations found while trying to make the bulk query APIs faster:
* Switches mutexes over to shared_lock to optimize for the multi-reader-single-writer pattern
* Surface provider point creation now uses a pre-created set of masks to initialize with, and uses std::move() to move the created point into the output list instead of copying it.
* Splits CombineSortAndFilterNeightboringPoints so that the FilterPoints() can occur separately and efficiently with erase/remove_if, and avoids making a copy of the output points.
* Optimized SurfaceDataShapeComponent::ModifySurfacePoints
* Fixed potential bug where the sort wasn't stable since it only compared the Z value, and could have produced unexpected results for differing points with the exact same Z value.
* Fixed up a couple small bugs and missing checks in the unit tests

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>

* Fixed syntax on unit tests.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
Mike Balfour
2022-02-01 10:44:14 -06:00
committed by GitHub
parent ff4529fc60
commit 3f63cf3546
12 changed files with 221 additions and 181 deletions
@@ -10,6 +10,7 @@
#include <AzCore/Component/Component.h>
#include <AzCore/Math/Aabb.h>
#include <AzCore/std/parallel/shared_mutex.h>
#include <SurfaceData/SurfaceDataSystemRequestBus.h>
namespace SurfaceData
@@ -57,7 +58,8 @@ namespace SurfaceData
void RefreshSurfaceData(const AZ::Aabb& dirtyArea) override;
private:
void CombineSortAndFilterNeighboringPoints(SurfacePointList& sourcePointList, bool hasDesiredTags, const SurfaceTagVector& desiredTags) const;
void FilterPoints(SurfacePointList& sourcePointList, const SurfaceTagVector& desiredTags) const;
void CombineAndSortNeighboringPoints(SurfacePointList& sourcePointList) const;
SurfaceDataRegistryHandle RegisterSurfaceDataProviderInternal(const SurfaceDataRegistryEntry& entry);
SurfaceDataRegistryEntry UnregisterSurfaceDataProviderInternal(const SurfaceDataRegistryHandle& handle);
@@ -67,7 +69,7 @@ namespace SurfaceData
SurfaceDataRegistryEntry UnregisterSurfaceDataModifierInternal(const SurfaceDataRegistryHandle& handle);
bool UpdateSurfaceDataModifierInternal(const SurfaceDataRegistryHandle& handle, const SurfaceDataRegistryEntry& entry, AZ::Aabb& oldBounds);
mutable AZStd::recursive_mutex m_registrationMutex;
mutable AZStd::shared_mutex m_registrationMutex;
AZStd::unordered_map<SurfaceDataRegistryHandle, SurfaceDataRegistryEntry> m_registeredSurfaceDataProviders;
AZStd::unordered_map<SurfaceDataRegistryHandle, SurfaceDataRegistryEntry> m_registeredSurfaceDataModifiers;
SurfaceDataRegistryHandle m_registeredSurfaceDataProviderHandleCounter = InvalidSurfaceDataRegistryHandle;