mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-10-23 20:41:13 +00:00
Make aligned buffer allocation a common function, out of serialiser
This commit is contained in:
14 files changed
+85
-85
No files matched your search
@@ -238,6 +238,47 @@ uint32_t CalcNumMips(int w, int h, int d)
|
||||
return mipLevels;
|
||||
}
|
||||
|
||||
byte *AllocAlignedBuffer(uint64_t size, uint64_t alignment)
|
||||
{
|
||||
byte *rawAlloc = NULL;
|
||||
|
||||
#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
|
||||
try
|
||||
#endif
|
||||
{
|
||||
rawAlloc = new byte[(size_t)size + sizeof(byte *) + (size_t)alignment];
|
||||
}
|
||||
#if defined(__EXCEPTIONS) || defined(_CPPUNWIND)
|
||||
catch(std::bad_alloc &)
|
||||
{
|
||||
rawAlloc = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(rawAlloc == NULL)
|
||||
RDCFATAL("Allocation for %llu bytes failed", size);
|
||||
|
||||
RDCASSERT(rawAlloc);
|
||||
|
||||
byte *alignedAlloc = (byte *)AlignUp(uint64_t(rawAlloc + sizeof(byte *)), alignment);
|
||||
|
||||
byte **realPointer = (byte **)alignedAlloc;
|
||||
realPointer[-1] = rawAlloc;
|
||||
|
||||
return alignedAlloc;
|
||||
}
|
||||
|
||||
void FreeAlignedBuffer(byte *buf)
|
||||
{
|
||||
if(buf == NULL)
|
||||
return;
|
||||
|
||||
byte **realPointer = (byte **)buf;
|
||||
byte *rawAlloc = realPointer[-1];
|
||||
|
||||
delete[] rawAlloc;
|
||||
}
|
||||
|
||||
uint32_t Log2Floor(uint32_t value)
|
||||
{
|
||||
RDCASSERT(value > 0);
|
||||
|
||||
Reference in new issue
Block a user