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
signature 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 {...@@ -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};
108108
109/// A general-purpose allocator which may be used to allocate resources for this module109/// A general-purpose allocator which may be used to allocate resources for this module
110gpa: Allocator,110gpa: Allocator,
111111
112/// An arena allocator used to store things that have the same lifetime as this module.
113arena: 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".
116sections: struct {113sections: struct {
117 /// Capability instructions114 /// Capability instructions
...@@ -176,10 +173,9 @@ globals: struct {...@@ -176,10 +173,9 @@ globals: struct {
176 section: Section = .{},173 section: Section = .{},
177} = .{},174} = .{},
178175
179pub fn init(gpa: Allocator, arena: Allocator) Module {176pub 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
641pub fn declareEntryPoint(self: *Module, decl_index: Decl.Index, name: []const u8) !void {637pub 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}
647643
src/link/SpirV.zig+4-5
...@@ -46,7 +46,6 @@ const IdResult = spec.IdResult;...@@ -46,7 +46,6 @@ const IdResult = spec.IdResult;
46base: link.File,46base: link.File,
4747
48spv: SpvModule,48spv: SpvModule,
49spv_arena: ArenaAllocator,
50decl_link: codegen.DeclLinkMap,49decl_link: codegen.DeclLinkMap,
51anon_decl_link: codegen.AnonDeclLinkMap,50anon_decl_link: codegen.AnonDeclLinkMap,
5251
...@@ -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();
6967
70 // TODO: Figure out where to put all of these68 // 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
102100
103pub fn deinit(self: *SpirV) void {101pub 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 old193 // 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.
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
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| {