From 05d9419e78d14061693a36913d4f5ca2094a0599 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 30 Dec 2023 23:15:57 +0100 Subject: [PATCH] early-access version 4040 --- README.md | 2 +- .../features/settings/model/IntSetting.kt | 3 +- .../settings/model/view/SettingsItem.kt | 10 ++++ .../settings/ui/SettingsFragmentPresenter.kt | 1 + .../res/layout/list_item_setting_switch.xml | 2 +- .../app/src/main/res/values/arrays.xml | 17 ++++++ .../app/src/main/res/values/strings.xml | 8 +++ src/core/CMakeLists.txt | 2 + src/core/file_sys/ips_layer.cpp | 7 +++ src/core/hle/kernel/k_capabilities.cpp | 6 +- src/core/hle/service/jit/jit.cpp | 59 +++++++++++++------ src/core/hle/service/jit/jit_code_memory.cpp | 54 +++++++++++++++++ src/core/hle/service/jit/jit_code_memory.h | 49 +++++++++++++++ src/yuzu/main.cpp | 4 ++ src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 2 +- .../emu_window/emu_window_sdl2_vk.cpp | 3 +- 16 files changed, 204 insertions(+), 25 deletions(-) create mode 100755 src/core/hle/service/jit/jit_code_memory.cpp create mode 100755 src/core/hle/service/jit/jit_code_memory.h diff --git a/README.md b/README.md index 069e76f9a..296593019 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4039. +This is the source code for early-access 4040. ## Legal Notice diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt index 21e4e1afd..df760440f 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt @@ -18,7 +18,8 @@ enum class IntSetting(override val key: String) : AbstractIntSetting { RENDERER_ANTI_ALIASING("anti_aliasing"), RENDERER_SCREEN_LAYOUT("screen_layout"), RENDERER_ASPECT_RATIO("aspect_ratio"), - AUDIO_OUTPUT_ENGINE("output_engine"); + AUDIO_OUTPUT_ENGINE("output_engine"), + MAX_ANISOTROPY("max_anisotropy"); override fun getInt(needsGlobal: Boolean): Int = NativeConfig.getInt(key, needsGlobal) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt index 2e97aee2c..12f7aa1ab 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt @@ -243,6 +243,15 @@ abstract class SettingsItem( R.string.renderer_reactive_flushing_description ) ) + put( + SingleChoiceSetting( + IntSetting.MAX_ANISOTROPY, + R.string.anisotropic_filtering, + R.string.anisotropic_filtering_description, + R.array.anisoEntries, + R.array.anisoValues + ) + ) put( SingleChoiceSetting( IntSetting.AUDIO_OUTPUT_ENGINE, @@ -298,6 +307,7 @@ abstract class SettingsItem( override val key: String = FASTMEM_COMBINED override val isRuntimeModifiable: Boolean = false + override val pairedSettingKey = BooleanSetting.CPU_DEBUG_MODE.key override val defaultValue: Boolean = true override val isSwitchable: Boolean = true override var global: Boolean diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt index a7e965589..db1a1076c 100755 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsFragmentPresenter.kt @@ -149,6 +149,7 @@ class SettingsFragmentPresenter( add(IntSetting.RENDERER_VSYNC.key) add(IntSetting.RENDERER_SCALING_FILTER.key) add(IntSetting.RENDERER_ANTI_ALIASING.key) + add(IntSetting.MAX_ANISOTROPY.key) add(IntSetting.RENDERER_SCREEN_LAYOUT.key) add(IntSetting.RENDERER_ASPECT_RATIO.key) add(BooleanSetting.PICTURE_IN_PICTURE.key) diff --git a/src/android/app/src/main/res/layout/list_item_setting_switch.xml b/src/android/app/src/main/res/layout/list_item_setting_switch.xml index 5cb84182e..1c08e2e1b 100755 --- a/src/android/app/src/main/res/layout/list_item_setting_switch.xml +++ b/src/android/app/src/main/res/layout/list_item_setting_switch.xml @@ -24,7 +24,7 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="24dp" - android:gravity="center_vertical" + android:layout_gravity="center_vertical" android:orientation="vertical" android:layout_weight="1"> diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index e3915ef4f..c882a8e62 100755 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -267,4 +267,21 @@ 3 + + @string/auto + @string/slider_default + @string/multiplier_two + @string/multiplier_four + @string/multiplier_eight + @string/multiplier_sixteen + + + 0 + 1 + 2 + 3 + 4 + 5 + + diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 0b80b04a4..4d5c268fe 100755 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -225,6 +225,8 @@ Improves rendering accuracy in some games at the cost of performance. Disk shader cache Reduces stuttering by locally storing and loading generated shaders. + Anisotropic filtering + Improves the quality of textures when viewed at oblique angles CPU @@ -506,6 +508,12 @@ oboe cubeb + + 2x + 4x + 8x + 16x + Black backgrounds When using the dark theme, apply black backgrounds. diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 48e174a9d..726ae9ece 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -988,6 +988,8 @@ if (ARCHITECTURE_x86_64 OR ARCHITECTURE_arm64) arm/dynarmic/dynarmic_cp15.h arm/dynarmic/dynarmic_exclusive_monitor.cpp arm/dynarmic/dynarmic_exclusive_monitor.h + hle/service/jit/jit_code_memory.cpp + hle/service/jit/jit_code_memory.h hle/service/jit/jit_context.cpp hle/service/jit/jit_context.h hle/service/jit/jit.cpp diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp index 67d9df5d9..69abc37b5 100755 --- a/src/core/file_sys/ips_layer.cpp +++ b/src/core/file_sys/ips_layer.cpp @@ -73,6 +73,9 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { return nullptr; auto in_data = in->ReadAllBytes(); + if (in_data.size() == 0) { + return nullptr; + } std::vector temp(type == IPSFileType::IPS ? 3 : 4); u64 offset = 5; // After header @@ -88,6 +91,10 @@ VirtualFile PatchIPS(const VirtualFile& in, const VirtualFile& ips) { else real_offset = (temp[0] << 16) | (temp[1] << 8) | temp[2]; + if (real_offset > in_data.size()) { + return nullptr; + } + u16 data_size{}; if (ips->ReadObject(&data_size, offset) != sizeof(u16)) return nullptr; diff --git a/src/core/hle/kernel/k_capabilities.cpp b/src/core/hle/kernel/k_capabilities.cpp index 274fee493..d2288c30d 100755 --- a/src/core/hle/kernel/k_capabilities.cpp +++ b/src/core/hle/kernel/k_capabilities.cpp @@ -185,6 +185,10 @@ Result KCapabilities::ProcessMapRegionCapability(const u32 cap, F f) { case RegionType::NoMapping: break; case RegionType::KernelTraceBuffer: + if constexpr (!IsKTraceEnabled) { + break; + } + [[fallthrough]]; case RegionType::OnMemoryBootImage: case RegionType::DTB: R_TRY(f(MemoryRegions[static_cast(type)], perm)); @@ -330,8 +334,6 @@ Result KCapabilities::SetCapabilities(std::span caps, KProcessPageTab // Map the range. R_TRY(this->MapRange_(cap, size_cap, page_table)); - } else if (GetCapabilityType(cap) == CapabilityType::MapRegion && !IsKTraceEnabled) { - continue; } else { R_TRY(this->SetCapability(cap, set_flags, set_svc, page_table)); } diff --git a/src/core/hle/service/jit/jit.cpp b/src/core/hle/service/jit/jit.cpp index 5dc9a96c0..771563d4d 100755 --- a/src/core/hle/service/jit/jit.cpp +++ b/src/core/hle/service/jit/jit.cpp @@ -4,11 +4,11 @@ #include "core/arm/debug.h" #include "core/arm/symbols.h" #include "core/core.h" -#include "core/hle/kernel/k_code_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/result.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/jit/jit.h" +#include "core/hle/service/jit/jit_code_memory.h" #include "core/hle/service/jit/jit_context.h" #include "core/hle/service/server_manager.h" #include "core/hle/service/service.h" @@ -23,10 +23,12 @@ struct CodeRange { class IJitEnvironment final : public ServiceFramework { public: - explicit IJitEnvironment(Core::System& system_, Kernel::KProcess& process_, CodeRange user_rx, - CodeRange user_ro) - : ServiceFramework{system_, "IJitEnvironment"}, process{&process_}, - context{process->GetMemory()} { + explicit IJitEnvironment(Core::System& system_, + Kernel::KScopedAutoObject&& process_, + CodeMemory&& user_rx_, CodeMemory&& user_ro_) + : ServiceFramework{system_, "IJitEnvironment"}, process{std::move(process_)}, + user_rx{std::move(user_rx_)}, user_ro{std::move(user_ro_)}, + context{system_.ApplicationMemory()} { // clang-format off static const FunctionInfo functions[] = { {0, &IJitEnvironment::GenerateCode, "GenerateCode"}, @@ -39,10 +41,13 @@ public: RegisterHandlers(functions); // Identity map user code range into sysmodule context - configuration.user_ro_memory = user_ro; - configuration.user_rx_memory = user_rx; - configuration.sys_ro_memory = user_ro; - configuration.sys_rx_memory = user_rx; + configuration.user_rx_memory.size = user_rx.GetSize(); + configuration.user_rx_memory.offset = user_rx.GetAddress(); + configuration.user_ro_memory.size = user_ro.GetSize(); + configuration.user_ro_memory.offset = user_ro.GetAddress(); + + configuration.sys_rx_memory = configuration.user_rx_memory; + configuration.sys_ro_memory = configuration.user_ro_memory; } void GenerateCode(HLERequestContext& ctx) { @@ -318,6 +323,8 @@ private: } Kernel::KScopedAutoObject process; + CodeMemory user_rx; + CodeMemory user_ro; GuestCallbacks callbacks; JITConfiguration configuration; JITContext context; @@ -335,6 +342,7 @@ public: RegisterHandlers(functions); } +private: void CreateJitEnvironment(HLERequestContext& ctx) { LOG_DEBUG(Service_JIT, "called"); @@ -380,20 +388,35 @@ public: return; } - const CodeRange user_rx{ - .offset = GetInteger(rx_mem->GetSourceAddress()), - .size = parameters.rx_size, - }; + CodeMemory rx, ro; + Result res; - const CodeRange user_ro{ - .offset = GetInteger(ro_mem->GetSourceAddress()), - .size = parameters.ro_size, - }; + res = rx.Initialize(*process, *rx_mem, parameters.rx_size, + Kernel::Svc::MemoryPermission::ReadExecute, generate_random); + if (R_FAILED(res)) { + LOG_ERROR(Service_JIT, "rx_mem could not be mapped for handle=0x{:08X}", rx_mem_handle); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(res); + return; + } + + res = ro.Initialize(*process, *ro_mem, parameters.ro_size, + Kernel::Svc::MemoryPermission::Read, generate_random); + if (R_FAILED(res)) { + LOG_ERROR(Service_JIT, "ro_mem could not be mapped for handle=0x{:08X}", ro_mem_handle); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(res); + return; + } IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); - rb.PushIpcInterface(system, *process, user_rx, user_ro); + rb.PushIpcInterface(system, std::move(process), std::move(rx), + std::move(ro)); } + +private: + std::mt19937_64 generate_random{}; }; void LoopProcess(Core::System& system) { diff --git a/src/core/hle/service/jit/jit_code_memory.cpp b/src/core/hle/service/jit/jit_code_memory.cpp new file mode 100755 index 000000000..2b480488a --- /dev/null +++ b/src/core/hle/service/jit/jit_code_memory.cpp @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/jit/jit_code_memory.h" + +namespace Service::JIT { + +Result CodeMemory::Initialize(Kernel::KProcess& process, Kernel::KCodeMemory& code_memory, + size_t size, Kernel::Svc::MemoryPermission perm, + std::mt19937_64& generate_random) { + auto& page_table = process.GetPageTable(); + const u64 alias_code_start = + GetInteger(page_table.GetAliasCodeRegionStart()) / Kernel::PageSize; + const u64 alias_code_size = page_table.GetAliasCodeRegionSize() / Kernel::PageSize; + + // NOTE: This will retry indefinitely until mapping the code memory succeeds. + while (true) { + // Generate a new trial address. + const u64 mapped_address = + (alias_code_start + (generate_random() % alias_code_size)) * Kernel::PageSize; + + // Try to map the address + R_TRY_CATCH(code_memory.MapToOwner(mapped_address, size, perm)) { + R_CATCH(Kernel::ResultInvalidMemoryRegion) { + // If we could not map here, retry. + continue; + } + } + R_END_TRY_CATCH; + + // Set members. + m_code_memory = std::addressof(code_memory); + m_size = size; + m_address = mapped_address; + m_perm = perm; + + // Open a new reference to the code memory. + m_code_memory->Open(); + + // We succeeded. + R_SUCCEED(); + } +} + +void CodeMemory::Finalize() { + if (m_code_memory) { + R_ASSERT(m_code_memory->UnmapFromOwner(m_address, m_size)); + m_code_memory->Close(); + } + + m_code_memory = nullptr; +} + +} // namespace Service::JIT diff --git a/src/core/hle/service/jit/jit_code_memory.h b/src/core/hle/service/jit/jit_code_memory.h new file mode 100755 index 000000000..6376d4c4e --- /dev/null +++ b/src/core/hle/service/jit/jit_code_memory.h @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include + +#include "core/hle/kernel/k_code_memory.h" + +namespace Service::JIT { + +class CodeMemory { +public: + YUZU_NON_COPYABLE(CodeMemory); + + explicit CodeMemory() = default; + + CodeMemory(CodeMemory&& rhs) { + std::swap(m_code_memory, rhs.m_code_memory); + std::swap(m_size, rhs.m_size); + std::swap(m_address, rhs.m_address); + std::swap(m_perm, rhs.m_perm); + } + + ~CodeMemory() { + this->Finalize(); + } + +public: + Result Initialize(Kernel::KProcess& process, Kernel::KCodeMemory& code_memory, size_t size, + Kernel::Svc::MemoryPermission perm, std::mt19937_64& generate_random); + void Finalize(); + + size_t GetSize() const { + return m_size; + } + + u64 GetAddress() const { + return m_address; + } + +private: + Kernel::KCodeMemory* m_code_memory{}; + size_t m_size{}; + u64 m_address{}; + Kernel::Svc::MemoryPermission m_perm{}; +}; + +} // namespace Service::JIT diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 0ff120f36..241bc4c74 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -5342,6 +5342,10 @@ int main(int argc, char* argv[]) { if (QString::fromLocal8Bit(qgetenv("DISPLAY")).isEmpty()) { qputenv("DISPLAY", ":0"); } + + // Fix the Wayland appId. This needs to match the name of the .desktop file without the .desktop + // suffix. + QGuiApplication::setDesktopFileName(QStringLiteral("org.yuzu_emu.yuzu")); #endif SetHighDPIAttributes(); diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 2ceca5f53..8d11a8e23 100755 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -20,7 +20,7 @@ EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_, Co : input_subsystem{input_subsystem_}, system{system_} { input_subsystem->Initialize(); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { - LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting..."); + LOG_CRITICAL(Frontend, "Failed to initialize SDL2: {}, Exiting...", SDL_GetError()); exit(1); } SDL_SetMainReady(); diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp index 233914091..73a7bcc63 100755 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp @@ -28,7 +28,8 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste SDL_SysWMinfo wm; SDL_VERSION(&wm.version); if (SDL_GetWindowWMInfo(render_window, &wm) == SDL_FALSE) { - LOG_CRITICAL(Frontend, "Failed to get information from the window manager"); + LOG_CRITICAL(Frontend, "Failed to get information from the window manager: {}", + SDL_GetError()); std::exit(EXIT_FAILURE); }