| ... | ... | @@ -31,7 +31,7 @@ pub const SPIRVModule = struct { |
| 31 | 31 | |
| 32 | 32 | pub fn init(allocator: *Allocator) SPIRVModule { |
| 33 | 33 | return .{ |
| 34 | | .next_result_id = 0, |
| 34 | .next_result_id = 1, // 0 is an invalid SPIR-V result ID. |
| 35 | 35 | .types_and_globals = std.ArrayList(u32).init(allocator), |
| 36 | 36 | .fn_decls = std.ArrayList(u32).init(allocator), |
| 37 | 37 | }; |
| ... | ... | @@ -146,17 +146,14 @@ pub const DeclGen = struct { |
| 146 | 146 | 16 => Target.spirv.featureSetHas(target.cpu.features, .Float16), |
| 147 | 147 | 32 => true, |
| 148 | 148 | 64 => Target.spirv.featureSetHas(target.cpu.features, .Float64), |
| 149 | | else => false |
| 149 | else => false, |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | 152 | if (!supported) { |
| 153 | 153 | return self.fail(.{.node_offset = 0}, "Floating point width of {} bits is not supported for the current SPIR-V feature set", .{ bits }); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | | try writeInstruction(code, .OpTypeFloat, &.{ |
| 157 | | result_id, |
| 158 | | bits |
| 159 | | }); |
| 156 | try writeInstruction(code, .OpTypeFloat, &[_]u32{ result_id, bits }); |
| 160 | 157 | }, |
| 161 | 158 | .Fn => { |
| 162 | 159 | // We only support zig-calling-convention functions, no varargs. |
| ... | ... | @@ -195,7 +192,7 @@ pub const DeclGen = struct { |
| 195 | 192 | |
| 196 | 193 | .BoundFn => unreachable, // this type will be deleted from the language. |
| 197 | 194 | |
| 198 | | else => |tag| return self.fail(.{ .node_offset = 0 }, "TODO: SPIR-V backend: implement type {}", .{ tag }), |
| 195 | else => |tag| return self.fail(.{.node_offset = 0}, "TODO: SPIR-V backend: implement type {}", .{ tag }), |
| 199 | 196 | } |
| 200 | 197 | |
| 201 | 198 | try self.types.put(ty, result_id); |
| ... | ... | @@ -203,11 +200,23 @@ pub const DeclGen = struct { |
| 203 | 200 | } |
| 204 | 201 | |
| 205 | 202 | pub fn gen(self: *DeclGen) !void { |
| 203 | const result_id = self.decl.fn_link.spirv.id; |
| 206 | 204 | const tv = self.decl.typed_value.most_recent.typed_value; |
| 207 | 205 | |
| 208 | 206 | if (tv.val.castTag(.function)) |func_payload| { |
| 209 | 207 | std.debug.assert(tv.ty.zigTypeTag() == .Fn); |
| 210 | | _ = try self.getOrGenType(tv.ty); |
| 208 | const prototype_id = try self.getOrGenType(tv.ty); |
| 209 | try writeInstruction(&self.spv.fn_decls, .OpFunction, &[_]u32{ |
| 210 | self.types.get(tv.ty.fnReturnType()).?, // This type should be generated along with the prototype. |
| 211 | result_id, |
| 212 | @bitCast(u32, spec.FunctionControl{}), // TODO: We can set inline here if the type requires it. |
| 213 | prototype_id, |
| 214 | }); |
| 215 | |
| 216 | // TODO: Parameters |
| 217 | // TODO: Body |
| 218 | |
| 219 | try writeInstruction(&self.spv.fn_decls, .OpFunctionEnd, &[_]u32{}); |
| 211 | 220 | } else { |
| 212 | 221 | return self.fail(.{.node_offset = 0}, "TODO: SPIR-V backend: generate decl type {}", .{ tv.ty.zigTypeTag() }); |
| 213 | 222 | } |