From 020993fb19b326adb692ff2aa2635936078f82a7 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 20 Mar 2024 19:25:22 +0900 Subject: [PATCH] Refactor: Move shader loading code to inner scope This prevents the loaded shader data from persisting on the stack even when it is no longer needed. --- src/blue_noise.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/blue_noise.cpp b/src/blue_noise.cpp index ffdec72..42a8143 100644 --- a/src/blue_noise.cpp +++ b/src/blue_noise.cpp @@ -436,29 +436,29 @@ image::Bl dither::blue_noise(int width, int height, int threads, } } - // Load shader. - std::vector shader; - { - std::ifstream ifs("compute.spv"); - if (!ifs.good()) { - std::clog << "WARNING: Failed to find compute.spv!\n"; - goto ENDOF_VULKAN; - } - ifs.seekg(0, std::ios_base::end); - auto size = ifs.tellg(); - shader.resize(size); - - ifs.seekg(0); - ifs.read(shader.data(), size); - ifs.close(); - } - // create compute pipeline. VkPipelineLayout compute_pipeline_layout; VkPipeline compute_pipeline; utility::Cleanup cleanup_pipeline_layout{}; utility::Cleanup cleanup_pipeline{}; { + // Load shader. + std::vector shader; + { + std::ifstream ifs("compute.spv"); + if (!ifs.good()) { + std::clog << "WARNING: Failed to find compute.spv!\n"; + goto ENDOF_VULKAN; + } + ifs.seekg(0, std::ios_base::end); + auto size = ifs.tellg(); + shader.resize(size); + + ifs.seekg(0); + ifs.read(shader.data(), size); + ifs.close(); + } + VkShaderModuleCreateInfo shader_module_create_info{}; shader_module_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;