Commit 3cd19b8884

Robin Voetter <robin@voetter.nl>
2024-10-13 01:56:33
spirv: don't try to lower types which have no runtime bits
1 parent 7e530c1
Changed files (2)
src
codegen
link
src/codegen/spirv.zig
@@ -190,6 +190,7 @@ pub const Object = struct {
         nav_index: InternPool.Nav.Index,
         air: Air,
         liveness: Liveness,
+        do_codegen: bool,
     ) !void {
         const zcu = pt.zcu;
         const gpa = zcu.gpa;
@@ -214,7 +215,7 @@ pub const Object = struct {
         };
         defer nav_gen.deinit();
 
-        nav_gen.genNav() catch |err| switch (err) {
+        nav_gen.genNav(do_codegen) catch |err| switch (err) {
             error.CodegenFail => {
                 try zcu.failed_codegen.put(gpa, nav_index, nav_gen.error_msg.?);
             },
@@ -239,7 +240,7 @@ pub const Object = struct {
     ) !void {
         const nav = pt.zcu.funcInfo(func_index).owner_nav;
         // TODO: Separate types for generating decls and functions?
-        try self.genNav(pt, nav, air, liveness);
+        try self.genNav(pt, nav, air, liveness, true);
     }
 
     pub fn updateNav(
@@ -247,7 +248,7 @@ pub const Object = struct {
         pt: Zcu.PerThread,
         nav: InternPool.Nav.Index,
     ) !void {
-        try self.genNav(pt, nav, undefined, undefined);
+        try self.genNav(pt, nav, undefined, undefined, false);
     }
 
     /// Fetch or allocate a result id for nav index. This function also marks the nav as alive.
@@ -2943,16 +2944,22 @@ const NavGen = struct {
         try self.spv.declareEntryPoint(spv_decl_index, test_name, .Kernel);
     }
 
-    fn genNav(self: *NavGen) !void {
+    fn genNav(self: *NavGen, do_codegen: bool) !void {
         const pt = self.pt;
         const zcu = pt.zcu;
         const ip = &zcu.intern_pool;
-        const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
-        const result_id = self.spv.declPtr(spv_decl_index).result_id;
 
         const nav = ip.getNav(self.owner_nav);
         const val = zcu.navValue(self.owner_nav);
         const ty = val.typeOf(zcu);
+
+        if (!do_codegen and !ty.hasRuntimeBits(zcu)) {
+            return;
+        }
+
+        const spv_decl_index = try self.object.resolveNav(zcu, self.owner_nav);
+        const result_id = self.spv.declPtr(spv_decl_index).result_id;
+
         switch (self.spv.declPtr(spv_decl_index).kind) {
             .func => {
                 const fn_info = zcu.typeToFunc(ty).?;
src/link/SpirV.zig
@@ -140,7 +140,7 @@ pub fn updateNav(self: *SpirV, pt: Zcu.PerThread, nav: InternPool.Nav.Index) !vo
     }
 
     const ip = &pt.zcu.intern_pool;
-    log.debug("lowering declaration {}", .{ip.getNav(nav).name.fmt(ip)});
+    log.debug("lowering nav {}({d})", .{ ip.getNav(nav).fqn.fmt(ip), nav });
 
     try self.object.updateNav(pt, nav);
 }