From 808736f34cfd752b4c4cf483660facd7749142bd Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sun, 8 Dec 2024 19:16:34 +0100 Subject: [PATCH] Add various formatting changes that ease maintenance --- CMakeLists.txt | 1 + source/CMakeLists.txt | 5 ++++ source/framework/settings.hpp | 2 ++ source/gui-sdl/main.cpp | 25 +++++-------------- source/interpreter.h | 1 + source/memory.cpp | 3 ++- source/os.cpp | 10 ++++++++ source/processes/dsp_hpv.cpp | 12 ++------- source/processes/ns.cpp | 3 +++ source/processes/pxi.cpp | 2 +- source/processes/pxi_fs.cpp | 2 +- source/settings.cpp | 2 ++ source/ui/key_database.cpp | 2 -- source/video_core/CMakeLists.txt | 1 + .../src/video_core/command_processor.cpp | 12 ++++----- .../src/video_core/debug_utils/debug_utils.h | 1 + 16 files changed, 43 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 112a73c..28f0ef8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Prefer Conan-provided packages over system ones set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) + # TODO: Move these flags into a "boost" cmake target add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED -DBOOST_COROUTINES_NO_DEPRECATION_WARNING) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 19dd1fd..dc8a2f0 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -67,6 +67,7 @@ target_sources(mikage PRIVATE ui/key_database.cpp utility/simple_tcp.cpp) + if (Pistache_FOUND) target_sources(mikage PRIVATE debug_server.cpp @@ -86,13 +87,17 @@ if (STD_FILESYSTEM_LIBRARY) target_link_libraries(mikage PRIVATE ${STD_FILESYSTEM_LIBRARY}) endif () + + target_link_libraries(mikage PRIVATE Boost::boost Boost::context Boost::filesystem Boost::iostreams Boost::program_options Boost::thread) if (Pistache_FOUND) target_link_libraries(mikage PRIVATE Pistache::Pistache) endif() + target_link_libraries(mikage PRIVATE SDL2::SDL2) target_link_libraries(mikage PRIVATE spdlog::spdlog) target_link_libraries(mikage PRIVATE Tracy::TracyClient) + diff --git a/source/framework/settings.hpp b/source/framework/settings.hpp index e4f6e18..ba4eb82 100644 --- a/source/framework/settings.hpp +++ b/source/framework/settings.hpp @@ -41,6 +41,7 @@ struct BootToHomeMenu : Config::BooleanOption { static constexpr const char* name = "BootToHomeMenu"; }; + // Use the native HID module upon OS startup struct UseNativeHID : Config::BooleanOption { static constexpr const char* name = "UseNativeHID"; @@ -51,6 +52,7 @@ struct UseNativeFS : Config::BooleanOption { static constexpr const char* name = "UseNativeFS"; }; + // Dump displayed frames to a series of binary files struct DumpFrames : Config::BooleanOption { static constexpr const char* name = "DumpFrames"; diff --git a/source/gui-sdl/main.cpp b/source/gui-sdl/main.cpp index 7172039..8c9f11e 100644 --- a/source/gui-sdl/main.cpp +++ b/source/gui-sdl/main.cpp @@ -41,8 +41,11 @@ #include + + void InstallCIA(std::filesystem::path, spdlog::logger&, const KeyDatabase&, HLE::PXI::FS::FileContext&, HLE::PXI::FS::File&); + using boost::endian::big_uint32_t; static const char* app_name = "Mikage"; @@ -53,27 +56,11 @@ std::mutex g_vulkan_queue_mutex; // TODO: Turn into a proper interface namespace bpo = boost::program_options; + static volatile int wait_debugger = 0; namespace Settings { -inline std::istream& operator>>(std::istream& is, CPUEngine& engine) { - std::string str; - is >> str; - if (str == "narmive") { - engine = CPUEngine::NARMive; - } else { - is.setstate(std::ios_base::failbit); - } - return is; -} - -inline std::ostream& operator<<(std::ostream& os, CPUEngine engine) { - switch (engine) { - case CPUEngine::NARMive: - return (os << "narmive"); - } -} inline std::istream& operator>>(std::istream& is, ShaderEngine& engine) { std::string str; @@ -124,6 +111,7 @@ int main(int argc, char* argv[]) { std::string filename; bool enable_debugging; + bpo::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") @@ -181,7 +169,6 @@ int main(int argc, char* argv[]) { settings.set(vm["attach_to_process"].as()); } settings.set(vm["appmemtype"].as()); - settings.set(Settings::CPUEngine::NARMive); if (vm["render_on_cpu"].as()) { settings.set(Settings::Renderer::Software); if (!vm.count("shader_engine")) { @@ -648,6 +635,7 @@ if (bootstrap_nand) // Experimental system bootstrapper break; } + case CustomEvents::CirclePadPosition: { float x, y; @@ -833,7 +821,6 @@ quit_application_loop: display->present_queue.waitIdle(); display->device->waitIdle(); - frontend_logger->info("Shutting down DSP JIT..."); session.reset(); } diff --git a/source/interpreter.h b/source/interpreter.h index 7308580..2c6b4f2 100644 --- a/source/interpreter.h +++ b/source/interpreter.h @@ -432,6 +432,7 @@ public: virtual void OnVirtualMemoryUnmapped(uint32_t vaddr, uint32_t size) = 0; + std::unique_ptr CreateExecutionContext() { return std::unique_ptr { CreateExecutionContextImpl() }; } diff --git a/source/memory.cpp b/source/memory.cpp index d117e7e..aeaf0c7 100644 --- a/source/memory.cpp +++ b/source/memory.cpp @@ -30,6 +30,7 @@ Memory::PhysicalMemory* g_mem = nullptr; // TODO: Remove bool g_dsp_running = false; // TODO: Remove bool g_dsp_just_reset = false; // TODO: Remove + namespace Pica { struct Context; } @@ -614,7 +615,6 @@ struct SPI : MemoryAccessHandler { struct CONFIG11 : MemoryAccessHandler { std::shared_ptr logger; - // TODO: Is this still needed? Teakra::Teakra *teakra = new Teakra::Teakra(Teakra::CreateInterpreterEngine); uint16_t unknown0x1c0 = 0; @@ -1015,6 +1015,7 @@ struct DSPMMIO : MemoryAccessHandler { } if (!config.trigger_reset() && prev_config.trigger_reset()) { + std::vector temp(0x80000); memcpy(temp.data(), g_teakra->GetDspMemory().data(), temp.size()); delete g_teakra; diff --git a/source/os.cpp b/source/os.cpp index eaffbf0..9460e90 100644 --- a/source/os.cpp +++ b/source/os.cpp @@ -6,6 +6,7 @@ #include "pica.hpp" #include "video_core/src/video_core/vulkan/renderer.hpp" // TODO: Get rid of this + #include #include #include @@ -46,6 +47,7 @@ #include "processes/pdn.hpp" #include "processes/ssl.hpp" + #include "platform/ns.hpp" #include "platform/sm.hpp" @@ -1046,6 +1048,7 @@ public: continue; } + GetLogger()->info("Launching FIRM title {:#x}", title_id); auto firm_file = HLE::PXI::FS::OpenNCCHSubFile(*this, info, 0, 1, std::basic_string_view(exefs_section, sizeof(exefs_section)), nullptr); auto [offset, num_bytes] = firm_titles.at(title_id); @@ -1070,6 +1073,7 @@ public: } } + GetLogger()->info("{}FakeThread \"BootThread\" exiting", ThreadPrinter{*this}); CallSVC(&OS::SVCExitThread); } catch (HLE::OS::FakeThread* stopped_thread) { @@ -1825,6 +1829,7 @@ EmuProcess::EmuProcess(OS& os, Interpreter::Setup& setup, uint32_t pid, std::sha case Settings::CPUEngine::NARMive: processor = Interpreter::CreateInterpreter(setup); break; + } } @@ -2191,6 +2196,7 @@ SVCFuture OS::SVCControlProcessMemory(Thread& source, Proce auto success = process.MapVirtualMemory(*paddr_opt, size, *vaddr_opt, permissions); ValidateContract(success); + Reschedule(source.GetPointer()); return MakeFuture(RESULT_OK, addr0); } @@ -4394,6 +4400,7 @@ SVCFuture> OS::SVCCreateProcess(Thread& s process->name = codeset->app_name; + // Finally, add the new process to the global process list RegisterProcess(process); @@ -5237,6 +5244,7 @@ SVCCallbackType OS::SVCRaw(Thread& source, unsigned svc_id, Interpreter::Executi return EncodeFuture(SVCControlProcessMemory(source, process, addr0, addr1, size, operation, permissions)); } + case 0x73: // CreateCodeSet { uint32_t code_set_info_addr = input_regs.reg[1]; @@ -6253,10 +6261,12 @@ void OS::Run(std::shared_ptr setup) { hle_titles["hid"].create = FakeProcessFactoryFor; } + if (!settings.get()) { hle_titles["fs"].create = FakeProcessFactoryFor; } + hle_titles["act"].create = FakeProcessFactoryFor; hle_titles["am"].create = FakeProcessFactoryFor; hle_titles["cam"].create = FakeProcessFactoryFor; diff --git a/source/processes/dsp_hpv.cpp b/source/processes/dsp_hpv.cpp index 30f2cde..175f517 100644 --- a/source/processes/dsp_hpv.cpp +++ b/source/processes/dsp_hpv.cpp @@ -7,6 +7,7 @@ #include + namespace HLE { namespace OS { @@ -66,6 +67,7 @@ struct DspService : SessionToPort { channel, num_bytes, peer == 0 ? "DSP" : peer == 1 ? "ARM" : "unknown peer"); Session::OnRequest(hypervisor, thread, session, description); + response.OnResponse([this](Hypervisor&, Thread& thread, Result result, uint32_t num_bytes_read, IPC::StaticBuffer data) { if (result != RESULT_OK || !num_bytes_read) { throw std::runtime_error("Unexpected error in ReadPipeIfPossible"); @@ -85,16 +87,6 @@ struct DspService : SessionToPort { signature[i] = thread.ReadMemory(data.addr + i); } -{ -auto filename = fmt::format("dsp.{:x}.dsp1", fmt::join(signature.begin(), signature.begin() + 16, "")); -fprintf(stderr, "%s\n", filename.c_str()); -std::ofstream dump(filename, /*std::ios::out |*/ std::ios::binary); -for (uint32_t i = 0; i < size; ++i) { -uint8_t val = thread.ReadMemory(data.addr + i); -dump.write((char*)&val, sizeof(val)); -} -} - pipe_read_state = PipeReadState::Reset; }); diff --git a/source/processes/ns.cpp b/source/processes/ns.cpp index f8dc214..2331f7d 100644 --- a/source/processes/ns.cpp +++ b/source/processes/ns.cpp @@ -45,6 +45,7 @@ using Platform::NS::AppletCommand; using Platform::NS::AppletPos; using Platform::PXI::PM::ProgramInfo; + template static uint32_t GetDecompressedLZSSDataSize(const RangeIn& compressed_reverse) { // Reverse the input buffer @@ -136,6 +137,7 @@ static void DecompressLZSSData(const RangeIn& compressed_reverse, const RangeOut } } + HandleTable::Entry LoadProcessFromFile(FakeThread& source, bool from_firm, const FileFormat::ExHeader& exheader, @@ -408,6 +410,7 @@ OS::ResultAnd LaunchTitleInternal(FakeThread& source, bool from_firm, return std::make_tuple(RESULT_OK, process_id); } + } // namespace OS } // namespace HLE diff --git a/source/processes/pxi.cpp b/source/processes/pxi.cpp index 3c06e4e..554f8ff 100644 --- a/source/processes/pxi.cpp +++ b/source/processes/pxi.cpp @@ -519,7 +519,7 @@ static void PXIPSCommandHandler(FakeThread& thread, Context& context, const IPC: throw IPC::IPCError{header.raw, 0xdeadbef1}; } } catch (const IPC::IPCError& err) { - throw std::runtime_error(fmt::format("Unknown PxiPM service command with header {:#010x}", err.header)); + throw std::runtime_error(fmt::format("Unknown pxi:ps9 service command with header {:#010x}", err.header)); } void FakePXI::PSThread(FakeThread& thread, Context& context) { diff --git a/source/processes/pxi_fs.cpp b/source/processes/pxi_fs.cpp index 907919c..a81dba2 100644 --- a/source/processes/pxi_fs.cpp +++ b/source/processes/pxi_fs.cpp @@ -1,4 +1,4 @@ -#include "fs_common.hpp" +#include "fs_common.hpp" #include "pxi.hpp" #include "os.hpp" diff --git a/source/settings.cpp b/source/settings.cpp index 218ee73..4d926f5 100644 --- a/source/settings.cpp +++ b/source/settings.cpp @@ -11,12 +11,14 @@ namespace Config { template<> bool BooleanOption::default_val = false; + template<> bool BooleanOption::default_val = false; template<> bool BooleanOption::default_val = false; + template<> bool BooleanOption::default_val = false; diff --git a/source/ui/key_database.cpp b/source/ui/key_database.cpp index 7cf1a3b..982810d 100644 --- a/source/ui/key_database.cpp +++ b/source/ui/key_database.cpp @@ -54,8 +54,6 @@ KeyDatabase LoadKeyDatabase(spdlog::logger& logger, const std::filesystem::path& // Ignore } else if (line.starts_with("dlp") || line.starts_with("nfc")) { // Not currently used - } else { - logger.warn("Ignoring line in {}: {}", filename.string(), line); } } diff --git a/source/video_core/CMakeLists.txt b/source/video_core/CMakeLists.txt index 0ece943..3d87385 100644 --- a/source/video_core/CMakeLists.txt +++ b/source/video_core/CMakeLists.txt @@ -31,6 +31,7 @@ if (PISTACHE_FOUND) target_sources(video_core PRIVATE src/debug/gpu.cpp) endif() + target_include_directories(video_core PRIVATE src/support src/ externals/nihstro/include) target_include_directories(video_core PRIVATE ../) # target_include_directories(video_core PRIVATE externals/vulkan-hpp/vulkan) TODO: Need to also include Vulkan headers with matching version... For now, I'm just using the headers shipping with my Linux distribution diff --git a/source/video_core/src/video_core/command_processor.cpp b/source/video_core/src/video_core/command_processor.cpp index 0a18d68..8c5f3c7 100644 --- a/source/video_core/src/video_core/command_processor.cpp +++ b/source/video_core/src/video_core/command_processor.cpp @@ -150,6 +150,7 @@ static bool IsNopDraw(const Regs& registers) { return false; } + static inline void WritePicaReg(Context& context, u32 id, u32 value, u32 mask, CommandListIterator& next_command) { auto& registers = context.registers; if (id >= registers.NumIds()) @@ -273,6 +274,7 @@ static inline void WritePicaReg(Context& context, u32 id, u32 value, u32 mask, C if (g_debug_context) g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr); + const auto& attribute_config = registers.vertex_attributes; VertexLoader vertex_loader(context, attribute_config); @@ -284,6 +286,7 @@ static inline void WritePicaReg(Context& context, u32 id, u32 value, u32 mask, C const uint32_t index_address = attribute_config.GetPhysicalBaseAddress() + index_info.offset; const bool index_u16 = index_info.format != 0; + const bool render_on_cpu = (context.settings->get() == Settings::Renderer::Software); ZoneNamedN(TriangleBatch, "Triangle Batch", true); @@ -423,11 +426,6 @@ Vulkan::preassembled_triangles = true; id <= PICA_REG_INDEX(fixed_vertex_attribute_sink.data[2])); }; -// context.shader_uniforms.f[95].x = float24::FromFloat32(1.0); -// context.shader_uniforms.f[95].y = float24::FromFloat32(1.0); -// context.shader_uniforms.f[95].z = float24::FromFloat32(1.0); -// context.shader_uniforms.f[95].w = float24::FromFloat32(1.0); - auto& sink = registers.fixed_vertex_attribute_sink; if (sink.IsImmediateSubmission()) { const bool render_on_cpu = (context.settings->get() == Settings::Renderer::Software); @@ -445,6 +443,7 @@ Vulkan::preassembled_triangles = true; break; } + VertexShader::InputVertex input {}; auto& engine = context.shader_engines.GetOrCompile(context, context.settings->get(), registers.vs_main_offset); engine.Reset(registers.vs_input_register_map, input, 1 + registers.max_shader_input_attribute_index()); @@ -467,7 +466,6 @@ Vulkan::preassembled_triangles = true; throw std::runtime_error("Submitted other commands before vertex was complete"); } data_buffer[word_index] = next_command.Value(); -fprintf(stderr, "WritePicaReg_cont: %#04x <- %#010x & %#010x\n", next_command.Id(), next_command.Value(), next_command.Mask()); ++next_command; } first = false; @@ -692,7 +690,7 @@ fprintf(stderr, "WritePicaReg_cont: %#04x <- %#010x & %#010x\n", next_command.Id void ProcessCommandList(Context& context, PAddr list_addr, u32 size) { CommandListIterator it(*context.mem, list_addr, size); - fprintf(stderr, "\nWritePicaReg: Incoming command list\n"); + while (it) { auto id = it.Id(); auto value = it.Value(); diff --git a/source/video_core/src/video_core/debug_utils/debug_utils.h b/source/video_core/src/video_core/debug_utils/debug_utils.h index 5f465e2..139e551 100644 --- a/source/video_core/src/video_core/debug_utils/debug_utils.h +++ b/source/video_core/src/video_core/debug_utils/debug_utils.h @@ -131,6 +131,7 @@ public: Event active_breakpoint; bool at_breakpoint = false; + private: /** * Private default constructor to make sure people always construct this through Construct()