summaryrefslogtreecommitdiffstats
path: root/src/vulkan/overlay-layer
diff options
context:
space:
mode:
authorLionel Landwerlin <[email protected]>2019-02-25 17:48:14 +0000
committerLionel Landwerlin <[email protected]>2019-02-28 12:40:57 +0000
commitadd4b8930a219008731f76830ffc12b260b7d1da (patch)
tree1f48e8a67bcc01055db853ca3e81472073239431 /src/vulkan/overlay-layer
parentb6b275212dc4eef9014f9e8bd247b72debde4b8b (diff)
vulkan/overlay: add support for fps output in file
Also make the sampling period configurable. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/vulkan/overlay-layer')
-rw-r--r--src/vulkan/overlay-layer/README4
-rw-r--r--src/vulkan/overlay-layer/overlay.cpp15
-rw-r--r--src/vulkan/overlay-layer/overlay_params.c30
-rw-r--r--src/vulkan/overlay-layer/overlay_params.h5
4 files changed, 39 insertions, 15 deletions
diff --git a/src/vulkan/overlay-layer/README b/src/vulkan/overlay-layer/README
index ae0d6dc37e9..660ab94a715 100644
--- a/src/vulkan/overlay-layer/README
+++ b/src/vulkan/overlay-layer/README
@@ -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
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 :
-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
diff --git a/src/vulkan/overlay-layer/overlay.cpp b/src/vulkan/overlay-layer/overlay.cpp
index c6f49c2ad75..a2f6f24bdec 100644
--- a/src/vulkan/overlay-layer/overlay.cpp
+++ b/src/vulkan/overlay-layer/overlay.cpp
@@ -211,6 +211,8 @@ static struct instance_data *new_instance_data(VkInstance instance)
static void destroy_instance_data(struct instance_data *data)
{
+ if (data->params.output_file)
+ fclose(data->params.output_file);
unmap_object(data->instance);
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)
{
- 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) {
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) {
- double elapsed = (double)(now - data->last_fps_update);
- if (elapsed >= 500000.0) {
- data->fps = ((uint64_t)data->n_frames_since_update * 1000000 / elapsed);
+ double elapsed = (double)(now - data->last_fps_update); /* us */
+ if (elapsed >= instance_data->params.fps_sampling_period) {
+ data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
data->n_frames_since_update = 0;
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 {
data->last_fps_update = now;
diff --git a/src/vulkan/overlay-layer/overlay_params.c b/src/vulkan/overlay-layer/overlay_params.c
index d28799ccf06..36819659c6f 100644
--- a/src/vulkan/overlay-layer/overlay_params.c
+++ b/src/vulkan/overlay-layer/overlay_params.c
@@ -41,6 +41,18 @@ parse_position(const char *str)
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
parse_help(const char *str)
{
@@ -51,11 +63,8 @@ parse_help(const char *str)
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
- fprintf(stderr, "\tposition=\n"
- "\t\ttop-left\n"
- "\t\ttop-right\n"
- "\t\tbottom-left\n"
- "\t\tbottom-right\n");
+ fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
+ fprintf(stderr, "\tfps_sampling_period=number of milliseconds\n");
return true;
}
@@ -80,7 +89,8 @@ parse_string(const char *s, char *out_param, char *out_value)
i++;
for (; !is_delimiter(*s); s++, out_value++, i++)
*out_value = *s;
- }
+ } else
+ *(out_value++) = '1';
*out_value = 0;
if (*s && is_delimiter(*s)) {
@@ -117,6 +127,7 @@ parse_overlay_env(struct overlay_params *params,
/* Visible by default */
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
+ params->fps_sampling_period = 500000; /* 500ms */
if (!env)
return;
@@ -126,11 +137,12 @@ parse_overlay_env(struct overlay_params *params,
#define OVERLAY_PARAM_BOOL(name) \
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; \
}
-#define OVERLAY_PARAM_CUSTOM(name) \
- if (!strcmp(#name, key)) { \
+#define OVERLAY_PARAM_CUSTOM(name) \
+ if (!strcmp(#name, key)) { \
params->name = parse_##name(value); \
continue; \
}
diff --git a/src/vulkan/overlay-layer/overlay_params.h b/src/vulkan/overlay-layer/overlay_params.h
index 7e86c6f0e43..75bcf956e8e 100644
--- a/src/vulkan/overlay-layer/overlay_params.h
+++ b/src/vulkan/overlay-layer/overlay_params.h
@@ -28,6 +28,7 @@
extern "C" {
#endif
+#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
@@ -47,6 +48,8 @@ extern "C" {
OVERLAY_PARAM_BOOL(pipeline_compute) \
OVERLAY_PARAM_BOOL(pipeline_raytracing) \
OVERLAY_PARAM_BOOL(acquire_timing) \
+ OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
+ OVERLAY_PARAM_CUSTOM(output_file) \
OVERLAY_PARAM_CUSTOM(position) \
OVERLAY_PARAM_CUSTOM(help)
@@ -69,6 +72,8 @@ enum overlay_param_enabled {
struct overlay_params {
bool enabled[OVERLAY_PARAM_ENABLED_MAX];
enum overlay_param_position position;
+ FILE *output_file;
+ uint32_t fps_sampling_period; /* us */
bool help;
};