Skip to content

Commit 86c8426

Browse files
committed
IUtilities Allow for null (0 sized) staging buffers for download/upload
1 parent f70af54 commit 86c8426

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

include/nbl/video/utilities/IUtilities.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
3737
, m_allocationAlignment(allocationAlignment)
3838
, m_allocationAlignmentForBufferImageCopy(allocationAlignmentForBufferImageCopy)
3939
{
40-
m_defaultDownloadBuffer->getBuffer()->setObjectDebugName(("Default Download Buffer of Utilities "+std::to_string(ptrdiff_t(this))).c_str());
41-
m_defaultUploadBuffer->getBuffer()->setObjectDebugName(("Default Upload Buffer of Utilities "+std::to_string(ptrdiff_t(this))).c_str());
40+
if (m_defaultDownloadBuffer)
41+
m_defaultDownloadBuffer->getBuffer()->setObjectDebugName(("Default Download Buffer of Utilities "+std::to_string(ptrdiff_t(this))).c_str());
42+
if (m_defaultUploadBuffer)
43+
m_defaultUploadBuffer->getBuffer()->setObjectDebugName(("Default Upload Buffer of Utilities "+std::to_string(ptrdiff_t(this))).c_str());
4244
}
4345

4446
IUtilities() = delete;
@@ -94,6 +96,7 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
9496
core::smart_refctd_ptr<StreamingTransientDataBufferMT<> > defaultDownloadBuffer = nullptr;
9597

9698
// Try Create Download Buffer
99+
if (downstreamSize > 0u)
97100
{
98101
IGPUBuffer::SCreationParams streamingBufferCreationParams = {};
99102
streamingBufferCreationParams.size = downstreamSize;
@@ -127,6 +130,7 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
127130
defaultDownloadBuffer = core::make_smart_refctd_ptr<StreamingTransientDataBufferMT<>>(asset::SBufferRange<video::IGPUBuffer>{0ull,downstreamSize,std::move(buffer)},maxStreamingBufferAllocationAlignment,minStreamingBufferAllocationSize);
128131
}
129132
// Try Create Upload Buffer
133+
if (upstreamSize > 0u)
130134
{
131135
IGPUBuffer::SCreationParams streamingBufferCreationParams = {};
132136
streamingBufferCreationParams.size = upstreamSize;
@@ -374,6 +378,11 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
374378
//! * data must not be nullptr
375379
inline bool updateBufferRangeViaStagingBuffer(SIntendedSubmitInfo& nextSubmit, const asset::SBufferRange<IGPUBuffer>& bufferRange, IUpstreamingDataProducer& callback)
376380
{
381+
if (!m_defaultUploadBuffer)
382+
{
383+
m_logger.log("no staging buffer available for upload. check `upstreamSize` passed to `IUtilities::create`",system::ILogger::ELL_ERROR);
384+
return false;
385+
}
377386
if (!bufferRange.isValid() || !bufferRange.buffer->getCreationParams().usage.hasFlags(asset::IBuffer::EUF_TRANSFER_DST_BIT))
378387
{
379388
m_logger.log("Invalid `bufferRange` or buffer has no `EUF_TRANSFER_DST_BIT` usage flag, cannot `updateBufferRangeViaStagingBuffer`!", system::ILogger::ELL_ERROR);
@@ -623,6 +632,11 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
623632
template<typename IntendedSubmitInfo> requires std::is_same_v<std::decay_t<IntendedSubmitInfo>, SIntendedSubmitInfo>
624633
inline bool downloadBufferRangeViaStagingBuffer(const std::function<data_consumption_callback_t>& consumeCallback, IntendedSubmitInfo&& nextSubmit, const asset::SBufferRange<IGPUBuffer>& srcBufferRange)
625634
{
635+
if (!m_defaultDownloadBuffer)
636+
{
637+
m_logger.log("no staging buffer available for download. check `downstreamSize` passed to `IUtilities::create`",system::ILogger::ELL_ERROR);
638+
return false;
639+
}
626640
if (!srcBufferRange.isValid() || !srcBufferRange.buffer->getCreationParams().usage.hasFlags(asset::IBuffer::EUF_TRANSFER_SRC_BIT))
627641
{
628642
m_logger.log("Invalid `srcBufferRange` or buffer has no `EUF_TRANSFER_SRC_BIT` usage flag, cannot `downloadBufferRangeViaStagingBuffer`!",system::ILogger::ELL_ERROR);

src/nbl/video/utilities/IUtilities.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ bool IUtilities::updateImageViaStagingBuffer(
1111
const std::span<const asset::IImage::SBufferCopy> regions
1212
)
1313
{
14+
if (!m_defaultUploadBuffer)
15+
{
16+
m_logger.log("no staging buffer available for upload. check `upstreamSize` passed to `IUtilities::create`",system::ILogger::ELL_ERROR);
17+
return false;
18+
}
1419
auto* scratch = commonTransferValidation(intendedNextSubmit);
1520
if (!scratch)
1621
return false;
@@ -164,6 +169,11 @@ bool IUtilities::downloadImageViaStagingBuffer(
164169
void* dest, const std::span<const asset::IImage::SBufferCopy> regions
165170
)
166171
{
172+
if (!m_defaultDownloadBuffer)
173+
{
174+
m_logger.log("no staging buffer available for download. check `downstreamSize` passed to `IUtilities::create`",system::ILogger::ELL_ERROR);
175+
return false;
176+
}
167177
if (regions.empty())
168178
return false;
169179

0 commit comments

Comments
 (0)