can't use shared_ptr on SDL_Window

This commit is contained in:
SimoZ64
2025-05-07 17:22:01 +02:00
parent c175d58f03
commit 6cf2e7ab70
11 changed files with 28 additions and 34 deletions

View File

@@ -23,8 +23,7 @@ Program *fullscreen_quad_program;
// Copied and modified from WSI::init_context_from_platform // Copied and modified from WSI::init_context_from_platform
Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, unsigned num_thread_indices, Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, unsigned num_thread_indices,
const Context::SystemHandles &system_handles, const Context::SystemHandles &system_handles) {
InstanceFactory *instance_factory) {
VK_ASSERT(platform); VK_ASSERT(platform);
auto instance_ext = platform->get_instance_extensions(); auto instance_ext = platform->get_instance_extensions();
auto device_ext = platform->get_device_extensions(); auto device_ext = platform->get_device_extensions();
@@ -33,9 +32,6 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, unsigned nu
new_context->set_application_info(platform->get_application_info()); new_context->set_application_info(platform->get_application_info());
new_context->set_num_thread_indices(num_thread_indices); new_context->set_num_thread_indices(num_thread_indices);
new_context->set_system_handles(system_handles); new_context->set_system_handles(system_handles);
if (instance_factory) {
new_context->set_instance_factory(instance_factory);
}
if (!new_context->init_instance(instance_ext.data(), instance_ext.size(), CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT)) { if (!new_context->init_instance(instance_ext.data(), instance_ext.size(), CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT)) {
Util::panic("Failed to create Vulkan instance.\n"); Util::panic("Failed to create Vulkan instance.\n");
@@ -57,8 +53,7 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, unsigned nu
return new_context; return new_context;
} }
void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instanceFactory, void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<WSIPlatform> &wsi_platform,
const std::shared_ptr<WSIPlatform> &wsi_platform,
const std::shared_ptr<WindowInfo> &newWindowInfo) { const std::shared_ptr<WindowInfo> &newWindowInfo) {
wsi = std::make_shared<WSI>(); wsi = std::make_shared<WSI>();
wsi->set_backbuffer_srgb(false); wsi->set_backbuffer_srgb(false);
@@ -66,7 +61,7 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instan
wsi->set_present_mode(PresentMode::SyncToVBlank); wsi->set_present_mode(PresentMode::SyncToVBlank);
Context::SystemHandles handles; Context::SystemHandles handles;
if (!wsi->init_from_existing_context(InitVulkanContext(wsi_platform.get(), 1, handles, instanceFactory.get()))) { if (!wsi->init_from_existing_context(InitVulkanContext(wsi_platform.get(), 1, handles))) {
Util::panic("Failed to initialize WSI: init_from_existing_context() failed"); Util::panic("Failed to initialize WSI: init_from_existing_context() failed");
} }
@@ -83,7 +78,7 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instan
void ParallelRDP::Init(const std::shared_ptr<WSIPlatform> &wsiPlatform, void ParallelRDP::Init(const std::shared_ptr<WSIPlatform> &wsiPlatform,
const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram) { const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram) {
LoadWSIPlatform(nullptr, wsiPlatform, newWindowInfo); LoadWSIPlatform(wsiPlatform, newWindowInfo);
ResourceLayout vertLayout; ResourceLayout vertLayout;
ResourceLayout fragLayout; ResourceLayout fragLayout;

View File

@@ -34,8 +34,7 @@ public:
std::shared_ptr<WindowInfo> windowInfo; std::shared_ptr<WindowInfo> windowInfo;
private: private:
void LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &, void LoadWSIPlatform(const std::shared_ptr<Vulkan::WSIPlatform> &, const std::shared_ptr<WindowInfo> &);
const std::shared_ptr<WindowInfo> &);
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>) const; void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>) const;
void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>) const; void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>) const;
}; };

View File

