Skip to content

Commit

Permalink
vk: draft checking for available performance query counters
Browse files Browse the repository at this point in the history
This extension doesn't seem to be universally supported, so we'd need to
check for it first? But why is it stated as built in into 1.1?
  • Loading branch information
w23 committed Apr 10, 2023
1 parent c917c7a commit 2799095
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
51 changes: 50 additions & 1 deletion ref/vk/vk_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ static const char *validation_layers[] = {

static const char* device_extensions_req[] = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
// FIXME make optional
VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME,
};

static const char* device_extensions_rt[] = {
Expand Down Expand Up @@ -693,6 +695,51 @@ static const r_vk_module_t *const modules[] = {
};
*/

static const char* perfCounterUnitName(VkPerformanceCounterUnitKHR unit) {
switch (unit) {
case VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR: return "generic";
case VK_PERFORMANCE_COUNTER_UNIT_PERCENTAGE_KHR: return "%";
case VK_PERFORMANCE_COUNTER_UNIT_NANOSECONDS_KHR: return "ns";
case VK_PERFORMANCE_COUNTER_UNIT_BYTES_KHR: return "b";
case VK_PERFORMANCE_COUNTER_UNIT_BYTES_PER_SECOND_KHR: return "bps";
case VK_PERFORMANCE_COUNTER_UNIT_KELVIN_KHR: return "K";
case VK_PERFORMANCE_COUNTER_UNIT_WATTS_KHR: return "W";
case VK_PERFORMANCE_COUNTER_UNIT_VOLTS_KHR: return "V";
case VK_PERFORMANCE_COUNTER_UNIT_AMPS_KHR: return "A";
case VK_PERFORMANCE_COUNTER_UNIT_HERTZ_KHR: return "Hz";
case VK_PERFORMANCE_COUNTER_UNIT_CYCLES_KHR: return "C";
default: return "?";
}
}

static const char *perfCounterScopeName(VkPerformanceCounterScopeKHR scope) {
switch(scope) {
case VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_BUFFER_KHR: return "cmdbuf";
case VK_PERFORMANCE_COUNTER_SCOPE_RENDER_PASS_KHR: return "renderpass";
case VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR: return "command";
default: return "unknown";
}
}

static void queryPerformanceQuery(void) {
const uint32_t queue_family_index = 0;
uint32_t counters_count = 0;
XVK_CHECK(vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(vk_core.physical_device.device, queue_family_index, &counters_count, NULL, NULL));

VkPerformanceCounterKHR *const counters = Mem_Malloc(vk_core.pool, counters_count * sizeof(*counters));
VkPerformanceCounterDescriptionKHR *const counters_desc = Mem_Malloc(vk_core.pool, counters_count * sizeof(*counters_desc));

XVK_CHECK(vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(vk_core.physical_device.device, queue_family_index, &counters_count, counters, counters_desc));

gEngine.Con_Reportf("Got %d counters:\n", counters_count);
for (uint32_t i = 0; i < counters_count; ++i) {
const VkPerformanceCounterKHR *const cnt = counters + i;
const VkPerformanceCounterDescriptionKHR *const desc = counters_desc + i;
gEngine.Con_Reportf(" %d: %s %s/%s, %s (%s)\n",
i, perfCounterScopeName(cnt->scope), desc->category, desc->name, perfCounterUnitName(cnt->unit), desc->description);
}
}

qboolean R_VkInit( void )
{
// FIXME !!!! handle initialization errors properly: destroy what has already been created
Expand Down Expand Up @@ -751,6 +798,8 @@ qboolean R_VkInit( void )
if (!createDevice())
return false;

queryPerformanceQuery();

VK_LoadCvarsAfterInit();

if (!R_VkCombuf_Init())
Expand Down Expand Up @@ -835,7 +884,7 @@ void R_VkShutdown( void ) {
VK_DescriptorShutdown();

R_VkStagingShutdown();

R_VkCombuf_Destroy();

VK_DevMemDestroy();
Expand Down
1 change: 1 addition & 0 deletions ref/vk/vk_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ do { \
X(vkDestroyDevice) \
X(vkDestroySurfaceKHR) \
X(vkEnumerateDeviceExtensionProperties) \
X(vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR) \

#define INSTANCE_DEBUG_FUNCS(X) \
X(vkCreateDebugUtilsMessengerEXT) \
Expand Down

0 comments on commit 2799095

Please sign in to comment.