Link ImGui
This commit is contained in:
90
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
90
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
@@ -7,14 +7,13 @@
|
|||||||
#include <imgui_impl_vulkan.h>
|
#include <imgui_impl_vulkan.h>
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_vulkan.h>
|
#include <SDL3/SDL_vulkan.h>
|
||||||
#include <RenderWidget.hpp>
|
|
||||||
|
|
||||||
using namespace Vulkan;
|
using namespace Vulkan;
|
||||||
using namespace RDP;
|
using namespace RDP;
|
||||||
|
|
||||||
bool ParallelRDP::IsFramerateUnlocked() { return wsi->get_present_mode() != PresentMode::SyncToVBlank; }
|
bool ParallelRDP::IsFramerateUnlocked() const { return wsi->get_present_mode() != PresentMode::SyncToVBlank; }
|
||||||
|
|
||||||
void ParallelRDP::SetFramerateUnlocked(bool unlocked) {
|
void ParallelRDP::SetFramerateUnlocked(bool unlocked) const {
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
wsi->set_present_mode(PresentMode::UnlockedForceTearing);
|
wsi->set_present_mode(PresentMode::UnlockedForceTearing);
|
||||||
} else {
|
} else {
|
||||||
@@ -24,9 +23,17 @@ void ParallelRDP::SetFramerateUnlocked(bool unlocked) {
|
|||||||
|
|
||||||
Program *fullscreen_quad_program;
|
Program *fullscreen_quad_program;
|
||||||
|
|
||||||
void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &instanceFactory,
|
static void check_vk_result(VkResult err) {
|
||||||
const std::shared_ptr<Vulkan::WSIPlatform> &wsi_platform,
|
if (err == 0)
|
||||||
const std::shared_ptr<ParallelRDP::WindowInfo> &newWindowInfo) {
|
return;
|
||||||
|
fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err);
|
||||||
|
if (err < 0)
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instanceFactory,
|
||||||
|
const std::shared_ptr<WSIPlatform> &wsi_platform,
|
||||||
|
const std::shared_ptr<WindowInfo> &newWindowInfo, void *winPtr) {
|
||||||
wsi = std::make_shared<WSI>();
|
wsi = std::make_shared<WSI>();
|
||||||
wsi->set_backbuffer_srgb(false);
|
wsi->set_backbuffer_srgb(false);
|
||||||
wsi->set_platform(wsi_platform.get());
|
wsi->set_platform(wsi_platform.get());
|
||||||
@@ -40,24 +47,64 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory>
|
|||||||
|
|
||||||
auto props = SDL_CreateProperties();
|
auto props = SDL_CreateProperties();
|
||||||
#ifdef SDL_PLATFORM_LINUX
|
#ifdef SDL_PLATFORM_LINUX
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER,
|
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER, winPtr);
|
||||||
dynamic_cast<QtWSIPlatform>(wsi_platform.get())->window->winId());
|
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, winPtr);
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_X11_DISPLAY_POINTER,
|
|
||||||
dynamic_cast<QtWSIPlatform>(wsi_platform.get())->window->winId());
|
|
||||||
#elif SDL_PLATFORM_WINDOWS
|
#elif SDL_PLATFORM_WINDOWS
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER,
|
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, winPtr);
|
||||||
dynamic_cast<QtWSIPlatform>(wsi_platform.get())->window->winId());
|
|
||||||
#else
|
#else
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER,
|
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER, winPtr);
|
||||||
dynamic_cast<QtWSIPlatform>(wsi_platform.get())->window->winId());
|
|
||||||
#endif
|
#endif
|
||||||
SDLWindow = SDL_CreateWindowWithProperties(props);
|
SDLWindow = SDL_CreateWindowWithProperties(props);
|
||||||
|
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||||
|
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
ImGui_ImplSDL3_InitForVulkan(SDLWindow);
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||||
|
init_info.Instance = wsi->get_context().get_instance();
|
||||||
|
init_info.PhysicalDevice = wsi->get_device().get_physical_device();
|
||||||
|
init_info.Device = wsi->get_device().get_device();
|
||||||
|
init_info.QueueFamily = wsi->get_context().get_queue_info().family_indices[QUEUE_INDEX_GRAPHICS];
|
||||||
|
init_info.Queue = wsi->get_context().get_queue_info().queues[QUEUE_INDEX_GRAPHICS];
|
||||||
|
init_info.PipelineCache = nullptr;
|
||||||
|
{
|
||||||
|
VkDescriptorPoolSize pool_sizes[] = {
|
||||||
|
{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1},
|
||||||
|
};
|
||||||
|
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 = 1;
|
||||||
|
pool_info.poolSizeCount = IM_ARRAYSIZE(pool_sizes);
|
||||||
|
pool_info.pPoolSizes = pool_sizes;
|
||||||
|
auto err = wsi->get_device().get_device_table().vkCreateDescriptorPool(wsi->get_device().get_device(), &pool_info,
|
||||||
|
nullptr, &init_info.DescriptorPool);
|
||||||
|
check_vk_result(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
init_info.RenderPass =
|
||||||
|
wsi->get_device()
|
||||||
|
.request_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly), false)
|
||||||
|
.get_render_pass();
|
||||||
|
init_info.Subpass = 0;
|
||||||
|
init_info.MinImageCount = 2;
|
||||||
|
init_info.ImageCount = 2;
|
||||||
|
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
init_info.Allocator = nullptr;
|
||||||
|
init_info.CheckVkResultFn = check_vk_result;
|
||||||
|
ImGui_ImplVulkan_Init(&init_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::Init(const std::shared_ptr<Vulkan::InstanceFactory> &factory,
|
void ParallelRDP::Init(const std::shared_ptr<Vulkan::InstanceFactory> &factory,
|
||||||
const std::shared_ptr<Vulkan::WSIPlatform> &wsiPlatform,
|
const std::shared_ptr<Vulkan::WSIPlatform> &wsiPlatform,
|
||||||
const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram) {
|
const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram, void *winPtr) {
|
||||||
LoadWSIPlatform(factory, wsiPlatform, newWindowInfo);
|
LoadWSIPlatform(factory, wsiPlatform, newWindowInfo, winPtr);
|
||||||
|
|
||||||
ResourceLayout vertLayout;
|
ResourceLayout vertLayout;
|
||||||
ResourceLayout fragLayout;
|
ResourceLayout fragLayout;
|
||||||
@@ -102,7 +149,8 @@ void ParallelRDP::Init(const std::shared_ptr<Vulkan::InstanceFactory> &factory,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image, Util::IntrusivePtr<CommandBuffer> cmd) {
|
void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image,
|
||||||
|
Util::IntrusivePtr<CommandBuffer> cmd) const {
|
||||||
cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp);
|
cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp);
|
||||||
cmd->set_program(fullscreen_quad_program);
|
cmd->set_program(fullscreen_quad_program);
|
||||||
cmd->set_quad_state();
|
cmd->set_quad_state();
|
||||||
@@ -136,7 +184,7 @@ void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr<Image> image, Ut
|
|||||||
cmd->draw(3, 1);
|
cmd->draw(3, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) {
|
void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) const {
|
||||||
wsi->begin_frame();
|
wsi->begin_frame();
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
@@ -170,7 +218,7 @@ void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) {
|
|||||||
wsi->end_frame();
|
wsi->end_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::UpdateScreen(n64::VI &vi) {
|
void ParallelRDP::UpdateScreen(const n64::VI &vi) const {
|
||||||
command_processor->set_vi_register(VIRegister::Control, vi.status.raw);
|
command_processor->set_vi_register(VIRegister::Control, vi.status.raw);
|
||||||
command_processor->set_vi_register(VIRegister::Origin, vi.origin);
|
command_processor->set_vi_register(VIRegister::Origin, vi.origin);
|
||||||
command_processor->set_vi_register(VIRegister::Width, vi.width);
|
command_processor->set_vi_register(VIRegister::Width, vi.width);
|
||||||
@@ -199,8 +247,8 @@ void ParallelRDP::UpdateScreen(n64::VI &vi) {
|
|||||||
command_processor->begin_frame_context();
|
command_processor->begin_frame_context();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::EnqueueCommand(int command_length, u32 *buffer) {
|
void ParallelRDP::EnqueueCommand(int command_length, const u32 *buffer) const {
|
||||||
command_processor->enqueue_command(command_length, buffer);
|
command_processor->enqueue_command(command_length, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::OnFullSync() { command_processor->wait_for_timeline(command_processor->signal_timeline()); }
|
void ParallelRDP::OnFullSync() const { command_processor->wait_for_timeline(command_processor->signal_timeline()); }
|
||||||
|
|||||||
18
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
18
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
@@ -17,20 +17,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Init(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
void Init(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
||||||
const std::shared_ptr<WindowInfo> &, const u8 *);
|
const std::shared_ptr<WindowInfo> &, const u8 *, void *);
|
||||||
ParallelRDP() = default;
|
ParallelRDP() = default;
|
||||||
|
|
||||||
void UpdateScreen(n64::VI &);
|
void UpdateScreen(const n64::VI &) const;
|
||||||
void EnqueueCommand(int, u32 *);
|
void EnqueueCommand(int, const u32 *) const;
|
||||||
void OnFullSync();
|
void OnFullSync() const;
|
||||||
bool IsFramerateUnlocked();
|
bool IsFramerateUnlocked() const;
|
||||||
void SetFramerateUnlocked(bool);
|
void SetFramerateUnlocked(bool) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
void LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
||||||
const std::shared_ptr<WindowInfo> &);
|
const std::shared_ptr<WindowInfo> &, void *);
|
||||||
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>);
|
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>) const;
|
||||||
void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>);
|
void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>) const;
|
||||||
|
|
||||||
std::shared_ptr<Vulkan::WSI> wsi;
|
std::shared_ptr<Vulkan::WSI> wsi;
|
||||||
std::shared_ptr<RDP::CommandProcessor> command_processor;
|
std::shared_ptr<RDP::CommandProcessor> command_processor;
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ add_subdirectory(../backend backend)
|
|||||||
add_subdirectory(../../external/parallel-rdp parallel-rdp)
|
add_subdirectory(../../external/parallel-rdp parallel-rdp)
|
||||||
add_subdirectory(../../external/unarr unarr)
|
add_subdirectory(../../external/unarr unarr)
|
||||||
add_subdirectory(../../external/SDL SDL)
|
add_subdirectory(../../external/SDL SDL)
|
||||||
|
add_subdirectory(../../external/imgui imgui)
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
@@ -95,7 +96,7 @@ if (${CMAKE_BUILD_TYPE} MATCHES Debug)
|
|||||||
#target_link_options(kaizen-qt PUBLIC -fsanitize=address -fsanitize=undefined)
|
#target_link_options(kaizen-qt PUBLIC -fsanitize=address -fsanitize=undefined)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_link_libraries(kaizen-qt PUBLIC SDL3::SDL3 SDL3::SDL3-static Qt6::Core Qt6::Gui Qt6::Widgets discord-rpc fmt mio nlohmann_json parallel-rdp backend)
|
target_link_libraries(kaizen-qt PUBLIC SDL3::SDL3 SDL3::SDL3-static Qt6::Core Qt6::Gui Qt6::Widgets discord-rpc fmt mio nlohmann_json imgui parallel-rdp backend)
|
||||||
target_compile_definitions(kaizen-qt PUBLIC SDL_MAIN_HANDLED)
|
target_compile_definitions(kaizen-qt PUBLIC SDL_MAIN_HANDLED)
|
||||||
|
|
||||||
file(COPY ../../resources/ DESTINATION ${PROJECT_BINARY_DIR}/resources/)
|
file(COPY ../../resources/ DESTINATION ${PROJECT_BINARY_DIR}/resources/)
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ EmuThread::EmuThread(const std::shared_ptr<QtInstanceFactory> &instance_,
|
|||||||
instance(instance_), wsiPlatform(wsiPlatform_), windowInfo(windowInfo_), core(parallel), settings(settings) {}
|
instance(instance_), wsiPlatform(wsiPlatform_), windowInfo(windowInfo_), core(parallel), settings(settings) {}
|
||||||
|
|
||||||
[[noreturn]] void EmuThread::run() noexcept {
|
[[noreturn]] void EmuThread::run() noexcept {
|
||||||
parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr());
|
parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr(),
|
||||||
|
reinterpret_cast<void *>(wsiPlatform->get_native_window()));
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
||||||
bool controllerConnected = false;
|
bool controllerConnected = false;
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ 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};
|
||||||
|
|
||||||
private:
|
|
||||||
QWindow *window;
|
QWindow *window;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user