mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
alittle better performance. depends on device.
This commit is contained in:
@@ -11,10 +11,12 @@
|
||||
#include <jni.h>
|
||||
|
||||
#include <climits>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sys/stat.h>
|
||||
@@ -205,6 +207,69 @@ static std::string JStringToString(JNIEnv* env, jstring value) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static std::string ToLowerAscii(std::string value) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
static std::string GetBuildField(JNIEnv* env, const char* field_name) {
|
||||
jclass buildClass = env->FindClass("android/os/Build");
|
||||
if (!buildClass) {
|
||||
HasException(env, "Build class lookup");
|
||||
return {};
|
||||
}
|
||||
jfieldID field = env->GetStaticFieldID(buildClass, field_name, "Ljava/lang/String;");
|
||||
if (!field) {
|
||||
HasException(env, field_name);
|
||||
env->DeleteLocalRef(buildClass);
|
||||
return {};
|
||||
}
|
||||
jstring value =
|
||||
static_cast<jstring>(env->GetStaticObjectField(buildClass, field));
|
||||
if (HasException(env, field_name)) {
|
||||
env->DeleteLocalRef(buildClass);
|
||||
return {};
|
||||
}
|
||||
std::string out = JStringToString(env, value);
|
||||
if (value) {
|
||||
env->DeleteLocalRef(value);
|
||||
}
|
||||
env->DeleteLocalRef(buildClass);
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool ShouldEnableInlineAioWorkaround() {
|
||||
const char* forced = SDL_getenv("XEMU_ANDROID_INLINE_AIO");
|
||||
if (forced) {
|
||||
return forced[0] != '\0' && forced[0] != '0';
|
||||
}
|
||||
|
||||
JNIEnv* env = GetEnv();
|
||||
if (!env) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string device = ToLowerAscii(GetBuildField(env, "DEVICE"));
|
||||
const std::string product = ToLowerAscii(GetBuildField(env, "PRODUCT"));
|
||||
const std::string model = ToLowerAscii(GetBuildField(env, "MODEL"));
|
||||
|
||||
static const char* kAffectedDevices[] = {
|
||||
"duchamp",
|
||||
};
|
||||
|
||||
for (const char* marker : kAffectedDevices) {
|
||||
if (device == marker ||
|
||||
product.find(marker) != std::string::npos ||
|
||||
model.find(marker) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static std::string GetPrefString(JNIEnv* env, jobject activity, const char* key) {
|
||||
jclass activityClass = env->GetObjectClass(activity);
|
||||
jmethodID getPrefs = env->GetMethodID(activityClass, "getSharedPreferences",
|
||||
@@ -324,10 +389,13 @@ static bool WriteConfigToml(const std::string& config_path,
|
||||
toml::table* general = EnsureTable(tbl, "general");
|
||||
toml::table* display = EnsureTable(tbl, "display");
|
||||
toml::table* display_window = EnsureTable(*display, "window");
|
||||
toml::table* audio = EnsureTable(tbl, "audio");
|
||||
toml::table* audio_vp = EnsureTable(*audio, "vp");
|
||||
toml::table* android = EnsureTable(tbl, "android");
|
||||
toml::table* sys = EnsureTable(tbl, "sys");
|
||||
toml::table* files = EnsureTable(*sys, "files");
|
||||
if (!general || !display || !display_window || !android || !sys || !files) {
|
||||
if (!general || !display || !display_window || !audio || !audio_vp ||
|
||||
!android || !sys || !files) {
|
||||
LogErrorFmt("Failed to build config tables at %s", config_path.c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -340,6 +408,15 @@ static bool WriteConfigToml(const std::string& config_path,
|
||||
if (!display_window->contains("vsync")) {
|
||||
display_window->insert_or_assign("vsync", false);
|
||||
}
|
||||
if (!audio_vp->contains("num_workers")) {
|
||||
audio_vp->insert_or_assign("num_workers", 0);
|
||||
}
|
||||
if (!audio->contains("hrtf")) {
|
||||
audio->insert_or_assign("hrtf", true);
|
||||
}
|
||||
if (!audio->contains("volume_limit")) {
|
||||
audio->insert_or_assign("volume_limit", 1.0);
|
||||
}
|
||||
if (!android->contains("force_cpu_blit")) {
|
||||
android->insert_or_assign("force_cpu_blit", false);
|
||||
}
|
||||
@@ -524,6 +601,12 @@ extern "C" int SDL_main(int argc, char* argv[]) {
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
LoadGameControllerMappingsFromAssets();
|
||||
|
||||
if (!SDL_getenv("XEMU_ANDROID_INLINE_AIO")) {
|
||||
const bool use_inline_aio = ShouldEnableInlineAioWorkaround();
|
||||
setenv("XEMU_ANDROID_INLINE_AIO", use_inline_aio ? "1" : "0", 1);
|
||||
LogInfoFmt("XEMU_ANDROID_INLINE_AIO=%s", use_inline_aio ? "1" : "0");
|
||||
}
|
||||
|
||||
SetupFiles setup = SyncSetupFiles();
|
||||
|
||||
if (!setup.config_path.empty()) {
|
||||
|
||||
@@ -196,6 +196,8 @@ const char *xemu_settings_get_default_eeprom_path(void)
|
||||
|
||||
bool xemu_settings_load(void)
|
||||
{
|
||||
const int kMaxAudioVpWorkers = 16;
|
||||
|
||||
xemu_settings_apply_defaults();
|
||||
error_msg.clear();
|
||||
setenv("XEMU_ANDROID_FORCE_CPU_BLIT", "0", 1);
|
||||
@@ -219,6 +221,8 @@ bool xemu_settings_load(void)
|
||||
auto general = tbl["general"];
|
||||
auto display = tbl["display"];
|
||||
auto display_window = display["window"];
|
||||
auto audio = tbl["audio"];
|
||||
auto audio_vp = audio["vp"];
|
||||
auto perf = tbl["perf"];
|
||||
auto android_cfg = tbl["android"];
|
||||
auto sys = tbl["sys"];
|
||||
@@ -259,6 +263,32 @@ bool xemu_settings_load(void)
|
||||
g_config.perf.cache_shaders = *cache_shaders;
|
||||
}
|
||||
|
||||
// Audio settings
|
||||
if (auto vp_workers = audio_vp["num_workers"].value<int64_t>()) {
|
||||
int workers = (int)*vp_workers;
|
||||
if (workers < 0) {
|
||||
workers = 0;
|
||||
} else if (workers > kMaxAudioVpWorkers) {
|
||||
workers = kMaxAudioVpWorkers;
|
||||
}
|
||||
g_config.audio.vp.num_workers = workers;
|
||||
}
|
||||
if (auto use_dsp = audio["use_dsp"].value<bool>()) {
|
||||
g_config.audio.use_dsp = *use_dsp;
|
||||
}
|
||||
if (auto hrtf = audio["hrtf"].value<bool>()) {
|
||||
g_config.audio.hrtf = *hrtf;
|
||||
}
|
||||
if (auto volume_limit = audio["volume_limit"].value<double>()) {
|
||||
double volume = *volume_limit;
|
||||
if (volume < 0.0) {
|
||||
volume = 0.0;
|
||||
} else if (volume > 1.0) {
|
||||
volume = 1.0;
|
||||
}
|
||||
g_config.audio.volume_limit = volume;
|
||||
}
|
||||
|
||||
// Android-specific settings
|
||||
if (auto force_cpu_blit = android_cfg["force_cpu_blit"].value<bool>()) {
|
||||
setenv("XEMU_ANDROID_FORCE_CPU_BLIT", *force_cpu_blit ? "1" : "0", 1);
|
||||
@@ -291,6 +321,43 @@ bool xemu_settings_load(void)
|
||||
snprintf(tb_size_str, sizeof(tb_size_str), "%d", tb_size);
|
||||
setenv("XEMU_ANDROID_TCG_TB_SIZE", tb_size_str, 1);
|
||||
}
|
||||
if (auto inline_aio = android_cfg["inline_aio"].value<bool>()) {
|
||||
setenv("XEMU_ANDROID_INLINE_AIO", *inline_aio ? "1" : "0", 1);
|
||||
}
|
||||
if (auto vp_workers = android_cfg["vp_workers"].value<int64_t>()) {
|
||||
int workers = (int)*vp_workers;
|
||||
if (workers < 0) {
|
||||
workers = 0;
|
||||
} else if (workers > kMaxAudioVpWorkers) {
|
||||
workers = kMaxAudioVpWorkers;
|
||||
}
|
||||
char workers_str[16];
|
||||
snprintf(workers_str, sizeof(workers_str), "%d", workers);
|
||||
setenv("XEMU_ANDROID_VP_WORKERS", workers_str, 1);
|
||||
}
|
||||
if (auto audio_samples = android_cfg["audio_samples"].value<int64_t>()) {
|
||||
int samples = (int)*audio_samples;
|
||||
if (samples < 256) {
|
||||
samples = 256;
|
||||
} else if (samples > 4096) {
|
||||
samples = 4096;
|
||||
}
|
||||
char samples_str[16];
|
||||
snprintf(samples_str, sizeof(samples_str), "%d", samples);
|
||||
setenv("XEMU_ANDROID_AUDIO_SAMPLES", samples_str, 1);
|
||||
}
|
||||
if (auto audio_fifo_frames =
|
||||
android_cfg["audio_fifo_frames"].value<int64_t>()) {
|
||||
int fifo_frames = (int)*audio_fifo_frames;
|
||||
if (fifo_frames < 3) {
|
||||
fifo_frames = 3;
|
||||
} else if (fifo_frames > 32) {
|
||||
fifo_frames = 32;
|
||||
}
|
||||
char fifo_str[16];
|
||||
snprintf(fifo_str, sizeof(fifo_str), "%d", fifo_frames);
|
||||
setenv("XEMU_ANDROID_AUDIO_FIFO_FRAMES", fifo_str, 1);
|
||||
}
|
||||
|
||||
// System file paths
|
||||
if (auto bootrom = sys_files["bootrom_path"].value<std::string>()) {
|
||||
|
||||
Reference in New Issue
Block a user