Skip to content

Commit e31a4f6

Browse files
authored
cmake: fix paths for vulkan shaders compilation on Windows (#8573)
* Vulkan-shaders: attempt fix compilation on windows * fix miss-matched parenthesis
1 parent 400ae6f commit e31a4f6

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ bool string_ends_with(const std::string& str, const std::string& suffix) {
179179
return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin());
180180
}
181181

182-
#ifdef _WIN32
183-
static const char path_separator = '\\';
184-
#else
185-
static const char path_separator = '/';
186-
#endif
182+
static const char path_separator = '/';
187183

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

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

483483
for (const auto& pair : shader_fnames) {
484484
const std::string& name = pair.first;
485-
const std::string& path = pair.second;
485+
#ifdef _WIN32
486+
std::string path = pair.second;
487+
std::replace(path.begin(), path.end(), '/', '\\' );
488+
#else
489+
const std::string& path = pair.second;
490+
#endif
491+
486492
FILE* spv = fopen(path.c_str(), "rb");
487493
if (!spv) {
488-
std::cerr << "Error opening SPIR-V file: " << path << "\n";
494+
std::cerr << "Error opening SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
489495
continue;
490496
}
491497

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

0 commit comments

Comments
 (0)