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".
This commit is contained in:
Stephen Seo 2024-03-19 16:13:10 +09:00
parent b73c6fb94b
commit 6cefcc5f94
2 changed files with 30 additions and 5 deletions

View file

@ -2,6 +2,7 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstdlib>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <iostream> #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].pImmutableSamplers = nullptr;
compute_layout_bindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; 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].descriptorCount = 1;
compute_layout_bindings[1].descriptorType = compute_layout_bindings[1].descriptorType =
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
compute_layout_bindings[1].pImmutableSamplers = nullptr; compute_layout_bindings[1].pImmutableSamplers = nullptr;
compute_layout_bindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; 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].descriptorCount = 1;
compute_layout_bindings[2].descriptorType = compute_layout_bindings[2].descriptorType =
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
compute_layout_bindings[2].pImmutableSamplers = nullptr; compute_layout_bindings[2].pImmutableSamplers = nullptr;
compute_layout_bindings[2].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; 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].descriptorCount = 1;
compute_layout_bindings[3].descriptorType = compute_layout_bindings[3].descriptorType =
VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
@ -316,6 +317,30 @@ image::Bl dither::blue_noise(int width, int height, int threads,
nullptr); nullptr);
}, },
&compute_desc_set_layout); &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: ENDOF_VULKAN:
std::clog << "TODO: Remove this once Vulkan support is implemented.\n"; std::clog << "TODO: Remove this once Vulkan support is implemented.\n";

View file

@ -34,8 +34,8 @@ void main() {
return; return;
} }
int x = index % width; int x = int(index % width);
int y = index / width; int y = int(index / width);
float sum = 0.0F; float sum = 0.0F;
for (int q = 0; q < filter_size; ++q) { for (int q = 0; q < filter_size; ++q) {