mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-21 09:20:12 +01:00
vk/overlay-layer: defer log creation to swapchain creation
Moving output file creation to coincide with swapchain creation ensures only rendering thread will create/destroy log file. This was causing problems with non-rendering processes stomping log file. Reviewed-by: Caleb Callaway <caleb.callaway@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32814>
This commit is contained in:
parent
de1eaa4019
commit
06423b1792
3 changed files with 63 additions and 54 deletions
|
|
@ -56,8 +56,6 @@ struct instance_data {
|
||||||
struct overlay_params params;
|
struct overlay_params params;
|
||||||
bool pipeline_statistics_enabled;
|
bool pipeline_statistics_enabled;
|
||||||
|
|
||||||
bool first_line_printed;
|
|
||||||
|
|
||||||
int control_client;
|
int control_client;
|
||||||
|
|
||||||
/* Dumping of frame stats to a file has been enabled. */
|
/* Dumping of frame stats to a file has been enabled. */
|
||||||
|
|
@ -67,6 +65,8 @@ struct instance_data {
|
||||||
bool capture_started;
|
bool capture_started;
|
||||||
|
|
||||||
int socket;
|
int socket;
|
||||||
|
|
||||||
|
FILE *output_file_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct frame_stat {
|
struct frame_stat {
|
||||||
|
|
@ -345,10 +345,16 @@ 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);
|
|
||||||
if (data->socket >= 0)
|
if (data->socket >= 0)
|
||||||
os_socket_close(data->socket);
|
os_socket_close(data->socket);
|
||||||
|
if (data->params.output_file) {
|
||||||
|
free((void*)data->params.output_file);
|
||||||
|
data->params.output_file = NULL;
|
||||||
|
}
|
||||||
|
if (data->params.control) {
|
||||||
|
free((void*)data->params.control);
|
||||||
|
data->params.control = NULL;
|
||||||
|
}
|
||||||
unmap_object(HKEY(data->instance));
|
unmap_object(HKEY(data->instance));
|
||||||
ralloc_free(data);
|
ralloc_free(data);
|
||||||
}
|
}
|
||||||
|
|
@ -472,6 +478,20 @@ static void destroy_device_data(struct device_data *data)
|
||||||
ralloc_free(data);
|
ralloc_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *param_unit(enum overlay_param_enabled param)
|
||||||
|
{
|
||||||
|
switch (param) {
|
||||||
|
case OVERLAY_PARAM_ENABLED_frame_timing:
|
||||||
|
case OVERLAY_PARAM_ENABLED_acquire_timing:
|
||||||
|
case OVERLAY_PARAM_ENABLED_present_timing:
|
||||||
|
return "(us)";
|
||||||
|
case OVERLAY_PARAM_ENABLED_gpu_timing:
|
||||||
|
return "(ns)";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
static struct command_buffer_data *new_command_buffer_data(VkCommandBuffer cmd_buffer,
|
static struct command_buffer_data *new_command_buffer_data(VkCommandBuffer cmd_buffer,
|
||||||
VkCommandBufferLevel level,
|
VkCommandBufferLevel level,
|
||||||
|
|
@ -510,6 +530,29 @@ static struct swapchain_data *new_swapchain_data(VkSwapchainKHR swapchain,
|
||||||
data->window_size = ImVec2(instance_data->params.width, instance_data->params.height);
|
data->window_size = ImVec2(instance_data->params.width, instance_data->params.height);
|
||||||
list_inithead(&data->draws);
|
list_inithead(&data->draws);
|
||||||
map_object(HKEY(data->swapchain), data);
|
map_object(HKEY(data->swapchain), data);
|
||||||
|
|
||||||
|
/* Open output file on swapchain creation */
|
||||||
|
assert(instance_data->output_file_fd == NULL);
|
||||||
|
instance_data->output_file_fd =
|
||||||
|
fopen(instance_data->params.output_file, "w+");
|
||||||
|
|
||||||
|
if (instance_data->output_file_fd) {
|
||||||
|
bool first_column = true;
|
||||||
|
#define OVERLAY_PARAM_BOOL(name) \
|
||||||
|
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_##name]) { \
|
||||||
|
fprintf(instance_data->output_file_fd, \
|
||||||
|
"%s%s%s", first_column ? "" : ", ", #name, \
|
||||||
|
param_unit(OVERLAY_PARAM_ENABLED_##name)); \
|
||||||
|
first_column = false; \
|
||||||
|
}
|
||||||
|
#define OVERLAY_PARAM_CUSTOM(name)
|
||||||
|
OVERLAY_PARAMS
|
||||||
|
#undef OVERLAY_PARAM_BOOL
|
||||||
|
#undef OVERLAY_PARAM_CUSTOM
|
||||||
|
fprintf(instance_data->output_file_fd, "\n");
|
||||||
|
} else
|
||||||
|
fprintf(stderr, "ERROR opening output file: %s\n", strerror(errno));
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -567,20 +610,6 @@ struct overlay_draw *get_overlay_draw(struct swapchain_data *data)
|
||||||
return draw;
|
return draw;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *param_unit(enum overlay_param_enabled param)
|
|
||||||
{
|
|
||||||
switch (param) {
|
|
||||||
case OVERLAY_PARAM_ENABLED_frame_timing:
|
|
||||||
case OVERLAY_PARAM_ENABLED_acquire_timing:
|
|
||||||
case OVERLAY_PARAM_ENABLED_present_timing:
|
|
||||||
return "(us)";
|
|
||||||
case OVERLAY_PARAM_ENABLED_gpu_timing:
|
|
||||||
return "(ns)";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void parse_command(struct instance_data *instance_data,
|
static void parse_command(struct instance_data *instance_data,
|
||||||
const char *cmd, unsigned cmdlen,
|
const char *cmd, unsigned cmdlen,
|
||||||
const char *param, unsigned paramlen)
|
const char *param, unsigned paramlen)
|
||||||
|
|
@ -833,39 +862,20 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
|
||||||
elapsed >= instance_data->params.fps_sampling_period) {
|
elapsed >= instance_data->params.fps_sampling_period) {
|
||||||
data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
|
data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
|
||||||
if (instance_data->capture_started) {
|
if (instance_data->capture_started) {
|
||||||
if (!instance_data->first_line_printed) {
|
|
||||||
bool first_column = true;
|
|
||||||
|
|
||||||
instance_data->first_line_printed = true;
|
|
||||||
|
|
||||||
#define OVERLAY_PARAM_BOOL(name) \
|
|
||||||
if (instance_data->params.enabled[OVERLAY_PARAM_ENABLED_##name]) { \
|
|
||||||
fprintf(instance_data->params.output_file, \
|
|
||||||
"%s%s%s", first_column ? "" : ", ", #name, \
|
|
||||||
param_unit(OVERLAY_PARAM_ENABLED_##name)); \
|
|
||||||
first_column = false; \
|
|
||||||
}
|
|
||||||
#define OVERLAY_PARAM_CUSTOM(name)
|
|
||||||
OVERLAY_PARAMS
|
|
||||||
#undef OVERLAY_PARAM_BOOL
|
|
||||||
#undef OVERLAY_PARAM_CUSTOM
|
|
||||||
fprintf(instance_data->params.output_file, "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int s = 0; s < OVERLAY_PARAM_ENABLED_MAX; s++) {
|
for (int s = 0; s < OVERLAY_PARAM_ENABLED_MAX; s++) {
|
||||||
if (!instance_data->params.enabled[s])
|
if (!instance_data->params.enabled[s])
|
||||||
continue;
|
continue;
|
||||||
if (s == OVERLAY_PARAM_ENABLED_fps) {
|
if (s == OVERLAY_PARAM_ENABLED_fps) {
|
||||||
fprintf(instance_data->params.output_file,
|
fprintf(instance_data->output_file_fd,
|
||||||
"%s%.2f", s == 0 ? "" : ", ", data->fps);
|
"%s%.2f", s == 0 ? "" : ", ", data->fps);
|
||||||
} else {
|
} else {
|
||||||
fprintf(instance_data->params.output_file,
|
fprintf(instance_data->output_file_fd,
|
||||||
"%s%" PRIu64, s == 0 ? "" : ", ",
|
"%s%" PRIu64, s == 0 ? "" : ", ",
|
||||||
data->accumulated_stats.stats[s]);
|
data->accumulated_stats.stats[s]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(instance_data->params.output_file, "\n");
|
fprintf(instance_data->output_file_fd, "\n");
|
||||||
fflush(instance_data->params.output_file);
|
fflush(instance_data->output_file_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&data->accumulated_stats, 0, sizeof(data->accumulated_stats));
|
memset(&data->accumulated_stats, 0, sizeof(data->accumulated_stats));
|
||||||
|
|
@ -1891,12 +1901,18 @@ static void overlay_DestroySwapchainKHR(
|
||||||
VkSwapchainKHR swapchain,
|
VkSwapchainKHR swapchain,
|
||||||
const VkAllocationCallbacks* pAllocator)
|
const VkAllocationCallbacks* pAllocator)
|
||||||
{
|
{
|
||||||
|
struct device_data *device_data = FIND(struct device_data, device);
|
||||||
|
struct instance_data *instance_data = device_data->instance;
|
||||||
if (swapchain == VK_NULL_HANDLE) {
|
if (swapchain == VK_NULL_HANDLE) {
|
||||||
struct device_data *device_data = FIND(struct device_data, device);
|
|
||||||
device_data->vtable.DestroySwapchainKHR(device, swapchain, pAllocator);
|
device_data->vtable.DestroySwapchainKHR(device, swapchain, pAllocator);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instance_data->output_file_fd) {
|
||||||
|
fclose(instance_data->output_file_fd);
|
||||||
|
instance_data->output_file_fd = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
struct swapchain_data *swapchain_data =
|
struct swapchain_data *swapchain_data =
|
||||||
FIND(struct swapchain_data, swapchain);
|
FIND(struct swapchain_data, swapchain);
|
||||||
|
|
||||||
|
|
@ -2646,7 +2662,7 @@ static VkResult overlay_CreateInstance(
|
||||||
* capturing fps data right away.
|
* capturing fps data right away.
|
||||||
*/
|
*/
|
||||||
instance_data->capture_enabled =
|
instance_data->capture_enabled =
|
||||||
instance_data->params.output_file && instance_data->params.control == NULL;
|
instance_data->output_file_fd && instance_data->params.control == NULL;
|
||||||
instance_data->capture_started = instance_data->capture_enabled;
|
instance_data->capture_started = instance_data->capture_enabled;
|
||||||
|
|
||||||
for (int i = OVERLAY_PARAM_ENABLED_vertices;
|
for (int i = OVERLAY_PARAM_ENABLED_vertices;
|
||||||
|
|
|
||||||
|
|
@ -45,23 +45,16 @@ parse_position(const char *str)
|
||||||
return LAYER_POSITION_TOP_LEFT;
|
return LAYER_POSITION_TOP_LEFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FILE *
|
static const char *
|
||||||
parse_output_file(const char *str)
|
parse_output_file(const char *str)
|
||||||
{
|
{
|
||||||
return fopen(str, "w+");
|
return strdup(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
parse_control(const char *str)
|
parse_control(const char *str)
|
||||||
{
|
{
|
||||||
static char control_str[64];
|
return strdup(str);
|
||||||
if (strlen(str) > 63) {
|
|
||||||
fprintf(stderr, "ERROR: control string too long. Must be < 64 chars");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strcpy(control_str, str);
|
|
||||||
|
|
||||||
return control_str;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ 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;
|
const char *output_file;
|
||||||
const char *control;
|
const char *control;
|
||||||
uint32_t fps_sampling_period; /* us */
|
uint32_t fps_sampling_period; /* us */
|
||||||
bool help;
|
bool help;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue