From 326ae72c767a244081067df335506f0b1e88520e Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Fri, 19 Jan 2024 05:18:32 +0100 Subject: [PATCH] early-access version 4072 --- README.md | 2 +- src/core/hle/service/acc/profile_manager.cpp | 17 ++++++ src/core/hle/service/acc/profile_manager.h | 1 + src/core/hle/service/hle_ipc.cpp | 60 ++++--------------- src/core/hle/service/hle_ipc.h | 3 + .../hle/service/nvnflinger/nvnflinger.cpp | 16 ++--- src/core/hle/service/nvnflinger/nvnflinger.h | 4 +- .../hle/service/vi/display/vi_display.cpp | 11 ++++ src/core/hle/service/vi/display/vi_display.h | 3 + src/core/hle/service/vi/layer/vi_layer.h | 9 +-- src/core/hle/service/vi/vi.cpp | 14 ++++- src/yuzu/main.cpp | 24 ++++++-- src/yuzu/main.h | 2 + 13 files changed, 97 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 5ac28ce26..764320f59 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 4071. +This is the source code for early-access 4072. ## Legal Notice diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 9445c90b2..e22a698c8 100755 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp @@ -11,6 +11,7 @@ #include "common/fs/path_util.h" #include "common/polyfill_ranges.h" #include "common/settings.h" +#include "common/string_util.h" #include "core/hle/service/acc/profile_manager.h" namespace Service::Account { @@ -164,6 +165,22 @@ std::optional ProfileManager::GetUserIndex(const ProfileInfo& user) return GetUserIndex(user.user_uuid); } +/// Returns the first user profile seen based on username (which does not enforce uniqueness) +std::optional ProfileManager::GetUserIndex(const std::string& username) const { + const auto iter = + std::find_if(profiles.begin(), profiles.end(), [&username](const ProfileInfo& p) { + const std::string profile_username = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(p.username.data()), p.username.size()); + + return username.compare(profile_username) == 0; + }); + if (iter == profiles.end()) { + return std::nullopt; + } + + return static_cast(std::distance(profiles.begin(), iter)); +} + /// Returns the data structure used by the switch when GetProfileBase is called on acc:* bool ProfileManager::GetProfileBase(std::optional index, ProfileBase& profile) const { if (!index || index >= MAX_USERS) { diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index cb408ef38..f171b3f7a 100755 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h @@ -70,6 +70,7 @@ public: std::optional GetUser(std::size_t index) const; std::optional GetUserIndex(const Common::UUID& uuid) const; std::optional GetUserIndex(const ProfileInfo& user) const; + std::optional GetUserIndex(const std::string& username) const; bool GetProfileBase(std::optional index, ProfileBase& profile) const; bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; diff --git a/src/core/hle/service/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp index 151790913..e491dd260 100755 --- a/src/core/hle/service/hle_ipc.cpp +++ b/src/core/hle/service/hle_ipc.cpp @@ -24,19 +24,6 @@ #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" -namespace { -static thread_local std::array read_buffer_data_a{ - Common::ScratchBuffer(), - Common::ScratchBuffer(), - Common::ScratchBuffer(), -}; -static thread_local std::array read_buffer_data_x{ - Common::ScratchBuffer(), - Common::ScratchBuffer(), - Common::ScratchBuffer(), -}; -} // Anonymous namespace - namespace Service { SessionRequestHandler::SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_) @@ -344,48 +331,27 @@ std::vector HLERequestContext::ReadBufferCopy(std::size_t buffer_index) cons } std::span HLERequestContext::ReadBufferA(std::size_t buffer_index) const { - static thread_local std::array read_buffer_a{ - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - }; + Core::Memory::CpuGuestMemory gm(memory, 0, 0); ASSERT_OR_EXECUTE_MSG( BufferDescriptorA().size() > buffer_index, { return {}; }, "BufferDescriptorA invalid buffer_index {}", buffer_index); - auto& read_buffer = read_buffer_a[buffer_index]; - return read_buffer.Read(BufferDescriptorA()[buffer_index].Address(), - BufferDescriptorA()[buffer_index].Size(), - &read_buffer_data_a[buffer_index]); + return gm.Read(BufferDescriptorA()[buffer_index].Address(), + BufferDescriptorA()[buffer_index].Size(), &read_buffer_data_a[buffer_index]); } std::span HLERequestContext::ReadBufferX(std::size_t buffer_index) const { - static thread_local std::array read_buffer_x{ - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - }; + Core::Memory::CpuGuestMemory gm(memory, 0, 0); ASSERT_OR_EXECUTE_MSG( BufferDescriptorX().size() > buffer_index, { return {}; }, "BufferDescriptorX invalid buffer_index {}", buffer_index); - auto& read_buffer = read_buffer_x[buffer_index]; - return read_buffer.Read(BufferDescriptorX()[buffer_index].Address(), - BufferDescriptorX()[buffer_index].Size(), - &read_buffer_data_x[buffer_index]); + return gm.Read(BufferDescriptorX()[buffer_index].Address(), + BufferDescriptorX()[buffer_index].Size(), &read_buffer_data_x[buffer_index]); } std::span HLERequestContext::ReadBuffer(std::size_t buffer_index) const { - static thread_local std::array read_buffer_a{ - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - }; - static thread_local std::array read_buffer_x{ - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - Core::Memory::CpuGuestMemory(memory, 0, 0), - }; + Core::Memory::CpuGuestMemory gm(memory, 0, 0); const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && BufferDescriptorA()[buffer_index].Size()}; @@ -402,18 +368,14 @@ std::span HLERequestContext::ReadBuffer(std::size_t buffer_index) cons ASSERT_OR_EXECUTE_MSG( BufferDescriptorA().size() > buffer_index, { return {}; }, "BufferDescriptorA invalid buffer_index {}", buffer_index); - auto& read_buffer = read_buffer_a[buffer_index]; - return read_buffer.Read(BufferDescriptorA()[buffer_index].Address(), - BufferDescriptorA()[buffer_index].Size(), - &read_buffer_data_a[buffer_index]); + return gm.Read(BufferDescriptorA()[buffer_index].Address(), + BufferDescriptorA()[buffer_index].Size(), &read_buffer_data_a[buffer_index]); } else { ASSERT_OR_EXECUTE_MSG( BufferDescriptorX().size() > buffer_index, { return {}; }, "BufferDescriptorX invalid buffer_index {}", buffer_index); - auto& read_buffer = read_buffer_x[buffer_index]; - return read_buffer.Read(BufferDescriptorX()[buffer_index].Address(), - BufferDescriptorX()[buffer_index].Size(), - &read_buffer_data_x[buffer_index]); + return gm.Read(BufferDescriptorX()[buffer_index].Address(), + BufferDescriptorX()[buffer_index].Size(), &read_buffer_data_x[buffer_index]); } } diff --git a/src/core/hle/service/hle_ipc.h b/src/core/hle/service/hle_ipc.h index 876c506b4..8329d7265 100755 --- a/src/core/hle/service/hle_ipc.h +++ b/src/core/hle/service/hle_ipc.h @@ -426,6 +426,9 @@ private: Kernel::KernelCore& kernel; Core::Memory::Memory& memory; + + mutable std::array, 3> read_buffer_data_a{}; + mutable std::array, 3> read_buffer_data_x{}; }; } // namespace Service diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp index 423b9aef1..71d6fdb0c 100755 --- a/src/core/hle/service/nvnflinger/nvnflinger.cpp +++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp @@ -112,9 +112,7 @@ void Nvnflinger::ShutdownLayers() { { const auto lock_guard = Lock(); for (auto& display : displays) { - for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { - display.GetLayer(layer).GetConsumer().Abandon(); - } + display.Abandon(); } is_abandoned = true; @@ -176,24 +174,28 @@ void Nvnflinger::CreateLayerAtId(VI::Display& display, u64 layer_id) { display.CreateLayer(layer_id, buffer_id, nvdrv->container); } -void Nvnflinger::OpenLayer(u64 layer_id) { +bool Nvnflinger::OpenLayer(u64 layer_id) { const auto lock_guard = Lock(); for (auto& display : displays) { if (auto* layer = display.FindLayer(layer_id); layer) { - layer->Open(); + return layer->Open(); } } + + return false; } -void Nvnflinger::CloseLayer(u64 layer_id) { +bool Nvnflinger::CloseLayer(u64 layer_id) { const auto lock_guard = Lock(); for (auto& display : displays) { if (auto* layer = display.FindLayer(layer_id); layer) { - layer->Close(); + return layer->Close(); } } + + return false; } void Nvnflinger::DestroyLayer(u64 layer_id) { diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h index 871285764..a60e0ae6b 100755 --- a/src/core/hle/service/nvnflinger/nvnflinger.h +++ b/src/core/hle/service/nvnflinger/nvnflinger.h @@ -74,10 +74,10 @@ public: [[nodiscard]] std::optional CreateLayer(u64 display_id); /// Opens a layer on all displays for the given layer ID. - void OpenLayer(u64 layer_id); + bool OpenLayer(u64 layer_id); /// Closes a layer on all displays for the given layer ID. - void CloseLayer(u64 layer_id); + bool CloseLayer(u64 layer_id); /// Destroys the given layer ID. void DestroyLayer(u64 layer_id); diff --git a/src/core/hle/service/vi/display/vi_display.cpp b/src/core/hle/service/vi/display/vi_display.cpp index 901ede743..0f49db4ab 100755 --- a/src/core/hle/service/vi/display/vi_display.cpp +++ b/src/core/hle/service/vi/display/vi_display.cpp @@ -91,6 +91,10 @@ void Display::CreateLayer(u64 layer_id, u32 binder_id, layers.emplace_back(std::make_unique(layer_id, binder_id, *core, *producer, std::move(buffer_item_consumer))); + if (is_abandoned) { + this->FindLayer(layer_id)->GetConsumer().Abandon(); + } + hos_binder_driver_server.RegisterProducer(std::move(producer)); } @@ -103,6 +107,13 @@ void Display::DestroyLayer(u64 layer_id) { [layer_id](const auto& layer) { return layer->GetLayerId() == layer_id; }); } +void Display::Abandon() { + for (auto& layer : layers) { + layer->GetConsumer().Abandon(); + } + is_abandoned = true; +} + Layer* Display::FindLayer(u64 layer_id) { const auto itr = std::find_if(layers.begin(), layers.end(), [layer_id](const std::unique_ptr& layer) { diff --git a/src/core/hle/service/vi/display/vi_display.h b/src/core/hle/service/vi/display/vi_display.h index 224ec87d0..7392065f8 100755 --- a/src/core/hle/service/vi/display/vi_display.h +++ b/src/core/hle/service/vi/display/vi_display.h @@ -98,6 +98,8 @@ public: layers.clear(); } + void Abandon(); + /// Attempts to find a layer with the given ID. /// /// @param layer_id The layer ID. @@ -124,6 +126,7 @@ private: std::vector> layers; Kernel::KEvent* vsync_event{}; + bool is_abandoned{}; }; } // namespace Service::VI diff --git a/src/core/hle/service/vi/layer/vi_layer.h b/src/core/hle/service/vi/layer/vi_layer.h index c4582cdc1..51e859398 100755 --- a/src/core/hle/service/vi/layer/vi_layer.h +++ b/src/core/hle/service/vi/layer/vi_layer.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "common/common_types.h" @@ -75,12 +76,12 @@ public: return open; } - void Close() { - open = false; + bool Close() { + return std::exchange(open, false); } - void Open() { - open = true; + bool Open() { + return !std::exchange(open, true); } private: diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 6205b42b0..d71e9b966 100755 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -719,7 +719,12 @@ private: return; } - nvnflinger.OpenLayer(layer_id); + if (!nvnflinger.OpenLayer(layer_id)) { + LOG_WARNING(Service_VI, "Tried to open layer which was already open"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultOperationFailed); + return; + } android::OutputParcel parcel; parcel.WriteInterface(NativeWindow{*buffer_queue_id}); @@ -737,7 +742,12 @@ private: LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}", layer_id); - nvnflinger.CloseLayer(layer_id); + if (!nvnflinger.CloseLayer(layer_id)) { + LOG_WARNING(Service_VI, "Tried to close layer which was not open"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultOperationFailed); + return; + } IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index ab6205e9b..8d22b612e 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -518,12 +518,21 @@ GMainWindow::GMainWindow(std::unique_ptr config_, bool has_broken_vulk continue; } + int user_arg_idx = ++i; bool argument_ok; - const std::size_t selected_user = args[++i].toUInt(&argument_ok); + std::size_t selected_user = args[user_arg_idx].toUInt(&argument_ok); if (!argument_ok) { - LOG_ERROR(Frontend, "Invalid user argument"); - continue; + // try to look it up by username, only finds the first username that matches. + const std::string user_arg_str = args[user_arg_idx].toStdString(); + const auto user_idx = system->GetProfileManager().GetUserIndex(user_arg_str); + + if (user_idx == std::nullopt) { + LOG_ERROR(Frontend, "Invalid user argument"); + continue; + } + + selected_user = user_idx.value(); } if (!system->GetProfileManager().UserExistsIndex(selected_user)) { @@ -532,6 +541,8 @@ GMainWindow::GMainWindow(std::unique_ptr config_, bool has_broken_vulk } Settings::values.current_user = static_cast(selected_user); + + user_flag_cmd_line = true; continue; } @@ -1942,7 +1953,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t Settings::LogSettings(); - if (UISettings::values.select_user_on_boot) { + if (UISettings::values.select_user_on_boot && !user_flag_cmd_line) { const Core::Frontend::ProfileSelectParameters parameters{ .mode = Service::AM::Applets::UiMode::UserSelector, .invalid_uid_list = {}, @@ -1954,6 +1965,11 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t } } + // If the user specifies -u (successfully) on the cmd line, don't prompt for a user on first + // game startup only. If the user stops emulation and starts a new one, go back to the expected + // behavior of asking. + user_flag_cmd_line = false; + if (!LoadROM(filename, program_id, program_index, launch_type)) { return; } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index fb51e2659..4a2460a60 100755 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -523,6 +523,8 @@ private: std::unique_ptr emu_thread; // The path to the game currently running QString current_game_path; + // Whether a user was set on the command line (skips UserSelector if it's forced to show up) + bool user_flag_cmd_line = false; bool auto_paused = false; bool auto_muted = false;