Skip to content

Commit 18a85ee

Browse files
committed
Don't allocate memory for arrays when structured serialising
1 parent 3bf805e commit 18a85ee

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

renderdoc/serialise/serialiser.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Serialiser
117117
Serialiser(const Serialiser &other) = delete;
118118

119119
bool IsErrored() { return IsReading() ? m_Read->IsErrored() : m_Write->IsErrored(); }
120+
bool IsDummy() { return m_Dummy; }
120121
StreamWriter *GetWriter() { return m_Write; }
121122
StreamReader *GetReader() { return m_Read; }
122123
uint32_t GetChunkMetadataRecording() { return m_ChunkFlags; }
@@ -299,7 +300,7 @@ class Serialiser
299300
// ScopedDeseralise* classes. We can verify with e.g. valgrind that there are no leaks, so to keep
300301
// the analysis non-spammy we just don't allocate for coverity builds
301302
#if !defined(__COVERITY__)
302-
if(flags & SerialiserFlags::AllocateMemory)
303+
if(!m_Dummy && (flags & SerialiserFlags::AllocateMemory))
303304
{
304305
if(byteSize > 0)
305306
el = AllocAlignedBuffer(byteSize);
@@ -702,7 +703,7 @@ class Serialiser
702703
// ScopedDeseralise* classes. We can verify with e.g. valgrind that there are no leaks, so to keep
703704
// the analysis non-spammy we just don't allocate for coverity builds
704705
#if !defined(__COVERITY__)
705-
if(IsReading() && (flags & SerialiserFlags::AllocateMemory))
706+
if(IsReading() && !m_Dummy && (flags & SerialiserFlags::AllocateMemory))
706707
{
707708
if(arrayCount > 0)
708709
el = new T[(size_t)arrayCount];
@@ -737,7 +738,7 @@ class Serialiser
737738
// ScopedDeseralise* classes. We can verify with e.g. valgrind that there are no leaks, so to keep
738739
// the analysis non-spammy we just don't allocate for coverity builds
739740
#if !defined(__COVERITY__)
740-
if(IsReading() && (flags & SerialiserFlags::AllocateMemory))
741+
if(IsReading() && !m_Dummy && (flags & SerialiserFlags::AllocateMemory))
741742
{
742743
if(arrayCount > 0)
743744
el = new T[(size_t)arrayCount];
@@ -1487,6 +1488,7 @@ class Serialiser
14871488
Serialiser(StreamWriter *writer, Ownership own);
14881489
Serialiser(StreamReader *reader, Ownership own, SDObject *rootStructuredObj);
14891490

1491+
void SetDummy(bool dummy) { m_Dummy = dummy; }
14901492
private:
14911493
static const uint64_t ChunkAlignment = 64;
14921494
template <class SerialiserMode, typename T, bool isEnum = std::is_enum<T>::value>
@@ -1550,6 +1552,7 @@ class Serialiser
15501552
// See SetStreamingMode
15511553
bool m_DataStreaming = false;
15521554
bool m_DrawChunk = false;
1555+
bool m_Dummy = false;
15531556

15541557
uint64_t m_LastChunkOffset = 0;
15551558
uint64_t m_ChunkFixup = 0;
@@ -1617,6 +1620,7 @@ class StructuredSerialiser : public Serialiser<SerialiserMode::Reading>
16171620
{
16181621
ConfigureStructuredExport(lookup, false);
16191622
SetStreamingMode(true);
1623+
SetDummy(true);
16201624
}
16211625
};
16221626
#endif

0 commit comments

Comments
 (0)