Migrated to the new std.ArrayList implementation

This commit is contained in:
Lorenzo Torres 2025-08-18 23:23:45 +02:00
parent 8f5c79eb01
commit 330d9b7711
11 changed files with 313 additions and 291 deletions

View file

@ -35,17 +35,17 @@ layout(push_constant) uniform pc {
int light_count;
} pushConstants;
layout (set = 1, binding = 0) uniform sampler2D diffuseSampler;
layout (set = 1, binding = 1) uniform sampler2D specularSampler;
layout (set = 1, binding = 0) uniform sampler2D diffuseSampler[4];
layout (set = 1, binding = 1) uniform sampler2D specularSampler[4];
vec3 calc_directional_light(vec3 normal, vec3 viewDir) {
vec3 lightDir = normalize(-directional_light.direction);
float diff = max(dot(normal, lightDir), 0.0);
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
vec3 ambient = directional_light.ambient * vec3(texture(diffuseSampler, TexCoords));
vec3 diffuse = directional_light.diffuse * diff * vec3(texture(diffuseSampler , TexCoords));
vec3 specular = directional_light.specular * spec * vec3(texture(specularSampler, TexCoords));
vec3 ambient = directional_light.ambient * vec3(texture(diffuseSampler[2], TexCoords));
vec3 diffuse = directional_light.diffuse * diff * vec3(texture(diffuseSampler[2] , TexCoords));
vec3 specular = directional_light.specular * spec * vec3(texture(specularSampler[2], TexCoords));
return (ambient + diffuse + specular);
}
@ -60,9 +60,9 @@ vec3 calc_point_light(int index, vec3 normal, vec3 fragPos, vec3 viewDir) {
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 2);
float distance = length(point_lights.point_lights[index].position - fragPos);
float attenuation = 1.0 / (constant + linear * distance + quadratic * (distance * distance));
vec3 ambient = point_lights.point_lights[index].ambient * vec3(texture(diffuseSampler, TexCoords));
vec3 diffuse = point_lights.point_lights[index].diffuse * diff * vec3(texture(diffuseSampler, TexCoords));
vec3 specular = point_lights.point_lights[index].specular * spec * vec3(texture(specularSampler, TexCoords));
vec3 ambient = point_lights.point_lights[index].ambient * vec3(texture(diffuseSampler[2], TexCoords));
vec3 diffuse = point_lights.point_lights[index].diffuse * diff * vec3(texture(diffuseSampler[2], TexCoords));
vec3 specular = point_lights.point_lights[index].specular * spec * vec3(texture(specularSampler[2], TexCoords));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;

View file

