Skip to content

Commit

Permalink
add missing parameter ImGui_ImplVulkan_RenderDrawData
Browse files Browse the repository at this point in the history
  • Loading branch information
scribam committed Sep 7, 2024
1 parent a5ee01c commit a50865b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion vita3k/gui/include/gui/imgui_impl_sdl_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateDeviceObjects(ImGui_VulkanState &stat
IMGUI_IMPL_API ImGui_VulkanState *ImGui_ImplVulkan_Init(renderer::State *renderer, ImGui_ImplVulkan_InitInfo* info);
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(ImGui_VulkanState &state);
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(ImGui_VulkanState &state);
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, ImGui_VulkanState &state);
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImGui_VulkanState &state, ImDrawData* draw_data, vk::CommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture();
IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
Expand Down
15 changes: 14 additions & 1 deletion vita3k/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,20 @@ void draw_end(GuiState &gui) {
return ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

case renderer::Backend::Vulkan:
return ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), dynamic_cast<ImGui_VulkanState &>(*gui.imgui_state));
auto &state = dynamic_cast<ImGui_VulkanState &>(*gui.imgui_state);
auto &vk_state = dynamic_cast<renderer::vulkan::VKState &>(*state.renderer);

if (vk_state.screen_renderer.swapchain_image_idx == ~0) {
// this happen in the game selection screen
if (!vk_state.screen_renderer.acquire_swapchain_image(true))
return;
} else if (!vk_state.screen_renderer.current_cmd_buffer) {
// Can happen while resizing the window
return;
}

state.CommandBuffer = vk_state.screen_renderer.current_cmd_buffer;
return ImGui_ImplVulkan_RenderDrawData(dynamic_cast<ImGui_VulkanState &>(*gui.imgui_state), ImGui::GetDrawData(), state.CommandBuffer);
}
}

Expand Down
30 changes: 9 additions & 21 deletions vita3k/gui/src/imgui_impl_sdl_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static void CreateOrResizeBuffer(ImGui_VulkanState &state, vk::Buffer& buffer, v
buffer_size = vertex_buffer_size_aligned;
}

static void ImGui_ImplVulkan_SetupRenderState(ImGui_VulkanState &state, ImDrawData* draw_data, vk::Pipeline pipeline, vk::CommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers * rb, int fb_width, int fb_height)
static void ImGui_ImplVulkan_SetupRenderState(ImGui_VulkanState &state, ImDrawData* draw_data, VkPipeline pipeline, vk::CommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers * rb, int fb_width, int fb_height)
{
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();

Expand Down Expand Up @@ -476,22 +476,9 @@ static void ImGui_ImplVulkan_DeletePipeline(ImGui_VulkanState &state)
static void ImGui_ImplVulkan_CreatePipeline(ImGui_VulkanState &state);

// Render function
void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, ImGui_VulkanState &state)
void ImGui_ImplVulkan_RenderDrawData(ImGui_VulkanState &state, ImDrawData* draw_data, vk::CommandBuffer command_buffer, VkPipeline pipeline)
{
auto &vk_state = dynamic_cast<renderer::vulkan::VKState &>(*state.renderer);

if (vk_state.screen_renderer.swapchain_image_idx == ~0) {
// this happen in the game selection screen
if (!vk_state.screen_renderer.acquire_swapchain_image(true))
return;
} else if (!vk_state.screen_renderer.current_cmd_buffer) {
// Can happen while resizing the window
return;
}

state.CommandBuffer = vk_state.screen_renderer.current_cmd_buffer;
// uint32_t image_index = vk_state.screen_renderer.swapchain_image_idx;

if (vk_state.screen_renderer.need_rebuild) {
ImGui_ImplVulkan_DeletePipeline(state);
ImGui_ImplVulkan_CreatePipeline(state);
Expand All @@ -506,6 +493,8 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, ImGui_VulkanState &s

ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo;
if (pipeline == VK_NULL_HANDLE)
pipeline = static_cast<VkPipeline>(state.Pipeline);

// Allocate array to store enough vertex/index buffers
ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &state.MainWindowRenderBuffers;
Expand Down Expand Up @@ -551,7 +540,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, ImGui_VulkanState &s
}

// Setup desired Vulkan state
ImGui_ImplVulkan_SetupRenderState(state, draw_data, state.Pipeline, state.CommandBuffer, rb, fb_width, fb_height);
ImGui_ImplVulkan_SetupRenderState(state, draw_data, pipeline, command_buffer, rb, fb_width, fb_height);

// Will project scissor/clipping rectangles into framebuffer space
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
Expand All @@ -572,7 +561,7 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, ImGui_VulkanState &s
// User callback, registered via ImDrawList::AddCallback()
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplVulkan_SetupRenderState(state, draw_data, state.Pipeline, state.CommandBuffer, rb, fb_width, fb_height);
ImGui_ImplVulkan_SetupRenderState(state, draw_data, static_cast<VkPipeline>(state.Pipeline), state.CommandBuffer, rb, fb_width, fb_height);
else
pcmd->UserCallback(cmd_list, pcmd);
}
Expand Down Expand Up @@ -987,6 +976,7 @@ static void ImGui_ImplVulkan_CreateShaderModules(ImGui_VulkanState &state)

static void ImGui_ImplVulkan_CreatePipeline(ImGui_VulkanState &state)
{
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
auto &vk_state = dynamic_cast<renderer::vulkan::VKState &>(*state.renderer);

std::vector<vk::PipelineShaderStageCreateInfo> shader_stage_infos = {
Expand Down Expand Up @@ -1106,8 +1096,7 @@ static void ImGui_ImplVulkan_CreatePipeline(ImGui_VulkanState &state)
}
#endif

vk::ResultValue<vk::Pipeline> pipelineResultValue = vk_state.device.createGraphicsPipeline(vk::PipelineCache(), gui_pipeline_info, nullptr);
state.Pipeline = pipelineResultValue.value;
state.Pipeline = vk_state.device.createGraphicsPipeline(vk::PipelineCache(), gui_pipeline_info, nullptr).value;
}

bool ImGui_ImplVulkan_CreateDeviceObjects(ImGui_VulkanState &state)
Expand All @@ -1120,6 +1109,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects(ImGui_VulkanState &state)

if (!state.FontSampler)
{
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
vk::SamplerCreateInfo info{
.magFilter = vk::Filter::eLinear,
.minFilter = vk::Filter::eLinear,
Expand Down Expand Up @@ -1163,8 +1153,6 @@ bool ImGui_ImplVulkan_CreateDeviceObjects(ImGui_VulkanState &state)
ImGui_ImplVulkan_CreatePipeline(state);

{
// Hopefully imgui doesn't use more than 2048 different images
// within k frames (where k is the number of images in the swapchain)
vk::DescriptorPoolSize pool_size{
.type = vk::DescriptorType::eCombinedImageSampler,
.descriptorCount = TextureState::nb_descriptor_sets + 1
Expand Down

0 comments on commit a50865b

Please sign in to comment.