Issue: https://github.com/KhronosGroup/glslang/issues/3799 --- glslang-14.3.0/StandAlone/spirv-remap.cpp.old 2024-06-25 17:42:43.000000000 -0500 +++ glslang-14.3.0/StandAlone/spirv-remap.cpp 2024-11-22 15:27:02.655869572 -0600 @@ -38,6 +38,7 @@ #include #include #include +#include // // Include remapper @@ -48,6 +49,8 @@ typedef unsigned int SpvWord; + static const SpvWord MagicNumber = 0x07230203; + // Poor man's basename: given a complete path, return file portion. // E.g: // Linux: /foo/bar/test -> test @@ -82,6 +85,7 @@ void read(std::vector& spv, const std::string& inFilename, int verbosity) { std::ifstream fp; + bool isNativeEndian = true; if (verbosity > 0) logHandler(std::string(" reading: ") + inFilename); @@ -97,11 +101,16 @@ spv.reserve(size_t(fp.tellg()) / sizeof(SpvWord)); fp.seekg(0, fp.beg); + char begin = fp.peek(); + char native_begin = reinterpret_cast(&MagicNumber)[0]; + if (begin != native_begin) isNativeEndian = false; + while (!fp.eof()) { SpvWord inWord; fp.read((char *)&inWord, sizeof(inWord)); if (!fp.eof()) { + if (!isNativeEndian) inWord = __bswap_32(inWord); spv.push_back(inWord); if (fp.fail()) errHandler(std::string("error reading file: ") + inFilename);