Updated all array_view uses with the C++20 span. (#7157)

* Updated all array_view uses with the C++20 span.

The updates were done in the following order
1. `AZStd::array_view<([^>].+)\* ?>`  -> `AZStd::span<\1 const>`
2. `AZStd::array_view<(?:const )(.+)>` -> `AZStd::span<const \1>`
3. `AZStd::array_view` -> `AZStd::span`

Removed the implementation of array_view.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Added missing whitespace between `const` and the typename for spans.

Updated the ShaderTest comparison of the ShaderResourceGroupLayout span
to compare the sizes as well

Updated comments on some of the methods that stated that they return "an
array" to mention they return "a span".

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
lumberyard-employee-dm
2022-01-26 16:15:47 -06:00
committed by GitHub
parent 48cea89910
commit b9824ed172
170 changed files with 833 additions and 1274 deletions
@@ -82,9 +82,9 @@ namespace AZ
return m_lodAssets.size();
}
AZStd::array_view<Data::Asset<ModelLodAsset>> ModelAsset::GetLodAssets() const
AZStd::span<const Data::Asset<ModelLodAsset>> ModelAsset::GetLodAssets() const
{
return AZStd::array_view<Data::Asset<ModelLodAsset>>(m_lodAssets);
return AZStd::span<const Data::Asset<ModelLodAsset>>(m_lodAssets);
}
void ModelAsset::SetReady()
@@ -213,7 +213,7 @@ namespace AZ
}
RHI::BufferViewDescriptor positionBufferViewDesc = positionBufferView->GetBufferViewDescriptor();
AZStd::array_view<uint8_t> positionRawBuffer = bufferAssetViewPtr->GetBuffer();
AZStd::span<const uint8_t> positionRawBuffer = bufferAssetViewPtr->GetBuffer();
const uint32_t positionElementSize = positionBufferViewDesc.m_elementSize;
const uint32_t positionElementCount = positionBufferViewDesc.m_elementCount;
@@ -227,7 +227,7 @@ namespace AZ
}
RHI::BufferViewDescriptor indexBufferViewDesc = indexBufferView.GetBufferViewDescriptor();
AZStd::array_view<uint8_t> indexRawBuffer = indexAssetViewPtr->GetBuffer();
AZStd::span<const uint8_t> indexRawBuffer = indexAssetViewPtr->GetBuffer();
const AZ::Vector3 rayEnd = rayStart + rayDir;
AZ::Vector3 a, b, c;
@@ -297,7 +297,7 @@ namespace AZ
{
for (const ModelLodAsset::Mesh& mesh : loadAssetPtr->GetMeshes())
{
const AZStd::array_view<ModelLodAsset::Mesh::StreamBufferInfo>& streamBufferList = mesh.GetStreamBufferInfoList();
const AZStd::span<const ModelLodAsset::Mesh::StreamBufferInfo>& streamBufferList = mesh.GetStreamBufferInfoList();
// find position semantic
const ModelLodAsset::Mesh::StreamBufferInfo* positionBuffer = nullptr;
@@ -101,7 +101,7 @@ namespace AZ
creator.SetName(sourceAsset->GetName().GetStringView());
AZ::Data::AssetId lastUsedId = cloneAssetId;
const AZStd::array_view<Data::Asset<ModelLodAsset>> sourceLodAssets = sourceAsset->GetLodAssets();
const AZStd::span<const Data::Asset<ModelLodAsset>> sourceLodAssets = sourceAsset->GetLodAssets();
for (const Data::Asset<ModelLodAsset>& sourceLodAsset : sourceLodAssets)
{
Data::Asset<ModelLodAsset> lodAsset;
@@ -61,7 +61,7 @@ namespace AZ
{
const auto& [first, second, third] = triangleIndices;
const AZStd::array_view<float>& positionBuffer = m_meshes[nObjIndex].m_vertexData;
const AZStd::span<const float>& positionBuffer = m_meshes[nObjIndex].m_vertexData;
if (positionBuffer.empty())
{
@@ -114,7 +114,7 @@ namespace AZ
for (AZ::u8 meshIndex = 0, meshCount = aznumeric_caster(m_meshes.size()); meshIndex < meshCount; ++meshIndex)
{
const AZStd::array_view<float> positionBuffer = m_meshes[meshIndex].m_vertexData;
const AZStd::span<const float> positionBuffer = m_meshes[meshIndex].m_vertexData;
for (size_t positionIndex = 0; positionIndex < positionBuffer.size(); positionIndex += 3)
{
entireBoundBox.AddPoint({positionBuffer[positionIndex], positionBuffer[positionIndex + 1], positionBuffer[positionIndex + 2]});
@@ -137,14 +137,14 @@ namespace AZ
return true;
}
AZStd::array_view<float> ModelKdTree::GetPositionsBuffer(const ModelLodAsset::Mesh& mesh)
AZStd::span<const float> ModelKdTree::GetPositionsBuffer(const ModelLodAsset::Mesh& mesh)
{
AZStd::array_view<float> positionBuffer = mesh.GetSemanticBufferTyped<float>(AZ::Name{"POSITION"});
AZStd::span<const float> positionBuffer = mesh.GetSemanticBufferTyped<float>(AZ::Name{"POSITION"});
AZ_Warning("ModelKdTree", !positionBuffer.empty(), "Could not find position buffers in a mesh");
return positionBuffer;
}
AZStd::array_view<ModelKdTree::TriangleIndices> ModelKdTree::GetIndexBuffer(const ModelLodAsset::Mesh& mesh)
AZStd::span<const ModelKdTree::TriangleIndices> ModelKdTree::GetIndexBuffer(const ModelLodAsset::Mesh& mesh)
{
return mesh.GetIndexBufferTyped<ModelKdTree::TriangleIndices>();
}
@@ -264,7 +264,7 @@ namespace AZ
const auto& [first, second, third] = pNode->GetVertexIndex(i);
const AZ::u32 nObjIndex = pNode->GetObjIndex(i);
const AZStd::array_view<float> positionBuffer = m_meshes[nObjIndex].m_vertexData;
const AZStd::span<const float> positionBuffer = m_meshes[nObjIndex].m_vertexData;
if (positionBuffer.empty())
{
@@ -95,9 +95,9 @@ namespace AZ
return m_indexBufferAssetView;
}
AZStd::array_view<ModelLodAsset::Mesh::StreamBufferInfo> ModelLodAsset::Mesh::GetStreamBufferInfoList() const
AZStd::span<const ModelLodAsset::Mesh::StreamBufferInfo> ModelLodAsset::Mesh::GetStreamBufferInfoList() const
{
return AZStd::array_view<ModelLodAsset::Mesh::StreamBufferInfo>(m_streamBufferInfo);
return AZStd::span<const ModelLodAsset::Mesh::StreamBufferInfo>(m_streamBufferInfo);
}
void ModelLodAsset::AddMesh(const Mesh& mesh)
@@ -109,9 +109,9 @@ namespace AZ
m_aabb.AddAabb(meshAabb);
}
AZStd::array_view<ModelLodAsset::Mesh> ModelLodAsset::GetMeshes() const
AZStd::span<const ModelLodAsset::Mesh> ModelLodAsset::GetMeshes() const
{
return AZStd::array_view<ModelLodAsset::Mesh>(m_meshes);
return AZStd::span<const ModelLodAsset::Mesh>(m_meshes);
}
const AZ::Aabb& ModelLodAsset::GetAabb() const
@@ -121,7 +121,7 @@ namespace AZ
const BufferAssetView* ModelLodAsset::Mesh::GetSemanticBufferAssetView(const AZ::Name& semantic) const
{
const AZStd::array_view<ModelLodAsset::Mesh::StreamBufferInfo>& streamBufferList = GetStreamBufferInfoList();
const AZStd::span<const ModelLodAsset::Mesh::StreamBufferInfo>& streamBufferList = GetStreamBufferInfoList();
for (const ModelLodAsset::Mesh::StreamBufferInfo& streamBufferInfo : streamBufferList)
{
@@ -243,7 +243,7 @@ namespace AZ
bool ModelLodAssetCreator::Clone(const Data::Asset<ModelLodAsset>& sourceAsset, Data::Asset<ModelLodAsset>& clonedResult, Data::AssetId& inOutLastCreatedAssetId)
{
AZStd::array_view<ModelLodAsset::Mesh> sourceMeshes = sourceAsset->GetMeshes();
AZStd::span<const ModelLodAsset::Mesh> sourceMeshes = sourceAsset->GetMeshes();
if (sourceMeshes.empty())
{
return true;