blob: 4c1fc78ff3cb4cc83ed6adde9fb85cfd8f0771c7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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 <cstring>
#include <stdexcept>
#include <filesystem>
+#include <byteswap.h>
//
// 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<SpvWord>& 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<const char*>(&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);
|