17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-28 23:57:28 +01:00

Validate shaders against GLSL 4.60 including compute stage

This commit is contained in:
2026-10-15 02:20:22 +02:00
parent 9e64244ebd
commit 9186819363
6 changed files with 62 additions and 12 deletions

View File

@@ -1,17 +1,20 @@
#include "stdafx.h"
#include "../gl/shader.h"
#include "../gl/glsl_common.h"
#include "Globals.h"
#include "utilities/Globals.h"
#include "utilities/Logs.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <filesystem>
#include <vector>
_global Global;
bool check_shader(std::string filename)
{
gl::shader shader_processor;
shader_processor.name = filename;
gl::glsl_common_setup();
std::pair<GLuint, std::string> source = shader_processor.process_source(filename, "../shaders/");
@@ -23,9 +26,17 @@ bool check_shader(std::string filename)
stage = "frag";
else if (source.first == GL_GEOMETRY_SHADER)
stage = "geom";
else if (source.first == GL_COMPUTE_SHADER)
stage = "comp";
else
return false;
if (ErrorLogged)
{
ErrorLogged = false;
return false;
}
std::ofstream file("/tmp/shader");
file << source.second;
file.close();
@@ -80,24 +91,38 @@ bool check_shader_confs(std::string filename)
int main()
{
if (system("glslangValidator --version > /dev/null 2>&1") != 0)
{
std::cerr << "glslangValidator not found in PATH" << std::endl;
return 1;
}
bool suc = true;
std::vector<std::string> failed;
for (auto &f : std::filesystem::recursive_directory_iterator("../shaders/")) {
if (!f.is_regular_file())
continue;
std::string relative = std::filesystem::relative(f.path(), "../shaders/").string();
if (f.path().extension() != ".frag" && f.path().extension() != ".geom" && f.path().extension() != ".vert")
auto const ext = f.path().extension();
if (ext != ".frag" && ext != ".geom" && ext != ".vert" && ext != ".comp")
continue;
std::cout << "== validating shader " << relative << ": " << std::flush;
if (!check_shader_confs(relative))
{
suc = false;
failed.push_back(relative);
}
}
if (suc)
std::cout << "==== all checks ok" << std::endl;
else {
std::cout << "==== checks failed" << std::endl;
std::cout << "==== checks failed:";
for (auto const &name : failed)
std::cout << " " << name;
std::cout << std::endl;
return 1;
}