Add DynamicTypedBuffer utility

This commit is contained in:
Wojciech Figat
2022-04-01 12:38:46 +02:00
parent 63b8b0cb50
commit ceb64afd4a
2 changed files with 42 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#include "DynamicBuffer.h"
#include "PixelFormatExtensions.h"
#include "GPUDevice.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Utilities.h"
@@ -87,3 +88,18 @@ void DynamicBuffer::Dispose()
SAFE_DELETE_GPU_RESOURCE(_buffer);
Data.Resize(0);
}
DynamicTypedBuffer::DynamicTypedBuffer(uint32 initialCapacity, PixelFormat format, bool isUnorderedAccess, const String& name)
: DynamicBuffer(initialCapacity, PixelFormatExtensions::SizeInBytes(format), name)
, _format(format)
, _isUnorderedAccess(isUnorderedAccess)
{
}
void DynamicTypedBuffer::InitDesc(GPUBufferDescription& desc, int32 numElements)
{
auto bufferFlags = GPUBufferFlags::ShaderResource;
if (_isUnorderedAccess)
bufferFlags |= GPUBufferFlags::UnorderedAccess;
desc = GPUBufferDescription::Buffer(numElements * _stride, bufferFlags, _format, nullptr, _stride);
}