Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ jobs:
/emulator-core/src/main/java/
/emulator-core/src/main/cpp/*.cpp
/emulator-core/src/main/cpp/*.h
/emulator-core/src/main/cpp/xenia/src/xenia/base/cvar.h

- name: Python syntax
run: python3 -m py_compile tools/*.py tools/ir3_offline/*.py

- name: CVar update macros
run: python3 tools/check-cvar-updates.py

- name: Release scripts
run: |
python3 tools/release_notes_test.py
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xendroid/compose/EmulatorHostActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class EmulatorHostActivity : ComponentActivity(), SurfaceHolder.Callback {
private const val ZEROFG_KEY = "Vulkan|zerofg_mode"
private val MENU_CONFIG_KEYS = listOf(FPS_KEY, SCALING_KEY, AA_KEY, CAS_KEY, DITHER_KEY, TOUCH_KEY, VOLUME_KEY, ZEROFG_KEY) +
xendroid.compose.core.GpuLiveOption.entries.map { it.key }
private val FPS_CHOICES = listOf(0, 30, 40, 45, 60, 90, 120)
private val FPS_CHOICES = listOf(0, 20, 30, 40, 45, 60, 90, 120)
private val HUD_DETAILS = listOf(xendroid.compose.core.HudDetail.COMPACT, xendroid.compose.core.HudDetail.FULL,
xendroid.compose.core.HudDetail.PANEL)
private const val HUD_SCALE_SPAN = xendroid.compose.core.HudPlacements.MAX_SCALE - xendroid.compose.core.HudPlacements.MIN_SCALE
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/xendroid/compose/settings/SettingsSchema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ object SettingsSchema {
SettingsCategory("HID", listOf(
l("HID", "hid", "HID backend", "android",
"android" to "android", "nop" to "nop"),
l("HID", "jit_frame_start", "Just-in-time frame start", "2",
l("HID", "jit_frame_start", "Just-in-time frame start", "0",
"0" to "Off", "1" to "Always on", "2" to "Auto (-20 ms latency)"),
)),

Expand Down Expand Up @@ -200,7 +200,7 @@ object SettingsSchema {
// A dropdown, not a slider: only a few values are meaningful, and "unlimited"
// needs to be an explicit choice rather than the bottom of a range.
l("GPU", "framerate_limit", "Frame rate limit", "60",
"60" to "60 FPS", "30" to "30 FPS", "40" to "40 FPS", "45" to "45 FPS",
"60" to "60 FPS", "20" to "20 FPS", "30" to "30 FPS", "40" to "40 FPS", "45" to "45 FPS",
"90" to "90 FPS", "120" to "120 FPS", "0" to "Unlimited"),
b("GPU", "guest_display_refresh_cap", "Cap guest display refresh (VSync)", true),
// vulkan_texture_cache: -1 leaves each sampler as the game set it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class FrameGenerationTargetTest {
assertFalse(FrameGenerationTarget.plan(120, 120f, 60)!!.lowBase)
}

@Test fun twentyFpsLimitPlansCleanlyAt60Hz() {
assertEquals(
Plan(60, 3, 20, limitedByDisplay = false, belowTarget = false),
FrameGenerationTarget.plan(60, 60f, 20),
)
assertTrue(FrameGenerationTarget.plan(60, 60f, 20)!!.lowBase)
}

@Test fun offIsTheMultiplier() {
assertNull(FrameGenerationTarget.plan(FrameGenerationTarget.OFF, 120f, 60))
assertNull(FrameGenerationTarget.plan(120, 0f, 60))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.junit.Test
import xendroid.compose.settings.ConfigMigrations.Update

class ConfigMigrationsTest {
private val jitFrameStart = Update(2026111918, "HID", "jit_frame_start", "int", "2", "0")
private val immediate = Update(2026111801, "Vulkan", "vulkan_allow_present_mode_immediate", "bool", "true", "false")
private val mailbox = Update(2026100712, "Vulkan", "vulkan_allow_present_mode_mailbox", "bool", "true", "false")
private val leaf = Update(2026100512, "CPU", "inline_leaf_max_instructions", "int", "16", "32")
Expand Down Expand Up @@ -93,4 +94,15 @@ class ConfigMigrationsTest {
"Config|defaults_date" to "2026111801",
"Vulkan|vulkan_allow_present_mode_immediate" to "true")))
}

@Test fun jitFrameStartDefaultMigrationDisablesOldAutoDefaultOnce() {
val plan = ConfigMigrations.plan(listOf(immediate, jitFrameStart), file(
"Config|defaults_date" to "2026111823",
"HID|jit_frame_start" to "2"))!!
assertEquals(listOf(jitFrameStart), plan.writes)
assertEquals(2026111918L, plan.date)
assertNull(ConfigMigrations.plan(listOf(immediate, jitFrameStart), file(
"Config|defaults_date" to "2026111918",
"HID|jit_frame_start" to "2")))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,18 @@ class SettingsSchemaTest {
.forEach { s -> s.options.forEach { assertEquals("${s.key} ${it.value}", 1, it.value.count { c -> c == '.' }) } }
}

@Test fun framerate_limit_offers_40_fps_for_120hz_displays() {
@Test fun framerate_limit_offers_20_and_40_fps_options() {
val s = SettingsSchema.byKey["GPU|framerate_limit"] as Setting.ListChoice
assertEquals(listOf("60", "30", "40", "45", "90", "120", "0"), s.options.map { it.value })
assertEquals(listOf("60", "20", "30", "40", "45", "90", "120", "0"), s.options.map { it.value })
assertEquals("60", s.default)
assertTrue(s.key in SettingsSchema.playerKeys)
}

@Test fun jit_frame_start_defaults_to_off() {
val s = SettingsSchema.byKey["HID|jit_frame_start"] as Setting.ListChoice
assertEquals("0", s.default)
}

/** vulkan_texture_cache reads -1 (no override) and 0..5 (off, 1x..16x). */
@Test fun anisotropic_override_offers_the_core_values() {
val s = SettingsSchema.byKey["GPU|anisotropic_override"] as Setting.ListChoice
Expand Down
51 changes: 12 additions & 39 deletions emulator-core/src/main/cpp/xe_android_input_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <chrono>
#include <thread>

#include "xe_jit_frame_start.h"
#include "xenia/base/cvar.h"
#include "xenia/base/frame_stats.h"
#include "xenia/base/logging.h"
Expand All @@ -21,13 +22,14 @@
#include "xenia/ui/vulkan/zerofg_config.h"

DEFINE_int32(
jit_frame_start, 2,
jit_frame_start, 0,
"Hold the guest's first controller state poll after each VdSwap so input "
"is sampled just in time before the command processor needs the next frame "
"(-15 to -20 ms input latency at 30 FPS with zero FPS drop). "
"0 = Off, 1 = Conservative (10 ms margin), 2 = Auto (6 ms margin). "
"0 = Off (default), 1 = Conservative (10 ms margin), 2 = Auto (6 ms margin). "
"Automatically bypassed while Frame Generation paces presentation.",
"HID");
UPDATE_from_int32(jit_frame_start, 2026, 11, 19, 18, 2);

namespace xe {
namespace hid {
Expand Down Expand Up @@ -142,43 +144,14 @@ void AndroidInputDriver::HoldForJitFrameStart() {
const uint64_t prev_work_start_ns =
jit_last_work_start_ns_.load(std::memory_order_relaxed);

// Asymmetric slack controller (XDroid360 9b41ad8d2):
// - Instant backoff when slack falls below safety margin (6 ms in auto mode,
// 10 ms in conservative mode) followed by an 8-frame calm hold.
// - Gradual +1/8th slew up to 20 ms max hold when spare slack persists.
const int64_t margin_us = (mode == 1) ? 10000 : 6000;
const int64_t max_hold_us = (mode == 1) ? 12000 : 20000;
int64_t delay_us =
static_cast<int64_t>(jit_delay_us_.load(std::memory_order_relaxed));

if (swap_ns > prev_swap_ns && prev_swap_ns != 0 &&
swap_ns > prev_work_start_ns && prev_work_start_ns != 0) {
const int64_t period_us = static_cast<int64_t>((swap_ns - prev_swap_ns) / 1000);
const int64_t active_work_us =
static_cast<int64_t>((swap_ns - prev_work_start_ns) / 1000);

// Only pace steady 20..90 Hz gameplay cadences; reset immediately across
// loading stalls (>100 ms) or uncapped >120 FPS menus (<8 ms).
if (period_us < 8000 || period_us > 100000) {
delay_us = 0;
jit_calm_frames_.store(8, std::memory_order_relaxed);
} else {
const int64_t remaining_slack_us = period_us - active_work_us - delay_us;
uint32_t calm = jit_calm_frames_.load(std::memory_order_relaxed);
if (remaining_slack_us < margin_us) {
delay_us -= (margin_us - remaining_slack_us);
calm = 8;
} else if (calm > 0) {
--calm;
} else {
delay_us += std::min<int64_t>((remaining_slack_us - margin_us) / 8, 1000);
}
jit_calm_frames_.store(calm, std::memory_order_relaxed);
}
delay_us = std::clamp<int64_t>(delay_us, 0, max_hold_us);
jit_delay_us_.store(static_cast<uint32_t>(delay_us),
std::memory_order_relaxed);
}
uint32_t calm = jit_calm_frames_.load(std::memory_order_relaxed);
int64_t delay_us = ComputeJitFrameStartDelayUs(
mode, swap_ns, prev_swap_ns, prev_work_start_ns,
static_cast<int64_t>(jit_delay_us_.load(std::memory_order_relaxed)),
calm);
jit_calm_frames_.store(calm, std::memory_order_relaxed);
jit_delay_us_.store(static_cast<uint32_t>(delay_us),
std::memory_order_relaxed);

if (delay_us >= 200) {
std::this_thread::sleep_for(std::chrono::microseconds(delay_us));
Expand Down
71 changes: 71 additions & 0 deletions emulator-core/src/main/cpp/xe_jit_frame_start.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#ifndef XENDROID_XE_JIT_FRAME_START_H_
#define XENDROID_XE_JIT_FRAME_START_H_

#include <algorithm>
#include <cstdint>

namespace xe {
namespace hid {
namespace android {

// Computes the next input-poll hold duration (microseconds) for jit_frame_start.
// Mode: 0 = Off, 1 = Conservative (10 ms margin, 12 ms cap), 2 = Auto (6 ms margin, 20 ms cap).
//
// Invariants (fixes #144 regression):
// - Never freezes a previous delay_us when the presenter timestamp (swap_ns) is
// behind or equal to prev_work_start_ns (pipelined frames where guest VdSwap
// ran before the previous frame was presented): resets delay to 0 instead of
// skipping backoff and sleeping up to 20 ms every frame.
// - Never holds on >= 56 FPS cadences (period_us < 18000) or stalls (> 100000 us).
// - Caps max_hold_us to at most (period_us - margin_us) so hold never exceeds
// available frame budget.
inline int64_t ComputeJitFrameStartDelayUs(int32_t mode, uint64_t swap_ns,
uint64_t prev_swap_ns,
uint64_t prev_work_start_ns,
int64_t current_delay_us,
uint32_t& calm_frames) {
if (mode <= 0) {
calm_frames = 0;
return 0;
}
if (prev_swap_ns == 0 || prev_work_start_ns == 0 || swap_ns <= prev_swap_ns ||
swap_ns <= prev_work_start_ns) {
calm_frames = 8;
return 0;
}

const int64_t period_us =
static_cast<int64_t>((swap_ns - prev_swap_ns) / 1000);
const int64_t active_work_us =
static_cast<int64_t>((swap_ns - prev_work_start_ns) / 1000);

// Only pace steady ~10..55 Hz cadences (e.g. 30/40 FPS titles). High-rate
// 60+ FPS games (<18 ms) have no safe hold budget, and >100 ms indicates loads.
if (period_us < 18000 || period_us > 100000) {
calm_frames = 8;
return 0;
}

const int64_t margin_us = (mode == 1) ? 10000 : 6000;
const int64_t mode_max_hold_us = (mode == 1) ? 12000 : 20000;
const int64_t max_hold_us = std::min<int64_t>(
mode_max_hold_us, std::max<int64_t>(0, period_us - margin_us));

int64_t delay_us = std::clamp<int64_t>(current_delay_us, 0, max_hold_us);
const int64_t remaining_slack_us = period_us - active_work_us - delay_us;
if (remaining_slack_us < margin_us) {
delay_us -= (margin_us - remaining_slack_us);
calm_frames = 8;
} else if (calm_frames > 0) {
--calm_frames;
} else {
delay_us += std::min<int64_t>((remaining_slack_us - margin_us) / 8, 1000);
}
return std::clamp<int64_t>(delay_us, 0, max_hold_us);
}

} // namespace android
} // namespace hid
} // namespace xe

#endif // XENDROID_XE_JIT_FRAME_START_H_
11 changes: 5 additions & 6 deletions emulator-core/src/main/cpp/xenia/src/xenia/base/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class IConfigVarUpdate {
// If you're reviewing a pull request with a change here, check if 1) has been
// done by the submitter before merging.
static constexpr uint32_t kLastCommittedUpdateDate =
MakeConfigVarUpdateDate(2026, 11, 18, 23);
MakeConfigVarUpdateDate(2026, 11, 19, 18);

virtual ~IConfigVarUpdate() = default;

Expand Down Expand Up @@ -828,8 +828,8 @@ class ConfigVarUpdate : public IConfigVarUpdate {
"updating config variable defaults."); \
namespace cv { \
static const cvar::ConfigVarUpdateFromAny \
update_##name_##year_##month_##day_##utc_hour(cv_##name, year, month, \
day, utc_hour); \
update_##name##_##year##_##month##_##day##_##utc_hour( \
cv_##name, year, month, day, utc_hour); \
}

#define UPDATE_CVar(name, year, month, day, utc_hour, old_default_value, type) \
Expand All @@ -842,9 +842,8 @@ class ConfigVarUpdate : public IConfigVarUpdate {
"updating config variable defaults."); \
namespace cv { \
static const cvar::ConfigVarUpdate<type> \
update_##name_##year_##month_##day_##utc_hour(cv_##name, year, month, \
day, utc_hour, \
old_default_value); \
update_##name##_##year##_##month##_##day##_##utc_hour( \
cv_##name, year, month, day, utc_hour, old_default_value); \
}

#define UPDATE_from_bool(name, year, month, day, utc_hour, old_default_value) \
Expand Down
4 changes: 4 additions & 0 deletions emulator-core/src/main/cpp/xenia/src/xenia/game_quirks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ static const Quirk kQuirks[] = {
"garbled character select and intro"},
// FIFA 16: stadium shadow mask readback requires fast resolve copy to RAM.
{0x454109EE, "readback_resolve", "fast", "half of the pitch black"},
// FIFA Street (2012): indoor pitch surfaces render with green/black colors
// unless all resolves are copied back to guest RAM (#114).
{0x4541097B, "readback_resolve", "all",
"indoor pitch surface renders with green/black colors without full readback"},
// Naruto: Rise of a Ninja: its worker thread 0x18 starts (8265BB68) by
// calling the routine at +0xEC of its object. When it ran on its
// creator's CPU right after its creation, the object held the thread's id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ Shader::Translation* GuestSpirvShaderCache::TranslateSpirv(
should_translate = translation.TryClaimTranslation();
if (!should_translate) {
// Another thread is translating this same modification - wait for it.
while (!translation.is_translated()) {
std::this_thread::yield();
}
translation.WaitForTranslation();
}
}
if (should_translate && !translator.TranslateAnalyzedShader(translation)) {
Expand Down
13 changes: 13 additions & 0 deletions emulator-core/src/main/cpp/xenia/src/xenia/gpu/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,13 @@ class Shader {
return !translation_claimed_.test_and_set(std::memory_order_acq_rel);
}

// Blocks until the claiming thread publishes the translation result (#123).
void WaitForTranslation() const {
while (!is_translated_.load(std::memory_order_acquire)) {
is_translated_.wait(false, std::memory_order_acquire);
}
}

// Errors that occurred during translation.
const std::vector<Error>& errors() const { return errors_; }

Expand Down Expand Up @@ -872,6 +879,12 @@ class Shader {
friend class Shader;
friend class ShaderTranslator;

void PublishTranslation(bool valid) {
is_valid_.store(valid, std::memory_order_relaxed);
is_translated_.store(true, std::memory_order_release);
is_translated_.notify_all();
}

Shader& shader_;
uint64_t modification_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ bool ShaderTranslator::TranslateAnalyzedShader(
assert_true(shader.is_ucode_analyzed());
if (!shader.is_ucode_analyzed()) {
XELOGE("AnalyzeUcode must be done on the shader before translation");
translation.PublishTranslation(false);
return false;
}
translation_ = &translation;
Expand Down Expand Up @@ -1047,6 +1048,7 @@ bool ShaderTranslator::TranslateAnalyzedShader(
// Publish last: creation threads take is_translated() as the binary, the
// validity and (after PostTranslation) the shader's bindings being complete.
translation.is_translated_.store(true, std::memory_order_release);
translation.is_translated_.notify_all();
return is_valid;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1850,9 +1850,7 @@ bool VulkanPipelineCache::TranslateAnalyzedShader(
if (use_try_claim) {
should_translate = translation.TryClaimTranslation();
if (!should_translate) {
while (!translation.is_translated()) {
xe::threading::MaybeYield();
}
translation.WaitForTranslation();
}
}
if (should_translate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ dword_result_t XAudioGetVoiceCategoryVolumeChangeMask_entry(
lpunknown_t driver_ptr, lpdword_t out_ptr) {
assert_true((driver_ptr.guest_address() & 0xFFFF0000) == 0x41550000);

xe::threading::MaybeYield();

// Checking these bits to see if any voice volume changed.
// I think.
*out_ptr = 0;
Expand Down
Loading
Loading