summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt19
-rw-r--r--src/common/free_region_manager.h55
-rw-r--r--src/common/host_memory.cpp219
-rw-r--r--src/common/host_memory.h15
-rw-r--r--src/common/linux/gamemode.cpp40
-rw-r--r--src/common/linux/gamemode.h24
-rw-r--r--src/common/settings.cpp23
-rw-r--r--src/common/settings.h58
-rw-r--r--src/common/settings_common.h1
-rw-r--r--src/common/settings_enums.h2
-rw-r--r--src/common/signal_chain.cpp42
-rw-r--r--src/common/signal_chain.h19
-rw-r--r--src/common/wall_clock.cpp4
13 files changed, 454 insertions, 67 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index e216eb3de..b58a7073f 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -52,6 +52,7 @@ add_library(common STATIC
fiber.cpp
fiber.h
fixed_point.h
+ free_region_manager.h
fs/file.cpp
fs/file.h
fs/fs.cpp
@@ -166,6 +167,13 @@ if (WIN32)
target_link_libraries(common PRIVATE ntdll)
endif()
+if (NOT WIN32)
+ target_sources(common PRIVATE
+ signal_chain.cpp
+ signal_chain.h
+ )
+endif()
+
if(ANDROID)
target_sources(common
PRIVATE
@@ -174,6 +182,15 @@ if(ANDROID)
)
endif()
+if (UNIX AND NOT APPLE)
+ target_sources(common PRIVATE
+ linux/gamemode.cpp
+ linux/gamemode.h
+ )
+
+ target_link_libraries(common PRIVATE gamemode::headers)
+endif()
+
if(ARCHITECTURE_x86_64)
target_sources(common
PRIVATE
@@ -191,7 +208,7 @@ if(ARCHITECTURE_x86_64)
target_link_libraries(common PRIVATE xbyak::xbyak)
endif()
-if (ARCHITECTURE_arm64 AND (ANDROID OR LINUX))
+if (HAS_NCE)
target_sources(common
PRIVATE
arm64/native_clock.cpp
diff --git a/src/common/free_region_manager.h b/src/common/free_region_manager.h
new file mode 100644
index 000000000..2e590d609
--- /dev/null
+++ b/src/common/free_region_manager.h
@@ -0,0 +1,55 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <mutex>
+#include <boost/icl/interval_set.hpp>
+
+namespace Common {
+
+class FreeRegionManager {
+public:
+ explicit FreeRegionManager() = default;
+ ~FreeRegionManager() = default;
+
+ void SetAddressSpace(void* start, size_t size) {
+ this->FreeBlock(start, size);
+ }
+
+ std::pair<void*, size_t> FreeBlock(void* block_ptr, size_t size) {
+ std::scoped_lock lk(m_mutex);
+
+ // Check to see if we are adjacent to any regions.
+ auto start_address = reinterpret_cast<uintptr_t>(block_ptr);
+ auto end_address = start_address + size;
+ auto it = m_free_regions.find({start_address - 1, end_address + 1});
+
+ // If we are, join with them, ensuring we stay in bounds.
+ if (it != m_free_regions.end()) {
+ start_address = std::min(start_address, it->lower());
+ end_address = std::max(end_address, it->upper());
+ }
+
+ // Free the relevant region.
+ m_free_regions.insert({start_address, end_address});
+
+ // Return the adjusted pointers.
+ block_ptr = reinterpret_cast<void*>(start_address);
+ size = end_address - start_address;
+ return {block_ptr, size};
+ }
+
+ void AllocateBlock(void* block_ptr, size_t size) {
+ std::scoped_lock lk(m_mutex);
+
+ auto address = reinterpret_cast<uintptr_t>(block_ptr);
+ m_free_regions.subtract({address, address + size});
+ }
+
+private:
+ std::mutex m_mutex;
+ boost::icl::interval_set<uintptr_t> m_free_regions;
+};
+
+} // namespace Common
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index ba22595e0..4bfc64f2d 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -21,15 +21,22 @@
#include <boost/icl/interval_set.hpp>
#include <fcntl.h>
#include <sys/mman.h>
+#include <sys/random.h>
#include <unistd.h>
#include "common/scope_exit.h"
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0
+#endif
+
#endif // ^^^ Linux ^^^
#include <mutex>
+#include <random>
#include "common/alignment.h"
#include "common/assert.h"
+#include "common/free_region_manager.h"
#include "common/host_memory.h"
#include "common/logging/log.h"
@@ -141,7 +148,7 @@ public:
Release();
}
- void Map(size_t virtual_offset, size_t host_offset, size_t length) {
+ void Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms) {
std::unique_lock lock{placeholder_mutex};
if (!IsNiechePlaceholder(virtual_offset, length)) {
Split(virtual_offset, length);
@@ -160,7 +167,7 @@ public:
}
}
- void Protect(size_t virtual_offset, size_t length, bool read, bool write) {
+ void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {
DWORD new_flags{};
if (read && write) {
new_flags = PAGE_READWRITE;
@@ -186,6 +193,11 @@ public:
}
}
+ void EnableDirectMappedAddress() {
+ // TODO
+ UNREACHABLE();
+ }
+
const size_t backing_size; ///< Size of the backing memory in bytes
const size_t virtual_size; ///< Size of the virtual address placeholder in bytes
@@ -353,6 +365,65 @@ private:
#elif defined(__linux__) || defined(__FreeBSD__) // ^^^ Windows ^^^ vvv Linux vvv
+#ifdef ARCHITECTURE_arm64
+
+static void* ChooseVirtualBase(size_t virtual_size) {
+ constexpr uintptr_t Map39BitSize = (1ULL << 39);
+ constexpr uintptr_t Map36BitSize = (1ULL << 36);
+
+ // This is not a cryptographic application, we just want something random.
+ std::mt19937_64 rng;
+
+ // We want to ensure we are allocating at an address aligned to the L2 block size.
+ // For Qualcomm devices, we must also allocate memory above 36 bits.
+ const size_t lower = Map36BitSize / HugePageSize;
+ const size_t upper = (Map39BitSize - virtual_size) / HugePageSize;
+ const size_t range = upper - lower;
+
+ // Try up to 64 times to allocate memory at random addresses in the range.
+ for (int i = 0; i < 64; i++) {
+ // Calculate a possible location.
+ uintptr_t hint_address = ((rng() % range) + lower) * HugePageSize;
+
+ // Try to map.
+ // Note: we may be able to take advantage of MAP_FIXED_NOREPLACE here.
+ void* map_pointer =
+ mmap(reinterpret_cast<void*>(hint_address), virtual_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
+
+ // If we successfully mapped, we're done.
+ if (reinterpret_cast<uintptr_t>(map_pointer) == hint_address) {
+ return map_pointer;
+ }
+
+ // Unmap if necessary, and try again.
+ if (map_pointer != MAP_FAILED) {
+ munmap(map_pointer, virtual_size);
+ }
+ }
+
+ return MAP_FAILED;
+}
+
+#else
+
+static void* ChooseVirtualBase(size_t virtual_size) {
+#if defined(__FreeBSD__)
+ void* virtual_base =
+ mmap(nullptr, virtual_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_ALIGNED_SUPER, -1, 0);
+
+ if (virtual_base != MAP_FAILED) {
+ return virtual_base;
+ }
+#endif
+
+ return mmap(nullptr, virtual_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
+}
+
+#endif
+
class HostMemory::Impl {
public:
explicit Impl(size_t backing_size_, size_t virtual_size_)
@@ -402,29 +473,16 @@ public:
}
// Virtual memory initialization
-#if defined(__FreeBSD__)
- virtual_base =
- static_cast<u8*>(mmap(nullptr, virtual_size, PROT_NONE,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER, -1, 0));
- if (virtual_base == MAP_FAILED) {
- virtual_base = static_cast<u8*>(
- mmap(nullptr, virtual_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0));
- if (virtual_base == MAP_FAILED) {
- LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno));
- throw std::bad_alloc{};
- }
- }
-#else
- virtual_base = static_cast<u8*>(mmap(nullptr, virtual_size, PROT_NONE,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0));
+ virtual_base = virtual_map_base = static_cast<u8*>(ChooseVirtualBase(virtual_size));
if (virtual_base == MAP_FAILED) {
LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno));
throw std::bad_alloc{};
}
+#if defined(__linux__)
madvise(virtual_base, virtual_size, MADV_HUGEPAGE);
#endif
- placeholders.add({0, virtual_size});
+ free_manager.SetAddressSpace(virtual_base, virtual_size);
good = true;
}
@@ -432,14 +490,29 @@ public:
Release();
}
- void Map(size_t virtual_offset, size_t host_offset, size_t length) {
- {
- std::scoped_lock lock{placeholder_mutex};
- placeholders.subtract({virtual_offset, virtual_offset + length});
+ void Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms) {
+ // Intersect the range with our address space.
+ AdjustMap(&virtual_offset, &length);
+
+ // We are removing a placeholder.
+ free_manager.AllocateBlock(virtual_base + virtual_offset, length);
+
+ // Deduce mapping protection flags.
+ int flags = PROT_NONE;
+ if (True(perms & MemoryPermission::Read)) {
+ flags |= PROT_READ;
+ }
+ if (True(perms & MemoryPermission::Write)) {
+ flags |= PROT_WRITE;
+ }
+#ifdef ARCHITECTURE_arm64
+ if (True(perms & MemoryPermission::Execute)) {
+ flags |= PROT_EXEC;
}
+#endif
- void* ret = mmap(virtual_base + virtual_offset, length, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_FIXED, fd, host_offset);
+ void* ret = mmap(virtual_base + virtual_offset, length, flags, MAP_SHARED | MAP_FIXED, fd,
+ host_offset);
ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno));
}
@@ -447,47 +520,54 @@ public:
// The method name is wrong. We're still talking about the virtual range.
// We don't want to unmap, we want to reserve this memory.
- {
- std::scoped_lock lock{placeholder_mutex};
- auto it = placeholders.find({virtual_offset - 1, virtual_offset + length + 1});
-
- if (it != placeholders.end()) {
- size_t prev_upper = virtual_offset + length;
- virtual_offset = std::min(virtual_offset, it->lower());
- length = std::max(it->upper(), prev_upper) - virtual_offset;
- }
+ // Intersect the range with our address space.
+ AdjustMap(&virtual_offset, &length);
- placeholders.add({virtual_offset, virtual_offset + length});
- }
+ // Merge with any adjacent placeholder mappings.
+ auto [merged_pointer, merged_size] =
+ free_manager.FreeBlock(virtual_base + virtual_offset, length);
- void* ret = mmap(virtual_base + virtual_offset, length, PROT_NONE,
+ void* ret = mmap(merged_pointer, merged_size, PROT_NONE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
ASSERT_MSG(ret != MAP_FAILED, "mmap failed: {}", strerror(errno));
}
- void Protect(size_t virtual_offset, size_t length, bool read, bool write) {
- int flags = 0;
+ void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {
+ // Intersect the range with our address space.
+ AdjustMap(&virtual_offset, &length);
+
+ int flags = PROT_NONE;
if (read) {
flags |= PROT_READ;
}
if (write) {
flags |= PROT_WRITE;
}
+#ifdef HAS_NCE
+ if (execute) {
+ flags |= PROT_EXEC;
+ }
+#endif
int ret = mprotect(virtual_base + virtual_offset, length, flags);
ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno));
}
+ void EnableDirectMappedAddress() {
+ virtual_base = nullptr;
+ }
+
const size_t backing_size; ///< Size of the backing memory in bytes
const size_t virtual_size; ///< Size of the virtual address placeholder in bytes
u8* backing_base{reinterpret_cast<u8*>(MAP_FAILED)};
u8* virtual_base{reinterpret_cast<u8*>(MAP_FAILED)};
+ u8* virtual_map_base{reinterpret_cast<u8*>(MAP_FAILED)};
private:
/// Release all resources in the object
void Release() {
- if (virtual_base != MAP_FAILED) {
- int ret = munmap(virtual_base, virtual_size);
+ if (virtual_map_base != MAP_FAILED) {
+ int ret = munmap(virtual_map_base, virtual_size);
ASSERT_MSG(ret == 0, "munmap failed: {}", strerror(errno));
}
@@ -502,10 +582,29 @@ private:
}
}
- int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create
+ void AdjustMap(size_t* virtual_offset, size_t* length) {
+ if (virtual_base != nullptr) {
+ return;
+ }
+
+ // If we are direct mapped, we want to make sure we are operating on a region
+ // that is in range of our virtual mapping.
+ size_t intended_start = *virtual_offset;
+ size_t intended_end = intended_start + *length;
+ size_t address_space_start = reinterpret_cast<size_t>(virtual_map_base);
+ size_t address_space_end = address_space_start + virtual_size;
- boost::icl::interval_set<size_t> placeholders; ///< Mapped placeholders
- std::mutex placeholder_mutex; ///< Mutex for placeholders
+ if (address_space_start > intended_end || intended_start > address_space_end) {
+ *virtual_offset = 0;
+ *length = 0;
+ } else {
+ *virtual_offset = std::max(intended_start, address_space_start);
+ *length = std::min(intended_end, address_space_end) - *virtual_offset;
+ }
+ }
+
+ int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create
+ FreeRegionManager free_manager{};
};
#else // ^^^ Linux ^^^ vvv Generic vvv
@@ -518,11 +617,13 @@ public:
throw std::bad_alloc{};
}
- void Map(size_t virtual_offset, size_t host_offset, size_t length) {}
+ void Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perm) {}
void Unmap(size_t virtual_offset, size_t length) {}
- void Protect(size_t virtual_offset, size_t length, bool read, bool write) {}
+ void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute) {}
+
+ void EnableDirectMappedAddress() {}
u8* backing_base{nullptr};
u8* virtual_base{nullptr};
@@ -535,15 +636,16 @@ HostMemory::HostMemory(size_t backing_size_, size_t virtual_size_)
try {
// Try to allocate a fastmem arena.
// The implementation will fail with std::bad_alloc on errors.
- impl = std::make_unique<HostMemory::Impl>(AlignUp(backing_size, PageAlignment),
- AlignUp(virtual_size, PageAlignment) +
- 3 * HugePageSize);
+ impl =
+ std::make_unique<HostMemory::Impl>(AlignUp(backing_size, PageAlignment),
+ AlignUp(virtual_size, PageAlignment) + HugePageSize);
backing_base = impl->backing_base;
virtual_base = impl->virtual_base;
if (virtual_base) {
- virtual_base += 2 * HugePageSize - 1;
- virtual_base -= reinterpret_cast<size_t>(virtual_base) & (HugePageSize - 1);
+ // Ensure the virtual base is aligned to the L2 block size.
+ virtual_base = reinterpret_cast<u8*>(
+ Common::AlignUp(reinterpret_cast<uintptr_t>(virtual_base), HugePageSize));
virtual_base_offset = virtual_base - impl->virtual_base;
}
@@ -562,7 +664,8 @@ HostMemory::HostMemory(HostMemory&&) noexcept = default;
HostMemory& HostMemory::operator=(HostMemory&&) noexcept = default;
-void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length) {
+void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length,
+ MemoryPermission perms) {
ASSERT(virtual_offset % PageAlignment == 0);
ASSERT(host_offset % PageAlignment == 0);
ASSERT(length % PageAlignment == 0);
@@ -571,7 +674,7 @@ void HostMemory::Map(size_t virtual_offset, size_t host_offset, size_t length) {
if (length == 0 || !virtual_base || !impl) {
return;
}
- impl->Map(virtual_offset + virtual_base_offset, host_offset, length);
+ impl->Map(virtual_offset + virtual_base_offset, host_offset, length, perms);
}
void HostMemory::Unmap(size_t virtual_offset, size_t length) {
@@ -584,14 +687,22 @@ void HostMemory::Unmap(size_t virtual_offset, size_t length) {
impl->Unmap(virtual_offset + virtual_base_offset, length);
}
-void HostMemory::Protect(size_t virtual_offset, size_t length, bool read, bool write) {
+void HostMemory::Protect(size_t virtual_offset, size_t length, bool read, bool write,
+ bool execute) {
ASSERT(virtual_offset % PageAlignment == 0);
ASSERT(length % PageAlignment == 0);
ASSERT(virtual_offset + length <= virtual_size);
if (length == 0 || !virtual_base || !impl) {
return;
}
- impl->Protect(virtual_offset + virtual_base_offset, length, read, write);
+ impl->Protect(virtual_offset + virtual_base_offset, length, read, write, execute);
+}
+
+void HostMemory::EnableDirectMappedAddress() {
+ if (impl) {
+ impl->EnableDirectMappedAddress();
+ virtual_size += reinterpret_cast<uintptr_t>(virtual_base);
+ }
}
} // namespace Common
diff --git a/src/common/host_memory.h b/src/common/host_memory.h
index 447975ded..cebfacab2 100644
--- a/src/common/host_memory.h
+++ b/src/common/host_memory.h
@@ -4,11 +4,20 @@
#pragma once
#include <memory>
+#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/virtual_buffer.h"
namespace Common {
+enum class MemoryPermission : u32 {
+ Read = 1 << 0,
+ Write = 1 << 1,
+ ReadWrite = Read | Write,
+ Execute = 1 << 2,
+};
+DECLARE_ENUM_FLAG_OPERATORS(MemoryPermission)
+
/**
* A low level linear memory buffer, which supports multiple mappings
* Its purpose is to rebuild a given sparse memory layout, including mirrors.
@@ -31,11 +40,13 @@ public:
HostMemory(HostMemory&& other) noexcept;
HostMemory& operator=(HostMemory&& other) noexcept;
- void Map(size_t virtual_offset, size_t host_offset, size_t length);
+ void Map(size_t virtual_offset, size_t host_offset, size_t length, MemoryPermission perms);
void Unmap(size_t virtual_offset, size_t length);
- void Protect(size_t virtual_offset, size_t length, bool read, bool write);
+ void Protect(size_t virtual_offset, size_t length, bool read, bool write, bool execute = false);
+
+ void EnableDirectMappedAddress();
[[nodiscard]] u8* BackingBasePointer() noexcept {
return backing_base;
diff --git a/src/common/linux/gamemode.cpp b/src/common/linux/gamemode.cpp
new file mode 100644
index 000000000..8d3e2934a
--- /dev/null
+++ b/src/common/linux/gamemode.cpp
@@ -0,0 +1,40 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <gamemode_client.h>
+
+#include "common/linux/gamemode.h"
+#include "common/logging/log.h"
+#include "common/settings.h"
+
+namespace Common::Linux {
+
+void StartGamemode() {
+ if (Settings::values.enable_gamemode) {
+ if (gamemode_request_start() < 0) {
+ LOG_WARNING(Frontend, "Failed to start gamemode: {}", gamemode_error_string());
+ } else {
+ LOG_INFO(Frontend, "Started gamemode");
+ }
+ }
+}
+
+void StopGamemode() {
+ if (Settings::values.enable_gamemode) {
+ if (gamemode_request_end() < 0) {
+ LOG_WARNING(Frontend, "Failed to stop gamemode: {}", gamemode_error_string());
+ } else {
+ LOG_INFO(Frontend, "Stopped gamemode");
+ }
+ }
+}
+
+void SetGamemodeState(bool state) {
+ if (state) {
+ StartGamemode();
+ } else {
+ StopGamemode();
+ }
+}
+
+} // namespace Common::Linux
diff --git a/src/common/linux/gamemode.h b/src/common/linux/gamemode.h
new file mode 100644
index 000000000..b80646ae2
--- /dev/null
+++ b/src/common/linux/gamemode.h
@@ -0,0 +1,24 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+namespace Common::Linux {
+
+/**
+ * Start the (Feral Interactive) Linux gamemode if it is installed and it is activated
+ */
+void StartGamemode();
+
+/**
+ * Stop the (Feral Interactive) Linux gamemode if it is installed and it is activated
+ */
+void StopGamemode();
+
+/**
+ * Start or stop the (Feral Interactive) Linux gamemode if it is installed and it is activated
+ * @param state The new state the gamemode should have
+ */
+void SetGamemodeState(bool state);
+
+} // namespace Common::Linux
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 51717be06..4666bd0a0 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -41,6 +41,7 @@ SWITCHABLE(AspectRatio, true);
SWITCHABLE(AstcDecodeMode, true);
SWITCHABLE(AstcRecompression, true);
SWITCHABLE(AudioMode, true);
+SWITCHABLE(CpuBackend, true);
SWITCHABLE(CpuAccuracy, true);
SWITCHABLE(FullscreenMode, true);
SWITCHABLE(GpuAccuracy, true);
@@ -155,6 +156,22 @@ bool IsFastmemEnabled() {
return true;
}
+static bool is_nce_enabled = false;
+
+void SetNceEnabled(bool is_39bit) {
+ const bool is_nce_selected = values.cpu_backend.GetValue() == CpuBackend::Nce;
+ is_nce_enabled = IsFastmemEnabled() && is_nce_selected && is_39bit;
+ if (is_nce_selected && !is_nce_enabled) {
+ LOG_WARNING(
+ Common,
+ "Program does not utilize 39-bit address space, unable to natively execute code");
+ }
+}
+
+bool IsNceEnabled() {
+ return is_nce_enabled;
+}
+
bool IsDockedMode() {
return values.use_docked_mode.GetValue() == Settings::ConsoleMode::Docked;
}
@@ -206,9 +223,9 @@ const char* TranslateCategory(Category category) {
case Category::UiAudio:
return "UiAudio";
case Category::UiLayout:
- return "UiLayout";
+ return "UILayout";
case Category::UiGameList:
- return "UiGameList";
+ return "UIGameList";
case Category::Screenshots:
return "Screenshots";
case Category::Shortcuts:
@@ -219,6 +236,8 @@ const char* TranslateCategory(Category category) {
return "Services";
case Category::Paths:
return "Paths";
+ case Category::Linux:
+ return "Linux";
case Category::MaxEnum:
break;
}
diff --git a/src/common/settings.h b/src/common/settings.h
index e899f1ae6..98341ad96 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -63,6 +63,7 @@ SWITCHABLE(AspectRatio, true);
SWITCHABLE(AstcDecodeMode, true);
SWITCHABLE(AstcRecompression, true);
SWITCHABLE(AudioMode, true);
+SWITCHABLE(CpuBackend, true);
SWITCHABLE(CpuAccuracy, true);
SWITCHABLE(FullscreenMode, true);
SWITCHABLE(GpuAccuracy, true);
@@ -179,6 +180,14 @@ struct Values {
&use_speed_limit};
// Cpu
+ SwitchableSetting<CpuBackend, true> cpu_backend{
+ linkage, CpuBackend::Dynarmic, CpuBackend::Dynarmic,
+#ifdef HAS_NCE
+ CpuBackend::Nce,
+#else
+ CpuBackend::Dynarmic,
+#endif
+ "cpu_backend", Category::Cpu};
SwitchableSetting<CpuAccuracy, true> cpu_accuracy{linkage, CpuAccuracy::Auto,
CpuAccuracy::Auto, CpuAccuracy::Paranoid,
"cpu_accuracy", Category::Cpu};
@@ -232,7 +241,11 @@ struct Values {
SwitchableSetting<bool> use_asynchronous_gpu_emulation{
linkage, true, "use_asynchronous_gpu_emulation", Category::Renderer};
SwitchableSetting<AstcDecodeMode, true> accelerate_astc{linkage,
+#ifdef ANDROID
+ AstcDecodeMode::Cpu,
+#else
AstcDecodeMode::Gpu,
+#endif
AstcDecodeMode::Cpu,
AstcDecodeMode::CpuAsynchronous,
"accelerate_astc",
@@ -304,7 +317,11 @@ struct Values {
linkage, 0, "bg_blue", Category::Renderer, Specialization::Default, true, true};
SwitchableSetting<GpuAccuracy, true> gpu_accuracy{linkage,
+#ifdef ANDROID
+ GpuAccuracy::Normal,
+#else
GpuAccuracy::High,
+#endif
GpuAccuracy::Normal,
GpuAccuracy::Extreme,
"gpu_accuracy",
@@ -313,20 +330,38 @@ struct Values {
true,
true};
GpuAccuracy current_gpu_accuracy{GpuAccuracy::High};
- SwitchableSetting<AnisotropyMode, true> max_anisotropy{
- linkage, AnisotropyMode::Automatic, AnisotropyMode::Automatic, AnisotropyMode::X16,
- "max_anisotropy", Category::RendererAdvanced};
+ SwitchableSetting<AnisotropyMode, true> max_anisotropy{linkage,
+#ifdef ANDROID
+ AnisotropyMode::Default,
+#else
+ AnisotropyMode::Automatic,
+#endif
+ AnisotropyMode::Automatic,
+ AnisotropyMode::X16,
+ "max_anisotropy",
+ Category::RendererAdvanced};
SwitchableSetting<AstcRecompression, true> astc_recompression{linkage,
AstcRecompression::Uncompressed,
AstcRecompression::Uncompressed,
AstcRecompression::Bc3,
"astc_recompression",
Category::RendererAdvanced};
- SwitchableSetting<bool> async_presentation{linkage, false, "async_presentation",
- Category::RendererAdvanced};
+ SwitchableSetting<bool> async_presentation{linkage,
+#ifdef ANDROID
+ true,
+#else
+ false,
+#endif
+ "async_presentation", Category::RendererAdvanced};
SwitchableSetting<bool> renderer_force_max_clock{linkage, false, "force_max_clock",
Category::RendererAdvanced};
- SwitchableSetting<bool> use_reactive_flushing{linkage, true, "use_reactive_flushing",
+ SwitchableSetting<bool> use_reactive_flushing{linkage,
+#ifdef ANDROID
+ false,
+#else
+ true,
+#endif
+ "use_reactive_flushing",
Category::RendererAdvanced};
SwitchableSetting<bool> use_asynchronous_shaders{linkage, false, "use_asynchronous_shaders",
Category::RendererAdvanced};
@@ -358,6 +393,8 @@ struct Values {
Category::RendererDebug};
// TODO: remove this once AMDVLK supports VK_EXT_depth_bias_control
bool renderer_amdvlk_depth_bias_workaround{};
+ Setting<bool> disable_buffer_reorder{linkage, false, "disable_buffer_reorder",
+ Category::RendererDebug};
// System
SwitchableSetting<Language, true> language_index{linkage,
@@ -390,13 +427,20 @@ struct Values {
Setting<s32> current_user{linkage, 0, "current_user", Category::System};
SwitchableSetting<ConsoleMode> use_docked_mode{linkage,
+#ifdef ANDROID
+ ConsoleMode::Handheld,
+#else
ConsoleMode::Docked,
+#endif
"use_docked_mode",
Category::System,
Specialization::Radio,
true,
true};
+ // Linux
+ SwitchableSetting<bool> enable_gamemode{linkage, true, "enable_gamemode", Category::Linux};
+
// Controls
InputSetting<std::array<PlayerInput, 10>> players;
@@ -534,6 +578,8 @@ bool IsGPULevelExtreme();
bool IsGPULevelHigh();
bool IsFastmemEnabled();
+void SetNceEnabled(bool is_64bit);
+bool IsNceEnabled();
bool IsDockedMode();
diff --git a/src/common/settings_common.h b/src/common/settings_common.h
index 7943223eb..344c04439 100644
--- a/src/common/settings_common.h
+++ b/src/common/settings_common.h
@@ -41,6 +41,7 @@ enum class Category : u32 {
Multiplayer,
Services,
Paths,
+ Linux,
MaxEnum,
};
diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h
index 11429d7a8..d6351e57e 100644
--- a/src/common/settings_enums.h
+++ b/src/common/settings_enums.h
@@ -129,6 +129,8 @@ ENUM(ShaderBackend, Glsl, Glasm, SpirV);
ENUM(GpuAccuracy, Normal, High, Extreme);
+ENUM(CpuBackend, Dynarmic, Nce);
+
ENUM(CpuAccuracy, Auto, Accurate, Unsafe, Paranoid);
ENUM(MemoryLayout, Memory_4Gb, Memory_6Gb, Memory_8Gb);
diff --git a/src/common/signal_chain.cpp b/src/common/signal_chain.cpp
new file mode 100644
index 000000000..2e4fecc48
--- /dev/null
+++ b/src/common/signal_chain.cpp
@@ -0,0 +1,42 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <dlfcn.h>
+
+#include "common/assert.h"
+#include "common/dynamic_library.h"
+#include "common/scope_exit.h"
+#include "common/signal_chain.h"
+
+namespace Common {
+
+template <typename T>
+T* LookupLibcSymbol(const char* name) {
+#if defined(__BIONIC__)
+ Common::DynamicLibrary provider("libc.so");
+ if (!provider.IsOpen()) {
+ UNREACHABLE_MSG("Failed to open libc!");
+ }
+#else
+ // For other operating environments, we assume the symbol is not overridden.
+ const char* base = nullptr;
+ Common::DynamicLibrary provider(base);
+#endif
+
+ void* sym = provider.GetSymbolAddress(name);
+ if (sym == nullptr) {
+ sym = dlsym(RTLD_DEFAULT, name);
+ }
+ if (sym == nullptr) {
+ UNREACHABLE_MSG("Unable to find symbol {}!", name);
+ }
+
+ return reinterpret_cast<T*>(sym);
+}
+
+int SigAction(int signum, const struct sigaction* act, struct sigaction* oldact) {
+ static auto libc_sigaction = LookupLibcSymbol<decltype(sigaction)>("sigaction");
+ return libc_sigaction(signum, act, oldact);
+}
+
+} // namespace Common
diff --git a/src/common/signal_chain.h b/src/common/signal_chain.h
new file mode 100644
index 000000000..8d06a1bd1
--- /dev/null
+++ b/src/common/signal_chain.h
@@ -0,0 +1,19 @@
+// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#ifndef _WIN32
+
+#include <signal.h>
+
+namespace Common {
+
+// Android's ART overrides sigaction with its own wrapper. This is problematic for SIGSEGV
+// in particular, because ART's handler accesses tpidr_el0, which conflicts with NCE.
+// This extracts the libc symbol and calls it directly.
+int SigAction(int signum, const struct sigaction* act, struct sigaction* oldact);
+
+} // namespace Common
+
+#endif
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp
index caca9a123..012fdc1e0 100644
--- a/src/common/wall_clock.cpp
+++ b/src/common/wall_clock.cpp
@@ -10,7 +10,7 @@
#include "common/x64/rdtsc.h"
#endif
-#if defined(ARCHITECTURE_arm64) && defined(__linux__)
+#ifdef HAS_NCE
#include "common/arm64/native_clock.h"
#endif
@@ -68,7 +68,7 @@ std::unique_ptr<WallClock> CreateOptimalClock() {
// - Is not more precise than 1 GHz (1ns resolution)
return std::make_unique<StandardWallClock>();
}
-#elif defined(ARCHITECTURE_arm64) && defined(__linux__)
+#elif defined(HAS_NCE)
return std::make_unique<Arm64::NativeClock>();
#else
return std::make_unique<StandardWallClock>();