[Scummvm-git-logs] scummvm master -> f614c5319115c6b89bc878959956c4a53e1ce1da

spleen1981 noreply at scummvm.org
Sun Apr 2 03:27:49 UTC 2023


This automated email contains information about 15 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f239211e3e CREDITS: add Libretro
779a81f6e0 LIBRETRO: reorder retro_run loop
9e0cad35fc LIBRETRO: add Auto performance tuner
cdf2f3ffac LIBRETRO: BUILD: add test on TOOLSET to identify 64bit platform
3e37845565 LIBRETRO: add isInGUI test
99cbf529db LIBRETRO: move frameskip log to debug
dfbd7c28c6 LIBRETRO: add performance settings group
480f38f03a LIBRETRO: rename frameskip manual setting to threshold
63fc1d4609 LIBRETRO: add bug report template
f6010ebdaf LIBRETRO: reorder frameskip_type tests
dbd7608f55 LIBRETRO: simplify audio_batch_cb call
99f71d3e41 LIBRETRO: test frame_skip before thread switch
bf42315fcd LIBRETRO: reorder audio retrieving
addf767ceb LIBRETRO: simplify audio retrieve test and drop unused isInGUI()
f614c53191 LIBRETRO: add framerate reduction option


Commit: f239211e3e35be13067a7a7fdbca6ce24f7a1ec6
    https://github.com/scummvm/scummvm/commit/f239211e3e35be13067a7a7fdbca6ce24f7a1ec6
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
CREDITS: add Libretro

Changed paths:
    devtools/credits.pl


diff --git a/devtools/credits.pl b/devtools/credits.pl
index b79cc1c4fd9..8f14246353d 100755
--- a/devtools/credits.pl
+++ b/devtools/credits.pl
@@ -657,6 +657,10 @@ begin_credits("Credits");
 				add_person("Manuel Alfayate", "vanfanel", "");
 			end_section();
 
+			begin_section("Libretro");
+				add_person("Giovanni Cascione", "spleen1981", "");
+			end_section();
+
 		end_section();
 
 		begin_section("Other subsystems", "other_subsystems");


Commit: 779a81f6e0483c72b16269514706968761666f76
    https://github.com/scummvm/scummvm/commit/779a81f6e0483c72b16269514706968761666f76
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: reorder retro_run loop

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 6a48222cf6b..3da40bed5f5 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -594,17 +594,15 @@ void retro_run(void) {
 	environ_cb(RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE, &audio_video_enable);
 
 	bool skip_frame = false;
-	retro_switch_to_emu_thread();
+	size_t samples_count = 0;
 
 	if (g_system) {
-		poll_cb();
-		retroProcessMouse(input_cb, retro_device, gampad_cursor_speed, gamepad_acceleration_time, analog_response_is_quadratic, analog_deadzone, mouse_speed);
-
 		/* ScummVM is not based on fixed framerate like libretro, and engines/scripts
 		can call multiple screen updates between two retro_run calls. Hence if consecutive screen updates
 		are detected we will loop within the same retro_run call until next pollEvent or
 		delayMillis call in ScummVM thread.
 		*/
+
 		do {
 			if (frameskip_type && can_dupe) {
 				if (audio_status & (AUDIO_STATUS_BUFFER_SUPPORT | AUDIO_STATUS_BUFFER_ACTIVE)){
@@ -622,12 +620,15 @@ void retro_run(void) {
 				} else
 					skip_frame = !(current_frame % frameskip_no == 0);
 			}
+
+			retro_switch_to_emu_thread();
+
 			/* Upload audio */
-			size_t count = 0;
+			samples_count = 0;
 			if (audio_video_enable & 2) {
-				count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
+				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
 			}
-			audio_status = count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
+			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
 			/* No frame skipping if there is no incoming audio (e.g. GUI) */
 			skip_frame = skip_frame && ! (audio_status & AUDIO_STATUS_MUTE);
@@ -657,14 +658,14 @@ void retro_run(void) {
 				audio_buffer_init(SAMPLE_RATE, (uint16) frame_rate);
 			}
 #endif
-			audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : (int16_t *) sound_buffer, count); // Set to NULL to skip sound rendering
+			audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : (int16_t *) sound_buffer, samples_count); // Set to NULL to skip sound rendering
 
 			current_frame++;
 
-			if (getThreadSwitchCaller() & THREAD_SWITCH_UPDATE)
-				retro_switch_to_emu_thread();
-
 		} while (getThreadSwitchCaller() & THREAD_SWITCH_UPDATE);
+
+		poll_cb();
+		retroProcessMouse(input_cb, retro_device, gampad_cursor_speed, gamepad_acceleration_time, analog_response_is_quadratic, analog_deadzone, mouse_speed);
 	}
 
 	bool updated = false;


Commit: 9e0cad35fc3a8feb6be8dae8f5209ae76fbd1126
    https://github.com/scummvm/scummvm/commit/9e0cad35fc3a8feb6be8dae8f5209ae76fbd1126
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: add Auto performance tuner

Changed paths:
    backends/platform/libretro/include/libretro-core-options-intl.h
    backends/platform/libretro/include/libretro-core-options.h
    backends/platform/libretro/include/os.h
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/include/libretro-core-options-intl.h b/backends/platform/libretro/include/libretro-core-options-intl.h
index f49f0412369..c369c70ea43 100644
--- a/backends/platform/libretro/include/libretro-core-options-intl.h
+++ b/backends/platform/libretro/include/libretro-core-options-intl.h
@@ -204,6 +204,18 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		},
 		NULL
 	},
+	{
+		"scummvm_auto_performance_tuner",
+		"Regolazione automatica performance",
+		NULL,
+		"Cambio automatico delle impostazioni di performance e salto dei fotogrammi se vengono rilevate performance scadenti durante il gioco. 'Consenti inaccuratezze di timing' e 'Salto dei fotogrammi Auto' saranno temporaneamente abilitati in sequenza per la sola sessione di gioco, se necessario. Le singole impostazioni salvate non saranno modificate.",
+		NULL,
+		NULL,
+		{
+			{NULL, NULL},
+		},
+		NULL
+	},
 	{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
 };
 
diff --git a/backends/platform/libretro/include/libretro-core-options.h b/backends/platform/libretro/include/libretro-core-options.h
index 177c44c9bd5..32d948d82c9 100644
--- a/backends/platform/libretro/include/libretro-core-options.h
+++ b/backends/platform/libretro/include/libretro-core-options.h
@@ -275,6 +275,20 @@ struct retro_core_option_v2_definition option_defs_us[] = {
 		"disabled"
 #endif
 	},
