-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vulkan: Re-create main window pipeline (standalone) with docking #8111
Open
SuperRonan
wants to merge
1
commit into
ocornut:docking
Choose a base branch
from
SuperRonan:feature/docking_vk_re_create_pipeline_2
base: docking
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−24
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -887,10 +887,21 @@ static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAlloca | |
} | ||
} | ||
|
||
static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationCallbacks* allocator, VkPipelineCache pipelineCache, VkRenderPass renderPass, VkSampleCountFlagBits MSAASamples, VkPipeline* pipeline, uint32_t subpass) | ||
struct ImGui_ImplVulkan_PipelineCreateInfo | ||
{ | ||
VkDevice Device = VK_NULL_HANDLE; | ||
const VkAllocationCallbacks* Allocator = nullptr; | ||
VkPipelineCache PipelineCache = VK_NULL_HANDLE; | ||
VkRenderPass RenderPass = VK_NULL_HANDLE; | ||
uint32_t Subpass = 0; | ||
VkSampleCountFlagBits MSAASamples = {}; | ||
const ImGui_ImplVulkan_PipelineRenderingInfo* pRenderingInfo = nullptr; | ||
}; | ||
|
||
static VkPipeline ImGui_ImplVulkan_CreatePipeline(ImGui_ImplVulkan_PipelineCreateInfo const& pci) | ||
{ | ||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); | ||
ImGui_ImplVulkan_CreateShaderModules(device, allocator); | ||
ImGui_ImplVulkan_CreateShaderModules(pci.Device, pci.Allocator); | ||
|
||
VkPipelineShaderStageCreateInfo stage[2] = {}; | ||
stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; | ||
|
@@ -945,7 +956,7 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC | |
|
||
VkPipelineMultisampleStateCreateInfo ms_info = {}; | ||
ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; | ||
ms_info.rasterizationSamples = (MSAASamples != 0) ? MSAASamples : VK_SAMPLE_COUNT_1_BIT; | ||
ms_info.rasterizationSamples = (pci.MSAASamples != 0) ? pci.MSAASamples : VK_SAMPLE_COUNT_1_BIT; | ||
|
||
VkPipelineColorBlendAttachmentState color_attachment[1] = {}; | ||
color_attachment[0].blendEnable = VK_TRUE; | ||
|
@@ -985,21 +996,22 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC | |
info.pColorBlendState = &blend_info; | ||
info.pDynamicState = &dynamic_state; | ||
info.layout = bd->PipelineLayout; | ||
info.renderPass = renderPass; | ||
info.subpass = subpass; | ||
info.renderPass = pci.RenderPass; | ||
info.subpass = pci.Subpass; | ||
|
||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||
if (bd->VulkanInitInfo.UseDynamicRendering) | ||
{ | ||
IM_ASSERT(bd->VulkanInitInfo.PipelineRenderingCreateInfo.sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR && "PipelineRenderingCreateInfo sType must be VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR"); | ||
IM_ASSERT(bd->VulkanInitInfo.PipelineRenderingCreateInfo.pNext == nullptr && "PipelineRenderingCreateInfo pNext must be NULL"); | ||
info.pNext = &bd->VulkanInitInfo.PipelineRenderingCreateInfo; | ||
info.renderPass = VK_NULL_HANDLE; // Just make sure it's actually nullptr. | ||
IM_ASSERT(pci.pRenderingInfo->sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR && "PipelineRenderingCreateInfo::sType must be VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR"); | ||
IM_ASSERT(pci.pRenderingInfo->pNext == nullptr && "PipelineRenderingCreateInfo::pNext must be NULL"); | ||
info.pNext = pci.pRenderingInfo; | ||
} | ||
#endif | ||
|
||
VkResult err = vkCreateGraphicsPipelines(device, pipelineCache, 1, &info, allocator, pipeline); | ||
VkPipeline res; | ||
VkResult err = vkCreateGraphicsPipelines(pci.Device, pci.PipelineCache, 1, &info, pci.Allocator, &res); | ||
check_vk_result(err); | ||
return res; | ||
} | ||
|
||
bool ImGui_ImplVulkan_CreateDeviceObjects() | ||
|
@@ -1058,11 +1070,43 @@ bool ImGui_ImplVulkan_CreateDeviceObjects() | |
check_vk_result(err); | ||
} | ||
|
||
ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, v->PipelineCache, v->RenderPass, v->MSAASamples, &bd->Pipeline, v->Subpass); | ||
|
||
return true; | ||
} | ||
|
||
void ImGui_ImplVulkan_ReCreateMainPipeline(ImGui_ImplVulkan_MainPipelineCreateInfo const& info) | ||
{ | ||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); | ||
ImGui_ImplVulkan_InitInfo* v = &bd->VulkanInitInfo; | ||
if (bd->Pipeline) | ||
{ | ||
vkDestroyPipeline(v->Device, bd->Pipeline, v->Allocator); | ||
bd->Pipeline = VK_NULL_HANDLE; | ||
} | ||
v->RenderPass = info.RenderPass; | ||
v->MSAASamples = info.MSAASamples; | ||
v->Subpass = info.Subpass; | ||
|
||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||
if (info.pDynamicRendering) | ||
{ | ||
v->PipelineRenderingCreateInfo = *info.pDynamicRendering; | ||
} | ||
#else | ||
IM_ASSERT(p_dynamic_rendering == nullptr); | ||
#endif | ||
|
||
ImGui_ImplVulkan_PipelineCreateInfo pci; | ||
pci.Device = v->Device; | ||
pci.Allocator = v->Allocator; | ||
pci.PipelineCache = v->PipelineCache; | ||
pci.RenderPass = v->RenderPass; | ||
pci.Subpass = v->Subpass; | ||
pci.MSAASamples = v->MSAASamples; | ||
pci.pRenderingInfo = info.pDynamicRendering; | ||
|
||
bd->Pipeline = ImGui_ImplVulkan_CreatePipeline(pci); | ||
} | ||
|
||
void ImGui_ImplVulkan_DestroyDeviceObjects() | ||
{ | ||
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData(); | ||
|
@@ -1145,10 +1189,11 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info) | |
IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE); | ||
IM_ASSERT(info->MinImageCount >= 2); | ||
IM_ASSERT(info->ImageCount >= info->MinImageCount); | ||
if (info->UseDynamicRendering == false) | ||
IM_ASSERT(info->RenderPass != VK_NULL_HANDLE); | ||
//if (info->UseDynamicRendering == false) | ||
// IM_ASSERT(info->RenderPass != VK_NULL_HANDLE); | ||
|
||
bd->VulkanInitInfo = *info; | ||
ImGui_ImplVulkan_InitInfo * v = &bd->VulkanInitInfo; | ||
*v = *info; | ||
|
||
ImGui_ImplVulkan_CreateDeviceObjects(); | ||
|
||
|
@@ -1158,6 +1203,35 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info) | |
|
||
ImGui_ImplVulkan_InitMultiViewportSupport(); | ||
|
||
{ | ||
bool create_pipeline = false; | ||
const ImGui_ImplVulkan_PipelineRenderingInfo * p_dynamic_rendering = nullptr; | ||
if (v->RenderPass) | ||
{ | ||
create_pipeline = true; | ||
} | ||
else | ||
{ | ||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||
if (v->UseDynamicRendering && v->PipelineRenderingCreateInfo.sType == VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR) | ||
{ | ||
p_dynamic_rendering = &v->PipelineRenderingCreateInfo; | ||
create_pipeline = true; | ||
} | ||
#endif | ||
} | ||
if (create_pipeline) | ||
{ | ||
ImGui_ImplVulkan_MainPipelineCreateInfo mp_info = {}; | ||
mp_info.RenderPass = v->RenderPass; | ||
mp_info.Subpass = v->Subpass; | ||
mp_info.MSAASamples = info->MSAASamples; | ||
mp_info.pDynamicRendering = p_dynamic_rendering; | ||
|
||
ImGui_ImplVulkan_ReCreateMainPipeline(mp_info); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
@@ -1699,8 +1773,33 @@ static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport) | |
vd->WindowOwned = true; | ||
|
||
// Create pipeline (shared by all secondary viewports) | ||
if (bd->PipelineForViewports == VK_NULL_HANDLE) | ||
ImGui_ImplVulkan_CreatePipeline(v->Device, v->Allocator, VK_NULL_HANDLE, wd->RenderPass, VK_SAMPLE_COUNT_1_BIT, &bd->PipelineForViewports, 0); | ||
if (bd->PipelineForViewports == VK_NULL_HANDLE) | ||
{ | ||
ImGui_ImplVulkan_PipelineCreateInfo pci; | ||
pci.Device = v->Device; | ||
pci.Allocator = v->Allocator; | ||
pci.PipelineCache = VK_NULL_HANDLE; | ||
pci.RenderPass = wd->RenderPass; | ||
pci.Subpass = 0; | ||
pci.MSAASamples = VK_SAMPLE_COUNT_1_BIT; | ||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING | ||
VkPipelineRenderingCreateInfoKHR rendering_info = {}; | ||
if (wd->UseDynamicRendering) | ||
{ | ||
rendering_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; | ||
rendering_info.pNext = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing with render_info. Surely there is some cross impl pattern in the data structure that make it worth creating a factory. |
||
rendering_info.viewMask = 0; | ||
rendering_info.colorAttachmentCount = 1; | ||
rendering_info.pColorAttachmentFormats = &wd->SurfaceFormat.format; | ||
rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED; | ||
rendering_info.stencilAttachmentFormat = VK_FORMAT_UNDEFINED; | ||
pci.RenderPass = VK_NULL_HANDLE; | ||
pci.pRenderingInfo = &rendering_info; | ||
} | ||
#endif | ||
bd->PipelineForViewports = ImGui_ImplVulkan_CreatePipeline(pci); | ||
|
||
} | ||
} | ||
|
||
static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be clean to use a PCI factory so you can one shot this pci struct with something like PCISettings.createBaseVulkanPCI()