From: Stephen Seo Date: Tue, 19 Mar 2024 07:13:10 +0000 (+0900) Subject: Compile glsl with glslc, fixes X-Git-Url: https://git.seodisparate.com/stephenseo/css/base.css?a=commitdiff_plain;h=6cefcc5f94913e522b7d0669bb3e585769f9c43b;p=blue_noise_generation Compile glsl with glslc, fixes Fix incorrectly set "bindings" for descriptors. Fix blue_gen.glsl . Program now attempts to compile blue_gen.glsl using "glslc". --- diff --git a/src/blue_noise.cpp b/src/blue_noise.cpp index a570d8f..fec8bcd 100644 --- a/src/blue_noise.cpp +++ b/src/blue_noise.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -278,21 +279,21 @@ image::Bl dither::blue_noise(int width, int height, int threads, compute_layout_bindings[0].pImmutableSamplers = nullptr; compute_layout_bindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; - compute_layout_bindings[1].binding = 0; + compute_layout_bindings[1].binding = 1; compute_layout_bindings[1].descriptorCount = 1; compute_layout_bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; compute_layout_bindings[1].pImmutableSamplers = nullptr; compute_layout_bindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; - compute_layout_bindings[2].binding = 0; + compute_layout_bindings[2].binding = 2; compute_layout_bindings[2].descriptorCount = 1; compute_layout_bindings[2].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; compute_layout_bindings[2].pImmutableSamplers = nullptr; compute_layout_bindings[2].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; - compute_layout_bindings[3].binding = 0; + compute_layout_bindings[3].binding = 3; compute_layout_bindings[3].descriptorCount = 1; compute_layout_bindings[3].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; @@ -316,6 +317,30 @@ image::Bl dither::blue_noise(int width, int height, int threads, nullptr); }, &compute_desc_set_layout); + + // Check and compile compute shader. + { + std::ifstream ifs("src/blue_noise.glsl"); + if (ifs.good()) { + 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 { + ifs = std::ifstream("../src/blue_noise.glsl"); + if (ifs.good()) { + 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; + } + } + } } ENDOF_VULKAN: std::clog << "TODO: Remove this once Vulkan support is implemented.\n"; diff --git a/src/blue_noise.glsl b/src/blue_noise.glsl index 2b5212e..e060014 100644 --- a/src/blue_noise.glsl +++ b/src/blue_noise.glsl @@ -34,8 +34,8 @@ void main() { return; } - int x = index % width; - int y = index / width; + int x = int(index % width); + int y = int(index / width); float sum = 0.0F; for (int q = 0; q < filter_size; ++q) {