SurfacePoint data structure encapsulations (#7413)

* First pass at encapsulating SurfacePointList.
The biggest challenge in optimizing SurfacePointList(s) usage is the overall memory management associated with it. There are M surface points with N surface mask entries created for every input point, which leads to a lot of container reallocation and memory shuffling when processing multiple input points. By encapsulating the list, it should become easier to preallocate the entries, as well as keep "helper data" around for managing the bookkeeping to associate the input points with the output points.

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

* Small fixes and TODO reminders.

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

* Encapsulate surface point creation and separate EnumeratePoints out from modifications.

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

* Start removing SurfacePoint from the exposed API.

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

* Changed SurfacePointList to split out the surface point storage to allow for span<> usage over time.

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

* Removed entity id

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

* Removed SurfacePoint from SurfaceData, changed all remaining uses to AzFramework::SurfaceData::SurfacePoint.

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

* Encapsulated SurfaceTagWeightMap and renamed to SurfaceTagWeights.

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

* Fixed make file.

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

* Better commenting and parameter naming.

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

* Renamed methods to be more descriptive.

Signed-off-by: Mike Balfour <82224783+mbalfour-amzn@users.noreply.github.com>
This commit is contained in:
Mike Balfour
2022-02-04 11:27:59 -06:00
committed by GitHub
parent ff4412db7c
commit d9ba0af645
39 changed files with 949 additions and 543 deletions
@@ -98,10 +98,9 @@ namespace GradientSignal
return [this]([[maybe_unused]] float sampleValue, const GradientSampleParams& params)
{
// Create a fake surface point with the position we're sampling.
SurfaceData::SurfacePoint point;
AzFramework::SurfaceData::SurfacePoint point;
point.m_position = params.m_position;
SurfaceData::SurfacePointList pointList;
pointList.emplace_back(point);
SurfaceData::SurfacePointList pointList = { { point } };
// Send it into the component, see what emerges
m_component.ModifySurfacePoints(pointList);
@@ -110,10 +109,18 @@ namespace GradientSignal
// Technically, they should all have the same value, but we'll grab the max from all of them in case
// the underlying logic ever changes to allow separate ranges per tag.
float result = 0.0f;
for (auto& mask : pointList[0].m_masks)
pointList.EnumeratePoints([&result](
[[maybe_unused]] const AZ::Vector3& position, [[maybe_unused]] const AZ::Vector3& normal,
const SurfaceData::SurfaceTagWeights& masks) -> bool
{
result = AZ::GetMax(result, mask.second);
}
masks.EnumerateWeights(
[&result]([[maybe_unused]] AZ::Crc32 surfaceType, float weight) -> bool
{
result = AZ::GetMax(result, weight);
return true;
});
return true;
});
return result;
};
}