From 3c857583fccf9e88ddad934b136d1283c1ea1dab Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Sun, 21 Jun 2026 21:46:32 +0330 Subject: [PATCH] spirv: fix `@SpirvType` opaque externs lowered as `OpUndef` --- src/codegen/spirv/CodeGen.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/codegen/spirv/CodeGen.zig b/src/codegen/spirv/CodeGen.zig index dd9a522b1719661129a2923003948a399eafb3c9..c04bc4f1ef648c565e7ae87c13a35ab18b89fe94 100644 --- a/src/codegen/spirv/CodeGen.zig +++ b/src/codegen/spirv/CodeGen.zig @@ -725,7 +725,10 @@ pub fn genNav(cg: *CodeGen, do_codegen: bool) Error!void { const val = zcu.navValue(cg.owner_nav); const ty = val.typeOf(zcu); - if (!do_codegen and !ty.hasRuntimeBits(zcu)) return; + if (!do_codegen and !ty.hasRuntimeBits(zcu)) { + const child_ty = if (ty.zigTypeTag(zcu) == .pointer) ty.childType(zcu) else ty; + if (child_ty.zigTypeTag(zcu) != .spirv) return; + } const spv_decl_index = try cg.resolveNav(ip, cg.owner_nav); const decl = cg.declPtr(spv_decl_index); @@ -1800,7 +1803,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { }, } - if (!nav_ty.hasRuntimeBits(zcu)) return cg.constUndef(ty_id); + if (!nav_ty.hasRuntimeBits(zcu) and nav_ty.zigTypeTag(zcu) != .spirv) { + return cg.constUndef(ty_id); + } const spv_decl_index = try cg.resolveNav(ip, nav_index); const spv_decl = cg.declPtr(spv_decl_index); @@ -1835,7 +1840,9 @@ fn derivePtr(cg: *CodeGen, derivation: Value.PointerDeriveStep) !Id { else => {}, } - if (!uav_ty.hasRuntimeBits(zcu)) return cg.constUndef(ty_id); + if (!uav_ty.hasRuntimeBits(zcu) and uav_ty.zigTypeTag(zcu) != .spirv) { + return cg.constUndef(ty_id); + } // Uav refs are always generic. assert(result_ptr_ty.ptrAddressSpace(zcu) == .generic); -- 2.54.0