Skip to content

Commit bc9b5f1

Browse files
author
devsh
committed
make the default memcpy IUTilities buffer streaming callback public (its useful externally too)
1 parent c32846f commit bc9b5f1

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

include/nbl/video/utilities/IUtilities.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,18 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
436436
return updateBufferRangeViaStagingBuffer(nextSubmit,bufferRange,callback);
437437
}
438438

439+
//
440+
class CMemcpyUpstreamingDataProducer final : public IUpstreamingDataProducer
441+
{
442+
public:
443+
inline uint32_t operator()(void* dst, const size_t offsetInRange, const uint32_t blockSize) override
444+
{
445+
memcpy(dst,reinterpret_cast<const uint8_t*>(data)+offsetInRange,blockSize);
446+
return blockSize;
447+
}
448+
449+
const void* data;
450+
};
439451
//! Copies `data` to stagingBuffer and Records the commands needed to copy the data from stagingBuffer to `bufferRange.buffer`.
440452
//! Returns same as `updateBufferRangeViaStagingBuffer` with a callback instead of a pointer, make sure to submit with `nextSubmit.popSubmit()` after this function returns.
441453
//! Parameters:
@@ -448,25 +460,9 @@ class NBL_API2 IUtilities : public core::IReferenceCounted
448460
template<typename IntendedSubmitInfo> requires std::is_same_v<std::decay_t<IntendedSubmitInfo>,SIntendedSubmitInfo>
449461
inline bool updateBufferRangeViaStagingBuffer(IntendedSubmitInfo&& nextSubmit, const asset::SBufferRange<IGPUBuffer>& bufferRange, const void* data)
450462
{
451-
// We check the guarantees of our documentation with the asserts while we're at it
452-
#ifdef _NBL_DEBUG
453-
size_t prevRangeEnd = 0;
454-
#endif
455-
456-
auto retval = updateBufferRangeViaStagingBuffer(nextSubmit,bufferRange,wrapUpstreamingDataProducerLambda(
457-
[&](void* dst, const size_t offsetInRange, const uint32_t blockSize) -> uint32_t
458-
{
459-
#ifdef _NBL_DEBUG
460-
assert(offsetInRange==prevRangeEnd);
461-
prevRangeEnd = offsetInRange+blockSize;
462-
#endif
463-
memcpy(dst,reinterpret_cast<const uint8_t*>(data)+offsetInRange,blockSize);
464-
return blockSize;
465-
}
466-
));
467-
#ifdef _NBL_DEBUG
468-
assert(prevRangeEnd==bufferRange.size);
469-
#endif
463+
CMemcpyUpstreamingDataProducer memcpyCb;
464+
memcpyCb.data = data;
465+
bool retval = updateBufferRangeViaStagingBuffer(nextSubmit,bufferRange,memcpyCb);
470466
return retval;
471467
}
472468

0 commit comments

Comments
 (0)