diff options
Diffstat (limited to '')
43 files changed, 316 insertions, 226 deletions
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 4fdc12f11..f64e4c6a6 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -26,7 +26,6 @@ using Vector = Dynarmic::A64::Vector; class ARM_Dynarmic_Callbacks : public Dynarmic::A64::UserCallbacks { public: explicit ARM_Dynarmic_Callbacks(ARM_Dynarmic& parent) : parent(parent) {} - ~ARM_Dynarmic_Callbacks() = default; u8 MemoryRead8(u64 vaddr) override { return Memory::Read8(vaddr); diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index aada1e862..81e0b4ac0 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -29,7 +29,7 @@ class ARM_Dynarmic final : public ARM_Interface { public: ARM_Dynarmic(Timing::CoreTiming& core_timing, ExclusiveMonitor& exclusive_monitor, std::size_t core_index); - ~ARM_Dynarmic(); + ~ARM_Dynarmic() override; void MapBackingMemory(VAddr address, std::size_t size, u8* memory, Kernel::VMAPermission perms) override; @@ -76,7 +76,7 @@ private: class DynarmicExclusiveMonitor final : public ExclusiveMonitor { public: explicit DynarmicExclusiveMonitor(std::size_t core_count); - ~DynarmicExclusiveMonitor(); + ~DynarmicExclusiveMonitor() override; void SetExclusive(std::size_t core_index, VAddr addr) override; void ClearExclusive() override; diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index a542a098b..27309280c 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -192,12 +192,13 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) { CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); core_timing.AddTicks(num_instructions); if (GDBStub::IsServerEnabled()) { - if (last_bkpt_hit) { + if (last_bkpt_hit && last_bkpt.type == GDBStub::BreakpointType::Execute) { uc_reg_write(uc, UC_ARM64_REG_PC, &last_bkpt.address); } + Kernel::Thread* thread = Kernel::GetCurrentThread(); SaveContext(thread->GetContext()); - if (last_bkpt_hit || GDBStub::GetCpuStepFlag()) { + if (last_bkpt_hit || GDBStub::IsMemoryBreak() || GDBStub::GetCpuStepFlag()) { last_bkpt_hit = false; GDBStub::Break(); GDBStub::SendTrap(thread, 5); diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index dbd6955ea..1e44f0736 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h @@ -18,7 +18,7 @@ namespace Core { class ARM_Unicorn final : public ARM_Interface { public: explicit ARM_Unicorn(Timing::CoreTiming& core_timing); - ~ARM_Unicorn(); + ~ARM_Unicorn() override; void MapBackingMemory(VAddr address, std::size_t size, u8* memory, Kernel::VMAPermission perms) override; @@ -50,7 +50,7 @@ private: uc_engine* uc{}; Timing::CoreTiming& core_timing; GDBStub::BreakpointAddress last_bkpt{}; - bool last_bkpt_hit; + bool last_bkpt_hit = false; }; } // namespace Core diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 47b7526c7..d126ae8dd 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp @@ -23,6 +23,7 @@ */ #include <cstring> +#include <string_view> #include "common/alignment.h" #include "common/assert.h" #include "core/file_sys/fsmitm_romfsbuild.h" @@ -97,7 +98,8 @@ struct RomFSBuildFileContext { VirtualFile source; }; -static u32 romfs_calc_path_hash(u32 parent, std::string path, u32 start, std::size_t path_len) { +static u32 romfs_calc_path_hash(u32 parent, std::string_view path, u32 start, + std::size_t path_len) { u32 hash = parent ^ 123456789; for (u32 i = 0; i < path_len; i++) { hash = (hash >> 5) | (hash << 27); diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp index 6f34b7836..93d0df6b9 100644 --- a/src/core/file_sys/nca_metadata.cpp +++ b/src/core/file_sys/nca_metadata.cpp @@ -10,14 +10,6 @@ namespace FileSys { -bool operator>=(TitleType lhs, TitleType rhs) { - return static_cast<std::size_t>(lhs) >= static_cast<std::size_t>(rhs); -} - -bool operator<=(TitleType lhs, TitleType rhs) { - return static_cast<std::size_t>(lhs) <= static_cast<std::size_t>(rhs); -} - CNMT::CNMT(VirtualFile file) { if (file->ReadObject(&header) != sizeof(CNMTHeader)) return; diff --git a/src/core/file_sys/nca_metadata.h b/src/core/file_sys/nca_metadata.h index a05d155f4..50bf38471 100644 --- a/src/core/file_sys/nca_metadata.h +++ b/src/core/file_sys/nca_metadata.h @@ -29,9 +29,6 @@ enum class TitleType : u8 { DeltaTitle = 0x83, }; -bool operator>=(TitleType lhs, TitleType rhs); -bool operator<=(TitleType lhs, TitleType rhs); - enum class ContentRecordType : u8 { Meta = 0, Program = 1, diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp index d3e00437f..d863253f8 100644 --- a/src/core/file_sys/program_metadata.cpp +++ b/src/core/file_sys/program_metadata.cpp @@ -3,7 +3,6 @@ // Refer to the license.txt file included. #include <cstddef> -#include <cstring> #include <vector> #include "common/logging/log.h" @@ -17,28 +16,30 @@ ProgramMetadata::ProgramMetadata() = default; ProgramMetadata::~ProgramMetadata() = default; Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) { - std::size_t total_size = static_cast<std::size_t>(file->GetSize()); - if (total_size < sizeof(Header)) + const std::size_t total_size = file->GetSize(); + if (total_size < sizeof(Header)) { return Loader::ResultStatus::ErrorBadNPDMHeader; + } - // TODO(DarkLordZach): Use ReadObject when Header/AcidHeader becomes trivially copyable. - std::vector<u8> npdm_header_data = file->ReadBytes(sizeof(Header)); - if (sizeof(Header) != npdm_header_data.size()) + if (sizeof(Header) != file->ReadObject(&npdm_header)) { return Loader::ResultStatus::ErrorBadNPDMHeader; - std::memcpy(&npdm_header, npdm_header_data.data(), sizeof(Header)); + } - std::vector<u8> acid_header_data = file->ReadBytes(sizeof(AcidHeader), npdm_header.acid_offset); - if (sizeof(AcidHeader) != acid_header_data.size()) + if (sizeof(AcidHeader) != file->ReadObject(&acid_header, npdm_header.acid_offset)) { return Loader::ResultStatus::ErrorBadACIDHeader; - std::memcpy(&acid_header, acid_header_data.data(), sizeof(AcidHeader)); + } - if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset)) + if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset)) { return Loader::ResultStatus::ErrorBadACIHeader; + } - if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset)) + if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset)) { return Loader::ResultStatus::ErrorBadFileAccessControl; - if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset)) + } + + if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset)) { return Loader::ResultStatus::ErrorBadFileAccessHeader; + } aci_kernel_capabilities.resize(aci_header.kac_size / sizeof(u32)); const u64 read_size = aci_header.kac_size; diff --git a/src/core/file_sys/program_metadata.h b/src/core/file_sys/program_metadata.h index 0033ba347..7de5b9cf9 100644 --- a/src/core/file_sys/program_metadata.h +++ b/src/core/file_sys/program_metadata.h @@ -58,7 +58,6 @@ public: void Print() const; private: - // TODO(DarkLordZach): BitField is not trivially copyable. struct Header { std::array<char, 4> magic; std::array<u8, 8> reserved; @@ -85,7 +84,6 @@ private: static_assert(sizeof(Header) == 0x80, "NPDM header structure size is wrong"); - // TODO(DarkLordZach): BitField is not trivially copyable. struct AcidHeader { std::array<u8, 0x100> signature; std::array<u8, 0x100> nca_modulus; diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 1913dc956..7974b031d 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -16,8 +16,10 @@ namespace FileSys { constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size"; std::string SaveDataDescriptor::DebugInfo() const { - return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]", - static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id); + return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, " + "rank={}, index={}]", + static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id, + static_cast<u8>(rank), index); } SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save_directory)) { @@ -28,7 +30,7 @@ SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save SaveDataFactory::~SaveDataFactory() = default; -ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, SaveDataDescriptor meta) { +ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) { if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { if (meta.zero_1 != 0) { LOG_WARNING(Service_FS, diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 3a1caf292..b73654571 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -32,12 +32,19 @@ enum class SaveDataType : u8 { CacheStorage = 5, }; +enum class SaveDataRank : u8 { + Primary, + Secondary, +}; + struct SaveDataDescriptor { u64_le title_id; u128 user_id; u64_le save_id; SaveDataType type; - INSERT_PADDING_BYTES(7); + SaveDataRank rank; + u16_le index; + INSERT_PADDING_BYTES(4); u64_le zero_1; u64_le zero_2; u64_le zero_3; @@ -57,7 +64,7 @@ public: explicit SaveDataFactory(VirtualDir dir); ~SaveDataFactory(); - ResultVal<VirtualDir> Open(SaveDataSpaceId space, SaveDataDescriptor meta); + ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataDescriptor& meta); VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index dafb32aae..afa812598 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -1030,7 +1030,7 @@ static void Step() { /// Tell the CPU if we hit a memory breakpoint. bool IsMemoryBreak() { - if (IsConnected()) { + if (!IsConnected()) { return false; } diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index ab10db3df..2fd07ab34 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -1339,6 +1339,20 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var "called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}", mutex_addr, condition_variable_addr, thread_handle, nano_seconds); + if (Memory::IsKernelVirtualAddress(mutex_addr)) { + LOG_ERROR( + Kernel_SVC, + "Given mutex address must not be within the kernel address space. address=0x{:016X}", + mutex_addr); + return ERR_INVALID_ADDRESS_STATE; + } + + if (!Common::IsWordAligned(mutex_addr)) { + LOG_ERROR(Kernel_SVC, "Given mutex address must be word-aligned. address=0x{:016X}", + mutex_addr); + return ERR_INVALID_ADDRESS; + } + auto* const current_process = Core::System::GetInstance().Kernel().CurrentProcess(); const auto& handle_table = current_process->GetHandleTable(); SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle); diff --git a/src/core/hle/result.h b/src/core/hle/result.h index ab84f5ddc..8a3701151 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -119,10 +119,6 @@ union ResultCode { BitField<0, 9, ErrorModule> module; BitField<9, 13, u32> description; - // The last bit of `level` is checked by apps and the kernel to determine if a result code is an - // error - BitField<31, 1, u32> is_error; - constexpr explicit ResultCode(u32 raw) : raw(raw) {} constexpr ResultCode(ErrorModule module_, u32 description_) diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp index 088410564..e5daefdde 100644 --- a/src/core/hle/service/audio/audin_u.cpp +++ b/src/core/hle/service/audio/audin_u.cpp @@ -2,9 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/service/audio/audin_u.h" namespace Service::Audio { @@ -33,7 +30,6 @@ public: RegisterHandlers(functions); } - ~IAudioIn() = default; }; AudInU::AudInU() : ServiceFramework("audin:u") { diff --git a/src/core/hle/service/audio/audrec_u.cpp b/src/core/hle/service/audio/audrec_u.cpp index 6956a2e64..1a5aed9ed 100644 --- a/src/core/hle/service/audio/audrec_u.cpp +++ b/src/core/hle/service/audio/audrec_u.cpp @@ -2,9 +2,6 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "common/logging/log.h" -#include "core/hle/ipc_helpers.h" -#include "core/hle/kernel/hle_ipc.h" #include "core/hle/service/audio/audrec_u.h" namespace Service::Audio { @@ -30,7 +27,6 @@ public: RegisterHandlers(functions); } - ~IFinalOutputRecorder() = default; }; AudRecU::AudRecU() : ServiceFramework("audrec:u") { diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index c6da2df43..4c2b371c3 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -197,13 +197,16 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, FileSys::Mode mode) const { - std::string path(FileUtil::SanitizePath(path_)); - auto npath = path; - while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\')) - npath = npath.substr(1); + const std::string path(FileUtil::SanitizePath(path_)); + std::string_view npath = path; + while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) { + npath.remove_prefix(1); + } + auto file = backing->GetFileRelative(npath); - if (file == nullptr) + if (file == nullptr) { return FileSys::ERROR_PATH_NOT_FOUND; + } if (mode == FileSys::Mode::Append) { return MakeResult<FileSys::VirtualFile>( @@ -319,15 +322,15 @@ ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId stora } ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, - FileSys::SaveDataDescriptor save_struct) { + const FileSys::SaveDataDescriptor& descriptor) { LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", - static_cast<u8>(space), save_struct.DebugInfo()); + static_cast<u8>(space), descriptor.DebugInfo()); if (save_data_factory == nullptr) { return FileSys::ERROR_ENTITY_NOT_FOUND; } - return save_data_factory->Open(space, save_struct); + return save_data_factory->Open(space, descriptor); } ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) { diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 6fd5e7b23..7cfc0d902 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -46,7 +46,7 @@ ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess(); ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type); ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, - FileSys::SaveDataDescriptor save_struct); + const FileSys::SaveDataDescriptor& descriptor); ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space); ResultVal<FileSys::VirtualDir> OpenSDMC(); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 592dce31a..657baddb8 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -604,7 +604,9 @@ private: u64_le save_id; u64_le title_id; u64_le save_image_size; - INSERT_PADDING_BYTES(0x28); + u16_le index; + FileSys::SaveDataRank rank; + INSERT_PADDING_BYTES(0x25); }; static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size."); @@ -767,16 +769,17 @@ void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - auto space_id = rp.PopRaw<FileSys::SaveDataSpaceId>(); - auto unk = rp.Pop<u32>(); - LOG_INFO(Service_FS, "called with unknown={:08X}", unk); + LOG_INFO(Service_FS, "called."); - auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>(); + struct Parameters { + FileSys::SaveDataSpaceId save_data_space_id; + FileSys::SaveDataDescriptor descriptor; + }; - auto dir = OpenSaveData(space_id, save_struct); + IPC::RequestParser rp{ctx}; + const auto parameters = rp.PopRaw<Parameters>(); + auto dir = OpenSaveData(parameters.save_data_space_id, parameters.descriptor); if (dir.Failed()) { IPC::ResponseBuilder rb{ctx, 2, 0, 0}; rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h index ace71169f..12f3ef825 100644 --- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h +++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h @@ -18,7 +18,7 @@ class nvmap; class nvdisp_disp0 final : public nvdevice { public: explicit nvdisp_disp0(std::shared_ptr<nvmap> nvmap_dev); - ~nvdisp_disp0(); + ~nvdisp_disp0() override; u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override; diff --git a/src/core/hle/service/nvdrv/interface.h b/src/core/hle/service/nvdrv/interface.h index fe311b069..5b4889910 100644 --- a/src/core/hle/service/nvdrv/interface.h +++ b/src/core/hle/service/nvdrv/interface.h @@ -17,7 +17,7 @@ namespace Service::Nvidia { class NVDRV final : public ServiceFramework<NVDRV> { public: NVDRV(std::shared_ptr<Module> nvdrv, const char* name); - ~NVDRV(); + ~NVDRV() override; private: void Open(Kernel::HLERequestContext& ctx); diff --git a/src/core/hle/service/nvdrv/nvmemp.h b/src/core/hle/service/nvdrv/nvmemp.h index 5a4dfc1f9..6eafb1346 100644 --- a/src/core/hle/service/nvdrv/nvmemp.h +++ b/src/core/hle/service/nvdrv/nvmemp.h @@ -11,7 +11,7 @@ namespace Service::Nvidia { class NVMEMP final : public ServiceFramework<NVMEMP> { public: NVMEMP(); - ~NVMEMP(); + ~NVMEMP() override; private: void Cmd0(Kernel::HLERequestContext& ctx); diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 830790269..abbfe5524 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -90,7 +90,7 @@ private: Kernel::HLERequestContext& ctx); ServiceFrameworkBase(const char* service_name, u32 max_sessions, InvokerFn* handler_invoker); - ~ServiceFrameworkBase(); + ~ServiceFrameworkBase() override; void RegisterHandlersBase(const FunctionInfoBase* functions, std::size_t n); void ReportUnimplementedFunction(Kernel::HLERequestContext& ctx, const FunctionInfoBase* info); diff --git a/src/core/hle/service/set/set_cal.h b/src/core/hle/service/set/set_cal.h index 583036eac..a0677e815 100644 --- a/src/core/hle/service/set/set_cal.h +++ b/src/core/hle/service/set/set_cal.h @@ -11,7 +11,7 @@ namespace Service::Set { class SET_CAL final : public ServiceFramework<SET_CAL> { public: explicit SET_CAL(); - ~SET_CAL(); + ~SET_CAL() override; }; } // namespace Service::Set diff --git a/src/core/hle/service/ssl/ssl.cpp b/src/core/hle/service/ssl/ssl.cpp index f671f355e..f7f87a958 100644 --- a/src/core/hle/service/ssl/ssl.cpp +++ b/src/core/hle/service/ssl/ssl.cpp @@ -64,7 +64,6 @@ public: }; RegisterHandlers(functions); } - ~ISslContext() = default; private: void SetOption(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index b77cb495d..4e17249a9 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -498,7 +498,6 @@ public: }; RegisterHandlers(functions); } - ~IHOSBinderDriver() = default; private: enum class TransactionId { @@ -692,7 +691,6 @@ public: }; RegisterHandlers(functions); } - ~ISystemDisplayService() = default; private: void SetLayerZ(Kernel::HLERequestContext& ctx) { @@ -818,7 +816,6 @@ public: }; RegisterHandlers(functions); } - ~IManagerDisplayService() = default; private: void CloseDisplay(Kernel::HLERequestContext& ctx) { @@ -884,7 +881,6 @@ private: class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> { public: explicit IApplicationDisplayService(std::shared_ptr<NVFlinger::NVFlinger> nv_flinger); - ~IApplicationDisplayService() = default; private: enum class ConvertedScaleMode : u64 { diff --git a/src/core/loader/xci.h b/src/core/loader/xci.h index d6995b61e..436f7387c 100644 --- a/src/core/loader/xci.h +++ b/src/core/loader/xci.h @@ -22,7 +22,7 @@ class AppLoader_NCA; class AppLoader_XCI final : public AppLoader { public: explicit AppLoader_XCI(FileSys::VirtualFile file); - ~AppLoader_XCI(); + ~AppLoader_XCI() override; /** * Returns the type of the file diff --git a/src/video_core/engines/fermi_2d.cpp b/src/video_core/engines/fermi_2d.cpp index 03b7ee5d8..55966eef1 100644 --- a/src/video_core/engines/fermi_2d.cpp +++ b/src/video_core/engines/fermi_2d.cpp @@ -6,12 +6,13 @@ #include "common/logging/log.h" #include "common/math_util.h" #include "video_core/engines/fermi_2d.h" +#include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" namespace Tegra::Engines { Fermi2D::Fermi2D(VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) - : memory_manager(memory_manager), rasterizer{rasterizer} {} + : rasterizer{rasterizer}, memory_manager{memory_manager} {} void Fermi2D::CallMethod(const GPU::MethodCall& method_call) { ASSERT_MSG(method_call.method < Regs::NUM_REGS, diff --git a/src/video_core/engines/fermi_2d.h b/src/video_core/engines/fermi_2d.h index 80523e320..2e51b7f13 100644 --- a/src/video_core/engines/fermi_2d.h +++ b/src/video_core/engines/fermi_2d.h @@ -10,7 +10,10 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "video_core/gpu.h" -#include "video_core/memory_manager.h" + +namespace Tegra { +class MemoryManager; +} namespace VideoCore { class RasterizerInterface; @@ -115,10 +118,9 @@ public: }; } regs{}; - MemoryManager& memory_manager; - private: VideoCore::RasterizerInterface& rasterizer; + MemoryManager& memory_manager; /// Performs the copy from the source surface to the destination surface as configured in the /// registers. diff --git a/src/video_core/engines/kepler_compute.h b/src/video_core/engines/kepler_compute.h index 6575afd0f..fb6cdf432 100644 --- a/src/video_core/engines/kepler_compute.h +++ b/src/video_core/engines/kepler_compute.h @@ -9,7 +9,10 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "video_core/gpu.h" -#include "video_core/memory_manager.h" + +namespace Tegra { +class MemoryManager; +} namespace Tegra::Engines { @@ -40,10 +43,11 @@ public: static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "KeplerCompute Regs has wrong size"); - MemoryManager& memory_manager; - /// Write the value to the register identified by method. void CallMethod(const GPU::MethodCall& method_call); + +private: + MemoryManager& memory_manager; }; #define ASSERT_REG_POSITION(field_name, position) \ diff --git a/src/video_core/engines/kepler_memory.cpp b/src/video_core/engines/kepler_memory.cpp index e259bf46b..cd51a31d7 100644 --- a/src/video_core/engines/kepler_memory.cpp +++ b/src/video_core/engines/kepler_memory.cpp @@ -5,9 +5,9 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/memory.h" #include "video_core/engines/kepler_memory.h" #include "video_core/engines/maxwell_3d.h" +#include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" #include "video_core/renderer_base.h" @@ -15,7 +15,7 @@ namespace Tegra::Engines { KeplerMemory::KeplerMemory(Core::System& system, VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) - : system{system}, memory_manager(memory_manager), rasterizer{rasterizer} {} + : system{system}, rasterizer{rasterizer}, memory_manager{memory_manager} {} KeplerMemory::~KeplerMemory() = default; diff --git a/src/video_core/engines/kepler_memory.h b/src/video_core/engines/kepler_memory.h index 9181e9d80..78b6c3e45 100644 --- a/src/video_core/engines/kepler_memory.h +++ b/src/video_core/engines/kepler_memory.h @@ -10,12 +10,15 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "video_core/gpu.h" -#include "video_core/memory_manager.h" namespace Core { class System; } +namespace Tegra { +class MemoryManager; +} + namespace VideoCore { class RasterizerInterface; } @@ -82,8 +85,8 @@ public: private: Core::System& system; - MemoryManager& memory_manager; VideoCore::RasterizerInterface& rasterizer; + MemoryManager& memory_manager; void ProcessData(u32 data); }; diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index defcfbd3f..3c3ac8f81 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp @@ -7,11 +7,10 @@ #include "common/assert.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/memory.h" #include "video_core/debug_utils/debug_utils.h" #include "video_core/engines/maxwell_3d.h" +#include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" -#include "video_core/renderer_base.h" #include "video_core/textures/texture.h" namespace Tegra::Engines { @@ -21,8 +20,8 @@ constexpr u32 MacroRegistersStart = 0xE00; Maxwell3D::Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) - : memory_manager(memory_manager), system{system}, rasterizer{rasterizer}, - macro_interpreter(*this) { + : system{system}, rasterizer{rasterizer}, memory_manager{memory_manager}, macro_interpreter{ + *this} { InitializeRegisterDefaults(); } diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 7fbf1026e..b352060a1 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h @@ -16,13 +16,16 @@ #include "common/math_util.h" #include "video_core/gpu.h" #include "video_core/macro_interpreter.h" -#include "video_core/memory_manager.h" #include "video_core/textures/texture.h" namespace Core { class System; } +namespace Tegra { +class MemoryManager; +} + namespace VideoCore { class RasterizerInterface; } @@ -1093,7 +1096,6 @@ public: }; State state{}; - MemoryManager& memory_manager; struct DirtyFlags { std::bitset<8> color_buffer{0xFF}; @@ -1141,6 +1143,8 @@ private: VideoCore::RasterizerInterface& rasterizer; + MemoryManager& memory_manager; + /// Start offsets of each macro in macro_memory std::unordered_map<u32, u32> macro_offsets; diff --git a/src/video_core/engines/maxwell_dma.cpp b/src/video_core/engines/maxwell_dma.cpp index 5cca5c29a..2426d0067 100644 --- a/src/video_core/engines/maxwell_dma.cpp +++ b/src/video_core/engines/maxwell_dma.cpp @@ -5,9 +5,9 @@ #include "common/assert.h" #include "common/logging/log.h" #include "core/core.h" -#include "core/memory.h" #include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_dma.h" +#include "video_core/memory_manager.h" #include "video_core/rasterizer_interface.h" #include "video_core/renderer_base.h" #include "video_core/textures/decoders.h" @@ -16,7 +16,7 @@ namespace Tegra::Engines { MaxwellDMA::MaxwellDMA(Core::System& system, VideoCore::RasterizerInterface& rasterizer, MemoryManager& memory_manager) - : memory_manager(memory_manager), system{system}, rasterizer{rasterizer} {} + : system{system}, rasterizer{rasterizer}, memory_manager{memory_manager} {} void MaxwellDMA::CallMethod(const GPU::MethodCall& method_call) { ASSERT_MSG(method_call.method < Regs::NUM_REGS, diff --git a/src/video_core/engines/maxwell_dma.h b/src/video_core/engines/maxwell_dma.h index 34c369320..c6b649842 100644 --- a/src/video_core/engines/maxwell_dma.h +++ b/src/video_core/engines/maxwell_dma.h @@ -10,12 +10,15 @@ #include "common/common_funcs.h" #include "common/common_types.h" #include "video_core/gpu.h" -#include "video_core/memory_manager.h" namespace Core { class System; } +namespace Tegra { +class MemoryManager; +} + namespace VideoCore { class RasterizerInterface; } @@ -139,13 +142,13 @@ public: }; } regs{}; - MemoryManager& memory_manager; - private: Core::System& system; VideoCore::RasterizerInterface& rasterizer; + MemoryManager& memory_manager; + /// Performs the copy from the source buffer to the destination buffer as configured in the /// registers. void HandleCopy(); diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp index 23f9bd422..cc56cf467 100644 --- a/src/video_core/gpu_thread.cpp +++ b/src/video_core/gpu_thread.cpp @@ -59,7 +59,7 @@ ThreadManager::ThreadManager(Core::System& system, VideoCore::RendererBase& rend Tegra::DmaPusher& dma_pusher) : system{system}, thread{RunThread, std::ref(renderer), std::ref(dma_pusher), std::ref(state)} { synchronization_event = system.CoreTiming().RegisterEvent( - "GPUThreadSynch", [this](u64 fence, int) { state.WaitForSynchronization(fence); }); + "GPUThreadSynch", [this](u64 fence, s64) { state.WaitForSynchronization(fence); }); } ThreadManager::~ThreadManager() { diff --git a/src/video_core/macro_interpreter.cpp b/src/video_core/macro_interpreter.cpp index 64f75db43..524d9ea5a 100644 --- a/src/video_core/macro_interpreter.cpp +++ b/src/video_core/macro_interpreter.cpp @@ -223,27 +223,21 @@ void MacroInterpreter::ProcessResult(ResultOperation operation, u32 reg, u32 res } u32 MacroInterpreter::FetchParameter() { - ASSERT(next_parameter_index < parameters.size()); - return parameters[next_parameter_index++]; + return parameters.at(next_parameter_index++); } u32 MacroInterpreter::GetRegister(u32 register_id) const { - // Register 0 is supposed to always return 0. - if (register_id == 0) - return 0; - - ASSERT(register_id < registers.size()); - return registers[register_id]; + return registers.at(register_id); } void MacroInterpreter::SetRegister(u32 register_id, u32 value) { - // Register 0 is supposed to always return 0. NOP is implemented as a store to the zero - // register. - if (register_id == 0) + // Register 0 is hardwired as the zero register. + // Ensure no writes to it actually occur. + if (register_id == 0) { return; + } - ASSERT(register_id < registers.size()); - registers[register_id] = value; + registers.at(register_id) = value; } void MacroInterpreter::SetMethodAddress(u32 address) { diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index e76b59842..8417324ff 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -77,16 +77,17 @@ GPUVAddr MemoryManager::UnmapBuffer(GPUVAddr gpu_addr, u64 size) { return gpu_addr; } -GPUVAddr MemoryManager::FindFreeRegion(GPUVAddr region_start, u64 size) { +GPUVAddr MemoryManager::FindFreeRegion(GPUVAddr region_start, u64 size) const { // Find the first Free VMA. - const VMAHandle vma_handle{std::find_if(vma_map.begin(), vma_map.end(), [&](const auto& vma) { - if (vma.second.type != VirtualMemoryArea::Type::Unmapped) { - return false; - } + const VMAHandle vma_handle{ + std::find_if(vma_map.begin(), vma_map.end(), [region_start, size](const auto& vma) { + if (vma.second.type != VirtualMemoryArea::Type::Unmapped) { + return false; + } - const VAddr vma_end{vma.second.base + vma.second.size}; - return vma_end > region_start && vma_end >= region_start + size; - })}; + const VAddr vma_end{vma.second.base + vma.second.size}; + return vma_end > region_start && vma_end >= region_start + size; + })}; if (vma_handle == vma_map.end()) { return {}; @@ -99,12 +100,12 @@ bool MemoryManager::IsAddressValid(GPUVAddr addr) const { return (addr >> page_bits) < page_table.pointers.size(); } -std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr addr) { +std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr addr) const { if (!IsAddressValid(addr)) { return {}; } - VAddr cpu_addr{page_table.backing_addr[addr >> page_bits]}; + const VAddr cpu_addr{page_table.backing_addr[addr >> page_bits]}; if (cpu_addr) { return cpu_addr + (addr & page_mask); } @@ -113,7 +114,7 @@ std::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr addr) { } template <typename T> -T MemoryManager::Read(GPUVAddr addr) { +T MemoryManager::Read(GPUVAddr addr) const { if (!IsAddressValid(addr)) { return {}; } @@ -165,10 +166,10 @@ void MemoryManager::Write(GPUVAddr addr, T data) { } } -template u8 MemoryManager::Read<u8>(GPUVAddr addr); -template u16 MemoryManager::Read<u16>(GPUVAddr addr); -template u32 MemoryManager::Read<u32>(GPUVAddr addr); -template u64 MemoryManager::Read<u64>(GPUVAddr addr); +template u8 MemoryManager::Read<u8>(GPUVAddr addr) const; +template u16 MemoryManager::Read<u16>(GPUVAddr addr) const; +template u32 MemoryManager::Read<u32>(GPUVAddr addr) const; +template u64 MemoryManager::Read<u64>(GPUVAddr addr) const; template void MemoryManager::Write<u8>(GPUVAddr addr, u8 data); template void MemoryManager::Write<u16>(GPUVAddr addr, u16 data); template void MemoryManager::Write<u32>(GPUVAddr addr, u32 data); @@ -179,8 +180,22 @@ u8* MemoryManager::GetPointer(GPUVAddr addr) { return {}; } - u8* page_pointer{page_table.pointers[addr >> page_bits]}; - if (page_pointer) { + u8* const page_pointer{page_table.pointers[addr >> page_bits]}; + if (page_pointer != nullptr) { + return page_pointer + (addr & page_mask); + } + + LOG_ERROR(HW_GPU, "Unknown GetPointer @ 0x{:016X}", addr); + return {}; +} + +const u8* MemoryManager::GetPointer(GPUVAddr addr) const { + if (!IsAddressValid(addr)) { + return {}; + } + + const u8* const page_pointer{page_table.pointers[addr >> page_bits]}; + if (page_pointer != nullptr) { return page_pointer + (addr & page_mask); } @@ -188,7 +203,7 @@ u8* MemoryManager::GetPointer(GPUVAddr addr) { return {}; } -void MemoryManager::ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) { +void MemoryManager::ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const { std::memcpy(dest_buffer, GetPointer(src_addr), size); } void MemoryManager::WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size) { diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h index 34744bb27..178e2f655 100644 --- a/src/video_core/memory_manager.h +++ b/src/video_core/memory_manager.h @@ -50,17 +50,18 @@ public: GPUVAddr MapBufferEx(VAddr cpu_addr, u64 size); GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr addr, u64 size); GPUVAddr UnmapBuffer(GPUVAddr addr, u64 size); - std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr); + std::optional<VAddr> GpuToCpuAddress(GPUVAddr addr) const; template <typename T> - T Read(GPUVAddr addr); + T Read(GPUVAddr addr) const; template <typename T> void Write(GPUVAddr addr, T data); u8* GetPointer(GPUVAddr addr); + const u8* GetPointer(GPUVAddr addr) const; - void ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size); + void ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const; void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size); void CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t size); @@ -127,7 +128,7 @@ private: void UpdatePageTableForVMA(const VirtualMemoryArea& vma); /// Finds a free (unmapped region) of the specified size starting at the specified address. - GPUVAddr FindFreeRegion(GPUVAddr region_start, u64 size); + GPUVAddr FindFreeRegion(GPUVAddr region_start, u64 size) const; private: static constexpr u64 page_bits{16}; diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 7300a4037..a1a51f226 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp @@ -69,10 +69,10 @@ public: shader_source += '\n'; } - std::string GenerateTemporal() { - std::string temporal = "tmp"; - temporal += std::to_string(temporal_index++); - return temporal; + std::string GenerateTemporary() { + std::string temporary = "tmp"; + temporary += std::to_string(temporary_index++); + return temporary; } std::string GetResult() { @@ -87,7 +87,7 @@ private: } std::string shader_source; - u32 temporal_index = 1; + u32 temporary_index = 1; }; /// Generates code to use for a swizzle operation. @@ -426,9 +426,14 @@ private: std::string Visit(Node node) { if (const auto operation = std::get_if<OperationNode>(node)) { const auto operation_index = static_cast<std::size_t>(operation->GetCode()); + if (operation_index >= operation_decompilers.size()) { + UNREACHABLE_MSG("Out of bounds operation: {}", operation_index); + return {}; + } const auto decompiler = operation_decompilers[operation_index]; if (decompiler == nullptr) { - UNREACHABLE_MSG("Operation decompiler {} not defined", operation_index); + UNREACHABLE_MSG("Undefined operation: {}", operation_index); + return {}; } return (this->*decompiler)(*operation); @@ -540,7 +545,7 @@ private: } else if (std::holds_alternative<OperationNode>(*offset)) { // Indirect access - const std::string final_offset = code.GenerateTemporal(); + const std::string final_offset = code.GenerateTemporary(); code.AddLine("uint " + final_offset + " = (ftou(" + Visit(offset) + ") / 4) & " + std::to_string(MAX_CONSTBUFFER_ELEMENTS - 1) + ';'); return fmt::format("{}[{} / 4][{} % 4]", GetConstBuffer(cbuf->GetIndex()), @@ -587,9 +592,9 @@ private: // There's a bug in NVidia's proprietary drivers that makes precise fail on fragment shaders const std::string precise = stage != ShaderStage::Fragment ? "precise " : ""; - const std::string temporal = code.GenerateTemporal(); - code.AddLine(precise + "float " + temporal + " = " + value + ';'); - return temporal; + const std::string temporary = code.GenerateTemporary(); + code.AddLine(precise + "float " + temporary + " = " + value + ';'); + return temporary; } std::string VisitOperand(Operation operation, std::size_t operand_index) { @@ -601,9 +606,9 @@ private: return Visit(operand); } - const std::string temporal = code.GenerateTemporal(); - code.AddLine("float " + temporal + " = " + Visit(operand) + ';'); - return temporal; + const std::string temporary = code.GenerateTemporary(); + code.AddLine("float " + temporary + " = " + Visit(operand) + ';'); + return temporary; } std::string VisitOperand(Operation operation, std::size_t operand_index, Type type) { diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp index 388b5ffd5..02a9f5ecb 100644 --- a/src/video_core/renderer_vulkan/vk_buffer_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.cpp @@ -10,6 +10,7 @@ #include "common/alignment.h" #include "common/assert.h" #include "core/memory.h" +#include "video_core/memory_manager.h" #include "video_core/renderer_vulkan/declarations.h" #include "video_core/renderer_vulkan/vk_buffer_cache.h" #include "video_core/renderer_vulkan/vk_scheduler.h" diff --git a/src/yuzu/debugger/graphics/graphics_surface.cpp b/src/yuzu/debugger/graphics/graphics_surface.cpp index 11023ed63..f2d14becf 100644 --- a/src/yuzu/debugger/graphics/graphics_surface.cpp +++ b/src/yuzu/debugger/graphics/graphics_surface.cpp @@ -7,6 +7,7 @@ #include <QDebug> #include <QFileDialog> #include <QLabel> +#include <QMessageBox> #include <QMouseEvent> #include <QPushButton> #include <QScrollArea> @@ -95,50 +96,91 @@ GraphicsSurfaceWidget::GraphicsSurfaceWidget(std::shared_ptr<Tegra::DebugContext surface_picker_y_control = new QSpinBox; surface_picker_y_control->setRange(0, max_dimension - 1); - surface_format_control = new QComboBox; - + // clang-format off // Color formats sorted by Maxwell texture format index - surface_format_control->addItem(tr("None")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("A8R8G8B8")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("Unknown")); - surface_format_control->addItem(tr("DXT1")); - surface_format_control->addItem(tr("DXT23")); - surface_format_control->addItem(tr("DXT45")); - surface_format_control->addItem(tr("DXN1")); - surface_format_control->addItem(tr("DXN2")); + const QStringList surface_formats{ + tr("None"), + QStringLiteral("R32_G32_B32_A32"), + QStringLiteral("R32_G32_B32"), + QStringLiteral("R16_G16_B16_A16"), + QStringLiteral("R32_G32"), + QStringLiteral("R32_B24G8"), + QStringLiteral("ETC2_RGB"), + QStringLiteral("X8B8G8R8"), + QStringLiteral("A8R8G8B8"), + QStringLiteral("A2B10G10R10"), + QStringLiteral("ETC2_RGB_PTA"), + QStringLiteral("ETC2_RGBA"), + QStringLiteral("R16_G16"), + QStringLiteral("G8R24"), + QStringLiteral("G24R8"), + QStringLiteral("R32"), + QStringLiteral("BC6H_SF16"), + QStringLiteral("BC6H_UF16"), + QStringLiteral("A4B4G4R4"), + QStringLiteral("A5B5G5R1"), + QStringLiteral("A1B5G5R5"), + QStringLiteral("B5G6R5"), + QStringLiteral("B6G5R5"), + QStringLiteral("BC7U"), + QStringLiteral("G8R8"), + QStringLiteral("EAC"), + QStringLiteral("EACX2"), + QStringLiteral("R16"), + QStringLiteral("Y8_VIDEO"), + QStringLiteral("R8"), + QStringLiteral("G4R4"), + QStringLiteral("R1"), + QStringLiteral("E5B9G9R9_SHAREDEXP"), + QStringLiteral("BF10GF11RF11"), + QStringLiteral("G8B8G8R8"), + QStringLiteral("B8G8R8G8"), + QStringLiteral("DXT1"), + QStringLiteral("DXT23"), + QStringLiteral("DXT45"), + QStringLiteral("DXN1"), + QStringLiteral("DXN2"), + QStringLiteral("Z24S8"), + QStringLiteral("X8Z24"), + QStringLiteral("S8Z24"), + QStringLiteral("X4V4Z24__COV4R4V"), + QStringLiteral("X4V4Z24__COV8R8V"), + QStringLiteral("V8Z24__COV4R12V"), + QStringLiteral("ZF32"), + QStringLiteral("ZF32_X24S8"), + QStringLiteral("X8Z24_X20V4S8__COV4R4V"), + QStringLiteral("X8Z24_X20V4S8__COV8R8V"), + QStringLiteral("ZF32_X20V4X8__COV4R4V"), + QStringLiteral("ZF32_X20V4X8__COV8R8V"), + QStringLiteral("ZF32_X20V4S8__COV4R4V"), + QStringLiteral("ZF32_X20V4S8__COV8R8V"), + QStringLiteral("X8Z24_X16V8S8__COV4R12V"), + QStringLiteral("ZF32_X16V8X8__COV4R12V"), + QStringLiteral("ZF32_X16V8S8__COV4R12V"), + QStringLiteral("Z16"), + QStringLiteral("V8Z24__COV8R24V"), + QStringLiteral("X8Z24_X16V8S8__COV8R24V"), + QStringLiteral("ZF32_X16V8X8__COV8R24V"), + QStringLiteral("ZF32_X16V8S8__COV8R24V"), + QStringLiteral("ASTC_2D_4X4"), + QStringLiteral("ASTC_2D_5X5"), + QStringLiteral("ASTC_2D_6X6"), + QStringLiteral("ASTC_2D_8X8"), + QStringLiteral("ASTC_2D_10X10"), + QStringLiteral("ASTC_2D_12X12"), + QStringLiteral("ASTC_2D_5X4"), + QStringLiteral("ASTC_2D_6X5"), + QStringLiteral("ASTC_2D_8X6"), + QStringLiteral("ASTC_2D_10X8"), + QStringLiteral("ASTC_2D_12X10"), + QStringLiteral("ASTC_2D_8X5"), + QStringLiteral("ASTC_2D_10X5"), + QStringLiteral("ASTC_2D_10X6"), + }; + // clang-format on + + surface_format_control = new QComboBox; + surface_format_control->addItems(surface_formats); surface_info_label = new QLabel(); surface_info_label->setWordWrap(true); @@ -157,22 +199,20 @@ GraphicsSurfaceWidget::GraphicsSurfaceWidget(std::shared_ptr<Tegra::DebugContext // Connections connect(this, &GraphicsSurfaceWidget::Update, this, &GraphicsSurfaceWidget::OnUpdate); - connect(surface_source_list, - static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, + connect(surface_source_list, qOverload<int>(&QComboBox::currentIndexChanged), this, &GraphicsSurfaceWidget::OnSurfaceSourceChanged); connect(surface_address_control, &CSpinBox::ValueChanged, this, &GraphicsSurfaceWidget::OnSurfaceAddressChanged); - connect(surface_width_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), - this, &GraphicsSurfaceWidget::OnSurfaceWidthChanged); - connect(surface_height_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), - this, &GraphicsSurfaceWidget::OnSurfaceHeightChanged); - connect(surface_format_control, - static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, + connect(surface_width_control, qOverload<int>(&QSpinBox::valueChanged), this, + &GraphicsSurfaceWidget::OnSurfaceWidthChanged); + connect(surface_height_control, qOverload<int>(&QSpinBox::valueChanged), this, + &GraphicsSurfaceWidget::OnSurfaceHeightChanged); + connect(surface_format_control, qOverload<int>(&QComboBox::currentIndexChanged), this, &GraphicsSurfaceWidget::OnSurfaceFormatChanged); - connect(surface_picker_x_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), - this, &GraphicsSurfaceWidget::OnSurfacePickerXChanged); - connect(surface_picker_y_control, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), - this, &GraphicsSurfaceWidget::OnSurfacePickerYChanged); + connect(surface_picker_x_control, qOverload<int>(&QSpinBox::valueChanged), this, + &GraphicsSurfaceWidget::OnSurfacePickerXChanged); + connect(surface_picker_y_control, qOverload<int>(&QSpinBox::valueChanged), this, + &GraphicsSurfaceWidget::OnSurfacePickerYChanged); connect(save_surface, &QPushButton::clicked, this, &GraphicsSurfaceWidget::SaveSurface); auto main_widget = new QWidget; @@ -420,40 +460,56 @@ void GraphicsSurfaceWidget::OnUpdate() { } void GraphicsSurfaceWidget::SaveSurface() { - QString png_filter = tr("Portable Network Graphic (*.png)"); - QString bin_filter = tr("Binary data (*.bin)"); + const QString png_filter = tr("Portable Network Graphic (*.png)"); + const QString bin_filter = tr("Binary data (*.bin)"); - QString selectedFilter; - QString filename = QFileDialog::getSaveFileName( + QString selected_filter; + const QString filename = QFileDialog::getSaveFileName( this, tr("Save Surface"), - QString("texture-0x%1.png").arg(QString::number(surface_address, 16)), - QString("%1;;%2").arg(png_filter, bin_filter), &selectedFilter); + QStringLiteral("texture-0x%1.png").arg(QString::number(surface_address, 16)), + QStringLiteral("%1;;%2").arg(png_filter, bin_filter), &selected_filter); if (filename.isEmpty()) { // If the user canceled the dialog, don't save anything. return; } - if (selectedFilter == png_filter) { - const QPixmap* pixmap = surface_picture_label->pixmap(); + if (selected_filter == png_filter) { + const QPixmap* const pixmap = surface_picture_label->pixmap(); ASSERT_MSG(pixmap != nullptr, "No pixmap set"); - QFile file(filename); - file.open(QIODevice::WriteOnly); - if (pixmap) - pixmap->save(&file, "PNG"); - } else if (selectedFilter == bin_filter) { + QFile file{filename}; + if (!file.open(QIODevice::WriteOnly)) { + QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename)); + return; + } + + if (!pixmap->save(&file, "PNG")) { + QMessageBox::warning(this, tr("Error"), + tr("Failed to save surface data to file '%1'").arg(filename)); + } + } else if (selected_filter == bin_filter) { auto& gpu = Core::System::GetInstance().GPU(); - std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); + const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); - const u8* buffer = Memory::GetPointer(*address); + const u8* const buffer = Memory::GetPointer(*address); ASSERT_MSG(buffer != nullptr, "Memory not accessible"); - QFile file(filename); - file.open(QIODevice::WriteOnly); - int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); - QByteArray data(reinterpret_cast<const char*>(buffer), size); - file.write(data); + QFile file{filename}; + if (!file.open(QIODevice::WriteOnly)) { + QMessageBox::warning(this, tr("Error"), tr("Failed to open file '%1'").arg(filename)); + return; + } + + const int size = + surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); + const QByteArray data(reinterpret_cast<const char*>(buffer), size); + if (file.write(data) != data.size()) { + QMessageBox::warning( + this, tr("Error"), + tr("Failed to completely write surface data to file. The saved data will " + "likely be corrupt.")); + } } else { UNREACHABLE_MSG("Unhandled filter selected"); } |