File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -425,10 +425,21 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
425
425
},
426
426
};
427
427
428
+ const zig_version = @import ("builtin" ).zig_version ;
429
+ const zig_spirv_compiler_version = comptime (zig_version .major << 12 ) | (zig_version .minor << 7 ) | zig_version .patch ;
430
+
431
+ // A SPIR-V Generator Magic Number is a 32 bit word: The high order 16
432
+ // bits are a tool ID, which should be unique across all SPIR-V
433
+ // generators. The low order 16 bits are reserved for use as a tool
434
+ // version number, or any other purpose the tool supplier chooses.
435
+ // Only the tool IDs are reserved with Khronos.
436
+ // See https://github.com/KhronosGroup/SPIRV-Headers/blob/main/include/spirv/spir-v.xml#L17C5-L21C54
437
+ const generator_id : u32 = (spec .zig_generator_id << 16 ) | zig_spirv_compiler_version ;
438
+
428
439
const header = [_ ]Word {
429
440
spec .magic_number ,
430
441
version .toWord (),
431
- spec . zig_generator_id ,
442
+ generator_id ,
432
443
module .idBound (),
433
444
0 , // Schema (currently reserved for future use)
434
445
};
@@ -437,7 +448,7 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
437
448
defer source .deinit (module .gpa );
438
449
try module .sections .debug_strings .emit (module .gpa , .OpSource , .{
439
450
.source_language = .zig ,
440
- .version = 0 ,
451
+ .version = zig_spirv_compiler_version ,
441
452
// We cannot emit these because the Khronos translator does not parse this instruction
442
453
// correctly.
443
454
// See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ pub fn finalize(self: BinaryModule, a: Allocator) ![]Word {
63
63
64
64
result [0 ] = spec .magic_number ;
65
65
result [1 ] = @bitCast (self .version );
66
- result [2 ] = spec . zig_generator_id ;
66
+ result [2 ] = @bitCast ( self . generator_magic ) ;
67
67
result [3 ] = self .id_bound ;
68
68
result [4 ] = 0 ; // Schema
69
69
@@ -196,7 +196,7 @@ pub const Parser = struct {
196
196
197
197
var binary = BinaryModule {
198
198
.version = @bitCast (module [1 ]),
199
- .generator_magic = module [2 ],
199
+ .generator_magic = @bitCast ( module [2 ]) ,
200
200
.id_bound = module [3 ],
201
201
.instructions = module [header_words .. ],
202
202
.ext_inst_map = .{},
You can’t perform that action at this time.
0 commit comments