Skip to content

Commit 14d4b36

Browse files
martin-ejdestigocornut
authored andcommitted
Backends: Vulkan: Remove duplicated and dead code in Vulkan backend (#6001)
Sampler, descriptor set layout and pipeline layout are created in exact same way directly in ImGui_ImplVulkan_CreateDeviceObjects(). The removed functions are local and only has call chain that starts in ImGui_ImplVulkan_CreateDeviceObjects(), so will always do early return.
1 parent 328695b commit 14d4b36

File tree

1 file changed

+1
-68
lines changed

1 file changed

+1
-68
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -739,72 +739,6 @@ static void ImGui_ImplVulkan_CreateShaderModules(VkDevice device, const VkAlloca
739739
}
740740
}
741741

742-
static void ImGui_ImplVulkan_CreateFontSampler(VkDevice device, const VkAllocationCallbacks* allocator)
743-
{
744-
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
745-
if (bd->FontSampler)
746-
return;
747-
748-
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
749-
VkSamplerCreateInfo info = {};
750-
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
751-
info.magFilter = VK_FILTER_LINEAR;
752-
info.minFilter = VK_FILTER_LINEAR;
753-
info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
754-
info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
755-
info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
756-
info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
757-
info.minLod = -1000;
758-
info.maxLod = 1000;
759-
info.maxAnisotropy = 1.0f;
760-
VkResult err = vkCreateSampler(device, &info, allocator, &bd->FontSampler);
761-
check_vk_result(err);
762-
}
763-
764-
static void ImGui_ImplVulkan_CreateDescriptorSetLayout(VkDevice device, const VkAllocationCallbacks* allocator)
765-
{
766-
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
767-
if (bd->DescriptorSetLayout)
768-
return;
769-
770-
ImGui_ImplVulkan_CreateFontSampler(device, allocator);
771-
VkSampler sampler[1] = { bd->FontSampler };
772-
VkDescriptorSetLayoutBinding binding[1] = {};
773-
binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
774-
binding[0].descriptorCount = 1;
775-
binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
776-
binding[0].pImmutableSamplers = sampler;
777-
VkDescriptorSetLayoutCreateInfo info = {};
778-
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
779-
info.bindingCount = 1;
780-
info.pBindings = binding;
781-
VkResult err = vkCreateDescriptorSetLayout(device, &info, allocator, &bd->DescriptorSetLayout);
782-
check_vk_result(err);
783-
}
784-
785-
static void ImGui_ImplVulkan_CreatePipelineLayout(VkDevice device, const VkAllocationCallbacks* allocator)
786-
{
787-
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
788-
if (bd->PipelineLayout)
789-
return;
790-
791-
// Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix
792-
ImGui_ImplVulkan_CreateDescriptorSetLayout(device, allocator);
793-
VkPushConstantRange push_constants[1] = {};
794-
push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
795-
push_constants[0].offset = sizeof(float) * 0;
796-
push_constants[0].size = sizeof(float) * 4;
797-
VkDescriptorSetLayout set_layout[1] = { bd->DescriptorSetLayout };
798-
VkPipelineLayoutCreateInfo layout_info = {};
799-
layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
800-
layout_info.setLayoutCount = 1;
801-
layout_info.pSetLayouts = set_layout;
802-
layout_info.pushConstantRangeCount = 1;
803-
layout_info.pPushConstantRanges = push_constants;
804-
VkResult err = vkCreatePipelineLayout(device, &layout_info, allocator, &bd->PipelineLayout);
805-
check_vk_result(err);
806-
}
807-
808742
static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationCallbacks* allocator, VkPipelineCache pipelineCache, VkRenderPass renderPass, VkSampleCountFlagBits MSAASamples, VkPipeline* pipeline, uint32_t subpass)
809743
{
810744
ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
@@ -889,8 +823,6 @@ static void ImGui_ImplVulkan_CreatePipeline(VkDevice device, const VkAllocationC
889823
dynamic_state.dynamicStateCount = (uint32_t)IM_ARRAYSIZE(dynamic_states);
890824
dynamic_state.pDynamicStates = dynamic_states;
891825

892-
ImGui_ImplVulkan_CreatePipelineLayout(device, allocator);
893-
894826
VkGraphicsPipelineCreateInfo info = {};
895827
info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
896828
info.flags = bd->PipelineCreateFlags;
@@ -919,6 +851,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
919851

920852
if (!bd->FontSampler)
921853
{
854+
// Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
922855
VkSamplerCreateInfo info = {};
923856
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
924857
info.magFilter = VK_FILTER_LINEAR;

0 commit comments

Comments
 (0)