authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-07 15:10:17+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 13:59:25+02:00
loga3d77bdba9f8c6c3a88cfdfc009e1fabff22d2eb
tree1cdcb7164c2068dffd97e1c586e38b8e3bde58fb
parentab701c3d375b102bc291f80a791109cb109964ba
signaturebadge-check Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: get rid of SpvModule arena


2 files changed, 8 insertions(+), 13 deletions(-)

src/codegen/spirv/Module.zig+4-8
......@@ -103,15 +103,12 @@ pub const EntryPoint = struct {
103103 /// The declaration that should be exported.
104104 decl_index: Decl.Index,
105105 /// The name of the kernel to be exported.
106 name: []const u8,
106 name: CacheString,
107107};
108108
109109/// A general-purpose allocator which may be used to allocate resources for this module
110110gpa: Allocator,
111111
112/// An arena allocator used to store things that have the same lifetime as this module.
113arena: Allocator,
114
115112/// Module layout, according to SPIR-V Spec section 2.4, "Logical Layout of a Module".
116113sections: struct {
117114 /// Capability instructions
......@@ -176,10 +173,9 @@ globals: struct {
176173 section: Section = .{},
177174} = .{},
178175
179pub fn init(gpa: Allocator, arena: Allocator) Module {
176pub fn init(gpa: Allocator) Module {
180177 return .{
181178 .gpa = gpa,
182 .arena = arena,
183179 .next_result_id = 1, // 0 is an invalid SPIR-V result id, so start counting at 1.
184180 };
185181}
......@@ -321,7 +317,7 @@ fn entryPoints(self: *Module) !Section {
321317 try entry_points.emit(self.gpa, .OpEntryPoint, .{
322318 .execution_model = .Kernel,
323319 .entry_point = entry_point_id,
324 .name = entry_point.name,
320 .name = self.cache.getString(entry_point.name).?,
325321 .interface = interface.items,
326322 });
327323 }
......@@ -641,7 +637,7 @@ pub fn endGlobal(self: *Module, global_index: Decl.Index, begin_inst: u32, resul
641637pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void {
642638 try self.entry_points.append(self.gpa, .{
643639 .decl_index = decl_index,
644 .name = try self.arena.dupe(u8, name),
640 .name = try self.resolveString(name),
645641 });
646642}
647643
src/link/SpirV.zig+4-5
......@@ -46,7 +46,6 @@ const IdResult = spec.IdResult;
4646base: link.File,
4747
4848spv: SpvModule,
49spv_arena: ArenaAllocator,
5049decl_link: codegen.DeclLinkMap,
5150anon_decl_link: codegen.AnonDeclLinkMap,
5251
......@@ -60,11 +59,10 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*SpirV {
6059 .allocator = gpa,
6160 },
6261 .spv = undefined,
63 .spv_arena = ArenaAllocator.init(gpa),
6462 .decl_link = codegen.DeclLinkMap.init(self.base.allocator),
6563 .anon_decl_link = codegen.AnonDeclLinkMap.init(self.base.allocator),
6664 };
67 self.spv = SpvModule.init(gpa, self.spv_arena.allocator());
65 self.spv = SpvModule.init(gpa);
6866 errdefer self.deinit();
6967
7068 // 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
102100
103101pub fn deinit(self: *SpirV) void {
104102 self.spv.deinit();
105 self.spv_arena.deinit();
106103 self.decl_link.deinit();
107104 self.anon_decl_link.deinit();
108105}
......@@ -196,7 +193,9 @@ pub fn flushModule(self: *SpirV, comp: *Compilation, prog_node: *std.Progress.No
196193 // executor. This is not really an important thing though, so we can just dump it in any old
197194 // nonsemantic instruction. For now, just put it in OpSourceExtension with a special name.
198195
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
200199 try error_info.appendSlice("zig_errors");
201200 const module = self.base.options.module.?;
202201 for (module.global_error_set.keys()) |name_nts| {