+	{
+		"scummvm_auto_performance_tuner",
+		"Auto performance tuner",
+		NULL,
+		"In-game automatic change of performance/frameskip settings if low performances are detected. 'Allow Timing Inaccuracies' and 'Auto Frameskip' will be temporarily set on in sequence, if necessary, for the current game session only. Single saved settings will not be affected.",
+		NULL,
+		NULL,
+		{
+			{"disabled", NULL},
+			{"enabled", NULL},
+			{NULL, NULL},
+		},
+		"enabled"
+	},
 	{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
 };
 
diff --git a/backends/platform/libretro/include/os.h b/backends/platform/libretro/include/os.h
index 5076fd7a9c8..3bb0ce25ac1 100644
--- a/backends/platform/libretro/include/os.h
+++ b/backends/platform/libretro/include/os.h
@@ -24,7 +24,7 @@
 
 #define SAMPLE_RATE     48000
 #define REFRESH_RATE    60
-#define FRAMESKIP_MAX   30
+#define FRAMESKIP_MAX   REFRESH_RATE / 2
 
 // Audio status
 #define AUDIO_STATUS_MUTE               (1 << 0)
@@ -33,6 +33,13 @@
 #define AUDIO_STATUS_BUFFER_UNDERRUN    (1 << 3)
 #define AUDIO_STATUS_UPDATE_LATENCY     (1 << 4)
 
+// Performance switcher
+#define PERF_SWITCH_FRAMESKIP_EVENTS              REFRESH_RATE * 2
+#define PERF_SWITCH_ON                            (1 << 0)
+#define PERF_SWITCH_ENABLE_TIMING_INACCURACIES    (1 << 1)
+#define PERF_SWITCH_ENABLE_AUTO_FRAMESKIP         (1 << 2)
+#define PERF_SWITCH_OVER                          (1 << 3)
+
 // Thread switch caller
 #define THREAD_SWITCH_POLL              (1 << 0)
 #define THREAD_SWITCH_DELAY             (1 << 1)
diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 3da40bed5f5..e039d176025 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -85,6 +85,7 @@ static uint8 frameskip_no;
 static uint8 frameskip_type;
 static uint8 frameskip_threshold;
 static uint32 frameskip_counter = 0;
+static uint8 frameskip_events = 0;
 
 static bool can_dupe = false;
 static uint8 audio_status = 0;
@@ -97,6 +98,8 @@ static size_t samples_per_frame_buffer_size = 0;
 
 static int16_t *sound_buffer = NULL;       // pointer to output buffer
 
