From 9e347ec71fc408fe77b95d39ec91c83b1c57f1ff Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 25 Jan 2018 19:09:55 -0500 Subject: [PATCH] detect shader file changes on move and delete as well, and wait a few frames before re-applying changes --- frontend/drivers/platform_unix.c | 4 ++++ frontend/frontend_driver.h | 5 ++++- gfx/video_shader_parse.c | 7 ++++++- retroarch.c | 27 ++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c index daee38d2a3..6f6015ed1a 100644 --- a/frontend/drivers/platform_unix.c +++ b/frontend/drivers/platform_unix.c @@ -2357,6 +2357,10 @@ static void frontend_unix_watch_path_for_changes(struct string_list *list, int f inotify_mask |= IN_MODIFY; if (flags & PATH_CHANGE_TYPE_WRITE_FILE_CLOSED) inotify_mask |= IN_CLOSE_WRITE; + if (flags & PATH_CHANGE_TYPE_FILE_MOVED) + inotify_mask |= IN_MOVE_SELF; + if (flags & PATH_CHANGE_TYPE_FILE_DELETED) + inotify_mask |= IN_DELETE_SELF; inotify_data->flags = inotify_mask; diff --git a/frontend/frontend_driver.h b/frontend/frontend_driver.h index 8e3fe089bf..a2f5ddf966 100644 --- a/frontend/frontend_driver.h +++ b/frontend/frontend_driver.h @@ -56,10 +56,13 @@ enum frontend_architecture FRONTEND_ARCH_TILE }; +/* different platforms may only support some of these types */ enum path_change_type { PATH_CHANGE_TYPE_MODIFIED = (1 << 0), - PATH_CHANGE_TYPE_WRITE_FILE_CLOSED = (1 << 1) + PATH_CHANGE_TYPE_WRITE_FILE_CLOSED = (1 << 1), + PATH_CHANGE_TYPE_FILE_MOVED = (1 << 2), + PATH_CHANGE_TYPE_FILE_DELETED = (1 << 3) }; typedef struct path_change_data diff --git a/gfx/video_shader_parse.c b/gfx/video_shader_parse.c index 6313cdacbc..d4160fd4a9 100644 --- a/gfx/video_shader_parse.c +++ b/gfx/video_shader_parse.c @@ -809,7 +809,12 @@ bool video_shader_read_conf_cgp(config_file_t *conf, if (settings->bools.video_shader_watch_files) { - frontend_driver_watch_path_for_changes(file_list, PATH_CHANGE_TYPE_WRITE_FILE_CLOSED, &file_change_data); + int flags = PATH_CHANGE_TYPE_MODIFIED | + PATH_CHANGE_TYPE_WRITE_FILE_CLOSED | + PATH_CHANGE_TYPE_FILE_MOVED | + PATH_CHANGE_TYPE_FILE_DELETED; + + frontend_driver_watch_path_for_changes(file_list, flags, &file_change_data); string_list_free(file_list); } diff --git a/retroarch.c b/retroarch.c index f07dc16e3a..1c6165f6c3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -130,6 +130,8 @@ #define DEFAULT_EXT "" #endif +#define SHADER_FILE_WATCH_DELAY_FRAMES 5 + /* Descriptive names for options without short variant. * * Please keep the name in sync with the option name. @@ -2996,8 +2998,31 @@ static enum runloop_state runloop_check_state( if (settings->bools.video_shader_watch_files) { + static bool need_to_apply = false; + static int elapsed_frames = 0; + if (video_shader_check_for_changes()) - command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); + { + need_to_apply = true; + elapsed_frames = 0; + } + + /* If a file is modified atomically (moved/renamed from a different file), we have no idea how long that might take. + * If we're trying to re-apply shaders immediately after changes are made to the original file(s), the filesystem might be in an in-between + * state where the new file hasn't been moved over yet and the original file was already deleted. This leaves us no choice + * but to wait an arbitrary amount of time and hope for the best. + */ + if (need_to_apply) + { + if (elapsed_frames > SHADER_FILE_WATCH_DELAY_FRAMES) + { + need_to_apply = false; + elapsed_frames = 0; + command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL); + } + else + elapsed_frames++; + } } return RUNLOOP_STATE_ITERATE;