b9824ed172
* 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>
175 lines
5.8 KiB
C++
175 lines
5.8 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <Atom/RPI.Reflect/Buffer/BufferAssetCreator.h>
|
|
|
|
#include <AzCore/Asset/AssetManager.h>
|
|
|
|
namespace AZ
|
|
{
|
|
namespace RPI
|
|
{
|
|
void BufferAssetCreator::Begin(const Data::AssetId& assetId)
|
|
{
|
|
BeginCommon(assetId);
|
|
}
|
|
|
|
void BufferAssetCreator::SetBuffer(const void* initialData, const size_t initialDataSize, const RHI::BufferDescriptor& descriptor)
|
|
{
|
|
if (!ValidateIsReady())
|
|
{
|
|
return;
|
|
}
|
|
|
|
// buffer is allowed to be nullptr as a BufferAsset may describe a Read/Write buffer
|
|
|
|
if (descriptor.m_byteCount == 0)
|
|
{
|
|
ReportError("Size of the buffer in the descriptor was 0");
|
|
return;
|
|
}
|
|
|
|
if (initialDataSize > descriptor.m_byteCount)
|
|
{
|
|
ReportError("initialSize is larger than the total size in the descriptor.");
|
|
return;
|
|
}
|
|
|
|
if (initialData == nullptr && initialDataSize > 0)
|
|
{
|
|
ReportError("Initial buffer data was not provided but the initial size was non-zero.");
|
|
return;
|
|
}
|
|
|
|
if (initialData != nullptr && initialDataSize == 0)
|
|
{
|
|
ReportError("Initial buffer data was not null but the initial size was zero.");
|
|
return;
|
|
}
|
|
|
|
BufferAsset* bufferAsset = m_asset.Get();
|
|
|
|
// Only allocate buffer if initial data is not empty
|
|
if (initialData != nullptr && initialDataSize > 0)
|
|
{
|
|
bufferAsset->m_buffer.resize_no_construct(descriptor.m_byteCount);
|
|
memcpy(bufferAsset->m_buffer.data(), initialData, initialDataSize);
|
|
}
|
|
|
|
bufferAsset->m_bufferDescriptor = descriptor;
|
|
}
|
|
|
|
void BufferAssetCreator::SetBufferViewDescriptor(const RHI::BufferViewDescriptor& viewDescriptor)
|
|
{
|
|
if (!ValidateIsReady())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (viewDescriptor.m_elementCount == 0)
|
|
{
|
|
ReportError("BufferAssetCreator::SetBufferViewDescriptor was given a view descriptor with an element count of 0.");
|
|
return;
|
|
}
|
|
|
|
if (viewDescriptor.m_elementSize == 0)
|
|
{
|
|
ReportError("BufferAssetCreator::SetBufferViewDescriptor was given a view descriptor with an element size of 0.");
|
|
return;
|
|
}
|
|
|
|
BufferAsset* bufferAsset = m_asset.Get();
|
|
|
|
bufferAsset->m_bufferViewDescriptor = viewDescriptor;
|
|
}
|
|
|
|
void BufferAssetCreator::SetPoolAsset(const Data::Asset<ResourcePoolAsset>& poolAsset)
|
|
{
|
|
if (ValidateIsReady())
|
|
{
|
|
m_asset->m_poolAsset = poolAsset;
|
|
}
|
|
}
|
|
|
|
void BufferAssetCreator::SetUseCommonPool(CommonBufferPoolType poolType)
|
|
{
|
|
if (ValidateIsReady())
|
|
{
|
|
m_asset->m_poolType = poolType;
|
|
}
|
|
}
|
|
|
|
bool BufferAssetCreator::End(Data::Asset<BufferAsset>& result)
|
|
{
|
|
if (!ValidateIsReady() || !ValidateBuffer())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
m_asset->SetReady();
|
|
return EndCommon(result);
|
|
}
|
|
|
|
bool BufferAssetCreator::ValidateBuffer()
|
|
{
|
|
RPI::BufferAsset* bufferAsset = m_asset.Get();
|
|
|
|
if (!bufferAsset->m_poolAsset.GetId().IsValid() && bufferAsset->m_poolType == CommonBufferPoolType::Invalid)
|
|
{
|
|
ReportError("BufferAssetCreator::ValidateBuffer Failed; need valid pool asset or select a valid common pool.");
|
|
return false;
|
|
}
|
|
|
|
if (bufferAsset->m_bufferDescriptor.m_byteCount == 0)
|
|
{
|
|
ReportError("BufferAssetCreator::ValidateBuffer Failed; buffer descriptor has a byte count of 0.");
|
|
return false;
|
|
}
|
|
|
|
if (bufferAsset->m_bufferViewDescriptor.m_elementCount == 0)
|
|
{
|
|
ReportError("BufferAssetCreator::ValidateBuffer Failed; buffer view descirptor has an element count of 0.");
|
|
return false;
|
|
}
|
|
|
|
if (bufferAsset->m_bufferViewDescriptor.m_elementSize == 0)
|
|
{
|
|
ReportError("BufferAssetCreator::ValidateBuffer Failed; buffer view descriptor has an element size of 0.");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void BufferAssetCreator::SetBufferName(AZStd::string_view name)
|
|
{
|
|
if (ValidateIsReady())
|
|
{
|
|
m_asset->m_name = name;
|
|
}
|
|
}
|
|
|
|
bool BufferAssetCreator::Clone(const Data::Asset<BufferAsset>& sourceAsset, Data::Asset<BufferAsset>& clonedResult, Data::AssetId& inOutLastCreatedAssetId)
|
|
{
|
|
BufferAssetCreator creator;
|
|
inOutLastCreatedAssetId.m_subId = inOutLastCreatedAssetId.m_subId + 1;
|
|
creator.Begin(inOutLastCreatedAssetId);
|
|
|
|
creator.SetBufferName(sourceAsset.GetHint());
|
|
creator.SetUseCommonPool(sourceAsset->GetCommonPoolType());
|
|
creator.SetPoolAsset(sourceAsset->GetPoolAsset());
|
|
creator.SetBufferViewDescriptor(sourceAsset->GetBufferViewDescriptor());
|
|
|
|
const AZStd::span<const uint8_t> sourceBuffer = sourceAsset->GetBuffer();
|
|
creator.SetBuffer(sourceBuffer.data(), sourceBuffer.size(), sourceAsset->GetBufferDescriptor());
|
|
|
|
return creator.End(clonedResult);
|
|
}
|
|
} // namespace RPI
|
|
} // namespace AZ
|