27 gl46core::GLenum usage = gl46core::GL_NONE;
64 _memoryBlock._bufferHandle,
68 _memoryBlock._offset = 0u;
69 _memoryBlock._size = _params._dataSize;
70 _memoryBlock._free =
false;
74 const gl46core::BufferStorageMask storageMask = gl46core::GL_MAP_PERSISTENT_BIT | gl46core::GL_MAP_WRITE_BIT | gl46core::GL_MAP_COHERENT_BIT;
75 const gl46core::BufferAccessMask accessMask = gl46core::GL_MAP_PERSISTENT_BIT | gl46core::GL_MAP_WRITE_BIT | gl46core::GL_MAP_COHERENT_BIT;
77 const size_t alignment = params.
_target == gl46core::GL_UNIFORM_BUFFER
79 : _params._target == gl46core::GL_SHADER_STORAGE_BUFFER
84 _memoryBlock = allocator.
allocate( _params._useChunkAllocation,
92 assert( _memoryBlock._ptr !=
nullptr && _memoryBlock._size >= _params._dataSize &&
"PersistentBuffer::Create error: Can't mapped persistent buffer!" );
100 if ( !
lockRange( { 0u, _params._dataSize }, sync ) )
118 if ( _memoryBlock._ptr !=
nullptr )
136 assert( rangeInBytes > 0u && offsetInBytes + rangeInBytes <= _memoryBlock._size );
139 PROFILE_TAG(
"Mapped",
static_cast<bool>(_memoryBlock._ptr !=
nullptr) );
155 if ( _memoryBlock._ptr !=
nullptr ) [[likely]]
157 if ( data ==
nullptr )
159 memset( &_memoryBlock._ptr[offsetInBytes], 0, rangeInBytes );
163 memcpy( &_memoryBlock._ptr[offsetInBytes], data, rangeInBytes );
166 ret.
_range = {offsetInBytes, rangeInBytes};
170 DIVIDE_ASSERT( data ==
nullptr || firstWrite,
"glBufferImpl: trying to write to a buffer create with BufferUpdateFrequency::ONCE" );
172 Byte* ptr = (
Byte*)gl46core::glMapNamedBufferRange( _memoryBlock._bufferHandle, _memoryBlock._offset + offsetInBytes, rangeInBytes, gl46core::GL_MAP_WRITE_BIT | gl46core::GL_MAP_INVALIDATE_RANGE_BIT | gl46core::GL_MAP_UNSYNCHRONIZED_BIT );
173 if ( data ==
nullptr )
175 memset( ptr, 0, rangeInBytes );
179 memcpy( ptr, data, rangeInBytes );
181 gl46core::glUnmapNamedBuffer( _memoryBlock._bufferHandle );
197 if ( _memoryBlock._ptr !=
nullptr ) [[likely]]
199 DIVIDE_ASSERT(rangeInBytes + offsetInBytes <= _memoryBlock._size );
200 memcpy( outData.first, _memoryBlock._ptr + offsetInBytes, rangeInBytes);
209 gl46core::GL_STREAM_READ,
216 gl46core::glCopyNamedBufferSubData( _memoryBlock._bufferHandle,
_copyBufferTarget, _memoryBlock._offset + offsetInBytes, 0u, rangeInBytes );
218 const Byte* bufferData = (
Byte*)gl46core::glMapNamedBufferRange(
_copyBufferTarget, 0u, rangeInBytes, gl46core::BufferAccessMask::GL_MAP_READ_BIT );
219 assert( bufferData !=
nullptr );
220 memcpy( outData.first, bufferData, rangeInBytes );
#define PROFILE_SCOPE_AUTO(CATEGORY)
#define PROFILE_TAG(NAME,...)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
static const DeviceInformation & GetDeviceInformation() noexcept
PerformanceMetrics & getPerformanceMetrics() noexcept
static GLUtil::GLMemory::DeviceAllocator & GetMemoryAllocator(GLUtil::GLMemory::GLMemoryType memoryType) noexcept
static GLUtil::GLMemory::GLMemoryType GetMemoryTypeForUsage(gl46core::GLenum usage) noexcept
void deallocate(const Block &block) const
Block allocate(bool poolAllocations, size_t size, size_t alignment, gl46core::BufferStorageMask storageMask, gl46core::BufferAccessMask accessMask, gl46core::GLenum usage, const char *blockName, std::pair< bufferPtr, size_t > initialData)
static constexpr U8 DEFAULT_SYNC_FLAG_SSBO
static SyncObjectHandle CreateSyncObject(RenderAPI api, U8 flag=DEFAULT_SYNC_FLAG_INTERNAL)
BufferLock writeOrClearBytes(size_t offsetInBytes, size_t rangeInBytes, const bufferPtr data, bool firstWrite=false)
virtual ~glBufferImpl() override
gl46core::GLuint _copyBufferTarget
void readBytes(size_t offsetInBytes, size_t rangeInBytes, std::pair< bufferPtr, size_t > outData)
glBufferImpl(GFXDevice &context, const BufferImplParams ¶ms, const std::pair< const bufferPtr, size_t > &initialData, const char *name)
void freeBuffer(gl46core::GLuint &bufferId, bufferPtr mappedPtr)
void createAndAllocBuffer(const size_t bufferSize, const gl46core::GLenum usageMask, gl46core::GLuint &bufferIdOut, const std::pair< bufferPtr, size_t > initialData, const char *name)
constexpr Optick::Category::Type Graphics
bool isMainThread() noexcept
Str StringFormat(const char *fmt, Args &&...args)
Handle console commands that start with a forward slash.
std::lock_guard< mutex > LockGuard
constexpr U32 to_U32(const T value)
constexpr gl46core::GLuint GL_NULL_HANDLE
Invalid object value. Used to compare handles and determine if they were properly created.
BufferUpdateUsage _updateUsage
BufferUpdateFrequency _updateFrequency
BufferParams _bufferParams
static NO_INLINE void errorfn(const char *format, T &&... args)
bool waitForLockedRange(BufferRange range) const
bool lockRange(BufferRange range, SyncObjectHandle &sync) const
LockManager_uptr _lockManager