Skip to content

Commit b68b368

Browse files
Merge branch 'master' into MemoryBudget
2 parents b85ff83 + 8317ba9 commit b68b368

10 files changed

Lines changed: 391 additions & 107 deletions

File tree

docs/Recording file format.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Formats with only minor version incremented are backward compatible.
2323
VmaReplay application supports all older versions.
2424
Current version is:
2525

26-
1,6
26+
1,7
2727

2828
# Configuration
2929

@@ -243,6 +243,11 @@ No parameters.
243243

244244
- context : pointer
245245

246+
**vmaSetPoolName** (min format version: 1.7)
247+
248+
- pool : pointer
249+
- pName : string (may contain additional commas)
250+
246251
# Data types
247252

248253
**bool**
@@ -271,7 +276,7 @@ An ordered sequence of values of some type, separated by single space.
271276
# Example file
272277

273278
Vulkan Memory Allocator,Calls recording
274-
1,6
279+
1,7
275280
Config,Begin
276281
PhysicalDevice,apiVersion,4198477
277282
PhysicalDevice,driverVersion,8388653

src/Doxyfile

Lines changed: 144 additions & 70 deletions
Large diffs are not rendered by default.

src/Tests.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,8 @@ static void TestBasics()
19881988

19891989
void TestHeapSizeLimit()
19901990
{
1991-
const VkDeviceSize HEAP_SIZE_LIMIT = 1ull * 1024 * 1024 * 1024; // 1 GB
1992-
const VkDeviceSize BLOCK_SIZE = 128ull * 1024 * 1024; // 128 MB
1991+
const VkDeviceSize HEAP_SIZE_LIMIT = 200ull * 1024 * 1024; // 200 MB
1992+
const VkDeviceSize BLOCK_SIZE = 20ull * 1024 * 1024; // 20 MB
19931993

19941994
VkDeviceSize heapSizeLimit[VK_MAX_MEMORY_HEAPS];
19951995
for(uint32_t i = 0; i < VK_MAX_MEMORY_HEAPS; ++i)
@@ -3111,6 +3111,18 @@ static void TestPool_SameSize()
31113111
res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool);
31123112
TEST(res == VK_SUCCESS);
31133113

3114+
// Test pool name
3115+
{
3116+
static const char* const POOL_NAME = "Pool name";
3117+
vmaSetPoolName(g_hAllocator, pool, POOL_NAME);
3118+
3119+
const char* fetchedPoolName = nullptr;
3120+
vmaGetPoolName(g_hAllocator, pool, &fetchedPoolName);
3121+
TEST(strcmp(fetchedPoolName, POOL_NAME) == 0);
3122+
3123+
vmaSetPoolName(g_hAllocator, pool, nullptr);
3124+
}
3125+
31143126
vmaSetCurrentFrameIndex(g_hAllocator, 1);
31153127

31163128
VmaAllocationCreateInfo allocInfo = {};

src/VmaReplay/Common.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,16 @@ class CsvSplit
173173
size_t GetCount() const { return m_Count; }
174174
StrRange GetRange(size_t index) const
175175
{
176-
return StrRange {
177-
m_Line.beg + m_Ranges[index * 2],
178-
m_Line.beg + m_Ranges[index * 2 + 1] };
176+
if(index < m_Count)
177+
{
178+
return StrRange {
179+
m_Line.beg + m_Ranges[index * 2],
180+
m_Line.beg + m_Ranges[index * 2 + 1] };
181+
}
182+
else
183+
{
184+
return StrRange{0, 0};
185+
}
179186
}
180187

181188
private:

src/VmaReplay/Constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const char* VMA_FUNCTION_NAMES[] = {
5454
"vmaResizeAllocation",
5555
"vmaDefragmentationBegin",
5656
"vmaDefragmentationEnd",
57+
"vmaSetPoolName",
5758
};
5859
static_assert(
5960
_countof(VMA_FUNCTION_NAMES) == (size_t)VMA_FUNCTION::Count,

src/VmaReplay/Constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum class VMA_FUNCTION
8787
ResizeAllocation,
8888
DefragmentationBegin,
8989
DefragmentationEnd,
90+
SetPoolName,
9091
Count
9192
};
9293
extern const char* VMA_FUNCTION_NAMES[];

src/VmaReplay/VmaReplay.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ static size_t g_DefragmentAfterLineNextIndex = 0;
688688
static bool ValidateFileVersion()
689689
{
690690
if(GetVersionMajor(g_FileVersion) == 1 &&
691-
GetVersionMinor(g_FileVersion) <= 6)
691+
GetVersionMinor(g_FileVersion) <= 7)
692692
{
693693
return true;
694694
}
@@ -1665,6 +1665,7 @@ class Player
16651665
void ExecuteResizeAllocation(size_t lineNumber, const CsvSplit& csvSplit);
16661666
void ExecuteDefragmentationBegin(size_t lineNumber, const CsvSplit& csvSplit);
16671667
void ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSplit);
1668+
void ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit);
16681669

16691670
void DestroyAllocation(size_t lineNumber, const CsvSplit& csvSplit, const char* functionName);
16701671

