Nah, let's roll our own
This commit is contained in:
1
external/imgui/CMakeLists.txt
vendored
1
external/imgui/CMakeLists.txt
vendored
@@ -8,3 +8,4 @@ list(APPEND SOURCES backends/imgui_impl_sdl3.cpp backends/imgui_impl_vulkan.cpp)
|
||||
add_library(imgui ${SOURCES} ${HEADERS})
|
||||
target_include_directories(imgui PRIVATE . backends ../SDL/include)
|
||||
target_compile_definitions(imgui PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK)
|
||||
target_compile_definitions(imgui PRIVATE IMGUI_IMPL_VULKAN_NO_PROTOTYPES)
|
||||
@@ -1,13 +1,13 @@
|
||||
#include <EmuThread.hpp>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
EmuThread::EmuThread(RenderWidget& renderWidget, SettingsWindow &settings) noexcept :
|
||||
EmuThread::EmuThread(RenderWidget &renderWidget, SettingsWindow &settings) noexcept :
|
||||
renderWidget(renderWidget), core(parallel), settings(settings) {}
|
||||
|
||||
[[noreturn]] void EmuThread::run() noexcept {
|
||||
parallel.Init(renderWidget.instance, renderWidget.wsiPlatform, renderWidget.windowInfo,
|
||||
parallel.Init(renderWidget.qtVkInstanceFactory, renderWidget.wsiPlatform, renderWidget.windowInfo,
|
||||
core.cpu->GetMem().GetRDRAMPtr());
|
||||
renderWidget.InitImgui(parallel.wsi);
|
||||
|
||||
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
||||
bool controllerConnected = false;
|
||||
|
||||
@@ -15,7 +15,7 @@ EmuThread::EmuThread(RenderWidget& renderWidget, SettingsWindow &settings) noexc
|
||||
Util::warn("[SDL] Could not load game controller DB");
|
||||
}
|
||||
|
||||
auto pollEvents = [&]() {
|
||||
auto pollEvents = [&] {
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
switch (e.type) {
|
||||
|
||||
@@ -1,82 +1,5 @@
|
||||
#include <KaizenQt.hpp>
|
||||
#include <RenderWidget.hpp>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_vulkan.h>
|
||||
|
||||
static void check_vk_result(VkResult err) {
|
||||
if (err == 0)
|
||||
return;
|
||||
fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err);
|
||||
if (err < 0)
|
||||
abort();
|
||||
}
|
||||
|
||||
void RenderWidget::InitImgui(std::shared_ptr<Vulkan::WSI>& wsi) {
|
||||
this->wsi = wsi;
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
style.WindowRounding = 0.0f;
|
||||
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
||||
|
||||
ImGui_ImplSDL3_InitForVulkan(sdlWindow);
|
||||
|
||||
auto myVkInstance = instance->qVkInstance.vkInstance();
|
||||
|
||||
volkInitialize();
|
||||
volkLoadInstance(myVkInstance);
|
||||
|
||||
ImGui_ImplVulkan_LoadFunctions(
|
||||
[](const char *function_name, void *instance) {
|
||||
return vkGetInstanceProcAddr(static_cast<VkInstance>(instance), function_name);
|
||||
},
|
||||
myVkInstance);
|
||||
|
||||
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||
init_info.Instance = myVkInstance;
|
||||
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[Vulkan::QUEUE_INDEX_GRAPHICS];
|
||||
init_info.Queue = wsi->get_context().get_queue_info().queues[Vulkan::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(Vulkan::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);
|
||||
|
||||
connect(&timer, &QTimer::timeout, this, &RenderWidget::UpdateEvents);
|
||||
timer.setInterval(16);
|
||||
timer.start();
|
||||
}
|
||||
|
||||
RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
|
||||
setAttribute(Qt::WA_NativeWindow);
|
||||
@@ -95,43 +18,10 @@ RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
|
||||
Util::panic("Could not initialize Vulkan ICD");
|
||||
}
|
||||
|
||||
instance = std::make_shared<QtInstanceFactory>();
|
||||
windowHandle()->setVulkanInstance(&instance->qVkInstance);
|
||||
qtVkInstanceFactory = std::make_shared<QtInstanceFactory>();
|
||||
windowHandle()->setVulkanInstance(&qtVkInstanceFactory->handle);
|
||||
windowHandle()->create();
|
||||
|
||||
wsiPlatform = std::make_shared<QtWSIPlatform>(windowHandle());
|
||||
windowInfo = std::make_shared<QtParallelRdpWindowInfo>(windowHandle());
|
||||
|
||||
auto winPtr = reinterpret_cast<void *>(winId());
|
||||
auto props = SDL_CreateProperties();
|
||||
#ifdef SDL_PLATFORM_LINUX
|
||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER, winPtr);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, static_cast<s64> winPtr);
|
||||
#elif SDL_PLATFORM_WINDOWS
|
||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, winPtr);
|
||||
#else
|
||||
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER, winPtr);
|
||||
#endif
|
||||
sdlWindow = SDL_CreateWindowWithProperties(props);
|
||||
}
|
||||
|
||||
void RenderWidget::UpdateEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
}
|
||||
|
||||
Util::IntrusivePtr<Vulkan::CommandBuffer> cmd = wsi->get_device().request_command_buffer();
|
||||
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->get_command_buffer());
|
||||
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
}
|
||||
|
||||
@@ -6,12 +6,11 @@
|
||||
#include <QWidget>
|
||||
#include <QWindow>
|
||||
#include <QTimer>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <imgui_impl_vulkan.h>
|
||||
|
||||
struct QtInstanceFactory : Vulkan::InstanceFactory {
|
||||
VkInstance create_instance(const VkInstanceCreateInfo *info) override {
|
||||
qVkInstance.setApiVersion({1, 3, 0});
|
||||
handle.setApiVersion({1, 3, 0});
|
||||
QByteArrayList exts;
|
||||
for (int i = 0; i < info->enabledExtensionCount; i++) {
|
||||
exts.push_back(QByteArray::fromStdString(info->ppEnabledExtensionNames[i]));
|
||||
@@ -20,15 +19,15 @@ struct QtInstanceFactory : Vulkan::InstanceFactory {
|
||||
for (int i = 0; i < info->enabledLayerCount; i++) {
|
||||
layers.push_back(QByteArray::fromStdString(info->ppEnabledLayerNames[i]));
|
||||
}
|
||||
qVkInstance.setExtensions(exts);
|
||||
qVkInstance.setLayers(layers);
|
||||
qVkInstance.setApiVersion({1, 3, 0});
|
||||
qVkInstance.create();
|
||||
handle.setExtensions(exts);
|
||||
handle.setLayers(layers);
|
||||
handle.setApiVersion({1, 3, 0});
|
||||
handle.create();
|
||||
|
||||
return qVkInstance.vkInstance();
|
||||
return handle.vkInstance();
|
||||
}
|
||||
|
||||
QVulkanInstance qVkInstance;
|
||||
QVulkanInstance handle;
|
||||
};
|
||||
|
||||
class QtParallelRdpWindowInfo : public ParallelRDP::WindowInfo {
|
||||
@@ -81,20 +80,15 @@ public:
|
||||
};
|
||||
|
||||
class RenderWidget : public QWidget {
|
||||
SDL_Window *sdlWindow;
|
||||
QTimer timer;
|
||||
void UpdateEvents();
|
||||
std::shared_ptr<Vulkan::WSI> wsi;
|
||||
|
||||
public:
|
||||
[[nodiscard]] VkInstance instance() const { return qtVkInstanceFactory->handle.vkInstance(); }
|
||||
explicit RenderWidget(QWidget *parent);
|
||||
void InitImgui(std::shared_ptr<Vulkan::WSI> &wsi);
|
||||
|
||||
[[nodiscard]] QPaintEngine *paintEngine() const override { return nullptr; }
|
||||
|
||||
std::shared_ptr<ParallelRDP::WindowInfo> windowInfo;
|
||||
std::shared_ptr<Vulkan::WSIPlatform> wsiPlatform;
|
||||
std::shared_ptr<QtInstanceFactory> instance;
|
||||
std::shared_ptr<QtInstanceFactory> qtVkInstanceFactory;
|
||||
Q_SIGNALS:
|
||||
void Show() { show(); }
|
||||
void Hide() { hide(); }
|
||||
|
||||
Reference in New Issue
Block a user