Skip to content

Commit cac77e0

Browse files
committed
Detect and enable VK_EXT_memory_budget if available
1 parent c0ebd37 commit cac77e0

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

scopehal/Unit.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Unit::Unit(const string& rhs)
9191
m_type = UNIT_VOLT_SEC;
9292
else if(rhs == "hex")
9393
m_type = UNIT_HEXNUM;
94+
else if(rhs == "B")
95+
m_type = UNIT_BYTES;
9496
else
9597
LogWarning("Unrecognized unit \"%s\"\n", rhs.c_str());
9698
}
@@ -174,6 +176,9 @@ string Unit::ToString() const
174176
case UNIT_HEXNUM:
175177
return "hex";
176178

179+
case UNIT_BYTES:
180+
return "B";
181+
177182
default:
178183
return "unknown";
179184
}
@@ -388,6 +393,16 @@ void Unit::GetUnitSuffix(UnitType type, double num, double& scaleFactor, string&
388393
suffix = "Vs";
389394
break;
390395

396+
//Bytes: use binary rather than decimal scaling factors
397+
case UNIT_BYTES:
398+
if(scaleFactor <= 1e-9)
399+
scaleFactor = 1.0 / (1024 * 1024 * 1024);
400+
else if(scaleFactor <= 1e-6)
401+
scaleFactor = 1.0 / (1024 * 1024);
402+
else if(scaleFactor <= 1e-3)
403+
scaleFactor = 1.0 / 1024;
404+
break;
405+
391406
default:
392407
break;
393408
}

scopehal/Unit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class Unit
7575
UNIT_MILLIVOLTS, //Hack needed for voltage in the X axis since we use integer coordinates there
7676
UNIT_VOLT_SEC, //Hack needed to measure area under the curve in terms of volt-seconds
7777

78+
UNIT_BYTES, //used mostly for displaying memory usage
79+
7880
//TODO: more here
7981
};
8082

scopehal/VulkanInit.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,24 @@ uint32_t g_vkComputeDeviceDriverVer;
127127
*/
128128
vk::raii::PhysicalDevice* g_vkComputePhysicalDevice;
129129

130+
/**
131+
@brief Heap from which g_vkPinnedMemoryType is allocated
132+
*/
133+
uint32_t g_vkPinnedMemoryHeap = 0;
134+
135+
/**
136+
@brief Heap from which g_vkLocalMemoryType is allocated
137+
*/
138+
uint32_t g_vkLocalMemoryHeap = 0;
139+
130140
bool IsDevicePreferred(const vk::PhysicalDeviceProperties& a, const vk::PhysicalDeviceProperties& b);
131141

132142
//Feature flags indicating that we have support for specific data types / features on the GPU
133143
bool g_hasShaderInt64 = false;
134144
bool g_hasShaderInt16 = false;
135145
bool g_hasShaderInt8 = false;
136146
bool g_hasDebugUtils = false;
147+
bool g_hasMemoryBudget = false;
137148

138149
//Feature flags indicating specific drivers, for bug workarounds
139150
bool g_vulkanDeviceIsIntelMesa = false;
@@ -690,7 +701,18 @@ bool VulkanInit(bool skipGLFW)
690701
if(!strcmp(&ext.extensionName[0], "VK_KHR_shader_non_semantic_info"))
691702
{
692703
hasNonSemanticInfo = true;
693-
LogDebug("Device has KHR_shader_non_semantic_info, requesting it\n");
704+
LogDebug("Device has VK_KHR_shader_non_semantic_info, requesting it\n");
705+
}
706+
707+
if(!strcmp(&ext.extensionName[0], "VK_EXT_memory_budget"))
708+
{
709+
if(!hasPhysicalDeviceProperties2)
710+
LogWarning("VK_EXT_memory_budget is supported, but not VK_KHR_get_physical_device_properties2 so it's useless\n");
711+
else
712+
{
713+
LogDebug("Device has VK_EXT_memory_budget, requesting it\n");
714+
g_hasMemoryBudget = true;
715+
}
694716
}
695717
}
696718

@@ -701,6 +723,8 @@ bool VulkanInit(bool skipGLFW)
701723
devextensions.push_back("VK_KHR_portability_subset");
702724
if(hasNonSemanticInfo)
703725
devextensions.push_back("VK_KHR_shader_non_semantic_info");
726+
if(g_hasMemoryBudget)
727+
devextensions.push_back("VK_EXT_memory_budget");
704728
vk::DeviceCreateInfo devinfo(
705729
{},
706730
qinfo,
@@ -715,6 +739,8 @@ bool VulkanInit(bool skipGLFW)
715739
bool foundLocalType = false;
716740
g_vkPinnedMemoryType = 0;
717741
g_vkLocalMemoryType = 0;
742+
g_vkPinnedMemoryType = 0;
743+
g_vkLocalMemoryType = 0;
718744
auto memProperties = device.getMemoryProperties();
719745
auto devtype = device.getProperties().deviceType;
720746
for(size_t j=0; j<memProperties.memoryTypeCount; j++)
@@ -743,6 +769,7 @@ bool VulkanInit(bool skipGLFW)
743769
{
744770
foundPinnedType = true;
745771
g_vkPinnedMemoryType = j;
772+
g_vkPinnedMemoryHeap = mtype.heapIndex;
746773
}
747774
}
748775

@@ -762,6 +789,7 @@ bool VulkanInit(bool skipGLFW)
762789
{
763790
foundLocalType = true;
764791
g_vkLocalMemoryType = j;
792+
g_vkLocalMemoryHeap = mtype.heapIndex;
765793
}
766794
}
767795
}

scopehal/scopehal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ extern std::unique_ptr<QueueManager> g_vkQueueManager;
198198
extern bool g_vulkanDeviceIsIntelMesa;
199199
extern bool g_vulkanDeviceIsAnyMesa;
200200
extern bool g_vulkanDeviceIsMoltenVK;
201+
extern uint32_t g_vkPinnedMemoryHeap;
202+
extern uint32_t g_vkLocalMemoryHeap;
201203

202204
//Enable flags for various features
203205
extern bool g_gpuFilterEnabled;
@@ -206,6 +208,7 @@ extern bool g_hasShaderInt64;
206208
extern bool g_hasShaderInt16;
207209
extern bool g_hasShaderInt8;
208210
extern bool g_hasDebugUtils;
211+
extern bool g_hasMemoryBudget;
209212

210213
//Shader args for frequently used kernels
211214
struct ConvertRawSamplesShaderArgs

0 commit comments

Comments
 (0)