Port to zig 0.17.0

This commit is contained in:
2026-10-12 00:45:24 +02:00
parent 1ca737e489
commit 2330c17e3b
21 changed files with 276 additions and 277 deletions

View File

@@ -65,16 +65,14 @@ pub fn build(b: *std.Build) !void {
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| { run_cmd.addPassthruArgs();
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the game"); const run_step = b.step("run", "Run the game");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
} }
fn addShaders(b: *std.Build, exe_mod: *std.Build.Module) !void { fn addShaders(b: *std.Build, exe_mod: *std.Build.Module) !void {
var dir = try b.build_root.handle.openDir(b.graph.io, "assets/shaders", .{ .iterate = true }); var dir = try b.root.openDir(b.graph.io, "assets/shaders", .{ .iterate = true });
defer dir.close(b.graph.io); defer dir.close(b.graph.io);
var it = dir.iterateAssumeFirstIteration(); var it = dir.iterateAssumeFirstIteration();

View File

@@ -16,8 +16,7 @@
.hash = "vulkan-0.0.0-r7Ytx4yGAwDZf0XsT6_L1ol_XUAkyOgOyBqamf8begA0", .hash = "vulkan-0.0.0-r7Ytx4yGAwDZf0XsT6_L1ol_XUAkyOgOyBqamf8begA0",
}, },
.zglfw = .{ .zglfw = .{
.url = "git+https://github.com/zig-gamedev/zglfw.git#51003c105d23db378bb59ce415a387b22f1b0892", .path = "vendor/zglfw",
.hash = "zglfw-0.10.0-dev-zgVDNIy4IQDJNRy4jrP1As-SZxfJpuWhU1iJ-wBab_VD",
}, },
}, },

2
castle

Submodule castle updated: 8a8b84a730...40c54c9a99

View File

