diff options
| author | Robin Voetter <robin@voetter.nl> | 2023-10-07 19:43:27 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-10-15 14:00:00 +0200 |
| commit | 4a6a024a4bd103cf7bf7e50a5ccf4103f4ce83a2 (patch) | |
| tree | 36411f3b31fc18c7d561c4efd1f421838f208bcf /src/codegen | |
| parent | 89b1dafa7808d22eab78ea486f158f794da46a2c (diff) | |
| download | zig-4a6a024a4bd103cf7bf7e50a5ccf4103f4ce83a2.tar.gz zig-4a6a024a4bd103cf7bf7e50a5ccf4103f4ce83a2.zip | |
spirv: properly skip comptime function parameters
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/spirv.zig | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 2fdec5675f..fd984c78d5 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1242,14 +1242,19 @@ const DeclGen = struct { const param_ty_refs = try self.gpa.alloc(CacheRef, fn_info.param_types.len); defer self.gpa.free(param_ty_refs); - for (param_ty_refs, fn_info.param_types.get(ip)) |*param_type, fn_param_type| { - param_type.* = try self.resolveType(fn_param_type.toType(), .direct); + var param_index: usize = 0; + for (fn_info.param_types.get(ip)) |param_ty_index| { + const param_ty = param_ty_index.toType(); + if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue; + + param_ty_refs[param_index] = try self.resolveType(param_ty, .direct); + param_index += 1; } const return_ty_ref = try self.resolveType(fn_info.return_type.toType(), .direct); const ty_ref = try self.spv.resolve(.{ .function_type = .{ .return_type = return_ty_ref, - .parameters = param_ty_refs, + .parameters = param_ty_refs[0..param_index], } }); try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); @@ -1675,9 +1680,11 @@ const DeclGen = struct { const fn_info = mod.typeToFunc(decl.ty).?; try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len); - for (0..fn_info.param_types.len) |i| { - const param_type = fn_info.param_types.get(ip)[i]; - const param_type_id = try self.resolveTypeId(param_type.toType()); + for (fn_info.param_types.get(ip)) |param_ty_index| { + const param_ty = param_ty_index.toType(); + if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue; + + const param_type_id = try self.resolveTypeId(param_ty); const arg_result_id = self.spv.allocId(); try self.func.prologue.emit(self.spv.gpa, .OpFunctionParameter, .{ .id_result_type = param_type_id, @@ -3986,9 +3993,9 @@ const DeclGen = struct { // Note: resolve() might emit instructions, so we need to call it // before starting to emit OpFunctionCall instructions. Hence the // temporary params buffer. - const arg_id = try self.resolve(arg); const arg_ty = self.typeOf(arg); if (!arg_ty.hasRuntimeBitsIgnoreComptime(mod)) continue; + const arg_id = try self.resolve(arg); params[n_params] = arg_id; n_params += 1; |