+static uint8 performance_switch = 0;
+
 static void audio_buffer_init(uint16 sample_rate, uint16 frame_rate) {
 	samples_per_frame = sample_rate / frame_rate;
 	samples_per_frame_buffer_size = samples_per_frame << 1 * sizeof(int16_t);
@@ -127,8 +130,8 @@ static void retro_audio_buff_status_cb(bool active, unsigned occupancy, bool und
 	retro_audio_buff_occupancy = occupancy;
 }
 
-static void set_audio_buffer_status(){
-	if (frameskip_type > 1) {
+static void set_audio_buffer_status() {
+	if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON)) {
 		struct retro_audio_buffer_status_callback buf_status_cb;
 		buf_status_cb.callback = retro_audio_buff_status_cb;
 		audio_status = environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, &buf_status_cb) ? (audio_status | AUDIO_STATUS_BUFFER_SUPPORT) : (audio_status & ~AUDIO_STATUS_BUFFER_SUPPORT);
@@ -137,9 +140,37 @@ static void set_audio_buffer_status(){
 	}
 }
 
+static void increase_performance() {
+	struct retro_message_ext retro_msg;
+	retro_msg.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
+	retro_msg.target = RETRO_MESSAGE_TARGET_OSD;
+	retro_msg.duration = 3000;
+	retro_msg.msg = "";
+
+	if (!timing_inaccuracies_enabled && !(performance_switch & PERF_SWITCH_ENABLE_TIMING_INACCURACIES)) {
+		retro_msg.msg = "Auto performance tuner: 'Allow Timing Inaccuracies' enabled";
+		log_cb(RETRO_LOG_INFO, "Auto performance tuner: 'Allow Timing Inaccuracies' enabled.\n");
+		performance_switch |= PERF_SWITCH_ENABLE_TIMING_INACCURACIES;
+	} else if (frameskip_type != 2 && !(performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP)) {
+		retro_msg.msg = "Auto performance tuner: 'Auto frameskip' enabled";
+		log_cb(RETRO_LOG_INFO, "Auto performance tuner: 'Auto frameskip' enabled.\n");
+		performance_switch |= PERF_SWITCH_ENABLE_AUTO_FRAMESKIP;
+	} else
+		performance_switch |= PERF_SWITCH_OVER;
+
+	if (retro_msg.msg[0] != '\0')
+		environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+}
+
 static void update_variables(void) {
 	struct retro_variable var;
 
+	struct retro_message_ext retro_msg;
+	retro_msg.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
+	retro_msg.target = RETRO_MESSAGE_TARGET_OSD;
+	retro_msg.duration = 3000;
+	retro_msg.msg = "";
+
 	var.key = "scummvm_gamepad_cursor_speed";
 	var.value = NULL;
 	gampad_cursor_speed = 1.0f;
@@ -185,20 +216,19 @@ static void update_variables(void) {
 	}
 
 	var.key = "scummvm_frameskip_threshold";
-	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
+	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
 		frameskip_threshold = (uint8)strtol(var.value, NULL, 10);
+	}
 
 	var.key = "scummvm_frameskip_no";
-	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
-	{
+	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
 		frameskip_no = (uint8)strtol(var.value, NULL, 10) + 1;
 	}
 
-	uint8 old_frameskip_type = frameskip_type;
 	var.key = "scummvm_frameskip_type";
 	var.value = NULL;
-	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
-	{
+	uint8 old_frameskip_type = frameskip_type;
+	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
 		if (strcmp(var.value, "disabled") == 0)
 			frameskip_type = 0;
 		else if (strcmp(var.value, "fixed") == 0)
@@ -209,14 +239,42 @@ static void update_variables(void) {
 			frameskip_type = 3;
 	}
 
-	if (old_frameskip_type != frameskip_type){
-		set_audio_buffer_status();
+	var.key = "scummvm_auto_performance_tuner";
+	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+		if (strcmp(var.value, "enabled") == 0) {
+			if (!performance_switch)
+				audio_status |= AUDIO_STATUS_UPDATE_LATENCY;
+
+			performance_switch &= ~PERF_SWITCH_OVER;
+			performance_switch |= PERF_SWITCH_ON;
+		} else
+			performance_switch = 0;
+	}
+
+	set_audio_buffer_status();
+
+	if (!(audio_status & AUDIO_STATUS_BUFFER_SUPPORT) && frameskip_type > 1) {
+		log_cb(RETRO_LOG_WARN, "Selected frameskip mode not available.\n");
+		retro_msg.msg = "Selected frameskip mode not available";
+		environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+		frameskip_type = 0;
+	}
+	if (old_frameskip_type != frameskip_type) {
 		audio_status |= AUDIO_STATUS_UPDATE_LATENCY;
 	}
+
+	if (!(audio_status & AUDIO_STATUS_BUFFER_SUPPORT) && performance_switch) {
+		log_cb(RETRO_LOG_WARN, "Auto performance tuner not available.\n");
+		retro_msg.msg = "Auto performance tuner not available";
+		environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+		performance_switch = 0;
+	}
+
+
 }
 
 bool timing_inaccuracies_is_enabled(){
-	return timing_inaccuracies_enabled;
+	return timing_inaccuracies_enabled || (performance_switch & PERF_SWITCH_ENABLE_TIMING_INACCURACIES);
 }
 
 void parse_command_params(char *cmdline) {
@@ -597,50 +655,53 @@ void retro_run(void) {
 	size_t samples_count = 0;
 
 	if (g_system) {
+
 		/* ScummVM is not based on fixed framerate like libretro, and engines/scripts
 		can call multiple screen updates between two retro_run calls. Hence if consecutive screen updates
 		are detected we will loop within the same retro_run call until next pollEvent or
 		delayMillis call in ScummVM thread.
 		*/
-
 		do {
-			if (frameskip_type && can_dupe) {
-				if (audio_status & (AUDIO_STATUS_BUFFER_SUPPORT | AUDIO_STATUS_BUFFER_ACTIVE)){
-					switch (frameskip_type) {
-					case 1:
-						skip_frame = !(current_frame % frameskip_no == 0);
-						break;
-					case 2:
-						skip_frame = (audio_status & AUDIO_STATUS_BUFFER_UNDERRUN);
-						break;
-					case 3:
-						skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
-						break;
-					}
-				} else
-					skip_frame = !(current_frame % frameskip_no == 0);
+			/* Performance counter */
+			if ((performance_switch & PERF_SWITCH_ON) && !(performance_switch & PERF_SWITCH_OVER) && (audio_status & AUDIO_STATUS_BUFFER_UNDERRUN) && !(audio_status & AUDIO_STATUS_MUTE)) {
+				frameskip_events++;
+				if (frameskip_events > PERF_SWITCH_FRAMESKIP_EVENTS) {
+					increase_performance();
+					frameskip_events = 0;
+				}
 			}
 
+			/* Determine frameskip need based on settings */
+			if (frameskip_type == 1)
+				skip_frame = !(current_frame % frameskip_no == 0);
+			else if ((frameskip_type == 2) || (performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP))
+				skip_frame = (audio_status & AUDIO_STATUS_BUFFER_UNDERRUN);
+			else if (frameskip_type == 3)
+				skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
+
 			retro_switch_to_emu_thread();
 
-			/* Upload audio */
+			/* Retrieve audio */
 			samples_count = 0;
 			if (audio_video_enable & 2) {
 				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
 			}
 			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
-			/* No frame skipping if there is no incoming audio (e.g. GUI) */
-			skip_frame = skip_frame && ! (audio_status & AUDIO_STATUS_MUTE);
+			/* No frame skipping if there is no incoming audio (e.g. GUI) or if frontend does not support frame skipping*/
+			skip_frame = skip_frame && ! (audio_status & AUDIO_STATUS_MUTE) && can_dupe;
 
+			/* Reset frameskip counter if not flagged */
 			if ((!skip_frame && frameskip_counter) || frameskip_counter >= FRAMESKIP_MAX) {
-				if (frameskip_counter)
-					log_cb(RETRO_LOG_WARN, "%d frame(s) skipped\n",frameskip_counter);
-				skip_frame        = false;
+				log_cb(RETRO_LOG_WARN, "%d frame(s) skipped\n",frameskip_counter);
+				skip_frame = false;
 				frameskip_counter = 0;
+
+			/* Keep on skipping frames if flagged */
 			} else if (skip_frame)
 				frameskip_counter++;
 
+			/* Retrieve video */
 			if ((audio_video_enable & 1) && !skip_frame) {
 				const Graphics::Surface &screen = getScreen();
 				video_cb(screen.getPixels(), screen.w, screen.h, screen.pitch);
@@ -675,7 +736,7 @@ void retro_run(void) {
 
 	if (audio_status & AUDIO_STATUS_UPDATE_LATENCY){
 		uint32 audio_latency;
-		if (frameskip_type > 1) {
+		if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON)) {
 			float frame_time_msec = 1000.0f / frame_rate;
 
 			audio_latency = (uint32)((8.0f * frame_time_msec) + 0.5f);


Commit: cdf2f3ffac8069d90f4274c669fb31b2b0972463
    https://github.com/scummvm/scummvm/commit/cdf2f3ffac8069d90f4274c669fb31b2b0972463
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: BUILD: add test on TOOLSET to identify 64bit platform

Changed paths:
    backends/platform/libretro/Makefile


diff --git a/backends/platform/libretro/Makefile b/backends/platform/libretro/Makefile
index 7e41ea2fc16..d5b9b99a731 100644
--- a/backends/platform/libretro/Makefile
+++ b/backends/platform/libretro/Makefile
@@ -18,7 +18,7 @@ ifeq ($(shell uname -a),)
 endif
 
 ifeq ($(BUILD_64BIT),)
-ifeq (,$(findstring 64,$(platform)))
+ifeq (,$(findstring 64,$(platform) $(TOOLSET)))
    BUILD_64BIT := 0
 else
    BUILD_64BIT := 1


Commit: 3e3784556591f3390ee5d0e08f38966d5db72f88
    https://github.com/scummvm/scummvm/commit/3e3784556591f3390ee5d0e08f38966d5db72f88
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: add isInGUI test

Changed paths:
    backends/platform/libretro/include/os.h
    backends/platform/libretro/src/libretro-os.cpp
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/include/os.h b/backends/platform/libretro/include/os.h
index 3bb0ce25ac1..cad4ab8b3b6 100644
--- a/backends/platform/libretro/include/os.h
+++ b/backends/platform/libretro/include/os.h
@@ -92,5 +92,6 @@ void retroSetSaveDir(const char *aPath);
 void retroKeyEvent(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
 
 uint8 getThreadSwitchCaller(void);
+bool isInGUI(void);
 
 #endif
diff --git a/backends/platform/libretro/src/libretro-os.cpp b/backends/platform/libretro/src/libretro-os.cpp
index f157920af6c..d6e9c74043f 100644
--- a/backends/platform/libretro/src/libretro-os.cpp
+++ b/backends/platform/libretro/src/libretro-os.cpp
@@ -662,6 +662,10 @@ public:
 		return _threadSwitchCaller;
 	}
 
+	bool isInGUI(){
+		return _overlayVisible && _overlayInGUI;
+	}
+
 	virtual bool pollEvent(Common::Event &event) {
 		_threadSwitchCaller = THREAD_SWITCH_POLL;
 		retroCheckThread();
@@ -1335,3 +1339,7 @@ void retroReset() {
 uint8 getThreadSwitchCaller(){
 	return dynamic_cast<OSystem_RETRO *>(g_system)->getThreadSwitchCaller();
 }
+
+bool isInGUI(){
+	return dynamic_cast<OSystem_RETRO *>(g_system)->isInGUI();
+}
diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index e039d176025..8181ea0f3bb 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -683,13 +683,13 @@ void retro_run(void) {
 
 			/* Retrieve audio */
 			samples_count = 0;
-			if (audio_video_enable & 2) {
+			if ((audio_video_enable & 2) && !isInGUI()) {
 				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
 			}
 			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
 			/* No frame skipping if there is no incoming audio (e.g. GUI) or if frontend does not support frame skipping*/
-			skip_frame = skip_frame && ! (audio_status & AUDIO_STATUS_MUTE) && can_dupe;
+			skip_frame = skip_frame && !(audio_status & AUDIO_STATUS_MUTE)  && can_dupe;
 
 			/* Reset frameskip counter if not flagged */
 			if ((!skip_frame && frameskip_counter) || frameskip_counter >= FRAMESKIP_MAX) {


Commit: 99cbf529dbcd2cb23bd6bab99bee549e339a4fb9
    https://github.com/scummvm/scummvm/commit/99cbf529dbcd2cb23bd6bab99bee549e339a4fb9
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: move frameskip log to debug

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 8181ea0f3bb..65b296c5ff1 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -693,7 +693,7 @@ void retro_run(void) {
 
 			/* Reset frameskip counter if not flagged */
 			if ((!skip_frame && frameskip_counter) || frameskip_counter >= FRAMESKIP_MAX) {
-				log_cb(RETRO_LOG_WARN, "%d frame(s) skipped\n",frameskip_counter);
+				log_cb(RETRO_LOG_DEBUG, "%d frame(s) skipped\n",frameskip_counter);
 				skip_frame = false;
 				frameskip_counter = 0;
 


Commit: dfbd7c28c6d605cf584eac21edf812708e1036fb
    https://github.com/scummvm/scummvm/commit/dfbd7c28c6d605cf584eac21edf812708e1036fb
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: add performance settings group

Changed paths:
    backends/platform/libretro/include/libretro-core-options-intl.h
    backends/platform/libretro/include/libretro-core-options.h


diff --git a/backends/platform/libretro/include/libretro-core-options-intl.h b/backends/platform/libretro/include/libretro-core-options-intl.h
index c369c70ea43..1dd468dc654 100644
--- a/backends/platform/libretro/include/libretro-core-options-intl.h
+++ b/backends/platform/libretro/include/libretro-core-options-intl.h
@@ -80,6 +80,11 @@ struct retro_core_option_v2_category option_cats_it[] = {
 		"Salto dei fotogrammi",
 		"Impostazioni per il salto dei fotogrammi"
 	},
+	{
+		"performance",
+		NULL,
+		"Impostazioni relative alle performance"
+	},
 	{ NULL, NULL, NULL },
 };
 
@@ -193,10 +198,10 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		NULL
 	},
 	{
-		"scummvm_allow_timing_inaccuracies",
-		"Consenti inaccuratezze di timing",
+		"scummvm_auto_performance_tuner",
+		"Regolazione automatica performance",
 		NULL,
-		"Consente inaccuratezze di timing che riducono significativamente le richeste di CPU. Anche se la maggior parte delle inaccuratezze sono impercettibili, in alcuni casi potrebbe introdurre problemi di sincronizzazione audio, quindi questa opzione andrebbe abilitata solo se il raggiungimento della piena velocità non è possibile in altro modo.",
+		"Cambio automatico delle impostazioni di performance e salto dei fotogrammi se vengono rilevate performance scadenti durante il gioco. 'Consenti inaccuratezze di timing' e 'Salto dei fotogrammi Auto' saranno temporaneamente abilitati in sequenza per la sola sessione di gioco, se necessario. Le singole impostazioni salvate non saranno modificate.",
 		NULL,
 		NULL,
 		{
@@ -205,10 +210,10 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		NULL
 	},
 	{
-		"scummvm_auto_performance_tuner",
-		"Regolazione automatica performance",
+		"scummvm_allow_timing_inaccuracies",
+		"Consenti inaccuratezze di timing",
 		NULL,
-		"Cambio automatico delle impostazioni di performance e salto dei fotogrammi se vengono rilevate performance scadenti durante il gioco. 'Consenti inaccuratezze di timing' e 'Salto dei fotogrammi Auto' saranno temporaneamente abilitati in sequenza per la sola sessione di gioco, se necessario. Le singole impostazioni salvate non saranno modificate.",
+		"Consente inaccuratezze di timing che riducono significativamente le richeste di CPU. Anche se la maggior parte delle inaccuratezze sono impercettibili, in alcuni casi potrebbe introdurre problemi di sincronizzazione audio, quindi questa opzione andrebbe abilitata solo se il raggiungimento della piena velocità non è possibile in altro modo.",
 		NULL,
 		NULL,
 		{
diff --git a/backends/platform/libretro/include/libretro-core-options.h b/backends/platform/libretro/include/libretro-core-options.h
index 32d948d82c9..7c28a6fd828 100644
--- a/backends/platform/libretro/include/libretro-core-options.h
+++ b/backends/platform/libretro/include/libretro-core-options.h
@@ -82,6 +82,11 @@ struct retro_core_option_v2_category option_cats_us[] = {
 		"Frameskip",
 		"Configure frameskip settings"
 	},
+	{
+		"performance",
+		"Performance",
+		"Configure performance settings"
+	},
 	{ NULL, NULL, NULL },
 };
 
@@ -258,36 +263,36 @@ struct retro_core_option_v2_definition option_defs_us[] = {
 		"0"
 	},
 	{
-		"scummvm_allow_timing_inaccuracies",
-		"Allow Timing Inaccuracies",
-		NULL,
-		"Allow timing inaccuracies that reduces CPU requirements. Though most timing deviations are imperceptible, in some cases it may introduce audio sync/timing issues, hence this option should be enabled only if full speed cannot be reached otherwise.",
+		"scummvm_auto_performance_tuner",
+		"Auto performance tuner",
 		NULL,
+		"In-game automatic change of performance/frameskip settings if low performances are detected. 'Allow Timing Inaccuracies' and 'Auto Frameskip' will be temporarily set on in sequence, if necessary, for the current game session only. Single saved settings will not be affected.",
 		NULL,
+		"performance",
 		{
 			{"disabled", NULL},
 			{"enabled", NULL},
 			{NULL, NULL},
 		},
-#if defined(DINGUX) || defined(_3DS)
 		"enabled"
-#else
-		"disabled"
-#endif
 	},
 	{
-		"scummvm_auto_performance_tuner",
-		"Auto performance tuner",
-		NULL,
-		"In-game automatic change of performance/frameskip settings if low performances are detected. 'Allow Timing Inaccuracies' and 'Auto Frameskip' will be temporarily set on in sequence, if necessary, for the current game session only. Single saved settings will not be affected.",
+		"scummvm_allow_timing_inaccuracies",
+		"Allow Timing Inaccuracies",
 		NULL,
+		"Allow timing inaccuracies that reduces CPU requirements. Though most timing deviations are imperceptible, in some cases it may introduce audio sync/timing issues, hence this option should be enabled only if full speed cannot be reached otherwise.",
 		NULL,
+		"performance",
 		{
 			{"disabled", NULL},
 			{"enabled", NULL},
 			{NULL, NULL},
 		},
+#if defined(DINGUX) || defined(_3DS)
 		"enabled"
+#else
+		"disabled"
+#endif
 	},
 	{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
 };


Commit: 480f38f03a82f6c72414bab45963b619f8c304e8
    https://github.com/scummvm/scummvm/commit/480f38f03a82f6c72414bab45963b619f8c304e8
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: rename frameskip manual setting to threshold

Changed paths:
    backends/platform/libretro/include/libretro-core-options-intl.h
    backends/platform/libretro/include/libretro-core-options.h


diff --git a/backends/platform/libretro/include/libretro-core-options-intl.h b/backends/platform/libretro/include/libretro-core-options-intl.h
index 1dd468dc654..9abc8a72d8f 100644
--- a/backends/platform/libretro/include/libretro-core-options-intl.h
+++ b/backends/platform/libretro/include/libretro-core-options-intl.h
@@ -155,14 +155,14 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		"scummvm_frameskip_type",
 		"Salto dei fotogrammi",
 		NULL,
-		"Salto dei fotogrammi per evitare buffer under-run audio (crackling). Migliora le prestazioni a discapito della fluidità video. 'Auto' salta i fotogrammi su indicazione del frontend, 'Manuale' usa l'impostazione di 'Soglia minima buffer audio (%)', 'Fisso' usa l'impostazione 'Salto dei fotogrammi fisso'.",
+		"Salto dei fotogrammi per evitare buffer under-run audio (crackling). Migliora le prestazioni a discapito della fluidità video. 'Auto' salta i fotogrammi su indicazione del frontend, 'Soglia' usa l'impostazione di 'Soglia minima buffer audio (%)', 'Fisso' usa l'impostazione 'Salto dei fotogrammi fisso'.",
 		NULL,
 		"frameskip",
 		{
 			{ "disabled", NULL },
 			{ "fixed", "Fisso" },
 			{ "auto", "Auto" },
-			{ "manual", "Manuale" },
+			{ "manual", "Soglia" },
 			{ NULL, NULL },
 		},
 		NULL
@@ -171,7 +171,7 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		"scummvm_frameskip_threshold",
 		"Soglia minima buffer audio (%)",
 		NULL,
-		"Quando 'Salto dei fotogrammi' è impostato su 'Manuale', specifica la soglia minima del buffer audio al di sotto della quale il fotogramma viene saltato. Valori più alti riducono il rischio di crackling al costo di un salto di fotogrammi più frequente.",
+		"Quando 'Salto dei fotogrammi' è impostato su 'Soglia', specifica la soglia minima del buffer audio al di sotto della quale il fotogramma viene saltato. Valori più alti riducono il rischio di crackling al costo di un salto di fotogrammi più frequente.",
 		NULL,
 		"frameskip",
 		{
diff --git a/backends/platform/libretro/include/libretro-core-options.h b/backends/platform/libretro/include/libretro-core-options.h
index 7c28a6fd828..eb6559d8c61 100644
--- a/backends/platform/libretro/include/libretro-core-options.h
+++ b/backends/platform/libretro/include/libretro-core-options.h
@@ -204,14 +204,14 @@ struct retro_core_option_v2_definition option_defs_us[] = {
 		"scummvm_frameskip_type",
 		"Frameskip Mode",
 		NULL,
-		"Skip frames to avoid audio buffer under-run (crackling). Improves performance at the expense of visual smoothness. 'Auto' skips frames when advised by the frontend. 'Manual' uses the 'Frameskip Threshold (%)' setting. 'Fixed' uses the 'Fixed Frameskip' setting.",
+		"Skip frames to avoid audio buffer under-run (crackling). Improves performance at the expense of visual smoothness. 'Auto' skips frames when advised by the frontend. 'Threshold' uses the 'Frameskip Threshold (%)' setting. 'Fixed' uses the 'Fixed Frameskip' setting.",
 		NULL,
 		"frameskip",
 		{
 			{ "disabled", NULL },
 			{ "fixed", "Fixed" },
 			{ "auto", "Auto" },
-			{ "manual", "Manual" },
+			{ "manual", "Threshold" },
 			{ NULL, NULL },
 		},
 		"auto"
@@ -220,7 +220,7 @@ struct retro_core_option_v2_definition option_defs_us[] = {
 		"scummvm_frameskip_threshold",
 		"Frameskip Threshold (%)",
 		NULL,
-		"When 'Frameskip' is set to 'Manual', specifies the audio buffer occupancy threshold (percentage) below which frames will be skipped. Higher values reduce the risk of crackling by causing frames to be dropped more frequently.",
+		"When 'Frameskip' is set to 'Threshold', specifies the audio buffer occupancy threshold (percentage) below which frames will be skipped. Higher values reduce the risk of crackling by causing frames to be dropped more frequently.",
 		NULL,
 		"frameskip",
 		{


Commit: 63fc1d460915d7fc3efc1847d22c601eec41b667
    https://github.com/scummvm/scummvm/commit/63fc1d460915d7fc3efc1847d22c601eec41b667
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:32+02:00

Commit Message:
LIBRETRO: add bug report template

Changed paths:
  A backends/platform/libretro/BUG_REPORT.md


diff --git a/backends/platform/libretro/BUG_REPORT.md b/backends/platform/libretro/BUG_REPORT.md
new file mode 100644
index 00000000000..6f30a737e04
--- /dev/null
+++ b/backends/platform/libretro/BUG_REPORT.md
@@ -0,0 +1,46 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: ''
+assignees: ''
+
+---
+
+## Description
+[Description of the bug]
+
+### Expected behavior
+[What you expected to happen]
+
+### Actual behavior
+[What is actually happening]
+
+### Screenshots
+[If applicable, add screenshots to help explain your problem]
+
+### Steps to reproduce the bug
+1. [First step]
+2. [Second step]
+3. [and so on...]
+
+### Version/Commit
+[You can find this information under Information->Core Information / System Information]
+- ScummVM core: [version/commit]
+- RetroArch: [version/commit]
+
+### Working on stand-alone ScummVM
+[Specify if the same issue also occurs with the daily build of stand-alone ScummVM]
+
+### ScummVM game/engine
+[Provide exact game version, better with ScummVM game ID]
+
+### Environment information
+- Device:
+- OS: [The operating system you're running]
+
+### RetroArch logs
+[Provide RetroArch logs with DEBUG level set both for frontend and cores]
+
+### Additional context
+[Add any other context about the problem here]


Commit: f6010ebdaf8c025259ad9d672b5724660ce48b52
    https://github.com/scummvm/scummvm/commit/f6010ebdaf8c025259ad9d672b5724660ce48b52
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: reorder frameskip_type tests

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 65b296c5ff1..6fecb2483c9 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -672,10 +672,10 @@ void retro_run(void) {
 			}
 
 			/* Determine frameskip need based on settings */
-			if (frameskip_type == 1)
-				skip_frame = !(current_frame % frameskip_no == 0);
-			else if ((frameskip_type == 2) || (performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP))
+			if ((frameskip_type == 2) || (performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP))
 				skip_frame = (audio_status & AUDIO_STATUS_BUFFER_UNDERRUN);
+			else if (frameskip_type == 1)
+				skip_frame = !(current_frame % frameskip_no == 0);
 			else if (frameskip_type == 3)
 				skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
 


Commit: dbd7608f5541a571f15aaea385afb236ca6f4202
    https://github.com/scummvm/scummvm/commit/dbd7608f5541a571f15aaea385afb236ca6f4202
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: simplify audio_batch_cb call

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 6fecb2483c9..c8362241a96 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -719,7 +719,7 @@ void retro_run(void) {
 				audio_buffer_init(SAMPLE_RATE, (uint16) frame_rate);
 			}
 #endif
-			audio_batch_cb((audio_status & AUDIO_STATUS_MUTE) ? NULL : (int16_t *) sound_buffer, samples_count); // Set to NULL to skip sound rendering
+			audio_batch_cb((int16_t *) sound_buffer, samples_count);
 
 			current_frame++;
 


Commit: 99f71d3e41af55fc4791998ecf384757b0af699b
    https://github.com/scummvm/scummvm/commit/99f71d3e41af55fc4791998ecf384757b0af699b
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: test frame_skip before thread switch

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index c8362241a96..de7d8ec884e 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -679,8 +679,6 @@ void retro_run(void) {
 			else if (frameskip_type == 3)
 				skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
 
-			retro_switch_to_emu_thread();
-
 			/* Retrieve audio */
 			samples_count = 0;
 			if ((audio_video_enable & 2) && !isInGUI()) {
@@ -701,6 +699,10 @@ void retro_run(void) {
 			} else if (skip_frame)
 				frameskip_counter++;
 
+			/* Switch to ScummVM thread, unless frameskipping is ongoing */
+			if (!skip_frame)
+				retro_switch_to_emu_thread();
+
 			/* Retrieve video */
 			if ((audio_video_enable & 1) && !skip_frame) {
 				const Graphics::Surface &screen = getScreen();


Commit: bf42315fcdd125fae25f44d04610d4840f71a135
    https://github.com/scummvm/scummvm/commit/bf42315fcdd125fae25f44d04610d4840f71a135
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: reorder audio retrieving

Changed paths:
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index de7d8ec884e..f7ee3e853d9 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -679,12 +679,6 @@ void retro_run(void) {
 			else if (frameskip_type == 3)
 				skip_frame = (retro_audio_buff_occupancy < frameskip_threshold);
 
-			/* Retrieve audio */
-			samples_count = 0;
-			if ((audio_video_enable & 2) && !isInGUI()) {
-				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
-			}
-			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
 			/* No frame skipping if there is no incoming audio (e.g. GUI) or if frontend does not support frame skipping*/
 			skip_frame = skip_frame && !(audio_status & AUDIO_STATUS_MUTE)  && can_dupe;
@@ -703,6 +697,13 @@ void retro_run(void) {
 			if (!skip_frame)
 				retro_switch_to_emu_thread();
 
+			/* Retrieve audio */
+			samples_count = 0;
+			if ((audio_video_enable & 2) && !isInGUI()) {
+				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
+			}
+			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
+
 			/* Retrieve video */
 			if ((audio_video_enable & 1) && !skip_frame) {
 				const Graphics::Surface &screen = getScreen();


Commit: addf767cebc34b94425186e0a10614a80c8ac7fe
    https://github.com/scummvm/scummvm/commit/addf767cebc34b94425186e0a10614a80c8ac7fe
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: simplify audio retrieve test and drop unused isInGUI()

Changed paths:
    backends/platform/libretro/include/os.h
    backends/platform/libretro/src/libretro-os.cpp
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/include/os.h b/backends/platform/libretro/include/os.h
index cad4ab8b3b6..3bb0ce25ac1 100644
--- a/backends/platform/libretro/include/os.h
+++ b/backends/platform/libretro/include/os.h
@@ -92,6 +92,5 @@ void retroSetSaveDir(const char *aPath);
 void retroKeyEvent(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
 
 uint8 getThreadSwitchCaller(void);
-bool isInGUI(void);
 
 #endif
diff --git a/backends/platform/libretro/src/libretro-os.cpp b/backends/platform/libretro/src/libretro-os.cpp
index d6e9c74043f..f157920af6c 100644
--- a/backends/platform/libretro/src/libretro-os.cpp
+++ b/backends/platform/libretro/src/libretro-os.cpp
@@ -662,10 +662,6 @@ public:
 		return _threadSwitchCaller;
 	}
 
-	bool isInGUI(){
-		return _overlayVisible && _overlayInGUI;
-	}
-
 	virtual bool pollEvent(Common::Event &event) {
 		_threadSwitchCaller = THREAD_SWITCH_POLL;
 		retroCheckThread();
@@ -1339,7 +1335,3 @@ void retroReset() {
 uint8 getThreadSwitchCaller(){
 	return dynamic_cast<OSystem_RETRO *>(g_system)->getThreadSwitchCaller();
 }
-
-bool isInGUI(){
-	return dynamic_cast<OSystem_RETRO *>(g_system)->isInGUI();
-}
diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index f7ee3e853d9..35bc523a6c4 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -699,7 +699,7 @@ void retro_run(void) {
 
 			/* Retrieve audio */
 			samples_count = 0;
-			if ((audio_video_enable & 2) && !isInGUI()) {
+			if (audio_video_enable & 2) {
 				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
 			}
 			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);


Commit: f614c5319115c6b89bc878959956c4a53e1ce1da
    https://github.com/scummvm/scummvm/commit/f614c5319115c6b89bc878959956c4a53e1ce1da
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2023-04-02T05:27:33+02:00

Commit Message:
LIBRETRO: add framerate reduction option

Changed paths:
    backends/platform/libretro/include/libretro-core-options-intl.h
    backends/platform/libretro/include/libretro-core-options.h
    backends/platform/libretro/include/os.h
    backends/platform/libretro/src/libretro.cpp


diff --git a/backends/platform/libretro/include/libretro-core-options-intl.h b/backends/platform/libretro/include/libretro-core-options-intl.h
index 9abc8a72d8f..5d1bd36555c 100644
--- a/backends/platform/libretro/include/libretro-core-options-intl.h
+++ b/backends/platform/libretro/include/libretro-core-options-intl.h
@@ -221,6 +221,22 @@ struct retro_core_option_v2_definition option_defs_it[] = {
 		},
 		NULL
 	},
+	{
+		"scummvm_reduce_framerate_type",
+		"Riduzione del framerate",
+		NULL,
+		"Riduce il framerate corrente per abbassare le richieste di CPU. La modalità 'Auto' riduce temporaneamente il framerate quando Reduces current framerate to reduce CPU requirements. 'Auto' mode temporarily reduces the framerate as needed when audio buffer underrun is detected, while the in the other modes the reduction is constant.",
+		NULL,
+		NULL,
+		{
+			{ "disabled", NULL },
+			{ "auto", "Auto" },
+			{ "half", "1/2 del framerate attuale" },
+			{ "quarter", "1/4 del framerate attuale" },
+			{ NULL, NULL },
+		},
+		NULL
+        },
 	{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
 };
 
diff --git a/backends/platform/libretro/include/libretro-core-options.h b/backends/platform/libretro/include/libretro-core-options.h
index eb6559d8c61..a5d0e6e37b7 100644
--- a/backends/platform/libretro/include/libretro-core-options.h
+++ b/backends/platform/libretro/include/libretro-core-options.h
@@ -294,6 +294,22 @@ struct retro_core_option_v2_definition option_defs_us[] = {
 		"disabled"
 #endif
 	},
+	{
+		"scummvm_reduce_framerate_type",
+		"Reduce framerate",
+		NULL,
+		"Reduces current framerate to reduce CPU requirements. 'Auto' mode temporarily reduces the framerate as needed when audio buffer underrun is detected, while the in the other modes the reduction is constant.",
+		NULL,
+		"performance",
+		{
+			{ "disabled", NULL },
+			{ "auto", "Auto" },
+			{ "half", "1/2 of current framerate" },
+			{ "quarter", "1/4 of current framerate" },
+			{ NULL, NULL },
+		},
+		"disabled"
+	},
 	{ NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
 };
 
diff --git a/backends/platform/libretro/include/os.h b/backends/platform/libretro/include/os.h
index 3bb0ce25ac1..3ee08980d54 100644
--- a/backends/platform/libretro/include/os.h
+++ b/backends/platform/libretro/include/os.h
@@ -37,8 +37,16 @@
 #define PERF_SWITCH_FRAMESKIP_EVENTS              REFRESH_RATE * 2
 #define PERF_SWITCH_ON                            (1 << 0)
 #define PERF_SWITCH_ENABLE_TIMING_INACCURACIES    (1 << 1)
-#define PERF_SWITCH_ENABLE_AUTO_FRAMESKIP         (1 << 2)
-#define PERF_SWITCH_OVER                          (1 << 3)
+#define PERF_SWITCH_ENABLE_REDUCE_FRAMERATE       (1 << 2)
+#define PERF_SWITCH_ENABLE_AUTO_FRAMESKIP         (1 << 3)
+#define PERF_SWITCH_OVER                          (1 << 4)
+
+// Reduce framerate
+#define REDUCE_FRAMERATE_TAIL           REFRESH_RATE / 2
+#define REDUCE_FRAMERATE_SHIFT_MAX      2
+#define REDUCE_FRAMERATE_SHIFT_AUTO     1
+#define REDUCE_FRAMERATE_SHIFT_HALF     2
+#define REDUCE_FRAMERATE_SHIFT_QUARTER  3
 
 // Thread switch caller
 #define THREAD_SWITCH_POLL              (1 << 0)
diff --git a/backends/platform/libretro/src/libretro.cpp b/backends/platform/libretro/src/libretro.cpp
index 35bc523a6c4..99591cd798a 100644
--- a/backends/platform/libretro/src/libretro.cpp
+++ b/backends/platform/libretro/src/libretro.cpp
@@ -87,6 +87,10 @@ static uint8 frameskip_threshold;
 static uint32 frameskip_counter = 0;
 static uint8 frameskip_events = 0;
 
+static uint8 reduce_framerate_type = 0;
+static uint8 reduce_framerate_shift = 0;
+static uint8 reduce_framerate_countdown = 0;
+
 static bool can_dupe = false;
 static uint8 audio_status = 0;
 
@@ -102,14 +106,15 @@ static uint8 performance_switch = 0;
 
 static void audio_buffer_init(uint16 sample_rate, uint16 frame_rate) {
 	samples_per_frame = sample_rate / frame_rate;
+
 	samples_per_frame_buffer_size = samples_per_frame << 1 * sizeof(int16_t);
 
 	if (sound_buffer)
-		sound_buffer = (int16_t *)realloc(sound_buffer, samples_per_frame_buffer_size);
+		sound_buffer = (int16_t *)realloc(sound_buffer, samples_per_frame_buffer_size << REDUCE_FRAMERATE_SHIFT_MAX);
 	else
-		sound_buffer = (int16_t *)malloc(samples_per_frame_buffer_size);
+		sound_buffer = (int16_t *)malloc(samples_per_frame_buffer_size << REDUCE_FRAMERATE_SHIFT_MAX);
 	if (sound_buffer)
-		memset(sound_buffer, 0, samples_per_frame_buffer_size);
+		memset(sound_buffer, 0, samples_per_frame_buffer_size << REDUCE_FRAMERATE_SHIFT_MAX);
 	else
 		log_cb(RETRO_LOG_ERROR, "audio_buffer_init error.\n");
 
@@ -131,7 +136,7 @@ static void retro_audio_buff_status_cb(bool active, unsigned occupancy, bool und
 }
 
 static void set_audio_buffer_status() {
-	if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON)) {
+	if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON) || reduce_framerate_type) {
 		struct retro_audio_buffer_status_callback buf_status_cb;
 		buf_status_cb.callback = retro_audio_buff_status_cb;
 		audio_status = environ_cb(RETRO_ENVIRONMENT_SET_AUDIO_BUFFER_STATUS_CALLBACK, &buf_status_cb) ? (audio_status | AUDIO_STATUS_BUFFER_SUPPORT) : (audio_status & ~AUDIO_STATUS_BUFFER_SUPPORT);
@@ -151,6 +156,10 @@ static void increase_performance() {
 		retro_msg.msg = "Auto performance tuner: 'Allow Timing Inaccuracies' enabled";
 		log_cb(RETRO_LOG_INFO, "Auto performance tuner: 'Allow Timing Inaccuracies' enabled.\n");
 		performance_switch |= PERF_SWITCH_ENABLE_TIMING_INACCURACIES;
+	} else if (reduce_framerate_type != REDUCE_FRAMERATE_SHIFT_AUTO && !(performance_switch & PERF_SWITCH_ENABLE_REDUCE_FRAMERATE)) {
+		retro_msg.msg = "Auto performance tuner: 'Auto reduce framerate' enabled";
+		log_cb(RETRO_LOG_INFO, "Auto performance tuner: 'Auto reduce framerate' enabled.\n");
+		performance_switch |= PERF_SWITCH_ENABLE_REDUCE_FRAMERATE;
 	} else if (frameskip_type != 2 && !(performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP)) {
 		retro_msg.msg = "Auto performance tuner: 'Auto frameskip' enabled";
 		log_cb(RETRO_LOG_INFO, "Auto performance tuner: 'Auto frameskip' enabled.\n");
@@ -239,6 +248,19 @@ static void update_variables(void) {
 			frameskip_type = 3;
 	}
 
+	var.key = "scummvm_reduce_framerate_type";
+	var.value = NULL;
+	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
+		if (strcmp(var.value, "disabled") == 0)
+			reduce_framerate_type = 0;
+		else if (strcmp(var.value, "auto") == 0)
+			reduce_framerate_type = REDUCE_FRAMERATE_SHIFT_AUTO;
+		else if (strcmp(var.value, "half") == 0)
+			reduce_framerate_type = REDUCE_FRAMERATE_SHIFT_HALF;
+		else if (strcmp(var.value, "quarter") == 0)
+			reduce_framerate_type = REDUCE_FRAMERATE_SHIFT_QUARTER;
+	}
+
 	var.key = "scummvm_auto_performance_tuner";
 	if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) {
 		if (strcmp(var.value, "enabled") == 0) {
@@ -253,23 +275,33 @@ static void update_variables(void) {
 
 	set_audio_buffer_status();
 
-	if (!(audio_status & AUDIO_STATUS_BUFFER_SUPPORT) && frameskip_type > 1) {
-		log_cb(RETRO_LOG_WARN, "Selected frameskip mode not available.\n");
-		retro_msg.msg = "Selected frameskip mode not available";
-		environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
-		frameskip_type = 0;
+	if (!(audio_status & AUDIO_STATUS_BUFFER_SUPPORT)) {
+		if (frameskip_type > 1) {
+			log_cb(RETRO_LOG_WARN, "Selected frameskip mode not available.\n");
+			retro_msg.msg = "Selected frameskip mode not available";
+			environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+			frameskip_type = 0;
+		}
+
+		if (reduce_framerate_type == REDUCE_FRAMERATE_SHIFT_AUTO) {
+			log_cb(RETRO_LOG_WARN, "Auto reduce framerate not available.\n");
+			retro_msg.msg = "Auto reduce framerate not available";
+			environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+			reduce_framerate_type = 0;
+		}
+
+		if (performance_switch) {
+			log_cb(RETRO_LOG_WARN, "Auto performance tuner not available.\n");
+			retro_msg.msg = "Auto performance tuner not available";
+			environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
+			performance_switch = 0;
+		}
 	}
+
 	if (old_frameskip_type != frameskip_type) {
 		audio_status |= AUDIO_STATUS_UPDATE_LATENCY;
 	}
 
-	if (!(audio_status & AUDIO_STATUS_BUFFER_SUPPORT) && performance_switch) {
-		log_cb(RETRO_LOG_WARN, "Auto performance tuner not available.\n");
-		retro_msg.msg = "Auto performance tuner not available";
-		environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &retro_msg);
-		performance_switch = 0;
-	}
-
 
 }
 
@@ -671,6 +703,25 @@ void retro_run(void) {
 				}
 			}
 
+			/* Framerate reduction using sound buffer size */
+			if (reduce_framerate_type == REDUCE_FRAMERATE_SHIFT_AUTO || (performance_switch & PERF_SWITCH_ENABLE_REDUCE_FRAMERATE)) {
+				if ((audio_status & AUDIO_STATUS_BUFFER_UNDERRUN) && !(audio_status & AUDIO_STATUS_MUTE)) {
+					if (reduce_framerate_shift < REDUCE_FRAMERATE_SHIFT_MAX)
+						reduce_framerate_shift++;
+					reduce_framerate_countdown = REDUCE_FRAMERATE_TAIL;
+				}
+				if (reduce_framerate_countdown)
+					reduce_framerate_countdown--;
+				else
+					reduce_framerate_shift = 0;
+			} else if (reduce_framerate_type == REDUCE_FRAMERATE_SHIFT_HALF) {
+				reduce_framerate_shift = 1;
+			} else if (reduce_framerate_type == REDUCE_FRAMERATE_SHIFT_QUARTER) {
+				reduce_framerate_shift = 2;
+			} else {
+				reduce_framerate_shift = 0;
+			}
+
 			/* Determine frameskip need based on settings */
 			if ((frameskip_type == 2) || (performance_switch & PERF_SWITCH_ENABLE_AUTO_FRAMESKIP))
 				skip_frame = (audio_status & AUDIO_STATUS_BUFFER_UNDERRUN);
@@ -700,7 +751,7 @@ void retro_run(void) {
 			/* Retrieve audio */
 			samples_count = 0;
 			if (audio_video_enable & 2) {
-				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size);
+				samples_count = ((Audio::MixerImpl *)g_system->getMixer())->mixCallback((byte *) sound_buffer, samples_per_frame_buffer_size << reduce_framerate_shift);
 			}
 			audio_status = samples_count ? (audio_status & ~AUDIO_STATUS_MUTE) : (audio_status | AUDIO_STATUS_MUTE);
 
@@ -739,7 +790,7 @@ void retro_run(void) {
 
 	if (audio_status & AUDIO_STATUS_UPDATE_LATENCY){
 		uint32 audio_latency;
-		if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON)) {
+		if (frameskip_type > 1 || (performance_switch & PERF_SWITCH_ON) || reduce_framerate_type) {
 			float frame_time_msec = 1000.0f / frame_rate;
 
 			audio_latency = (uint32)((8.0f * frame_time_msec) + 0.5f);




More information about the Scummvm-git-logs mailing list