From 8fa341bf72d03fbf2726221af298cfa00d15f649 Mon Sep 17 00:00:00 2001 From: SimoZ64 Date: Tue, 20 May 2025 17:47:52 +0200 Subject: [PATCH] Upgrade to C++23 --- external/capstone/CMakeLists.txt | 2 +- src/frontend/CMakeLists.txt | 2 +- src/frontend/EmuThread.cpp | 4 +- src/frontend/KaizenGui.cpp | 108 ------------------------------- src/frontend/RenderWidget.cpp | 7 +- src/frontend/RenderWidget.hpp | 20 +++--- src/utils/byteswap.hpp | 16 ++--- 7 files changed, 26 insertions(+), 133 deletions(-) diff --git a/external/capstone/CMakeLists.txt b/external/capstone/CMakeLists.txt index b4c77a79..e4627bf3 100644 --- a/external/capstone/CMakeLists.txt +++ b/external/capstone/CMakeLists.txt @@ -30,7 +30,7 @@ string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PROJECT_VERSION_BASE ${PROJECT_VE # Set the project version without the pre-release identifier project(capstone VERSION ${PROJECT_VERSION_BASE}) -set(UNIX_COMPILER_OPTIONS -Werror -Wall -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation) +set(UNIX_COMPILER_OPTIONS -Werror -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation) # maybe-uninitialized is only supported by newer versions of GCC. # Unfortunately, it is pretty unreliable and reports wrong results. diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index e4994391..10d58a51 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -11,7 +11,7 @@ if(APPLE) enable_language(OBJC) endif() -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) include_directories( diff --git a/src/frontend/EmuThread.cpp b/src/frontend/EmuThread.cpp index dfd67ad3..8cfe0105 100644 --- a/src/frontend/EmuThread.cpp +++ b/src/frontend/EmuThread.cpp @@ -8,7 +8,9 @@ EmuThread::EmuThread(const std::shared_ptr &core, double &fps, Render void EmuThread::start() noexcept { thread = std::thread([this]() { isRunning = true; - + core->parallel.Init(renderWidget.wsiPlatform, renderWidget.windowInfo, + core->cpu->GetMem().GetRDRAMPtr()); + auto lastSample = std::chrono::high_resolution_clock::now(); auto avgFps = 16.667; auto sampledFps = 0; diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index d83cd5fb..25d6ba99 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -15,115 +15,7 @@ static void check_vk_result(VkResult err) abort(); } -void KaizenGui::InitImGui() { - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - (void)io; - - // Setup Dear ImGui style - ImGui::StyleColorsDark(); - - ParallelRDP& prdp = core->parallel; - Vulkan::WSI& wsi = *prdp.wsi.get(); - volkInitialize(); - volkLoadInstance(wsi.get_context().get_instance()); - ImGui_ImplVulkan_LoadFunctions(VK_API_VERSION_1_3, [](const char* function_name, void* userdata) { - auto wsi = (Vulkan::WSI*)userdata; - return vkGetInstanceProcAddr(wsi->get_context().get_instance(), function_name); - }, &wsi); - - ImGui_ImplVulkan_InitInfo init_info = {}; - // Create Descriptor Pool - { - VkDescriptorPoolSize pool_sizes[] = - { - { VK_DESCRIPTOR_TYPE_SAMPLER, 1000 }, - { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 }, - { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000 }, - { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000 }, - { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000 }, - { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000 }, - { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000 }, - { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 }, - { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000 }, - { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000 }, - { VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000 } - }; - VkDescriptorPoolCreateInfo pool_info = {}; - pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; - pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; - pool_info.maxSets = 1000 * IM_ARRAYSIZE(pool_sizes); - pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes); - pool_info.pPoolSizes = pool_sizes; - auto err = vkCreateDescriptorPool(wsi.get_context().get_device(), &pool_info, nullptr, &init_info.DescriptorPool); - check_vk_result(err); - } - - // Create the Render Pass - VkRenderPass renderPass; - { - VkAttachmentDescription attachment = {}; - attachment.format = wsi.get_device().get_swapchain_view().get_format(); - attachment.samples = VK_SAMPLE_COUNT_1_BIT; - attachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE; - attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; - VkAttachmentReference color_attachment = {}; - color_attachment.attachment = 0; - color_attachment.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - VkSubpassDescription subpass = {}; - subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - subpass.colorAttachmentCount = 1; - subpass.pColorAttachments = &color_attachment; - VkSubpassDependency dependency = {}; - dependency.srcSubpass = VK_SUBPASS_EXTERNAL; - dependency.dstSubpass = 0; - dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; - dependency.srcAccessMask = 0; - dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - VkRenderPassCreateInfo info = {}; - info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - info.attachmentCount = 1; - info.pAttachments = &attachment; - info.subpassCount = 1; - info.pSubpasses = &subpass; - info.dependencyCount = 1; - info.pDependencies = &dependency; - auto err = vkCreateRenderPass(wsi.get_context().get_device(), &info, nullptr, &renderPass); - check_vk_result(err); - } - - // Setup Platform/Renderer backends - ImGui_ImplSDL3_InitForVulkan(window.getHandle()); - init_info.Instance = wsi.get_context().get_instance(); - init_info.PhysicalDevice = wsi.get_context().get_gpu(); - init_info.Device = wsi.get_context().get_device(); - init_info.QueueFamily = wsi.get_context().get_queue_info().family_indices[Vulkan::QUEUE_INDEX_GRAPHICS]; - init_info.Queue = wsi.get_context().get_queue_info().queues[Vulkan::QUEUE_INDEX_GRAPHICS]; - init_info.PipelineCache = nullptr; - init_info.Allocator = nullptr; - init_info.MinImageCount = 2; - init_info.ImageCount = 2; - init_info.RenderPass = renderPass; - init_info.CheckVkResultFn = check_vk_result; - - ImGui_ImplVulkan_Init(&init_info); - - io.Fonts->AddFontDefault(); - { - ImGui_ImplVulkan_CreateFontsTexture(); - } -} - KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { - core->parallel.Init(vulkanWidget.wsiPlatform, vulkanWidget.windowInfo, core->cpu->GetMem().GetRDRAMPtr()); - InitImGui(); - emuExitFunc = [&]() { quit = true; if (emuThread.isRunning) { diff --git a/src/frontend/RenderWidget.cpp b/src/frontend/RenderWidget.cpp index 289cb8a8..0009b508 100644 --- a/src/frontend/RenderWidget.cpp +++ b/src/frontend/RenderWidget.cpp @@ -2,16 +2,17 @@ #include #include #include +#include -RenderWidget::RenderWidget(const std::shared_ptr &core, SDL_Window* window) { +RenderWidget::RenderWidget(const std::shared_ptr &core, InputSettings& inputSettings, SDL_Window* window) : inputSettings(inputSettings) { if (!Vulkan::Context::init_loader(nullptr)) { Util::panic("Could not initialize Vulkan ICD"); } - wsiPlatform = std::make_shared(core, window); + wsiPlatform = std::make_shared(core, inputSettings, window); } -void ImGuiWSIPlatform::poll_input() { +void SDLWSIPlatform::poll_input() { if (!canPollEvents) return; diff --git a/src/frontend/RenderWidget.hpp b/src/frontend/RenderWidget.hpp index c26538b1..515f42cf 100644 --- a/src/frontend/RenderWidget.hpp +++ b/src/frontend/RenderWidget.hpp @@ -3,13 +3,15 @@ #include #include +struct InputSettings; + namespace n64 { struct Core; } -class ImGuiParallelRdpWindowInfo final : public ParallelRDP::WindowInfo { +class SDLParallelRdpWindowInfo final : public ParallelRDP::WindowInfo { public: - explicit ImGuiParallelRdpWindowInfo(const std::shared_ptr window) : window(window) {} + explicit SDLParallelRdpWindowInfo(const std::shared_ptr window) : window(window) {} CoordinatePair get_window_size() override { int w,h; SDL_GetWindowSizeInPixels(window.get(), &w, &h); @@ -20,18 +22,18 @@ private: std::shared_ptr window{}; }; -class ImGuiWSIPlatform final : public Vulkan::WSIPlatform { +class SDLWSIPlatform final : public Vulkan::WSIPlatform { public: - explicit ImGuiWSIPlatform(const std::shared_ptr &core, SDL_Window* window) : window(window), core(core) {} + explicit SDLWSIPlatform(const std::shared_ptr &core, InputSettings& inputSettings, SDL_Window* window) : window(window), inputSettings(inputSettings), core(core) {} std::vector get_instance_extensions() override { auto vec = std::vector(); u32 extCount; const auto &extensions = SDL_Vulkan_GetInstanceExtensions(&extCount); - vec.reserve(extCount); + vec.resize(extCount); for (u32 i = 0; i < extCount; i++) { - vec.emplace_back(extensions[i]); + vec[i] = extensions[i]; } return vec; @@ -67,14 +69,16 @@ public: private: std::shared_ptr core; SDL_Gamepad *gamepad{}; + InputSettings& inputSettings; bool gamepadConnected = false; bool canPollEvents = true; }; class RenderWidget final { public: - explicit RenderWidget(const std::shared_ptr &, SDL_Window*); + explicit RenderWidget(const std::shared_ptr &, InputSettings&, SDL_Window*); std::shared_ptr windowInfo; - std::shared_ptr wsiPlatform; + std::shared_ptr wsiPlatform; + InputSettings& inputSettings; }; diff --git a/src/utils/byteswap.hpp b/src/utils/byteswap.hpp index 02a42ab8..8117f971 100644 --- a/src/utils/byteswap.hpp +++ b/src/utils/byteswap.hpp @@ -1,14 +1,8 @@ #pragma once #include +#include -static FORCE_INLINE u16 bswap(const u16 x) { return (x & 0xFF00u) >> 8 | (x & 0x00FFu) << 8; } - -static FORCE_INLINE u32 bswap(const u32 x) { - return (x & 0xFF000000u) >> 24u | (x & 0x00FF0000u) >> 8u | (x & 0x0000FF00u) << 8u | (x & 0x000000FFu) << 24u; -} - -static FORCE_INLINE u64 bswap(const u64 x) { - return (x & 0xFF00000000000000u) >> 56u | (x & 0x00FF000000000000u) >> 40u | (x & 0x0000FF0000000000u) >> 24u | - (x & 0x000000FF00000000u) >> 8u | (x & 0x00000000FF000000u) << 8u | (x & 0x0000000000FF0000u) << 24u | - (x & 0x000000000000FF00u) << 40u | (x & 0x00000000000000FFu) << 56u; -} +template +static constexpr T bswap(const T x) { + return std::byteswap(x); +} \ No newline at end of file