Skip to content

Commit df76480

Browse files
Fixes in GpuMemDumpVis.py regarding image height calculation
Added GpuMemDump.schema.json. Minor improvement in SaveAllocatorStatsToFile.
1 parent 0c7ad4e commit df76480

File tree

4 files changed

+173
-11
lines changed

4 files changed

+173
-11
lines changed

src/SparseBindingTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern VkCommandBuffer g_hTemporaryCommandBuffer;
3838

3939
void BeginSingleTimeCommands();
4040
void EndSingleTimeCommands();
41-
void SaveAllocatorStatsToFile(const wchar_t* filePath);
41+
void SaveAllocatorStatsToFile(const wchar_t* filePath, bool detailed = true);
4242
void LoadShader(std::vector<char>& out, const char* fileName);
4343

4444
////////////////////////////////////////////////////////////////////////////////

src/Tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,12 @@ VkResult MainTest(Result& outResult, const Config& config)
719719
return res;
720720
}
721721

722-
void SaveAllocatorStatsToFile(const wchar_t* filePath)
722+
void SaveAllocatorStatsToFile(const wchar_t* filePath, bool detailed = true)
723723
{
724724
#if !defined(VMA_STATS_STRING_ENABLED) || VMA_STATS_STRING_ENABLED
725725
wprintf(L"Saving JSON dump to file \"%s\"\n", filePath);
726726
char* stats;
727-
vmaBuildStatsString(g_hAllocator, &stats, VK_TRUE);
727+
vmaBuildStatsString(g_hAllocator, &stats, detailed ? VK_TRUE : VK_FALSE);
728728
SaveFile(filePath, stats, strlen(stats));
729729
vmaFreeStatsString(g_hAllocator, stats);
730730
#endif
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"$id": "https://gpuopen.com/vulkan-memory-allocator/schemas/GpuMemDump",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"type": "object",
5+
"properties": {
6+
"General": {
7+
"type": "object",
8+
"properties": {
9+
"API": {"type": "string", "enum": ["Vulkan", "Direct3D 12"]},
10+
"GPU": {"type": "string"}
11+
},
12+
"required": ["API", "GPU"]
13+
},
14+
"Total": {"$ref": "#/$defs/Stats"},
15+
"MemoryInfo": {
16+
"type": "object",
17+
"additionalProperties": {
18+
"type": "object",
19+
"properties": {
20+
"Flags": {
21+
"type": "array",
22+
"items": {"type": "string"}
23+
},
24+
"Size": {"type": "integer"},
25+
"Budget": {
26+
"type": "object",
27+
"properties": {
28+
"BudgetBytes": {"type": "integer"},
29+
"UsageBytes": {"type": "integer"}
30+
},
31+
"additionalProperties": false
32+
},
33+
"Stats": {"$ref": "#/$defs/Stats"},
34+
"MemoryPools": {
35+
"type": "object",
36+
"additionalProperties": {
37+
"type": "object",
38+
"properties": {
39+
"Flags": {
40+
"type": "array",
41+
"items": {"type": "string"}
42+
},
43+
"Stats": {"$ref": "#/$defs/Stats"}
44+
},
45+
"additionalProperties": false
46+
}
47+
}
48+
},
49+
"required": ["Budget", "Stats"],
50+
"additionalProperties": false
51+
}
52+
},
53+
"DefaultPools": {
54+
"type": "object",
55+
"additionalProperties": {
56+
"type": "object",
57+
"properties": {
58+
"PreferredBlockSize": {"type": "integer"},
59+
"Blocks": {
60+
"type": "object",
61+
"propertyNames": {"pattern": "[0-9]+"},
62+
"additionalProperties": {"$ref": "#/$defs/Block"}
63+
},
64+
"DedicatedAllocations": {
65+
"type": "array",
66+
"items": {"$ref": "#/$defs/DedicatedAllocation"}
67+
}
68+
}
69+
}
70+
},
71+
"CustomPools": {
72+
"type": "object",
73+
"additionalProperties": {
74+
"type": "array",
75+
"items": {
76+
"type": "object",
77+
"properties": {
78+
"Name": {"type": "string"},
79+
"Flags": {"type": "array"},
80+
"PreferredBlockSize": {"type": "integer"},
81+
"Blocks": {
82+
"type": "object",
83+
"additionalProperties": {"$ref": "#/$defs/Block"}
84+
},
85+
"DedicatedAllocations": {
86+
"type": "array",
87+
"items": {"$ref": "#/$defs/DedicatedAllocation"}
88+
}
89+
},
90+
"required": ["PreferredBlockSize"],
91+
"additionalProperties": false
92+
}
93+
}
94+
}
95+
},
96+
"required": ["General", "Total", "MemoryInfo"],
97+
"additionalProperties": false,
98+
"$defs": {
99+
"CustomData": {
100+
"type": "string",
101+
"pattern": "^[0-9a-zA-Z]+$"
102+
},
103+
"Stats": {
104+
"type": "object",
105+
"properties": {
106+
"BlockCount": {"type": "integer"},
107+
"BlockBytes": {"type": "integer"},
108+
"AllocationCount": {"type": "integer"},
109+
"AllocationBytes": {"type": "integer"},
110+
"UnusedRangeCount": {"type": "integer"},
111+
"AllocationSizeMin": {"type": "integer"},
112+
"AllocationSizeMax": {"type": "integer"},
113+
"UnusedRangeSizeMin": {"type": "integer"},
114+
"UnusedRangeSizeMax": {"type": "integer"}
115+
},
116+
"required": [
117+
"BlockCount", "BlockBytes",
118+
"AllocationCount", "AllocationBytes",
119+
"UnusedRangeCount"
120+
],
121+
"additionalProperties": false
122+
},
123+
"Block": {
124+
"type": "object",
125+
"properties": {
126+
"MapRefCount": {"type": "integer"},
127+
"TotalBytes": {"type": "integer"},
128+
"UnusedBytes": {"type": "integer"},
129+
"Allocations": {"type": "integer"},
130+
"UnusedRanges": {"type": "integer"},
131+
"Suballocations": {"type": "array", "items": {"$ref": "#/$defs/Suballocation"}}
132+
},
133+
"required": ["TotalBytes", "UnusedBytes", "Allocations", "UnusedRanges"]
134+
},
135+
"DedicatedAllocation": {
136+
"type": "object",
137+
"properties": {
138+
"Type": {"type": "string"},
139+
"Size": {"type": "integer"},
140+
"Usage": {"type": "integer"},
141+
"CustomData": {"$ref": "#/$defs/CustomData"},
142+
"Name": {"type": "string"},
143+
"Layout": {"type": "integer"}
144+
},
145+
"required": ["Type", "Size"],
146+
"additionalProperties": false
147+
},
148+
"Suballocation": {
149+
"type": "object",
150+
"properties": {
151+
"Offset": {"type": "integer"},
152+
"Type": {"type": "string"},
153+
"Size": {"type": "integer"},
154+
"Usage": {"type": "integer"},
155+
"CustomData": {"$ref": "#/$defs/CustomData"},
156+
"Name": {"type": "string"},
157+
"Layout": {"type": "integer"}
158+
},
159+
"required": ["Offset", "Type", "Size"],
160+
"additionalProperties": false
161+
}
162+
}
163+
}

