From a6fe6f15f66f32f767a97023460d6a657bd81137 Mon Sep 17 00:00:00 2001 From: daiqingshuang Date: Mon, 19 Feb 2024 16:44:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/rhi/vulkan/renderer_vulkan.cpp | 23 ++++++++++------------- core/rhi/vulkan/renderer_vulkan.h | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/core/rhi/vulkan/renderer_vulkan.cpp b/core/rhi/vulkan/renderer_vulkan.cpp index 7f2fa83..1e3cee6 100644 --- a/core/rhi/vulkan/renderer_vulkan.cpp +++ b/core/rhi/vulkan/renderer_vulkan.cpp @@ -3,8 +3,6 @@ #include "imgui_impl_glfw.h" #include "utils/utils.hpp" -extern GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); - static void check_vk_result(vk::Result err) { if (err == vk::Result::eSuccess) return; @@ -123,13 +121,13 @@ void renderer_vulkan::setup_vulkan(ImVector instance_extensions) { // All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo. // Your real engine/app may not use them. -void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, - int height) const { - wd->Surface = surface; +void renderer_vulkan::setup_vulkan_window(VkSurfaceKHR surface, int width, + int height) { + main_window_data.Surface = surface; // Check for WSI support vk::Bool32 res; - const auto err = physical_device.getSurfaceSupportKHR(queue_family, wd->Surface, &res); + const auto err = physical_device.getSurfaceSupportKHR(queue_family, main_window_data.Surface, &res); check_vk_result(err); if (res != VK_TRUE) { fprintf(stderr, "Error no WSI support on physical device 0\n"); @@ -141,7 +139,7 @@ void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfac VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM }; constexpr VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR; - wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(physical_device, wd->Surface, requestSurfaceImageFormat, + main_window_data.SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(physical_device, main_window_data.Surface, requestSurfaceImageFormat, (size_t) IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace); @@ -151,14 +149,14 @@ void renderer_vulkan::setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfac #else VkPresentModeKHR present_modes[] = {VK_PRESENT_MODE_FIFO_KHR}; #endif - wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(physical_device, wd->Surface, &present_modes[0], + main_window_data.PresentMode = ImGui_ImplVulkanH_SelectPresentMode(physical_device, main_window_data.Surface, &present_modes[0], IM_ARRAYSIZE(present_modes)); //printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode); // Create SwapChain, RenderPass, Framebuffer, etc. IM_ASSERT(min_image_count >= 2); - ImGui_ImplVulkanH_CreateOrResizeWindow(instance, physical_device, device, wd, queue_family, + ImGui_ImplVulkanH_CreateOrResizeWindow(instance, physical_device, device, &main_window_data, queue_family, reinterpret_cast(allocator), width, height, min_image_count); } @@ -369,8 +367,7 @@ void renderer_vulkan::init_vulkan(GLFWwindow* window_handle) { // Create Framebuffers int w, h; glfwGetFramebufferSize(window_handle, &w, &h); - ImGui_ImplVulkanH_Window* wd = &main_window_data; - setup_vulkan_window(wd, surface, w, h); + setup_vulkan_window(surface, w, h); ImGui_ImplGlfw_InitForVulkan(window_handle, true); @@ -382,10 +379,10 @@ void renderer_vulkan::init_vulkan(GLFWwindow* window_handle) { init_info.Queue = queue; init_info.PipelineCache = pipeline_cache; init_info.DescriptorPool = descriptor_pool; - init_info.RenderPass = wd->RenderPass; + init_info.RenderPass = main_window_data.RenderPass; init_info.Subpass = 0; init_info.MinImageCount = min_image_count; - init_info.ImageCount = wd->ImageCount; + init_info.ImageCount = main_window_data.ImageCount; init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT; init_info.Allocator = reinterpret_cast(allocator); init_info.CheckVkResultFn = check_vk_result; diff --git a/core/rhi/vulkan/renderer_vulkan.h b/core/rhi/vulkan/renderer_vulkan.h index 9a510dd..a8aa6c0 100644 --- a/core/rhi/vulkan/renderer_vulkan.h +++ b/core/rhi/vulkan/renderer_vulkan.h @@ -46,11 +46,11 @@ public: bool swap_chain_rebuild = false; protected: - vk::PhysicalDevice setup_vulkan_select_physical_device() const; + [[nodiscard]] vk::PhysicalDevice setup_vulkan_select_physical_device() const; void setup_vulkan(ImVector instance_extensions); - void setup_vulkan_window(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height) const; + void setup_vulkan_window(VkSurfaceKHR surface, int width, int height); void cleanup_vulkan() const;