Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/codegen/spirv/Module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,21 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
},
};

const zig_version = @import("builtin").zig_version;
const zig_spirv_compiler_version = comptime (zig_version.major << 12) | (zig_version.minor << 7) | zig_version.patch;

// A SPIR-V Generator Magic Number is a 32 bit word: The high order 16
// bits are a tool ID, which should be unique across all SPIR-V
// generators. The low order 16 bits are reserved for use as a tool
// version number, or any other purpose the tool supplier chooses.
// Only the tool IDs are reserved with Khronos.
// See https://github.com/KhronosGroup/SPIRV-Headers/blob/main/include/spirv/spir-v.xml#L17C5-L21C54
const generator_id: u32 = (spec.zig_generator_id << 16) | zig_spirv_compiler_version;

const header = [_]Word{
spec.magic_number,
version.toWord(),
spec.zig_generator_id,
generator_id,
module.idBound(),
0, // Schema (currently reserved for future use)
};
Expand All @@ -437,7 +448,7 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
defer source.deinit(module.gpa);
try module.sections.debug_strings.emit(module.gpa, .OpSource, .{
.source_language = .zig,
.version = 0,
.version = zig_spirv_compiler_version,
// We cannot emit these because the Khronos translator does not parse this instruction
// correctly.
// See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188
Expand Down
4 changes: 2 additions & 2 deletions src/link/SpirV/BinaryModule.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn finalize(self: BinaryModule, a: Allocator) ![]Word {

result[0] = spec.magic_number;
result[1] = @bitCast(self.version);
result[2] = spec.zig_generator_id;
result[2] = @bitCast(self.generator_magic);
result[3] = self.id_bound;
result[4] = 0; // Schema

Expand Down Expand Up @@ -196,7 +196,7 @@ pub const Parser = struct {

var binary = BinaryModule{
.version = @bitCast(module[1]),
.generator_magic = module[2],
.generator_magic = @bitCast(module[2]),
.id_bound = module[3],
.instructions = module[header_words..],
.ext_inst_map = .{},
Expand Down