Skip to content

Commit 82abebc

Browse files
committed
Backend/SpirV: Fix generator number in header
1 parent 8f8a990 commit 82abebc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/NZSL/SpirvWriter.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,16 @@ namespace nzsl
10031003

10041004
std::uint32_t version = MakeSpirvVersion(m_environment.spvMajorVersion, m_environment.spvMinorVersion);
10051005

1006+
// A SPIR-V Generator Magic Number is a 32 bit word: The high order 16 bits are a tool ID. The low order 16 bits are reserved for use as a tool version number, or any other purpose the tool supplier chooses.
1007+
// version is encoded as 0MMM mmmm mppp pppp (first bit is set to zero to allow to change version format)
1008+
static_assert(NZSL_VERSION_MAJOR <= 0b111 && NZSL_VERSION_MINOR <= 0b11111 && NZSL_VERSION_PATCH <= 0b1111111);
1009+
constexpr std::uint32_t GeneratorMagicNumber = VendorId << 16
1010+
| (NZSL_VERSION_MAJOR << 12)
1011+
| (NZSL_VERSION_MINOR << 7)
1012+
| (NZSL_VERSION_PATCH << 0);
1013+
10061014
m_currentState->header.AppendRaw(version); //< SPIR-V version number
1007-
m_currentState->header.AppendRaw(VendorId); //< Generator identifier
1015+
m_currentState->header.AppendRaw(GeneratorMagicNumber);
10081016

10091017
m_currentState->header.AppendRaw(m_currentState->nextResultId); //< Bound (ID count)
10101018
m_currentState->header.AppendRaw(0); //< Instruction schema (required to be 0 for now)

0 commit comments

Comments
 (0)