Skip to content

Commit ea0434d

Browse files
committed
Fix TLM allocator
1 parent e402800 commit ea0434d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/engine/renderer-vulkan/Thread/ThreadMemory.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,25 @@ byte* ThreadMemory::Alloc( const uint64 size, const uint64 alignment ) {
141141
chunkID |= id << 4;
142142
}
143143

144+
#ifdef _MSC_VER
145+
static constexpr const char* pathStrip = "engine\\renderer-vulkan\\";
146+
#else
147+
static constexpr const char* pathStrip = "engine/renderer-vulkan/";
148+
#endif
149+
144150
std::string source = FormatStackTrace( std::stacktrace::current(), true, true );
145-
AllocationRecord alloc{ .size = dataSize, .alignment = ( uint32 ) alignment, .chunkID = chunkID };
146151

147-
Q_strncpyz( alloc.source, source.size() < 104 ? source.c_str() : source.c_str() + ( source.size() - 103 ), 103 );
152+
uint32_t pos = 0;
153+
while ( ( pos = source.find( pathStrip, pos ) ) < source.size() ) {
154+
source = source.erase( pos, strlen( pathStrip ) );
155+
}
156+
157+
AllocationRecord alloc { .size = dataSize, .alignment = ( uint32 ) alignment, .chunkID = chunkID };
158+
159+
Q_strncpyz( alloc.source, source.c_str(), 103 );
148160
alloc.source[103] = '\0';
149161

150-
*( ( AllocationRecord* ) found->chunk.memory + found->offset ) = alloc;
162+
*( ( AllocationRecord* ) ( found->chunk.memory + found->offset ) ) = alloc;
151163

152164
byte* ret = found->chunk.memory + found->offset + sizeof( AllocationRecord );
153165
found->offset += paddedSize;
@@ -163,12 +175,12 @@ void ThreadMemory::Free( byte* memory ) {
163175
Err( "Memory chunk corrupted: %s", record->Format() );
164176
}
165177

178+
UnSetBit( &record->chunkID, 31 );
179+
166180
uint32 chunkID = record->chunkID >> 4;
167181
uint32 area = chunkID / 64;
168182
ChunkAllocator& chunkAllocator = chunkAllocators[record->chunkID & 0xF][area];
169183

170-
UnSetBit( &record->chunkID, 31 );
171-
172184
uint32 chunk = chunkID - area;
173185
chunkAllocator.chunks[chunk].allocs--;
174186

0 commit comments

Comments
 (0)