Refactor glslc usage

This commit is contained in:
Stephen Seo 2024-03-20 11:11:22 +09:00
parent bd5cfaebd3
commit 8c1190d923

View file

@ -320,26 +320,28 @@ image::Bl dither::blue_noise(int width, int height, int threads,
// Check and compile compute shader. // Check and compile compute shader.
{ {
std::ifstream ifs("src/blue_noise.glsl"); std::array<const char *, 3> filenames{
"blue_noise.glsl", "src/blue_noise.glsl", "../src/blue_noise.glsl"};
bool success = false;
for (const auto filename : filenames) {
std::ifstream ifs(filename);
if (ifs.good()) { if (ifs.good()) {
ifs.close(); ifs.close();
if (std::system("glslc -fshader-stage=compute -o compute.spv src/blue_noise.glsl") != 0) { std::string command("glslc -fshader-stage=compute -o compute.spv ");
std::clog << "WARNING: Failed to compile src/blue_noise.glsl!\n"; command.append(filename);
if (std::system(command.c_str()) != 0) {
std::clog << "WARNING: Failed to compile " << filename << "!\n";
goto ENDOF_VULKAN; goto ENDOF_VULKAN;
}
} else { } else {
ifs = std::ifstream("../src/blue_noise.glsl"); success = true;
if (ifs.good()) { break;
ifs.close();
if (std::system("glslc -fshader-stage=compute -o compute.spv ../src/blue_noise.glsl") != 0) {
std::clog << "WARNING: Failed to compile ../src/blue_noise.glsl!\n";
goto ENDOF_VULKAN;
} }
} else {
std::clog << "WARNING: Unable to find blue_noise.glsl!\n";
goto ENDOF_VULKAN;
} }
} }
if (!success) {
std::clog << "WARNING: Could not find blue_noise.glsl!\n";
goto ENDOF_VULKAN;
}
} }
} }
ENDOF_VULKAN: ENDOF_VULKAN: