authorgravatar for kbz_8.dev@akel-engine.comkbz_8 <kbz_8.dev@akel-engine.com> 2025-11-04 05:40:29+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-11-04 04:40:29+00:00
logc603d27f900540b52586ee2638060a4b2ac7c557
treed576609f8f556b37ff19853863add72755115bd6
parentee4df4ad3edad160fb737a1935cd86bc2f9cfbbe
signaturebadge-check Signed by PGP key B5690EEEBB952194

Fixing SPIR-V header generator magic + Adding Zig compiler version to SPIR-V OpSource (#25435)

* fixing Zig generator magic in SPIR-V header; adding zig compiler version to SPIR-V OpSource * Update src/codegen/spirv/Module.zig Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com> --------- Co-authored-by: rpkak <67059904+rpkak@users.noreply.github.com>

2 files changed, 15 insertions(+), 4 deletions(-)

src/codegen/spirv/Module.zig+13-2
......@@ -425,10 +425,21 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
425425 },
426426 };
427427
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/f2e4bd213104fe323a01e935df56557328d37ac8/include/spirv/spir-v.xml#L17C5-L21C54
437 const generator_id: u32 = (spec.zig_generator_id << 16) | zig_spirv_compiler_version;
438
428439 const header = [_]Word{
429440 spec.magic_number,
430441 version.toWord(),
431 spec.zig_generator_id,
442 generator_id,
432443 module.idBound(),
433444 0, // Schema (currently reserved for future use)
434445 };
......@@ -437,7 +448,7 @@ pub fn finalize(module: *Module, gpa: Allocator) ![]Word {
437448 defer source.deinit(module.gpa);
438449 try module.sections.debug_strings.emit(module.gpa, .OpSource, .{
439450 .source_language = .zig,
440 .version = 0,
451 .version = zig_spirv_compiler_version,
441452 // We cannot emit these because the Khronos translator does not parse this instruction
442453 // correctly.
443454 // See https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2188
src/link/SpirV/BinaryModule.zig+2-2
......@@ -63,7 +63,7 @@ pub fn finalize(self: BinaryModule, a: Allocator) ![]Word {
6363
6464 result[0] = spec.magic_number;
6565 result[1] = @bitCast(self.version);
66 result[2] = spec.zig_generator_id;
66 result[2] = @bitCast(self.generator_magic);
6767 result[3] = self.id_bound;
6868 result[4] = 0; // Schema
6969
......@@ -196,7 +196,7 @@ pub const Parser = struct {
196196
197197 var binary = BinaryModule{
198198 .version = @bitCast(module[1]),
199 .generator_magic = module[2],
199 .generator_magic = @bitCast(module[2]),
200200 .id_bound = module[3],
201201 .instructions = module[header_words..],
202202 .ext_inst_map = .{},