3030
3131#define ASYNCIO_CONCURRENCY 64
3232
33+ // define prototypes
34+ void execute_command (const std::string& command, std::string& stdout_str, std::string& stderr_str);
35+ bool directory_exists (const std::string& path);
36+ bool create_directory (const std::string& path);
37+ std::string to_uppercase (const std::string& input);
38+ bool string_ends_with (const std::string& str, const std::string& suffix);
39+ std::string join_paths (const std::string& path1, const std::string& path2);
40+ std::string basename (const std::string &path);
41+ void string_to_spv (const std::string& _name, const std::string& in_fname, const std::map<std::string, std::string>& defines, bool fp16);
42+ std::map<std::string, std::string> merge_maps (const std::map<std::string, std::string>& a, const std::map<std::string, std::string>& b);
43+ void matmul_shaders (std::vector<std::future<void >>& tasks, bool fp16, bool matmul_id);
44+ void process_shaders (std::vector<std::future<void >>& tasks);
45+ void write_output_files ();
46+
3347std::mutex lock;
3448std::vector<std::pair<std::string, std::string>> shader_fnames;
3549
@@ -38,7 +52,7 @@ std::string input_dir = "vulkan-shaders";
3852std::string output_dir = " /tmp" ;
3953std::string target_hpp = " ggml-vulkan-shaders.hpp" ;
4054std::string target_cpp = " ggml-vulkan-shaders.cpp" ;
41- bool no_clean = false ;
55+ bool clean = true ;
4256
4357const std::vector<std::string> type_names = {
4458 " f32" ,
@@ -464,8 +478,9 @@ void write_output_files() {
464478 }
465479 fprintf (src, " \n };\n\n " );
466480
467- if (!no_clean ) {
481+ if (clean ) {
468482 std::remove (path.c_str ());
483+ // fprintf(stderr, "Removed: %s\n", path.c_str());
469484 }
470485 }
471486
@@ -481,6 +496,18 @@ int main(int argc, char** argv) {
481496 }
482497 }
483498
499+ if (argc <= 1 || args.find (" --help" ) != args.end ()) {
500+ std::cout << " Usage:\n "
501+ " \t vulkan-shaders-gen [options]\n\n "
502+ " Options:\n "
503+ " \t --glslc <path> Path to glslc executable (default: /usr/bin/glslc)\n "
504+ " \t --input-dir Directory containing shader sources (required)\n "
505+ " \t --output-dir Output directory for generated SPIR-V files and optional C++ headers\n "
506+ " \t --target-hpp <path> Path to generate a header file with shader declarations in C++ format\n "
507+ " \t --target-cpp <path> Path to generate a source code file implementing the declared shaders (optional)\n "
508+ " \t --no-clean Keep temporary SPIR-V files after build (default: remove them)\n " ;
509+ return EXIT_SUCCESS;
510+ }
484511 if (args.find (" --glslc" ) != args.end ()) {
485512 GLSLC = args[" --glslc" ]; // Path to glslc
486513 }
@@ -497,7 +524,7 @@ int main(int argc, char** argv) {
497524 target_cpp = args[" --target-cpp" ]; // Path to generated cpp file
498525 }
499526 if (args.find (" --no-clean" ) != args.end ()) {
500- no_clean = true ; // Keep temporary SPIR-V files in output-dir after build
527+ clean = false ; // Keep temporary SPIR-V files in output-dir after build
501528 }
502529
503530 if (!directory_exists (input_dir)) {
0 commit comments