| author | |
| committer | |
| log | a3d77bdba9f8c6c3a88cfdfc009e1fabff22d2eb |
| tree | 1cdcb7164c2068dffd97e1c586e38b8e3bde58fb |
| parent | ab701c3d375b102bc291f80a791109cb109964ba |
| signature | Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4 |
2 files changed, 8 insertions(+), 13 deletions(-)
src/codegen/spirv/Module.zig+4-8| ... | @@ -103,15 +103,12 @@ pub const EntryPoint = struct { | ... | @@ -103,15 +103,12 @@ pub const EntryPoint = struct { |
| 103 | /// The declaration that should be exported. | 103 | /// The declaration that should be exported. |
| 104 | decl_index: Decl.Index, | 104 | decl_index: Decl.Index, |
| 105 | /// The name of the kernel to be exported. | 105 | /// The name of the kernel to be exported. |
| 106 | name: []const u8, | 106 | name: CacheString, |
| 107 | }; | 107 | }; |
| 108 | 108 | ||
| 109 | /// A general-purpose allocator which may be used to allocate resources for this module | 109 | /// A general-purpose allocator which may be used to allocate resources for this module |
| 110 | gpa: Allocator, | 110 | gpa: Allocator, |
| 111 | 111 | ||
| 112 | /// An arena allocator used to store things that have the same lifetime as this module. | ||
| 113 | arena: Allocator, | ||
| 114 | |||
| 115 | /// Module layout, according to SPIR-V Spec section 2.4, "Logical Layout of a Module". | 112 | /// Module layout, according to SPIR-V Spec section 2.4, "Logical Layout of a Module". |
| 116 | sections: struct { | 113 | sections: struct { |
| 117 | /// Capability instructions | 114 | /// Capability instructions |
| ... | @@ -176,10 +173,9 @@ globals: struct { | ... | @@ -176,10 +173,9 @@ globals: struct { |
| 176 | section: Section = .{}, | 173 | section: Section = .{}, |
| 177 | } = .{}, | 174 | } = .{}, |
| 178 | 175 | ||
| 179 | pub fn init(gpa: Allocator, arena: Allocator) Module { | 176 | pub fn init(gpa: Allocator) Module { |
| 180 | return .{ | 177 | return .{ |
| 181 | .gpa = gpa, | 178 | .gpa = gpa, |
| 182 | .arena = arena, | ||
| 183 | .next_result_id = 1, // 0 is an invalid SPIR-V result id, so start counting at 1. | 179 | .next_result_id = 1, // 0 is an invalid SPIR-V result id, so start counting at 1. |
| 184 | }; | 180 | }; |
| 185 | } | 181 | } |
| ... | @@ -321,7 +317,7 @@ fn entryPoints(self: *Module) !Section { | ... | @@ -321,7 +317,7 @@ fn entryPoints(self: *Module) !Section { |
| 321 | try entry_points.emit(self.gpa, .OpEntryPoint, .{ | 317 | try entry_points.emit(self.gpa, .OpEntryPoint, .{ |
| 322 | .execution_model = .Kernel, | 318 | .execution_model = .Kernel, |
| 323 | .entry_point = entry_point_id, | 319 | .entry_point = entry_point_id, |
| 324 | .name = entry_point.name, | 320 | .name = self.cache.getString(entry_point.name).?, |
| 325 | .interface = interface.items, | 321 | .interface = interface.items, |
| 326 | }); | 322 | }); |
| 327 | } | 323 | } |
| ... | @@ -641,7 +637,7 @@ pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32, resul | ... | @@ -641,7 +637,7 @@ pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32, resul |
| 641 | pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void { | 637 | pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void { |
| 642 | try self.entry_points.append(self.gpa, .{ | 638 | try self.entry_points.append(self.gpa, .{ |
| 643 | .decl_index = decl_index, | 639 | .decl_index = decl_index, |
| 644 | .name = try self.arena.dupe(u8, name), | 640 | .name = try self.resolveString(name), |
| 645 | }); | 641 | }); |
| 646 | } | 642 | } |
| 647 | 643 |
src/link/SpirV.zig+4-5| ... | @@ -46,7 +46,6 @@ const IdResult = spec.IdResult; | ... | @@ -46,7 +46,6 @@ const IdResult = spec.IdResult; |
| 46 | base: link.File, | 46 | base: link.File, |
| 47 | 47 | ||
| 48 | spv: SpvModule, | 48 | spv: SpvModule, |
| 49 | spv_arena: ArenaAllocator, | ||
| 50 | decl_link: codegen.DeclLinkMap, | 49 | decl_link: codegen.DeclLinkMap, |
| 51 | anon_decl_link: codegen.AnonDeclLinkMap, | 50 | anon_decl_link: codegen.AnonDeclLinkMap, |
| 52 | 51 | ||
| ... | @@ -60,11 +59,10 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*SpirV { | ... | @@ -60,11 +59,10 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*SpirV { |
| 60 | .allocator = gpa, | 59 | .allocator = gpa, |
| 61 | }, | 60 | }, |
| 62 | .spv = undefined, | 61 | .spv = undefined, |
| 63 | .spv_arena = ArenaAllocator.init(gpa), | ||
| 64 | .decl_link = codegen.DeclLinkMap.init(self.base.allocator), | 62 | .decl_link = codegen.DeclLinkMap.init(self.base.allocator), |
| 65 | .anon_decl_link = codegen.AnonDeclLinkMap.init(self.base.allocator), | 63 | .anon_decl_link = codegen.AnonDeclLinkMap.init(self.base.allocator), |
| 66 | }; | 64 | }; |
| 67 | self.spv = SpvModule.init(gpa, self.spv_arena.allocator()); | 65 | self.spv = SpvModule.init(gpa); |
| 68 | errdefer self.deinit(); | 66 | errdefer self.deinit(); |
| 69 | 67 | ||
| 70 | // TODO: Figure out where to put all of these | 68 | // TODO: Figure out where to put all of these |
| ... | @@ -102,7 +100,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -102,7 +100,6 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 102 | 100 | ||
| 103 | pub fn deinit(self: *SpirV) void { | 101 | pub fn deinit(self: *SpirV) void { |
| 104 | self.spv.deinit(); | 102 | self.spv.deinit(); |
| 105 | self.spv_arena.deinit(); | ||
| 106 | self.decl_link.deinit(); | 103 | self.decl_link.deinit(); |
| 107 | self.anon_decl_link.deinit(); | 104 | self.anon_decl_link.deinit(); |
| 108 | } | 105 | } |
| ... | @@ -196,7 +193,9 @@ pub fn flushModule(self: *SpirV, comp: *Compilation, prog_node: *std.Progress.No | ... | @@ -196,7 +193,9 @@ pub fn flushModule(self: *SpirV, comp: *Compilation, prog_node: *std.Progress.No |
| 196 | // executor. This is not really an important thing though, so we can just dump it in any old | 193 | // executor. This is not really an important thing though, so we can just dump it in any old |
| 197 | // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name. | 194 | // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name. |
| 198 | 195 | ||
| 199 | var error_info = std.ArrayList(u8).init(self.spv.arena); | 196 | var error_info = std.ArrayList(u8).init(self.spv.gpa); |
| 197 | defer error_info.deinit(); | ||
| 198 | |||
| 200 | try error_info.appendSlice("zig_errors"); | 199 | try error_info.appendSlice("zig_errors"); |
| 201 | const module = self.base.options.module.?; | 200 | const module = self.base.options.module.?; |
| 202 | for (module.global_error_set.keys()) |name_nts| { | 201 | for (module.global_error_set.keys()) |name_nts| { |