reducing results sizes
This commit is contained in:
@@ -77,7 +77,7 @@ pub fn main() !void {
|
|||||||
defer {
|
defer {
|
||||||
const ns = frame_timer.lap();
|
const ns = frame_timer.lap();
|
||||||
const ms = @as(f32, @floatFromInt(ns)) / std.time.ns_per_s;
|
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 = .{};
|
var wait_group: std.Thread.WaitGroup = .{};
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ const shader_source = @embedFile("shader.spv");
|
|||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
{
|
{
|
||||||
var gpa: std.heap.DebugAllocator(.{}) = .init;
|
var gpa: std.heap.DebugAllocator(.{
|
||||||
|
.enable_memory_limit = true,
|
||||||
|
}) = .init;
|
||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
|
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
@@ -13,25 +15,27 @@ pub fn main() !void {
|
|||||||
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
|
var module = try spv.Module.init(allocator, @ptrCast(@alignCast(shader_source)), .{});
|
||||||
defer module.deinit(allocator);
|
defer module.deinit(allocator);
|
||||||
|
|
||||||
var rt = try spv.Runtime.init(allocator, &module);
|
//var rt = try spv.Runtime.init(allocator, &module);
|
||||||
defer rt.deinit(allocator);
|
//defer rt.deinit(allocator);
|
||||||
|
|
||||||
const entry = try rt.getEntryPointByName("main");
|
//const entry = try rt.getEntryPointByName("main");
|
||||||
const color = try rt.getResultByName("color");
|
//const color = try rt.getResultByName("color");
|
||||||
const time = try rt.getResultByName("time");
|
//const time = try rt.getResultByName("time");
|
||||||
const pos = try rt.getResultByName("pos");
|
//const pos = try rt.getResultByName("pos");
|
||||||
const res = try rt.getResultByName("res");
|
//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, &.{@as(f32, @floatFromInt(std.time.milliTimestamp()))}, time);
|
||||||
try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res);
|
//try rt.writeInput(f32, &.{ 1250.0, 720.0 }, res);
|
||||||
try rt.writeInput(f32, &.{ 0.0, 0.0 }, pos);
|
//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);
|
//try rt.readOutput(f32, output[0..output.len], color);
|
||||||
std.log.info("Output: Vec4{any}", .{output});
|
//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", .{});
|
std.log.info("Successfully executed", .{});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,6 @@ pub const TypeData = union(Type) {
|
|||||||
RuntimeArray: struct {},
|
RuntimeArray: struct {},
|
||||||
Structure: struct {
|
Structure: struct {
|
||||||
members_type_word: []const SpvWord,
|
members_type_word: []const SpvWord,
|
||||||
members: []Type,
|
|
||||||
member_names: std.ArrayList([]const u8),
|
member_names: std.ArrayList([]const u8),
|
||||||
},
|
},
|
||||||
Function: struct {
|
Function: struct {
|
||||||
@@ -326,14 +325,11 @@ name: ?[]const u8,
|
|||||||
|
|
||||||
decorations: std.ArrayList(Decoration),
|
decorations: std.ArrayList(Decoration),
|
||||||
|
|
||||||
parent: ?*const Self,
|
|
||||||
|
|
||||||
variant: ?VariantData,
|
variant: ?VariantData,
|
||||||
|
|
||||||
pub fn init() Self {
|
pub fn init() Self {
|
||||||
return .{
|
return .{
|
||||||
.name = null,
|
.name = null,
|
||||||
.parent = null,
|
|
||||||
.decorations = .empty,
|
.decorations = .empty,
|
||||||
.variant = null,
|
.variant = null,
|
||||||
};
|
};
|
||||||
@@ -349,7 +345,6 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
|||||||
.Function => |data| allocator.free(data.params),
|
.Function => |data| allocator.free(data.params),
|
||||||
.Structure => |*data| {
|
.Structure => |*data| {
|
||||||
allocator.free(data.members_type_word);
|
allocator.free(data.members_type_word);
|
||||||
allocator.free(data.members);
|
|
||||||
for (data.member_names.items) |name| {
|
for (data.member_names.items) |name| {
|
||||||
allocator.free(name);
|
allocator.free(name);
|
||||||
}
|
}
|
||||||
@@ -409,7 +404,6 @@ pub fn dupe(self: *const Self, allocator: std.mem.Allocator) RuntimeError!Self {
|
|||||||
return .{
|
return .{
|
||||||
.name = if (self.name) |name| allocator.dupe(u8, name) catch return RuntimeError.OutOfMemory else null,
|
.name = if (self.name) |name| allocator.dupe(u8, name) catch return RuntimeError.OutOfMemory else null,
|
||||||
.decorations = self.decorations.clone(allocator) catch return RuntimeError.OutOfMemory,
|
.decorations = self.decorations.clone(allocator) catch return RuntimeError.OutOfMemory,
|
||||||
.parent = self.parent,
|
|
||||||
.variant = blk: {
|
.variant = blk: {
|
||||||
if (self.variant) |variant| {
|
if (self.variant) |variant| {
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
@@ -421,7 +415,6 @@ pub fn dupe(self: *const Self, allocator: std.mem.Allocator) RuntimeError!Self {
|
|||||||
.Type = .{
|
.Type = .{
|
||||||
.Structure = .{
|
.Structure = .{
|
||||||
.members_type_word = allocator.dupe(SpvWord, s.members_type_word) catch return RuntimeError.OutOfMemory,
|
.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: {
|
.member_names = blk2: {
|
||||||
const member_names = s.member_names.clone(allocator) catch return RuntimeError.OutOfMemory;
|
const member_names = s.member_names.clone(allocator) catch return RuntimeError.OutOfMemory;
|
||||||
for (member_names.items, s.member_names.items) |*new_name, name| {
|
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,
|
.Matrix => |m| return m.member_count,
|
||||||
.Array => |a| return a.member_count,
|
.Array => |a| return a.member_count,
|
||||||
.SampledImage => return 2,
|
.SampledImage => return 2,
|
||||||
.Structure => |s| return s.members.len,
|
.Structure => |s| return s.members_type_word.len,
|
||||||
.Function => |f| return f.params.len,
|
.Function => |f| return f.params.len,
|
||||||
else => {},
|
else => {},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1330,7 +1330,6 @@ fn opMemberName(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime)
|
|||||||
.Type = .{
|
.Type = .{
|
||||||
.Structure = .{
|
.Structure = .{
|
||||||
.members_type_word = undefined,
|
.members_type_word = undefined,
|
||||||
.members = undefined,
|
|
||||||
.member_names = .empty,
|
.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 {
|
fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
const id = try rt.it.next();
|
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;
|
const members_type_word = allocator.alloc(SpvWord, word_count - 1) catch return RuntimeError.OutOfMemory;
|
||||||
errdefer allocator.free(members_type_word);
|
errdefer allocator.free(members_type_word);
|
||||||
|
|
||||||
const members = allocator.alloc(Result.Type, word_count - 1) catch return RuntimeError.OutOfMemory;
|
for (members_type_word) |*member_type_word| {
|
||||||
errdefer allocator.free(members);
|
|
||||||
|
|
||||||
for (members_type_word, members) |*member_type_word, *member| {
|
|
||||||
member_type_word.* = try rt.it.next();
|
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| {
|
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.*) {
|
.Type => |*t| switch (t.*) {
|
||||||
.Structure => |*s| {
|
.Structure => |*s| {
|
||||||
s.members_type_word = members_type_word;
|
s.members_type_word = members_type_word;
|
||||||
s.members = members;
|
|
||||||
},
|
},
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
},
|
},
|
||||||
@@ -1552,7 +1546,6 @@ fn opTypeStruct(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime)
|
|||||||
.Type = .{
|
.Type = .{
|
||||||
.Structure = .{
|
.Structure = .{
|
||||||
.members_type_word = members_type_word,
|
.members_type_word = members_type_word,
|
||||||
.members = members,
|
|
||||||
.member_names = .empty,
|
.member_names = .empty,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user