early-access version 4021

This commit is contained in:
pineappleEA 2023-12-15 06:40:33 +01:00
parent ba87c29152
commit 41343d3db3
30 changed files with 66 additions and 56 deletions

View File

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

View File

@ -11,10 +11,6 @@
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv #elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
#ifdef ANDROID
#include <android/sharedmem.h>
#endif
#ifndef _GNU_SOURCE #ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif #endif
@ -193,6 +189,11 @@ public:
} }
} }
bool ClearBackingRegion(size_t physical_offset, size_t length) {
// TODO: This does not seem to be possible on Windows.
return false;
}
void EnableDirectMappedAddress() { void EnableDirectMappedAddress() {
// TODO // TODO
UNREACHABLE(); UNREACHABLE();
@ -442,9 +443,7 @@ public:
} }
// Backing memory initialization // Backing memory initialization
#ifdef ANDROID #if defined(__FreeBSD__) && __FreeBSD__ < 13
fd = ASharedMemory_create("HostMemory", backing_size);
#elif defined(__FreeBSD__) && __FreeBSD__ < 13
// XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30 // XXX Drop after FreeBSD 12.* reaches EOL on 2024-06-30
fd = shm_open(SHM_ANON, O_RDWR, 0600); fd = shm_open(SHM_ANON, O_RDWR, 0600);
#else #else
@ -455,7 +454,6 @@ public:
throw std::bad_alloc{}; throw std::bad_alloc{};
} }
#ifndef ANDROID
// Defined to extend the file with zeros // Defined to extend the file with zeros
int ret = ftruncate(fd, backing_size); int ret = ftruncate(fd, backing_size);
if (ret != 0) { if (ret != 0) {
@ -463,7 +461,6 @@ public:
strerror(errno)); strerror(errno));
throw std::bad_alloc{}; throw std::bad_alloc{};
} }
#endif
backing_base = static_cast<u8*>( backing_base = static_cast<u8*>(
mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
@ -552,6 +549,19 @@ public:
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno)); ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
} }
bool ClearBackingRegion(size_t physical_offset, size_t length) {
#ifdef __linux__
// Set MADV_REMOVE on backing map to destroy it instantly.
// This also deletes the area from the backing file.
int ret = madvise(backing_base + physical_offset, length, MADV_REMOVE);
ASSERT_MSG(ret == 0, "madvise failed: {}", strerror(errno));
return true;
#else
return false;
#endif
}
void EnableDirectMappedAddress() { void EnableDirectMappedAddress() {
virtual_base = nullptr; virtual_base = nullptr;
} }
@ -623,6 +633,8 @@ public:
void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {} void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {}
void ClearBackingRegion(size_t physical_offset, size_t length) {}
void EnableDirectMappedAddress() {} void EnableDirectMappedAddress() {}
u8* backing_base{nullptr}; u8* backing_base{nullptr};
@ -698,6 +710,12 @@ void HostMemory::Protect(size_t virtual_offset, size_t length, bool read, bool w
impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute); impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute);
} }
void HostMemory::ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value) {
if (!impl || fill_value != 0 || !impl->ClearBackingRegion(physical_offset, length)) {
std::memset(backing_base + physical_offset, fill_value, length);
}
}
void HostMemory::EnableDirectMappedAddress() { void HostMemory::EnableDirectMappedAddress() {
if (impl) { if (impl) {
impl->EnableDirectMappedAddress(); impl->EnableDirectMappedAddress();

View File

@ -48,6 +48,8 @@ public:
void EnableDirectMappedAddress(); void EnableDirectMappedAddress();
void ClearBackingRegion(size_t physical_offset, size_t length, u32 fill_value);
[[nodiscard]] u8* BackingBasePointer() noexcept { [[nodiscard]] u8* BackingBasePointer() noexcept {
return backing_base; return backing_base;
} }

View File

@ -20,6 +20,9 @@ InputInterpreter::InputInterpreter(Core::System& system)
InputInterpreter::~InputInterpreter() = default; InputInterpreter::~InputInterpreter() = default;
void InputInterpreter::PollInput() { void InputInterpreter::PollInput() {
if (npad == nullptr) {
return;
}
const auto button_state = npad->GetAndResetPressState(); const auto button_state = npad->GetAndResetPressState();
previous_index = current_index; previous_index = current_index;

View File

@ -421,8 +421,9 @@ Result KMemoryManager::AllocateForProcess(KPageGroup* out, size_t num_pages, u32
} else { } else {
// Set all the allocated memory. // Set all the allocated memory.
for (const auto& block : *out) { for (const auto& block : *out) {
std::memset(m_system.DeviceMemory().GetPointer<void>(block.GetAddress()), fill_pattern, m_system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(block.GetAddress()) -
block.GetSize()); Core::DramMemoryMap::Base,
block.GetSize(), fill_pattern);
} }
} }

View File

@ -81,6 +81,11 @@ void InvalidateInstructionCache(KernelCore& kernel, AddressType addr, u64 size)
} }
} }
void ClearBackingRegion(Core::System& system, KPhysicalAddress addr, u64 size, u32 fill_value) {
system.DeviceMemory().buffer.ClearBackingRegion(GetInteger(addr) - Core::DramMemoryMap::Base,
size, fill_value);
}
template <typename AddressType> template <typename AddressType>
Result InvalidateDataCache(AddressType addr, u64 size) { Result InvalidateDataCache(AddressType addr, u64 size) {
R_SUCCEED(); R_SUCCEED();
@ -1363,8 +1368,7 @@ Result KPageTableBase::MapInsecureMemory(KProcessAddress address, size_t size) {
// Clear all the newly allocated pages. // Clear all the newly allocated pages.
for (const auto& it : pg) { for (const auto& it : pg) {
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
static_cast<u32>(m_heap_fill_value), it.GetSize());
} }
// Lock the table. // Lock the table.
@ -1570,8 +1574,7 @@ Result KPageTableBase::AllocateAndMapPagesImpl(PageLinkedList* page_list, KProce
// Clear all pages. // Clear all pages.
for (const auto& it : pg) { for (const auto& it : pg) {
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
static_cast<u32>(m_heap_fill_value), it.GetSize());
} }
// Map the pages. // Map the pages.
@ -2159,8 +2162,7 @@ Result KPageTableBase::SetHeapSize(KProcessAddress* out, size_t size) {
// Clear all the newly allocated pages. // Clear all the newly allocated pages.
for (const auto& it : pg) { for (const auto& it : pg) {
std::memset(GetHeapVirtualPointer(m_kernel, it.GetAddress()), m_heap_fill_value, ClearBackingRegion(m_system, it.GetAddress(), it.GetSize(), m_heap_fill_value);
it.GetSize());
} }
// Map the pages. // Map the pages.

View File

@ -1,13 +1,11 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hid/emulated_console.h" #include "core/hid/emulated_console.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/console_six_axis.h" #include "core/hle/service/hid/controllers/console_six_axis.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/shared_memory_format.h"
#include "core/memory.h"
namespace Service::HID { namespace Service::HID {

View File

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include "common/common_types.h"
#include "common/settings.h" #include "common/settings.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hid/emulated_controller.h" #include "core/hid/emulated_controller.h"

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include "common/common_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/types/debug_pad_types.h" #include "core/hle/service/hid/controllers/types/debug_pad_types.h"

View File

@ -1,11 +1,10 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "common/logging/log.h"
#include "common/math_util.h" #include "common/math_util.h"
#include "common/settings.h" #include "common/settings.h"
#include "core/core_timing.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_console.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/service/hid/controllers/gesture.h" #include "core/hle/service/hid/controllers/gesture.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/shared_memory_format.h"

View File

@ -6,10 +6,13 @@
#include <array> #include <array>
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hid/emulated_console.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/types/touch_types.h" #include "core/hle/service/hid/controllers/types/touch_types.h"
namespace Core::HID {
class EmulatedConsole;
}
namespace Service::HID { namespace Service::HID {
struct GestureSharedMemoryFormat; struct GestureSharedMemoryFormat;

View File

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include "common/common_types.h"
#include "common/settings.h" #include "common/settings.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_devices.h"

View File

@ -3,10 +3,8 @@
#pragma once #pragma once
#include "common/common_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/types/keyboard_types.h" #include "core/hle/service/hid/controllers/types/keyboard_types.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Service::HID { namespace Service::HID {
struct KeyboardSharedMemoryFormat; struct KeyboardSharedMemoryFormat;

View File

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include "common/common_types.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_devices.h"

View File

@ -3,9 +3,7 @@
#pragma once #pragma once
#include "common/common_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Core::HID { namespace Core::HID {
class EmulatedDevices; class EmulatedDevices;

View File

@ -8,13 +8,10 @@
#include <mutex> #include <mutex>
#include <span> #include <span>
#include "common/bit_field.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "core/hid/hid_types.h" #include "core/hid/hid_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/types/npad_types.h" #include "core/hle/service/hid/controllers/types/npad_types.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Core::HID { namespace Core::HID {
class EmulatedController; class EmulatedController;
@ -192,7 +189,7 @@ private:
std::atomic<u64> press_state{}; std::atomic<u64> press_state{};
std::array<NpadControllerData, NPAD_COUNT> controller_data{}; std::array<NpadControllerData, NpadCount> controller_data{};
KernelHelpers::ServiceContext& service_context; KernelHelpers::ServiceContext& service_context;
std::mutex mutex; std::mutex mutex;
std::vector<Core::HID::NpadIdType> supported_npad_id_types{}; std::vector<Core::HID::NpadIdType> supported_npad_id_types{};

View File

@ -171,7 +171,7 @@ static_assert(sizeof(NpadSharedMemoryEntry) == 0x5000, "NpadSharedMemoryEntry is
// This is nn::hid::detail::NpadSharedMemoryFormat // This is nn::hid::detail::NpadSharedMemoryFormat
struct NpadSharedMemoryFormat { struct NpadSharedMemoryFormat {
std::array<NpadSharedMemoryEntry, NPAD_COUNT> npad_entry; std::array<NpadSharedMemoryEntry, NpadCount> npad_entry;
}; };
static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000, static_assert(sizeof(NpadSharedMemoryFormat) == 0x32000,
"NpadSharedMemoryFormat is an invalid size"); "NpadSharedMemoryFormat is an invalid size");
@ -198,6 +198,7 @@ struct ConsoleSixAxisSensorSharedMemoryFormat {
static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20, static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20,
"ConsoleSixAxisSensorSharedMemoryFormat is an invalid size"); "ConsoleSixAxisSensorSharedMemoryFormat is an invalid size");
// This is nn::hid::detail::SharedMemoryFormat
struct SharedMemoryFormat { struct SharedMemoryFormat {
void Initialize() {} void Initialize() {}

View File

@ -10,6 +10,10 @@
namespace Service::HID { namespace Service::HID {
SharedMemoryHolder::SharedMemoryHolder() {} SharedMemoryHolder::SharedMemoryHolder() {}
SharedMemoryHolder::~SharedMemoryHolder() {
Finalize();
}
Result SharedMemoryHolder::Initialize(Core::System& system) { Result SharedMemoryHolder::Initialize(Core::System& system) {
shared_memory = Kernel::KSharedMemory::Create(system.Kernel()); shared_memory = Kernel::KSharedMemory::Create(system.Kernel());
const Result result = shared_memory->Initialize( const Result result = shared_memory->Initialize(

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include "common/common_types.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace Core { namespace Core {
@ -21,6 +20,7 @@ struct SharedMemoryFormat;
class SharedMemoryHolder { class SharedMemoryHolder {
public: public:
SharedMemoryHolder(); SharedMemoryHolder();
~SharedMemoryHolder();
Result Initialize(Core::System& system); Result Initialize(Core::System& system);
void Finalize(); void Finalize();

View File

@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <cstring>
#include "common/common_types.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/shared_memory_format.h"
#include "core/hle/service/hid/controllers/stubbed.h" #include "core/hle/service/hid/controllers/stubbed.h"

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include "common/common_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
namespace Service::HID { namespace Service::HID {

View File

@ -2,10 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm> #include <algorithm>
#include <cstring>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/settings.h" #include "common/settings.h"
#include "core/core.h"
#include "core/core_timing.h" #include "core/core_timing.h"
#include "core/frontend/emu_window.h" #include "core/frontend/emu_window.h"
#include "core/hid/emulated_console.h" #include "core/hid/emulated_console.h"

View File

@ -5,11 +5,9 @@
#include <array> #include <array>
#include "common/common_types.h"
#include "core/hid/hid_types.h" #include "core/hid/hid_types.h"
#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/controller_base.h"
#include "core/hle/service/hid/controllers/types/touch_types.h" #include "core/hle/service/hid/controllers/types/touch_types.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Core::HID { namespace Core::HID {
class EmulatedConsole; class EmulatedConsole;

View File

@ -3,10 +3,6 @@
#pragma once #pragma once
#include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/vector_math.h"
#include "core/hid/hid_types.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Service::HID {} // namespace Service::HID namespace Service::HID {} // namespace Service::HID

View File

@ -3,14 +3,13 @@
#pragma once #pragma once
#include "common/bit_field.h"
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/vector_math.h"
#include "core/hid/hid_types.h" #include "core/hid/hid_types.h"
#include "core/hle/service/hid/ring_lifo.h"
namespace Service::HID { namespace Service::HID {
static constexpr std::size_t NPAD_COUNT = 10; static constexpr std::size_t NpadCount = 10;
// This is nn::hid::NpadJoyHoldType // This is nn::hid::NpadJoyHoldType
enum class NpadJoyHoldType : u64 { enum class NpadJoyHoldType : u64 {

View File

@ -231,6 +231,7 @@ void ResourceManager::UpdateControllers(std::uintptr_t user_data,
std::chrono::nanoseconds ns_late) { std::chrono::nanoseconds ns_late) {
auto& core_timing = system.CoreTiming(); auto& core_timing = system.CoreTiming();
debug_pad->OnUpdate(core_timing); debug_pad->OnUpdate(core_timing);
digitizer->OnUpdate(core_timing);
unique_pad->OnUpdate(core_timing); unique_pad->OnUpdate(core_timing);
gesture->OnUpdate(core_timing); gesture->OnUpdate(core_timing);
touch_screen->OnUpdate(core_timing); touch_screen->OnUpdate(core_timing);

View File

@ -62,7 +62,7 @@ u64 StandardVmCallbacks::HidKeysDown() {
} }
const auto applet_resource = hid->GetResourceManager(); const auto applet_resource = hid->GetResourceManager();
if (applet_resource == nullptr) { if (applet_resource == nullptr || applet_resource->GetNpad() == nullptr) {
LOG_WARNING(CheatEngine, LOG_WARNING(CheatEngine,
"Attempted to read input state, but applet resource is not initialized!"); "Attempted to read input state, but applet resource is not initialized!");
return 0; return 0;

View File

@ -29,6 +29,8 @@ RasterizerAccelerated::RasterizerAccelerated(Memory& cpu_memory_) : map{}, cpu_m
RasterizerAccelerated::~RasterizerAccelerated() = default; RasterizerAccelerated::~RasterizerAccelerated() = default;
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) { void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, bool cache) {
std::scoped_lock lk{map_lock};
// Align sizes. // Align sizes.
addr = Common::AlignDown(addr, YUZU_PAGESIZE); addr = Common::AlignDown(addr, YUZU_PAGESIZE);
size = Common::AlignUp(size, YUZU_PAGESIZE); size = Common::AlignUp(size, YUZU_PAGESIZE);

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <mutex>
#include <boost/icl/interval_map.hpp> #include <boost/icl/interval_map.hpp>
#include "common/common_types.h" #include "common/common_types.h"
@ -30,6 +31,7 @@ private:
using IntervalType = IntervalMap::interval_type; using IntervalType = IntervalMap::interval_type;
IntervalMap map; IntervalMap map;
std::mutex map_lock;
Core::Memory::Memory& cpu_memory; Core::Memory::Memory& cpu_memory;
}; };

View File

@ -289,7 +289,7 @@ void PresentManager::PresentThread(std::stop_token token) {
void PresentManager::RecreateSwapchain(Frame* frame) { void PresentManager::RecreateSwapchain(Frame* frame) {
swapchain.Create(*surface, frame->width, frame->height); swapchain.Create(*surface, frame->width, frame->height);
image_count = swapchain.GetImageCount(); SetImageCount();
} }
void PresentManager::SetImageCount() { void PresentManager::SetImageCount() {