diff options
69 files changed, 1337 insertions, 995 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b2056885..01109785d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,136 +1 @@ -# Reporting Issues - -**The issue tracker is not a support forum.** Unless you can provide precise *technical information* regarding an issue, you *should not post in it*. If you need support, first read the [FAQ](https://github.com/yuzu-emu/yuzu/wiki/FAQ) and then either visit our [Discord server](https://discordapp.com/invite/u77vRWY), [our forum](https://community.citra-emu.org) or ask in a general emulation forum such as [/r/emulation](https://www.reddit.com/r/emulation/). If you post support questions, generic messages to the developers or vague reports without technical details, they will be closed and locked. - -If you believe you have a valid issue report, please post text or a screenshot from the log (the console window that opens alongside yuzu) and build version (hex string visible in the titlebar and zip filename), as well as your hardware and software information if applicable. - -# Contributing -yuzu is a brand new project, so we have a great opportunity to keep things clean and well organized early on. As such, coding style is very important when making commits. We run clang-format on our CI to check the code. Please use it to format your code when contributing. However, it doesn't cover all the rules below. Some of them aren't very strict rules since we want to be flexible and we understand that under certain circumstances some of them can be counterproductive. Just try to follow as many of them as possible. - -# Using clang format (version 6.0) -When generating the native build script for your toolset, cmake will try to find the correct version of clang format (or will download it on windows). Before running cmake, please install clang format version 6.0 for your platform as follows: - -* Windows: do nothing; cmake will download a pre built binary for MSVC and MINGW. MSVC users can additionally install a clang format Visual Studio extension to add features like format on save. -* OSX: run `brew install clang-format`. -* Linux: use your package manager to get an appropriate binary. - -If clang format is found, then cmake will add a custom build target that can be run at any time to run clang format against *all* source files and update the formatting in them. This should be used before making a pull request so that the reviewers can spend more time reviewing the code instead of having to worry about minor style violations. On MSVC, you can run clang format by building the clang-format project in the solution. On OSX, you can either use the Makefile target `make clang-format` or by building the clang-format target in XCode. For Makefile builds, you can use the clang-format target with `make clang-format` - -### General Rules -* A lot of code was taken from other projects (e.g. Citra, Dolphin, PPSSPP, Gekko). In general, when editing other people's code, follow the style of the module you're in (or better yet, fix the style if it drastically differs from our guide). -* Line width is typically 100 characters. Please do not use 80-characters. -* Don't ever introduce new external dependencies into Core -* Don't use any platform specific code in Core -* Use namespaces often -* Avoid the use of C-style casts and instead prefer C++-style `static_cast` and `reinterpret_cast`. Try to avoid using `dynamic_cast`. Never use `const_cast`. - -### Naming Rules -* Functions: `PascalCase` -* Variables: `lower_case_underscored`. Prefix with `g_` if global. -* Classes: `PascalCase` -* Files and Directories: `lower_case_underscored` -* Namespaces: `PascalCase`, `_` may also be used for clarity (e.g. `ARM_InitCore`) - -### Indentation/Whitespace Style -Follow the indentation/whitespace style shown below. Do not use tabs, use 4-spaces instead. - -### Comments -* For regular comments, use C++ style (`//`) comments, even for multi-line ones. -* For doc-comments (Doxygen comments), use `/// ` if it's a single line, else use the `/**` `*/` style featured in the example. Start the text on the second line, not the first containing `/**`. -* For items that are both defined and declared in two separate files, put the doc-comment only next to the associated declaration. (In a header file, usually.) Otherwise, put it next to the implementation. Never duplicate doc-comments in both places. - -```cpp -// Includes should be sorted lexicographically -// STD includes first -#include <map> -#include <memory> - -// then, library includes -#include <nihstro/shared_binary.h> - -// finally, yuzu includes -#include "common/math_util.h" -#include "common/vector_math.h" - -// each major module is separated -#include "video_core/pica.h" -#include "video_core/video_core.h" - -namespace Example { - -// Namespace contents are not indented - -// Declare globals at the top -int g_foo{}; // {} can be used to initialize types as 0, false, or nullptr -char* g_some_pointer{}; // Pointer * and reference & stick to the type name, and make sure to initialize as nullptr! - -/// A colorful enum. -enum SomeEnum { - ColorRed, ///< The color of fire. - ColorGreen, ///< The color of grass. - ColorBlue, ///< Not actually the color of water. -}; - -/** - * Very important struct that does a lot of stuff. - * Note that the asterisks are indented by one space to align to the first line. - */ -struct Position { - int x{}, y{}; // Always intitialize member variables! -}; - -// Use "typename" rather than "class" here -template <typename T> -void FooBar() { - const std::string some_string{ "prefer uniform initialization" }; - - int some_array[]{ - 5, - 25, - 7, - 42, - }; - - if (note == the_space_after_the_if) { - CallAfunction(); - } else { - // Use a space after the // when commenting - } - - // Place a single space after the for loop semicolons, prefer pre-increment - for (int i{}; i != 25; ++i) { - // This is how we write loops - } - - DoStuff(this, function, call, takes, up, multiple, - lines, like, this); - - if (this || condition_takes_up_multiple && - lines && like && this || everything || - alright || then) { - - // Leave a blank space before the if block body if the condition was continued across - // several lines. - } - - switch (var) { - // No indentation for case label - case 1: { - int case_var{ var + 3 }; - DoSomething(case_var); - break; - } - case 3: - DoSomething(var); - return; - - default: - // Yes, even break for the last case - break; - } - - std::vector<T> you_can_declare, a_few, variables, like_this; -} - -} -``` +**The Contributor's Guide has moved to [the Citra wiki](https://github.com/citra-emu/citra/wiki/Contributing).** diff --git a/externals/fmt b/externals/fmt -Subproject 3e75ad9822980e41bc591938f26548f24eb8890 +Subproject 9e554999ce02cf86fcdfe74fe740c4fe3f5a56d diff --git a/src/audio_core/audio_out.cpp b/src/audio_core/audio_out.cpp index cbba17632..50d2a1ed3 100644 --- a/src/audio_core/audio_out.cpp +++ b/src/audio_core/audio_out.cpp @@ -22,8 +22,7 @@ static Stream::Format ChannelsToStreamFormat(u32 num_channels) { return Stream::Format::Multi51Channel16; } - LOG_CRITICAL(Audio, "Unimplemented num_channels={}", num_channels); - UNREACHABLE(); + UNIMPLEMENTED_MSG("Unimplemented num_channels={}", num_channels); return {}; } diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp index 2683f3a5f..00c026511 100644 --- a/src/audio_core/audio_renderer.cpp +++ b/src/audio_core/audio_renderer.cpp @@ -260,8 +260,7 @@ void AudioRenderer::VoiceState::RefreshBuffer() { break; } default: - LOG_CRITICAL(Audio, "Unimplemented sample_format={}", info.sample_format); - UNREACHABLE(); + UNIMPLEMENTED_MSG("Unimplemented sample_format={}", info.sample_format); break; } @@ -280,8 +279,7 @@ void AudioRenderer::VoiceState::RefreshBuffer() { break; } default: - LOG_CRITICAL(Audio, "Unimplemented channel_count={}", info.channel_count); - UNREACHABLE(); + UNIMPLEMENTED_MSG("Unimplemented channel_count={}", info.channel_count); break; } diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index f35628e45..874673c4e 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -28,8 +28,7 @@ u32 Stream::GetNumChannels() const { case Format::Multi51Channel16: return 6; } - LOG_CRITICAL(Audio, "Unimplemented format={}", static_cast<u32>(format)); - UNREACHABLE(); + UNIMPLEMENTED_MSG("Unimplemented format={}", static_cast<u32>(format)); return {}; } @@ -49,7 +48,7 @@ void Stream::Play() { void Stream::Stop() { state = State::Stopped; - ASSERT_MSG(false, "Unimplemented"); + UNIMPLEMENTED(); } Stream::State Stream::GetState() const { @@ -120,7 +119,7 @@ bool Stream::QueueBuffer(BufferPtr&& buffer) { } bool Stream::ContainsBuffer(Buffer::Tag tag) const { - ASSERT_MSG(false, "Unimplemented"); + UNIMPLEMENTED(); return {}; } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 94a576508..aa9e05089 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,5 +1,6 @@ add_library(core STATIC arm/arm_interface.h + arm/arm_interface.cpp arm/exclusive_monitor.cpp arm/exclusive_monitor.h arm/unicorn/arm_unicorn.cpp diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp new file mode 100644 index 000000000..2223cbeed --- /dev/null +++ b/src/core/arm/arm_interface.cpp @@ -0,0 +1,27 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "common/common_types.h" +#include "common/logging/log.h" +#include "core/arm/arm_interface.h" +#include "core/memory.h" + +namespace Core { +void ARM_Interface::LogBacktrace() const { + VAddr fp = GetReg(29); + VAddr lr = GetReg(30); + const VAddr sp = GetReg(13); + const VAddr pc = GetPC(); + + LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + while (true) { + LOG_ERROR(Core_ARM, "{:016X}", lr); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8) - 4; + fp = Memory::Read64(fp); + } +} +} // namespace Core diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 59da33f30..4dfd41b43 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -141,6 +141,14 @@ public: /// Prepare core for thread reschedule (if needed to correctly handle state) virtual void PrepareReschedule() = 0; + + /// fp (= r29) points to the last frame record. + /// Note that this is the frame record for the *previous* frame, not the current one. + /// Note we need to subtract 4 from our last read to get the proper address + /// Frame records are two words long: + /// fp+0 : pointer to previous frame record + /// fp+8 : value of lr for frame + void LogBacktrace() const; }; } // namespace Core diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index ded4dd359..c455c81fb 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -10,6 +10,7 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/hle/kernel/svc.h" +#include "core/memory.h" namespace Core { diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 0a7142ada..0d6c85aed 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -18,7 +18,7 @@ #include "core/hle/kernel/client_session.h" #include "core/hle/kernel/hle_ipc.h" #include "core/hle/kernel/object.h" -#include "core/hle/kernel/server_port.h" +#include "core/hle/kernel/server_session.h" namespace IPC { diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index c114eaf99..704e82824 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp @@ -8,6 +8,7 @@ #include "core/hle/kernel/server_session.h" #include "core/hle/kernel/session.h" #include "core/hle/kernel/thread.h" +#include "core/hle/result.h" namespace Kernel { diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 439fbdb35..4c18de69c 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h @@ -6,9 +6,9 @@ #include <memory> #include <string> -#include "common/common_types.h" #include "core/hle/kernel/object.h" -#include "core/hle/result.h" + +union ResultCode; namespace Kernel { diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 61ce7d7e4..5dd855db8 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -22,11 +22,16 @@ #include "core/hle/kernel/process.h" #include "core/hle/kernel/readable_event.h" #include "core/hle/kernel/server_session.h" +#include "core/hle/kernel/thread.h" #include "core/hle/kernel/writable_event.h" #include "core/memory.h" namespace Kernel { +SessionRequestHandler::SessionRequestHandler() = default; + +SessionRequestHandler::~SessionRequestHandler() = default; + void SessionRequestHandler::ClientConnected(SharedPtr<ServerSession> server_session) { server_session->SetHleHandler(shared_from_this()); connected_sessions.push_back(std::move(server_session)); diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h index e5c0610cd..cb1c5aff3 100644 --- a/src/core/hle/kernel/hle_ipc.h +++ b/src/core/hle/kernel/hle_ipc.h @@ -14,8 +14,6 @@ #include "common/swap.h" #include "core/hle/ipc.h" #include "core/hle/kernel/object.h" -#include "core/hle/kernel/server_session.h" -#include "core/hle/kernel/thread.h" namespace Service { class ServiceFrameworkBase; @@ -27,9 +25,13 @@ class Domain; class HandleTable; class HLERequestContext; class Process; +class ServerSession; +class Thread; class ReadableEvent; class WritableEvent; +enum class ThreadWakeupReason; + /** * Interface implemented by HLE Session handlers. * This can be provided to a ServerSession in order to hook into several relevant events @@ -37,7 +39,8 @@ class WritableEvent; */ class SessionRequestHandler : public std::enable_shared_from_this<SessionRequestHandler> { public: - virtual ~SessionRequestHandler() = default; + SessionRequestHandler(); + virtual ~SessionRequestHandler(); /** * Handles a sync request from the emulated application. diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 1c2290651..67674cd47 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include <array> #include <atomic> #include <memory> #include <mutex> diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h index f1606a204..1541b6e3c 100644 --- a/src/core/hle/kernel/object.h +++ b/src/core/hle/kernel/object.h @@ -36,7 +36,6 @@ enum class HandleType : u32 { enum class ResetType { OneShot, ///< Reset automatically on object acquisition Sticky, ///< Never reset automatically - Pulse, ///< Reset automatically on wakeup }; class Object : NonCopyable { diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 06a673b9b..c5aa19afa 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -20,6 +20,35 @@ #include "core/settings.h" namespace Kernel { +namespace { +/** + * Sets up the primary application thread + * + * @param owner_process The parent process for the main thread + * @param kernel The kernel instance to create the main thread under. + * @param entry_point The address at which the thread should start execution + * @param priority The priority to give the main thread + */ +void SetupMainThread(Process& owner_process, KernelCore& kernel, VAddr entry_point, u32 priority) { + // Setup page table so we can write to memory + SetCurrentPageTable(&owner_process.VMManager().page_table); + + // Initialize new "main" thread + const VAddr stack_top = owner_process.VMManager().GetTLSIORegionEndAddress(); + auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, + owner_process.GetIdealCore(), stack_top, owner_process); + + SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); + + // Register 1 must be a handle to the main thread + const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); + thread->SetGuestHandle(guest_handle); + thread->GetContext().cpu_registers[1] = guest_handle; + + // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires + thread->ResumeFromWait(); +} +} // Anonymous namespace CodeSet::CodeSet() = default; CodeSet::~CodeSet() = default; @@ -64,7 +93,7 @@ ResultCode Process::ClearSignalState() { ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata) { program_id = metadata.GetTitleID(); - ideal_processor = metadata.GetMainThreadCore(); + ideal_core = metadata.GetMainThreadCore(); is_64bit_process = metadata.Is64BitProgram(); vm_manager.Reset(metadata.GetAddressSpaceType()); @@ -86,7 +115,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { vm_manager.LogLayout(); ChangeStatus(ProcessStatus::Running); - Kernel::SetupMainThread(kernel, entry_point, main_thread_priority, *this); + SetupMainThread(*this, kernel, entry_point, main_thread_priority); } void Process::PrepareForTermination() { diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index ac6956266..dcc57ae9f 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h @@ -14,7 +14,6 @@ #include "common/common_types.h" #include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/process_capability.h" -#include "core/hle/kernel/thread.h" #include "core/hle/kernel/vm_manager.h" #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" @@ -27,6 +26,7 @@ namespace Kernel { class KernelCore; class ResourceLimit; +class Thread; struct AddressMapping { // Address and size must be page-aligned @@ -168,18 +168,18 @@ public: /// Gets the resource limit descriptor for this process SharedPtr<ResourceLimit> GetResourceLimit() const; - /// Gets the default CPU ID for this process - u8 GetDefaultProcessorID() const { - return ideal_processor; + /// Gets the ideal CPU core ID for this process + u8 GetIdealCore() const { + return ideal_core; } - /// Gets the bitmask of allowed CPUs that this process' threads can run on. - u64 GetAllowedProcessorMask() const { + /// Gets the bitmask of allowed cores that this process' threads can run on. + u64 GetCoreMask() const { return capabilities.GetCoreMask(); } /// Gets the bitmask of allowed thread priorities. - u64 GetAllowedThreadPriorityMask() const { + u64 GetPriorityMask() const { return capabilities.GetPriorityMask(); } @@ -280,8 +280,8 @@ private: /// Resource limit descriptor for this process SharedPtr<ResourceLimit> resource_limit; - /// The default CPU for this process, threads are scheduled on this cpu by default. - u8 ideal_processor = 0; + /// The ideal CPU core for this process, threads are scheduled on this core by default. + u8 ideal_core = 0; u32 is_virtual_address_memory_enabled = 0; /// The Thread Local Storage area is allocated as processes create threads, diff --git a/src/core/hle/kernel/readable_event.cpp b/src/core/hle/kernel/readable_event.cpp index ba01f495c..6973e580c 100644 --- a/src/core/hle/kernel/readable_event.cpp +++ b/src/core/hle/kernel/readable_event.cpp @@ -46,9 +46,6 @@ ResultCode ReadableEvent::Reset() { void ReadableEvent::WakeupAllWaitingThreads() { WaitObject::WakeupAllWaitingThreads(); - - if (reset_type == ResetType::Pulse) - signaled = false; } } // namespace Kernel diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index 80897f3a4..027434f92 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp @@ -6,6 +6,7 @@ #include <utility> #include "common/assert.h" +#include "common/common_types.h" #include "common/logging/log.h" #include "core/core.h" #include "core/hle/ipc_helpers.h" diff --git a/src/core/hle/kernel/server_session.h b/src/core/hle/kernel/server_session.h index e068db2bf..e0e9d64c8 100644 --- a/src/core/hle/kernel/server_session.h +++ b/src/core/hle/kernel/server_session.h @@ -8,7 +8,6 @@ #include <string> #include <vector> -#include "common/common_types.h" #include "core/hle/kernel/object.h" #include "core/hle/kernel/wait_object.h" #include "core/hle/result.h" diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index b955f9839..6588bd3b8 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -684,6 +684,9 @@ static void Break(u32 reason, u64 info1, u64 info2) { "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", reason, info1, info2); handle_debug_buffer(info1, info2); + Core::System::GetInstance() + .ArmInterface(static_cast<std::size_t>(GetCurrentThread()->GetProcessorID())) + .LogBacktrace(); ASSERT(false); Core::CurrentProcess()->PrepareForTermination(); @@ -712,8 +715,8 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) enum class GetInfoType : u64 { // 1.0.0+ - AllowedCpuIdBitmask = 0, - AllowedThreadPrioBitmask = 1, + AllowedCPUCoreMask = 0, + AllowedThreadPriorityMask = 1, MapRegionBaseAddr = 2, MapRegionSize = 3, HeapRegionBaseAddr = 4, @@ -744,8 +747,8 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) const auto info_id_type = static_cast<GetInfoType>(info_id); switch (info_id_type) { - case GetInfoType::AllowedCpuIdBitmask: - case GetInfoType::AllowedThreadPrioBitmask: + case GetInfoType::AllowedCPUCoreMask: + case GetInfoType::AllowedThreadPriorityMask: case GetInfoType::MapRegionBaseAddr: case GetInfoType::MapRegionSize: case GetInfoType::HeapRegionBaseAddr: @@ -771,12 +774,12 @@ static ResultCode GetInfo(u64* result, u64 info_id, u64 handle, u64 info_sub_id) } switch (info_id_type) { - case GetInfoType::AllowedCpuIdBitmask: - *result = process->GetAllowedProcessorMask(); + case GetInfoType::AllowedCPUCoreMask: + *result = process->GetCoreMask(); return RESULT_SUCCESS; - case GetInfoType::AllowedThreadPrioBitmask: - *result = process->GetAllowedThreadPriorityMask(); + case GetInfoType::AllowedThreadPriorityMask: + *result = process->GetPriorityMask(); return RESULT_SUCCESS; case GetInfoType::MapRegionBaseAddr: @@ -1216,31 +1219,37 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V "threadpriority=0x{:08X}, processorid=0x{:08X} : created handle=0x{:08X}", entry_point, arg, stack_top, priority, processor_id, *out_handle); - if (priority > THREADPRIO_LOWEST) { - LOG_ERROR(Kernel_SVC, "An invalid priority was specified, expected {} but got {}", - THREADPRIO_LOWEST, priority); - return ERR_INVALID_THREAD_PRIORITY; - } - auto* const current_process = Core::CurrentProcess(); - if (processor_id == THREADPROCESSORID_DEFAULT) { - // Set the target CPU to the one specified in the process' exheader. - processor_id = current_process->GetDefaultProcessorID(); - ASSERT(processor_id != THREADPROCESSORID_DEFAULT); + if (processor_id == THREADPROCESSORID_IDEAL) { + // Set the target CPU to the one specified by the process. + processor_id = current_process->GetIdealCore(); + ASSERT(processor_id != THREADPROCESSORID_IDEAL); } - switch (processor_id) { - case THREADPROCESSORID_0: - case THREADPROCESSORID_1: - case THREADPROCESSORID_2: - case THREADPROCESSORID_3: - break; - default: + if (processor_id < THREADPROCESSORID_0 || processor_id > THREADPROCESSORID_3) { LOG_ERROR(Kernel_SVC, "Invalid thread processor ID: {}", processor_id); return ERR_INVALID_PROCESSOR_ID; } + const u64 core_mask = current_process->GetCoreMask(); + if ((core_mask | (1ULL << processor_id)) != core_mask) { + LOG_ERROR(Kernel_SVC, "Invalid thread core specified ({})", processor_id); + return ERR_INVALID_PROCESSOR_ID; + } + + if (priority > THREADPRIO_LOWEST) { + LOG_ERROR(Kernel_SVC, + "Invalid thread priority specified ({}). Must be within the range 0-64", + priority); + return ERR_INVALID_THREAD_PRIORITY; + } + + if (((1ULL << priority) & current_process->GetPriorityMask()) == 0) { + LOG_ERROR(Kernel_SVC, "Invalid thread priority specified ({})", priority); + return ERR_INVALID_THREAD_PRIORITY; + } + const std::string name = fmt::format("thread-{:X}", entry_point); auto& kernel = Core::System::GetInstance().Kernel(); CASCADE_RESULT(SharedPtr<Thread> thread, @@ -1636,13 +1645,13 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) { return ERR_INVALID_HANDLE; } - if (core == static_cast<u32>(THREADPROCESSORID_DEFAULT)) { - const u8 default_processor_id = thread->GetOwnerProcess()->GetDefaultProcessorID(); + if (core == static_cast<u32>(THREADPROCESSORID_IDEAL)) { + const u8 ideal_cpu_core = thread->GetOwnerProcess()->GetIdealCore(); - ASSERT(default_processor_id != static_cast<u8>(THREADPROCESSORID_DEFAULT)); + ASSERT(ideal_cpu_core != static_cast<u8>(THREADPROCESSORID_IDEAL)); - // Set the target CPU to the one specified in the process' exheader. - core = default_processor_id; + // Set the target CPU to the ideal core specified by the process. + core = ideal_cpu_core; mask = 1ULL << core; } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 434655638..d3984dfc4 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -12,7 +12,6 @@ #include "common/assert.h" #include "common/common_types.h" #include "common/logging/log.h" -#include "common/math_util.h" #include "common/thread_queue_list.h" #include "core/arm/arm_interface.h" #include "core/core.h" @@ -232,29 +231,6 @@ void Thread::BoostPriority(u32 priority) { current_priority = priority; } -SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority, - Process& owner_process) { - // Setup page table so we can write to memory - SetCurrentPageTable(&owner_process.VMManager().page_table); - - // Initialize new "main" thread - const VAddr stack_top = owner_process.VMManager().GetTLSIORegionEndAddress(); - auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, THREADPROCESSORID_0, - stack_top, owner_process); - - SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); - - // Register 1 must be a handle to the main thread - const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); - thread->SetGuestHandle(guest_handle); - thread->GetContext().cpu_registers[1] = guest_handle; - - // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires - thread->ResumeFromWait(); - - return thread; -} - void Thread::SetWaitSynchronizationResult(ResultCode result) { context.cpu_registers[0] = result.raw; } diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index fe5398d56..c48b21aba 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -30,12 +30,12 @@ enum ThreadPriority : u32 { }; enum ThreadProcessorId : s32 { - THREADPROCESSORID_DEFAULT = -2, ///< Run thread on default core specified by exheader - THREADPROCESSORID_0 = 0, ///< Run thread on core 0 - THREADPROCESSORID_1 = 1, ///< Run thread on core 1 - THREADPROCESSORID_2 = 2, ///< Run thread on core 2 - THREADPROCESSORID_3 = 3, ///< Run thread on core 3 - THREADPROCESSORID_MAX = 4, ///< Processor ID must be less than this + THREADPROCESSORID_IDEAL = -2, ///< Run thread on the ideal core specified by the process. + THREADPROCESSORID_0 = 0, ///< Run thread on core 0 + THREADPROCESSORID_1 = 1, ///< Run thread on core 1 + THREADPROCESSORID_2 = 2, ///< Run thread on core 2 + THREADPROCESSORID_3 = 3, ///< Run thread on core 3 + THREADPROCESSORID_MAX = 4, ///< Processor ID must be less than this /// Allowed CPU mask THREADPROCESSORID_DEFAULT_MASK = (1 << THREADPROCESSORID_0) | (1 << THREADPROCESSORID_1) | @@ -456,17 +456,6 @@ private: }; /** - * Sets up the primary application thread - * @param kernel The kernel instance to create the main thread under. - * @param entry_point The address at which the thread should start execution - * @param priority The priority to give the main thread - * @param owner_process The parent process for the main thread - * @return A shared pointer to the main thread - */ -SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority, - Process& owner_process); - -/** * Gets the current thread */ Thread* GetCurrentThread(); diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 6957b16e0..2c4f50e2b 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp @@ -68,9 +68,6 @@ void Timer::Clear() { void Timer::WakeupAllWaitingThreads() { WaitObject::WakeupAllWaitingThreads(); - - if (reset_type == ResetType::Pulse) - signaled = false; } void Timer::Signal(int cycles_late) { diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp index 530ee6af7..90580ed93 100644 --- a/src/core/hle/kernel/wait_object.cpp +++ b/src/core/hle/kernel/wait_object.cpp @@ -4,11 +4,11 @@ #include <algorithm> #include "common/assert.h" +#include "common/common_types.h" #include "common/logging/log.h" #include "core/hle/kernel/object.h" #include "core/hle/kernel/process.h" #include "core/hle/kernel/thread.h" -#include "core/hle/kernel/timer.h" namespace Kernel { diff --git a/src/core/hle/kernel/wait_object.h b/src/core/hle/kernel/wait_object.h index f4367ee28..d70b67893 100644 --- a/src/core/hle/kernel/wait_object.h +++ b/src/core/hle/kernel/wait_object.h @@ -6,7 +6,6 @@ #include <vector> #include <boost/smart_ptr/intrusive_ptr.hpp> -#include "common/common_types.h" #include "core/hle/kernel/object.h" namespace Kernel { diff --git a/src/core/hle/kernel/writable_event.h b/src/core/hle/kernel/writable_event.h index 8fa8d68ee..c9068dd3d 100644 --- a/src/core/hle/kernel/writable_event.h +++ b/src/core/hle/kernel/writable_event.h @@ -4,9 +4,7 @@ #pragma once -#include "common/common_types.h" #include "core/hle/kernel/object.h" -#include "core/hle/kernel/wait_object.h" namespace Kernel { diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index c851e5420..d1cbe0e44 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -39,6 +39,7 @@ namespace Service::AM { constexpr ResultCode ERR_NO_DATA_IN_CHANNEL{ErrorModule::AM, 0x2}; +constexpr ResultCode ERR_NO_MESSAGES{ErrorModule::AM, 0x3}; constexpr ResultCode ERR_SIZE_OUT_OF_BOUNDS{ErrorModule::AM, 0x1F7}; enum class AppletId : u32 { @@ -462,9 +463,17 @@ void ICommonStateGetter::GetEventHandle(Kernel::HLERequestContext& ctx) { void ICommonStateGetter::ReceiveMessage(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called"); + const auto message = msg_queue->PopMessage(); IPC::ResponseBuilder rb{ctx, 3}; + + if (message == AppletMessageQueue::AppletMessage::NoMessage) { + LOG_ERROR(Service_AM, "Message queue is empty"); + rb.Push(ERR_NO_MESSAGES); + rb.PushEnum<AppletMessageQueue::AppletMessage>(message); + return; + } rb.Push(RESULT_SUCCESS); - rb.PushEnum<AppletMessageQueue::AppletMessage>(msg_queue->PopMessage()); + rb.PushEnum<AppletMessageQueue::AppletMessage>(message); } void ICommonStateGetter::GetCurrentFocusState(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/am/applets/applets.cpp b/src/core/hle/service/am/applets/applets.cpp index 7698ca819..a6064c63f 100644 --- a/src/core/hle/service/am/applets/applets.cpp +++ b/src/core/hle/service/am/applets/applets.cpp @@ -6,7 +6,7 @@ #include "common/assert.h" #include "core/core.h" #include "core/hle/kernel/readable_event.h" -#include "core/hle/kernel/server_port.h" +#include "core/hle/kernel/server_session.h" #include "core/hle/kernel/writable_event.h" #include "core/hle/service/am/am.h" #include "core/hle/service/am/applets/applets.h" diff --git a/src/core/hle/service/am/applets/applets.h b/src/core/hle/service/am/applets/applets.h index b0a8913c3..37424c379 100644 --- a/src/core/hle/service/am/applets/applets.h +++ b/src/core/hle/service/am/applets/applets.h @@ -7,7 +7,7 @@ #include <memory> #include <queue> #include "common/swap.h" -#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/object.h" #include "core/hle/kernel/writable_event.h" union ResultCode; diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index 2f15ac2a6..770590d0b 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -111,7 +111,8 @@ static void GenerateErrorReport(ResultCode error_code, const FatalInfo& info) { } static void ThrowFatalError(ResultCode error_code, FatalType fatal_type, const FatalInfo& info) { - LOG_ERROR(Service_Fatal, "Threw fatal error type {}", static_cast<u32>(fatal_type)); + LOG_ERROR(Service_Fatal, "Threw fatal error type {} with error code 0x{:X}", + static_cast<u32>(fatal_type), error_code.raw); switch (fatal_type) { case FatalType::ErrorReportAndScreen: GenerateErrorReport(error_code, info); diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 9ca5461db..1c4482e47 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -9,6 +9,7 @@ #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/readable_event.h" +#include "core/hle/kernel/thread.h" #include "core/hle/kernel/writable_event.h" #include "core/hle/lock.h" #include "core/hle/service/nfp/nfp.h" @@ -19,7 +20,8 @@ namespace Service::NFP { namespace ErrCodes { constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP, -1); // TODO(ogniK): Find the actual error code -} +constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152); +} // namespace ErrCodes Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) : ServiceFramework(name), module(std::move(module)) { @@ -291,10 +293,9 @@ private: } void OpenApplicationArea(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_NFP, "called"); - // We don't need to worry about this since we can just open the file + LOG_WARNING(Service_NFP, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(RESULT_SUCCESS); + rb.Push(ErrCodes::ERR_NO_APPLICATION_AREA); } void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp index 05af2d593..6a613aeab 100644 --- a/src/core/hle/service/nvflinger/nvflinger.cpp +++ b/src/core/hle/service/nvflinger/nvflinger.cpp @@ -166,7 +166,7 @@ Layer::~Layer() = default; Display::Display(u64 id, std::string name) : id(id), name(std::move(name)) { auto& kernel = Core::System::GetInstance().Kernel(); - vsync_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Pulse, + vsync_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Sticky, fmt::format("Display VSync Event {}", id)); } diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 60b201d06..16564de24 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -264,14 +264,12 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_Time, "called"); IPC::RequestParser rp{ctx}; - auto unknown_u8 = rp.PopRaw<u8>(); - - ClockSnapshot clock_snapshot{}; + const auto initial_type = rp.PopRaw<u8>(); const s64 time_since_epoch{std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch()) .count()}; - CalendarTime calendar_time{}; + const std::time_t time(time_since_epoch); const std::tm* tm = std::localtime(&time); if (tm == nullptr) { @@ -280,16 +278,19 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { rb.Push(ResultCode(-1)); // TODO(ogniK): Find appropriate error code return; } - SteadyClockTimePoint steady_clock_time_point{CoreTiming::cyclesToMs(CoreTiming::GetTicks()) / - 1000}; - LocationName location_name{"UTC"}; + const SteadyClockTimePoint steady_clock_time_point{ + CoreTiming::cyclesToMs(CoreTiming::GetTicks()) / 1000, {}}; + + CalendarTime calendar_time{}; calendar_time.year = tm->tm_year + 1900; calendar_time.month = tm->tm_mon + 1; calendar_time.day = tm->tm_mday; calendar_time.hour = tm->tm_hour; calendar_time.minute = tm->tm_min; calendar_time.second = tm->tm_sec; + + ClockSnapshot clock_snapshot{}; clock_snapshot.system_posix_time = time_since_epoch; clock_snapshot.network_posix_time = time_since_epoch; clock_snapshot.system_calendar_time = calendar_time; @@ -302,9 +303,10 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { clock_snapshot.network_calendar_info = additional_info; clock_snapshot.steady_clock_timepoint = steady_clock_time_point; - clock_snapshot.location_name = location_name; + clock_snapshot.location_name = LocationName{"UTC"}; clock_snapshot.clock_auto_adjustment_enabled = 1; - clock_snapshot.ipc_u8 = unknown_u8; + clock_snapshot.type = initial_type; + IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); ctx.WriteBuffer(&clock_snapshot, sizeof(ClockSnapshot)); diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h index ea43fbea7..f11affe95 100644 --- a/src/core/hle/service/time/time.h +++ b/src/core/hle/service/time/time.h @@ -22,7 +22,6 @@ struct CalendarTime { u8 hour; u8 minute; u8 second; - INSERT_PADDING_BYTES(1); }; static_assert(sizeof(CalendarTime) == 0x8, "CalendarTime structure has incorrect size"); @@ -30,7 +29,7 @@ struct CalendarAdditionalInfo { u32_le day_of_week; u32_le day_of_year; std::array<u8, 8> name; - INSERT_PADDING_BYTES(1); + u8 is_dst; s32_le utc_offset; }; static_assert(sizeof(CalendarAdditionalInfo) == 0x18, @@ -42,8 +41,10 @@ struct TimeZoneRule { }; struct SteadyClockTimePoint { + using SourceID = std::array<u8, 16>; + u64_le value; - INSERT_PADDING_WORDS(4); + SourceID source_id; }; static_assert(sizeof(SteadyClockTimePoint) == 0x18, "SteadyClockTimePoint is incorrect size"); @@ -66,8 +67,9 @@ struct ClockSnapshot { SteadyClockTimePoint steady_clock_timepoint; LocationName location_name; u8 clock_auto_adjustment_enabled; - u8 ipc_u8; - INSERT_PADDING_BYTES(2); + u8 type; + u8 version; + INSERT_PADDING_BYTES(1); }; static_assert(sizeof(ClockSnapshot) == 0xd0, "ClockSnapshot is an invalid size"); diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 311b0c765..70c933934 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -19,6 +19,7 @@ #include "core/core_timing.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/readable_event.h" +#include "core/hle/kernel/thread.h" #include "core/hle/kernel/writable_event.h" #include "core/hle/service/nvdrv/nvdrv.h" #include "core/hle/service/nvflinger/buffer_queue.h" @@ -31,12 +32,26 @@ namespace Service::VI { +constexpr ResultCode ERR_OPERATION_FAILED{ErrorModule::VI, 1}; +constexpr ResultCode ERR_UNSUPPORTED{ErrorModule::VI, 6}; + struct DisplayInfo { + /// The name of this particular display. char display_name[0x40]{"Default"}; - u64 unknown_1{1}; - u64 unknown_2{1}; - u64 width{1280}; - u64 height{720}; + + /// Whether or not the display has a limited number of layers. + u8 has_limited_layers{1}; + INSERT_PADDING_BYTES(7){}; + + /// Indicates the total amount of layers supported by the display. + /// @note This is only valid if has_limited_layers is set. + u64 max_layers{1}; + + /// Maximum width in pixels. + u64 width{1920}; + + /// Maximum height in pixels. + u64 height{1080}; }; static_assert(sizeof(DisplayInfo) == 0x60, "DisplayInfo has wrong size"); @@ -502,10 +517,12 @@ private: void TransactParcel(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u32 id = rp.Pop<u32>(); - auto transaction = static_cast<TransactionId>(rp.Pop<u32>()); - u32 flags = rp.Pop<u32>(); - LOG_DEBUG(Service_VI, "called, transaction={:X}", static_cast<u32>(transaction)); + const u32 id = rp.Pop<u32>(); + const auto transaction = static_cast<TransactionId>(rp.Pop<u32>()); + const u32 flags = rp.Pop<u32>(); + + LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id, + static_cast<u32>(transaction), flags); auto buffer_queue = nv_flinger->GetBufferQueue(id); @@ -593,9 +610,10 @@ private: void AdjustRefcount(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u32 id = rp.Pop<u32>(); - s32 addval = rp.PopRaw<s32>(); - u32 type = rp.Pop<u32>(); + const u32 id = rp.Pop<u32>(); + const s32 addval = rp.PopRaw<s32>(); + const u32 type = rp.Pop<u32>(); + LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={:08X}, type={:08X}", id, addval, type); @@ -605,11 +623,12 @@ private: void GetNativeHandle(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u32 id = rp.Pop<u32>(); - u32 unknown = rp.Pop<u32>(); + const u32 id = rp.Pop<u32>(); + const u32 unknown = rp.Pop<u32>(); + LOG_WARNING(Service_VI, "(STUBBED) called id={}, unknown={:08X}", id, unknown); - auto buffer_queue = nv_flinger->GetBufferQueue(id); + const auto buffer_queue = nv_flinger->GetBufferQueue(id); // TODO(Subv): Find out what this actually is. IPC::ResponseBuilder rb{ctx, 2, 1}; @@ -674,11 +693,12 @@ public: private: void SetLayerZ(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u64 layer_id = rp.Pop<u64>(); - u64 z_value = rp.Pop<u64>(); + const u64 layer_id = rp.Pop<u64>(); + const u64 z_value = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}, z_value=0x{:016X}", layer_id, + z_value); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -686,8 +706,9 @@ private: void SetLayerVisibility(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u64 layer_id = rp.Pop<u64>(); - bool visibility = rp.Pop<bool>(); + const u64 layer_id = rp.Pop<u64>(); + const bool visibility = rp.Pop<bool>(); + LOG_WARNING(Service_VI, "(STUBBED) called, layer_id=0x{:08X}, visibility={}", layer_id, visibility); @@ -796,25 +817,27 @@ public: private: void CloseDisplay(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u64 display = rp.Pop<u64>(); + const u64 display = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. display=0x{:016X}", display); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } void CreateManagedLayer(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u32 unknown = rp.Pop<u32>(); + const u32 unknown = rp.Pop<u32>(); rp.Skip(1, false); - u64 display = rp.Pop<u64>(); - u64 aruid = rp.Pop<u64>(); + const u64 display = rp.Pop<u64>(); + const u64 aruid = rp.Pop<u64>(); - u64 layer_id = nv_flinger->CreateLayer(display); + LOG_WARNING(Service_VI, + "(STUBBED) called. unknown=0x{:08X}, display=0x{:016X}, aruid=0x{:016X}", + unknown, display, aruid); + + const u64 layer_id = nv_flinger->CreateLayer(display); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS); @@ -822,11 +845,12 @@ private: } void AddToLayerStack(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u32 stack = rp.Pop<u32>(); - u64 layer_id = rp.Pop<u64>(); + const u32 stack = rp.Pop<u32>(); + const u64 layer_id = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. stack=0x{:08X}, layer_id=0x{:016X}", stack, + layer_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); @@ -834,8 +858,9 @@ private: void SetLayerVisibility(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u64 layer_id = rp.Pop<u64>(); - bool visibility = rp.Pop<bool>(); + const u64 layer_id = rp.Pop<u64>(); + const bool visibility = rp.Pop<bool>(); + LOG_WARNING(Service_VI, "(STUBBED) called, layer_id=0x{:X}, visibility={}", layer_id, visibility); @@ -852,6 +877,22 @@ public: ~IApplicationDisplayService() = default; private: + enum class ConvertedScaleMode : u64 { + Freeze = 0, + ScaleToWindow = 1, + ScaleAndCrop = 2, + None = 3, + PreserveAspectRatio = 4, + }; + + enum class NintendoScaleMode : u32 { + None = 0, + Freeze = 1, + ScaleToWindow = 2, + ScaleAndCrop = 3, + PreserveAspectRatio = 4, + }; + void GetRelayService(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_VI, "(STUBBED) called"); @@ -888,10 +929,23 @@ private: LOG_WARNING(Service_VI, "(STUBBED) called"); IPC::RequestParser rp{ctx}; - auto name_buf = rp.PopRaw<std::array<u8, 0x40>>(); - auto end = std::find(name_buf.begin(), name_buf.end(), '\0'); + const auto name_buf = rp.PopRaw<std::array<char, 0x40>>(); + + OpenDisplayImpl(ctx, std::string_view{name_buf.data(), name_buf.size()}); + } + + void OpenDefaultDisplay(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_VI, "called"); - std::string name(name_buf.begin(), end); + OpenDisplayImpl(ctx, "Default"); + } + + void OpenDisplayImpl(Kernel::HLERequestContext& ctx, std::string_view name) { + const auto trim_pos = name.find('\0'); + + if (trim_pos != std::string_view::npos) { + name.remove_suffix(name.size() - trim_pos); + } ASSERT_MSG(name == "Default", "Non-default displays aren't supported yet"); @@ -901,45 +955,65 @@ private: } void CloseDisplay(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u64 display_id = rp.Pop<u64>(); + const u64 display_id = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } - void GetDisplayResolution(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); + // This literally does nothing internally in the actual service itself, + // and just returns a successful result code regardless of the input. + void SetDisplayEnabled(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_VI, "called."); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + void GetDisplayResolution(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - u64 display_id = rp.Pop<u64>(); + const u64 display_id = rp.Pop<u64>(); + + LOG_DEBUG(Service_VI, "called. display_id=0x{:016X}", display_id); IPC::ResponseBuilder rb{ctx, 6}; rb.Push(RESULT_SUCCESS); - if (Settings::values.use_docked_mode) { - rb.Push(static_cast<u64>(DisplayResolution::DockedWidth) * - static_cast<u32>(Settings::values.resolution_factor)); - rb.Push(static_cast<u64>(DisplayResolution::DockedHeight) * - static_cast<u32>(Settings::values.resolution_factor)); - } else { - rb.Push(static_cast<u64>(DisplayResolution::UndockedWidth) * - static_cast<u32>(Settings::values.resolution_factor)); - rb.Push(static_cast<u64>(DisplayResolution::UndockedHeight) * - static_cast<u32>(Settings::values.resolution_factor)); - } + // This only returns the fixed values of 1280x720 and makes no distinguishing + // between docked and undocked dimensions. We take the liberty of applying + // the resolution scaling factor here. + rb.Push(static_cast<u64>(DisplayResolution::UndockedWidth) * + static_cast<u32>(Settings::values.resolution_factor)); + rb.Push(static_cast<u64>(DisplayResolution::UndockedHeight) * + static_cast<u32>(Settings::values.resolution_factor)); } void SetLayerScalingMode(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u32 scaling_mode = rp.Pop<u32>(); - u64 unknown = rp.Pop<u64>(); + const auto scaling_mode = rp.PopEnum<NintendoScaleMode>(); + const u64 unknown = rp.Pop<u64>(); + + LOG_DEBUG(Service_VI, "called. scaling_mode=0x{:08X}, unknown=0x{:016X}", + static_cast<u32>(scaling_mode), unknown); IPC::ResponseBuilder rb{ctx, 2}; + + if (scaling_mode > NintendoScaleMode::PreserveAspectRatio) { + LOG_ERROR(Service_VI, "Invalid scaling mode provided."); + rb.Push(ERR_OPERATION_FAILED); + return; + } + + if (scaling_mode != NintendoScaleMode::ScaleToWindow && + scaling_mode != NintendoScaleMode::PreserveAspectRatio) { + LOG_ERROR(Service_VI, "Unsupported scaling mode supplied."); + rb.Push(ERR_UNSUPPORTED); + return; + } + rb.Push(RESULT_SUCCESS); } @@ -957,19 +1031,19 @@ private: } void OpenLayer(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_VI, "called"); - IPC::RequestParser rp{ctx}; - auto name_buf = rp.PopRaw<std::array<u8, 0x40>>(); - auto end = std::find(name_buf.begin(), name_buf.end(), '\0'); + const auto name_buf = rp.PopRaw<std::array<u8, 0x40>>(); + const auto end = std::find(name_buf.begin(), name_buf.end(), '\0'); + + const std::string display_name(name_buf.begin(), end); - std::string display_name(name_buf.begin(), end); + const u64 layer_id = rp.Pop<u64>(); + const u64 aruid = rp.Pop<u64>(); - u64 layer_id = rp.Pop<u64>(); - u64 aruid = rp.Pop<u64>(); + LOG_DEBUG(Service_VI, "called. layer_id=0x{:016X}, aruid=0x{:016X}", layer_id, aruid); - u64 display_id = nv_flinger->OpenDisplay(display_name); - u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id); + const u64 display_id = nv_flinger->OpenDisplay(display_name); + const u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id); NativeWindow native_window{buffer_queue_id}; IPC::ResponseBuilder rb{ctx, 4}; @@ -978,17 +1052,17 @@ private: } void CreateStrayLayer(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_VI, "called"); - IPC::RequestParser rp{ctx}; - u32 flags = rp.Pop<u32>(); + const u32 flags = rp.Pop<u32>(); rp.Pop<u32>(); // padding - u64 display_id = rp.Pop<u64>(); + const u64 display_id = rp.Pop<u64>(); + + LOG_DEBUG(Service_VI, "called. flags=0x{:08X}, display_id=0x{:016X}", flags, display_id); // TODO(Subv): What's the difference between a Stray and a Managed layer? - u64 layer_id = nv_flinger->CreateLayer(display_id); - u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id); + const u64 layer_id = nv_flinger->CreateLayer(display_id); + const u32 buffer_queue_id = nv_flinger->GetBufferQueueId(display_id, layer_id); NativeWindow native_window{buffer_queue_id}; IPC::ResponseBuilder rb{ctx, 6}; @@ -998,73 +1072,59 @@ private: } void DestroyStrayLayer(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u64 layer_id = rp.Pop<u64>(); + const u64 layer_id = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } void GetDisplayVsyncEvent(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_VI, "(STUBBED) called"); - IPC::RequestParser rp{ctx}; - u64 display_id = rp.Pop<u64>(); + const u64 display_id = rp.Pop<u64>(); + + LOG_WARNING(Service_VI, "(STUBBED) called. display_id=0x{:016X}", display_id); - auto vsync_event = nv_flinger->GetVsyncEvent(display_id); + const auto vsync_event = nv_flinger->GetVsyncEvent(display_id); IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(RESULT_SUCCESS); rb.PushCopyObjects(vsync_event); } - enum class ConvertedScaleMode : u64 { - None = 0, // VI seems to name this as "Unknown" but lots of games pass it, assume it's no - // scaling/default - Freeze = 1, - ScaleToWindow = 2, - Crop = 3, - NoCrop = 4, - }; - - // This struct is different, currently it's 1:1 but this might change in the future. - enum class NintendoScaleMode : u32 { - None = 0, - Freeze = 1, - ScaleToWindow = 2, - Crop = 3, - NoCrop = 4, - }; - void ConvertScalingMode(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - auto mode = rp.PopEnum<NintendoScaleMode>(); + const auto mode = rp.PopEnum<NintendoScaleMode>(); LOG_DEBUG(Service_VI, "called mode={}", static_cast<u32>(mode)); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(RESULT_SUCCESS); + const auto converted_mode = ConvertScalingModeImpl(mode); + + if (converted_mode.Succeeded()) { + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.PushEnum(*converted_mode); + } else { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(converted_mode.Code()); + } + } + + static ResultVal<ConvertedScaleMode> ConvertScalingModeImpl(NintendoScaleMode mode) { switch (mode) { case NintendoScaleMode::None: - rb.PushEnum(ConvertedScaleMode::None); - break; + return MakeResult(ConvertedScaleMode::None); case NintendoScaleMode::Freeze: - rb.PushEnum(ConvertedScaleMode::Freeze); - break; + return MakeResult(ConvertedScaleMode::Freeze); case NintendoScaleMode::ScaleToWindow: - rb.PushEnum(ConvertedScaleMode::ScaleToWindow); - break; - case NintendoScaleMode::Crop: - rb.PushEnum(ConvertedScaleMode::Crop); - break; - case NintendoScaleMode::NoCrop: - rb.PushEnum(ConvertedScaleMode::NoCrop); - break; + return MakeResult(ConvertedScaleMode::ScaleToWindow); + case NintendoScaleMode::ScaleAndCrop: + return MakeResult(ConvertedScaleMode::ScaleAndCrop); + case NintendoScaleMode::PreserveAspectRatio: + return MakeResult(ConvertedScaleMode::PreserveAspectRatio); default: - UNIMPLEMENTED_MSG("Unknown scaling mode {}", static_cast<u32>(mode)); - rb.PushEnum(ConvertedScaleMode::None); - break; + return ERR_OPERATION_FAILED; } } @@ -1082,9 +1142,9 @@ IApplicationDisplayService::IApplicationDisplayService( "GetIndirectDisplayTransactionService"}, {1000, &IApplicationDisplayService::ListDisplays, "ListDisplays"}, {1010, &IApplicationDisplayService::OpenDisplay, "OpenDisplay"}, - {1011, nullptr, "OpenDefaultDisplay"}, + {1011, &IApplicationDisplayService::OpenDefaultDisplay, "OpenDefaultDisplay"}, {1020, &IApplicationDisplayService::CloseDisplay, "CloseDisplay"}, - {1101, nullptr, "SetDisplayEnabled"}, + {1101, &IApplicationDisplayService::SetDisplayEnabled, "SetDisplayEnabled"}, {1102, &IApplicationDisplayService::GetDisplayResolution, "GetDisplayResolution"}, {2020, &IApplicationDisplayService::OpenLayer, "OpenLayer"}, {2021, nullptr, "CloseLayer"}, diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 0406fbcd9..327db68a5 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt @@ -30,6 +30,8 @@ add_library(video_core STATIC renderer_base.h renderer_opengl/gl_buffer_cache.cpp renderer_opengl/gl_buffer_cache.h + renderer_opengl/gl_global_cache.cpp + renderer_opengl/gl_global_cache.h renderer_opengl/gl_primitive_assembler.cpp renderer_opengl/gl_primitive_assembler.h renderer_opengl/gl_rasterizer.cpp diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index b19b3a75a..0ed7bc5d8 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -135,6 +135,14 @@ void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) { if (regs.reg_array[method_call.method] != method_call.argument) { regs.reg_array[method_call.method] = method_call.argument; + // Shader + constexpr u32 shader_registers_count = + sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32); + if (method_call.method >= MAXWELL3D_REG_INDEX(shader_config[0]) && + method_call.method < MAXWELL3D_REG_INDEX(shader_config[0]) + shader_registers_count) { + dirty_flags.shaders = true; + } + // Vertex format if (method_call.method >= MAXWELL3D_REG_INDEX(vertex_attrib_format) && method_call.method < diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 0faff6fdf..d50e5a126 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -1089,10 +1089,13 @@ public: MemoryManager& memory_manager; struct DirtyFlags { + bool shaders = true; + bool vertex_attrib_format = true; u32 vertex_array = 0xFFFFFFFF; void OnMemoryWrite() { + shaders = true; vertex_array = 0xFFFFFFFF; } }; diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index 47e76d8fe..b68f4fb13 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp @@ -66,8 +66,6 @@ static constexpr ConversionArray morton_to_linear_fns = { MortonCopy<true, PixelFormat::BC6H_UF16>, MortonCopy<true, PixelFormat::BC6H_SF16>, MortonCopy<true, PixelFormat::ASTC_2D_4X4>, - MortonCopy<true, PixelFormat::G8R8U>, - MortonCopy<true, PixelFormat::G8R8S>, MortonCopy<true, PixelFormat::BGRA8>, MortonCopy<true, PixelFormat::RGBA32F>, MortonCopy<true, PixelFormat::RG32F>, @@ -138,8 +136,6 @@ static constexpr ConversionArray linear_to_morton_fns = { MortonCopy<false, PixelFormat::BC6H_SF16>, // TODO(Subv): Swizzling ASTC formats are not supported nullptr, - MortonCopy<false, PixelFormat::G8R8U>, - MortonCopy<false, PixelFormat::G8R8S>, MortonCopy<false, PixelFormat::BGRA8>, MortonCopy<false, PixelFormat::RGBA32F>, MortonCopy<false, PixelFormat::RG32F>, diff --git a/src/video_core/renderer_opengl/gl_global_cache.cpp b/src/video_core/renderer_opengl/gl_global_cache.cpp new file mode 100644 index 000000000..7992b82c4 --- /dev/null +++ b/src/video_core/renderer_opengl/gl_global_cache.cpp @@ -0,0 +1,24 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <glad/glad.h> + +#include "video_core/renderer_opengl/gl_global_cache.h" +#include "video_core/renderer_opengl/gl_rasterizer.h" +#include "video_core/renderer_opengl/utils.h" + +namespace OpenGL { + +CachedGlobalRegion::CachedGlobalRegion(VAddr addr, u32 size) : addr{addr}, size{size} { + buffer.Create(); + // Bind and unbind the buffer so it gets allocated by the driver + glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer.handle); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + LabelGLObject(GL_BUFFER, buffer.handle, addr, "GlobalMemory"); +} + +GlobalRegionCacheOpenGL::GlobalRegionCacheOpenGL(RasterizerOpenGL& rasterizer) + : RasterizerCache{rasterizer} {} + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_global_cache.h b/src/video_core/renderer_opengl/gl_global_cache.h new file mode 100644 index 000000000..406a735bc --- /dev/null +++ b/src/video_core/renderer_opengl/gl_global_cache.h @@ -0,0 +1,60 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> +#include <glad/glad.h> + +#include "common/common_types.h" +#include "video_core/rasterizer_cache.h" +#include "video_core/renderer_opengl/gl_resource_manager.h" + +namespace OpenGL { + +namespace GLShader { +class GlobalMemoryEntry; +} // namespace GLShader + +class RasterizerOpenGL; +class CachedGlobalRegion; +using GlobalRegion = std::shared_ptr<CachedGlobalRegion>; + +class CachedGlobalRegion final : public RasterizerCacheObject { +public: + explicit CachedGlobalRegion(VAddr addr, u32 size); + + /// Gets the address of the shader in guest memory, required for cache management + VAddr GetAddr() const { + return addr; + } + + /// Gets the size of the shader in guest memory, required for cache management + std::size_t GetSizeInBytes() const { + return size; + } + + /// Gets the GL program handle for the buffer + GLuint GetBufferHandle() const { + return buffer.handle; + } + + // TODO(Rodrigo): When global memory is written (STG), implement flushing + void Flush() override { + UNIMPLEMENTED(); + } + +private: + VAddr addr{}; + u32 size{}; + + OGLBuffer buffer; +}; + +class GlobalRegionCacheOpenGL final : public RasterizerCache<GlobalRegion> { +public: + explicit GlobalRegionCacheOpenGL(RasterizerOpenGL& rasterizer); +}; + +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2b29fc45f..73567eb8c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -101,7 +101,7 @@ struct FramebufferCacheKey { RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window, ScreenInfo& info) : res_cache{*this}, shader_cache{*this}, emu_window{window}, screen_info{info}, - buffer_cache(*this, STREAM_BUFFER_SIZE) { + buffer_cache(*this, STREAM_BUFFER_SIZE), global_cache{*this} { // Create sampler objects for (std::size_t i = 0; i < texture_samplers.size(); ++i) { texture_samplers[i].Create(); @@ -293,7 +293,7 @@ DrawParameters RasterizerOpenGL::SetupDraw() { void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { MICROPROFILE_SCOPE(OpenGL_Shader); - const auto& gpu = Core::System::GetInstance().GPU().Maxwell3D(); + auto& gpu = Core::System::GetInstance().GPU().Maxwell3D(); // Next available bindpoints to use when uploading the const buffers and textures to the GLSL // shaders. The constbuffer bindpoint starts after the shader stage configuration bind points. @@ -376,6 +376,8 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { } SyncClipEnabled(clip_distances); + + gpu.dirty_flags.shaders = false; } void RasterizerOpenGL::SetupCachedFramebuffer(const FramebufferCacheKey& fbkey, @@ -761,6 +763,7 @@ void RasterizerOpenGL::InvalidateRegion(VAddr addr, u64 size) { MICROPROFILE_SCOPE(OpenGL_CacheManagement); res_cache.InvalidateRegion(addr, size); shader_cache.InvalidateRegion(addr, size); + global_cache.InvalidateRegion(addr, size); buffer_cache.InvalidateRegion(addr, size); } @@ -1014,8 +1017,11 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, texture_samplers[current_bindpoint].SyncWithConfig(texture.tsc); Surface surface = res_cache.GetTextureSurface(texture, entry); if (surface != nullptr) { - state.texture_units[current_bindpoint].texture = surface->Texture().handle; - state.texture_units[current_bindpoint].target = surface->Target(); + const GLuint handle = + entry.IsArray() ? surface->TextureLayer().handle : surface->Texture().handle; + const GLenum target = entry.IsArray() ? surface->TargetLayer() : surface->Target(); + state.texture_units[current_bindpoint].texture = handle; + state.texture_units[current_bindpoint].target = target; state.texture_units[current_bindpoint].swizzle.r = MaxwellToGL::SwizzleSource(texture.tic.x_source); state.texture_units[current_bindpoint].swizzle.g = diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 8a891ffc7..a53edee6d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -23,6 +23,7 @@ #include "video_core/rasterizer_cache.h" #include "video_core/rasterizer_interface.h" #include "video_core/renderer_opengl/gl_buffer_cache.h" +#include "video_core/renderer_opengl/gl_global_cache.h" #include "video_core/renderer_opengl/gl_primitive_assembler.h" #include "video_core/renderer_opengl/gl_rasterizer_cache.h" #include "video_core/renderer_opengl/gl_resource_manager.h" @@ -66,6 +67,10 @@ public: static_assert(MaxConstbufferSize % sizeof(GLvec4) == 0, "The maximum size of a constbuffer must be a multiple of the size of GLvec4"); + static constexpr std::size_t MaxGlobalMemorySize = 0x10000; + static_assert(MaxGlobalMemorySize % sizeof(float) == 0, + "The maximum size of a global memory must be a multiple of the size of float"); + private: class SamplerInfo { public: @@ -105,7 +110,7 @@ private: bool using_depth_fb = true, bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); - /* + /** * Configures the current constbuffers to use for the draw command. * @param stage The shader stage to configure buffers for. * @param shader The shader object that contains the specified stage. @@ -115,7 +120,7 @@ private: u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, Shader& shader, GLenum primitive_mode, u32 current_bindpoint); - /* + /** * Configures the current textures to use for the draw command. * @param stage The shader stage to configure textures for. * @param shader The shader object that contains the specified stage. @@ -185,6 +190,7 @@ private: RasterizerCacheOpenGL res_cache; ShaderCacheOpenGL shader_cache; + GlobalRegionCacheOpenGL global_cache; Core::Frontend::EmuWindow& emu_window; diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 7ea07631a..bff0c65cd 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -44,6 +44,17 @@ struct FormatTuple { bool compressed; }; +static void ApplyTextureDefaults(GLenum target, u32 max_mip_level) { + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, max_mip_level - 1); + if (max_mip_level == 1) { + glTexParameterf(target, GL_TEXTURE_LOD_BIAS, 1000.0); + } +} + void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) { auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; const auto cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr_)}; @@ -288,8 +299,6 @@ static constexpr std::array<FormatTuple, VideoCore::Surface::MaxPixelFormat> tex {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_RGB, GL_UNSIGNED_INT_8_8_8_8, ComponentType::Float, true}, // BC6H_SF16 {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // ASTC_2D_4X4 - {GL_RG8, GL_RG, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // G8R8U - {GL_RG8, GL_RG, GL_BYTE, ComponentType::SNorm, false}, // G8R8S {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE, ComponentType::UNorm, false}, // BGRA8 {GL_RGBA32F, GL_RGBA, GL_FLOAT, ComponentType::Float, false}, // RGBA32F {GL_RG32F, GL_RG, GL_FLOAT, ComponentType::Float, false}, // RG32F @@ -443,7 +452,7 @@ static void CopySurface(const Surface& src_surface, const Surface& dst_surface, const std::size_t buffer_size = std::max(src_params.size_in_bytes, dst_params.size_in_bytes); glBindBuffer(GL_PIXEL_PACK_BUFFER, copy_pbo_handle); - glBufferData(GL_PIXEL_PACK_BUFFER, buffer_size, nullptr, GL_STREAM_DRAW); + glBufferData(GL_PIXEL_PACK_BUFFER, buffer_size, nullptr, GL_STREAM_COPY); if (source_format.compressed) { glGetCompressedTextureImage(src_surface->Texture().handle, src_attachment, static_cast<GLsizei>(src_params.size_in_bytes), nullptr); @@ -532,6 +541,9 @@ CachedSurface::CachedSurface(const SurfaceParams& params) glActiveTexture(GL_TEXTURE0); const auto& format_tuple = GetFormatTuple(params.pixel_format, params.component_type); + gl_internal_format = format_tuple.internal_format; + gl_is_compressed = format_tuple.compressed; + if (!format_tuple.compressed) { // Only pre-create the texture for non-compressed textures. switch (params.target) { @@ -560,15 +572,7 @@ CachedSurface::CachedSurface(const SurfaceParams& params) } } - glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(SurfaceTargetToGL(params.target), GL_TEXTURE_MAX_LEVEL, - params.max_mip_level - 1); - if (params.max_mip_level == 1) { - glTexParameterf(SurfaceTargetToGL(params.target), GL_TEXTURE_LOD_BIAS, 1000.0); - } + ApplyTextureDefaults(SurfaceTargetToGL(params.target), params.max_mip_level); LabelGLObject(GL_TEXTURE, texture.handle, params.addr, SurfaceParams::SurfaceTargetName(params.target)); @@ -620,18 +624,6 @@ static void ConvertS8Z24ToZ24S8(std::vector<u8>& data, u32 width, u32 height, bo } } -static void ConvertG8R8ToR8G8(std::vector<u8>& data, u32 width, u32 height) { - constexpr auto bpp{GetBytesPerPixel(PixelFormat::G8R8U)}; - for (std::size_t y = 0; y < height; ++y) { - for (std::size_t x = 0; x < width; ++x) { - const std::size_t offset{bpp * (y * width + x)}; - const u8 temp{data[offset]}; - data[offset] = data[offset + 1]; - data[offset + 1] = temp; - } - } -} - /** * Helper function to perform software conversion (as needed) when loading a buffer from Switch * memory. This is for Maxwell pixel formats that cannot be represented as-is in OpenGL or with @@ -664,12 +656,6 @@ static void ConvertFormatAsNeeded_LoadGLBuffer(std::vector<u8>& data, PixelForma // Convert the S8Z24 depth format to Z24S8, as OpenGL does not support S8Z24. ConvertS8Z24ToZ24S8(data, width, height, false); break; - - case PixelFormat::G8R8U: - case PixelFormat::G8R8S: - // Convert the G8R8 color format to R8G8, as OpenGL does not support G8R8. - ConvertG8R8ToR8G8(data, width, height); - break; } } @@ -681,8 +667,6 @@ static void ConvertFormatAsNeeded_LoadGLBuffer(std::vector<u8>& data, PixelForma static void ConvertFormatAsNeeded_FlushGLBuffer(std::vector<u8>& data, PixelFormat pixel_format, u32 width, u32 height) { switch (pixel_format) { - case PixelFormat::G8R8U: - case PixelFormat::G8R8S: case PixelFormat::ASTC_2D_4X4: case PixelFormat::ASTC_2D_8X8: case PixelFormat::ASTC_2D_4X4_SRGB: @@ -886,6 +870,31 @@ void CachedSurface::UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } +void CachedSurface::EnsureTextureView() { + if (texture_view.handle != 0) + return; + // Compressed texture are not being created with immutable storage + UNIMPLEMENTED_IF(gl_is_compressed); + + const GLenum target{TargetLayer()}; + + texture_view.Create(); + glTextureView(texture_view.handle, target, texture.handle, gl_internal_format, 0, + params.max_mip_level, 0, 1); + + OpenGLState cur_state = OpenGLState::GetCurState(); + const auto& old_tex = cur_state.texture_units[0]; + SCOPE_EXIT({ + cur_state.texture_units[0] = old_tex; + cur_state.Apply(); + }); + cur_state.texture_units[0].texture = texture_view.handle; + cur_state.texture_units[0].target = target; + cur_state.Apply(); + + ApplyTextureDefaults(target, params.max_mip_level); +} + MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64)); void CachedSurface::UploadGLTexture(GLuint read_fb_handle, GLuint draw_fb_handle) { if (params.type == SurfaceType::Fill) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.h b/src/video_core/renderer_opengl/gl_rasterizer_cache.h index c710aa245..7223700c4 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.h +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.h @@ -293,10 +293,31 @@ public: return texture; } + const OGLTexture& TextureLayer() { + if (params.is_layered) { + return Texture(); + } + EnsureTextureView(); + return texture_view; + } + GLenum Target() const { return gl_target; } + GLenum TargetLayer() const { + using VideoCore::Surface::SurfaceTarget; + switch (params.target) { + case SurfaceTarget::Texture1D: + return GL_TEXTURE_1D_ARRAY; + case SurfaceTarget::Texture2D: + return GL_TEXTURE_2D_ARRAY; + case SurfaceTarget::TextureCubemap: + return GL_TEXTURE_CUBE_MAP_ARRAY; + } + return Target(); + } + const SurfaceParams& GetSurfaceParams() const { return params; } @@ -311,11 +332,16 @@ public: private: void UploadGLMipmapTexture(u32 mip_map, GLuint read_fb_handle, GLuint draw_fb_handle); + void EnsureTextureView(); + OGLTexture texture; + OGLTexture texture_view; std::vector<std::vector<u8>> gl_buffer; - SurfaceParams params; - GLenum gl_target; - std::size_t cached_size_in_bytes; + SurfaceParams params{}; + GLenum gl_target{}; + GLenum gl_internal_format{}; + bool gl_is_compressed{}; + std::size_t cached_size_in_bytes{}; }; class RasterizerCacheOpenGL final : public RasterizerCache<Surface> { diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index aea6bf1af..c785fffa3 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp @@ -188,6 +188,10 @@ void CachedShader::CalculateProperties() { ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {} Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { + if (!Core::System::GetInstance().GPU().Maxwell3D().dirty_flags.shaders) { + return last_shaders[static_cast<u32>(program)]; + } + const VAddr program_addr{GetShaderAddress(program)}; // Look up shader in the cache based on address @@ -199,7 +203,7 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { Register(shader); } - return shader; + return last_shaders[static_cast<u32>(program)] = shader; } } // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h index de3671acf..768747968 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_cache.h @@ -4,6 +4,7 @@ #pragma once +#include <array> #include <map> #include <memory> @@ -115,6 +116,9 @@ public: /// Gets the current specified shader stage program Shader GetStageProgram(Maxwell::ShaderProgram program); + +private: + std::array<Shader, Maxwell::MaxShaderProgram> last_shaders; }; } // namespace OpenGL diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index a97b1562b..1a344229f 100644 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -196,11 +196,14 @@ PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format, LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type)); UNREACHABLE(); case Tegra::Texture::TextureFormat::G8R8: + // TextureFormat::G8R8 is actually ordered red then green, as such we can use + // PixelFormat::RG8U and PixelFormat::RG8S. This was tested with The Legend of Zelda: Breath + // of the Wild, which uses this format to render the hearts on the UI. switch (component_type) { case Tegra::Texture::ComponentType::UNORM: - return PixelFormat::G8R8U; + return PixelFormat::RG8U; case Tegra::Texture::ComponentType::SNORM: - return PixelFormat::G8R8S; + return PixelFormat::RG8S; } LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type)); UNREACHABLE(); diff --git a/src/video_core/surface.h b/src/video_core/surface.h index e23cfecbc..c2259c3c2 100644 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -38,57 +38,55 @@ enum class PixelFormat { BC6H_UF16 = 20, BC6H_SF16 = 21, ASTC_2D_4X4 = 22, - G8R8U = 23, - G8R8S = 24, - BGRA8 = 25, - RGBA32F = 26, - RG32F = 27, - R32F = 28, - R16F = 29, - R16U = 30, - R16S = 31, - R16UI = 32, - R16I = 33, - RG16 = 34, - RG16F = 35, - RG16UI = 36, - RG16I = 37, - RG16S = 38, - RGB32F = 39, - RGBA8_SRGB = 40, - RG8U = 41, - RG8S = 42, - RG32UI = 43, - R32UI = 44, - ASTC_2D_8X8 = 45, - ASTC_2D_8X5 = 46, - ASTC_2D_5X4 = 47, - BGRA8_SRGB = 48, - DXT1_SRGB = 49, - DXT23_SRGB = 50, - DXT45_SRGB = 51, - BC7U_SRGB = 52, - ASTC_2D_4X4_SRGB = 53, - ASTC_2D_8X8_SRGB = 54, - ASTC_2D_8X5_SRGB = 55, - ASTC_2D_5X4_SRGB = 56, - ASTC_2D_5X5 = 57, - ASTC_2D_5X5_SRGB = 58, - ASTC_2D_10X8 = 59, - ASTC_2D_10X8_SRGB = 60, + BGRA8 = 23, + RGBA32F = 24, + RG32F = 25, + R32F = 26, + R16F = 27, + R16U = 28, + R16S = 29, + R16UI = 30, + R16I = 31, + RG16 = 32, + RG16F = 33, + RG16UI = 34, + RG16I = 35, + RG16S = 36, + RGB32F = 37, + RGBA8_SRGB = 38, + RG8U = 39, + RG8S = 40, + RG32UI = 41, + R32UI = 42, + ASTC_2D_8X8 = 43, + ASTC_2D_8X5 = 44, + ASTC_2D_5X4 = 45, + BGRA8_SRGB = 46, + DXT1_SRGB = 47, + DXT23_SRGB = 48, + DXT45_SRGB = 49, + BC7U_SRGB = 50, + ASTC_2D_4X4_SRGB = 51, + ASTC_2D_8X8_SRGB = 52, + ASTC_2D_8X5_SRGB = 53, + ASTC_2D_5X4_SRGB = 54, + ASTC_2D_5X5 = 55, + ASTC_2D_5X5_SRGB = 56, + ASTC_2D_10X8 = 57, + ASTC_2D_10X8_SRGB = 58, MaxColorFormat, // Depth formats - Z32F = 61, - Z16 = 62, + Z32F = 59, + Z16 = 60, MaxDepthFormat, // DepthStencil formats - Z24S8 = 63, - S8Z24 = 64, - Z32FS8 = 65, + Z24S8 = 61, + S8Z24 = 62, + Z32FS8 = 63, MaxDepthStencilFormat, @@ -149,8 +147,6 @@ constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{ 4, // BC6H_UF16 4, // BC6H_SF16 4, // ASTC_2D_4X4 - 1, // G8R8U - 1, // G8R8S 1, // BGRA8 1, // RGBA32F 1, // RG32F @@ -232,8 +228,6 @@ constexpr std::array<u32, MaxPixelFormat> block_width_table = {{ 4, // BC6H_UF16 4, // BC6H_SF16 4, // ASTC_2D_4X4 - 1, // G8R8U - 1, // G8R8S 1, // BGRA8 1, // RGBA32F 1, // RG32F @@ -309,8 +303,6 @@ constexpr std::array<u32, MaxPixelFormat> block_height_table = {{ 4, // BC6H_UF16 4, // BC6H_SF16 4, // ASTC_2D_4X4 - 1, // G8R8U - 1, // G8R8S 1, // BGRA8 1, // RGBA32F 1, // RG32F @@ -386,8 +378,6 @@ constexpr std::array<u32, MaxPixelFormat> bpp_table = {{ 128, // BC6H_UF16 128, // BC6H_SF16 128, // ASTC_2D_4X4 - 16, // G8R8U - 16, // G8R8S 32, // BGRA8 128, // RGBA32F 64, // RG32F diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index c6378bce9..1f852df4b 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -39,6 +39,8 @@ add_executable(yuzu configuration/configure_input_simple.h configuration/configure_mouse_advanced.cpp configuration/configure_mouse_advanced.h + configuration/configure_profile_manager.cpp + configuration/configure_profile_manager.h configuration/configure_system.cpp configuration/configure_system.h configuration/configure_per_general.cpp @@ -96,6 +98,7 @@ set(UIS configuration/configure_input_simple.ui configuration/configure_mouse_advanced.ui configuration/configure_per_general.ui + configuration/configure_profile_manager.ui configuration/configure_system.ui configuration/configure_touchscreen_advanced.ui configuration/configure_web.ui diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index c4349ccc8..165d70e9c 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -470,6 +470,8 @@ void Config::ReadValues() { qt_config->value("enable_discord_presence", true).toBool(); UISettings::values.screenshot_resolution_factor = static_cast<u16>(qt_config->value("screenshot_resolution_factor", 0).toUInt()); + UISettings::values.select_user_on_boot = + qt_config->value("select_user_on_boot", false).toBool(); qt_config->beginGroup("UIGameList"); UISettings::values.show_unknown = qt_config->value("show_unknown", true).toBool(); @@ -680,7 +682,7 @@ void Config::SaveValues() { qt_config->setValue("title_id", QVariant::fromValue<u64>(elem.first)); qt_config->beginWriteArray("disabled"); for (std::size_t j = 0; j < elem.second.size(); ++j) { - qt_config->setArrayIndex(j); + qt_config->setArrayIndex(static_cast<int>(j)); qt_config->setValue("d", QString::fromStdString(elem.second[j])); } qt_config->endArray(); @@ -693,6 +695,7 @@ void Config::SaveValues() { qt_config->setValue("enable_discord_presence", UISettings::values.enable_discord_presence); qt_config->setValue("screenshot_resolution_factor", UISettings::values.screenshot_resolution_factor); + qt_config->setValue("select_user_on_boot", UISettings::values.select_user_on_boot); qt_config->beginGroup("UIGameList"); qt_config->setValue("show_unknown", UISettings::values.show_unknown); diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index 8706b80d2..3f03f0b77 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>461</width> - <height>659</height> + <width>382</width> + <height>241</height> </rect> </property> <property name="windowTitle"> @@ -15,51 +15,76 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QTabWidget" name="tabWidget"> - <property name="currentIndex"> - <number>0</number> - </property> - <widget class="ConfigureGeneral" name="generalTab"> - <attribute name="title"> - <string>General</string> - </attribute> - </widget> - <widget class="ConfigureGameList" name="gameListTab"> - <attribute name="title"> - <string>Game List</string> - </attribute> - </widget> - <widget class="ConfigureSystem" name="systemTab"> - <attribute name="title"> - <string>System</string> - </attribute> - </widget> - <widget class="ConfigureInputSimple" name="inputTab"> - <attribute name="title"> - <string>Input</string> - </attribute> - </widget> - <widget class="ConfigureGraphics" name="graphicsTab"> - <attribute name="title"> - <string>Graphics</string> - </attribute> - </widget> - <widget class="ConfigureAudio" name="audioTab"> - <attribute name="title"> - <string>Audio</string> - </attribute> - </widget> - <widget class="ConfigureDebug" name="debugTab"> - <attribute name="title"> - <string>Debug</string> - </attribute> - </widget> - <widget class="ConfigureWeb" name="webTab"> - <attribute name="title"> - <string>Web</string> - </attribute> - </widget> - </widget> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QListWidget" name="selectorList"> + <property name="minimumSize"> + <size> + <width>150</width> + <height>0</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>150</width> + <height>16777215</height> + </size> + </property> + </widget> + </item> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="ConfigureGeneral" name="generalTab"> + <attribute name="title"> + <string>General</string> + </attribute> + </widget> + <widget class="ConfigureGameList" name="gameListTab"> + <attribute name="title"> + <string>Game List</string> + </attribute> + </widget> + <widget class="ConfigureSystem" name="systemTab"> + <attribute name="title"> + <string>System</string> + </attribute> + </widget> + <widget class="ConfigureProfileManager" name="profileManagerTab"> + <attribute name="title"> + <string>Profiles</string> + </attribute> + </widget> + <widget class="ConfigureInputSimple" name="inputTab"> + <attribute name="title"> + <string>Input</string> + </attribute> + </widget> + <widget class="ConfigureGraphics" name="graphicsTab"> + <attribute name="title"> + <string>Graphics</string> + </attribute> + </widget> + <widget class="ConfigureAudio" name="audioTab"> + <attribute name="title"> + <string>Audio</string> + </attribute> + </widget> + <widget class="ConfigureDebug" name="debugTab"> + <attribute name="title"> + <string>Debug</string> + </attribute> + </widget> + <widget class="ConfigureWeb" name="webTab"> + <attribute name="title"> + <string>Web</string> + </attribute> + </widget> + </widget> + </item> + </layout> </item> <item> <widget class="QDialogButtonBox" name="buttonBox"> @@ -78,15 +103,15 @@ <container>1</container> </customwidget> <customwidget> - <class>ConfigureGameList</class> + <class>ConfigureSystem</class> <extends>QWidget</extends> - <header>configuration/configure_gamelist.h</header> + <header>configuration/configure_system.h</header> <container>1</container> </customwidget> <customwidget> - <class>ConfigureSystem</class> + <class>ConfigureProfileManager</class> <extends>QWidget</extends> - <header>configuration/configure_system.h</header> + <header>configuration/configure_profile_manager.h</header> <container>1</container> </customwidget> <customwidget> @@ -102,12 +127,6 @@ <container>1</container> </customwidget> <customwidget> - <class>ConfigureInputSimple</class> - <extends>QWidget</extends> - <header>configuration/configure_input_simple.h</header> - <container>1</container> - </customwidget> - <customwidget> <class>ConfigureGraphics</class> <extends>QWidget</extends> <header>configuration/configure_graphics.h</header> @@ -119,6 +138,18 @@ <header>configuration/configure_web.h</header> <container>1</container> </customwidget> + <customwidget> + <class>ConfigureGameList</class> + <extends>QWidget</extends> + <header>configuration/configure_gamelist.h</header> + <container>1</container> + </customwidget> + <customwidget> + <class>ConfigureInputSimple</class> + <extends>QWidget</extends> + <header>configuration/configure_input_simple.h</header> + <container>1</container> + </customwidget> </customwidgets> <resources/> <connections> diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 3905423e9..d802443d0 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <QHash> +#include <QListWidgetItem> #include "core/settings.h" #include "ui_configure.h" #include "yuzu/configuration/config.h" @@ -13,6 +15,13 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, const HotkeyRegistry& registry ui->setupUi(this); ui->generalTab->PopulateHotkeyList(registry); this->setConfiguration(); + this->PopulateSelectionList(); + connect(ui->selectorList, &QListWidget::itemSelectionChanged, this, + &ConfigureDialog::UpdateVisibleTabs); + + adjustSize(); + + ui->selectorList->setCurrentRow(0); } ConfigureDialog::~ConfigureDialog() = default; @@ -23,6 +32,7 @@ void ConfigureDialog::applyConfiguration() { ui->generalTab->applyConfiguration(); ui->gameListTab->applyConfiguration(); ui->systemTab->applyConfiguration(); + ui->profileManagerTab->applyConfiguration(); ui->inputTab->applyConfiguration(); ui->graphicsTab->applyConfiguration(); ui->audioTab->applyConfiguration(); @@ -30,3 +40,41 @@ void ConfigureDialog::applyConfiguration() { ui->webTab->applyConfiguration(); Settings::Apply(); } + +void ConfigureDialog::PopulateSelectionList() { + const std::array<std::pair<QString, QStringList>, 4> items{ + {{tr("General"), {tr("General"), tr("Web"), tr("Debug"), tr("Game List")}}, + {tr("System"), {tr("System"), tr("Profiles"), tr("Audio")}}, + {tr("Graphics"), {tr("Graphics")}}, + {tr("Controls"), {tr("Input")}}}}; + + for (const auto& entry : items) { + auto* const item = new QListWidgetItem(entry.first); + item->setData(Qt::UserRole, entry.second); + + ui->selectorList->addItem(item); + } +} + +void ConfigureDialog::UpdateVisibleTabs() { + const auto items = ui->selectorList->selectedItems(); + if (items.isEmpty()) + return; + + const std::map<QString, QWidget*> widgets = {{tr("General"), ui->generalTab}, + {tr("System"), ui->systemTab}, + {tr("Profiles"), ui->profileManagerTab}, + {tr("Input"), ui->inputTab}, + {tr("Graphics"), ui->graphicsTab}, + {tr("Audio"), ui->audioTab}, + {tr("Debug"), ui->debugTab}, + {tr("Web"), ui->webTab}, + {tr("Game List"), ui->gameListTab}}; + + ui->tabWidget->clear(); + + const QStringList tabs = items[0]->data(Qt::UserRole).toStringList(); + + for (const auto& tab : tabs) + ui->tabWidget->addTab(widgets.find(tab)->second, tab); +} diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index f6df7b827..243d9fa09 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h @@ -24,6 +24,8 @@ public: private: void setConfiguration(); + void UpdateVisibleTabs(); + void PopulateSelectionList(); std::unique_ptr<Ui::ConfigureDialog> ui; }; diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 92a441308..4116b6cd7 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -30,6 +30,7 @@ ConfigureGeneral::~ConfigureGeneral() = default; void ConfigureGeneral::setConfiguration() { ui->toggle_deepscan->setChecked(UISettings::values.gamedir_deepscan); ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); + ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot); ui->theme_combobox->setCurrentIndex(ui->theme_combobox->findData(UISettings::values.theme)); ui->use_cpu_jit->setChecked(Settings::values.use_cpu_jit); ui->enable_nfc->setChecked(Settings::values.enable_nfc); @@ -42,6 +43,7 @@ void ConfigureGeneral::PopulateHotkeyList(const HotkeyRegistry& registry) { void ConfigureGeneral::applyConfiguration() { UISettings::values.gamedir_deepscan = ui->toggle_deepscan->isChecked(); UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); + UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked(); UISettings::values.theme = ui->theme_combobox->itemData(ui->theme_combobox->currentIndex()).toString(); diff --git a/src/yuzu/configuration/configure_general.ui b/src/yuzu/configuration/configure_general.ui index bf37446c6..dff0ad5d0 100644 --- a/src/yuzu/configuration/configure_general.ui +++ b/src/yuzu/configuration/configure_general.ui @@ -38,6 +38,13 @@ </property> </widget> </item> + <item> + <widget class="QCheckBox" name="toggle_user_on_boot"> + <property name="text"> + <string>Prompt for user on game boot</string> + </property> + </widget> + </item> </layout> </item> </layout> diff --git a/src/yuzu/configuration/configure_per_general.cpp b/src/yuzu/configuration/configure_per_general.cpp index dffaba5ed..e13d2eac8 100644 --- a/src/yuzu/configuration/configure_per_general.cpp +++ b/src/yuzu/configuration/configure_per_general.cpp @@ -120,7 +120,7 @@ void ConfigurePerGameGeneral::loadConfiguration() { QPixmap map; const auto bytes = control.second->ReadAllBytes(); - map.loadFromData(bytes.data(), bytes.size()); + map.loadFromData(bytes.data(), static_cast<u32>(bytes.size())); scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); @@ -130,7 +130,7 @@ void ConfigurePerGameGeneral::loadConfiguration() { scene->clear(); QPixmap map; - map.loadFromData(bytes.data(), bytes.size()); + map.loadFromData(bytes.data(), static_cast<u32>(bytes.size())); scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp new file mode 100644 index 000000000..41663e39a --- /dev/null +++ b/src/yuzu/configuration/configure_profile_manager.cpp @@ -0,0 +1,300 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <algorithm> +#include <QFileDialog> +#include <QGraphicsItem> +#include <QGraphicsScene> +#include <QHeaderView> +#include <QMessageBox> +#include <QStandardItemModel> +#include <QTreeView> +#include <QVBoxLayout> +#include "common/assert.h" +#include "common/file_util.h" +#include "common/string_util.h" +#include "core/core.h" +#include "core/hle/service/acc/profile_manager.h" +#include "core/settings.h" +#include "ui_configure_profile_manager.h" +#include "yuzu/configuration/configure_profile_manager.h" +#include "yuzu/util/limitable_input_dialog.h" + +namespace { +// Same backup JPEG used by acc IProfile::GetImage if no jpeg found +constexpr std::array<u8, 107> backup_jpeg{ + 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, + 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, + 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, + 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, + 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, + 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, + 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, +}; + +QString GetImagePath(Service::Account::UUID uuid) { + const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + + "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; + return QString::fromStdString(path); +} + +QString GetAccountUsername(const Service::Account::ProfileManager& manager, + Service::Account::UUID uuid) { + Service::Account::ProfileBase profile; + if (!manager.GetProfileBase(uuid, profile)) { + return {}; + } + + const auto text = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); + return QString::fromStdString(text); +} + +QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) { + return ConfigureProfileManager::tr("%1\n%2", + "%1 is the profile username, %2 is the formatted UUID (e.g. " + "00112233-4455-6677-8899-AABBCCDDEEFF))") + .arg(username, QString::fromStdString(uuid.FormatSwitch())); +} + +QPixmap GetIcon(Service::Account::UUID uuid) { + QPixmap icon{GetImagePath(uuid)}; + + if (!icon) { + icon.fill(Qt::black); + icon.loadFromData(backup_jpeg.data(), static_cast<u32>(backup_jpeg.size())); + } + + return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +} + +QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_text) { + return LimitableInputDialog::GetText(parent, ConfigureProfileManager::tr("Enter Username"), + description_text, 1, + static_cast<int>(Service::Account::profile_username_size)); +} +} // Anonymous namespace + +ConfigureProfileManager ::ConfigureProfileManager(QWidget* parent) + : QWidget(parent), ui(new Ui::ConfigureProfileManager), + profile_manager(std::make_unique<Service::Account::ProfileManager>()) { + ui->setupUi(this); + + layout = new QVBoxLayout; + tree_view = new QTreeView; + item_model = new QStandardItemModel(tree_view); + tree_view->setModel(item_model); + + tree_view->setAlternatingRowColors(true); + tree_view->setSelectionMode(QHeaderView::SingleSelection); + tree_view->setSelectionBehavior(QHeaderView::SelectRows); + tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel); + tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel); + tree_view->setSortingEnabled(true); + tree_view->setEditTriggers(QHeaderView::NoEditTriggers); + tree_view->setUniformRowHeights(true); + tree_view->setIconSize({64, 64}); + tree_view->setContextMenuPolicy(Qt::NoContextMenu); + + item_model->insertColumns(0, 1); + item_model->setHeaderData(0, Qt::Horizontal, "Users"); + + // We must register all custom types with the Qt Automoc system so that we are able to use it + // with signals/slots. In this case, QList falls under the umbrells of custom types. + qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>"); + + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + layout->addWidget(tree_view); + + ui->scrollArea->setLayout(layout); + + connect(tree_view, &QTreeView::clicked, this, &ConfigureProfileManager::SelectUser); + + connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureProfileManager::AddUser); + connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureProfileManager::RenameUser); + connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureProfileManager::DeleteUser); + connect(ui->pm_set_image, &QPushButton::pressed, this, &ConfigureProfileManager::SetUserImage); + + scene = new QGraphicsScene; + ui->current_user_icon->setScene(scene); + + this->setConfiguration(); +} + +ConfigureProfileManager::~ConfigureProfileManager() = default; + +void ConfigureProfileManager::setConfiguration() { + enabled = !Core::System::GetInstance().IsPoweredOn(); + item_model->removeRows(0, item_model->rowCount()); + list_items.clear(); + + PopulateUserList(); + UpdateCurrentUser(); +} + +void ConfigureProfileManager::PopulateUserList() { + const auto& profiles = profile_manager->GetAllUsers(); + for (const auto& user : profiles) { + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(user, profile)) + continue; + + const auto username = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); + + list_items.push_back(QList<QStandardItem*>{new QStandardItem{ + GetIcon(user), FormatUserEntryText(QString::fromStdString(username), user)}}); + } + + for (const auto& item : list_items) + item_model->appendRow(item); +} + +void ConfigureProfileManager::UpdateCurrentUser() { + ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); + + const auto& current_user = profile_manager->GetUser(Settings::values.current_user); + ASSERT(current_user); + const auto username = GetAccountUsername(*profile_manager, *current_user); + + scene->clear(); + scene->addPixmap( + GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + ui->current_user_username->setText(username); +} + +void ConfigureProfileManager::applyConfiguration() { + if (!enabled) + return; + + Settings::Apply(); +} + +void ConfigureProfileManager::SelectUser(const QModelIndex& index) { + Settings::values.current_user = + std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager->GetUserCount() - 1)); + + UpdateCurrentUser(); + + ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); + ui->pm_rename->setEnabled(true); + ui->pm_set_image->setEnabled(true); +} + +void ConfigureProfileManager::AddUser() { + const auto username = + GetProfileUsernameFromUser(this, tr("Enter a username for the new user:")); + if (username.isEmpty()) { + return; + } + + const auto uuid = Service::Account::UUID::Generate(); + profile_manager->CreateNewUser(uuid, username.toStdString()); + + item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); +} + +void ConfigureProfileManager::RenameUser() { + const auto user = tree_view->currentIndex().row(); + const auto uuid = profile_manager->GetUser(user); + ASSERT(uuid); + + Service::Account::ProfileBase profile; + if (!profile_manager->GetProfileBase(*uuid, profile)) + return; + + const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); + if (new_username.isEmpty()) { + return; + } + + const auto username_std = new_username.toStdString(); + std::fill(profile.username.begin(), profile.username.end(), '\0'); + std::copy(username_std.begin(), username_std.end(), profile.username.begin()); + + profile_manager->SetProfileBase(*uuid, profile); + + item_model->setItem( + user, 0, + new QStandardItem{GetIcon(*uuid), + FormatUserEntryText(QString::fromStdString(username_std), *uuid)}); + UpdateCurrentUser(); +} + +void ConfigureProfileManager::DeleteUser() { + const auto index = tree_view->currentIndex().row(); + const auto uuid = profile_manager->GetUser(index); + ASSERT(uuid); + const auto username = GetAccountUsername(*profile_manager, *uuid); + + const auto confirm = QMessageBox::question( + this, tr("Confirm Delete"), + tr("You are about to delete user with name \"%1\". Are you sure?").arg(username)); + + if (confirm == QMessageBox::No) + return; + + if (Settings::values.current_user == tree_view->currentIndex().row()) + Settings::values.current_user = 0; + UpdateCurrentUser(); + + if (!profile_manager->RemoveUser(*uuid)) + return; + + item_model->removeRows(tree_view->currentIndex().row(), 1); + tree_view->clearSelection(); + + ui->pm_remove->setEnabled(false); + ui->pm_rename->setEnabled(false); +} + +void ConfigureProfileManager::SetUserImage() { + const auto index = tree_view->currentIndex().row(); + const auto uuid = profile_manager->GetUser(index); + ASSERT(uuid); + + const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), + tr("JPEG Images (*.jpg *.jpeg)")); + + if (file.isEmpty()) { + return; + } + + const auto image_path = GetImagePath(*uuid); + if (QFile::exists(image_path) && !QFile::remove(image_path)) { + QMessageBox::warning( + this, tr("Error deleting image"), + tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path)); + return; + } + + const auto raw_path = QString::fromStdString( + FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"); + const QFileInfo raw_info{raw_path}; + if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) { + QMessageBox::warning(this, tr("Error deleting file"), + tr("Unable to delete existing file: %1.").arg(raw_path)); + return; + } + + const QString absolute_dst_path = QFileInfo{image_path}.absolutePath(); + if (!QDir{raw_path}.mkpath(absolute_dst_path)) { + QMessageBox::warning( + this, tr("Error creating user image directory"), + tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path)); + return; + } + + if (!QFile::copy(file, image_path)) { + QMessageBox::warning(this, tr("Error copying user image"), + tr("Unable to copy image from %1 to %2").arg(file, image_path)); + return; + } + + const auto username = GetAccountUsername(*profile_manager, *uuid); + item_model->setItem(index, 0, + new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); + UpdateCurrentUser(); +} diff --git a/src/yuzu/configuration/configure_profile_manager.h b/src/yuzu/configuration/configure_profile_manager.h new file mode 100644 index 000000000..7fe95a2a8 --- /dev/null +++ b/src/yuzu/configuration/configure_profile_manager.h @@ -0,0 +1,57 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> + +#include <QList> +#include <QWidget> + +class QGraphicsScene; +class QStandardItem; +class QStandardItemModel; +class QTreeView; +class QVBoxLayout; + +namespace Service::Account { +class ProfileManager; +} + +namespace Ui { +class ConfigureProfileManager; +} + +class ConfigureProfileManager : public QWidget { + Q_OBJECT + +public: + explicit ConfigureProfileManager(QWidget* parent = nullptr); + ~ConfigureProfileManager() override; + + void applyConfiguration(); + void setConfiguration(); + +private: + void PopulateUserList(); + void UpdateCurrentUser(); + + void SelectUser(const QModelIndex& index); + void AddUser(); + void RenameUser(); + void DeleteUser(); + void SetUserImage(); + + QVBoxLayout* layout; + QTreeView* tree_view; + QStandardItemModel* item_model; + QGraphicsScene* scene; + + std::vector<QList<QStandardItem*>> list_items; + + std::unique_ptr<Ui::ConfigureProfileManager> ui; + bool enabled = false; + + std::unique_ptr<Service::Account::ProfileManager> profile_manager; +}; diff --git a/src/yuzu/configuration/configure_profile_manager.ui b/src/yuzu/configuration/configure_profile_manager.ui new file mode 100644 index 000000000..dedba4998 --- /dev/null +++ b/src/yuzu/configuration/configure_profile_manager.ui @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ConfigureProfileManager</class> + <widget class="QWidget" name="ConfigureProfileManager"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>366</width> + <height>483</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="gridGroupBox"> + <property name="title"> + <string>Profile Manager</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <property name="sizeConstraint"> + <enum>QLayout::SetNoConstraint</enum> + </property> + <item row="0" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Current User</string> + </property> + </widget> + </item> + <item> + <widget class="QGraphicsView" name="current_user_icon"> + <property name="minimumSize"> + <size> + <width>48</width> + <height>48</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>48</width> + <height>48</height> + </size> + </property> + <property name="verticalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="horizontalScrollBarPolicy"> + <enum>Qt::ScrollBarAlwaysOff</enum> + </property> + <property name="interactive"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="current_user_username"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Username</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QScrollArea" name="scrollArea"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="widgetResizable"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="2" column="0"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QPushButton" name="pm_set_image"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Set Image</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pm_add"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pm_rename"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Rename</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pm_remove"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QLabel" name="label_disable_info"> + <property name="text"> + <string>Profile management is available only when game is not running.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index ab5d46492..445d01ca0 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -15,7 +15,6 @@ #include "common/file_util.h" #include "common/string_util.h" #include "core/core.h" -#include "core/hle/service/acc/profile_manager.h" #include "core/settings.h" #include "ui_configure_system.h" #include "yuzu/configuration/configure_system.h" @@ -36,64 +35,9 @@ constexpr std::array<int, 12> days_in_month = {{ 30, 31, }}; - -// Same backup JPEG used by acc IProfile::GetImage if no jpeg found -constexpr std::array<u8, 107> backup_jpeg{ - 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x02, 0x02, - 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x06, 0x06, 0x05, - 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a, 0x0c, 0x0f, 0x0c, 0x0a, 0x0b, 0x0e, - 0x0b, 0x09, 0x09, 0x0d, 0x11, 0x0d, 0x0e, 0x0f, 0x10, 0x10, 0x11, 0x10, 0x0a, 0x0c, 0x12, 0x13, - 0x12, 0x10, 0x13, 0x0f, 0x10, 0x10, 0x10, 0xff, 0xc9, 0x00, 0x0b, 0x08, 0x00, 0x01, 0x00, 0x01, - 0x01, 0x01, 0x11, 0x00, 0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, - 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, -}; - -QString GetImagePath(Service::Account::UUID uuid) { - const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + - "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; - return QString::fromStdString(path); -} - -QString GetAccountUsername(const Service::Account::ProfileManager& manager, - Service::Account::UUID uuid) { - Service::Account::ProfileBase profile; - if (!manager.GetProfileBase(uuid, profile)) { - return {}; - } - - const auto text = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); - return QString::fromStdString(text); -} - -QString FormatUserEntryText(const QString& username, Service::Account::UUID uuid) { - return ConfigureSystem::tr("%1\n%2", - "%1 is the profile username, %2 is the formatted UUID (e.g. " - "00112233-4455-6677-8899-AABBCCDDEEFF))") - .arg(username, QString::fromStdString(uuid.FormatSwitch())); -} - -QPixmap GetIcon(Service::Account::UUID uuid) { - QPixmap icon{GetImagePath(uuid)}; - - if (!icon) { - icon.fill(Qt::black); - icon.loadFromData(backup_jpeg.data(), static_cast<u32>(backup_jpeg.size())); - } - - return icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); -} - -QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_text) { - return LimitableInputDialog::GetText(parent, ConfigureSystem::tr("Enter Username"), - description_text, 1, - static_cast<int>(Service::Account::profile_username_size)); -} } // Anonymous namespace -ConfigureSystem::ConfigureSystem(QWidget* parent) - : QWidget(parent), ui(new Ui::ConfigureSystem), - profile_manager(std::make_unique<Service::Account::ProfileManager>()) { +ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { ui->setupUi(this); connect(ui->combo_birthmonth, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, @@ -101,51 +45,12 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, &ConfigureSystem::RefreshConsoleID); - layout = new QVBoxLayout; - tree_view = new QTreeView; - item_model = new QStandardItemModel(tree_view); - tree_view->setModel(item_model); - - tree_view->setAlternatingRowColors(true); - tree_view->setSelectionMode(QHeaderView::SingleSelection); - tree_view->setSelectionBehavior(QHeaderView::SelectRows); - tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel); - tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel); - tree_view->setSortingEnabled(true); - tree_view->setEditTriggers(QHeaderView::NoEditTriggers); - tree_view->setUniformRowHeights(true); - tree_view->setIconSize({64, 64}); - tree_view->setContextMenuPolicy(Qt::NoContextMenu); - - item_model->insertColumns(0, 1); - item_model->setHeaderData(0, Qt::Horizontal, "Users"); - - // We must register all custom types with the Qt Automoc system so that we are able to use it - // with signals/slots. In this case, QList falls under the umbrells of custom types. - qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>"); - - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(0); - layout->addWidget(tree_view); - - ui->scrollArea->setLayout(layout); - - connect(tree_view, &QTreeView::clicked, this, &ConfigureSystem::SelectUser); - - connect(ui->pm_add, &QPushButton::pressed, this, &ConfigureSystem::AddUser); - connect(ui->pm_rename, &QPushButton::pressed, this, &ConfigureSystem::RenameUser); - connect(ui->pm_remove, &QPushButton::pressed, this, &ConfigureSystem::DeleteUser); - connect(ui->pm_set_image, &QPushButton::pressed, this, &ConfigureSystem::SetUserImage); - connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) { ui->rng_seed_edit->setEnabled(checked); if (!checked) ui->rng_seed_edit->setText(QStringLiteral("00000000")); }); - scene = new QGraphicsScene; - ui->current_user_icon->setScene(scene); - this->setConfiguration(); } @@ -156,12 +61,6 @@ void ConfigureSystem::setConfiguration() { ui->combo_language->setCurrentIndex(Settings::values.language_index); - item_model->removeRows(0, item_model->rowCount()); - list_items.clear(); - - PopulateUserList(); - UpdateCurrentUser(); - ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.has_value()); ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.has_value()); @@ -170,37 +69,6 @@ void ConfigureSystem::setConfiguration() { ui->rng_seed_edit->setText(rng_seed); } -void ConfigureSystem::PopulateUserList() { - const auto& profiles = profile_manager->GetAllUsers(); - for (const auto& user : profiles) { - Service::Account::ProfileBase profile; - if (!profile_manager->GetProfileBase(user, profile)) - continue; - - const auto username = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast<const char*>(profile.username.data()), profile.username.size()); - - list_items.push_back(QList<QStandardItem*>{new QStandardItem{ - GetIcon(user), FormatUserEntryText(QString::fromStdString(username), user)}}); - } - - for (const auto& item : list_items) - item_model->appendRow(item); -} - -void ConfigureSystem::UpdateCurrentUser() { - ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); - - const auto& current_user = profile_manager->GetUser(Settings::values.current_user); - ASSERT(current_user); - const auto username = GetAccountUsername(*profile_manager, *current_user); - - scene->clear(); - scene->addPixmap( - GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - ui->current_user_username->setText(username); -} - void ConfigureSystem::ReadSystemSettings() {} void ConfigureSystem::applyConfiguration() { @@ -256,130 +124,3 @@ void ConfigureSystem::RefreshConsoleID() { ui->label_console_id->setText( tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); } - -void ConfigureSystem::SelectUser(const QModelIndex& index) { - Settings::values.current_user = - std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager->GetUserCount() - 1)); - - UpdateCurrentUser(); - - ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); - ui->pm_rename->setEnabled(true); - ui->pm_set_image->setEnabled(true); -} - -void ConfigureSystem::AddUser() { - const auto username = - GetProfileUsernameFromUser(this, tr("Enter a username for the new user:")); - if (username.isEmpty()) { - return; - } - - const auto uuid = Service::Account::UUID::Generate(); - profile_manager->CreateNewUser(uuid, username.toStdString()); - - item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); -} - -void ConfigureSystem::RenameUser() { - const auto user = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(user); - ASSERT(uuid); - - Service::Account::ProfileBase profile; - if (!profile_manager->GetProfileBase(*uuid, profile)) - return; - - const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); - if (new_username.isEmpty()) { - return; - } - - const auto username_std = new_username.toStdString(); - std::fill(profile.username.begin(), profile.username.end(), '\0'); - std::copy(username_std.begin(), username_std.end(), profile.username.begin()); - - profile_manager->SetProfileBase(*uuid, profile); - - item_model->setItem( - user, 0, - new QStandardItem{GetIcon(*uuid), - FormatUserEntryText(QString::fromStdString(username_std), *uuid)}); - UpdateCurrentUser(); -} - -void ConfigureSystem::DeleteUser() { - const auto index = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(index); - ASSERT(uuid); - const auto username = GetAccountUsername(*profile_manager, *uuid); - - const auto confirm = QMessageBox::question( - this, tr("Confirm Delete"), - tr("You are about to delete user with name \"%1\". Are you sure?").arg(username)); - - if (confirm == QMessageBox::No) - return; - - if (Settings::values.current_user == tree_view->currentIndex().row()) - Settings::values.current_user = 0; - UpdateCurrentUser(); - - if (!profile_manager->RemoveUser(*uuid)) - return; - - item_model->removeRows(tree_view->currentIndex().row(), 1); - tree_view->clearSelection(); - - ui->pm_remove->setEnabled(false); - ui->pm_rename->setEnabled(false); -} - -void ConfigureSystem::SetUserImage() { - const auto index = tree_view->currentIndex().row(); - const auto uuid = profile_manager->GetUser(index); - ASSERT(uuid); - - const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), - tr("JPEG Images (*.jpg *.jpeg)")); - - if (file.isEmpty()) { - return; - } - - const auto image_path = GetImagePath(*uuid); - if (QFile::exists(image_path) && !QFile::remove(image_path)) { - QMessageBox::warning( - this, tr("Error deleting image"), - tr("Error occurred attempting to overwrite previous image at: %1.").arg(image_path)); - return; - } - - const auto raw_path = QString::fromStdString( - FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010"); - const QFileInfo raw_info{raw_path}; - if (raw_info.exists() && !raw_info.isDir() && !QFile::remove(raw_path)) { - QMessageBox::warning(this, tr("Error deleting file"), - tr("Unable to delete existing file: %1.").arg(raw_path)); - return; - } - - const QString absolute_dst_path = QFileInfo{image_path}.absolutePath(); - if (!QDir{raw_path}.mkpath(absolute_dst_path)) { - QMessageBox::warning( - this, tr("Error creating user image directory"), - tr("Unable to create directory %1 for storing user images.").arg(absolute_dst_path)); - return; - } - - if (!QFile::copy(file, image_path)) { - QMessageBox::warning(this, tr("Error copying user image"), - tr("Unable to copy image from %1 to %2").arg(file, image_path)); - return; - } - - const auto username = GetAccountUsername(*profile_manager, *uuid); - item_model->setItem(index, 0, - new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); - UpdateCurrentUser(); -} diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 07764e1f7..cf1e54de5 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -9,16 +9,6 @@ #include <QList> #include <QWidget> -class QGraphicsScene; -class QStandardItem; -class QStandardItemModel; -class QTreeView; -class QVBoxLayout; - -namespace Service::Account { -class ProfileManager; -} - namespace Ui { class ConfigureSystem; } @@ -39,21 +29,6 @@ private: void UpdateBirthdayComboBox(int birthmonth_index); void RefreshConsoleID(); - void PopulateUserList(); - void UpdateCurrentUser(); - void SelectUser(const QModelIndex& index); - void AddUser(); - void RenameUser(); - void DeleteUser(); - void SetUserImage(); - - QVBoxLayout* layout; - QTreeView* tree_view; - QStandardItemModel* item_model; - QGraphicsScene* scene; - - std::vector<QList<QStandardItem*>> list_items; - std::unique_ptr<Ui::ConfigureSystem> ui; bool enabled = false; @@ -61,6 +36,4 @@ private: int birthday = 0; int language_index = 0; int sound_index = 0; - - std::unique_ptr<Service::Account::ProfileManager> profile_manager; }; diff --git a/src/yuzu/configuration/configure_system.ui b/src/yuzu/configuration/configure_system.ui index a91580893..74e800c2a 100644 --- a/src/yuzu/configuration/configure_system.ui +++ b/src/yuzu/configuration/configure_system.ui @@ -280,141 +280,17 @@ </widget> </item> <item> - <widget class="QGroupBox" name="gridGroupBox"> - <property name="title"> - <string>Profile Manager</string> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> </property> - <layout class="QGridLayout" name="gridLayout_2"> - <property name="sizeConstraint"> - <enum>QLayout::SetNoConstraint</enum> - </property> - <item row="0" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QLabel" name="label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Current User</string> - </property> - </widget> - </item> - <item> - <widget class="QGraphicsView" name="current_user_icon"> - <property name="minimumSize"> - <size> - <width>48</width> - <height>48</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>48</width> - <height>48</height> - </size> - </property> - <property name="verticalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOff</enum> - </property> - <property name="horizontalScrollBarPolicy"> - <enum>Qt::ScrollBarAlwaysOff</enum> - </property> - <property name="interactive"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="current_user_username"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Username</string> - </property> - </widget> - </item> - </layout> - </item> - <item row="1" column="0"> - <widget class="QScrollArea" name="scrollArea"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="frameShape"> - <enum>QFrame::StyledPanel</enum> - </property> - <property name="widgetResizable"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="2" column="0"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QPushButton" name="pm_set_image"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Set Image</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pm_add"> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pm_rename"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Rename</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pm_remove"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Remove</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> </item> <item> <widget class="QLabel" name="label_disable_info"> diff --git a/src/yuzu/debugger/wait_tree.cpp b/src/yuzu/debugger/wait_tree.cpp index 1adf6e330..0c0864742 100644 --- a/src/yuzu/debugger/wait_tree.cpp +++ b/src/yuzu/debugger/wait_tree.cpp @@ -182,8 +182,6 @@ QString WaitTreeWaitObject::GetResetTypeQString(Kernel::ResetType reset_type) { return tr("one shot"); case Kernel::ResetType::Sticky: return tr("sticky"); - case Kernel::ResetType::Pulse: - return tr("pulse"); } UNREACHABLE(); return {}; @@ -293,8 +291,8 @@ std::vector<std::unique_ptr<WaitTreeItem>> WaitTreeThread::GetChildren() const { QString processor; switch (thread.GetProcessorID()) { - case Kernel::ThreadProcessorId::THREADPROCESSORID_DEFAULT: - processor = tr("default"); + case Kernel::ThreadProcessorId::THREADPROCESSORID_IDEAL: + processor = tr("ideal"); break; case Kernel::ThreadProcessorId::THREADPROCESSORID_0: case Kernel::ThreadProcessorId::THREADPROCESSORID_1: diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4eb73792f..f564de994 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -837,10 +837,26 @@ bool GMainWindow::LoadROM(const QString& filename) { return true; } +void GMainWindow::SelectAndSetCurrentUser() { + QtProfileSelectionDialog dialog(this); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); + dialog.exec(); + + if (dialog.GetStatus()) { + Settings::values.current_user = static_cast<s32>(dialog.GetIndex()); + } +} + void GMainWindow::BootGame(const QString& filename) { LOG_INFO(Frontend, "yuzu starting..."); StoreRecentFile(filename); // Put the filename on top of the list + if (UISettings::values.select_user_on_boot) { + SelectAndSetCurrentUser(); + } + if (!LoadROM(filename)) return; @@ -977,31 +993,25 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target const std::string nand_dir = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir); ASSERT(program_id != 0); - Service::Account::ProfileManager manager{}; - const auto user_ids = manager.GetAllUsers(); - QStringList list; - for (const auto& user_id : user_ids) { - if (user_id == Service::Account::UUID{}) - continue; - Service::Account::ProfileBase base; - if (!manager.GetProfileBase(user_id, base)) - continue; - - list.push_back(QString::fromStdString(Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast<const char*>(base.username.data()), base.username.size()))); - } + const auto select_profile = [this]() -> s32 { + QtProfileSelectionDialog dialog(this); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); + dialog.exec(); - bool ok = false; - const auto index_string = - QInputDialog::getItem(this, tr("Select User"), - tr("Please select the user's save data you would like to open."), - list, Settings::values.current_user, false, &ok); - if (!ok) - return; + if (!dialog.GetStatus()) { + return -1; + } + + return dialog.GetIndex(); + }; - const auto index = list.indexOf(index_string); - ASSERT(index != -1 && index < 8); + const auto index = select_profile(); + if (index == -1) + return; + Service::Account::ProfileManager manager; const auto user_id = manager.GetUser(index); ASSERT(user_id); path = nand_dir + FileSys::SaveDataFactory::GetFullPath(FileSys::SaveDataSpaceId::NandUser, diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 8a0485de9..2d705ad54 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -135,6 +135,8 @@ private: void ShowTelemetryCallout(); void SetDiscordEnabled(bool state); + void SelectAndSetCurrentUser(); + /** * Stores the filename in the recently loaded files list. * The new filename is stored at the beginning of the recently loaded files list. diff --git a/src/yuzu/ui_settings.h b/src/yuzu/ui_settings.h index 58ba240fd..82aaeedb0 100644 --- a/src/yuzu/ui_settings.h +++ b/src/yuzu/ui_settings.h @@ -40,6 +40,8 @@ struct Values { bool confirm_before_closing; bool first_start; + bool select_user_on_boot; + // Discord RPC bool enable_discord_presence; |