@@ -1,7 +1,6 @@
#include <Audio.hpp> #include <Audio.hpp>
#include <SDL3/SDL_audio.h>
#include <SDL3/SDL_init.h>
#include <log.hpp> #include <log.hpp>
#include <SDL3/SDL.h>
namespace n64 { namespace n64 {
#define AUDIO_SAMPLE_RATE 44100 #define AUDIO_SAMPLE_RATE 44100

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <MemoryHelpers.hpp> #include <MemoryHelpers.hpp>
#include <SDL3/SDL_audio.h> #include <SDL3/SDL.h>
namespace n64 { namespace n64 {
struct AudioDevice { struct AudioDevice {

View File

@@ -1,8 +1,6 @@
#include <InputSettings.hpp> #include <InputSettings.hpp>
#include <log.hpp> #include <log.hpp>
#include <SDL3/SDL_events.h> #include <SDL3/SDL.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_keycode.h>
InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) { InputSettings::InputSettings(nlohmann::json &settings) : settings(settings) {
for(auto& kb : kbButtons) { for(auto& kb : kbButtons) {

View File

@@ -3,7 +3,7 @@
#include <unordered_map> #include <unordered_map>
#include <ImGuiImpl/PushButton.hpp> #include <ImGuiImpl/PushButton.hpp>
#include <ImGuiImpl/Combobox.hpp> #include <ImGuiImpl/Combobox.hpp>
#include <SDL3/SDL_keycode.h> #include <SDL3/SDL.h>
class InputSettings final { class InputSettings final {
bool grabbing = false; bool grabbing = false;

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <NativeWindow.hpp>
#include <RenderWidget.hpp> #include <RenderWidget.hpp>
#include <Debugger.hpp> #include <Debugger.hpp>
#include <ImGuiImpl/Menu.hpp> #include <ImGuiImpl/Menu.hpp>
#include <ImGuiImpl/StatusBar.hpp> #include <ImGuiImpl/StatusBar.hpp>
#include <NativeWindow.hpp>
#include <EmuThread.hpp> #include <EmuThread.hpp>
#include <Discord.hpp> #include <Discord.hpp>
@@ -14,10 +14,10 @@ public:
double fpsCounter; double fpsCounter;
gui::MenuBar<true> menuBar; gui::MenuBar<true> menuBar;
gui::MenuItem actionPause{"Pause"}, actionStop{"Stop"}, actionReset{"Reset"}; gui::MenuItem actionPause{"Pause"}, actionStop{"Stop"}, actionReset{"Reset"};
std::shared_ptr<n64::Core> core;
EmuThread emuThread;
SettingsWindow settingsWindow; SettingsWindow settingsWindow;
std::shared_ptr<n64::Core> core;
RenderWidget vulkanWidget; RenderWidget vulkanWidget;
EmuThread emuThread;
int run(); int run();
void LoadTAS(const std::string &path) const noexcept; void LoadTAS(const std::string &path) const noexcept;
@@ -28,5 +28,4 @@ private:
std::function<void()> emuExitFunc; std::function<void()> emuExitFunc;
gui::PopupWindow about{"About Kaizen"}; gui::PopupWindow about{"About Kaizen"};
gui::StatusBar statusBar{}; gui::StatusBar statusBar{};
bool textPauseToggle = false;
}; };

View File

@@ -1,18 +1,22 @@
#pragma once #pragma once
#include <SDL3/SDL_video.h> #include <SDL3/SDL.h>
#include <SDL3/SDL_init.h>
#include <string> #include <string>
#include <memory>
namespace gui { namespace gui {
struct NativeWindow { struct NativeWindow {
NativeWindow(const std::string& title, int w, int h, int posX = SDL_WINDOWPOS_CENTERED, int posY = SDL_WINDOWPOS_CENTERED) { NativeWindow(const std::string& title, int w, int h, int posX = SDL_WINDOWPOS_CENTERED, int posY = SDL_WINDOWPOS_CENTERED) {
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
window = std::make_shared<SDL_Window>(SDL_CreateWindow(title.c_str(), w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY)); window = SDL_CreateWindow(title.c_str(), w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
}
~NativeWindow() {
SDL_DestroyWindow(window);
} }
void setTitle(const std::string& v) { title = v; } void setTitle(const std::string& v) { title = v; }
const std::shared_ptr<SDL_Window>& getHandle() { return window; } SDL_Window* getHandle() { return window; }
private: private:
std::shared_ptr<SDL_Window> window; SDL_Window* window;
std::string title; std::string title;
}; };
} }

View File

@@ -1,9 +1,9 @@
#include <Core.hpp> #include <Core.hpp>
#include <KaizenGui.hpp> #include <KaizenGui.hpp>
#include <RenderWidget.hpp> #include <RenderWidget.hpp>
#include <SDL3/SDL_events.h> #include <SDL3/SDL.h>
RenderWidget::RenderWidget(const std::shared_ptr<n64::Core> &core, const std::shared_ptr<SDL_Window>& window) { RenderWidget::RenderWidget(const std::shared_ptr<n64::Core> &core, SDL_Window* window) {
if (!Vulkan::Context::init_loader(nullptr)) { if (!Vulkan::Context::init_loader(nullptr)) {
Util::panic("Could not initialize Vulkan ICD"); Util::panic("Could not initialize Vulkan ICD");
} }

View File

@@ -22,7 +22,7 @@ private:
class ImGuiWSIPlatform final : public Vulkan::WSIPlatform { class ImGuiWSIPlatform final : public Vulkan::WSIPlatform {
public: public:
explicit ImGuiWSIPlatform(const std::shared_ptr<n64::Core> &core, const std::shared_ptr<SDL_Window> &window) : window(window), core(core) {} explicit ImGuiWSIPlatform(const std::shared_ptr<n64::Core> &core, SDL_Window* window) : window(window), core(core) {}
std::vector<const char *> get_instance_extensions() override { std::vector<const char *> get_instance_extensions() override {
auto vec = std::vector<const char *>(); auto vec = std::vector<const char *>();
@@ -38,7 +38,7 @@ public:
} }
VkSurfaceKHR create_surface(VkInstance instance, VkPhysicalDevice pDevice) override { VkSurfaceKHR create_surface(VkInstance instance, VkPhysicalDevice pDevice) override {
SDL_Vulkan_CreateSurface(window.get(), instance, nullptr, &surface); SDL_Vulkan_CreateSurface(window, instance, nullptr, &surface);
return surface; return surface;
} }
@@ -62,7 +62,7 @@ public:
VkApplicationInfo appInfo{.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3}; VkApplicationInfo appInfo{.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .apiVersion = VK_API_VERSION_1_3};
std::shared_ptr<SDL_Window> window{}; SDL_Window* window{};
VkSurfaceKHR surface; VkSurfaceKHR surface;
private: private:
std::shared_ptr<n64::Core> core; std::shared_ptr<n64::Core> core;
@@ -73,7 +73,7 @@ private:
class RenderWidget final { class RenderWidget final {
public: public:
explicit RenderWidget(const std::shared_ptr<n64::Core> &, const std::shared_ptr<SDL_Window>&); explicit RenderWidget(const std::shared_ptr<n64::Core> &, SDL_Window*);
std::shared_ptr<ParallelRDP::WindowInfo> windowInfo; std::shared_ptr<ParallelRDP::WindowInfo> windowInfo;
std::shared_ptr<ImGuiWSIPlatform> wsiPlatform; std::shared_ptr<ImGuiWSIPlatform> wsiPlatform;

View File

@@ -4,7 +4,7 @@
#include <InputSettings.hpp> #include <InputSettings.hpp>
#include <ImGuiImpl/TabBar.hpp> #include <ImGuiImpl/TabBar.hpp>
#include <ImGuiImpl/PopupWindow.hpp> #include <ImGuiImpl/PopupWindow.hpp>
#include <SDL3/SDL_keycode.h> #include <SDL3/SDL.h>
#include <memory> #include <memory>
class SettingsWindow final { class SettingsWindow final {