Skip to content

Commit 4f17468

Browse files
committed
Vulkan-shaders: attempt fix compilation on windows
1 parent 3807c3d commit 4f17468

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

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

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

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

187183
std::string join_paths(const std::string& path1, const std::string& path2) {
188184
return path1 + path_separator + path2;
@@ -197,7 +193,7 @@ void string_to_spv(const std::string& _name, const std::string& in_fname, const
197193
std::string out_fname = join_paths(output_dir, name + ".spv");
198194
std::string in_path = join_paths(input_dir, in_fname);
199195

200-
std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", in_path, "-o", out_fname};
196+
std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", "\"" + in_path + "\"", "-o", "\"" + out_fname + "\""};
201197
for (const auto& define : defines) {
202198
cmd.push_back("-D" + define.first + "=" + define.second);
203199
}
@@ -434,10 +430,16 @@ void write_output_files() {
434430

435431
for (const auto& pair : shader_fnames) {
436432
const std::string& name = pair.first;
437-
const std::string& path = pair.second;
433+
#ifdef _WIN32
434+
std::string path = pair.second;
435+
std::replace(path.begin(), path.end(), '/', '\\' );
436+
#else
437+
const std::string& path = pair.second;
438+
#endif
439+
438440
FILE* spv = fopen(path.c_str(), "rb");
439441
if (!spv) {
440-
std::cerr << "Error opening SPIR-V file: " << path << "\n";
442+
std::cerr << "Error opening SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
441443
continue;
442444
}
443445

@@ -449,7 +451,7 @@ void write_output_files() {
449451
size_t read_size = fread(data.data(), 1, size, spv);
450452
fclose(spv);
451453
if (read_size != size) {
452-
std::cerr << "Error reading SPIR-V file: " << path << "\n";
454+
std::cerr << "Error reading SPIR-V file: " << path << " (" << strerror(errno) << "\n";
453455
continue;
454456
}
455457

0 commit comments

Comments
 (0)