@@ -82,7 +82,7 @@ pub fn init(init_info: InitInfo) !Chunk {
engine.setObjectName(object_buffer.device_memory, "DM Chunk[{d}]", .{chunk_id}); engine.setObjectName(object_buffer.device_memory, "DM Chunk[{d}]", .{chunk_id});
return .{ return .{
.blocks = .{.{[_]Blocks.Id{.air} ** chunk_size} ** chunk_size} ** chunk_size, .blocks = @splat(@splat(@splat(.air))),
.origin = init_info.origin, .origin = init_info.origin,
.descriptor_set = descriptor_set, .descriptor_set = descriptor_set,
.object_buffer = object_buffer, .object_buffer = object_buffer,
@@ -94,7 +94,7 @@ pub fn init(init_info: InitInfo) !Chunk {
pub fn deinit(self: *Chunk, descriptor_pool: vk.DescriptorPool) void { pub fn deinit(self: *Chunk, descriptor_pool: vk.DescriptorPool) void {
const engine = ctx.engine; const engine = ctx.engine;
std.log.scoped(.deinit).debug("Deinitializing chunk {d} with {s}#{X}", .{ self.chunk_id, @typeName(vk.DescriptorPool), @intFromEnum(descriptor_pool) }); std.log.scoped(.deinit).debug("Deinitializing chunk {d} with {s}#{X}", .{ self.chunk_id, @typeName(vk.DescriptorPool), @backingInt(descriptor_pool) });
self.object_buffer.deinit(); self.object_buffer.deinit();
engine.freeDescriptorSet(descriptor_pool, self.descriptor_set); engine.freeDescriptorSet(descriptor_pool, self.descriptor_set);
@@ -117,9 +117,9 @@ pub fn refresh(self: *Chunk, blocks: *const Blocks, neighbors: Neighbors) !void
const block: *const Blocks.Definition = &blocks.array.items[id.toInt()]; const block: *const Blocks.Definition = &blocks.array.items[id.toInt()];
const origin = vm.Vector3.add(self.origin, .init(fx, fy, fz)); const origin = vm.Vector3.add(self.origin, .init(fx, fy, fz));
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| { inline for (@typeInfo(voxels.Orientation).@"enum".field_names) |field_name| {
const side = @field(voxels.Orientation, field.name); const side = @field(voxels.Orientation, field_name);
const wall: Blocks.Definition.Wall = @field(block.walls, field.name); const wall: Blocks.Definition.Wall = @field(block.walls, field_name);
if (wall.material != .empty and self.getOpposite(side, ix, iy, iz, blocks, neighbors) == .empty) { if (wall.material != .empty and self.getOpposite(side, ix, iy, iz, blocks, neighbors) == .empty) {
const matrix = getMatrix(side, origin); const matrix = getMatrix(side, origin);
try uniforms.append(allocator_frame, .{ try uniforms.append(allocator_frame, .{

View File

@@ -107,38 +107,38 @@ pub fn init() !Game {
.binding = 0, .binding = 0,
.descriptor_type = .uniform_buffer, .descriptor_type = .uniform_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 2, .binding = 2,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 3, .binding = 3,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 4, .binding = 4,
.descriptor_type = .sampler, .descriptor_type = .sampler,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
.immutable_samplers = &.{sampler}, .immutable_samplers = &.{sampler},
}, },
.{ .{
.binding = 5, .binding = 5,
.descriptor_type = .sampled_image, .descriptor_type = .sampled_image,
.descriptor_count = Textures.max_textures, .descriptor_count = Textures.max_textures,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
}, },
}); });
@@ -151,7 +151,7 @@ pub fn init() !Game {
.binding = 0, .binding = 0,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
}, },
}); });
@@ -272,12 +272,12 @@ pub fn init() !Game {
const pipeline = try engine.createGraphicsPipeline(.{ const pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{ .stages = &.{
.{ .{
.stage = .{ .vertex_bit = true }, .stage = .{ .vertex = true },
.module = shader, .module = shader,
.name = "vertexMain", .name = "vertexMain",
}, },
.{ .{
.stage = .{ .fragment_bit = true }, .stage = .{ .fragment = true },
.module = shader, .module = shader,
.name = "fragmentMain", .name = "fragmentMain",
}, },
@@ -329,7 +329,7 @@ pub fn init() !Game {
.depth_clamp_enable = .false, .depth_clamp_enable = .false,
.rasterizer_discard_enable = .false, .rasterizer_discard_enable = .false,
.polygon_mode = .fill, .polygon_mode = .fill,
.cull_mode = .{ .back_bit = true }, .cull_mode = .{ .back = true },
.front_face = .counter_clockwise, .front_face = .counter_clockwise,
.depth_bias_enable = .false, .depth_bias_enable = .false,
.depth_bias_constant_factor = 0, .depth_bias_constant_factor = 0,
@@ -338,7 +338,7 @@ pub fn init() !Game {
.line_width = 1, .line_width = 1,
}, },
.multisample_state = .{ .multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true }, .rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false, .sample_shading_enable = .false,
.min_sample_shading = 1, .min_sample_shading = 1,
.alpha_to_coverage_enable = .false, .alpha_to_coverage_enable = .false,
@@ -384,10 +384,10 @@ pub fn init() !Game {
.dst_alpha_blend_factor = .zero, .dst_alpha_blend_factor = .zero,
.alpha_blend_op = .add, .alpha_blend_op = .add,
.color_write_mask = .{ .color_write_mask = .{
.r_bit = true, .r = true,
.g_bit = true, .g = true,
.b_bit = true, .b = true,
.a_bit = true, .a = true,
}, },
}, },
}, },
@@ -407,7 +407,7 @@ pub fn init() !Game {
const descriptor_pool = try engine.createDescriptorPool(.{ const descriptor_pool = try engine.createDescriptorPool(.{
.flags = .{ .flags = .{
.free_descriptor_set_bit = true, .free_descriptor_set = true,
}, },
.max_sets = 1 + chunk_descriptor_pool, .max_sets = 1 + chunk_descriptor_pool,
.pool_sizes = &.{ .pool_sizes = &.{
@@ -627,7 +627,7 @@ pub fn init() !Game {
var skybox = try Skybox.load("skybox.hdr", 512, global_uniforms.buffer); var skybox = try Skybox.load("skybox.hdr", 512, global_uniforms.buffer);
errdefer skybox.deinit(); errdefer skybox.deinit();
const font = &fonts.array.items[@intFromEnum(font_id)]; const font = &fonts.array.items[@backingInt(font_id)];
// TODO This coupling is not elegant - the game must provide the GUI with // TODO This coupling is not elegant - the game must provide the GUI with
// uniform buffer for globals. Maybe GUI should just use their own global // uniform buffer for globals. Maybe GUI should just use their own global
@@ -669,7 +669,7 @@ pub fn init() !Game {
.{ .{
.dst_set = gui.text_descriptor_set, .dst_set = gui.text_descriptor_set,
.dst_binding = 2, .dst_binding = 2,
.dst_array_element = @intFromEnum(font_id), .dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_infos = .{ .descriptor_infos = .{
.buffer = &.{ .buffer = &.{
@@ -684,7 +684,7 @@ pub fn init() !Game {
.{ .{
.dst_set = gui.text_descriptor_set, .dst_set = gui.text_descriptor_set,
.dst_binding = 3, .dst_binding = 3,
.dst_array_element = @intFromEnum(font_id), .dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_infos = .{ .descriptor_infos = .{
.buffer = &.{ .buffer = &.{
@@ -699,7 +699,7 @@ pub fn init() !Game {
.{ .{
.dst_set = gui.text_descriptor_set, .dst_set = gui.text_descriptor_set,
.dst_binding = 4, .dst_binding = 4,
.dst_array_element = @intFromEnum(font_id), .dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_infos = .{ .descriptor_infos = .{
.buffer = &.{ .buffer = &.{
@@ -955,14 +955,14 @@ fn render(self: *Game) !void {
const swapchain_image = swapchain.getCurrentSwapchainImage(); const swapchain_image = swapchain.getCurrentSwapchainImage();
command_buffer.pipelineBarrier(.{ command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true }, .src_stage_mask = .{ .color_attachment_output = true },
.dst_stage_mask = .{ .color_attachment_output_bit = true }, .dst_stage_mask = .{ .color_attachment_output = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{}, .src_access_mask = .{},
.dst_access_mask = .{ .dst_access_mask = .{
.color_attachment_read_bit = true, .color_attachment_read = true,
.color_attachment_write_bit = true, .color_attachment_write = true,
}, },
.old_layout = .undefined, .old_layout = .undefined,
.new_layout = .color_attachment_optimal, .new_layout = .color_attachment_optimal,
@@ -970,7 +970,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image, .image = swapchain_image.image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -981,15 +981,15 @@ fn render(self: *Game) !void {
}); });
command_buffer.pipelineBarrier(.{ command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .late_fragment_tests_bit = true }, .src_stage_mask = .{ .late_fragment_tests = true },
.dst_stage_mask = .{ .early_fragment_tests_bit = true }, .dst_stage_mask = .{ .early_fragment_tests = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{ .src_access_mask = .{
.depth_stencil_attachment_write_bit = true, .depth_stencil_attachment_write = true,
}, },
.dst_access_mask = .{ .dst_access_mask = .{
.depth_stencil_attachment_write_bit = true, .depth_stencil_attachment_write = true,
}, },
.old_layout = .undefined, .old_layout = .undefined,
.new_layout = .depth_stencil_attachment_optimal, .new_layout = .depth_stencil_attachment_optimal,
@@ -997,7 +997,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain.depth_texture.?.image, .image = swapchain.depth_texture.?.image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .depth_bit = true }, .aspect_mask = .{ .depth = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -1079,11 +1079,11 @@ fn render(self: *Game) !void {
command_buffer.endRendering(); command_buffer.endRendering();
command_buffer.pipelineBarrier(.{ command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true }, .src_stage_mask = .{ .color_attachment_output = true },
.dst_stage_mask = .{ .bottom_of_pipe_bit = true }, .dst_stage_mask = .{ .bottom_of_pipe = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{ .color_attachment_write_bit = true }, .src_access_mask = .{ .color_attachment_write = true },
.dst_access_mask = .{}, .dst_access_mask = .{},
.old_layout = .color_attachment_optimal, .old_layout = .color_attachment_optimal,
.new_layout = .present_src_khr, .new_layout = .present_src_khr,
@@ -1091,7 +1091,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image, .image = swapchain_image.image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -1108,7 +1108,7 @@ fn render(self: *Game) !void {
.wait_semaphores = &.{ .wait_semaphores = &.{
.{ .{
.semaphore = self.global_uniforms_transfer_semaphores[swapchain.image_index.?], .semaphore = self.global_uniforms_transfer_semaphores[swapchain.image_index.?],
.stage_flags = .{ .vertex_shader_bit = true }, .stage_flags = .{ .vertex_shader = true },
}, },
}, },
}) catch |err| switch (err) { }) catch |err| switch (err) {

View File

@@ -229,9 +229,9 @@ pub fn onKeyDown(self: *Player, key: glfw.Key) void {
self.y_input.onKeyDown(key); self.y_input.onKeyDown(key);
self.z_input.onKeyDown(key); self.z_input.onKeyDown(key);
const key_code = @intFromEnum(key); const key_code = @backingInt(key);
if (key_code >= @intFromEnum(glfw.Key.one) and key_code <= @intFromEnum(glfw.Key.nine)) { if (key_code >= @backingInt(glfw.Key.one) and key_code <= @backingInt(glfw.Key.nine)) {
self.block_index = @intCast(key_code - @intFromEnum(glfw.Key.one)); self.block_index = @intCast(key_code - @backingInt(glfw.Key.one));
} }
} }
@@ -437,21 +437,21 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
gui.printLine("X {s}", .{formatHexCoord(self.position_sv.x, &number_buf)}, .{ gui.printLine("X {s}", .{formatHexCoord(self.position_sv.x, &number_buf)}, .{
.position_sspx = .init(margin, margin + font_size), .position_sspx = .init(margin, margin + font_size),
.font_id = @enumFromInt(0), .font_id = game.font,
.cap_height_px = font_size, .cap_height_px = font_size,
.color = .init(1, 1, 1, 1), .color = .init(1, 1, 1, 1),
}); });
gui.printLine("Y {s}", .{formatHexCoord(self.position_sv.y, &number_buf)}, .{ gui.printLine("Y {s}", .{formatHexCoord(self.position_sv.y, &number_buf)}, .{
.position_sspx = .init(margin, 2 * (margin + font_size)), .position_sspx = .init(margin, 2 * (margin + font_size)),
.font_id = @enumFromInt(0), .font_id = game.font,
.cap_height_px = font_size, .cap_height_px = font_size,
.color = .init(1, 1, 1, 1), .color = .init(1, 1, 1, 1),
}); });
gui.printLine("Z {s}", .{formatHexCoord(self.position_sv.z, &number_buf)}, .{ gui.printLine("Z {s}", .{formatHexCoord(self.position_sv.z, &number_buf)}, .{
.position_sspx = .init(margin, 3 * (margin + font_size)), .position_sspx = .init(margin, 3 * (margin + font_size)),
.font_id = @enumFromInt(0), .font_id = game.font,
.cap_height_px = font_size, .cap_height_px = font_size,
.color = .init(1, 1, 1, 1), .color = .init(1, 1, 1, 1),
}); });
@@ -487,10 +487,10 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
std.log.err("Error while rendering hotbar block {s}: {}", .{ filename, err }); std.log.err("Error while rendering hotbar block {s}: {}", .{ filename, err });
continue; continue;
}; };
const definition = &game.blocks.array.items[@intFromEnum(id)]; const definition = &game.blocks.array.items[@backingInt(id)];
const material_id = definition.walls.positive_z.material; const material_id = definition.walls.positive_z.material;
const material = &materials.array.items[@intFromEnum(material_id)]; const material = &materials.array.items[@backingInt(material_id)];
if (i == self.block_index) { if (i == self.block_index) {
gui.pushBox(.{ gui.pushBox(.{
@@ -527,9 +527,10 @@ fn formatHexCoord(coord: i32, buf: *[9]u8) []const u8 {
} }
fn resetAllButtons(self: *Player) void { fn resetAllButtons(self: *Player) void {
inline for (@typeInfo(Player).@"struct".fields) |field| { const type_info = @typeInfo(Player).@"struct";
if (field.type == Button) { inline for (type_info.field_types, type_info.field_names) |field_type, field_name| {
@field(self, field.name).reset(); if (field_type == Button) {
@field(self, field_name).reset();
} }
} }
} }

View File

@@ -21,26 +21,27 @@ pub const Id = enum(u16) {
/// Cast an integer into an ID. This can produce an invalid ID. /// Cast an integer into an ID. This can produce an invalid ID.
pub fn fromInt(value: u16) Id { pub fn fromInt(value: u16) Id {
return @enumFromInt(value); std.debug.assert(value < max_blocks);
return @fromBackingInt(value);
} }
/// Cast an index into an ID. This can produce an invalid ID. The caller /// Cast an index into an ID. This can produce an invalid ID. The caller
/// asserts that the index is not greater than the max ID value. /// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id { pub fn fromIndex(index: usize) Id {
std.debug.assert(index < max_blocks); std.debug.assert(index < max_blocks);
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an index into an ID. This can produce an invalid ID. Returns an /// Cast an index into an ID. This can produce an invalid ID. Returns an
/// error if the index is greater than the max ID value. /// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id { pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_blocks) return error.Overflow; if (index >= max_blocks) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an ID into an integer. /// Cast an ID into an integer.
pub fn toInt(self: Id) u16 { pub fn toInt(self: Id) u16 {
return @intFromEnum(self); return @backingInt(self);
} }
}; };
@@ -265,10 +266,10 @@ fn loadBlock(filename: []const u8) !Definition {
break :blk .{ break :blk .{
.walls = walls: { .walls = walls: {
var ret: Definition.Walls = undefined; var ret: Definition.Walls = undefined;
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| { inline for (@typeInfo(voxels.Orientation).@"enum".field_names) |field_name| {
@field(ret, field.name) = .{ @field(ret, field_name) = .{
.material = try materials.getOrLoad(@field(walls, field.name).material), .material = try materials.getOrLoad(@field(walls, field_name).material),
.transform = @field(walls, field.name).transform, .transform = @field(walls, field_name).transform,
}; };
} }
break :walls ret; break :walls ret;

View File

@@ -16,19 +16,19 @@ pub const Atom = enum(u16) {
/// Cast an integer into an atom. This can produce an invalid atom. /// Cast an integer into an atom. This can produce an invalid atom.
pub fn fromInt(value: u16) Atom { pub fn fromInt(value: u16) Atom {
return @enumFromInt(value); return @fromBackingInt(value);
} }
/// Cast an index into an atom. This can produce an invalid atom. The caller /// Cast an index into an atom. This can produce an invalid atom. The caller
/// asserts that the index is not greater than the max atom value. /// asserts that the index is not greater than the max atom value.
pub fn fromIndex(index: usize) Atom { pub fn fromIndex(index: usize) Atom {
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an index into an atom. This can produce an invalid atom. Returns an /// Cast an index into an atom. This can produce an invalid atom. Returns an
/// error if the index is greater than the max atom value. /// error if the index is greater than the max atom value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Atom { pub fn fromIndexSafe(index: usize) error{Overflow}!Atom {
return @enumFromInt(std.math.cast(u16, index) orelse return error.Overflow); return @fromBackingInt(std.math.cast(u16, index) orelse return error.Overflow);
} }
/// Turn a string into an atom. Returns either an existing atom or makes a /// Turn a string into an atom. Returns either an existing atom or makes a
@@ -52,7 +52,7 @@ pub const Atom = enum(u16) {
const atom = Atom.fromIndexSafe(atoms.array.items.len) catch |err| switch (err) { const atom = Atom.fromIndexSafe(atoms.array.items.len) catch |err| switch (err) {
error.Overflow => return error.OutOfAtoms, error.Overflow => return error.OutOfAtoms,
}; };
const owned_string = try allocator_persistent.dupeZ(u8, string); const owned_string = try allocator_persistent.dupeSentinel(u8, string, 0);
atoms.map.putAssumeCapacityNoClobber(owned_string, atom); atoms.map.putAssumeCapacityNoClobber(owned_string, atom);
atoms.array.appendAssumeCapacity(owned_string); atoms.array.appendAssumeCapacity(owned_string);
@@ -76,7 +76,7 @@ pub const Atom = enum(u16) {
/// Cast an atom into an integer. /// Cast an atom into an integer.
pub fn toInt(self: Atom) u16 { pub fn toInt(self: Atom) u16 {
return @intFromEnum(self); return @backingInt(self);
} }
/// Cast an atom into a string. The caller asserts that the atom is valid. /// Cast an atom into a string. The caller asserts that the atom is valid.

View File

@@ -168,7 +168,7 @@ pub const VertexBufferBinding = struct {
pub fn beginCommandBuffer(self: CommandBuffer) !void { pub fn beginCommandBuffer(self: CommandBuffer) !void {
try self.proxy.beginCommandBuffer(&.{ try self.proxy.beginCommandBuffer(&.{
.flags = .{ .flags = .{
.one_time_submit_bit = true, .one_time_submit = true,
}, },
}); });
} }

View File

@@ -87,7 +87,7 @@ transfer_command_pool: vk.CommandPool,
prng_ptr: *std.Random.Pcg, prng_ptr: *std.Random.Pcg,
random: std.Random, random: std.Random,
const debug = @import("builtin").mode == .Debug; const debug = @import("builtin").mode == .debug;
const vk_version: vk.Version = vk.makeApiVersion( const vk_version: vk.Version = vk.makeApiVersion(
0, 0,
c.app_version.major, c.app_version.major,
@@ -96,15 +96,15 @@ const vk_version: vk.Version = vk.makeApiVersion(
); );
const vk_debug_utils_messenger_create_info: vk.DebugUtilsMessengerCreateInfoEXT = .{ const vk_debug_utils_messenger_create_info: vk.DebugUtilsMessengerCreateInfoEXT = .{
.message_severity = .{ .message_severity = .{
.verbose_bit_ext = false, .verbose_ext = false,
.info_bit_ext = false, .info_ext = false,
.warning_bit_ext = true, .warning_ext = true,
.error_bit_ext = true, .error_ext = true,
}, },
.message_type = .{ .message_type = .{
.general_bit_ext = true, .general_ext = true,
.validation_bit_ext = true, .validation_ext = true,
.performance_bit_ext = true, .performance_ext = true,
}, },
.pfn_user_callback = &debugUtilsMessengerCallback, .pfn_user_callback = &debugUtilsMessengerCallback,
.p_user_data = null, .p_user_data = null,
@@ -230,7 +230,7 @@ pub fn init() !*Engine {
const transfer_queue_index = queue_allocator.allocateQueueIndex(transfer_queue_family); const transfer_queue_index = queue_allocator.allocateQueueIndex(transfer_queue_family);
const presentation_queue_index = queue_allocator.allocateQueueIndex(presentation_queue_family); const presentation_queue_index = queue_allocator.allocateQueueIndex(presentation_queue_family);
const queue_priorities = [_]f32{1.0} ** max_queues; const queue_priorities: [max_queues]f32 = @splat(1.0);
for (queue_allocator.queueInUse(), 0..) |count, queue_family| { for (queue_allocator.queueInUse(), 0..) |count, queue_family| {
if (count == 0) continue; if (count == 0) continue;
@@ -315,19 +315,19 @@ pub fn init() !*Engine {
// --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------ // --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------
const graphics_command_pool = try device.createCommandPool(&.{ const graphics_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true }, .flags = .{ .transient = true },
.queue_family_index = queue_allocations.graphics_queue.family, .queue_family_index = queue_allocations.graphics_queue.family,
}, ctx.vk_allocator.capture()); }, ctx.vk_allocator.capture());
errdefer device.destroyCommandPool(graphics_command_pool, ctx.vk_allocator.capture()); errdefer device.destroyCommandPool(graphics_command_pool, ctx.vk_allocator.capture());
const compute_command_pool = try device.createCommandPool(&.{ const compute_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true }, .flags = .{ .transient = true },
.queue_family_index = queue_allocations.compute_queue.family, .queue_family_index = queue_allocations.compute_queue.family,
}, ctx.vk_allocator.capture()); }, ctx.vk_allocator.capture());
errdefer device.destroyCommandPool(compute_command_pool, ctx.vk_allocator.capture()); errdefer device.destroyCommandPool(compute_command_pool, ctx.vk_allocator.capture());
const transfer_command_pool = try device.createCommandPool(&.{ const transfer_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true }, .flags = .{ .transient = true },
.queue_family_index = queue_allocations.transfer_queue.family, .queue_family_index = queue_allocations.transfer_queue.family,
}, ctx.vk_allocator.capture()); }, ctx.vk_allocator.capture());
errdefer device.destroyCommandPool(transfer_command_pool, ctx.vk_allocator.capture()); errdefer device.destroyCommandPool(transfer_command_pool, ctx.vk_allocator.capture());
@@ -499,10 +499,10 @@ pub fn setObjectName(self: *const Engine, handle: anytype, comptime fmt: []const
else => @compileError("Unsupported type " ++ type_name ++ " for setting and object name"), else => @compileError("Unsupported type " ++ type_name ++ " for setting and object name"),
}; };
const handle_value: u64 = @intFromEnum(handle); const handle_value: u64 = @backingInt(handle);
var buf: [256]u8 = undefined; var buf: [256]u8 = undefined;
const name = std.fmt.bufPrintZ(&buf, fmt, args) catch |err| { const name = std.mem.printSentinel(&buf, fmt, args, 0) catch |err| {
std.log.debug("Failed to set object name for {s}#{X}: {s}", .{ type_name, handle_value, @errorName(err) }); std.log.debug("Failed to set object name for {s}#{X}: {s}", .{ type_name, handle_value, @errorName(err) });
return; return;
}; };
@@ -592,18 +592,18 @@ fn debugUtilsMessengerCallback(
const log = std.log.scoped(.vulkan); const log = std.log.scoped(.vulkan);
const message = if (maybe_callback_data) |callback_data| callback_data.p_message orelse return .false else return .false; const message = if (maybe_callback_data) |callback_data| callback_data.p_message orelse return .false else return .false;
const type_name = if (message_type.general_bit_ext) "general" else if (message_type.validation_bit_ext) "validation" else if (message_type.performance_bit_ext) "performance" else if (message_type.device_address_binding_bit_ext) "device_address_binding" else "unknown"; const type_name = if (message_type.general_ext) "general" else if (message_type.validation_ext) "validation" else if (message_type.performance_ext) "performance" else if (message_type.device_address_binding_ext) "device_address_binding" else "unknown";
const format = "[{s}] {s}"; const format = "[{s}] {s}";
const args = .{ type_name, message }; const args = .{ type_name, message };
if (severity.error_bit_ext) { if (severity.error_ext) {
log.err(format, args); log.err(format, args);
} else if (severity.warning_bit_ext) { } else if (severity.warning_ext) {
log.warn(format, args); log.warn(format, args);
} else if (severity.info_bit_ext) { } else if (severity.info_ext) {
log.info(format, args); log.info(format, args);
} else if (severity.verbose_bit_ext) { } else if (severity.verbose_ext) {
log.debug(format, args); log.debug(format, args);
} }
@@ -611,10 +611,10 @@ fn debugUtilsMessengerCallback(
} }
fn findGraphicsQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 { fn findGraphicsQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 {
// Look for the first family that has the `graphics_bit` set. // Look for the first family that has the `graphics` bit set.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const graphics_bit = queue_family_properties.queue_flags.graphics_bit; const graphics_bit = queue_family_properties.queue_flags.graphics;
if (graphics_bit) { if (graphics_bit) {
return @intCast(i); return @intCast(i);
} }
@@ -624,21 +624,21 @@ fn findGraphicsQueueFamily(queue_families_properties: []const vk.QueueFamilyProp
} }
fn findComputeQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 { fn findComputeQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 {
// Look for the first family that has the `compute_bit` set, but not // Look for the first family that has the `compute` bit set, but not
// `graphics_bit`. // `graphics` bit.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const compute_bit = queue_family_properties.queue_flags.compute_bit; const compute_bit = queue_family_properties.queue_flags.compute;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit; const graphics_bit = queue_family_properties.queue_flags.graphics;
if (compute_bit and !graphics_bit) { if (compute_bit and !graphics_bit) {
return @intCast(i); return @intCast(i);
} }
} }
// Look for the first family that has the `compute_bit` set. // Look for the first family that has the `compute` bit set.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const compute_bit = queue_family_properties.queue_flags.compute_bit; const compute_bit = queue_family_properties.queue_flags.compute;
if (compute_bit) { if (compute_bit) {
return @intCast(i); return @intCast(i);
} }
@@ -648,28 +648,28 @@ fn findComputeQueueFamily(queue_families_properties: []const vk.QueueFamilyPrope
} }
fn findTransferQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 { fn findTransferQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 {
// Look for the first family that has the `transfer_bit` set, but neither // Look for the first family that has the `transfer` bit set, but neither
// `graphics_bit` or `compute_bit`. // `graphics` bit or `compute` bit.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const transfer_bit = queue_family_properties.queue_flags.transfer_bit; const transfer_bit = queue_family_properties.queue_flags.transfer;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit; const graphics_bit = queue_family_properties.queue_flags.graphics;
const compute_bit = queue_family_properties.queue_flags.compute_bit; const compute_bit = queue_family_properties.queue_flags.compute;
if (transfer_bit and !graphics_bit and !compute_bit) { if (transfer_bit and !graphics_bit and !compute_bit) {
return @intCast(i); return @intCast(i);
} }
} }
// Look for the first family that has either `transfer_bit`, `graphics_bit` // Look for the first family that has either `transfer_` bit, `graphics` bit
// or `compute_bit` set. // or `compute` bit set.
// NOTE `graphics_bit` or `compute_bit` imply `transfer_bit`, even if not // NOTE `graphics` bit or `compute` bit imply `transfer` bit, even if not
// set explicitly. // set explicitly.
for (queue_families_properties, 0..) |queue_family_properties, i| { for (queue_families_properties, 0..) |queue_family_properties, i| {
const transfer_bit = queue_family_properties.queue_flags.transfer_bit; const transfer_bit = queue_family_properties.queue_flags.transfer;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit; const graphics_bit = queue_family_properties.queue_flags.graphics;
const compute_bit = queue_family_properties.queue_flags.compute_bit; const compute_bit = queue_family_properties.queue_flags.compute;
if (transfer_bit or graphics_bit or compute_bit) { if (transfer_bit or graphics_bit or compute_bit) {
return @intCast(i); return @intCast(i);
} }

View File

@@ -17,12 +17,12 @@ pub const Usage = enum {
pub fn asBufferUsageFlags(self: Usage) vk.BufferUsageFlags { pub fn asBufferUsageFlags(self: Usage) vk.BufferUsageFlags {
return switch (self) { return switch (self) {
.uniform => .{ .transfer_dst_bit = true, .uniform_buffer_bit = true }, .uniform => .{ .transfer_dst = true, .uniform_buffer = true },
.storage => .{ .transfer_dst_bit = true, .storage_buffer_bit = true }, .storage => .{ .transfer_dst = true, .storage_buffer = true },
.index => .{ .transfer_dst_bit = true, .index_buffer_bit = true }, .index => .{ .transfer_dst = true, .index_buffer = true },
.vertex => .{ .transfer_dst_bit = true, .vertex_buffer_bit = true }, .vertex => .{ .transfer_dst = true, .vertex_buffer = true },
.indirect => .{ .transfer_dst_bit = true, .indirect_buffer_bit = true }, .indirect => .{ .transfer_dst = true, .indirect_buffer = true },
.staging => .{ .transfer_src_bit = true }, .staging => .{ .transfer_src = true },
}; };
} }
}; };
@@ -70,8 +70,8 @@ pub fn GenericBuffer(comptime T: type) type {
const memory_requirements = engine.getBufferMemoryRequirements(buffer); const memory_requirements = engine.getBufferMemoryRequirements(buffer);
const device_memory = try engine.allocate(memory_requirements, .{ const device_memory = try engine.allocate(memory_requirements, .{
.device_local_bit = !init_info.mappable, .device_local = !init_info.mappable,
.host_visible_bit = init_info.mappable, .host_visible = init_info.mappable,
}); });
errdefer engine.freeMemory(device_memory); errdefer engine.freeMemory(device_memory);
if (init_info.name) |name| { if (init_info.name) |name| {

View File

@@ -154,13 +154,13 @@ pub fn init() !*Gui {
.binding = 0, .binding = 0,
.descriptor_type = .uniform_buffer, .descriptor_type = .uniform_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
}, },
}); });
@@ -182,12 +182,12 @@ pub fn init() !*Gui {
const box_pipeline = try engine.createGraphicsPipeline(.{ const box_pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{ .stages = &.{
.{ .{
.stage = .{ .vertex_bit = true }, .stage = .{ .vertex = true },
.module = box_shader, .module = box_shader,
.name = "vertexMain", .name = "vertexMain",
}, },
.{ .{
.stage = .{ .fragment_bit = true }, .stage = .{ .fragment = true },
.module = box_shader, .module = box_shader,
.name = "fragmentMain", .name = "fragmentMain",
}, },
@@ -214,7 +214,7 @@ pub fn init() !*Gui {
.line_width = 1, .line_width = 1,
}, },
.multisample_state = .{ .multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true }, .rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false, .sample_shading_enable = .false,
.min_sample_shading = 1, .min_sample_shading = 1,
.alpha_to_coverage_enable = .false, .alpha_to_coverage_enable = .false,
@@ -260,10 +260,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha, .dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add, .alpha_blend_op = .add,
.color_write_mask = .{ .color_write_mask = .{
.r_bit = true, .r = true,
.g_bit = true, .g = true,
.b_bit = true, .b = true,
.a_bit = true, .a = true,
}, },
}, },
}, },
@@ -287,31 +287,31 @@ pub fn init() !*Gui {
.binding = 0, .binding = 0,
.descriptor_type = .uniform_buffer, .descriptor_type = .uniform_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 2, .binding = 2,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = Fonts.max_fonts, .descriptor_count = Fonts.max_fonts,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 3, .binding = 3,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = Fonts.max_fonts, .descriptor_count = Fonts.max_fonts,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 4, .binding = 4,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = Fonts.max_fonts, .descriptor_count = Fonts.max_fonts,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
}, },
}); });
@@ -333,12 +333,12 @@ pub fn init() !*Gui {
const text_pipeline = try engine.createGraphicsPipeline(.{ const text_pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{ .stages = &.{
.{ .{
.stage = .{ .vertex_bit = true }, .stage = .{ .vertex = true },
.module = text_shader, .module = text_shader,
.name = "vertexMain", .name = "vertexMain",
}, },
.{ .{
.stage = .{ .fragment_bit = true }, .stage = .{ .fragment = true },
.module = text_shader, .module = text_shader,
.name = "fragmentMain", .name = "fragmentMain",
}, },
@@ -365,7 +365,7 @@ pub fn init() !*Gui {
.line_width = 1, .line_width = 1,
}, },
.multisample_state = .{ .multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true }, .rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false, .sample_shading_enable = .false,
.min_sample_shading = 1, .min_sample_shading = 1,
.alpha_to_coverage_enable = .false, .alpha_to_coverage_enable = .false,
@@ -411,10 +411,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha, .dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add, .alpha_blend_op = .add,
.color_write_mask = .{ .color_write_mask = .{
.r_bit = true, .r = true,
.g_bit = true, .g = true,
.b_bit = true, .b = true,
.a_bit = true, .a = true,
}, },
}, },
}, },
@@ -438,26 +438,26 @@ pub fn init() !*Gui {
.binding = 0, .binding = 0,
.descriptor_type = .uniform_buffer, .descriptor_type = .uniform_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .storage_buffer, .descriptor_type = .storage_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
.{ .{
.binding = 2, .binding = 2,
.descriptor_type = .sampler, .descriptor_type = .sampler,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
.immutable_samplers = &.{sampler}, .immutable_samplers = &.{sampler},
}, },
.{ .{
.binding = 3, .binding = 3,
.descriptor_type = .sampled_image, .descriptor_type = .sampled_image,
.descriptor_count = Textures.max_textures, .descriptor_count = Textures.max_textures,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true }, .stage_flags = .{ .vertex = true, .fragment = true },
}, },
}, },
}); });
@@ -479,12 +479,12 @@ pub fn init() !*Gui {
const image_pipeline = try engine.createGraphicsPipeline(.{ const image_pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{ .stages = &.{
.{ .{
.stage = .{ .vertex_bit = true }, .stage = .{ .vertex = true },
.module = image_shader, .module = image_shader,
.name = "vertexMain", .name = "vertexMain",
}, },
.{ .{
.stage = .{ .fragment_bit = true }, .stage = .{ .fragment = true },
.module = image_shader, .module = image_shader,
.name = "fragmentMain", .name = "fragmentMain",
}, },
@@ -511,7 +511,7 @@ pub fn init() !*Gui {
.line_width = 1, .line_width = 1,
}, },
.multisample_state = .{ .multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true }, .rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false, .sample_shading_enable = .false,
.min_sample_shading = 1, .min_sample_shading = 1,
.alpha_to_coverage_enable = .false, .alpha_to_coverage_enable = .false,
@@ -557,10 +557,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha, .dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add, .alpha_blend_op = .add,
.color_write_mask = .{ .color_write_mask = .{
.r_bit = true, .r = true,
.g_bit = true, .g = true,
.b_bit = true, .b = true,
.a_bit = true, .a = true,
}, },
}, },
}, },
@@ -770,7 +770,7 @@ pub fn printLine(self: *Gui, comptime fmt: []const u8, fmt_args: anytype, print_
return; return;
}; };
const font = fonts.array.items[@intFromEnum(print_args.font_id)]; const font = fonts.array.items[@backingInt(print_args.font_id)];
const font_size_px = print_args.cap_height_px / font.cap_height_em; const font_size_px = print_args.cap_height_px / font.cap_height_em;
const utf8_view = std.unicode.Utf8View.init(text) catch { const utf8_view = std.unicode.Utf8View.init(text) catch {

View File

@@ -30,26 +30,27 @@ pub const Id = enum(u16) {
/// Cast an integer into an ID. This can produce an invalid ID. /// Cast an integer into an ID. This can produce an invalid ID.
pub fn fromInt(value: u16) Id { pub fn fromInt(value: u16) Id {
return @enumFromInt(value); std.debug.assert(value < max_materials);
return @fromBackingInt(value);
} }
/// Cast an index into an ID. This can produce an invalid ID. The caller /// Cast an index into an ID. This can produce an invalid ID. The caller
/// asserts that the index is not greater than the max ID value. /// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id { pub fn fromIndex(index: usize) Id {
std.debug.assert(index < max_materials); std.debug.assert(index < max_materials);
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an index into an ID. This can produce an invalid ID. Returns an /// Cast an index into an ID. This can produce an invalid ID. Returns an
/// error if the index is greater than the max ID value. /// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id { pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_materials) return error.Overflow; if (index >= max_materials) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an ID into an integer. /// Cast an ID into an integer.
pub fn toInt(self: Id) u16 { pub fn toInt(self: Id) u16 {
return @intFromEnum(self); return @backingInt(self);
} }
}; };
@@ -116,7 +117,7 @@ pub fn init() !*Materials {
materials.array.appendSliceAssumeCapacity(&material_data); materials.array.appendSliceAssumeCapacity(&material_data);
try materials.material_buffer.writeSlice(&material_data); try materials.material_buffer.writeSlice(&material_data);
std.debug.assert(materials.array.items.len == @typeInfo(Id).@"enum".fields.len); std.debug.assert(materials.array.items.len == @typeInfo(Id).@"enum".field_names.len);
return materials; return materials;
} }

View File

@@ -96,11 +96,11 @@ pub fn load(
}, },
.mip_levels = 1, .mip_levels = 1,
.array_layers = 1, .array_layers = 1,
.samples = .{ .@"1_bit" = true }, .samples = .{ .@"1" = true },
.tiling = .optimal, .tiling = .optimal,
.usage = .{ .usage = .{
.transfer_dst_bit = true, .transfer_dst = true,
.sampled_bit = true, .sampled = true,
}, },
.queue_family_indices = &.{ .queue_family_indices = &.{
engine.compute_queue.allocation.family, engine.compute_queue.allocation.family,
@@ -111,7 +111,7 @@ pub fn load(
defer engine.destroyImage(equirect_image); defer engine.destroyImage(equirect_image);
const equirect_memory_requirements = engine.getImageMemoryRequirements(equirect_image); const equirect_memory_requirements = engine.getImageMemoryRequirements(equirect_image);
const equirect_device_memory = try engine.allocate(equirect_memory_requirements, .{ .device_local_bit = true }); const equirect_device_memory = try engine.allocate(equirect_memory_requirements, .{ .device_local = true });
defer engine.freeMemory(equirect_device_memory); defer engine.freeMemory(equirect_device_memory);
try engine.bindImageMemory(equirect_image, equirect_device_memory, 0); try engine.bindImageMemory(equirect_image, equirect_device_memory, 0);
@@ -121,7 +121,7 @@ pub fn load(
.view_type = .@"2d", .view_type = .@"2d",
.format = .r16g16b16a16_sfloat, .format = .r16g16b16a16_sfloat,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -137,19 +137,19 @@ pub fn load(
try transfer_command_buffer.beginCommandBuffer(); try transfer_command_buffer.beginCommandBuffer();
transfer_command_buffer.pipelineBarrier(.{ transfer_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true }, .src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .transfer_bit = true }, .dst_stage_mask = .{ .transfer = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{}, .src_access_mask = .{},
.dst_access_mask = .{ .transfer_write_bit = true }, .dst_access_mask = .{ .transfer_write = true },
.old_layout = .undefined, .old_layout = .undefined,
.new_layout = .transfer_dst_optimal, .new_layout = .transfer_dst_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = equirect_image, .image = equirect_image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -168,7 +168,7 @@ pub fn load(
.buffer_row_length = img.width, .buffer_row_length = img.width,
.buffer_image_height = img.height, .buffer_image_height = img.height,
.image_subresource = .{ .image_subresource = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.mip_level = 0, .mip_level = 0,
.base_array_layer = 0, .base_array_layer = 0,
.layer_count = 1, .layer_count = 1,
@@ -191,19 +191,19 @@ pub fn load(
try transition1_command_buffer.beginCommandBuffer(); try transition1_command_buffer.beginCommandBuffer();
transition1_command_buffer.pipelineBarrier(.{ transition1_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .transfer_bit = true }, .src_stage_mask = .{ .transfer = true },
.dst_stage_mask = .{ .compute_shader_bit = true }, .dst_stage_mask = .{ .compute_shader = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{ .transfer_write_bit = true }, .src_access_mask = .{ .transfer_write = true },
.dst_access_mask = .{ .shader_read_bit = true }, .dst_access_mask = .{ .shader_read = true },
.old_layout = .transfer_dst_optimal, .old_layout = .transfer_dst_optimal,
.new_layout = .shader_read_only_optimal, .new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = equirect_image, .image = equirect_image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -222,7 +222,7 @@ pub fn load(
// --- CREATE CUBEMAP IMAGE ------------------------------------------------ // --- CREATE CUBEMAP IMAGE ------------------------------------------------
const cubemap_image = try engine.createImage(.{ const cubemap_image = try engine.createImage(.{
.flags = .{ .cube_compatible_bit = true }, .flags = .{ .cube_compatible = true },
.image_type = .@"2d", .image_type = .@"2d",
.format = .r16g16b16a16_sfloat, .format = .r16g16b16a16_sfloat,
.extent = .{ .extent = .{
@@ -232,11 +232,11 @@ pub fn load(
}, },
.mip_levels = 1, .mip_levels = 1,
.array_layers = 6, .array_layers = 6,
.samples = .{ .@"1_bit" = true }, .samples = .{ .@"1" = true },
.tiling = .optimal, .tiling = .optimal,
.usage = .{ .usage = .{
.sampled_bit = true, .sampled = true,
.storage_bit = true, .storage = true,
}, },
.queue_family_indices = &.{ .queue_family_indices = &.{
engine.graphics_queue.allocation.family, engine.graphics_queue.allocation.family,
@@ -247,7 +247,7 @@ pub fn load(
errdefer engine.destroyImage(cubemap_image); errdefer engine.destroyImage(cubemap_image);
const cubemap_memory_requirements = engine.getImageMemoryRequirements(cubemap_image); const cubemap_memory_requirements = engine.getImageMemoryRequirements(cubemap_image);
const cubemap_device_memory = try engine.allocate(cubemap_memory_requirements, .{ .device_local_bit = true }); const cubemap_device_memory = try engine.allocate(cubemap_memory_requirements, .{ .device_local = true });
errdefer engine.freeMemory(cubemap_device_memory); errdefer engine.freeMemory(cubemap_device_memory);
try engine.bindImageMemory(cubemap_image, cubemap_device_memory, 0); try engine.bindImageMemory(cubemap_image, cubemap_device_memory, 0);
@@ -257,7 +257,7 @@ pub fn load(
.view_type = .cube, .view_type = .cube,
.format = .r16g16b16a16_sfloat, .format = .r16g16b16a16_sfloat,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -277,7 +277,7 @@ pub fn load(
.view_type = .@"2d_array", .view_type = .@"2d_array",
.format = .r16g16b16a16_sfloat, .format = .r16g16b16a16_sfloat,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -313,20 +313,20 @@ pub fn load(
.binding = 0, .binding = 0,
.descriptor_type = .sampler, .descriptor_type = .sampler,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .compute_bit = true }, .stage_flags = .{ .compute = true },
.immutable_samplers = &.{sampler}, .immutable_samplers = &.{sampler},
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .sampled_image, .descriptor_type = .sampled_image,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .compute_bit = true }, .stage_flags = .{ .compute = true },
}, },
.{ .{
.binding = 2, .binding = 2,
.descriptor_type = .storage_image, .descriptor_type = .storage_image,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .compute_bit = true }, .stage_flags = .{ .compute = true },
}, },
}, },
}); });
@@ -344,7 +344,7 @@ pub fn load(
_ = try engine.device.createComputePipelines(.null_handle, &.{ _ = try engine.device.createComputePipelines(.null_handle, &.{
.{ .{
.stage = .{ .stage = .{
.stage = .{ .compute_bit = true }, .stage = .{ .compute = true },
.module = compute_shader, .module = compute_shader,
.p_name = "main", .p_name = "main",
}, },
@@ -423,19 +423,19 @@ pub fn load(
try compute_command_buffer.beginCommandBuffer(); try compute_command_buffer.beginCommandBuffer();
compute_command_buffer.pipelineBarrier(.{ compute_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true }, .src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .compute_shader_bit = true }, .dst_stage_mask = .{ .compute_shader = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{}, .src_access_mask = .{},
.dst_access_mask = .{ .shader_write_bit = true }, .dst_access_mask = .{ .shader_write = true },
.old_layout = .undefined, .old_layout = .undefined,
.new_layout = .general, .new_layout = .general,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = cubemap_image, .image = cubemap_image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -453,7 +453,7 @@ pub fn load(
.wait_semaphores = &.{ .wait_semaphores = &.{
.{ .{
.semaphore = semaphore_transition_compute, .semaphore = semaphore_transition_compute,
.stage_flags = .{ .compute_shader_bit = true }, .stage_flags = .{ .compute_shader = true },
}, },
}, },
.signal_semaphores = &.{semaphore_compute_transition}, .signal_semaphores = &.{semaphore_compute_transition},
@@ -466,19 +466,19 @@ pub fn load(
try transition2_command_buffer.beginCommandBuffer(); try transition2_command_buffer.beginCommandBuffer();
transition2_command_buffer.pipelineBarrier(.{ transition2_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .compute_shader_bit = true }, .src_stage_mask = .{ .compute_shader = true },
.dst_stage_mask = .{ .fragment_shader_bit = true }, .dst_stage_mask = .{ .fragment_shader = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{ .shader_write_bit = true }, .src_access_mask = .{ .shader_write = true },
.dst_access_mask = .{ .shader_read_bit = true }, .dst_access_mask = .{ .shader_read = true },
.old_layout = .general, .old_layout = .general,
.new_layout = .shader_read_only_optimal, .new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = cubemap_image, .image = cubemap_image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -560,20 +560,20 @@ pub fn load(
.binding = 0, .binding = 0,
.descriptor_type = .uniform_buffer, .descriptor_type = .uniform_buffer,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true }, .stage_flags = .{ .vertex = true },
}, },
.{ .{
.binding = 1, .binding = 1,
.descriptor_type = .sampler, .descriptor_type = .sampler,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .fragment_bit = true }, .stage_flags = .{ .fragment = true },
.immutable_samplers = &.{sampler}, .immutable_samplers = &.{sampler},
}, },
.{ .{
.binding = 2, .binding = 2,
.descriptor_type = .sampled_image, .descriptor_type = .sampled_image,
.descriptor_count = 1, .descriptor_count = 1,
.stage_flags = .{ .fragment_bit = true }, .stage_flags = .{ .fragment = true },
}, },
}, },
}); });
@@ -649,12 +649,12 @@ pub fn load(
const pipeline = try engine.createGraphicsPipeline(.{ const pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{ .stages = &.{
.{ .{
.stage = .{ .vertex_bit = true }, .stage = .{ .vertex = true },
.module = shader, .module = shader,
.name = "vertexMain", .name = "vertexMain",
}, },
.{ .{
.stage = .{ .fragment_bit = true }, .stage = .{ .fragment = true },
.module = shader, .module = shader,
.name = "fragmentMain", .name = "fragmentMain",
}, },
@@ -688,7 +688,7 @@ pub fn load(
.depth_clamp_enable = .false, .depth_clamp_enable = .false,
.rasterizer_discard_enable = .false, .rasterizer_discard_enable = .false,
.polygon_mode = .fill, .polygon_mode = .fill,
.cull_mode = .{ .back_bit = true }, .cull_mode = .{ .back = true },
.front_face = .counter_clockwise, .front_face = .counter_clockwise,
.depth_bias_enable = .false, .depth_bias_enable = .false,
.depth_bias_constant_factor = 0, .depth_bias_constant_factor = 0,
@@ -697,7 +697,7 @@ pub fn load(
.line_width = 1, .line_width = 1,
}, },
.multisample_state = .{ .multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true }, .rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false, .sample_shading_enable = .false,
.min_sample_shading = 1, .min_sample_shading = 1,
.alpha_to_coverage_enable = .false, .alpha_to_coverage_enable = .false,
@@ -743,10 +743,10 @@ pub fn load(
.dst_alpha_blend_factor = .zero, .dst_alpha_blend_factor = .zero,
.alpha_blend_op = .add, .alpha_blend_op = .add,
.color_write_mask = .{ .color_write_mask = .{
.r_bit = true, .r = true,
.g_bit = true, .g = true,
.b_bit = true, .b = true,
.a_bit = true, .a = true,
}, },
}, },
}, },

View File

@@ -94,13 +94,13 @@ pub fn recreate(self: *Swapchain) !void {
.image_color_space = self.params.surface_format.color_space, .image_color_space = self.params.surface_format.color_space,
.image_extent = extent, .image_extent = extent,
.image_array_layers = 1, .image_array_layers = 1,
.image_usage = .{ .color_attachment_bit = true }, .image_usage = .{ .color_attachment = true },
.queue_family_indices = &.{ .queue_family_indices = &.{
engine.graphics_queue.allocation.family, engine.graphics_queue.allocation.family,
engine.presentation_queue.allocation.family, engine.presentation_queue.allocation.family,
}, },
.pre_transform = surface_capabilities.current_transform, .pre_transform = surface_capabilities.current_transform,
.composite_alpha = .{ .opaque_bit_khr = true }, .composite_alpha = .{ .opaque_khr = true },
.present_mode = .fifo_khr, .present_mode = .fifo_khr,
.clipped = .true, .clipped = .true,
.old_swapchain = old_swapchain, .old_swapchain = old_swapchain,
@@ -189,7 +189,7 @@ pub fn recreate(self: *Swapchain) !void {
engine.setObjectName(semaphore_image_acquired, "S Acquired[E]", .{}); engine.setObjectName(semaphore_image_acquired, "S Acquired[E]", .{});
const fence = try engine.createFence(.{ const fence = try engine.createFence(.{
.flags = .{ .signaled_bit = true }, .flags = .{ .signaled = true },
}); });
errdefer engine.destroyFence(fence); errdefer engine.destroyFence(fence);
engine.setObjectName(fence, "F", .{}); engine.setObjectName(fence, "F", .{});
@@ -239,7 +239,7 @@ pub fn present(self: *Swapchain, present_info: PresentInfo) !void {
wait_semaphores.appendAssumeCapacity(.{ wait_semaphores.appendAssumeCapacity(.{
.semaphore = current_swapchain_image.semaphore_image_acquired, .semaphore = current_swapchain_image.semaphore_image_acquired,
.stage_flags = .{ .top_of_pipe_bit = true }, .stage_flags = .{ .top_of_pipe = true },
}); });
wait_semaphores.appendSliceAssumeCapacity(present_info.wait_semaphores); wait_semaphores.appendSliceAssumeCapacity(present_info.wait_semaphores);
@@ -349,7 +349,7 @@ const SwapchainImage = struct {
.view_type = .@"2d", .view_type = .@"2d",
.format = props.format, .format = props.format,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,

View File

@@ -103,12 +103,12 @@ pub fn init(init_info: InitInfo) !Texture {
}, },
.mip_levels = 1, .mip_levels = 1,
.array_layers = 1, .array_layers = 1,
.samples = .{ .@"1_bit" = true }, .samples = .{ .@"1" = true },
.tiling = .optimal, .tiling = .optimal,
.usage = .{ .usage = .{
.depth_stencil_attachment_bit = init_info.usage == .depth, .depth_stencil_attachment = init_info.usage == .depth,
.transfer_dst_bit = init_info.usage != .depth, .transfer_dst = init_info.usage != .depth,
.sampled_bit = init_info.usage != .depth, .sampled = init_info.usage != .depth,
}, },
.queue_family_indices = &.{ target_queue_family, transfer_queue_family }, .queue_family_indices = &.{ target_queue_family, transfer_queue_family },
.initial_layout = .undefined, .initial_layout = .undefined,
@@ -125,7 +125,7 @@ pub fn init(init_info: InitInfo) !Texture {
try device_allocation.bindImage(image); try device_allocation.bindImage(image);
} else { } else {
const memory_requirements = engine.getImageMemoryRequirements(image); const memory_requirements = engine.getImageMemoryRequirements(image);
device_memory = try engine.allocate(memory_requirements, .{ .device_local_bit = true }); device_memory = try engine.allocate(memory_requirements, .{ .device_local = true });
if (init_info.name) |name| { if (init_info.name) |name| {
engine.setObjectName(device_memory, "DM {s} [{s}]", .{ name, @tagName(init_info.usage) }); engine.setObjectName(device_memory, "DM {s} [{s}]", .{ name, @tagName(init_info.usage) });
} }
@@ -139,8 +139,8 @@ pub fn init(init_info: InitInfo) !Texture {
.format = init_info.usage.vkFormat(), .format = init_info.usage.vkFormat(),
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .aspect_mask = .{
.color_bit = init_info.usage != .depth, .color = init_info.usage != .depth,
.depth_bit = init_info.usage == .depth, .depth = init_info.usage == .depth,
}, },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
@@ -231,19 +231,19 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
try transfer_command_buffer.beginCommandBuffer(); try transfer_command_buffer.beginCommandBuffer();
transfer_command_buffer.pipelineBarrier(.{ transfer_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true }, .src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .transfer_bit = true }, .dst_stage_mask = .{ .transfer = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{}, .src_access_mask = .{},
.dst_access_mask = .{ .transfer_write_bit = true }, .dst_access_mask = .{ .transfer_write = true },
.old_layout = .undefined, .old_layout = .undefined,
.new_layout = .transfer_dst_optimal, .new_layout = .transfer_dst_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = self.image, .image = self.image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,
@@ -263,7 +263,7 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
.buffer_row_length = self.width, .buffer_row_length = self.width,
.buffer_image_height = self.height, .buffer_image_height = self.height,
.image_subresource = .{ .image_subresource = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.mip_level = 0, .mip_level = 0,
.base_array_layer = 0, .base_array_layer = 0,
.layer_count = 1, .layer_count = 1,
@@ -291,19 +291,19 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
try graphics_command_buffer.beginCommandBuffer(); try graphics_command_buffer.beginCommandBuffer();
graphics_command_buffer.pipelineBarrier(.{ graphics_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .transfer_bit = true }, .src_stage_mask = .{ .transfer = true },
.dst_stage_mask = .{ .fragment_shader_bit = true }, .dst_stage_mask = .{ .fragment_shader = true },
.image_memory_barriers = &.{ .image_memory_barriers = &.{
.{ .{
.src_access_mask = .{ .transfer_write_bit = true }, .src_access_mask = .{ .transfer_write = true },
.dst_access_mask = .{ .shader_read_bit = true }, .dst_access_mask = .{ .shader_read = true },
.old_layout = .transfer_dst_optimal, .old_layout = .transfer_dst_optimal,
.new_layout = .shader_read_only_optimal, .new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED, .dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = self.image, .image = self.image,
.subresource_range = .{ .subresource_range = .{
.aspect_mask = .{ .color_bit = true }, .aspect_mask = .{ .color = true },
.base_mip_level = 0, .base_mip_level = 0,
.level_count = 1, .level_count = 1,
.base_array_layer = 0, .base_array_layer = 0,

View File

@@ -29,26 +29,27 @@ pub const Id = enum(u16) {
/// Cast an integer into an ID. This can produce an invalid ID. /// Cast an integer into an ID. This can produce an invalid ID.
pub fn fromInt(value: u16) Id { pub fn fromInt(value: u16) Id {
return @enumFromInt(value); std.debug.assert(value < max_textures);
return @fromBackingInt(value);
} }
/// Cast an index into an ID. This can produce an invalid ID. The caller /// Cast an index into an ID. This can produce an invalid ID. The caller
/// asserts that the index is not greater than the max ID value. /// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id { pub fn fromIndex(index: usize) Id {
std.debug.assert(index < max_textures); std.debug.assert(index < max_textures);
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an index into an ID. This can produce an invalid ID. Returns an /// Cast an index into an ID. This can produce an invalid ID. Returns an
/// error if the index is greater than the max ID value. /// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id { pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_textures) return error.Overflow; if (index >= max_textures) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index))); return @fromBackingInt(@intCast(index));
} }
/// Cast an ID into an integer. /// Cast an ID into an integer.
pub fn toInt(self: Id) u16 { pub fn toInt(self: Id) u16 {
return @intFromEnum(self); return @backingInt(self);
} }
}; };
@@ -102,11 +103,11 @@ pub fn init() !*Textures {
}, },
.mip_levels = 1, .mip_levels = 1,
.array_layers = 1, .array_layers = 1,
.samples = .{ .@"1_bit" = true }, .samples = .{ .@"1" = true },
.tiling = .optimal, .tiling = .optimal,
.usage = .{ .usage = .{
.transfer_dst_bit = true, .transfer_dst = true,
.sampled_bit = true, .sampled = true,
}, },
.queue_family_indices = &.{ .queue_family_indices = &.{
engine.graphics_queue.allocation.family, engine.graphics_queue.allocation.family,
@@ -114,9 +115,9 @@ pub fn init() !*Textures {
}, },
.initial_layout = .undefined, .initial_layout = .undefined,
}, },
.{ .color_bit = true }, .{ .color = true },
max_memory, max_memory,
.{ .device_local_bit = true }, .{ .device_local = true },
); );
// VOLATILE Synchronize with explicit values on top of `Id` type. // VOLATILE Synchronize with explicit values on top of `Id` type.

View File

@@ -46,7 +46,7 @@ interface: vk.AllocationCallbacks,
// around it, but it would add much complexity. Instead, we allocate everything // around it, but it would add much complexity. Instead, we allocate everything
// with the same, relatively big alignment and hope for the best. // with the same, relatively big alignment and hope for the best.
const actual_alignment: std.mem.Alignment = .@"16"; const actual_alignment: std.mem.Alignment = .@"16";
const debug = @import("builtin").mode == .Debug; const debug = @import("builtin").mode == .debug;
const stack_frames: usize = if (debug and std.debug.sys_can_stack_trace) 6 else 0; const stack_frames: usize = if (debug and std.debug.sys_can_stack_trace) 6 else 0;
const log = std.log.scoped(.vk_allocator); const log = std.log.scoped(.vk_allocator);

View File

@@ -1,4 +1,4 @@
const vk = @import("vulkan"); const vk = @import("vulkan");
semaphore: vk.Semaphore, semaphore: vk.Semaphore,
stage_flags: vk.PipelineStageFlags = .{ .top_of_pipe_bit = true }, stage_flags: vk.PipelineStageFlags = .{ .top_of_pipe = true },

View File

@@ -28,8 +28,9 @@ pub fn build(b: *std.Build) void {
}; };
const options_step = b.addOptions(); const options_step = b.addOptions();
inline for (std.meta.fields(@TypeOf(options))) |field| { const options_type_info = @typeInfo(@TypeOf(options)).@"struct";
options_step.addOption(field.type, field.name, @field(options, field.name)); inline for (options_type_info.field_types, options_type_info.field_names) |field_type, field_name| {
options_step.addOption(field_type, field_name, @field(options, field_name));
} }
const options_module = options_step.createModule(); const options_module = options_step.createModule();

View File

@@ -14,7 +14,7 @@ fn cIntCast(value: anytype) c_int {
const ValueType = @TypeOf(value); const ValueType = @TypeOf(value);
return switch (@typeInfo(ValueType)) { return switch (@typeInfo(ValueType)) {
.int => @intCast(value), .int => @intCast(value),
.@"enum", .enum_literal => @intFromEnum(value), .@"enum", .enum_literal => @backingInt(value),
.bool => @intFromBool(value), .bool => @intFromBool(value),
else => @compileError("Cannot cast " ++ @typeName(ValueType) ++ "to int."), else => @compileError("Cannot cast " ++ @typeName(ValueType) ++ "to int."),
}; };
@@ -26,8 +26,8 @@ fn cIntCast(value: anytype) c_int {
// //
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
pub const Bool = enum(c_int) { _ }; pub const Bool = enum(c_int) { _ };
pub const TRUE: Bool = @enumFromInt(1); pub const TRUE: Bool = @fromBackingInt(1);
pub const FALSE: Bool = @enumFromInt(0); pub const FALSE: Bool = @fromBackingInt(0);
pub const InitHint = enum(c_int) { pub const InitHint = enum(c_int) {
joystick_hat_buttons = 0x00050001, joystick_hat_buttons = 0x00050001,
@@ -92,15 +92,12 @@ extern fn glfwGetRequiredInstanceExtensions(count: *u32) ?*?[*:0]const u8;
pub const VulkanFn = *const fn () callconv(.c) void; pub const VulkanFn = *const fn () callconv(.c) void;
const vk = if (options.enable_vulkan_import) const vk = struct {
@import("vulkan") pub const Instance = if (options.enable_vulkan_import) ?@import("vulkan").Instance else ?*const anyopaque;
else pub const PhysicalDevice = if (options.enable_vulkan_import) ?@import("vulkan").PhysicalDevice else ?*const anyopaque;
struct { pub const AllocationCallbacks = if (options.enable_vulkan_import) @import("vulkan").AllocationCallbacks else anyopaque;
pub const Instance = ?*const anyopaque; pub const SurfaceKHR = if (options.enable_vulkan_import) @import("vulkan").SurfaceKHR else anyopaque;
pub const PhysicalDevice = ?*const anyopaque; };
pub const AllocationCallbacks = anyopaque;
pub const SurfaceKHR = anyopaque;
};
pub const getInstanceProcAddress = glfwGetInstanceProcAddress; pub const getInstanceProcAddress = glfwGetInstanceProcAddress;
extern fn glfwGetInstanceProcAddress(instance: vk.Instance, procname: [*:0]const u8) ?VulkanFn; extern fn glfwGetInstanceProcAddress(instance: vk.Instance, procname: [*:0]const u8) ?VulkanFn;
@@ -527,7 +524,7 @@ pub fn joystickIsGamepad(joystick: Joystick) bool {
extern fn glfwJoystickIsGamepad(Joystick) Bool; extern fn glfwJoystickIsGamepad(Joystick) Bool;
pub fn joystickAsGamepad(joystick: Joystick) ?Gamepad { pub fn joystickAsGamepad(joystick: Joystick) ?Gamepad {
return if (joystickIsGamepad(joystick)) @enumFromInt(@intFromEnum(joystick)) else null; return if (joystickIsGamepad(joystick)) @fromBackingInt(@backingInt(joystick)) else null;
} }
pub const JoystickFn = *const fn (joystick: Joystick, event: Joystick.Event) callconv(.c) void; pub const JoystickFn = *const fn (joystick: Joystick, event: Joystick.Event) callconv(.c) void;
@@ -579,15 +576,15 @@ pub const Gamepad = enum(c_int) {
}; };
pub const State = extern struct { pub const State = extern struct {
comptime { //comptime {
const c = @cImport(@cInclude("GLFW/glfw3.h")); // const c = @cImport(@cInclude("GLFW/glfw3.h"));
assert(@sizeOf(c.GLFWgamepadstate) == @sizeOf(State)); // assert(@sizeOf(c.GLFWgamepadstate) == @sizeOf(State));
for (std.meta.fieldNames(State)) |field_name| { // for (std.meta.fieldNames(State)) |field_name| {
assert(@offsetOf(c.GLFWgamepadstate, field_name) == @offsetOf(State, field_name)); // assert(@offsetOf(c.GLFWgamepadstate, field_name) == @offsetOf(State, field_name));
} // }
} //}
buttons: [Button.count]Joystick.ButtonAction = .{Joystick.ButtonAction.release} ** Button.count, buttons: [Button.count]Joystick.ButtonAction = @splat(.release),
axes: [Axis.count]f32 = .{@as(f32, 0)} ** Axis.count, axes: [Axis.count]f32 = @splat(0),
}; };
pub const getName = getGamepadName; pub const getName = getGamepadName;
@@ -710,14 +707,14 @@ pub fn getVideoModes(monitor: *Monitor) Error![]VideoMode {
extern fn glfwGetVideoModes(*Monitor, count: *c_int) ?[*]VideoMode; extern fn glfwGetVideoModes(*Monitor, count: *c_int) ?[*]VideoMode;
pub const VideoMode = extern struct { pub const VideoMode = extern struct {
comptime { //comptime {
const c = @cImport(@cInclude("GLFW/glfw3.h")); // const c = @cImport(@cInclude("GLFW/glfw3.h"));
assert(@sizeOf(c.GLFWvidmode) == @sizeOf(VideoMode)); // assert(@sizeOf(c.GLFWvidmode) == @sizeOf(VideoMode));
for (std.meta.fieldNames(VideoMode), 0..) |field_name, i| { // for (std.meta.fieldNames(VideoMode), 0..) |field_name, i| {
assert(@offsetOf(c.GLFWvidmode, std.meta.fieldNames(c.GLFWvidmode)[i]) == // assert(@offsetOf(c.GLFWvidmode, std.meta.fieldNames(c.GLFWvidmode)[i]) ==
@offsetOf(VideoMode, field_name)); // @offsetOf(VideoMode, field_name));
} // }
} //}
width: c_int, width: c_int,
height: c_int, height: c_int,
red_bits: c_int, red_bits: c_int,
@@ -731,13 +728,13 @@ pub const VideoMode = extern struct {
// //
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
pub const Image = extern struct { pub const Image = extern struct {
comptime { //comptime {
const c = @cImport(@cInclude("GLFW/glfw3.h")); // const c = @cImport(@cInclude("GLFW/glfw3.h"));
assert(@sizeOf(c.GLFWimage) == @sizeOf(Image)); // assert(@sizeOf(c.GLFWimage) == @sizeOf(Image));
for (std.meta.fieldNames(Image)) |field_name| { // for (std.meta.fieldNames(Image)) |field_name| {
assert(@offsetOf(c.GLFWimage, field_name) == @offsetOf(Image, field_name)); // assert(@offsetOf(c.GLFWimage, field_name) == @offsetOf(Image, field_name));
} // }
} //}
width: c_int, width: c_int,
height: c_int, height: c_int,
pixels: [*]u8, pixels: [*]u8,
@@ -904,7 +901,7 @@ pub fn getWindowAttribute(
comptime attrib: Window.Attribute, comptime attrib: Window.Attribute,
) Window.Attribute.ValueType(attrib) { ) Window.Attribute.ValueType(attrib) {
return switch (@typeInfo(Window.Attribute.ValueType(attrib))) { return switch (@typeInfo(Window.Attribute.ValueType(attrib))) {
.bool => @as(Bool, @enumFromInt(getWindowAttributeUntyped(window, attrib))) == TRUE, .bool => getWindowAttributeUntyped(window, attrib) != 0,
.int => getWindowAttributeUntyped(window, attrib), .int => getWindowAttributeUntyped(window, attrib),
else => unreachable, else => unreachable,
}; };
@@ -1142,7 +1139,7 @@ pub fn getInputMode(
window: *Window, window: *Window,
comptime mode: InputMode, comptime mode: InputMode,
) Error!InputMode.ValueType(mode) { ) Error!InputMode.ValueType(mode) {
return @enumFromInt(try getInputModeUntyped(window, mode)); return @fromBackingInt(try getInputModeUntyped(window, mode));
} }
pub fn getInputModeUntyped(window: *Window, mode: InputMode) Error!c_int { pub fn getInputModeUntyped(window: *Window, mode: InputMode) Error!c_int {
const value = glfwGetInputMode(window, mode); const value = glfwGetInputMode(window, mode);