@ -20,15 +20,17 @@ pub const hooks = struct {
pub var key: std.ArrayList(Key) = undefined;
pub var scroll: std.ArrayList(Scroll) = undefined;
var allocator: std.mem.Allocator = undefined;
pub const Layer = enum {
key,
scroll
};
pub fn init(allocator: std.mem.Allocator) !void {
key = std.ArrayList(Key).init(allocator);
scroll = std.ArrayList(Scroll).init(allocator);
pub fn init(gpa: std.mem.Allocator) !void {
key = std.ArrayList(Key).empty;
scroll = std.ArrayList(Scroll).empty;
allocator = gpa;
}
pub fn addHook(comptime layer: Layer, hook: anytype) !void {
@ -37,7 +39,7 @@ pub const hooks = struct {
.scroll => &scroll,
};
try list.append(hook);
try list.append(allocator, hook);
}
};

View file

@ -41,8 +41,8 @@ pub const Pool = struct {
var pool = @This(){
.humans = .{},
.resources = resources,
.system_groups = std.ArrayList(SystemGroup).init(allocator),
.sync_groups = std.ArrayList(SystemGroup).init(allocator),
.system_groups = std.ArrayList(SystemGroup).empty,
.sync_groups = std.ArrayList(SystemGroup).empty,
.thread_pool = try allocator.create(std.Thread.Pool),
.wait_group = .{},
.mutex = .{},
@ -59,17 +59,17 @@ pub const Pool = struct {
pub fn addSystemGroup(self: *@This(), group: SystemGroup, sync: bool) !void {
if (sync) {
try self.sync_groups.append(group);
try self.sync_groups.append(self.allocator, group);
} else {
try self.system_groups.append(group);
try self.system_groups.append(self.allocator, group);
}
}
pub fn deinit(self: *@This()) void {
self.humans.deinit(self.allocator);
self.system_groups.deinit();
self.sync_groups.deinit();
self.system_groups.deinit(self.allocator);
self.sync_groups.deinit(self.allocator);
self.thread_pool.deinit();
self.allocator.destroy(self.thread_pool);
}

View file

@ -143,7 +143,7 @@ pub const Runtime = struct {
}
pub fn deinit(self: *Runtime, allocator: Allocator) void {
self.stack.deinit();
self.stack.deinit(allocator);
self.global_runtime.deinit();
self.module.deinit(allocator);
self.externalFuncs.deinit(allocator);
@ -181,10 +181,10 @@ pub const Runtime = struct {
},
.@"return" => break :loop,
.call => {
var parameters = std.ArrayList(Value).init(allocator);
defer parameters.deinit();
var parameters = std.ArrayList(Value).empty;
defer parameters.deinit(allocator);
for (self.module.functions[index.u32].func_type.parameters) |_| {
try parameters.append(self.stack.pop().?);
try parameters.append(allocator, self.stack.pop().?);
}
try self.call(allocator, index.u32, parameters.items);
},
@ -194,22 +194,22 @@ pub const Runtime = struct {
}
const j: u32 = @intCast(self.stack.pop().?.i32);
const funcIdx = self.module.elems[index.indirect.x][j];
var parameters = std.ArrayList(Value).init(allocator);
defer parameters.deinit();
var parameters = std.ArrayList(Value).empty;
defer parameters.deinit(allocator);
for (self.module.functions[funcIdx].func_type.parameters) |_| {
try parameters.append(self.stack.pop().?);
try parameters.append(allocator, self.stack.pop().?);
}
try self.call(allocator, funcIdx, parameters.items);
},
.refnull => {
try self.stack.append(.{.ref = .{.type = null, .val = 0}});
try self.stack.append(allocator, .{.ref = .{.type = null, .val = 0}});
},
.refisnull => {
try self.stack.append(.{ .i32 = @intCast(@as(i1, @bitCast(self.stack.pop().?.ref.type == null))) });
try self.stack.append(allocator, .{ .i32 = @intCast(@as(i1, @bitCast(self.stack.pop().?.ref.type == null))) });
},
.reffunc => {
try self.stack.append(.{.ref = .{.type = std.wasm.RefType.funcref, .val = index.u32}});
try self.stack.append(allocator, .{.ref = .{.type = std.wasm.RefType.funcref, .val = index.u32}});
},
.drop => {
@ -220,17 +220,17 @@ pub const Runtime = struct {
const val2 = self.stack.pop().?;
const val1 = self.stack.pop().?;
if (c != 0) {
try self.stack.append(val1);
try self.stack.append(allocator, val1);
} else {
try self.stack.append(val2);
try self.stack.append(allocator, val2);
}
},
.select_with_values => @panic("UNIMPLEMENTED"),
.localget => try self.stack.append(frame.locals[index.u32]),
.localget => try self.stack.append(allocator, frame.locals[index.u32]),
.localset => frame.locals[index.u32] = self.stack.pop().?,
.localtee => frame.locals[index.u32] = self.stack.items[self.stack.items.len - 1],
.globalget => try self.stack.append(self.global_runtime.getGlobal(index.u32)),
.globalget => try self.stack.append(allocator, self.global_runtime.getGlobal(index.u32)),
.globalset => try self.global_runtime.updateGlobal(index.u32, self.stack.pop().?),
.tableget => @panic("UNIMPLEMENTED"),
@ -246,82 +246,82 @@ pub const Runtime = struct {
.i32_load => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i32);
try self.stack.append(.{ .i32 = std.mem.littleToNative(i32, std.mem.bytesAsValue(i32, self.memory[start..end]).*) });
try self.stack.append(allocator, .{ .i32 = std.mem.littleToNative(i32, std.mem.bytesAsValue(i32, self.memory[start..end]).*) });
},
.i64_load => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i64);
try self.stack.append(.{ .i64 = std.mem.littleToNative(i64, std.mem.bytesAsValue(i64, self.memory[start..end]).*) });
try self.stack.append(allocator, .{ .i64 = std.mem.littleToNative(i64, std.mem.bytesAsValue(i64, self.memory[start..end]).*) });
},
.f32_load => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(f32);
try self.stack.append(.{ .f32 = std.mem.littleToNative(f32, std.mem.bytesAsValue(f32, self.memory[start..end]).*) });
try self.stack.append(allocator, .{ .f32 = std.mem.littleToNative(f32, std.mem.bytesAsValue(f32, self.memory[start..end]).*) });
},
.f64_load => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(f64);
try self.stack.append(.{ .f64 = std.mem.littleToNative(f64, std.mem.bytesAsValue(f64, self.memory[start..end]).*) });
try self.stack.append(allocator, .{ .f64 = std.mem.littleToNative(f64, std.mem.bytesAsValue(f64, self.memory[start..end]).*) });
},
.i32_load8_s => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i8);
const raw_value = std.mem.readInt(i8, @as(*const [1]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i32 = @intCast(@as(i32, raw_value)) });
try self.stack.append(allocator, .{ .i32 = @intCast(@as(i32, raw_value)) });
},
.i32_load8_u => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(u8);
const raw_value = std.mem.readInt(u8, @as(*const [1]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i32 = @intCast(@as(u32, raw_value)) });
try self.stack.append(allocator, .{ .i32 = @intCast(@as(u32, raw_value)) });
},
.i32_load16_s => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i16);
const raw_value = std.mem.readInt(i16, @as(*const [2]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i32 = @intCast(@as(i32, raw_value)) });
try self.stack.append(allocator, .{ .i32 = @intCast(@as(i32, raw_value)) });
},
.i32_load16_u => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(u16);
const raw_value = std.mem.readInt(u16, @as(*const [2]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i32 = @intCast(@as(u32, raw_value)) });
try self.stack.append(allocator, .{ .i32 = @intCast(@as(u32, raw_value)) });
},
.i64_load8_s => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i8);
const raw_value = std.mem.readInt(i8, @as(*const [1]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(i64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(i64, raw_value)) });
},
.i64_load8_u => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(u8);
const raw_value = std.mem.readInt(u8, @as(*const [1]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(u64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(u64, raw_value)) });
},
.i64_load16_s => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i16);
const raw_value = std.mem.readInt(i16, @as(*const [2]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(i64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(i64, raw_value)) });
},
.i64_load16_u => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(u16);
const raw_value = std.mem.readInt(u16, @as(*const [2]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(u64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(u64, raw_value)) });
},
.i64_load32_s => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(i32);
const raw_value = std.mem.readInt(i32, @as(*const [4]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(i64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(i64, raw_value)) });
},
.i64_load32_u => {
const start = index.memarg.offset + @as(u32, @intCast(self.stack.pop().?.i32));
const end = start + @sizeOf(u32);
const raw_value = std.mem.readInt(u32, @as(*const [4]u8, @ptrCast(self.memory[start..end])), std.builtin.Endian.little);
try self.stack.append(.{ .i64 = @intCast(@as(u64, raw_value)) });
try self.stack.append(allocator, .{ .i64 = @intCast(@as(u64, raw_value)) });
},
.i32_store => {
const val = std.mem.nativeToLittle(i32, self.stack.pop().?.i32);
@ -424,7 +424,7 @@ pub const Runtime = struct {
},
.memorysize => {
try self.stack.append(.{ .i32 = @intCast(self.memory.len / Parser.PAGE_SIZE) });
try self.stack.append(allocator, .{ .i32 = @intCast(self.memory.len / Parser.PAGE_SIZE) });
},
.memorygrow => {
const newPages = self.stack.pop().?.i32;
@ -434,7 +434,7 @@ pub const Runtime = struct {
}
const oldPages: i32 = @intCast(self.memory.len / Parser.PAGE_SIZE);
self.memory = try allocator.realloc(self.memory, newSize * Parser.PAGE_SIZE);
try self.stack.append(.{ .i32 = oldPages });
try self.stack.append(allocator, .{ .i32 = oldPages });
},
// TODO(luccie): We need passive memory for this
.memoryinit => @panic("UNIMPLEMENTED"),
@ -453,218 +453,218 @@ pub const Runtime = struct {
},
.i32_const => {
try self.stack.append(.{ .i32 = frame.code.indices[frame.program_counter].i32 });
try self.stack.append(allocator, .{ .i32 = frame.code.indices[frame.program_counter].i32 });
},
.i64_const => {
try self.stack.append(.{ .i64 = frame.code.indices[frame.program_counter].i64 });
try self.stack.append(allocator, .{ .i64 = frame.code.indices[frame.program_counter].i64 });
},
.f32_const => {
try self.stack.append(.{ .f32 = frame.code.indices[frame.program_counter].f32 });
try self.stack.append(allocator, .{ .f32 = frame.code.indices[frame.program_counter].f32 });
},
.f64_const => {
try self.stack.append(.{ .f64 = frame.code.indices[frame.program_counter].f64 });
try self.stack.append(allocator, .{ .f64 = frame.code.indices[frame.program_counter].f64 });
},
.i32_eqz => {
const val = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(val == 0) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(val == 0) });
},
.i32_eq => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(a == b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a == b) });
},
.i32_ne => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(a != b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a != b) });
},
.i32_lt_s => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.i32_lt_u => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.i32_gt_s => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.i32_gt_u => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.i32_le_s => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.i32_le_u => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.i32_ge_s => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.i32_ge_u => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.i64_eqz => {
const val = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(val == 0) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(val == 0) });
},
.i64_eq => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(a == b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a == b) });
},
.i64_ne => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(a != b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a != b) });
},
.i64_lt_s => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.i64_lt_u => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.i64_gt_s => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.i64_gt_u => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.i64_le_s => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.i64_le_u => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.i64_ge_s => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.i64_ge_u => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.f32_eq => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(a == b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a == b) });
},
.f32_ne => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(a != b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a != b) });
},
.f32_lt => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.f32_gt => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.f32_le => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.f32_ge => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.f64_eq => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(a == b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a == b) });
},
.f64_ne => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(a != b) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(a != b) });
},
.f64_lt => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(b < a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b < a) });
},
.f64_gt => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(b > a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b > a) });
},
.f64_le => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(b <= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b <= a) });
},
.f64_ge => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .i32 = @intFromBool(b >= a) });
try self.stack.append(allocator, .{ .i32 = @intFromBool(b >= a) });
},
.i32_clz => {
try self.stack.append(.{ .i32 = @clz(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .i32 = @clz(self.stack.pop().?.i32) });
},
.i32_ctz => {
try self.stack.append(.{ .i32 = @ctz(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .i32 = @ctz(self.stack.pop().?.i32) });
},
.i32_popcnt => {
try self.stack.append(.{ .i32 = @popCount(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .i32 = @popCount(self.stack.pop().?.i32) });
},
.i32_add => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = a + b });
try self.stack.append(allocator, .{ .i32 = a + b });
},
.i32_sub => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = b - a });
try self.stack.append(allocator, .{ .i32 = b - a });
},
.i32_and => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = a & b });
try self.stack.append(allocator, .{ .i32 = a & b });
},
.i32_mul => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = a * b });
try self.stack.append(allocator, .{ .i32 = a * b });
},
.i32_div_s => {
const a_signed = self.stack.pop().?.i32;
@ -672,7 +672,7 @@ pub const Runtime = struct {
if (a_signed == 0){
std.debug.panic("Division by 0 error!\n", .{});
}
try self.stack.append(.{ .i32 = @divTrunc(b_signed, a_signed) });
try self.stack.append(allocator, .{ .i32 = @divTrunc(b_signed, a_signed) });
},
.i32_div_u => {
const a_unsigned = @as(u32, @bitCast(self.stack.pop().?.i32));
@ -680,7 +680,7 @@ pub const Runtime = struct {
if (a_unsigned == 0){
std.debug.panic("Division by 0 error!\n", .{});
}
try self.stack.append(.{ .i32 = @bitCast(b_unsigned / a_unsigned) });
try self.stack.append(allocator, .{ .i32 = @bitCast(b_unsigned / a_unsigned) });
},
.i32_rem_s => {
const divisor = self.stack.pop().?.i32;
@ -688,7 +688,7 @@ pub const Runtime = struct {
if (divisor == 0) {
std.debug.panic("Divide by 0\n", .{});
}
try self.stack.append(.{ .i32 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
try self.stack.append(allocator, .{ .i32 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
},
.i32_rem_u => {
const divisor = @as(u32, @bitCast(self.stack.pop().?.i32));
@ -696,67 +696,67 @@ pub const Runtime = struct {
if (divisor == 0) {
std.debug.panic("Divide by 0\n", .{});
}
try self.stack.append(.{ .i32 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
try self.stack.append(allocator, .{ .i32 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
},
.i32_or => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = a | b });
try self.stack.append(allocator, .{ .i32 = a | b });
},
.i32_xor => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = a ^ b });
try self.stack.append(allocator, .{ .i32 = a ^ b });
},
.i32_shl => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = (b << @as(u5, @intCast(a))) });
try self.stack.append(allocator, .{ .i32 = (b << @as(u5, @intCast(a))) });
},
.i32_shr_s => {
const a = self.stack.pop().?.i32;
const b = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = (b >> @as(u5, @intCast(a))) });
try self.stack.append(allocator, .{ .i32 = (b >> @as(u5, @intCast(a))) });
},
.i32_shr_u => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @bitCast(b >> @as(u5, @intCast(a))) });
try self.stack.append(allocator, .{ .i32 = @bitCast(b >> @as(u5, @intCast(a))) });
},
.i32_rotl => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intCast(std.math.rotl(u32, b, a)) });
try self.stack.append(allocator, .{ .i32 = @intCast(std.math.rotl(u32, b, a)) });
},
.i32_rotr => {
const a = @as(u32, @bitCast(self.stack.pop().?.i32));
const b = @as(u32, @bitCast(self.stack.pop().?.i32));
try self.stack.append(.{ .i32 = @intCast(std.math.rotr(u32, b, a)) });
try self.stack.append(allocator, .{ .i32 = @intCast(std.math.rotr(u32, b, a)) });
},
.i64_clz => {
try self.stack.append(.{ .i64 = @clz(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .i64 = @clz(self.stack.pop().?.i64) });
},
.i64_ctz => {
try self.stack.append(.{ .i64 = @ctz(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .i64 = @ctz(self.stack.pop().?.i64) });
},
.i64_popcnt => {
try self.stack.append(.{ .i64 = @popCount(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .i64 = @popCount(self.stack.pop().?.i64) });
},
.i64_add => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = a + b });
try self.stack.append(allocator, .{ .i64 = a + b });
},
.i64_sub => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = b - a });
try self.stack.append(allocator, .{ .i64 = b - a });
},
.i64_mul => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = a * b });
try self.stack.append(allocator, .{ .i64 = a * b });
},
.i64_div_s => {
const a_signed = self.stack.pop().?.i64;
@ -764,7 +764,7 @@ pub const Runtime = struct {
if (a_signed == 0){
std.debug.panic("Division by 0 error!\n", .{});
}
try self.stack.append(.{ .i64 = @divTrunc(b_signed, a_signed) });
try self.stack.append(allocator, .{ .i64 = @divTrunc(b_signed, a_signed) });
},
.i64_div_u => {
const a_unsigned = @as(u64, @bitCast(self.stack.pop().?.i64));
@ -772,7 +772,7 @@ pub const Runtime = struct {
if (a_unsigned == 0){
std.debug.panic("Division by 0 error!\n", .{});
}
try self.stack.append(.{ .i64 = @bitCast(b_unsigned / a_unsigned) });
try self.stack.append(allocator, .{ .i64 = @bitCast(b_unsigned / a_unsigned) });
},
.i64_rem_s => {
const divisor = self.stack.pop().?.i64;
@ -780,7 +780,7 @@ pub const Runtime = struct {
if (divisor == 0) {
std.debug.panic("Divide by 0\n", .{});
}
try self.stack.append(.{ .i64 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
try self.stack.append(allocator, .{ .i64 = @intCast(dividend - divisor * @divTrunc(dividend, divisor)) });
},
.i64_rem_u => {
const divisor = @as(u64, @bitCast(self.stack.pop().?.i64));
@ -788,86 +788,86 @@ pub const Runtime = struct {
if (divisor == 0) {
std.debug.panic("Divide by 0\n", .{});
}
try self.stack.append(.{ .i64 = @bitCast(dividend - divisor * @divTrunc(dividend, divisor)) });
try self.stack.append(allocator, .{ .i64 = @bitCast(dividend - divisor * @divTrunc(dividend, divisor)) });
},
.i64_and => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = a & b });
try self.stack.append(allocator, .{ .i64 = a & b });
},
.i64_or => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = a | b });
try self.stack.append(allocator, .{ .i64 = a | b });
},
.i64_xor => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = a ^ b });
try self.stack.append(allocator, .{ .i64 = a ^ b });
},
.i64_shl => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = @intCast(b << @as(u6, @intCast(a))) });
try self.stack.append(allocator, .{ .i64 = @intCast(b << @as(u6, @intCast(a))) });
},
.i64_shr_s => {
const a = self.stack.pop().?.i64;
const b = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = @intCast(b >> @as(u6, @intCast(a))) });
try self.stack.append(allocator, .{ .i64 = @intCast(b >> @as(u6, @intCast(a))) });
},
.i64_shr_u => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i64 = @bitCast(b >> @as(u6, @intCast(a))) });
try self.stack.append(allocator, .{ .i64 = @bitCast(b >> @as(u6, @intCast(a))) });
},
.i64_rotl => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i64 = @intCast(std.math.rotl(u64, b, a)) });
try self.stack.append(allocator, .{ .i64 = @intCast(std.math.rotl(u64, b, a)) });
},
.i64_rotr => {
const a = @as(u64, @bitCast(self.stack.pop().?.i64));
const b = @as(u64, @bitCast(self.stack.pop().?.i64));
try self.stack.append(.{ .i64 = @intCast(std.math.rotr(u64, b, a)) });
try self.stack.append(allocator, .{ .i64 = @intCast(std.math.rotr(u64, b, a)) });
},
// The value 0x7FFFFFFF here represents the bitmask that masks everything except for the IEEE754 32 bit precision sign bit
.f32_abs => {
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) & 0x7FFFFFFF) });
try self.stack.append(allocator, .{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) & 0x7FFFFFFF) });
},
// The value 0x80000000 here represents the bitmask that only masks the IEEE754 32 bit precision sign bit
.f32_neg => {
try self.stack.append(.{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) ^ 0x80000000) });
try self.stack.append(allocator, .{ .f32 = @bitCast(@as(u32, @bitCast(self.stack.pop().?.f32)) ^ 0x80000000) });
},
.f32_ceil => {
try self.stack.append(.{ .f32 = @ceil(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f32 = @ceil(self.stack.pop().?.f32) });
},
.f32_floor => {
try self.stack.append(.{ .f32 = @floor(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f32 = @floor(self.stack.pop().?.f32) });
},
.f32_trunc => {
try self.stack.append(.{ .f32 = @trunc(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f32 = @trunc(self.stack.pop().?.f32) });
},
.f32_nearest => {
try self.stack.append(.{ .f32 = @round(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f32 = @round(self.stack.pop().?.f32) });
},
.f32_sqrt => {
try self.stack.append(.{ .f32 = @sqrt(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f32 = @sqrt(self.stack.pop().?.f32) });
},
.f32_add => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = a + b });
try self.stack.append(allocator, .{ .f32 = a + b });
},
.f32_sub => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = b - a });
try self.stack.append(allocator, .{ .f32 = b - a });
},
.f32_mul => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = a * b });
try self.stack.append(allocator, .{ .f32 = a * b });
},
.f32_div => {
const a = self.stack.pop().?.f32;
@ -875,205 +875,205 @@ pub const Runtime = struct {
if (a == 0){
std.debug.panic("[ERROR]: Division by 0\n", .{});
}
try self.stack.append(.{ .f32 = b / a });
try self.stack.append(allocator, .{ .f32 = b / a });
},
.f32_min => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = @min(a, b) });
try self.stack.append(allocator, .{ .f32 = @min(a, b) });
},
.f32_max => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = @max(a, b) });
try self.stack.append(allocator, .{ .f32 = @max(a, b) });
},
// See f32_abs and f32_neg for explainations behind these magic values
.f32_copysign => {
const a = self.stack.pop().?.f32;
const b = self.stack.pop().?.f32;
try self.stack.append(.{ .f32 = @bitCast((@as(u32, @bitCast(b)) & 0x7FFFFFFF) | (@as(u32, @bitCast(a)) & 0x80000000)) });
try self.stack.append(allocator, .{ .f32 = @bitCast((@as(u32, @bitCast(b)) & 0x7FFFFFFF) | (@as(u32, @bitCast(a)) & 0x80000000)) });
},
// The value 0x7FFFFFFFFFFFFFFF here represents the bitmask that masks everything except for the IEEE754 64 bit precision sign bit
.f64_abs => {
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) & 0x7FFFFFFFFFFFFFFF) });
try self.stack.append(allocator, .{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) & 0x7FFFFFFFFFFFFFFF) });
},
// The value 0x8000000000000000 here represents the bitmask that only masks the IEEE754 64 bit precision sign bit
.f64_neg => {
try self.stack.append(.{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) ^ 0x8000000000000000) });
try self.stack.append(allocator, .{ .f64 = @bitCast(@as(u64, @bitCast(self.stack.pop().?.f64)) ^ 0x8000000000000000) });
},
.f64_ceil => {
try self.stack.append(.{ .f64 = @ceil(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f64 = @ceil(self.stack.pop().?.f64) });
},
.f64_floor => {
try self.stack.append(.{ .f64 = @floor(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f64 = @floor(self.stack.pop().?.f64) });
},
.f64_trunc => {
try self.stack.append(.{ .f64 = @trunc(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f64 = @trunc(self.stack.pop().?.f64) });
},
.f64_nearest => {
try self.stack.append(.{ .f64 = @round(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f64 = @round(self.stack.pop().?.f64) });
},
.f64_sqrt => {
try self.stack.append(.{ .f64 = @sqrt(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f64 = @sqrt(self.stack.pop().?.f64) });
},
.f64_add => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = a + b });
try self.stack.append(allocator, .{ .f64 = a + b });
},
.f64_sub => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = b - a });
try self.stack.append(allocator, .{ .f64 = b - a });
},
.f64_mul => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = a * b });
try self.stack.append(allocator, .{ .f64 = a * b });
},
.f64_div => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = b / a });
try self.stack.append(allocator, .{ .f64 = b / a });
},
.f64_min => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = @min(a, b) });
try self.stack.append(allocator, .{ .f64 = @min(a, b) });
},
.f64_max => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = @max(a, b) });
try self.stack.append(allocator, .{ .f64 = @max(a, b) });
},
// See f64_abs and f64_neg for explainations behind these magic values
.f64_copysign => {
const a = self.stack.pop().?.f64;
const b = self.stack.pop().?.f64;
try self.stack.append(.{ .f64 = @bitCast((@as(u64, @bitCast(b)) & 0x7FFFFFFFFFFFFFFF) | (@as(u64, @bitCast(a)) & 0x8000000000000000)) });
try self.stack.append(allocator, .{ .f64 = @bitCast((@as(u64, @bitCast(b)) & 0x7FFFFFFFFFFFFFFF) | (@as(u64, @bitCast(a)) & 0x8000000000000000)) });
},
.i32_wrap_i64 => {
try self.stack.append(.{ .i32 = @truncate(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .i32 = @truncate(self.stack.pop().?.i64) });
},
.i32_trunc_f32_s => {
try self.stack.append(.{ .i32 = @intFromFloat(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .i32 = @intFromFloat(self.stack.pop().?.f32) });
},
.i32_trunc_f32_u => {
try self.stack.append(.{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f32))) });
try self.stack.append(allocator, .{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f32))) });
},
.i32_trunc_f64_s => {
try self.stack.append(.{ .i32 = @intFromFloat(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .i32 = @intFromFloat(self.stack.pop().?.f64) });
},
.i32_trunc_f64_u => {
try self.stack.append(.{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f64))) });
try self.stack.append(allocator, .{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f64))) });
},
.i64_extend_i32_s => {
try self.stack.append(.{ .i64 = @as(i64, self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .i64 = @as(i64, self.stack.pop().?.i32) });
},
.i64_extend_i32_u => {
try self.stack.append(.{ .i64 = @as(i64, @as(u32, @bitCast(self.stack.pop().?.i32))) });
try self.stack.append(allocator, .{ .i64 = @as(i64, @as(u32, @bitCast(self.stack.pop().?.i32))) });
},
.i64_trunc_f32_s => {
try self.stack.append(.{ .i64 = @intFromFloat(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .i64 = @intFromFloat(self.stack.pop().?.f32) });
},
.i64_trunc_f32_u => {
try self.stack.append(.{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f32))) });
try self.stack.append(allocator, .{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f32))) });
},
.i64_trunc_f64_s => {
try self.stack.append(.{ .i64 = @intFromFloat(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .i64 = @intFromFloat(self.stack.pop().?.f64) });
},
.i64_trunc_f64_u => {
try self.stack.append(.{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f64))) });
try self.stack.append(allocator, .{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f64))) });
},
.f32_convert_i32_s => {
try self.stack.append(.{ .f32 = @floatFromInt(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .f32 = @floatFromInt(self.stack.pop().?.i32) });
},
.f32_convert_i32_u => {
try self.stack.append(.{ .f32 = @floatFromInt(@as(u32, @bitCast(self.stack.pop().?.i32))) });
try self.stack.append(allocator, .{ .f32 = @floatFromInt(@as(u32, @bitCast(self.stack.pop().?.i32))) });
},
.f32_convert_i64_s => {
try self.stack.append(.{ .f32 = @floatFromInt(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .f32 = @floatFromInt(self.stack.pop().?.i64) });
},
.f32_convert_i64_u => {
try self.stack.append(.{ .f32 = @floatFromInt(@as(u64, @bitCast(self.stack.pop().?.i64))) });
try self.stack.append(allocator, .{ .f32 = @floatFromInt(@as(u64, @bitCast(self.stack.pop().?.i64))) });
},
.f32_demote_f64 => {
try self.stack.append(.{ .f32 = @floatCast(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .f32 = @floatCast(self.stack.pop().?.f64) });
},
.f64_convert_i32_s => {
try self.stack.append(.{ .f64 = @floatFromInt(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .f64 = @floatFromInt(self.stack.pop().?.i32) });
},
.f64_convert_i32_u => {
try self.stack.append(.{ .f64 = @floatFromInt(@as(u32, @bitCast(self.stack.pop().?.i32))) });
try self.stack.append(allocator, .{ .f64 = @floatFromInt(@as(u32, @bitCast(self.stack.pop().?.i32))) });
},
.f64_convert_i64_s => {
try self.stack.append(.{ .f64 = @floatFromInt(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .f64 = @floatFromInt(self.stack.pop().?.i64) });
},
.f64_convert_i64_u => {
try self.stack.append(.{ .f64 = @floatFromInt(@as(u64, @bitCast(self.stack.pop().?.i64))) });
try self.stack.append(allocator, .{ .f64 = @floatFromInt(@as(u64, @bitCast(self.stack.pop().?.i64))) });
},
.f64_promote_f32 => {
try self.stack.append(.{ .f64 = @floatCast(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .f64 = @floatCast(self.stack.pop().?.f32) });
},
.i32_reinterpret_f32 => {
try self.stack.append(.{ .i32 = @bitCast(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .i32 = @bitCast(self.stack.pop().?.f32) });
},
.i64_reinterpret_f64 => {
try self.stack.append(.{ .i64 = @bitCast(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .i64 = @bitCast(self.stack.pop().?.f64) });
},
.f32_reinterpret_i32 => {
try self.stack.append(.{ .f32 = @bitCast(self.stack.pop().?.i32) });
try self.stack.append(allocator, .{ .f32 = @bitCast(self.stack.pop().?.i32) });
},
.f64_reinterpret_i64 => {
try self.stack.append(.{ .f64 = @bitCast(self.stack.pop().?.i64) });
try self.stack.append(allocator, .{ .f64 = @bitCast(self.stack.pop().?.i64) });
},
.i32_extend8_s => {
const val = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @as(i32, @as(i8, @truncate(val))) });
try self.stack.append(allocator, .{ .i32 = @as(i32, @as(i8, @truncate(val))) });
},
.i32_extend16_s => {
const val = self.stack.pop().?.i32;
try self.stack.append(.{ .i32 = @as(i32, @as(i16, @truncate(val))) });
try self.stack.append(allocator, .{ .i32 = @as(i32, @as(i16, @truncate(val))) });
},
.i64_extend8_s => {
const val = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = @as(i64, @as(i8, @truncate(val))) });
try self.stack.append(allocator, .{ .i64 = @as(i64, @as(i8, @truncate(val))) });
},
.i64_extend16_s => {
const val = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = @as(i64, @as(i16, @truncate(val))) });
try self.stack.append(allocator, .{ .i64 = @as(i64, @as(i16, @truncate(val))) });
},
.i64_extend32_s => {
const val = self.stack.pop().?.i64;
try self.stack.append(.{ .i64 = @as(i64, @as(i32, @truncate(val))) });
try self.stack.append(allocator, .{ .i64 = @as(i64, @as(i32, @truncate(val))) });
},
.i32_trunc_sat_f32_s => {
try self.stack.append(.{ .i32 = @intFromFloat(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .i32 = @intFromFloat(self.stack.pop().?.f32) });
},
.i32_trunc_sat_f32_u => {
try self.stack.append(.{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f32))) });
try self.stack.append(allocator, .{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f32))) });
},
.i32_trunc_sat_f64_s => {
try self.stack.append(.{ .i32 = @intFromFloat(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .i32 = @intFromFloat(self.stack.pop().?.f64) });
},
.i32_trunc_sat_f64_u => {
try self.stack.append(.{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f64))) });
try self.stack.append(allocator, .{ .i32 = @bitCast(@as(u32, @intFromFloat(self.stack.pop().?.f64))) });
},
.i64_trunc_sat_f32_s => {
try self.stack.append(.{ .i64 = @intFromFloat(self.stack.pop().?.f32) });
try self.stack.append(allocator, .{ .i64 = @intFromFloat(self.stack.pop().?.f32) });
},
.i64_trunc_sat_f32_u => {
try self.stack.append(.{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f32))) });
try self.stack.append(allocator, .{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f32))) });
},
.i64_trunc_sat_f64_s => {
try self.stack.append(.{ .i64 = @intFromFloat(self.stack.pop().?.f64) });
try self.stack.append(allocator, .{ .i64 = @intFromFloat(self.stack.pop().?.f64) });
},
.i64_trunc_sat_f64_u => {
try self.stack.append(.{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f64))) });
try self.stack.append(allocator, .{ .i64 = @bitCast(@as(u64, @intFromFloat(self.stack.pop().?.f64))) });
},
.vecinst => @panic("UNIMPLEMENTED"),
@ -1166,7 +1166,7 @@ pub const Runtime = struct {
}
const ret = func.?.func(self, parameters);
if (ret != null){
try self.stack.append(ret.?);
try self.stack.append(allocator, ret.?);
}
},
}
@ -1176,12 +1176,12 @@ pub const Runtime = struct {
pub fn handleGlobalInit(allocator: Allocator, ir: IR) !Value {
var instruction_pointer: usize = 0;
var stack = try std.ArrayList(Value).initCapacity(allocator, 10);
defer stack.deinit();
defer stack.deinit(allocator);
while (instruction_pointer < ir.opcodes.len) {
const opcode: IR.Opcode = ir.opcodes[instruction_pointer];
const index = ir.indices[instruction_pointer];
switch (opcode) {
.i32_const => try stack.append(Value{ .i32 = index.i32 }),
.i32_const => try stack.append(allocator, Value{ .i32 = index.i32 }),
else => {
std.debug.panic("TODO: Handle opcode {any}\n", .{opcode});
},

View file

@ -210,8 +210,8 @@ pub fn bindVertexBuffer(self: Self, buffer: vk.Buffer, frame: usize) void {
c.vkCmdBindVertexBuffers(self.command_buffers[frame], 0, 1, &buffer.handle, &offset);
}
pub fn bindDescriptorSets(self: Self, pipeline: vk.GraphicsPipeline, frame: usize, texture: usize) void {
const sets = [_]c.VkDescriptorSet {pipeline.descriptor_set, pipeline.textures.items[texture]};
pub fn bindDescriptorSets(self: Self, pipeline: vk.GraphicsPipeline, frame: usize) void {
const sets = [_]c.VkDescriptorSet {pipeline.descriptor_set, pipeline.textures};
c.vkCmdBindDescriptorSets(self.command_buffers[frame], c.VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 2, sets[0..].ptr, 0, null);
}

View file

@ -28,7 +28,7 @@ view_pos_memory: [*c]u8,
view_pos_buffer: vk.Buffer,
diffuse_sampler: vk.Sampler,
specular_sampler: vk.Sampler,
textures: std.ArrayList(c.VkDescriptorSet),
textures: c.VkDescriptorSet,
directional_light: *lights.DirectionalLight,
directional_light_buffer: vk.Buffer,
point_lights: []lights.PointLight,
@ -45,13 +45,17 @@ pub const Builder = struct {
current_index: u32 = 0,
vertex_buffers: std.ArrayList(vk.Buffer),
index_buffers: std.ArrayList(vk.Buffer),
diffuse_textures: std.ArrayList(vk.Texture),
specular_textures: std.ArrayList(vk.Texture),
device: vk.Device,
allocator: Allocator,
pub fn init(allocator: Allocator, device: vk.Device) Builder {
return .{
.vertex_buffers = std.ArrayList(vk.Buffer).init(allocator),
.index_buffers = std.ArrayList(vk.Buffer).init(allocator),
.vertex_buffers = std.ArrayList(vk.Buffer).empty,
.index_buffers = std.ArrayList(vk.Buffer).empty,
.diffuse_textures = std.ArrayList(vk.Texture).empty,
.specular_textures = std.ArrayList(vk.Texture).empty,
.device = device,
.allocator = allocator,
};
@ -66,8 +70,8 @@ pub const Builder = struct {
const index_cursor = self.current_index;
self.current_vertex += @intCast(vertex_buffer.size);
self.current_index += @intCast(index_buffer.size);
try self.vertex_buffers.append(vertex_buffer);
try self.index_buffers.append(index_buffer);
try self.vertex_buffers.append(self.allocator, vertex_buffer);
try self.index_buffers.append(self.allocator, index_buffer);
return .{
.vertex_buffer = vertex_cursor,
@ -76,9 +80,21 @@ pub const Builder = struct {
};
}
pub fn addTexture(self: *Builder, diffuse: Texture, specular: Texture) !usize {
const index = self.diffuse_textures.items.len;
try self.diffuse_textures.append(self.allocator, diffuse);
try self.specular_textures.append(self.allocator, specular);
return index;
}
pub fn build(self: *Builder, swapchain: vk.Swapchain, render_pass: vk.RenderPass, vertex_shader: c.VkShaderModule, fragment_shader: c.VkShaderModule) !Self {
const vertex_buffer, const index_buffer = try self.createBuffers();
return Self.init(self.allocator, self.device, swapchain, render_pass, vertex_shader, fragment_shader, vertex_buffer, index_buffer);
const pipeline = try Self.init(self.allocator, self.device, swapchain, render_pass, vertex_shader, fragment_shader, vertex_buffer, index_buffer, self.diffuse_textures, self.specular_textures);
self.diffuse_textures.deinit(self.allocator);
self.specular_textures.deinit(self.allocator);
return pipeline;
}
pub fn createBuffers(self: *Builder) !struct { vk.Buffer, vk.Buffer } {
@ -100,8 +116,8 @@ pub const Builder = struct {
buffer.deinit(self.device.handle);
}
self.vertex_buffers.deinit();
self.index_buffers.deinit();
self.vertex_buffers.deinit(self.allocator);
self.index_buffers.deinit(self.allocator);
return .{
vertex_buffer,
@ -197,7 +213,7 @@ pub const Builder = struct {
};
pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, render_pass: vk.RenderPass, vertex_shader: c.VkShaderModule, fragment_shader: c.VkShaderModule, vertex_buffer: vk.Buffer, index_buffer: vk.Buffer) !Self {
pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, render_pass: vk.RenderPass, vertex_shader: c.VkShaderModule, fragment_shader: c.VkShaderModule, vertex_buffer: vk.Buffer, index_buffer: vk.Buffer, diffuse_textures: std.ArrayList(vk.Texture), specular_textures: std.ArrayList(vk.Texture)) !Self {
const vertex_shader_stage_info: c.VkPipelineShaderStageCreateInfo = .{
.sType = c.VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = c.VK_SHADER_STAGE_VERTEX_BIT,
@ -339,14 +355,14 @@ pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, re
const diffuse_sampler_binding = c.VkDescriptorSetLayoutBinding{
.binding = 0,
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 1,
.descriptorCount = @intCast(diffuse_textures.items.len),
.stageFlags = c.VK_SHADER_STAGE_FRAGMENT_BIT,
};
const specular_sampler_binding = c.VkDescriptorSetLayoutBinding{
.binding = 1,
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 1,
.descriptorCount = @intCast(specular_textures.items.len),
.stageFlags = c.VK_SHADER_STAGE_FRAGMENT_BIT,
};
@ -440,7 +456,7 @@ pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, re
const sampler_size = c.VkDescriptorPoolSize{
.type = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.descriptorCount = 2,
.descriptorCount = @intCast(diffuse_textures.items.len + specular_textures.items.len),
};
const transforms_size = c.VkDescriptorPoolSize{
@ -634,6 +650,61 @@ pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, re
c.vkUpdateDescriptorSets(device.handle, 1, &write_view_pos_descriptor_set, 0, null);
const diffuse_sampler = try vk.Sampler.init(device, .linear);
const specular_sampler = try vk.Sampler.init(device, .linear);
const texture_descriptor_allocate_info = c.VkDescriptorSetAllocateInfo{
.sType = c.VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = &texture_descriptor_set_layout,
};
var texture_descriptor_set: c.VkDescriptorSet = undefined;
try vk.mapError(c.vkAllocateDescriptorSets(device.handle, &texture_descriptor_allocate_info, &texture_descriptor_set));
var diffuse_infos = std.ArrayList(c.VkDescriptorImageInfo).empty;
defer diffuse_infos.deinit(allocator);
var specular_infos = std.ArrayList(c.VkDescriptorImageInfo).empty;
defer specular_infos.deinit(allocator);
for (diffuse_textures.items, specular_textures.items) |diffuse, specular| {
try diffuse_infos.append(allocator, .{
.imageLayout = c.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.imageView = diffuse.image_view,
.sampler = diffuse_sampler.handle,
});
try specular_infos.append(allocator, .{
.imageLayout = c.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.imageView = specular.image_view,
.sampler = specular_sampler.handle,
});
}
const write_diffuse_descriptor_set = c.VkWriteDescriptorSet{
.sType = c.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = texture_descriptor_set,
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = @intCast(diffuse_infos.items.len),
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = diffuse_infos.items[0..].ptr,
};
const write_specular_descriptor_set = c.VkWriteDescriptorSet{
.sType = c.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = texture_descriptor_set,
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorCount = @intCast(specular_infos.items.len),
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = specular_infos.items[0..].ptr,
};
const writes = [_]c.VkWriteDescriptorSet {write_diffuse_descriptor_set, write_specular_descriptor_set};
c.vkUpdateDescriptorSets(device.handle, 2, writes[0..].ptr, 0, null);
return Self{
.layout = layout,
.handle = pipeline,
@ -647,83 +718,27 @@ pub fn init(allocator: Allocator, device: vk.Device, swapchain: vk.Swapchain, re
.view_pos_memory = view_pos_data,
.view_pos_buffer = view_pos_buffer,
.transform_buffer = transform_buffer,
.diffuse_sampler = try vk.Sampler.init(device, .linear),
.specular_sampler = try vk.Sampler.init(device, .linear),
.textures = std.ArrayList(c.VkDescriptorSet).init(allocator),
.textures = texture_descriptor_set,
.vertex_buffer = vertex_buffer,
.index_buffer = index_buffer,
.directional_light = directional_light,
.directional_light_buffer = directional_light_buffer,
.point_lights = point_lights,
.point_lights_buffer = point_lights_buffer,
.diffuse_sampler = diffuse_sampler,
.specular_sampler = specular_sampler,
.device = device,
.swapchain = swapchain,
.render_pass = render_pass,
};
}
pub fn addTexture(self: *Self, device: anytype, texture: Texture, diffuse: Texture) !usize {
var set_layouts = [_]c.VkDescriptorSetLayout{self.texture_set_layout};
const descriptor_allocate_info = c.VkDescriptorSetAllocateInfo{
.sType = c.VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = self.descriptor_pool,
.descriptorSetCount = 1,
.pSetLayouts = set_layouts[0..].ptr,
};
var descriptor_set: c.VkDescriptorSet = undefined;
try vk.mapError(c.vkAllocateDescriptorSets(device.handle, &descriptor_allocate_info, &descriptor_set));
const texture_info: c.VkDescriptorImageInfo = .{
.imageLayout = c.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.imageView = texture.image_view,
.sampler = self.diffuse_sampler.handle,
};
const diffuse_info: c.VkDescriptorImageInfo = .{
.imageLayout = c.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
.imageView = diffuse.image_view,
.sampler = self.specular_sampler.handle,
};
const write_texture_descriptor_set = c.VkWriteDescriptorSet{
.sType = c.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptor_set,
.dstBinding = 0,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = &texture_info,
};
const write_diffuse_descriptor_set = c.VkWriteDescriptorSet{
.sType = c.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = descriptor_set,
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorCount = 1,
.descriptorType = c.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = &diffuse_info,
};
const writes = [_]c.VkWriteDescriptorSet {write_texture_descriptor_set, write_diffuse_descriptor_set};
c.vkUpdateDescriptorSets(device.handle, 2, writes[0..].ptr, 0, null);
const index = self.textures.items.len;
try self.textures.append(descriptor_set);
return index;
}
pub fn bind(self: Self, device: vk.Device, frame: usize) void {
std.debug.assert(frame < 2);
c.vkCmdBindPipeline(device.command_buffers[frame], c.VK_PIPELINE_BIND_POINT_GRAPHICS, self.handle);
}
pub fn deinit(self: Self, device: vk.Device) void {
self.textures.deinit();
self.diffuse_sampler.deinit(device);
self.specular_sampler.deinit(device);
self.projection_buffer.deinit(device.handle);

View file

@ -163,10 +163,10 @@ fn createIndexBuffer(device: vk.Device, indices: std.ArrayList(u32)) !vk.Buffer
}
pub fn terrain(allocator: std.mem.Allocator, device: vk.Device, width: usize, height: usize, resolution: usize) !struct { vk.Buffer, vk.Buffer } {
var vertices = std.ArrayList([6]f32).init(allocator);
defer vertices.deinit();
var indices = std.ArrayList(u32).init(allocator);
defer indices.deinit();
var vertices = std.ArrayList([6]f32).empty;
defer vertices.deinit(allocator);
var indices = std.ArrayList(u32).empty;
defer indices.deinit(allocator);
for (0..width*resolution) |x| {
for (0..height*resolution) |z| {
@ -176,7 +176,7 @@ pub fn terrain(allocator: std.mem.Allocator, device: vk.Device, width: usize, he
const v = @as(f32, @floatFromInt(z)) / @as(f32, @floatFromInt(width*resolution - 1));
const vertex: [6]f32 = .{offset_x, offset_z, u, v, offset_x, offset_z };
try vertices.append(vertex);
try vertices.append(allocator, vertex);
}
}
@ -188,13 +188,13 @@ pub fn terrain(allocator: std.mem.Allocator, device: vk.Device, width: usize, he
const bottom_left = @as(u32, @intCast((z+1) * width*resolution + x));
const bottom_right = @as(u32, @intCast((z+1) * width*resolution + (x + 1)));
try indices.append(top_left);
try indices.append(top_right);
try indices.append(bottom_left);
try indices.append(allocator, top_left);
try indices.append(allocator, top_right);
try indices.append(allocator, bottom_left);
try indices.append(top_right);
try indices.append(bottom_right);
try indices.append(bottom_left);
try indices.append(allocator, top_right);
try indices.append(allocator, bottom_right);
try indices.append(allocator, bottom_left);
}
}

View file

@ -39,6 +39,15 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
const swapchain = try vk.Swapchain.init(allocator, surface, device, physical_device, render_pass);
var pipeline_builder = vk.GraphicsPipeline.Builder.init(allocator, device);
const texture = try Texture.init("assets/textures/container.png", device);
const diffuse = try Texture.init("assets/textures/container_specular.png", device);
_ = try pipeline_builder.addTexture(texture, diffuse);
_ = try pipeline_builder.addTexture(texture, diffuse);
_ = try pipeline_builder.addTexture(texture, diffuse);
_ = try pipeline_builder.addTexture(texture, diffuse);
const mesh = try pipeline_builder.addMesh("assets/models/cube.glb");
var graphics_pipeline = try pipeline_builder.build(swapchain, render_pass, vertex_shader, fragment_shader);
@ -48,10 +57,7 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
defer device.deinitShader(terrain_fragment_shader);
const terrain_pipeline = try vk.TerrainPipeline.init(graphics_pipeline, terrain_vertex_shader, terrain_fragment_shader);
const texture = try Texture.init("assets/textures/container.png", device);
const diffuse = try Texture.init("assets/textures/container_specular.png", device);
_ = try graphics_pipeline.addTexture(device, texture, diffuse);
graphics_pipeline.directional_light.direction = .{-0.2, -1.0, -0.3};
graphics_pipeline.directional_light.ambient = .{0.5, 0.5, 0.5};
@ -74,11 +80,10 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
graphics_pipeline.point_lights[1].diffuse = .{0.5, 0.5, 0.5};
graphics_pipeline.point_lights[1].specular = .{1.0, 1.0, 1.0};
var transforms = std.ArrayList(math.Transform).init(allocator);
try transforms.append(math.Transform.init(.{0.0, 0.5, 1.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}));
try transforms.append(math.Transform.init(.{0.0, 0.0, 0.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}));
var transforms = std.ArrayList(math.Transform).empty;
try transforms.append(allocator, math.Transform.init(.{0.0, 0.0, 0.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}));
try transforms.append(allocator, math.Transform.init(.{0.0, 0.5, 1.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}));
return .{
.instance = instance,
@ -130,7 +135,7 @@ pub fn beginGraphics(self: *Self) !void {
self.graphics_pipeline.bind(self.device, self.current_frame);
self.device.bindVertexBuffer(self.graphics_pipeline.vertex_buffer, self.current_frame);
self.device.bindIndexBuffer(self.graphics_pipeline.index_buffer, self.current_frame);
self.device.bindDescriptorSets(self.graphics_pipeline, self.current_frame, 0);
self.device.bindDescriptorSets(self.graphics_pipeline, self.current_frame);
}
pub fn beginTerrain(self: *Self) !void {

View file

@ -84,9 +84,9 @@ pub fn DynamicBuffer(comptime T: type) type {
c.vkUpdateDescriptorSets(device.handle, 1, &write_descriptor_set, 0, null);
var free_indices = std.ArrayList(usize).init(allocator);
var free_indices = std.ArrayList(usize).empty;
for (0..10) |i| {
try free_indices.append(i);
try free_indices.append(allocator, i);
}
return .{

View file

@ -143,12 +143,12 @@ export fn sideros_init(init: api.GameInit) callconv(.c) void {
ecs.hooks.addHook(.scroll, systems.zoomCamera) catch @panic("TODO handle this");
pool = ecs.Pool.init(allocator, &resources) catch @panic("TODO: Gracefully handle error");
// TODO(ernesto): I think this @ptrCast are unavoidable but maybe not?
renderer = Renderer.init(allocator, @ptrCast(init.instance), @ptrCast(init.surface)) catch @panic("TODO: Gracefully handle error");
renderer = Renderer.init(allocator, @ptrCast(init.instance), @ptrCast(init.surface)) catch |err| std.debug.panic("TODO: Gracefully handle error: {}\n", .{err});
resources.terrain = rendering.Terrain.init(allocator, renderer.device, .{
.octaves = 4,
.octaves = 8,
.lacunarity = 2.0,
.gain = 0.5,
.gain = 0.6,
.scale = 30,
.multiplier = 1.0,
.exponent = 1.0,

View file

@ -78,8 +78,8 @@ fn vulkan_init_instance(allocator: std.mem.Allocator, handle: *c.VkInstance) !vo
_ = c.vkEnumerateInstanceLayerProperties(&avaliableLayersCount, availableLayers.ptr);
// Every layer we do have we add to this list, if we don't have it no worries just print a message and continue
var newLayers = std.ArrayList([*c]const u8).init(allocator);
defer newLayers.deinit();
var newLayers = std.ArrayList([*c]const u8).empty;
defer newLayers.deinit(allocator);
// Loop over layers we want
for (validation_layers) |want_layer| {
var found = false;
@ -94,7 +94,7 @@ fn vulkan_init_instance(allocator: std.mem.Allocator, handle: *c.VkInstance) !vo
std.debug.print("WARNING: Compiled in debug mode, but wanted validation layer {s} not found.\n", .{want_layer});
std.debug.print("NOTE: Validation layer will be removed from the wanted validation layers\n", .{});
} else {
try newLayers.append(want_layer);
try newLayers.append(allocator, want_layer);
}
}