30
30
31
31
#define ASYNCIO_CONCURRENCY 64
32
32
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
+
33
47
std::mutex lock;
34
48
std::vector<std::pair<std::string, std::string>> shader_fnames;
35
49
@@ -38,7 +52,7 @@ std::string input_dir = "vulkan-shaders";
38
52
std::string output_dir = " /tmp" ;
39
53
std::string target_hpp = " ggml-vulkan-shaders.hpp" ;
40
54
std::string target_cpp = " ggml-vulkan-shaders.cpp" ;
41
- bool no_clean = false ;
55
+ bool clean = true ;
42
56
43
57
const std::vector<std::string> type_names = {
44
58
" f32" ,
@@ -464,8 +478,9 @@ void write_output_files() {
464
478
}
465
479
fprintf (src, " \n };\n\n " );
466
480
467
- if (!no_clean ) {
481
+ if (clean ) {
468
482
std::remove (path.c_str ());
483
+ // fprintf(stderr, "Removed: %s\n", path.c_str());
469
484
}
470
485
}
471
486
@@ -481,6 +496,18 @@ int main(int argc, char** argv) {
481
496
}
482
497
}
483
498
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
+ }
484
511
if (args.find (" --glslc" ) != args.end ()) {
485
512
GLSLC = args[" --glslc" ]; // Path to glslc
486
513
}
@@ -497,7 +524,7 @@ int main(int argc, char** argv) {
497
524
target_cpp = args[" --target-cpp" ]; // Path to generated cpp file
498
525
}
499
526
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
501
528
}
502
529
503
530
if (!directory_exists (input_dir)) {
0 commit comments