diff --git a/example/main.zig b/example/main.zig index 49f27fa..e02223e 100644 --- a/example/main.zig +++ b/example/main.zig @@ -77,7 +77,7 @@ pub fn main() !void { defer { const ns = frame_timer.lap(); const ms = @as(f32, @floatFromInt(ns)) / std.time.ns_per_s; - std.log.info("Took {d:.3}s - {d:.3}fps to render {d:.2}", .{ ms, 1.0 / ms, delta }); + std.log.info("Took {d:.3}s - {d:.3}fps to render", .{ ms, 1.0 / ms }); } var wait_group: std.Thread.WaitGroup = .{}; diff --git a/sandbox/main.zig b/sandbox/main.zig index 757bf5b..01418f0 100644 --- a/sandbox/main.zig +++ b/sandbox/main.zig @@ -5,7 +5,9 @@ const shader_source = @embedFile("shader.spv"); pub fn main() !void { { - var gpa: std.heap.DebugAllocator(.{}) = .init; + var gpa: std.heap.DebugAllocator(.{ + .enable_memory_limit = true, + }) = .init; defer _ = gpa.deinit(); const allocator = gpa.allocator(); @@ -13,25 +15,27 @@ pub fn main() !void { var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{}); defer module.deinit(allocator); - var rt = try spv.Runtime.init(allocator, &module); - defer rt.deinit(allocator); + //var rt = try spv.Runtime.init(allocator, &module); + //defer rt.deinit(allocator); - const entry = try rt.getEntryPointByName("main"); - const color = try rt.getResultByName("color"); - const time = try rt.getResultByName("time"); - const pos = try rt.getResultByName("pos"); - const res = try rt.getResultByName("res"); + //const entry = try rt.getEntryPointByName("main"); + //const color = try rt.getResultByName("color"); + //const time = try rt.getResultByName("time"); + //const pos = try rt.getResultByName("pos"); + //const res = try rt.getResultByName("res"); - var output: [4]f32 = undefined; + //var output: [4]f32 = undefined; - try rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time); - try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res); - try rt.writeInput(f32, &.{ 0.0, 0.0 }, pos); + //try rt.writeInput(f32, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time); + //try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res); + //try rt.writeInput(f32, &.{ 0.0, 0.0 }, pos); - try rt.callEntryPoint(allocator, entry); + //try rt.callEntryPoint(allocator, entry); - try rt.readOutput(f32, output[0..output.len], color); - std.log.info("Output: Vec4{any}", .{output}); + //try rt.readOutput(f32, output[0..output.len], color); + //std.log.info("Output: Vec4{any}", .{output}); + + std.log.info("Total memory used: {d:.3} MB\n", .{@as(f32, @floatFromInt(gpa.total_requested_bytes)) / 1000.0}); } std.log.info("Successfully executed", .{}); } diff --git a/src/Result.zig b/src/Result.zig index 2ec4385..c197546 100644 --- a/src/Result.zig +++ b/src/Result.zig @@ -265,7 +265,6 @@ pub const TypeData = union(Type) { RuntimeArray: struct {}, Structure: struct { members_type_word: []const SpvWord, - members: []Type, member_names: std.ArrayList([]const u8), }, Function: struct { @@ -326,14 +325,11 @@ name: ?[]const u8, decorations: std.ArrayList(Decoration), -parent: ?*const Self, - variant: ?VariantData, pub fn init() Self { return .{ .name = null, - .parent = null, .decorations = .empty, .variant = null, }; @@ -349,7 +345,6 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { .Function => |data| allocator.free(data.params), .Structure => |*data| { allocator.free(data.members_type_word); - allocator.free(data.members); for (data.member_names.items) |name| { allocator.free(name); } @@ -409,7 +404,6 @@ pub fn dupe(self: *const Self, allocator: std.mem.Allocator) RuntimeError!Self { return .{ .name = if (self.name) |name| allocator.dupe(u8, name) catch return RuntimeError.OutOfMemory else null, .decorations = self.decorations.clone(allocator) catch return RuntimeError.OutOfMemory, - .parent = self.parent, .variant = blk: { if (self.variant) |variant| { switch (variant) { @@ -421,7 +415,6 @@ pub fn dupe(self: *const Self, allocator: std.mem.Allocator) RuntimeError!Self { .Type = .{ .Structure = .{ .members_type_word = allocator.dupe(SpvWord, s.members_type_word) catch return RuntimeError.OutOfMemory, - .members = allocator.dupe(Type, s.members) catch return RuntimeError.OutOfMemory, .member_names = blk2: { const member_names = s.member_names.clone(allocator) catch return RuntimeError.OutOfMemory; for (member_names.items, s.member_names.items) |*new_name, name| { @@ -519,7 +512,7 @@ pub fn getMemberCounts(self: *const Self) usize { .Matrix => |m| return m.member_count, .Array => |a| return a.member_count, .SampledImage => return 2, - .Structure => |s| return s.members.len, + .Structure => |s| return s.members_type_word.len, .Function => |f| return f.params.len, else => {}, }, diff --git a/src/opcodes.zig b/src/opcodes.zig index cb0c19a..ad225b1 100644 --- a/src/opcodes.zig +++ b/src/opcodes.zig @@ -1330,7 +1330,6 @@ fn opMemberName(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) .Type = .{ .Structure = .{ .members_type_word = undefined, - .members = undefined, .member_names = .empty, }, }, @@ -1522,18 +1521,14 @@ fn opTypePointer(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!vo fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void { const id = try rt.it.next(); - const members_type_word, const members = blk: { + const members_type_word = blk: { const members_type_word = allocator.alloc(SpvWord, word_count - 1) catch return RuntimeError.OutOfMemory; errdefer allocator.free(members_type_word); - const members = allocator.alloc(Result.Type, word_count - 1) catch return RuntimeError.OutOfMemory; - errdefer allocator.free(members); - - for (members_type_word, members) |*member_type_word, *member| { + for (members_type_word) |*member_type_word| { member_type_word.* = try rt.it.next(); - member.* = rt.mod.results[member_type_word.*].variant.?.Type; } - break :blk .{ members_type_word, members }; + break :blk members_type_word; }; if (rt.mod.results[id].variant) |*variant| { @@ -1541,7 +1536,6 @@ fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) .Type => |*t| switch (t.*) { .Structure => |*s| { s.members_type_word = members_type_word; - s.members = members; }, else => unreachable, }, @@ -1552,7 +1546,6 @@ fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) .Type = .{ .Structure = .{ .members_type_word = members_type_word, - .members = members, .member_names = .empty, }, },