vulkan/overlay: add support for fps output in file
Also make the sampling period configurable. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
This commit is contained in:
@@ -10,8 +10,8 @@ List the available statistics :
|
|||||||
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=help /path/to/my_vulkan_app
|
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=help /path/to/my_vulkan_app
|
||||||
|
|
||||||
Turn on some statistics :
|
Turn on some statistics :
|
||||||
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1 /path/to/my_vulkan_app
|
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics /path/to/my_vulkan_app
|
||||||
|
|
||||||
Position the layer :
|
Position the layer :
|
||||||
|
|
||||||
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1,position=top-right /path/to/my_vulkan_app
|
VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics,position=top-right /path/to/my_vulkan_app
|
||||||
|
@@ -211,6 +211,8 @@ static struct instance_data *new_instance_data(VkInstance instance)
|
|||||||
|
|
||||||
static void destroy_instance_data(struct instance_data *data)
|
static void destroy_instance_data(struct instance_data *data)
|
||||||
{
|
{
|
||||||
|
if (data->params.output_file)
|
||||||
|
fclose(data->params.output_file);
|
||||||
unmap_object(data->instance);
|
unmap_object(data->instance);
|
||||||
ralloc_free(data);
|
ralloc_free(data);
|
||||||
}
|
}
|
||||||
@@ -338,7 +340,8 @@ static void destroy_swapchain_data(struct swapchain_data *data)
|
|||||||
|
|
||||||
static void snapshot_swapchain_frame(struct swapchain_data *data)
|
static void snapshot_swapchain_frame(struct swapchain_data *data)
|
||||||
{
|
{
|
||||||
uint64_t now = os_time_get();
|
struct instance_data *instance_data = data->device->instance;
|
||||||
|
uint64_t now = os_time_get(); /* us */
|
||||||
|
|
||||||
if (data->last_present_time) {
|
if (data->last_present_time) {
|
||||||
data->frame_times[(data->n_frames - 1) % ARRAY_SIZE(data->frame_times)] =
|
data->frame_times[(data->n_frames - 1) % ARRAY_SIZE(data->frame_times)] =
|
||||||
@@ -346,11 +349,15 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data->last_fps_update) {
|
if (data->last_fps_update) {
|
||||||
double elapsed = (double)(now - data->last_fps_update);
|
double elapsed = (double)(now - data->last_fps_update); /* us */
|
||||||
if (elapsed >= 500000.0) {
|
if (elapsed >= instance_data->params.fps_sampling_period) {
|
||||||
data->fps = ((uint64_t)data->n_frames_since_update * 1000000 / elapsed);
|
data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
|
||||||
data->n_frames_since_update = 0;
|
data->n_frames_since_update = 0;
|
||||||
data->last_fps_update = now;
|
data->last_fps_update = now;
|
||||||
|
if (instance_data->params.output_file) {
|
||||||
|
fprintf(instance_data->params.output_file, "%.2f\n", data->fps);
|
||||||
|
fflush(instance_data->params.output_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
data->last_fps_update = now;
|
data->last_fps_update = now;
|
||||||
|
@@ -41,6 +41,18 @@ parse_position(const char *str)
|
|||||||
return LAYER_POSITION_TOP_LEFT;
|
return LAYER_POSITION_TOP_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FILE *
|
||||||
|
parse_output_file(const char *str)
|
||||||
|
{
|
||||||
|
return fopen(str, "w+");
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t
|
||||||
|
parse_fps_sampling_period(const char *str)
|
||||||
|
{
|
||||||
|
return strtol(str, NULL, 0) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
parse_help(const char *str)
|
parse_help(const char *str)
|
||||||
{
|
{
|
||||||
@@ -51,11 +63,8 @@ parse_help(const char *str)
|
|||||||
OVERLAY_PARAMS
|
OVERLAY_PARAMS
|
||||||
#undef OVERLAY_PARAM_BOOL
|
#undef OVERLAY_PARAM_BOOL
|
||||||
#undef OVERLAY_PARAM_CUSTOM
|
#undef OVERLAY_PARAM_CUSTOM
|
||||||
fprintf(stderr, "\tposition=\n"
|
fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
|
||||||
"\t\ttop-left\n"
|
fprintf(stderr, "\tfps_sampling_period=number of milliseconds\n");
|
||||||
"\t\ttop-right\n"
|
|
||||||
"\t\tbottom-left\n"
|
|
||||||
"\t\tbottom-right\n");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -80,7 +89,8 @@ parse_string(const char *s, char *out_param, char *out_value)
|
|||||||
i++;
|
i++;
|
||||||
for (; !is_delimiter(*s); s++, out_value++, i++)
|
for (; !is_delimiter(*s); s++, out_value++, i++)
|
||||||
*out_value = *s;
|
*out_value = *s;
|
||||||
}
|
} else
|
||||||
|
*(out_value++) = '1';
|
||||||
*out_value = 0;
|
*out_value = 0;
|
||||||
|
|
||||||
if (*s && is_delimiter(*s)) {
|
if (*s && is_delimiter(*s)) {
|
||||||
@@ -117,6 +127,7 @@ parse_overlay_env(struct overlay_params *params,
|
|||||||
/* Visible by default */
|
/* Visible by default */
|
||||||
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
|
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
|
||||||
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
|
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
|
||||||
|
params->fps_sampling_period = 500000; /* 500ms */
|
||||||
|
|
||||||
if (!env)
|
if (!env)
|
||||||
return;
|
return;
|
||||||
@@ -126,7 +137,8 @@ parse_overlay_env(struct overlay_params *params,
|
|||||||
|
|
||||||
#define OVERLAY_PARAM_BOOL(name) \
|
#define OVERLAY_PARAM_BOOL(name) \
|
||||||
if (!strcmp(#name, key)) { \
|
if (!strcmp(#name, key)) { \
|
||||||
params->enabled[OVERLAY_PARAM_ENABLED_##name] = strtol(value, NULL, 0); \
|
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
|
||||||
|
strtol(value, NULL, 0); \
|
||||||
continue; \
|
continue; \
|
||||||
}
|
}
|
||||||
#define OVERLAY_PARAM_CUSTOM(name) \
|
#define OVERLAY_PARAM_CUSTOM(name) \
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ extern "C" {
|
|||||||
OVERLAY_PARAM_BOOL(pipeline_compute) \
|
OVERLAY_PARAM_BOOL(pipeline_compute) \
|
||||||
OVERLAY_PARAM_BOOL(pipeline_raytracing) \
|
OVERLAY_PARAM_BOOL(pipeline_raytracing) \
|
||||||
OVERLAY_PARAM_BOOL(acquire_timing) \
|
OVERLAY_PARAM_BOOL(acquire_timing) \
|
||||||
|
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
|
||||||
|
OVERLAY_PARAM_CUSTOM(output_file) \
|
||||||
OVERLAY_PARAM_CUSTOM(position) \
|
OVERLAY_PARAM_CUSTOM(position) \
|
||||||
OVERLAY_PARAM_CUSTOM(help)
|
OVERLAY_PARAM_CUSTOM(help)
|
||||||
|
|
||||||
@@ -69,6 +72,8 @@ enum overlay_param_enabled {
|
|||||||
struct overlay_params {
|
struct overlay_params {
|
||||||
bool enabled[OVERLAY_PARAM_ENABLED_MAX];
|
bool enabled[OVERLAY_PARAM_ENABLED_MAX];
|
||||||
enum overlay_param_position position;
|
enum overlay_param_position position;
|
||||||
|
FILE *output_file;
|
||||||
|
uint32_t fps_sampling_period; /* us */
|
||||||
bool help;
|
bool help;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user