early-access version 3440

main
pineappleEA 2023-03-08 04:41:37 +01:00
parent 294b1b8c34
commit fcd34e75d7
23 changed files with 159 additions and 67 deletions

View File

@ -1,7 +1,7 @@
yuzu emulator early access
=============
This is the source code for early-access 3439.
This is the source code for early-access 3440.
## Legal Notice

View File

@ -135,7 +135,7 @@ void AudioRenderer::ThreadFunc() {
static constexpr char name[]{"AudioRenderer"};
MicroProfileOnThreadCreate(name);
Common::SetCurrentThreadName(name);
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
if (mailbox->ADSPWaitMessage() != RenderMessage::AudioRenderer_InitializeOK) {
LOG_ERROR(Service_Audio,
"ADSP Audio Renderer -- Failed to receive initialize message from host!");

View File

@ -46,7 +46,7 @@ enum class PollingMode {
// Constant polling of buttons, analogs and motion data
Active,
// Only update on button change, digital analogs
Pasive,
Passive,
// Enable near field communication polling
NFC,
// Enable infrared camera polling

View File

@ -23,6 +23,19 @@ static s64 WindowsQueryPerformanceCounter() {
QueryPerformanceCounter(&counter);
return counter.QuadPart;
}
static s64 GetSystemTimeNS() {
// GetSystemTimePreciseAsFileTime returns the file time in 100ns units.
static constexpr s64 Multiplier = 100;
// Convert Windows epoch to Unix epoch.
static constexpr s64 WindowsEpochToUnixEpochNS = 0x19DB1DED53E8000LL;
FILETIME filetime;
GetSystemTimePreciseAsFileTime(&filetime);
return Multiplier * ((static_cast<s64>(filetime.dwHighDateTime) << 32) +
static_cast<s64>(filetime.dwLowDateTime)) -
WindowsEpochToUnixEpochNS;
}
#endif
SteadyClock::time_point SteadyClock::Now() noexcept {
@ -53,4 +66,16 @@ SteadyClock::time_point SteadyClock::Now() noexcept {
#endif
}
RealTimeClock::time_point RealTimeClock::Now() noexcept {
#if defined(_WIN32)
return time_point{duration{GetSystemTimeNS()}};
#elif defined(__APPLE__)
return time_point{duration{clock_gettime_nsec_np(CLOCK_REALTIME)}};
#else
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return time_point{std::chrono::seconds{ts.tv_sec} + std::chrono::nanoseconds{ts.tv_nsec}};
#endif
}
}; // namespace Common

View File

@ -20,4 +20,15 @@ struct SteadyClock {
[[nodiscard]] static time_point Now() noexcept;
};
struct RealTimeClock {
using rep = s64;
using period = std::nano;
using duration = std::chrono::nanoseconds;
using time_point = std::chrono::time_point<RealTimeClock>;
static constexpr bool is_steady = false;
[[nodiscard]] static time_point Now() noexcept;
};
} // namespace Common

View File

@ -53,11 +53,11 @@ u64 EstimateRDTSCFrequency() {
FencedRDTSC();
// Get the current time.
const auto start_time = Common::SteadyClock::Now();
const auto start_time = Common::RealTimeClock::Now();
const u64 tsc_start = FencedRDTSC();
// Wait for 250 milliseconds.
std::this_thread::sleep_for(std::chrono::milliseconds{250});
const auto end_time = Common::SteadyClock::Now();
const auto end_time = Common::RealTimeClock::Now();
const u64 tsc_end = FencedRDTSC();
// Calculate differences.
const u64 timer_diff = static_cast<u64>(
@ -72,13 +72,29 @@ NativeClock::NativeClock(u64 emulated_cpu_frequency_, u64 emulated_clock_frequen
u64 rtsc_frequency_)
: WallClock(emulated_cpu_frequency_, emulated_clock_frequency_, true), rtsc_frequency{
rtsc_frequency_} {
// Thread to re-adjust the RDTSC frequency after 10 seconds has elapsed.
time_sync_thread = std::jthread{[this](std::stop_token token) {
// Get the current time.
const auto start_time = Common::RealTimeClock::Now();
const u64 tsc_start = FencedRDTSC();
// Wait for 10 seconds.
if (!Common::StoppableTimedWait(token, std::chrono::seconds{10})) {
return;
}
const auto end_time = Common::RealTimeClock::Now();
const u64 tsc_end = FencedRDTSC();
// Calculate differences.
const u64 timer_diff = static_cast<u64>(
std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
const u64 tsc_diff = tsc_end - tsc_start;
const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff);
rtsc_frequency = tsc_freq;
CalculateAndSetFactors();
}};
time_point.inner.last_measure = FencedRDTSC();
time_point.inner.accumulated_ticks = 0U;
ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
ms_rtsc_factor = GetFixedPoint64Factor(MS_RATIO, rtsc_frequency);
clock_rtsc_factor = GetFixedPoint64Factor(emulated_clock_frequency, rtsc_frequency);
cpu_rtsc_factor = GetFixedPoint64Factor(emulated_cpu_frequency, rtsc_frequency);
CalculateAndSetFactors();
}
u64 NativeClock::GetRTSC() {
@ -138,6 +154,14 @@ u64 NativeClock::GetCPUCycles() {
return MultiplyHigh(rtsc_value, cpu_rtsc_factor);
}
void NativeClock::CalculateAndSetFactors() {
ns_rtsc_factor = GetFixedPoint64Factor(NS_RATIO, rtsc_frequency);
us_rtsc_factor = GetFixedPoint64Factor(US_RATIO, rtsc_frequency);
ms_rtsc_factor = GetFixedPoint64Factor(MS_RATIO, rtsc_frequency);
clock_rtsc_factor = GetFixedPoint64Factor(emulated_clock_frequency, rtsc_frequency);
cpu_rtsc_factor = GetFixedPoint64Factor(emulated_cpu_frequency, rtsc_frequency);
}
} // namespace X64
} // namespace Common

View File

@ -3,6 +3,7 @@
#pragma once
#include "common/polyfill_thread.h"
#include "common/wall_clock.h"
namespace Common {
@ -28,6 +29,8 @@ public:
private:
u64 GetRTSC();
void CalculateAndSetFactors();
union alignas(16) TimePoint {
TimePoint() : pack{} {}
u128 pack{};
@ -47,6 +50,8 @@ private:
u64 ms_rtsc_factor{};
u64 rtsc_frequency;
std::jthread time_sync_thread;
};
} // namespace X64

View File

@ -53,7 +53,7 @@ void CoreTiming::ThreadEntry(CoreTiming& instance) {
static constexpr char name[] = "HostTiming";
MicroProfileOnThreadCreate(name);
Common::SetCurrentThreadName(name);
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
instance.on_thread_init();
instance.ThreadLoop();
MicroProfileOnThreadExit();

View File

@ -192,7 +192,7 @@ void CpuManager::RunThread(std::stop_token token, std::size_t core) {
}
MicroProfileOnThreadCreate(name.c_str());
Common::SetCurrentThreadName(name.c_str());
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
auto& data = core_data[core];
data.host_context = Common::Fiber::ThreadToFiber();

View File

@ -49,6 +49,7 @@ static void ResetThreadContext32(Core::ARM_Interface::ThreadContext32& context,
context.cpu_registers[0] = arg;
context.cpu_registers[15] = entry_point;
context.cpu_registers[13] = stack_top;
context.fpscr = 0;
}
static void ResetThreadContext64(Core::ARM_Interface::ThreadContext64& context, VAddr stack_top,
@ -58,8 +59,8 @@ static void ResetThreadContext64(Core::ARM_Interface::ThreadContext64& context,
context.cpu_registers[18] = Kernel::KSystemControl::GenerateRandomU64() | 1;
context.pc = entry_point;
context.sp = stack_top;
// TODO(merry): Perform a hardware test to determine the below value.
context.fpcr = 0;
context.fpsr = 0;
}
} // namespace
@ -815,6 +816,27 @@ void KThread::Continue() {
KScheduler::OnThreadStateChanged(kernel, this, old_state);
}
void KThread::CloneFpuStatus() {
// We shouldn't reach here when starting kernel threads.
ASSERT(this->GetOwnerProcess() != nullptr);
ASSERT(this->GetOwnerProcess() == GetCurrentProcessPointer(kernel));
if (this->GetOwnerProcess()->Is64BitProcess()) {
// Clone FPSR and FPCR.
ThreadContext64 cur_ctx{};
kernel.System().CurrentArmInterface().SaveContext(cur_ctx);
this->GetContext64().fpcr = cur_ctx.fpcr;
this->GetContext64().fpsr = cur_ctx.fpsr;
} else {
// Clone FPSCR.
ThreadContext32 cur_ctx{};
kernel.System().CurrentArmInterface().SaveContext(cur_ctx);
this->GetContext32().fpscr = cur_ctx.fpscr;
}
}
Result KThread::SetActivity(Svc::ThreadActivity activity) {
// Lock ourselves.
KScopedLightLock lk(activity_pause_lock);

View File

@ -254,6 +254,8 @@ public:
thread_context_32.tpidr = static_cast<u32>(value);
}
void CloneFpuStatus();
[[nodiscard]] ThreadContext32& GetContext32() {
return thread_context_32;
}

View File

@ -82,6 +82,9 @@ Result CreateThread(Core::System& system, Handle* out_handle, VAddr entry_point,
// Commit the thread reservation.
thread_reservation.Commit();
// Clone the current fpu status to the new thread.
thread->CloneFpuStatus();
// Register the new thread.
KThread::Register(kernel, thread);

View File

@ -26,7 +26,7 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
}
CommonHeader header{};
header.timestamp = core_timing.GetCPUTicks();
header.timestamp = core_timing.GetGlobalTimeNs().count();
header.total_entry_count = 17;
header.entry_count = 0;
header.last_entry_index = 0;

View File

@ -32,7 +32,7 @@ void Controller_Touchscreen::OnInit() {}
void Controller_Touchscreen::OnRelease() {}
void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
shared_memory->touch_screen_lifo.timestamp = core_timing.GetCPUTicks();
shared_memory->touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
if (!IsControllerActivated()) {
shared_memory->touch_screen_lifo.buffer_count = 0;
@ -85,7 +85,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
const auto active_fingers_count =
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
const u64 tick = core_timing.GetCPUTicks();
const u64 timestamp = static_cast<u64>(core_timing.GetGlobalTimeNs().count());
const auto& last_entry = shared_memory->touch_screen_lifo.ReadCurrentEntry().state;
next_state.sampling_number = last_entry.sampling_number + 1;
@ -102,8 +102,8 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
touch_entry.diameter_x = Settings::values.touchscreen.diameter_x;
touch_entry.diameter_y = Settings::values.touchscreen.diameter_y;
touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle;
touch_entry.delta_time = tick - active_fingers[id].last_touch;
fingers[active_fingers[id].id].last_touch = tick;
touch_entry.delta_time = timestamp - active_fingers[id].last_touch;
fingers[active_fingers[id].id].last_touch = timestamp;
touch_entry.finger = active_fingers[id].id;
touch_entry.attribute.raw = active_fingers[id].attribute.raw;
} else {

View File

@ -307,8 +307,8 @@ Common::Input::DriverResult Joycons::SetPollingMode(const PadIdentifier& identif
switch (polling_mode) {
case Common::Input::PollingMode::Active:
return static_cast<Common::Input::DriverResult>(handle->SetActiveMode());
case Common::Input::PollingMode::Pasive:
return static_cast<Common::Input::DriverResult>(handle->SetPasiveMode());
case Common::Input::PollingMode::Passive:
return static_cast<Common::Input::DriverResult>(handle->SetPassiveMode());
case Common::Input::PollingMode::IR:
return static_cast<Common::Input::DriverResult>(handle->SetIrMode());
case Common::Input::PollingMode::NFC:

View File

@ -14,7 +14,7 @@ namespace InputCommon {
constexpr int update_time = 10;
constexpr float default_stick_sensitivity = 0.0044f;
constexpr float default_motion_sensitivity = 0.0003f;
constexpr float maximum_rotation_speed = 1.0f;
constexpr float maximum_rotation_speed = 2.0f;
constexpr int mouse_axis_x = 0;
constexpr int mouse_axis_y = 1;
constexpr int wheel_axis_x = 2;

View File

@ -60,6 +60,6 @@ private:
std::string file_path{};
State state{State::Initialized};
std::vector<u8> nfc_data;
Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Pasive};
Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Passive};
};
} // namespace InputCommon

View File

@ -410,7 +410,7 @@ DriverResult JoyconDriver::SetIrsConfig(IrsMode mode_, IrsResolution format_) {
return result;
}
DriverResult JoyconDriver::SetPasiveMode() {
DriverResult JoyconDriver::SetPassiveMode() {
std::scoped_lock lock{mutex};
motion_enabled = false;
hidbus_enabled = false;

View File

@ -44,7 +44,7 @@ public:
DriverResult SetVibration(const VibrationValue& vibration);
DriverResult SetLedConfig(u8 led_pattern);
DriverResult SetIrsConfig(IrsMode mode_, IrsResolution format_);
DriverResult SetPasiveMode();
DriverResult SetPassiveMode();
DriverResult SetActiveMode();
DriverResult SetIrMode();
DriverResult SetNfcMode();

View File

@ -78,7 +78,7 @@ enum class PadButton : u32 {
Capture = 0x200000,
};
enum class PasivePadButton : u32 {
enum class PassivePadButton : u32 {
Down_A = 0x0001,
Right_X = 0x0002,
Left_B = 0x0004,
@ -95,7 +95,7 @@ enum class PasivePadButton : u32 {
ZL_ZR = 0x8000,
};
enum class PasivePadStick : u8 {
enum class PassivePadStick : u8 {
Right = 0x00,
RightDown = 0x01,
Down = 0x02,

View File

@ -48,13 +48,13 @@ void JoyconPoller::ReadPassiveMode(std::span<u8> buffer) {
switch (device_type) {
case ControllerType::Left:
UpdatePasiveLeftPadInput(data);
UpdatePassiveLeftPadInput(data);
break;
case ControllerType::Right:
UpdatePasiveRightPadInput(data);
UpdatePassiveRightPadInput(data);
break;
case ControllerType::Pro:
UpdatePasiveProPadInput(data);
UpdatePassiveProPadInput(data);
break;
default:
break;
@ -210,12 +210,12 @@ void JoyconPoller::UpdateActiveProPadInput(const InputReportActive& input,
}
}
void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
static constexpr std::array<PasivePadButton, 11> left_buttons{
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
PasivePadButton::Capture, PasivePadButton::StickL,
void JoyconPoller::UpdatePassiveLeftPadInput(const InputReportPassive& input) {
static constexpr std::array<PassivePadButton, 11> left_buttons{
PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Minus,
PassivePadButton::Capture, PassivePadButton::StickL,
};
for (auto left_button : left_buttons) {
@ -225,17 +225,17 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
}
const auto [left_axis_x, left_axis_y] =
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state));
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
}
void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
static constexpr std::array<PasivePadButton, 11> right_buttons{
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Plus,
PasivePadButton::Home, PasivePadButton::StickR,
void JoyconPoller::UpdatePassiveRightPadInput(const InputReportPassive& input) {
static constexpr std::array<PassivePadButton, 11> right_buttons{
PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Plus,
PassivePadButton::Home, PassivePadButton::StickR,
};
for (auto right_button : right_buttons) {
@ -245,18 +245,18 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
}
const auto [right_axis_x, right_axis_y] =
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state));
GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state));
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickY), right_axis_y);
}
void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
static constexpr std::array<PasivePadButton, 14> pro_buttons{
PasivePadButton::Down_A, PasivePadButton::Right_X, PasivePadButton::Left_B,
PasivePadButton::Up_Y, PasivePadButton::SL, PasivePadButton::SR,
PasivePadButton::L_R, PasivePadButton::ZL_ZR, PasivePadButton::Minus,
PasivePadButton::Plus, PasivePadButton::Capture, PasivePadButton::Home,
PasivePadButton::StickL, PasivePadButton::StickR,
void JoyconPoller::UpdatePassiveProPadInput(const InputReportPassive& input) {
static constexpr std::array<PassivePadButton, 14> pro_buttons{
PassivePadButton::Down_A, PassivePadButton::Right_X, PassivePadButton::Left_B,
PassivePadButton::Up_Y, PassivePadButton::SL, PassivePadButton::SR,
PassivePadButton::L_R, PassivePadButton::ZL_ZR, PassivePadButton::Minus,
PassivePadButton::Plus, PassivePadButton::Capture, PassivePadButton::Home,
PassivePadButton::StickL, PassivePadButton::StickR,
};
for (auto pro_button : pro_buttons) {
@ -266,9 +266,9 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
}
const auto [left_axis_x, left_axis_y] =
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state && 0xf));
GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state & 0xf));
const auto [right_axis_x, right_axis_y] =
GetPassiveAxisValue(static_cast<PasivePadStick>(input.stick_state >> 4));
GetPassiveAxisValue(static_cast<PassivePadStick>(input.stick_state >> 4));
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickX), left_axis_x);
callbacks.on_stick_data(static_cast<int>(PadAxes::LeftStickY), left_axis_y);
callbacks.on_stick_data(static_cast<int>(PadAxes::RightStickX), right_axis_x);
@ -283,25 +283,25 @@ f32 JoyconPoller::GetAxisValue(u16 raw_value, Joycon::JoyStickAxisCalibration ca
return value / calibration.min;
}
std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PasivePadStick raw_value) const {
std::pair<f32, f32> JoyconPoller::GetPassiveAxisValue(PassivePadStick raw_value) const {
switch (raw_value) {
case PasivePadStick::Right:
case PassivePadStick::Right:
return {1.0f, 0.0f};
case PasivePadStick::RightDown:
case PassivePadStick::RightDown:
return {1.0f, -1.0f};
case PasivePadStick::Down:
case PassivePadStick::Down:
return {0.0f, -1.0f};
case PasivePadStick::DownLeft:
case PassivePadStick::DownLeft:
return {-1.0f, -1.0f};
case PasivePadStick::Left:
case PassivePadStick::Left:
return {-1.0f, 0.0f};
case PasivePadStick::LeftUp:
case PassivePadStick::LeftUp:
return {-1.0f, 1.0f};
case PasivePadStick::Up:
case PassivePadStick::Up:
return {0.0f, 1.0f};
case PasivePadStick::UpRight:
case PassivePadStick::UpRight:
return {1.0f, 1.0f};
case PasivePadStick::Neutral:
case PassivePadStick::Neutral:
default:
return {0.0f, 0.0f};
}

View File

@ -46,15 +46,15 @@ private:
const MotionStatus& motion_status);
void UpdateActiveProPadInput(const InputReportActive& input, const MotionStatus& motion_status);
void UpdatePasiveLeftPadInput(const InputReportPassive& buffer);
void UpdatePasiveRightPadInput(const InputReportPassive& buffer);
void UpdatePasiveProPadInput(const InputReportPassive& buffer);
void UpdatePassiveLeftPadInput(const InputReportPassive& buffer);
void UpdatePassiveRightPadInput(const InputReportPassive& buffer);
void UpdatePassiveProPadInput(const InputReportPassive& buffer);
/// Returns a calibrated joystick axis from raw axis data
f32 GetAxisValue(u16 raw_value, JoyStickAxisCalibration calibration) const;
/// Returns a digital joystick axis from passive axis data
std::pair<f32, f32> GetPassiveAxisValue(PasivePadStick raw_value) const;
std::pair<f32, f32> GetPassiveAxisValue(PassivePadStick raw_value) const;
/// Returns a calibrated accelerometer axis from raw motion data
f32 GetAccelerometerValue(s16 raw, const MotionSensorCalibration& cal,

View File

@ -25,7 +25,7 @@ static void RunThread(std::stop_token stop_token, Core::System& system,
SCOPE_EXIT({ MicroProfileOnThreadExit(); });
Common::SetCurrentThreadName(name.c_str());
Common::SetCurrentThreadPriority(Common::ThreadPriority::High);
Common::SetCurrentThreadPriority(Common::ThreadPriority::Critical);
system.RegisterHostThread();
auto current_context = context.Acquire();