]> git.seodisparate.com - blue_noise_generation/commitdiff
Compile glsl with glslc, fixes
authorStephen Seo <seo.disparate@gmail.com>
Tue, 19 Mar 2024 07:13:10 +0000 (16:13 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 19 Mar 2024 07:13:10 +0000 (16:13 +0900)
Fix incorrectly set "bindings" for descriptors.

Fix blue_gen.glsl .

Program now attempts to compile blue_gen.glsl using "glslc".

src/blue_noise.cpp
src/blue_noise.glsl

index a570d8f41cefe20169911d0161d90bf03fd621df..fec8bcd6c697c54424498dca49ccaab926d91bf2 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <cassert>
 #include <cstdio>
+#include <cstdlib>
 #include <cstring>
 #include <fstream>
 #include <iostream>
@@ -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";
index 2b5212e9946ef0b10eff3298107e753f605aa30e..e060014450a07dcef271b0992ac1ca72d76a1f99 100644 (file)
@@ -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) {