early-access version 4072

This commit is contained in:
pineappleEA 2024-01-19 05:18:32 +01:00
parent 3412de5371
commit 326ae72c76
13 changed files with 97 additions and 69 deletions

View file

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

View file

@ -11,6 +11,7 @@
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "common/polyfill_ranges.h" #include "common/polyfill_ranges.h"
#include "common/settings.h" #include "common/settings.h"
#include "common/string_util.h"
#include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/acc/profile_manager.h"
namespace Service::Account { namespace Service::Account {
@ -164,6 +165,22 @@ std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user)
return GetUserIndex(user.user_uuid); return GetUserIndex(user.user_uuid);
} }
/// Returns the first user profile seen based on username (which does not enforce uniqueness)
std::optional<std::size_t> 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<const char*>(p.username.data()), p.username.size());
return username.compare(profile_username) == 0;
});
if (iter == profiles.end()) {
return std::nullopt;
}
return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
}
/// Returns the data structure used by the switch when GetProfileBase is called on acc:* /// Returns the data structure used by the switch when GetProfileBase is called on acc:*
bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const { bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const {
if (!index || index >= MAX_USERS) { if (!index || index >= MAX_USERS) {

View file

@ -70,6 +70,7 @@ public:
std::optional<Common::UUID> GetUser(std::size_t index) const; std::optional<Common::UUID> GetUser(std::size_t index) const;
std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const; std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const;
std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
std::optional<std::size_t> GetUserIndex(const std::string& username) const;
bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const;
bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const;
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;

View file

@ -24,19 +24,6 @@
#include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ipc_helpers.h"
#include "core/memory.h" #include "core/memory.h"
namespace {
static thread_local std::array read_buffer_data_a{
Common::ScratchBuffer<u8>(),
Common::ScratchBuffer<u8>(),
Common::ScratchBuffer<u8>(),
};
static thread_local std::array read_buffer_data_x{
Common::ScratchBuffer<u8>(),
Common::ScratchBuffer<u8>(),
Common::ScratchBuffer<u8>(),
};
} // Anonymous namespace
namespace Service { namespace Service {
SessionRequestHandler::SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_) SessionRequestHandler::SessionRequestHandler(Kernel::KernelCore& kernel_, const char* service_name_)
@ -344,48 +331,27 @@ std::vector<u8> HLERequestContext::ReadBufferCopy(std::size_t buffer_index) cons
} }
std::span<const u8> HLERequestContext::ReadBufferA(std::size_t buffer_index) const { std::span<const u8> HLERequestContext::ReadBufferA(std::size_t buffer_index) const {
static thread_local std::array read_buffer_a{ Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> gm(memory, 0, 0);
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
};
ASSERT_OR_EXECUTE_MSG( ASSERT_OR_EXECUTE_MSG(
BufferDescriptorA().size() > buffer_index, { return {}; }, BufferDescriptorA().size() > buffer_index, { return {}; },
"BufferDescriptorA invalid buffer_index {}", buffer_index); "BufferDescriptorA invalid buffer_index {}", buffer_index);
auto& read_buffer = read_buffer_a[buffer_index]; return gm.Read(BufferDescriptorA()[buffer_index].Address(),
return read_buffer.Read(BufferDescriptorA()[buffer_index].Address(), BufferDescriptorA()[buffer_index].Size(), &read_buffer_data_a[buffer_index]);
BufferDescriptorA()[buffer_index].Size(),
&read_buffer_data_a[buffer_index]);
} }
std::span<const u8> HLERequestContext::ReadBufferX(std::size_t buffer_index) const { std::span<const u8> HLERequestContext::ReadBufferX(std::size_t buffer_index) const {
static thread_local std::array read_buffer_x{ Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> gm(memory, 0, 0);
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
};
ASSERT_OR_EXECUTE_MSG( ASSERT_OR_EXECUTE_MSG(
BufferDescriptorX().size() > buffer_index, { return {}; }, BufferDescriptorX().size() > buffer_index, { return {}; },
"BufferDescriptorX invalid buffer_index {}", buffer_index); "BufferDescriptorX invalid buffer_index {}", buffer_index);
auto& read_buffer = read_buffer_x[buffer_index]; return gm.Read(BufferDescriptorX()[buffer_index].Address(),
return read_buffer.Read(BufferDescriptorX()[buffer_index].Address(), BufferDescriptorX()[buffer_index].Size(), &read_buffer_data_x[buffer_index]);
BufferDescriptorX()[buffer_index].Size(),
&read_buffer_data_x[buffer_index]);
} }
std::span<const u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const { std::span<const u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const {
static thread_local std::array read_buffer_a{ Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead> gm(memory, 0, 0);
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
};
static thread_local std::array read_buffer_x{
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::UnsafeRead>(memory, 0, 0),
};
const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
BufferDescriptorA()[buffer_index].Size()}; BufferDescriptorA()[buffer_index].Size()};
@ -402,18 +368,14 @@ std::span<const u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) cons
ASSERT_OR_EXECUTE_MSG( ASSERT_OR_EXECUTE_MSG(
BufferDescriptorA().size() > buffer_index, { return {}; }, BufferDescriptorA().size() > buffer_index, { return {}; },
"BufferDescriptorA invalid buffer_index {}", buffer_index); "BufferDescriptorA invalid buffer_index {}", buffer_index);
auto& read_buffer = read_buffer_a[buffer_index]; return gm.Read(BufferDescriptorA()[buffer_index].Address(),
return read_buffer.Read(BufferDescriptorA()[buffer_index].Address(), BufferDescriptorA()[buffer_index].Size(), &read_buffer_data_a[buffer_index]);
BufferDescriptorA()[buffer_index].Size(),
&read_buffer_data_a[buffer_index]);
} else { } else {
ASSERT_OR_EXECUTE_MSG( ASSERT_OR_EXECUTE_MSG(
BufferDescriptorX().size() > buffer_index, { return {}; }, BufferDescriptorX().size() > buffer_index, { return {}; },
"BufferDescriptorX invalid buffer_index {}", buffer_index); "BufferDescriptorX invalid buffer_index {}", buffer_index);
auto& read_buffer = read_buffer_x[buffer_index]; return gm.Read(BufferDescriptorX()[buffer_index].Address(),
return read_buffer.Read(BufferDescriptorX()[buffer_index].Address(), BufferDescriptorX()[buffer_index].Size(), &read_buffer_data_x[buffer_index]);
BufferDescriptorX()[buffer_index].Size(),
&read_buffer_data_x[buffer_index]);
} }
} }

