Skip to content

Commit

Permalink
cmake: fix paths for vulkan shaders compilation on Windows (#8573)
Browse files Browse the repository at this point in the history
* Vulkan-shaders: attempt fix compilation on windows

* fix miss-matched parenthesis
  • Loading branch information
stduhpf authored Aug 5, 2024
1 parent 400ae6f commit e31a4f6
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ bool string_ends_with(const std::string& str, const std::string& suffix) {
return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin());
}

#ifdef _WIN32
static const char path_separator = '\\';
#else
static const char path_separator = '/';
#endif
static const char path_separator = '/';

std::string join_paths(const std::string& path1, const std::string& path2) {
return path1 + path_separator + path2;
Expand All @@ -198,7 +194,11 @@ void string_to_spv(const std::string& _name, const std::string& in_fname, const
std::string out_fname = join_paths(output_dir, name + ".spv");
std::string in_path = join_paths(input_dir, in_fname);

std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", in_path, "-o", out_fname};
#ifdef _WIN32
std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", "\"" + in_path + "\"", "-o", "\"" + out_fname + "\""};
#else
std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", in_path, "-o", out_fname};
#endif
for (const auto& define : defines) {
cmd.push_back("-D" + define.first + "=" + define.second);
}
Expand Down Expand Up @@ -482,10 +482,16 @@ void write_output_files() {

for (const auto& pair : shader_fnames) {
const std::string& name = pair.first;
const std::string& path = pair.second;
#ifdef _WIN32
std::string path = pair.second;
std::replace(path.begin(), path.end(), '/', '\\' );
#else
const std::string& path = pair.second;
#endif

FILE* spv = fopen(path.c_str(), "rb");
if (!spv) {
std::cerr << "Error opening SPIR-V file: " << path << "\n";
std::cerr << "Error opening SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
continue;
}

Expand All @@ -497,7 +503,7 @@ void write_output_files() {
size_t read_size = fread(data.data(), 1, size, spv);
fclose(spv);
if (read_size != size) {
std::cerr << "Error reading SPIR-V file: " << path << "\n";
std::cerr << "Error reading SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
continue;
}

Expand Down

0 comments on commit e31a4f6

Please sign in to comment.