tools/GpuMemDumpVis/GpuMemDumpVis.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,25 @@ def CalcParams():
106106
maxBlockSize = 0
107107
# Get height occupied by every memory pool
108108
for poolData in data.values():
109-
height += IMG_MARGIN + FONT_SIZE
110-
height += len(poolData['DedicatedAllocations']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
111-
height += len(poolData['Blocks']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
109+
height += FONT_SIZE + IMG_MARGIN # Memory pool title
110+
height += len(poolData['Blocks']) * (FONT_SIZE + MAP_SIZE + IMG_MARGIN * 2)
111+
height += len(poolData['DedicatedAllocations']) * (FONT_SIZE + MAP_SIZE + IMG_MARGIN * 2)
112112
# Get longest block size
113113
for dedicatedAlloc in poolData['DedicatedAllocations']:
114114
maxBlockSize = max(maxBlockSize, dedicatedAlloc['Size'])
115115
for block in poolData['Blocks']:
116116
maxBlockSize = max(maxBlockSize, block['Size'])
117117
# Same for custom pools
118118
for customPoolData in poolData['CustomPools'].values():
119-
height += len(customPoolData['DedicatedAllocations']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
120-
height += len(customPoolData['Blocks']) * (IMG_MARGIN * 2 + FONT_SIZE + MAP_SIZE)
121-
height += FONT_SIZE * 2 + IMG_MARGIN if len(customPoolData['DedicatedAllocations']) == 0 else 0
119+
height += len(customPoolData['Blocks']) * (FONT_SIZE + MAP_SIZE + IMG_MARGIN * 2)
120+
height += len(customPoolData['DedicatedAllocations']) * (FONT_SIZE + MAP_SIZE + IMG_MARGIN * 2)
122121
# Get longest block size
123122
for dedicatedAlloc in customPoolData['DedicatedAllocations']:
124123
maxBlockSize = max(maxBlockSize, dedicatedAlloc['Size'])
125124
for block in customPoolData['Blocks']:
126125
maxBlockSize = max(maxBlockSize, block['Size'])
127126

128-
return height + FONT_SIZE, (IMG_WIDTH - IMG_MARGIN * 2) / float(maxBlockSize)
127+
return height, (IMG_WIDTH - IMG_MARGIN * 2) / float(maxBlockSize)
129128

130129
def BytesToStr(bytes):
131130
if bytes < 1024:
@@ -306,7 +305,7 @@ def DrawDedicatedAllocationBlock(draw, y, dedicatedAlloc, pixelsPerByte):
306305
draw.text((IMG_MARGIN, y), "Custom pool %s block %s" % (poolName, block['ID']), fill=COLOR_TEXT_H2, font=font)
307306
y += FONT_SIZE + IMG_MARGIN
308307
DrawBlock(draw, y, block, pixelsPerByte)
309-
y += 2 * (FONT_SIZE + IMG_MARGIN)
308+
y += MAP_SIZE + IMG_MARGIN
310309
index = 0
311310
for dedicatedAlloc in pool['DedicatedAllocations']:
312311
draw.text((IMG_MARGIN, y), "Custom pool %s dedicated allocation %d" % (poolName, index), fill=COLOR_TEXT_H2, font=font)

0 commit comments

Comments
 (0)