View file

@ -426,6 +426,9 @@ private:
Kernel::KernelCore& kernel; Kernel::KernelCore& kernel;
Core::Memory::Memory& memory; Core::Memory::Memory& memory;
mutable std::array<Common::ScratchBuffer<u8>, 3> read_buffer_data_a{};
mutable std::array<Common::ScratchBuffer<u8>, 3> read_buffer_data_x{};
}; };
} // namespace Service } // namespace Service

View file

@ -112,9 +112,7 @@ void Nvnflinger::ShutdownLayers() {
{ {
const auto lock_guard = Lock(); const auto lock_guard = Lock();
for (auto& display : displays) { for (auto& display : displays) {
for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { display.Abandon();
display.GetLayer(layer).GetConsumer().Abandon();
}
} }
is_abandoned = true; is_abandoned = true;
@ -176,24 +174,28 @@ void Nvnflinger::CreateLayerAtId(VI::Display& display, u64 layer_id) {
display.CreateLayer(layer_id, buffer_id, nvdrv->container); 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(); const auto lock_guard = Lock();
for (auto& display : displays) { for (auto& display : displays) {
if (auto* layer = display.FindLayer(layer_id); layer) { 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(); const auto lock_guard = Lock();
for (auto& display : displays) { for (auto& display : displays) {
if (auto* layer = display.FindLayer(layer_id); layer) { if (auto* layer = display.FindLayer(layer_id); layer) {
layer->Close(); return layer->Close();
} }
} }
return false;
} }
void Nvnflinger::DestroyLayer(u64 layer_id) { void Nvnflinger::DestroyLayer(u64 layer_id) {

View file

@ -74,10 +74,10 @@ public:
[[nodiscard]] std::optional<u64> CreateLayer(u64 display_id); [[nodiscard]] std::optional<u64> CreateLayer(u64 display_id);
/// Opens a layer on all displays for the given layer 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. /// 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. /// Destroys the given layer ID.
void DestroyLayer(u64 layer_id); void DestroyLayer(u64 layer_id);

View file

@ -91,6 +91,10 @@ void Display::CreateLayer(u64 layer_id, u32 binder_id,
layers.emplace_back(std::make_unique<Layer>(layer_id, binder_id, *core, *producer, layers.emplace_back(std::make_unique<Layer>(layer_id, binder_id, *core, *producer,
std::move(buffer_item_consumer))); std::move(buffer_item_consumer)));
if (is_abandoned) {
this->FindLayer(layer_id)->GetConsumer().Abandon();
}
hos_binder_driver_server.RegisterProducer(std::move(producer)); 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; }); [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) { Layer* Display::FindLayer(u64 layer_id) {
const auto itr = const auto itr =
std::find_if(layers.begin(), layers.end(), [layer_id](const std::unique_ptr<Layer>& layer) { std::find_if(layers.begin(), layers.end(), [layer_id](const std::unique_ptr<Layer>& layer) {

View file

@ -98,6 +98,8 @@ public:
layers.clear(); layers.clear();
} }
void Abandon();
/// Attempts to find a layer with the given ID. /// Attempts to find a layer with the given ID.
/// ///
/// @param layer_id The layer ID. /// @param layer_id The layer ID.
@ -124,6 +126,7 @@ private:
std::vector<std::unique_ptr<Layer>> layers; std::vector<std::unique_ptr<Layer>> layers;
Kernel::KEvent* vsync_event{}; Kernel::KEvent* vsync_event{};
bool is_abandoned{};
}; };
} // namespace Service::VI } // namespace Service::VI

View file

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <utility>
#include "common/common_types.h" #include "common/common_types.h"
@ -75,12 +76,12 @@ public:
return open; return open;
} }
void Close() { bool Close() {
open = false; return std::exchange(open, false);
} }
void Open() { bool Open() {
open = true; return !std::exchange(open, true);
} }
private: private:

View file

@ -719,7 +719,12 @@ private:
return; 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; android::OutputParcel parcel;
parcel.WriteInterface(NativeWindow{*buffer_queue_id}); parcel.WriteInterface(NativeWindow{*buffer_queue_id});
@ -737,7 +742,12 @@ private:
LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}", layer_id); 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}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);

View file

@ -518,20 +518,31 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
continue; continue;
} }
int user_arg_idx = ++i;
bool argument_ok; 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) { if (!argument_ok) {
// 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"); LOG_ERROR(Frontend, "Invalid user argument");
continue; continue;
} }
selected_user = user_idx.value();
}
if (!system->GetProfileManager().UserExistsIndex(selected_user)) { if (!system->GetProfileManager().UserExistsIndex(selected_user)) {
LOG_ERROR(Frontend, "Selected user doesn't exist"); LOG_ERROR(Frontend, "Selected user doesn't exist");
continue; continue;
} }
Settings::values.current_user = static_cast<s32>(selected_user); Settings::values.current_user = static_cast<s32>(selected_user);
user_flag_cmd_line = true;
continue; continue;
} }
@ -1942,7 +1953,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t
Settings::LogSettings(); 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{ const Core::Frontend::ProfileSelectParameters parameters{
.mode = Service::AM::Applets::UiMode::UserSelector, .mode = Service::AM::Applets::UiMode::UserSelector,
.invalid_uid_list = {}, .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)) { if (!LoadROM(filename, program_id, program_index, launch_type)) {
return; return;
} }

View file

@ -523,6 +523,8 @@ private:
std::unique_ptr<EmuThread> emu_thread; std::unique_ptr<EmuThread> emu_thread;
// The path to the game currently running // The path to the game currently running
QString current_game_path; 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_paused = false;
bool auto_muted = false; bool auto_muted = false;