@@ -1819,6 +1820,8 @@ void Player::ExecuteLine(size_t lineNumber, const StrRange& line)
18191820
ExecuteDefragmentationBegin(lineNumber, csvSplit);
18201821
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::DefragmentationEnd]))
18211822
ExecuteDefragmentationEnd(lineNumber, csvSplit);
1823+
else if(StrRangeEq(functionName, VMA_FUNCTION_NAMES[(uint32_t)VMA_FUNCTION::SetPoolName]))
1824+
ExecuteSetPoolName(lineNumber, csvSplit);
18221825
else
18231826
{
18241827
if(IssueWarning())
@@ -3863,6 +3866,48 @@ void Player::ExecuteDefragmentationEnd(size_t lineNumber, const CsvSplit& csvSpl
38633866
}
38643867
}
38653868

3869+
void Player::ExecuteSetPoolName(size_t lineNumber, const CsvSplit& csvSplit)
3870+
{
3871+
m_Stats.RegisterFunctionCall(VMA_FUNCTION::SetPoolName);
3872+
3873+
if(!g_UserDataEnabled)
3874+
{
3875+
return;
3876+
}
3877+
3878+
if(ValidateFunctionParameterCount(lineNumber, csvSplit, 2, true))
3879+
{
3880+
uint64_t origPtr = 0;
3881+
if(StrRangeToPtr(csvSplit.GetRange(FIRST_PARAM_INDEX), origPtr))
3882+
{
3883+
if(origPtr != 0)
3884+
{
3885+
const auto it = m_Pools.find(origPtr);
3886+
if(it != m_Pools.end())
3887+
{
3888+
std::string poolName;
3889+
csvSplit.GetRange(FIRST_PARAM_INDEX + 1).to_str(poolName);
3890+
vmaSetPoolName(m_Allocator, it->second.pool, !poolName.empty() ? poolName.c_str() : nullptr);
3891+
}
3892+
else
3893+
{
3894+
if(IssueWarning())
3895+
{
3896+
printf("Line %zu: Pool %llX not found.\n", lineNumber, origPtr);
3897+
}
3898+
}
3899+
}
3900+
}
3901+
else
3902+
{
3903+
if(IssueWarning())
3904+
{
3905+
printf("Line %zu: Invalid parameters for vmaSetPoolName.\n", lineNumber);
3906+
}
3907+
}
3908+
}
3909+
}
3910+
38663911
////////////////////////////////////////////////////////////////////////////////
38673912
// Main functions
38683913

src/VulkanSample.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "Tests.h"
2727
#include "VmaUsage.h"
2828
#include "Common.h"
29+
#include <atomic>
2930

3031
static const char* const SHADER_PATH1 = "./";
3132
static const char* const SHADER_PATH2 = "../bin/";
@@ -37,7 +38,7 @@ static const wchar_t* const APP_TITLE_W = L"Vulkan Memory Allocator Sample 2.3.0
3738
static const bool VSYNC = true;
3839
static const uint32_t COMMAND_BUFFER_COUNT = 2;
3940
static void* const CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA = (void*)(intptr_t)43564544;
40-
static const bool USE_CUSTOM_CPU_ALLOCATION_CALLBACKS = false;
41+
static const bool USE_CUSTOM_CPU_ALLOCATION_CALLBACKS = true;
4142

4243
VkPhysicalDevice g_hPhysicalDevice;
4344
VkDevice g_hDevice;
@@ -111,26 +112,47 @@ static VkImage g_hTextureImage;
111112
static VmaAllocation g_hTextureImageAlloc;
112113
static VkImageView g_hTextureImageView;
113114

115+
static std::atomic_uint32_t g_CpuAllocCount;
116+
114117
static void* CustomCpuAllocation(
115118
void* pUserData, size_t size, size_t alignment,
116119
VkSystemAllocationScope allocationScope)
117120
{
118121
assert(pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
119-
return _aligned_malloc(size, alignment);
122+
void* const result = _aligned_malloc(size, alignment);
123+
if(result)
124+
{
125+
++g_CpuAllocCount;
126+
}
127+
return result;
120128
}
121129

122130
static void* CustomCpuReallocation(
123131
void* pUserData, void* pOriginal, size_t size, size_t alignment,
124132
VkSystemAllocationScope allocationScope)
125133
{
126134
assert(pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
127-
return _aligned_realloc(pOriginal, size, alignment);
135+
void* const result = _aligned_realloc(pOriginal, size, alignment);
136+
if(pOriginal && !result)
137+
{
138+
--g_CpuAllocCount;
139+
}
140+
else if(!pOriginal && result)
141+
{
142+
++g_CpuAllocCount;
143+
}
144+
return result;
128145
}
129146

130147
static void CustomCpuFree(void* pUserData, void* pMemory)
131148
{
132149
assert(pUserData == CUSTOM_CPU_ALLOCATION_CALLBACK_USER_DATA);
133-
_aligned_free(pMemory);
150+
if(pMemory)
151+
{
152+
const uint32_t oldAllocCount = g_CpuAllocCount.fetch_sub(1);
153+
TEST(oldAllocCount > 0);
154+
_aligned_free(pMemory);
155+
}
134156
}
135157

136158
static const VkAllocationCallbacks g_CpuAllocationCallbacks = {
@@ -1873,6 +1895,8 @@ int main()
18731895
DrawFrame();
18741896
}
18751897

1898+
TEST(g_CpuAllocCount.load() == 0);
1899+
18761900
return 0;
18771901
}
18781902

0 commit comments

Comments
 (0)