diff options
Diffstat (limited to 'src')
51 files changed, 650 insertions, 326 deletions
diff --git a/src/common/settings.h b/src/common/settings.h index 832358036..ce1bc647d 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -368,7 +368,7 @@ struct Values { "udp_input_servers"}; BasicSetting<bool> mouse_panning{false, "mouse_panning"}; - BasicSetting<u8> mouse_panning_sensitivity{1, "mouse_panning_sensitivity"}; + BasicSetting<u8> mouse_panning_sensitivity{10, "mouse_panning_sensitivity"}; BasicSetting<bool> mouse_enabled{false, "mouse_enabled"}; std::string mouse_device; MouseButtonsRaw mouse_buttons; diff --git a/src/common/uuid.h b/src/common/uuid.h index 2e7a18405..0ffa37e7c 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h @@ -20,12 +20,11 @@ struct UUID { constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} [[nodiscard]] constexpr explicit operator bool() const { - return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1]; + return uuid != INVALID_UUID; } [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { - // TODO(DarkLordZach): Replace with uuid == rhs.uuid with C++20 - return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; + return uuid == rhs.uuid; } [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const { diff --git a/src/core/core.cpp b/src/core/core.cpp index 406320ed6..15226cf41 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -216,9 +216,9 @@ struct System::Impl { } ResultStatus Load(System& system, Frontend::EmuWindow& emu_window, const std::string& filepath, - std::size_t program_index) { + u64 program_id, std::size_t program_index) { app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath), - program_index); + program_id, program_index); if (!app_loader) { LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); @@ -269,11 +269,10 @@ struct System::Impl { } } - u64 title_id{0}; - if (app_loader->ReadProgramId(title_id) != Loader::ResultStatus::Success) { + if (app_loader->ReadProgramId(program_id) != Loader::ResultStatus::Success) { LOG_ERROR(Core, "Failed to find title id for ROM (Error {})", load_result); } - perf_stats = std::make_unique<PerfStats>(title_id); + perf_stats = std::make_unique<PerfStats>(program_id); // Reset counters and set time origin to current frame GetAndResetPerfStats(); perf_stats->BeginSystemFrame(); @@ -459,8 +458,8 @@ void System::Shutdown() { } System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::string& filepath, - std::size_t program_index) { - return impl->Load(*this, emu_window, filepath, program_index); + u64 program_id, std::size_t program_index) { + return impl->Load(*this, emu_window, filepath, program_id, program_index); } bool System::IsPoweredOn() const { diff --git a/src/core/core.h b/src/core/core.h index 8b93ba998..b93c32e60 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -175,7 +175,7 @@ public: * @returns ResultStatus code, indicating if the operation succeeded. */ [[nodiscard]] ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath, - std::size_t program_index = 0); + u64 program_id = 0, std::size_t program_index = 0); /** * Indicates if the emulated system is powered on (all subsystems initialized and able to run an diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp index db2f6a955..755d3303e 100644 --- a/src/core/file_sys/card_image.cpp +++ b/src/core/file_sys/card_image.cpp @@ -29,7 +29,7 @@ constexpr std::array partition_names{ "logo", }; -XCI::XCI(VirtualFile file_, std::size_t program_index) +XCI::XCI(VirtualFile file_, u64 program_id, size_t program_index) : file(std::move(file_)), program_nca_status{Loader::ResultStatus::ErrorXCIMissingProgramNCA}, partitions(partition_names.size()), partitions_raw(partition_names.size()), keys{Core::Crypto::KeyManager::Instance()} { @@ -63,12 +63,12 @@ XCI::XCI(VirtualFile file_, std::size_t program_index) secure_partition = std::make_shared<NSP>( main_hfs.GetFile(partition_names[static_cast<std::size_t>(XCIPartition::Secure)]), - program_index); + program_id, program_index); ncas = secure_partition->GetNCAsCollapsed(); program = secure_partition->GetNCA(secure_partition->GetProgramTitleID(), ContentRecordType::Program); - program_nca_status = secure_partition->GetProgramStatus(secure_partition->GetProgramTitleID()); + program_nca_status = secure_partition->GetProgramStatus(); if (program_nca_status == Loader::ResultStatus::ErrorNSPMissingProgramNCA) { program_nca_status = Loader::ResultStatus::ErrorXCIMissingProgramNCA; } @@ -174,6 +174,10 @@ u64 XCI::GetProgramTitleID() const { return secure_partition->GetProgramTitleID(); } +std::vector<u64> XCI::GetProgramTitleIDs() const { + return secure_partition->GetProgramTitleIDs(); +} + u32 XCI::GetSystemUpdateVersion() { const auto update = GetPartition(XCIPartition::Update); if (update == nullptr) { @@ -229,9 +233,11 @@ const std::vector<std::shared_ptr<NCA>>& XCI::GetNCAs() const { } std::shared_ptr<NCA> XCI::GetNCAByType(NCAContentType type) const { - const auto iter = - std::find_if(ncas.begin(), ncas.end(), - [type](const std::shared_ptr<NCA>& nca) { return nca->GetType() == type; }); + const auto program_id = secure_partition->GetProgramTitleID(); + const auto iter = std::find_if( + ncas.begin(), ncas.end(), [this, type, program_id](const std::shared_ptr<NCA>& nca) { + return nca->GetType() == type && nca->GetTitleId() == program_id; + }); return iter == ncas.end() ? nullptr : *iter; } diff --git a/src/core/file_sys/card_image.h b/src/core/file_sys/card_image.h index 4960e90fe..0fd9fa87c 100644 --- a/src/core/file_sys/card_image.h +++ b/src/core/file_sys/card_image.h @@ -78,7 +78,7 @@ enum class XCIPartition : u8 { Update, Normal, Secure, Logo }; class XCI : public ReadOnlyVfsDirectory { public: - explicit XCI(VirtualFile file, std::size_t program_index = 0); + explicit XCI(VirtualFile file, u64 program_id = 0, size_t program_index = 0); ~XCI() override; Loader::ResultStatus GetStatus() const; @@ -104,6 +104,7 @@ public: VirtualFile GetLogoPartitionRaw() const; u64 GetProgramTitleID() const; + std::vector<u64> GetProgramTitleIDs() const; u32 GetSystemUpdateVersion(); u64 GetSystemUpdateTitleID() const; diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index d51d469e3..f192dffa5 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp @@ -20,8 +20,9 @@ namespace FileSys { -NSP::NSP(VirtualFile file_, std::size_t program_index_) - : file(std::move(file_)), program_index(program_index_), status{Loader::ResultStatus::Success}, +NSP::NSP(VirtualFile file_, u64 title_id_, std::size_t program_index_) + : file(std::move(file_)), expected_program_id(title_id_), + program_index(program_index_), status{Loader::ResultStatus::Success}, pfs(std::make_shared<PartitionFilesystem>(file)), keys{Core::Crypto::KeyManager::Instance()} { if (pfs->GetStatus() != Loader::ResultStatus::Success) { status = pfs->GetStatus(); @@ -46,60 +47,59 @@ Loader::ResultStatus NSP::GetStatus() const { return status; } -Loader::ResultStatus NSP::GetProgramStatus(u64 title_id) const { +Loader::ResultStatus NSP::GetProgramStatus() const { if (IsExtractedType() && GetExeFS() != nullptr && FileSys::IsDirectoryExeFS(GetExeFS())) { return Loader::ResultStatus::Success; } - const auto iter = program_status.find(title_id); + const auto iter = program_status.find(GetProgramTitleID()); if (iter == program_status.end()) return Loader::ResultStatus::ErrorNSPMissingProgramNCA; return iter->second; } -u64 NSP::GetFirstTitleID() const { - if (IsExtractedType()) { - return GetProgramTitleID(); - } - - if (program_status.empty()) - return 0; - return program_status.begin()->first; -} - u64 NSP::GetProgramTitleID() const { if (IsExtractedType()) { - if (GetExeFS() == nullptr || !IsDirectoryExeFS(GetExeFS())) { - return 0; - } + return GetExtractedTitleID() + program_index; + } - ProgramMetadata meta; - if (meta.Load(GetExeFS()->GetFile("main.npdm")) == Loader::ResultStatus::Success) { - return meta.GetTitleID(); - } else { - return 0; + auto program_id = expected_program_id; + if (program_id == 0) { + if (!program_status.empty()) { + program_id = program_status.begin()->first; } } - const auto out = GetFirstTitleID(); - if ((out & 0x800) == 0) - return out; + program_id = program_id + program_index; + if (program_status.find(program_id) != program_status.end()) { + return program_id; + } - const auto ids = GetTitleIDs(); + const auto ids = GetProgramTitleIDs(); const auto iter = std::find_if(ids.begin(), ids.end(), [](u64 tid) { return (tid & 0x800) == 0; }); - return iter == ids.end() ? out : *iter; + return iter == ids.end() ? 0 : *iter; +} + +u64 NSP::GetExtractedTitleID() const { + if (GetExeFS() == nullptr || !IsDirectoryExeFS(GetExeFS())) { + return 0; + } + + ProgramMetadata meta; + if (meta.Load(GetExeFS()->GetFile("main.npdm")) == Loader::ResultStatus::Success) { + return meta.GetTitleID(); + } else { + return 0; + } } -std::vector<u64> NSP::GetTitleIDs() const { +std::vector<u64> NSP::GetProgramTitleIDs() const { if (IsExtractedType()) { - return {GetProgramTitleID()}; + return {GetExtractedTitleID()}; } - std::vector<u64> out; - out.reserve(ncas.size()); - for (const auto& kv : ncas) - out.push_back(kv.first); + std::vector<u64> out{program_ids.cbegin(), program_ids.cend()}; return out; } @@ -146,7 +146,7 @@ std::shared_ptr<NCA> NSP::GetNCA(u64 title_id, ContentRecordType type, TitleType if (extracted) LOG_WARNING(Service_FS, "called on an NSP that is of type extracted."); - const auto title_id_iter = ncas.find(title_id + program_index); + const auto title_id_iter = ncas.find(title_id); if (title_id_iter == ncas.end()) return nullptr; @@ -160,7 +160,7 @@ std::shared_ptr<NCA> NSP::GetNCA(u64 title_id, ContentRecordType type, TitleType VirtualFile NSP::GetNCAFile(u64 title_id, ContentRecordType type, TitleType title_type) const { if (extracted) LOG_WARNING(Service_FS, "called on an NSP that is of type extracted."); - const auto nca = GetNCA(title_id, type); + const auto nca = GetNCA(title_id, type, title_type); if (nca != nullptr) return nca->GetBaseFile(); return nullptr; @@ -286,6 +286,7 @@ void NSP::ReadNCAs(const std::vector<VirtualFile>& files) { if (next_nca->GetType() == NCAContentType::Program) { program_status[next_nca->GetTitleId()] = next_nca->GetStatus(); + program_ids.insert(next_nca->GetTitleId() & 0xFFFFFFFFFFFFF000); } if (next_nca->GetStatus() != Loader::ResultStatus::Success && diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h index ecb3b6f15..030f36c09 100644 --- a/src/core/file_sys/submission_package.h +++ b/src/core/file_sys/submission_package.h @@ -6,6 +6,7 @@ #include <map> #include <memory> +#include <set> #include <vector> #include "common/common_types.h" #include "core/file_sys/vfs.h" @@ -27,15 +28,15 @@ enum class ContentRecordType : u8; class NSP : public ReadOnlyVfsDirectory { public: - explicit NSP(VirtualFile file_, std::size_t program_index_ = 0); + explicit NSP(VirtualFile file_, u64 title_id = 0, std::size_t program_index_ = 0); ~NSP() override; Loader::ResultStatus GetStatus() const; - Loader::ResultStatus GetProgramStatus(u64 title_id) const; + Loader::ResultStatus GetProgramStatus() const; // Should only be used when one title id can be assured. - u64 GetFirstTitleID() const; u64 GetProgramTitleID() const; - std::vector<u64> GetTitleIDs() const; + u64 GetExtractedTitleID() const; + std::vector<u64> GetProgramTitleIDs() const; bool IsExtractedType() const; @@ -69,6 +70,7 @@ private: VirtualFile file; + const u64 expected_program_id; const std::size_t program_index; bool extracted = false; @@ -78,6 +80,7 @@ private: std::shared_ptr<PartitionFilesystem> pfs; // Map title id -> {map type -> NCA} std::map<u64, std::map<std::pair<TitleType, ContentRecordType>, std::shared_ptr<NCA>>> ncas; + std::set<u64> program_ids; std::vector<VirtualFile> ticket_files; Core::Crypto::KeyManager& keys; diff --git a/src/core/hle/service/am/applets/applet_controller.cpp b/src/core/hle/service/am/applets/applet_controller.cpp index 12682effe..2721679c1 100644 --- a/src/core/hle/service/am/applets/applet_controller.cpp +++ b/src/core/hle/service/am/applets/applet_controller.cpp @@ -87,6 +87,10 @@ void Controller::Initialize() { case sizeof(ControllerUpdateFirmwareArg): controller_private_arg.mode = ControllerSupportMode::ShowControllerFirmwareUpdate; break; + case sizeof(ControllerKeyRemappingArg): + controller_private_arg.mode = + ControllerSupportMode::ShowControllerKeyRemappingForSystem; + break; default: UNIMPLEMENTED_MSG("Unknown ControllerPrivateArg mode={} with arg_size={}", controller_private_arg.mode, controller_private_arg.arg_size); @@ -99,7 +103,9 @@ void Controller::Initialize() { // This is always 0 (Application) except with ShowControllerFirmwareUpdateForSystem. if (controller_private_arg.caller >= ControllerSupportCaller::MaxControllerSupportCaller) { if (controller_private_arg.flag_1 && - controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate) { + (controller_private_arg.mode == ControllerSupportMode::ShowControllerFirmwareUpdate || + controller_private_arg.mode == + ControllerSupportMode::ShowControllerKeyRemappingForSystem)) { controller_private_arg.caller = ControllerSupportCaller::System; } else { controller_private_arg.caller = ControllerSupportCaller::Application; @@ -121,6 +127,7 @@ void Controller::Initialize() { std::memcpy(&controller_user_arg_old, user_arg.data(), user_arg.size()); break; case ControllerAppletVersion::Version7: + case ControllerAppletVersion::Version8: ASSERT(user_arg.size() == sizeof(ControllerSupportArgNew)); std::memcpy(&controller_user_arg_new, user_arg.data(), user_arg.size()); break; @@ -143,6 +150,16 @@ void Controller::Initialize() { std::memcpy(&controller_update_arg, update_arg.data(), update_arg.size()); break; } + case ControllerSupportMode::ShowControllerKeyRemappingForSystem: { + const auto remapping_arg_storage = broker.PopNormalDataToApplet(); + ASSERT(remapping_arg_storage != nullptr); + + const auto& remapping_arg = remapping_arg_storage->GetData(); + ASSERT(remapping_arg.size() == sizeof(ControllerKeyRemappingArg)); + + std::memcpy(&controller_key_remapping_arg, remapping_arg.data(), remapping_arg.size()); + break; + } default: { UNIMPLEMENTED_MSG("Unimplemented ControllerSupportMode={}", controller_private_arg.mode); break; @@ -179,6 +196,7 @@ void Controller::Execute() { std::vector<ExplainText>(controller_user_arg_old.explain_text.begin(), controller_user_arg_old.explain_text.end())); case ControllerAppletVersion::Version7: + case ControllerAppletVersion::Version8: default: return ConvertToFrontendParameters( controller_private_arg, controller_user_arg_new.header, @@ -210,6 +228,7 @@ void Controller::Execute() { } case ControllerSupportMode::ShowControllerStrapGuide: case ControllerSupportMode::ShowControllerFirmwareUpdate: + case ControllerSupportMode::ShowControllerKeyRemappingForSystem: UNIMPLEMENTED_MSG("ControllerSupportMode={} is not implemented", controller_private_arg.mode); ConfigurationComplete(); diff --git a/src/core/hle/service/am/applets/applet_controller.h b/src/core/hle/service/am/applets/applet_controller.h index 20617e91f..0a34c4fc0 100644 --- a/src/core/hle/service/am/applets/applet_controller.h +++ b/src/core/hle/service/am/applets/applet_controller.h @@ -25,13 +25,15 @@ enum class ControllerAppletVersion : u32_le { Version3 = 0x3, // 1.0.0 - 2.3.0 Version4 = 0x4, // 3.0.0 - 5.1.0 Version5 = 0x5, // 6.0.0 - 7.0.1 - Version7 = 0x7, // 8.0.0+ + Version7 = 0x7, // 8.0.0 - 10.2.0 + Version8 = 0x8, // 11.0.0+ }; enum class ControllerSupportMode : u8 { ShowControllerSupport, ShowControllerStrapGuide, ShowControllerFirmwareUpdate, + ShowControllerKeyRemappingForSystem, MaxControllerSupportMode, }; @@ -78,7 +80,7 @@ struct ControllerSupportArgOld { static_assert(sizeof(ControllerSupportArgOld) == 0x21C, "ControllerSupportArgOld has incorrect size."); -// LibraryAppletVersion 0x7 +// LibraryAppletVersion 0x7, 0x8 struct ControllerSupportArgNew { ControllerSupportArgHeader header{}; std::array<IdentificationColor, 8> identification_colors{}; @@ -95,6 +97,14 @@ struct ControllerUpdateFirmwareArg { static_assert(sizeof(ControllerUpdateFirmwareArg) == 0x4, "ControllerUpdateFirmwareArg has incorrect size."); +struct ControllerKeyRemappingArg { + u64 unknown{}; + u32 unknown_2{}; + INSERT_PADDING_WORDS(1); +}; +static_assert(sizeof(ControllerKeyRemappingArg) == 0x10, + "ControllerKeyRemappingArg has incorrect size."); + struct ControllerSupportResultInfo { s8 player_count{}; INSERT_PADDING_BYTES(3); @@ -128,6 +138,7 @@ private: ControllerSupportArgOld controller_user_arg_old; ControllerSupportArgNew controller_user_arg_new; ControllerUpdateFirmwareArg controller_update_arg; + ControllerKeyRemappingArg controller_key_remapping_arg; bool complete{false}; ResultCode status{ResultSuccess}; bool is_single_mode{false}; diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 228dc6389..199e69e89 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -206,7 +206,8 @@ AppLoader::~AppLoader() = default; * @return std::unique_ptr<AppLoader> a pointer to a loader object; nullptr for unsupported type */ static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::VirtualFile file, - FileType type, std::size_t program_index) { + FileType type, u64 program_id, + std::size_t program_index) { switch (type) { // Standard ELF file format. case FileType::ELF: @@ -227,7 +228,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::V // NX XCI (nX Card Image) file format. case FileType::XCI: return std::make_unique<AppLoader_XCI>(std::move(file), system.GetFileSystemController(), - system.GetContentProvider(), program_index); + system.GetContentProvider(), program_id, + program_index); // NX NAX (NintendoAesXts) file format. case FileType::NAX: @@ -236,7 +238,8 @@ static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::V // NX NSP (Nintendo Submission Package) file format case FileType::NSP: return std::make_unique<AppLoader_NSP>(std::move(file), system.GetFileSystemController(), - system.GetContentProvider(), program_index); + system.GetContentProvider(), program_id, + program_index); // NX KIP (Kernel Internal Process) file format case FileType::KIP: @@ -252,7 +255,7 @@ static std::unique_ptr<AppLoader> GetFileLoader(Core::System& system, FileSys::V } std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file, - std::size_t program_index) { + u64 program_id, std::size_t program_index) { FileType type = IdentifyFile(file); const FileType filename_type = GuessFromFilename(file->GetName()); @@ -266,7 +269,7 @@ std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile LOG_DEBUG(Loader, "Loading file {} as {}...", file->GetName(), GetFileTypeString(type)); - return GetFileLoader(system, std::move(file), type, program_index); + return GetFileLoader(system, std::move(file), type, program_id, program_index); } } // namespace Loader diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index edc8bb257..7b1bac3f7 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -227,6 +227,17 @@ public: } /** + * Get the program ids of the application + * + * @param[out] out_program_ids Reference to store program ids into + * + * @return ResultStatus result of function + */ + virtual ResultStatus ReadProgramIds(std::vector<u64>& out_program_ids) { + return ResultStatus::ErrorNotImplemented; + } + + /** * Get the RomFS of the application * Since the RomFS can be huge, we return a file reference instead of copying to a buffer * @@ -324,6 +335,6 @@ protected: * @return the best loader for this file. */ std::unique_ptr<AppLoader> GetLoader(Core::System& system, FileSys::VirtualFile file, - std::size_t program_index = 0); + u64 program_id = 0, std::size_t program_index = 0); } // namespace Loader diff --git a/src/core/loader/nsp.cpp b/src/core/loader/nsp.cpp index d815a7cd3..8b167ad3c 100644 --- a/src/core/loader/nsp.cpp +++ b/src/core/loader/nsp.cpp @@ -23,10 +23,9 @@ namespace Loader { AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider, + const FileSys::ContentProvider& content_provider, u64 program_id, std::size_t program_index) - : AppLoader(file_), nsp(std::make_unique<FileSys::NSP>(file_, program_index)), - title_id(nsp->GetProgramTitleID()) { + : AppLoader(file_), nsp(std::make_unique<FileSys::NSP>(file_, program_id, program_index)) { if (nsp->GetStatus() != ResultStatus::Success) { return; @@ -46,12 +45,8 @@ AppLoader_NSP::AppLoader_NSP(FileSys::VirtualFile file_, return pm.ParseControlNCA(*control_nca); }(); - if (title_id == 0) { - return; - } - secondary_loader = std::make_unique<AppLoader_NCA>( - nsp->GetNCAFile(title_id, FileSys::ContentRecordType::Program)); + nsp->GetNCAFile(nsp->GetProgramTitleID(), FileSys::ContentRecordType::Program)); } } @@ -68,10 +63,11 @@ FileType AppLoader_NSP::IdentifyType(const FileSys::VirtualFile& nsp_file) { } // Non-Extracted Type case + const auto program_id = nsp.GetProgramTitleID(); if (!nsp.IsExtractedType() && - nsp.GetNCA(nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program) != nullptr && - AppLoader_NCA::IdentifyType(nsp.GetNCAFile( - nsp.GetFirstTitleID(), FileSys::ContentRecordType::Program)) == FileType::NCA) { + nsp.GetNCA(program_id, FileSys::ContentRecordType::Program) != nullptr && + AppLoader_NCA::IdentifyType( + nsp.GetNCAFile(program_id, FileSys::ContentRecordType::Program)) == FileType::NCA) { return FileType::NSP; } } @@ -84,6 +80,8 @@ AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::KProcess& process, Core::S return {ResultStatus::ErrorAlreadyLoaded, {}}; } + const auto title_id = nsp->GetProgramTitleID(); + if (!nsp->IsExtractedType() && title_id == 0) { return {ResultStatus::ErrorNSPMissingProgramNCA, {}}; } @@ -93,7 +91,7 @@ AppLoader_NSP::LoadResult AppLoader_NSP::Load(Kernel::KProcess& process, Core::S return {nsp_status, {}}; } - const auto nsp_program_status = nsp->GetProgramStatus(title_id); + const auto nsp_program_status = nsp->GetProgramStatus(); if (nsp_program_status != ResultStatus::Success) { return {nsp_program_status, {}}; } @@ -134,8 +132,8 @@ ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& out_file) { return ResultStatus::ErrorNoPackedUpdate; } - const auto read = - nsp->GetNCAFile(FileSys::GetUpdateTitleID(title_id), FileSys::ContentRecordType::Program); + const auto read = nsp->GetNCAFile(FileSys::GetUpdateTitleID(nsp->GetProgramTitleID()), + FileSys::ContentRecordType::Program); if (read == nullptr) { return ResultStatus::ErrorNoPackedUpdate; @@ -151,11 +149,15 @@ ResultStatus AppLoader_NSP::ReadUpdateRaw(FileSys::VirtualFile& out_file) { } ResultStatus AppLoader_NSP::ReadProgramId(u64& out_program_id) { - if (title_id == 0) { + out_program_id = nsp->GetProgramTitleID(); + if (out_program_id == 0) { return ResultStatus::ErrorNotInitialized; } + return ResultStatus::Success; +} - out_program_id = title_id; +ResultStatus AppLoader_NSP::ReadProgramIds(std::vector<u64>& out_program_ids) { + out_program_ids = nsp->GetProgramTitleIDs(); return ResultStatus::Success; } diff --git a/src/core/loader/nsp.h b/src/core/loader/nsp.h index 644c0ff58..50406a92e 100644 --- a/src/core/loader/nsp.h +++ b/src/core/loader/nsp.h @@ -28,7 +28,7 @@ class AppLoader_NSP final : public AppLoader { public: explicit AppLoader_NSP(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider, + const FileSys::ContentProvider& content_provider, u64 program_id, std::size_t program_index); ~AppLoader_NSP() override; @@ -51,6 +51,7 @@ public: u64 ReadRomFSIVFCOffset() const override; ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; ResultStatus ReadProgramId(u64& out_program_id) override; + ResultStatus ReadProgramIds(std::vector<u64>& out_program_ids) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; ResultStatus ReadTitle(std::string& title) override; ResultStatus ReadControlData(FileSys::NACP& nacp) override; @@ -67,7 +68,6 @@ private: FileSys::VirtualFile icon_file; std::unique_ptr<FileSys::NACP> nacp_file; - u64 title_id; }; } // namespace Loader diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 635d6ae15..269603eef 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -22,9 +22,9 @@ namespace Loader { AppLoader_XCI::AppLoader_XCI(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider, + const FileSys::ContentProvider& content_provider, u64 program_id, std::size_t program_index) - : AppLoader(file_), xci(std::make_unique<FileSys::XCI>(file_, program_index)), + : AppLoader(file_), xci(std::make_unique<FileSys::XCI>(file_, program_id, program_index)), nca_loader(std::make_unique<AppLoader_NCA>(xci->GetProgramNCAFile())) { if (xci->GetStatus() != ResultStatus::Success) { return; @@ -121,6 +121,11 @@ ResultStatus AppLoader_XCI::ReadProgramId(u64& out_program_id) { return nca_loader->ReadProgramId(out_program_id); } +ResultStatus AppLoader_XCI::ReadProgramIds(std::vector<u64>& out_program_ids) { + out_program_ids = xci->GetProgramTitleIDs(); + return ResultStatus::Success; +} + ResultStatus AppLoader_XCI::ReadIcon(std::vector<u8>& buffer) { if (icon_file == nullptr) { return ResultStatus::ErrorNoControl; @@ -149,8 +154,9 @@ ResultStatus AppLoader_XCI::ReadControlData(FileSys::NACP& control) { } ResultStatus AppLoader_XCI::ReadManualRomFS(FileSys::VirtualFile& out_file) { - const auto nca = xci->GetSecurePartitionNSP()->GetNCA(xci->GetProgramTitleID(), - FileSys::ContentRecordType::HtmlDocument); + const auto nca = + xci->GetSecurePartitionNSP()->GetNCA(xci->GetSecurePartitionNSP()->GetProgramTitleID(), + FileSys::ContentRecordType::HtmlDocument); if (xci->GetStatus() != ResultStatus::Success || nca == nullptr) { return ResultStatus::ErrorXCIMissingPartition; } diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index 708155c30..30caaf90e 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -28,7 +28,7 @@ class AppLoader_XCI final : public AppLoader { public: explicit AppLoader_XCI(FileSys::VirtualFile file_, const Service::FileSystem::FileSystemController& fsc, - const FileSys::ContentProvider& content_provider, + const FileSys::ContentProvider& content_provider, u64 program_id, std::size_t program_index); ~AppLoader_XCI() override; @@ -51,6 +51,7 @@ public: u64 ReadRomFSIVFCOffset() const override; ResultStatus ReadUpdateRaw(FileSys::VirtualFile& out_file) override; ResultStatus ReadProgramId(u64& out_program_id) override; + ResultStatus ReadProgramIds(std::vector<u64>& out_program_ids) override; ResultStatus ReadIcon(std::vector<u8>& buffer) override; ResultStatus ReadTitle(std::string& title) override; ResultStatus ReadControlData(FileSys::NACP& control) override; diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index 1e84eaddd..efcdd85d2 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp @@ -84,7 +84,7 @@ public: std::lock_guard lock{mutex}; const auto axis_value = static_cast<float>(mouse_input->GetMouseState(button).axis.at(axis)); - const float sensitivity = Settings::values.mouse_panning_sensitivity.GetValue() * 0.15f; + const float sensitivity = Settings::values.mouse_panning_sensitivity.GetValue() * 0.10f; return axis_value * sensitivity / (100.0f * range); } diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index 2f7ccdd37..70a0ba09c 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp @@ -115,6 +115,41 @@ public: return state.buttons.at(button); } + bool ToggleButton(int button) { + std::lock_guard lock{mutex}; + + if (!state.toggle_buttons.contains(button) || !state.lock_buttons.contains(button)) { + state.toggle_buttons.insert_or_assign(button, false); + state.lock_buttons.insert_or_assign(button, false); + } + + const bool button_state = state.toggle_buttons.at(button); + const bool button_lock = state.lock_buttons.at(button); + + if (button_lock) { + return button_state; + } + + state.lock_buttons.insert_or_assign(button, true); + + if (button_state) { + state.toggle_buttons.insert_or_assign(button, false); + } else { + state.toggle_buttons.insert_or_assign(button, true); + } + + return !button_state; + } + + bool UnlockButton(int button) { + std::lock_guard lock{mutex}; + if (!state.toggle_buttons.contains(button)) { + return false; + } + state.lock_buttons.insert_or_assign(button, false); + return state.toggle_buttons.at(button); + } + void SetAxis(int axis, Sint16 value) { std::lock_guard lock{mutex}; state.axes.insert_or_assign(axis, value); @@ -130,10 +165,10 @@ public: if (sdl_controller) { return SDL_GameControllerRumble(sdl_controller.get(), amp_low, amp_high, - rumble_max_duration_ms) == 0; + rumble_max_duration_ms) != -1; } else if (sdl_joystick) { return SDL_JoystickRumble(sdl_joystick.get(), amp_low, amp_high, - rumble_max_duration_ms) == 0; + rumble_max_duration_ms) != -1; } return false; @@ -241,6 +276,8 @@ public: private: struct State { std::unordered_map<int, bool> buttons; + std::unordered_map<int, bool> toggle_buttons{}; + std::unordered_map<int, bool> lock_buttons{}; std::unordered_map<int, Sint16> axes; std::unordered_map<int, Uint8> hats; } state; @@ -402,16 +439,25 @@ void SDLState::CloseJoysticks() { class SDLButton final : public Input::ButtonDevice { public: - explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_) - : joystick(std::move(joystick_)), button(button_) {} + explicit SDLButton(std::shared_ptr<SDLJoystick> joystick_, int button_, bool toggle_) + : joystick(std::move(joystick_)), button(button_), toggle(toggle_) {} bool GetStatus() const override { - return joystick->GetButton(button); + const bool button_state = joystick->GetButton(button); + if (!toggle) { + return button_state; + } + + if (button_state) { + return joystick->ToggleButton(button); + } + return joystick->UnlockButton(button); } private: std::shared_ptr<SDLJoystick> joystick; int button; + bool toggle; }; class SDLDirectionButton final : public Input::ButtonDevice { @@ -635,6 +681,7 @@ public: std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override { const std::string guid = params.Get("guid", "0"); const int port = params.Get("port", 0); + const auto toggle = params.Get("toggle", false); auto joystick = state.GetSDLJoystickByGUID(guid, port); @@ -680,7 +727,7 @@ public: const int button = params.Get("button", 0); // This is necessary so accessing GetButton with button won't crash joystick->SetButton(button, false); - return std::make_unique<SDLButton>(joystick, button); + return std::make_unique<SDLButton>(joystick, button, toggle); } private: diff --git a/src/input_common/sdl/sdl_impl.h b/src/input_common/sdl/sdl_impl.h index b77afcbd8..7a9ad6346 100644 --- a/src/input_common/sdl/sdl_impl.h +++ b/src/input_common/sdl/sdl_impl.h @@ -10,15 +10,7 @@ #include <thread> #include <unordered_map> -// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -#endif #include <SDL.h> -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif #include "common/common_types.h" #include "common/threadsafe_queue.h" diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 2871682f6..7373cb62d 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -164,11 +164,16 @@ public: /// Pop asynchronous downloads void PopAsyncFlushes(); - [[nodiscard]] bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount); + bool DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount); + + bool DMAClear(GPUVAddr src_address, u64 amount, u32 value); /// Return true when a CPU region is modified from the GPU [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); + /// Return true when a region is registered on the cache + [[nodiscard]] bool IsRegionRegistered(VAddr addr, size_t size); + /// Return true when a CPU region is modified from the CPU [[nodiscard]] bool IsRegionCpuModified(VAddr addr, size_t size); @@ -324,6 +329,8 @@ private: [[nodiscard]] bool HasFastUniformBufferBound(size_t stage, u32 binding_index) const noexcept; + void ClearDownload(IntervalType subtract_interval); + VideoCore::RasterizerInterface& rasterizer; Tegra::Engines::Maxwell3D& maxwell3d; Tegra::Engines::KeplerCompute& kepler_compute; @@ -463,23 +470,28 @@ void BufferCache<P>::DownloadMemory(VAddr cpu_addr, u64 size) { } template <class P> +void BufferCache<P>::ClearDownload(IntervalType subtract_interval) { + uncommitted_ranges.subtract(subtract_interval); + for (auto& interval_set : committed_ranges) { + interval_set.subtract(subtract_interval); + } +} + +template <class P> bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { const std::optional<VAddr> cpu_src_address = gpu_memory.GpuToCpuAddress(src_address); const std::optional<VAddr> cpu_dest_address = gpu_memory.GpuToCpuAddress(dest_address); if (!cpu_src_address || !cpu_dest_address) { return false; } - const bool source_dirty = IsRegionGpuModified(*cpu_src_address, amount); - const bool dest_dirty = IsRegionGpuModified(*cpu_dest_address, amount); + const bool source_dirty = IsRegionRegistered(*cpu_src_address, amount); + const bool dest_dirty = IsRegionRegistered(*cpu_dest_address, amount); if (!source_dirty && !dest_dirty) { return false; } const IntervalType subtract_interval{*cpu_dest_address, *cpu_dest_address + amount}; - uncommitted_ranges.subtract(subtract_interval); - for (auto& interval_set : committed_ranges) { - interval_set.subtract(subtract_interval); - } + ClearDownload(subtract_interval); BufferId buffer_a; BufferId buffer_b; @@ -510,12 +522,13 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am ForEachWrittenRange(*cpu_src_address, amount, mirror); // This subtraction in this order is important for overlapping copies. common_ranges.subtract(subtract_interval); + bool atleast_1_download = tmp_intervals.size() != 0; for (const IntervalType add_interval : tmp_intervals) { common_ranges.add(add_interval); } runtime.CopyBuffer(dest_buffer, src_buffer, copies); - if (source_dirty) { + if (atleast_1_download) { dest_buffer.MarkRegionAsGpuModified(*cpu_dest_address, amount); } std::vector<u8> tmp_buffer(amount); @@ -525,6 +538,33 @@ bool BufferCache<P>::DMACopy(GPUVAddr src_address, GPUVAddr dest_address, u64 am } template <class P> +bool BufferCache<P>::DMAClear(GPUVAddr dst_address, u64 amount, u32 value) { + const std::optional<VAddr> cpu_dst_address = gpu_memory.GpuToCpuAddress(dst_address); + if (!cpu_dst_address) { + return false; + } + const bool dest_dirty = IsRegionRegistered(*cpu_dst_address, amount); + if (!dest_dirty) { + return false; + } + + const size_t size = amount * sizeof(u32); + const IntervalType subtract_interval{*cpu_dst_address, *cpu_dst_address + size}; + ClearDownload(subtract_interval); + common_ranges.subtract(subtract_interval); + + BufferId buffer; + do { + has_deleted_buffers = false; + buffer = FindBuffer(*cpu_dst_address, static_cast<u32>(size)); + } while (has_deleted_buffers); + auto& dest_buffer = slot_buffers[buffer]; + const u32 offset = static_cast<u32>(*cpu_dst_address - dest_buffer.CpuAddr()); + runtime.ClearBuffer(dest_buffer, offset, size, value); + return true; +} + +template <class P> void BufferCache<P>::BindGraphicsUniformBuffer(size_t stage, u32 index, GPUVAddr gpu_addr, u32 size) { const std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); @@ -782,6 +822,27 @@ bool BufferCache<P>::IsRegionGpuModified(VAddr addr, size_t size) { } template <class P> +bool BufferCache<P>::IsRegionRegistered(VAddr addr, size_t size) { + const VAddr end_addr = addr + size; + const u64 page_end = Common::DivCeil(end_addr, PAGE_SIZE); + for (u64 page = addr >> PAGE_BITS; page < page_end;) { + const BufferId buffer_id = page_table[page]; + if (!buffer_id) { + ++page; + continue; + } + Buffer& buffer = slot_buffers[buffer_id]; + const VAddr buf_start_addr = buffer.CpuAddr(); + const VAddr buf_end_addr = buf_start_addr + buffer.SizeBytes(); + if (buf_start_addr < end_addr && addr < buf_end_addr) { + return true; + } + page = Common::DivCeil(end_addr, PAGE_SIZE); + } + return false; +} + +template <class P> bool BufferCache<P>::IsRegionCpuModified(VAddr addr, size_t size) { const u64 page_end = Common::DivCeil(addr + size, PAGE_SIZE); for (u64 page = addr >> PAGE_BITS; page < page_end;) { @@ -1425,6 +1486,7 @@ void BufferCache<P>::DownloadBufferMemory(Buffer& buffer, VAddr cpu_addr, u64 si const VAddr end_address = start_address + range_size; ForEachWrittenRange(start_address, range_size, add_download); const IntervalType subtract_interval{start_address, end_address}; + ClearDownload(subtract_interval); common_ranges.subtract(subtract_interval); }); if (total_size_bytes == 0) { diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index 24481952b..c51776466 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp @@ -4,6 +4,7 @@ #include "common/assert.h" #include "common/logging/log.h" +#include "common/microprofile.h" #include "common/settings.h" #include "core/core.h" #include "video_core/engines/maxwell_3d.h" @@ -12,6 +13,9 @@ #include "video_core/renderer_base.h" #include "video_core/textures/decoders.h" +MICROPROFILE_DECLARE(GPU_DMAEngine); +MICROPROFILE_DEFINE(GPU_DMAEngine, "GPU", "DMA Engine", MP_RGB(224, 224, 128)); + namespace Tegra::Engines { using namespace Texture; @@ -43,6 +47,7 @@ void MaxwellDMA::CallMultiMethod(u32 method, const u32* base_start, u32 amount, } void MaxwellDMA::Launch() { + MICROPROFILE_SCOPE(GPU_DMAEngine); LOG_TRACE(Render_OpenGL, "DMA copy 0x{:x} -> 0x{:x}", static_cast<GPUVAddr>(regs.offset_in), static_cast<GPUVAddr>(regs.offset_out)); @@ -87,9 +92,11 @@ void MaxwellDMA::CopyPitchToPitch() { // TODO: allow multisized components. if (is_buffer_clear) { ASSERT(regs.remap_const.component_size_minus_one == 3); + accelerate.BufferClear(regs.offset_out, regs.line_length_in, regs.remap_consta_value); std::vector<u32> tmp_buffer(regs.line_length_in, regs.remap_consta_value); - memory_manager.WriteBlock(regs.offset_out, reinterpret_cast<u8*>(tmp_buffer.data()), - regs.line_length_in * sizeof(u32)); + memory_manager.WriteBlockUnsafe(regs.offset_out, + reinterpret_cast<u8*>(tmp_buffer.data()), + regs.line_length_in * sizeof(u32)); return; } UNIMPLEMENTED_IF(regs.launch_dma.remap_enable != 0); @@ -179,8 +186,13 @@ void MaxwellDMA::CopyPitchToBlockLinear() { write_buffer.resize(dst_size); } - memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); - memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); + if (Settings::IsGPULevelExtreme()) { + memory_manager.ReadBlock(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlock(regs.offset_out, write_buffer.data(), dst_size); + } else { + memory_manager.ReadBlockUnsafe(regs.offset_in, read_buffer.data(), src_size); + memory_manager.ReadBlockUnsafe(regs.offset_out, write_buffer.data(), dst_size); + } // If the input is linear and the output is tiled, swizzle the input and copy it over. if (regs.dst_params.block_size.depth > 0) { diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h index 4ed0d0996..d3329b0f8 100644 --- a/src/video_core/engines/maxwell_dma.h +++ b/src/video_core/engines/maxwell_dma.h @@ -31,6 +31,8 @@ class AccelerateDMAInterface { public: /// Write the value to the register identified by method. virtual bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) = 0; + + virtual bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) = 0; }; /** diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.cpp b/src/video_core/renderer_opengl/gl_buffer_cache.cpp index c225d1fc9..c4189fb60 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_buffer_cache.cpp @@ -98,6 +98,12 @@ void BufferCacheRuntime::CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer, } } +void BufferCacheRuntime::ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value) { + glClearNamedBufferSubData(dest_buffer.Handle(), GL_R32UI, static_cast<GLintptr>(offset), + static_cast<GLsizeiptr>(size / sizeof(u32)), GL_RGBA, GL_UNSIGNED_INT, + &value); +} + void BufferCacheRuntime::BindIndexBuffer(Buffer& buffer, u32 offset, u32 size) { if (has_unified_vertex_buffers) { buffer.MakeResident(GL_READ_ONLY); diff --git a/src/video_core/renderer_opengl/gl_buffer_cache.h b/src/video_core/renderer_opengl/gl_buffer_cache.h index d8b20a9af..fe91aa452 100644 --- a/src/video_core/renderer_opengl/gl_buffer_cache.h +++ b/src/video_core/renderer_opengl/gl_buffer_cache.h @@ -57,6 +57,8 @@ public: void CopyBuffer(Buffer& dst_buffer, Buffer& src_buffer, std::span<const VideoCommon::BufferCopy> copies); + void ClearBuffer(Buffer& dest_buffer, u32 offset, size_t size, u32 value); + void BindIndexBuffer(Buffer& buffer, u32 offset, u32 size); void BindVertexBuffer(u32 index, Buffer& buffer, u32 offset, u32 size, u32 stride); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 82c84127a..ceb3abcb2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -1407,4 +1407,9 @@ bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 return buffer_cache.DMACopy(src_address, dest_address, amount); } +bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) { + std::scoped_lock lock{buffer_cache.mutex}; + return buffer_cache.DMAClear(src_address, amount, value); +} + } // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index ccee9ba33..d30ad698f 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -65,6 +65,8 @@ public: bool BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) override; + bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override; + private: BufferCache& buffer_cache; }; diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index 25fe61566..cf3b789e3 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h @@ -122,7 +122,7 @@ private: bool has_broken_texture_view_formats = false; StagingBuffers upload_buffers{GL_MAP_WRITE_BIT, GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT}; - StagingBuffers download_buffers{GL_MAP_READ_BIT, GL_MAP_READ_BIT}; + StagingBuffers download_buffers{GL_MAP_READ_BIT | GL_CLIENT_STORAGE_BIT, GL_MAP_READ_BIT}; OGLTexture null_image_1d_array; OGLTexture null_image_cube_array; diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp index 0df4e1a1c..0def1e769 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp @@ -136,6 +136,30 @@ void BufferCacheRuntime::CopyBuffer(VkBuffer dst_buffer, VkBuffer src_buffer, }); } +void BufferCacheRuntime::ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value) { + static constexpr VkMemoryBarrier READ_BARRIER{ + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, + .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, + }; + static constexpr VkMemoryBarrier WRITE_BARRIER{ + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, + }; + + scheduler.RequestOutsideRenderPassOperationContext(); + scheduler.Record([dest_buffer, offset, size, value](vk::CommandBuffer cmdbuf) { + cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, READ_BARRIER); + cmdbuf.FillBuffer(dest_buffer, offset, size, value); + cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, WRITE_BARRIER); + }); +} + void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 base_vertex, u32 num_indices, VkBuffer buffer, u32 offset, [[maybe_unused]] u32 size) { @@ -152,8 +176,8 @@ void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat } if (vk_buffer == VK_NULL_HANDLE) { // Vulkan doesn't support null index buffers. Replace it with our own null buffer. - ReserveNullIndexBuffer(); - vk_buffer = *null_index_buffer; + ReserveNullBuffer(); + vk_buffer = *null_buffer; } scheduler.Record([vk_buffer, vk_offset, vk_index_type](vk::CommandBuffer cmdbuf) { cmdbuf.BindIndexBuffer(vk_buffer, vk_offset, vk_index_type); @@ -161,6 +185,13 @@ void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat } void BufferCacheRuntime::BindQuadArrayIndexBuffer(u32 first, u32 count) { + if (count == 0) { + ReserveNullBuffer(); + scheduler.Record([this](vk::CommandBuffer cmdbuf) { + cmdbuf.BindIndexBuffer(*null_buffer, 0, VK_INDEX_TYPE_UINT32); + }); + return; + } ReserveQuadArrayLUT(first + count, true); // The LUT has the indices 0, 1, 2, and 3 copied as an array @@ -195,6 +226,14 @@ void BufferCacheRuntime::BindTransformFeedbackBuffer(u32 index, VkBuffer buffer, // Already logged in the rasterizer return; } + if (buffer == VK_NULL_HANDLE) { + // Vulkan doesn't support null transform feedback buffers. + // Replace it with our own null buffer. + ReserveNullBuffer(); + buffer = *null_buffer; + offset = 0; + size = 0; + } scheduler.Record([index, buffer, offset, size](vk::CommandBuffer cmdbuf) { const VkDeviceSize vk_offset = offset; const VkDeviceSize vk_size = size; @@ -279,11 +318,11 @@ void BufferCacheRuntime::ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle }); } -void BufferCacheRuntime::ReserveNullIndexBuffer() { - if (null_index_buffer) { +void BufferCacheRuntime::ReserveNullBuffer() { + if (null_buffer) { return; } - null_index_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{ + null_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{ .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .pNext = nullptr, .flags = 0, @@ -294,12 +333,12 @@ void BufferCacheRuntime::ReserveNullIndexBuffer() { .pQueueFamilyIndices = nullptr, }); if (device.HasDebuggingToolAttached()) { - null_index_buffer.SetObjectNameEXT("Null index buffer"); + null_buffer.SetObjectNameEXT("Null index buffer"); } - null_index_buffer_commit = memory_allocator.Commit(null_index_buffer, MemoryUsage::DeviceLocal); + null_buffer_commit = memory_allocator.Commit(null_buffer, MemoryUsage::DeviceLocal); scheduler.RequestOutsideRenderPassOperationContext(); - scheduler.Record([buffer = *null_index_buffer](vk::CommandBuffer cmdbuf) { + scheduler.Record([buffer = *null_buffer](vk::CommandBuffer cmdbuf) { cmdbuf.FillBuffer(buffer, 0, VK_WHOLE_SIZE, 0); }); } diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h index 982e92191..3bb81d5b3 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.h +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h @@ -60,6 +60,8 @@ public: void CopyBuffer(VkBuffer src_buffer, VkBuffer dst_buffer, std::span<const VideoCommon::BufferCopy> copies); + void ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t size, u32 value); + void BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format, u32 num_indices, u32 base_vertex, VkBuffer buffer, u32 offset, u32 size); @@ -92,7 +94,7 @@ private: void ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle); - void ReserveNullIndexBuffer(); + void ReserveNullBuffer(); const Device& device; MemoryAllocator& memory_allocator; @@ -105,8 +107,8 @@ private: VkIndexType quad_array_lut_index_type{}; u32 current_num_indices = 0; - vk::Buffer null_index_buffer; - MemoryCommit null_index_buffer_commit; + vk::Buffer null_buffer; + MemoryCommit null_buffer_commit; Uint8Pass uint8_pass; QuadIndexedPass quad_index_pass; diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp index 205cd3b05..4181d83ee 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp @@ -374,20 +374,20 @@ void ASTCDecoderPass::MakeDataBuffer() { scheduler.Record([src = staging_ref.buffer, offset = staging_ref.offset, dst = *data_buffer, TOTAL_BUFFER_SIZE](vk::CommandBuffer cmdbuf) { - cmdbuf.CopyBuffer(src, dst, - VkBufferCopy{ - .srcOffset = offset, - .dstOffset = 0, - .size = TOTAL_BUFFER_SIZE, - }); - cmdbuf.PipelineBarrier( - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, - VkMemoryBarrier{ - .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, - .pNext = nullptr, - .srcAccessMask = 0, - .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, - }); + static constexpr VkMemoryBarrier write_barrier{ + .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, + .pNext = nullptr, + .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, + .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, + }; + const VkBufferCopy copy{ + .srcOffset = offset, + .dstOffset = 0, + .size = TOTAL_BUFFER_SIZE, + }; + cmdbuf.CopyBuffer(src, dst, copy); + cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + 0, write_barrier); }); } @@ -411,7 +411,7 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map, const VkImageMemoryBarrier image_barrier{ .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .pNext = nullptr, - .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT, + .srcAccessMask = is_initialized ? VK_ACCESS_SHADER_WRITE_BIT : VkAccessFlags{}, .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, .oldLayout = is_initialized ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_UNDEFINED, .newLayout = VK_IMAGE_LAYOUT_GENERAL, @@ -426,7 +426,8 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map, .layerCount = VK_REMAINING_ARRAY_LAYERS, }, }; - cmdbuf.PipelineBarrier(is_initialized ? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT : 0, + cmdbuf.PipelineBarrier(is_initialized ? VK_PIPELINE_STAGE_ALL_COMMANDS_BIT + : VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, image_barrier); cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, vk_pipeline); }); diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index a8ffbe6ba..f57c15b37 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -706,6 +706,11 @@ void RasterizerVulkan::FlushWork() { AccelerateDMA::AccelerateDMA(BufferCache& buffer_cache_) : buffer_cache{buffer_cache_} {} +bool AccelerateDMA::BufferClear(GPUVAddr src_address, u64 amount, u32 value) { + std::scoped_lock lock{buffer_cache.mutex}; + return buffer_cache.DMAClear(src_address, amount, value); +} + bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 amount) { std::scoped_lock lock{buffer_cache.mutex}; return buffer_cache.DMACopy(src_address, dest_address, amount); diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 3a78de258..2065209be 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h @@ -56,6 +56,8 @@ public: bool BufferCopy(GPUVAddr start_address, GPUVAddr end_address, u64 amount) override; + bool BufferClear(GPUVAddr src_address, u64 amount, u32 value) override; + private: BufferCache& buffer_cache; }; diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index a2ab4d1ee..fd01c902c 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp @@ -608,7 +608,10 @@ void TextureCacheRuntime::BlitImage(Framebuffer* dst_framebuffer, ImageView& dst const VkImageAspectFlags aspect_mask = ImageAspectMask(src.format); const bool is_dst_msaa = dst.Samples() != VK_SAMPLE_COUNT_1_BIT; const bool is_src_msaa = src.Samples() != VK_SAMPLE_COUNT_1_BIT; - ASSERT(aspect_mask == ImageAspectMask(dst.format)); + if (aspect_mask != ImageAspectMask(dst.format)) { + UNIMPLEMENTED_MSG("Incompatible blit from format {} to {}", src.format, dst.format); + return; + } if (aspect_mask == VK_IMAGE_ASPECT_COLOR_BIT && !is_src_msaa && !is_dst_msaa) { blit_image_helper.BlitColor(dst_framebuffer, src, dst_region, src_region, filter, operation); @@ -911,6 +914,7 @@ void Image::UploadMemory(const StagingBufferRef& map, void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); + scheduler->RequestOutsideRenderPassOperationContext(); scheduler->Record([buffer = map.buffer, image = *image, aspect_mask = aspect_mask, vk_copies](vk::CommandBuffer cmdbuf) { const VkImageMemoryBarrier read_barrier{ diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 01de2d498..85ce06d56 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -599,6 +599,12 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) { using namespace VideoCommon::Dirty; auto& flags = maxwell3d.dirty.flags; if (!flags[Dirty::RenderTargets]) { + for (size_t index = 0; index < NUM_RT; ++index) { + ImageViewId& color_buffer_id = render_targets.color_buffer_ids[index]; + PrepareImageView(color_buffer_id, true, is_clear && IsFullClear(color_buffer_id)); + } + const ImageViewId depth_buffer_id = render_targets.depth_buffer_id; + PrepareImageView(depth_buffer_id, true, is_clear && IsFullClear(depth_buffer_id)); return; } flags[Dirty::RenderTargets] = false; diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index c872517b8..59cf2f561 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp @@ -169,23 +169,6 @@ template <u32 GOB_EXTENT> return Common::DivCeil(AdjustMipSize(size, level), block_size); } -[[nodiscard]] constexpr std::pair<int, int> Samples(int num_samples) { - switch (num_samples) { - case 1: - return {1, 1}; - case 2: - return {2, 1}; - case 4: - return {2, 2}; - case 8: - return {4, 2}; - case 16: - return {4, 4}; - } - UNREACHABLE_MSG("Invalid number of samples={}", num_samples); - return {1, 1}; -} - [[nodiscard]] constexpr Extent2D DefaultBlockSize(PixelFormat format) { return {DefaultBlockWidth(format), DefaultBlockHeight(format)}; } @@ -283,14 +266,13 @@ template <u32 GOB_EXTENT> } [[nodiscard]] constexpr LevelInfo MakeLevelInfo(PixelFormat format, Extent3D size, Extent3D block, - u32 num_samples, u32 tile_width_spacing) { - const auto [samples_x, samples_y] = Samples(num_samples); + u32 tile_width_spacing) { const u32 bytes_per_block = BytesPerBlock(format); return { .size = { - .width = size.width * samples_x, - .height = size.height * samples_y, + .width = size.width, + .height = size.height, .depth = size.depth, }, .block = block, @@ -301,14 +283,12 @@ template <u32 GOB_EXTENT> } [[nodiscard]] constexpr LevelInfo MakeLevelInfo(const ImageInfo& info) { - return MakeLevelInfo(info.format, info.size, info.block, info.num_samples, - info.tile_width_spacing); + return MakeLevelInfo(info.format, info.size, info.block, info.tile_width_spacing); } [[nodiscard]] constexpr u32 CalculateLevelOffset(PixelFormat format, Extent3D size, Extent3D block, - u32 num_samples, u32 tile_width_spacing, - u32 level) { - const LevelInfo info = MakeLevelInfo(format, size, block, num_samples, tile_width_spacing); + u32 tile_width_spacing, u32 level) { + const LevelInfo info = MakeLevelInfo(format, size, block, tile_width_spacing); u32 offset = 0; for (u32 current_level = 0; current_level < level; ++current_level) { offset += CalculateLevelSize(info, current_level); @@ -645,8 +625,8 @@ u32 CalculateLayerStride(const ImageInfo& info) noexcept { u32 CalculateLayerSize(const ImageInfo& info) noexcept { ASSERT(info.type != ImageType::Linear); - return CalculateLevelOffset(info.format, info.size, info.block, info.num_samples, - info.tile_width_spacing, info.resources.levels); + return CalculateLevelOffset(info.format, info.size, info.block, info.tile_width_spacing, + info.resources.levels); } LevelArray CalculateMipLevelOffsets(const ImageInfo& info) noexcept { @@ -1195,37 +1175,37 @@ static_assert(CalculateLevelSize(LevelInfo{{1920, 1080, 1}, {0, 2, 0}, {1, 1}, 2 0x7f8000); static_assert(CalculateLevelSize(LevelInfo{{32, 32, 1}, {0, 0, 4}, {1, 1}, 4, 0}, 0) == 0x4000); -static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 1, 0, 7) == +static_assert(CalculateLevelOffset(PixelFormat::R8_SINT, {1920, 1080, 1}, {0, 2, 0}, 0, 7) == 0x2afc00); -static_assert(CalculateLevelOffset(PixelFormat::ASTC_2D_12X12_UNORM, {8192, 4096, 1}, {0, 2, 0}, 1, - 0, 12) == 0x50d200); - -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 0) == 0); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 1) == 0x400000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 2) == 0x500000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 3) == 0x540000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 4) == 0x550000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 5) == 0x554000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 6) == 0x555000); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 7) == 0x555400); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 8) == 0x555600); -static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 1, 0, - 9) == 0x555800); +static_assert(CalculateLevelOffset(PixelFormat::ASTC_2D_12X12_UNORM, {8192, 4096, 1}, {0, 2, 0}, 0, + 12) == 0x50d200); + +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 0) == + 0); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 1) == + 0x400000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 2) == + 0x500000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 3) == + 0x540000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 4) == + 0x550000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 5) == + 0x554000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 6) == + 0x555000); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 7) == + 0x555400); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 8) == + 0x555600); +static_assert(CalculateLevelOffset(PixelFormat::A8B8G8R8_UNORM, {1024, 1024, 1}, {0, 4, 0}, 0, 9) == + 0x555800); constexpr u32 ValidateLayerSize(PixelFormat format, u32 width, u32 height, u32 block_height, u32 tile_width_spacing, u32 level) { const Extent3D size{width, height, 1}; const Extent3D block{0, block_height, 0}; - const u32 offset = CalculateLevelOffset(format, size, block, 1, tile_width_spacing, level); + const u32 offset = CalculateLevelOffset(format, size, block, tile_width_spacing, level); return AlignLayerSize(offset, size, block, DefaultBlockHeight(format), tile_width_spacing); } diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 7524e3c40..d72ca5acc 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -411,8 +411,9 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) { if (event->source() == Qt::MouseEventSynthesizedBySystem) { return; } - - auto pos = event->pos(); + // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse + // coordinates and map them to the current render area + const auto pos = mapFromGlobal(QCursor::pos()); const auto [x, y] = ScaleTouch(pos); const auto button = QtButtonToMouseButton(event->button()); input_subsystem->GetMouse()->PressButton(x, y, button); @@ -429,7 +430,9 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { if (event->source() == Qt::MouseEventSynthesizedBySystem) { return; } - auto pos = event->pos(); + // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse + // coordinates and map them to the current render area + const auto pos = mapFromGlobal(QCursor::pos()); const auto [x, y] = ScaleTouch(pos); const int center_x = width() / 2; const int center_y = height() / 2; @@ -564,6 +567,12 @@ std::unique_ptr<Core::Frontend::GraphicsContext> GRenderWindow::CreateSharedCont bool GRenderWindow::InitRenderTarget() { ReleaseRenderTarget(); + { + // Create a dummy render widget so that Qt + // places the render window at the correct position. + const RenderWidget dummy_widget{this}; + } + first_frame = false; switch (Settings::values.renderer_backend.GetValue()) { diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index d8ba939d2..1d84bf4ed 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -47,8 +47,8 @@ void ConfigureAudio::SetConfiguration() { SetAudioDeviceFromDeviceID(); - const auto volume_value = Settings::values.volume.GetValue() * ui->volume_slider->maximum(); - ui->volume_slider->setValue(volume_value / 100); + const auto volume_value = static_cast<int>(Settings::values.volume.GetValue()); + ui->volume_slider->setValue(volume_value); ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching.GetValue()); @@ -113,16 +113,16 @@ void ConfigureAudio::ApplyConfiguration() { // Guard if during game and set to game-specific value if (Settings::values.volume.UsingGlobal()) { - const s32 volume = ui->volume_slider->sliderPosition() / ui->volume_slider->maximum(); - Settings::values.volume.SetValue(static_cast<u8>(100 * volume)); + const auto volume = static_cast<u8>(ui->volume_slider->value()); + Settings::values.volume.SetValue(volume); } } else { if (ui->volume_combo_box->currentIndex() == 0) { Settings::values.volume.SetGlobal(true); } else { Settings::values.volume.SetGlobal(false); - const s32 volume = ui->volume_slider->sliderPosition() / ui->volume_slider->maximum(); - Settings::values.volume.SetValue(static_cast<u8>(100 * volume)); + const auto volume = static_cast<u8>(ui->volume_slider->value()); + Settings::values.volume.SetValue(volume); } } } diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index d69324a69..6b9bd05f1 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -149,8 +149,9 @@ QString ButtonToText(const Common::ParamPackage& param) { if (param.Has("button")) { const QString button_str = QString::fromStdString(param.Get("button", "")); + const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); - return QObject::tr("Button %1").arg(button_str); + return QObject::tr("%1Button %2").arg(toggle, button_str); } if (param.Has("motion")) { diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 218b4782b..76c063c97 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -404,9 +404,11 @@ void GameList::ValidateEntry(const QModelIndex& item) { return; } + const auto title_id = selected.data(GameListItemPath::ProgramIdRole).toULongLong(); + // Users usually want to run a different game after closing one search_field->clear(); - emit GameChosen(file_path); + emit GameChosen(file_path, title_id); break; } case GameListItemType::AddDir: @@ -548,10 +550,10 @@ void GameList::AddGamePopup(QMenu& context_menu, u64 program_id, const std::stri emit OpenFolderRequested(program_id, GameListOpenTarget::SaveData, path); }); connect(start_game, &QAction::triggered, [this, path]() { - emit BootGame(QString::fromStdString(path), 0, StartGameType::Normal); + emit BootGame(QString::fromStdString(path), 0, 0, StartGameType::Normal); }); connect(start_game_global, &QAction::triggered, [this, path]() { - emit BootGame(QString::fromStdString(path), 0, StartGameType::Global); + emit BootGame(QString::fromStdString(path), 0, 0, StartGameType::Global); }); connect(open_mod_location, &QAction::triggered, [this, program_id, path]() { emit OpenFolderRequested(program_id, GameListOpenTarget::ModData, path); diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index 50402da51..c9a9f4654 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h @@ -88,8 +88,9 @@ public: static const QStringList supported_file_extensions; signals: - void BootGame(const QString& game_path, std::size_t program_index, StartGameType type); - void GameChosen(const QString& game_path); + void BootGame(const QString& game_path, u64 program_id, std::size_t program_index, + StartGameType type); + void GameChosen(const QString& game_path, const u64 title_id = 0); void ShouldCancelWorker(); void OpenFolderRequested(u64 program_id, GameListOpenTarget target, const std::string& game_path); diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 33cc90d5a..2d5492157 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -336,18 +336,44 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa } } } else { - std::vector<u8> icon; - [[maybe_unused]] const auto res1 = loader->ReadIcon(icon); + std::vector<u64> program_ids; + loader->ReadProgramIds(program_ids); + + if (res2 == Loader::ResultStatus::Success && program_ids.size() > 1 && + (file_type == Loader::FileType::XCI || file_type == Loader::FileType::NSP)) { + for (const auto id : program_ids) { + loader = Loader::GetLoader(system, file, id); + if (!loader) { + continue; + } + + std::vector<u8> icon; + [[maybe_unused]] const auto res1 = loader->ReadIcon(icon); - std::string name = " "; - [[maybe_unused]] const auto res3 = loader->ReadTitle(name); + std::string name = " "; + [[maybe_unused]] const auto res3 = loader->ReadTitle(name); - const FileSys::PatchManager patch{program_id, system.GetFileSystemController(), - system.GetContentProvider()}; + const FileSys::PatchManager patch{id, system.GetFileSystemController(), + system.GetContentProvider()}; + + emit EntryReady(MakeGameListEntry(physical_name, name, icon, *loader, id, + compatibility_list, patch), + parent_dir); + } + } else { + std::vector<u8> icon; + [[maybe_unused]] const auto res1 = loader->ReadIcon(icon); - emit EntryReady(MakeGameListEntry(physical_name, name, icon, *loader, program_id, - compatibility_list, patch), - parent_dir); + std::string name = " "; + [[maybe_unused]] const auto res3 = loader->ReadTitle(name); + + const FileSys::PatchManager patch{program_id, system.GetFileSystemController(), + system.GetContentProvider()}; + + emit EntryReady(MakeGameListEntry(physical_name, name, icon, *loader, + program_id, compatibility_list, patch), + parent_dir); + } } } else if (is_dir) { watch_list.append(QString::fromStdString(physical_name)); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index b7fd33ae7..03a909d17 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1221,7 +1221,7 @@ void GMainWindow::AllowOSSleep() { #endif } -bool GMainWindow::LoadROM(const QString& filename, std::size_t program_index) { +bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t program_index) { // Shutdown previous session if the emu thread is still active... if (emu_thread != nullptr) ShutdownGame(); @@ -1244,7 +1244,7 @@ bool GMainWindow::LoadROM(const QString& filename, std::size_t program_index) { }); const Core::System::ResultStatus result{ - system.Load(*render_window, filename.toStdString(), program_index)}; + system.Load(*render_window, filename.toStdString(), program_id, program_index)}; const auto drd_callout = (UISettings::values.callout_flags.GetValue() & static_cast<u32>(CalloutFlag::DRDDeprecation)) == 0; @@ -1331,7 +1331,8 @@ void GMainWindow::SelectAndSetCurrentUser() { Settings::values.current_user = dialog.GetIndex(); } -void GMainWindow::BootGame(const QString& filename, std::size_t program_index, StartGameType type) { +void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t program_index, + StartGameType type) { LOG_INFO(Frontend, "yuzu starting..."); StoreRecentFile(filename); // Put the filename on top of the list @@ -1341,7 +1342,7 @@ void GMainWindow::BootGame(const QString& filename, std::size_t program_index, S auto& system = Core::System::GetInstance(); const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData()); - const auto loader = Loader::GetLoader(system, v_file, program_index); + const auto loader = Loader::GetLoader(system, v_file, program_id, program_index); if (loader != nullptr && loader->ReadProgramId(title_id) == Loader::ResultStatus::Success && type == StartGameType::Normal) { @@ -1369,7 +1370,7 @@ void GMainWindow::BootGame(const QString& filename, std::size_t program_index, S SelectAndSetCurrentUser(); } - if (!LoadROM(filename, program_index)) + if (!LoadROM(filename, program_id, program_index)) return; // Create and start the emulation thread @@ -1548,8 +1549,8 @@ void GMainWindow::UpdateRecentFiles() { ui.menu_recent_files->setEnabled(num_recent_files != 0); } -void GMainWindow::OnGameListLoadFile(QString game_path) { - BootGame(game_path); +void GMainWindow::OnGameListLoadFile(QString game_path, u64 program_id) { + BootGame(game_path, program_id); } void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target, @@ -2450,7 +2451,7 @@ void GMainWindow::OnLoadComplete() { void GMainWindow::OnExecuteProgram(std::size_t program_index) { ShutdownGame(); - BootGame(last_filename_booted, program_index); + BootGame(last_filename_booted, 0, program_index); } void GMainWindow::ErrorDisplayDisplayError(QString error_code, QString error_text) { diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 45c8310e1..a50e5b9fe 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -186,8 +186,8 @@ private: void PreventOSSleep(); void AllowOSSleep(); - bool LoadROM(const QString& filename, std::size_t program_index); - void BootGame(const QString& filename, std::size_t program_index = 0, + bool LoadROM(const QString& filename, u64 program_id, std::size_t program_index); + void BootGame(const QString& filename, u64 program_id = 0, std::size_t program_index = 0, StartGameType with_config = StartGameType::Normal); void ShutdownGame(); @@ -238,7 +238,7 @@ private slots: void OnOpenQuickstartGuide(); void OnOpenFAQ(); /// Called whenever a user selects a game in the game list widget. - void OnGameListLoadFile(QString game_path); + void OnGameListLoadFile(QString game_path, u64 program_id); void OnGameListOpenFolder(u64 program_id, GameListOpenTarget target, const std::string& game_path); void OnTransferableShaderCacheOpenFile(u64 program_id); diff --git a/src/yuzu_cmd/CMakeLists.txt b/src/yuzu_cmd/CMakeLists.txt index 4bf25727b..e55a19649 100644 --- a/src/yuzu_cmd/CMakeLists.txt +++ b/src/yuzu_cmd/CMakeLists.txt @@ -38,6 +38,11 @@ target_include_directories(yuzu-cmd PRIVATE ${RESOURCES_DIR}) target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include) +if (YUZU_USE_EXTERNAL_SDL2) + target_compile_definitions(yuzu-cmd PRIVATE -DYUZU_USE_EXTERNAL_SDL2) + target_include_directories(yuzu-cmd PRIVATE ${PROJECT_BINARY_DIR}/externals/SDL/include) +endif() + if(UNIX AND NOT APPLE) install(TARGETS yuzu-cmd RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") endif() diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 23ada3f92..b18056baf 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -292,6 +292,8 @@ void Config::ReadValues() { ReadSetting("ControlsGeneral", Settings::values.motion_device); + ReadSetting("ControlsGeneral", Settings::values.touch_device); + ReadSetting("ControlsGeneral", Settings::values.keyboard_enabled); ReadSetting("ControlsGeneral", Settings::values.debug_pad_enabled); @@ -414,11 +416,31 @@ void Config::ReadValues() { } ReadSetting("System", Settings::values.language_index); + ReadSetting("System", Settings::values.region_index); ReadSetting("System", Settings::values.time_zone_index); + ReadSetting("System", Settings::values.sound_index); // Core ReadSetting("Core", Settings::values.use_multi_core); + // Cpu + ReadSetting("Cpu", Settings::values.cpu_accuracy); + ReadSetting("Cpu", Settings::values.cpu_debug_mode); + ReadSetting("Cpu", Settings::values.cpuopt_page_tables); + ReadSetting("Cpu", Settings::values.cpuopt_block_linking); + ReadSetting("Cpu", Settings::values.cpuopt_return_stack_buffer); + ReadSetting("Cpu", Settings::values.cpuopt_fast_dispatcher); + ReadSetting("Cpu", Settings::values.cpuopt_context_elimination); + ReadSetting("Cpu", Settings::values.cpuopt_const_prop); + ReadSetting("Cpu", Settings::values.cpuopt_misc_ir); + ReadSetting("Cpu", Settings::values.cpuopt_reduce_misalign_checks); + ReadSetting("Cpu", Settings::values.cpuopt_fastmem); + ReadSetting("Cpu", Settings::values.cpuopt_unsafe_unfuse_fma); + ReadSetting("Cpu", Settings::values.cpuopt_unsafe_reduce_fp_error); + ReadSetting("Cpu", Settings::values.cpuopt_unsafe_ignore_standard_fpcr); + ReadSetting("Cpu", Settings::values.cpuopt_unsafe_inaccurate_nan); + ReadSetting("Cpu", Settings::values.cpuopt_unsafe_fastmem_check); + // Renderer ReadSetting("Renderer", Settings::values.renderer_backend); ReadSetting("Renderer", Settings::values.renderer_debug); @@ -438,6 +460,7 @@ void Config::ReadValues() { ReadSetting("Renderer", Settings::values.use_nvdec_emulation); ReadSetting("Renderer", Settings::values.accelerate_astc); ReadSetting("Renderer", Settings::values.use_fast_gpu_time); + ReadSetting("Renderer", Settings::values.use_caches_gc); ReadSetting("Renderer", Settings::values.bg_red); ReadSetting("Renderer", Settings::values.bg_green); @@ -458,7 +481,6 @@ void Config::ReadValues() { // Debugging Settings::values.record_frame_times = sdl2_config->GetBoolean("Debugging", "record_frame_times", false); - ReadSetting("Debugging", Settings::values.program_args); ReadSetting("Debugging", Settings::values.dump_exefs); ReadSetting("Debugging", Settings::values.dump_nso); ReadSetting("Debugging", Settings::values.enable_fs_access_log); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 7d6bcccc7..b362f10b4 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -65,6 +65,13 @@ button_screenshot= lstick= rstick= +# To use the debug_pad, prepend `debug_pad_` before each button setting above. +# i.e. debug_pad_button_a= + +# Enable debug pad inputs to the guest +# 0 (default): Disabled, 1: Enabled +debug_pad_enabled = + # Whether to enable or disable vibration # 0: Disabled, 1 (default): Enabled vibration_enabled= @@ -73,6 +80,10 @@ vibration_enabled= # 0 (default): Disabled, 1: Enabled enable_accurate_vibrations= +# Enables controller motion inputs +# 0: Disabled, 1 (default): Enabled +motion_enabled = + # for motion input, the following devices are available: # - "motion_emu" (default) for emulating motion input from mouse input. Required parameters: # - "update_period": update period in milliseconds (default to 100) @@ -98,19 +109,30 @@ use_touch_from_button= #touch_from_button_maps_0_bind_1=bar # etc. -# Most desktop operating systems do not expose a way to poll the motion state of the controllers -# so as a way around it, cemuhook created a udp client/server protocol to broadcast the data directly -# from a controller device to the client program. Citra has a client that can connect and read -# from any cemuhook compatible motion program. +# List of Cemuhook UDP servers, delimited by ','. +# Default: 127.0.0.1:26760 +# Example: 127.0.0.1:26760,123.4.5.67:26761 +udp_input_servers = -# IPv4 address of the udp input server (Default "127.0.0.1") -udp_input_address=127.0.0.1 +# Enable controlling an axis via a mouse input. +# 0 (default): Off, 1: On +mouse_panning = + +# Set mouse sensitivity. +# Default: 1.0 +mouse_panning_sensitivity = + +# Emulate an analog control stick from keyboard inputs. +# 0 (default): Disabled, 1: Enabled +emulate_analog_keyboard = -# Port of the udp input server. (Default 26760) -udp_input_port= +# Enable mouse inputs to the guest +# 0 (default): Disabled, 1: Enabled +mouse_enabled = -# The pad to request data on. Should be between 0 (Pad 1) and 3 (Pad 4). (Default 0) -udp_pad_index= +# Enable keyboard inputs to the guest +# 0 (default): Disabled, 1: Enabled +keyboard_enabled = [Core] # Whether to use multi-core for CPU emulation @@ -118,6 +140,17 @@ udp_pad_index= use_multi_core= [Cpu] +# Adjusts various optimizations. +# Auto-select mode enables choice unsafe optimizations. +# Accurate enables only safe optimizations. +# Unsafe allows any unsafe optimizations. +# 0 (default): Auto-select, 1: Accurate, 2: Enable unsafe optimizations +cpu_accuracy = + +# Allow disabling safe optimizations. +# 0 (default): Disabled, 1: Enabled +cpu_debug_mode = + # Enable inline page tables optimization (faster guest memory access) # 0: Disabled, 1 (default): Enabled cpuopt_page_tables = @@ -154,6 +187,31 @@ cpuopt_reduce_misalign_checks = # 0: Disabled, 1 (default): Enabled cpuopt_fastmem = +# Enable unfuse FMA (improve performance on CPUs without FMA) +# Only enabled if cpu_accuracy is set to Unsafe. Automatically chosen with cpu_accuracy = Auto-select. +# 0: Disabled, 1 (default): Enabled +cpuopt_unsafe_unfuse_fma = + +# Enable faster FRSQRTE and FRECPE +# Only enabled if cpu_accuracy is set to Unsafe. +# 0: Disabled, 1 (default): Enabled +cpuopt_unsafe_reduce_fp_error = + +# Enable faster ASIMD instructions (32 bits only) +# Only enabled if cpu_accuracy is set to Unsafe. Automatically chosen with cpu_accuracy = Auto-select. +# 0: Disabled, 1 (default): Enabled +cpuopt_unsafe_ignore_standard_fpcr = + +# Enable inaccurate NaN handling +# Only enabled if cpu_accuracy is set to Unsafe. Automatically chosen with cpu_accuracy = Auto-select. +# 0: Disabled, 1 (default): Enabled +cpuopt_unsafe_inaccurate_nan = + +# Disable address space checks (64 bits only) +# Only enabled if cpu_accuracy is set to Unsafe. Automatically chosen with cpu_accuracy = Auto-select. +# 0: Disabled, 1 (default): Enabled +cpuopt_unsafe_fastmem_check = + [Renderer] # Which backend API to use. # 0 (default): OpenGL, 1: Vulkan @@ -166,14 +224,6 @@ debug = # Which Vulkan physical device to use (defaults to 0) vulkan_device = -# Whether to use software or hardware rendering. -# 0: Software, 1 (default): Hardware -use_hw_renderer = - -# Whether to use the Just-In-Time (JIT) compiler for shader emulation -# 0: Interpreter (slow), 1 (default): JIT (fast) -use_shader_jit = - # Aspect ratio # 0: Default (16:9), 1: Force 4:3, 2: Force 21:9, 3: Stretch to Window aspect_ratio = @@ -211,21 +261,20 @@ use_frame_limit = frame_limit = # Whether to use disk based shader cache -# 0 (default): Off, 1 : On +# 0: Off, 1 (default): On use_disk_shader_cache = # Which gpu accuracy level to use -# 0 (Normal), 1 (High), 2 (Extreme) +# 0: Normal, 1 (default): High, 2: Extreme (Very slow) gpu_accuracy = # Whether to use asynchronous GPU emulation # 0 : Off (slow), 1 (default): On (fast) use_asynchronous_gpu_emulation = -# Forces VSync on the display thread. Usually doesn't impact performance, but on some drivers it can -# so only turn this off if you notice a speed difference. +# Inform the guest that GPU operations completed more quickly than they did. # 0: Off, 1 (default): On -use_vsync = +use_fast_gpu_time = # Whether to use garbage collection or not for GPU caches. # 0 (default): Off, 1: On @@ -237,31 +286,6 @@ bg_red = bg_blue = bg_green = -[Layout] -# Layout for the screen inside the render window. -# 0 (default): Default Top Bottom Screen, 1: Single Screen Only, 2: Large Screen Small Screen -layout_option = - -# Toggle custom layout (using the settings below) on or off. -# 0 (default): Off, 1: On -custom_layout = - -# Screen placement when using Custom layout option -# 0x, 0y is the top left corner of the render window. -custom_top_left = -custom_top_top = -custom_top_right = -custom_top_bottom = -custom_bottom_left = -custom_bottom_top = -custom_bottom_right = -custom_bottom_bottom = - -# Swaps the prominent screen with the other screen. -# For example, if Single Screen is chosen, setting this to 1 will display the bottom screen instead of the top screen. -# 0 (default): Top Screen is prominent, 1: Bottom Screen is prominent -swap_screen = - [Audio] # Which audio output engine to use. # auto (default): Auto-select @@ -308,10 +332,6 @@ gamecard_path = # 1 (default): Yes, 0: No use_docked_mode = -# Allow the use of NFC in games -# 1 (default): Yes, 0 : No -enable_nfc = - # Sets the seed for the RNG generator built into the switch # rng_seed will be ignored and randomly generated if rng_seed_enabled is false rng_seed_enabled = @@ -323,10 +343,6 @@ rng_seed = custom_rtc_enabled = custom_rtc = -# Sets the account username, max length is 32 characters -# yuzu (default) -username = yuzu - # Sets the systems language index # 0: Japanese, 1: English (default), 2: French, 3: German, 4: Italian, 5: Spanish, 6: Chinese, # 7: Korean, 8: Dutch, 9: Portuguese, 10: Russian, 11: Taiwanese, 12: British English, 13: Canadian French, @@ -335,17 +351,25 @@ language_index = # The system region that yuzu will use during emulation # -1: Auto-select (default), 0: Japan, 1: USA, 2: Europe, 3: Australia, 4: China, 5: Korea, 6: Taiwan -region_value = +region_index = # The system time zone that yuzu will use during emulation # 0: Auto-select (default), 1: Default (system archive value), Others: Index for specified time zone time_zone_index = +# Sets the sound output mode. +# 0: Mono, 1 (default): Stereo, 2: Surround +sound_index = + [Miscellaneous] # A filter which removes logs below a certain logging level. # Examples: *:Debug Kernel.SVC:Trace Service.*:Critical log_filter = *:Trace +# Use developer keys +# 0 (default): Disabled, 1: Enabled +use_dev_keys = + [Debugging] # Record frame time data, can be found in the log directory. Boolean value record_frame_times = @@ -355,6 +379,8 @@ dump_exefs=false dump_nso=false # Determines whether or not yuzu will save the filesystem access log. enable_fs_access_log=false +# Enables verbose reporting services +reporting_services = # Determines whether or not yuzu will report to the game that the emulated console is in Kiosk Mode # false: Retail/Normal Mode (default), true: Kiosk Mode quest_flag = @@ -393,4 +419,4 @@ title_ids = # For each title ID, have a key/value pair called `disabled_<title_id>` equal to the names of the add-ons to disable (sep. by '|') # e.x. disabled_0100000000010000 = Update|DLC <- disables Updates and DLC on Super Mario Odyssey )"; -} +} // namespace DefaultINI diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 06b20c975..8dfc09393 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -2,15 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wimplicit-fallthrough" -#endif #include <SDL.h> -#ifdef __clang__ -#pragma clang diagnostic pop -#endif #include "common/logging/log.h" #include "common/scm_rev.h" @@ -130,12 +122,6 @@ void EmuWindow_SDL2::OnResize() { } void EmuWindow_SDL2::Fullscreen() { - if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { - return; - } - - LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); - // Try a different fullscreening method LOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { @@ -144,6 +130,12 @@ void EmuWindow_SDL2::Fullscreen() { LOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { + return; + } + + LOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); + // Fallback algorithm: Maximise window. // Works on all systems (unless something is seriously wrong), so no fallback for this one. LOG_INFO(Frontend, "Falling back on a maximised window..."); diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp index 837a44be7..eadb41790 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp @@ -7,15 +7,7 @@ #include <string> #define SDL_MAIN_HANDLED -// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wimplicit-fallthrough" -#endif #include <SDL.h> -#ifdef __clang__ -#pragma clang diagnostic pop -#endif #include <fmt/format.h> #include <glad/glad.h> diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp index 3401ad4b4..d1473dbab 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.cpp @@ -15,19 +15,16 @@ #include "video_core/renderer_vulkan/renderer_vulkan.h" #include "yuzu_cmd/emu_window/emu_window_sdl2_vk.h" -// Include these late to avoid polluting everything with Xlib macros -// Ignore -Wimplicit-fallthrough due to https://github.com/libsdl-org/SDL/issues/4307 -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wimplicit-fallthrough" +#ifdef YUZU_USE_EXTERNAL_SDL2 +// Include this before SDL.h to prevent the external from including a dummy +#define USING_GENERATED_CONFIG_H +#include <SDL_config.h> #endif + #include <SDL.h> -#ifdef __clang__ -#pragma clang diagnostic pop -#endif #include <SDL_syswm.h> -EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem) +EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen) : EmuWindow_SDL2{input_subsystem} { const std::string window_title = fmt::format("yuzu {} | {}-{} (Vulkan)", Common::g_build_name, Common::g_scm_branch, Common::g_scm_desc); @@ -45,12 +42,21 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste SetWindowIcon(); + if (fullscreen) { + Fullscreen(); + } + switch (wm.subsystem) { #ifdef SDL_VIDEO_DRIVER_WINDOWS case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: window_info.type = Core::Frontend::WindowSystemType::Windows; window_info.render_surface = reinterpret_cast<void*>(wm.info.win.window); break; +#else + case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: + LOG_CRITICAL(Frontend, "Window manager subsystem Windows not compiled"); + std::exit(EXIT_FAILURE); + break; #endif #ifdef SDL_VIDEO_DRIVER_X11 case SDL_SYSWM_TYPE::SDL_SYSWM_X11: @@ -58,6 +64,11 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste window_info.display_connection = wm.info.x11.display; window_info.render_surface = reinterpret_cast<void*>(wm.info.x11.window); break; +#else + case SDL_SYSWM_TYPE::SDL_SYSWM_X11: + LOG_CRITICAL(Frontend, "Window manager subsystem X11 not compiled"); + std::exit(EXIT_FAILURE); + break; #endif #ifdef SDL_VIDEO_DRIVER_WAYLAND case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND: @@ -65,6 +76,11 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste window_info.display_connection = wm.info.wl.display; window_info.render_surface = wm.info.wl.surface; break; +#else + case SDL_SYSWM_TYPE::SDL_SYSWM_WAYLAND: + LOG_CRITICAL(Frontend, "Window manager subsystem Wayland not compiled"); + std::exit(EXIT_FAILURE); + break; #endif default: LOG_CRITICAL(Frontend, "Window manager subsystem not implemented"); diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h index bdfdc3c6f..de53844f0 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_vk.h @@ -19,7 +19,7 @@ class InputSubsystem; class EmuWindow_SDL2_VK final : public EmuWindow_SDL2 { public: - explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem); + explicit EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsystem, bool fullscreen); ~EmuWindow_SDL2_VK() override; std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override; diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 9607cdcb1..ac4ea88d3 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -175,7 +175,7 @@ int main(int argc, char** argv) { emu_window = std::make_unique<EmuWindow_SDL2_GL>(&input_subsystem, fullscreen); break; case Settings::RendererBackend::Vulkan: - emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem); + emu_window = std::make_unique<EmuWindow_SDL2_VK>(&input_subsystem, fullscreen); break; } |