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

@@ -82,7 +82,7 @@ pub fn init(init_info: InitInfo) !Chunk {
engine.setObjectName(object_buffer.device_memory, "DM Chunk[{d}]", .{chunk_id});
return .{
.blocks = .{.{[_]Blocks.Id{.air} ** chunk_size} ** chunk_size} ** chunk_size,
.blocks = @splat(@splat(@splat(.air))),
.origin = init_info.origin,
.descriptor_set = descriptor_set,
.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 {
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();
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 origin = vm.Vector3.add(self.origin, .init(fx, fy, fz));
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| {
const side = @field(voxels.Orientation, field.name);
const wall: Blocks.Definition.Wall = @field(block.walls, field.name);
inline for (@typeInfo(voxels.Orientation).@"enum".field_names) |field_name| {
const side = @field(voxels.Orientation, 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) {
const matrix = getMatrix(side, origin);
try uniforms.append(allocator_frame, .{

View File

@@ -107,38 +107,38 @@ pub fn init() !Game {
.binding = 0,
.descriptor_type = .uniform_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 1,
.descriptor_type = .storage_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 2,
.descriptor_type = .storage_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 3,
.descriptor_type = .storage_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 4,
.descriptor_type = .sampler,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
.immutable_samplers = &.{sampler},
},
.{
.binding = 5,
.descriptor_type = .sampled_image,
.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,
.descriptor_type = .storage_buffer,
.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(.{
.stages = &.{
.{
.stage = .{ .vertex_bit = true },
.stage = .{ .vertex = true },
.module = shader,
.name = "vertexMain",
},
.{
.stage = .{ .fragment_bit = true },
.stage = .{ .fragment = true },
.module = shader,
.name = "fragmentMain",
},
@@ -329,7 +329,7 @@ pub fn init() !Game {
.depth_clamp_enable = .false,
.rasterizer_discard_enable = .false,
.polygon_mode = .fill,
.cull_mode = .{ .back_bit = true },
.cull_mode = .{ .back = true },
.front_face = .counter_clockwise,
.depth_bias_enable = .false,
.depth_bias_constant_factor = 0,
@@ -338,7 +338,7 @@ pub fn init() !Game {
.line_width = 1,
},
.multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true },
.rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false,
.min_sample_shading = 1,
.alpha_to_coverage_enable = .false,
@@ -384,10 +384,10 @@ pub fn init() !Game {
.dst_alpha_blend_factor = .zero,
.alpha_blend_op = .add,
.color_write_mask = .{
.r_bit = true,
.g_bit = true,
.b_bit = true,
.a_bit = true,
.r = true,
.g = true,
.b = true,
.a = true,
},
},
},
@@ -407,7 +407,7 @@ pub fn init() !Game {
const descriptor_pool = try engine.createDescriptorPool(.{
.flags = .{
.free_descriptor_set_bit = true,
.free_descriptor_set = true,
},
.max_sets = 1 + chunk_descriptor_pool,
.pool_sizes = &.{
@@ -627,7 +627,7 @@ pub fn init() !Game {
var skybox = try Skybox.load("skybox.hdr", 512, global_uniforms.buffer);
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
// 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_binding = 2,
.dst_array_element = @intFromEnum(font_id),
.dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer,
.descriptor_infos = .{
.buffer = &.{
@@ -684,7 +684,7 @@ pub fn init() !Game {
.{
.dst_set = gui.text_descriptor_set,
.dst_binding = 3,
.dst_array_element = @intFromEnum(font_id),
.dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer,
.descriptor_infos = .{
.buffer = &.{
@@ -699,7 +699,7 @@ pub fn init() !Game {
.{
.dst_set = gui.text_descriptor_set,
.dst_binding = 4,
.dst_array_element = @intFromEnum(font_id),
.dst_array_element = @backingInt(font_id),
.descriptor_type = .storage_buffer,
.descriptor_infos = .{
.buffer = &.{
@@ -955,14 +955,14 @@ fn render(self: *Game) !void {
const swapchain_image = swapchain.getCurrentSwapchainImage();
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true },
.dst_stage_mask = .{ .color_attachment_output_bit = true },
.src_stage_mask = .{ .color_attachment_output = true },
.dst_stage_mask = .{ .color_attachment_output = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{},
.dst_access_mask = .{
.color_attachment_read_bit = true,
.color_attachment_write_bit = true,
.color_attachment_read = true,
.color_attachment_write = true,
},
.old_layout = .undefined,
.new_layout = .color_attachment_optimal,
@@ -970,7 +970,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -981,15 +981,15 @@ fn render(self: *Game) !void {
});
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .late_fragment_tests_bit = true },
.dst_stage_mask = .{ .early_fragment_tests_bit = true },
.src_stage_mask = .{ .late_fragment_tests = true },
.dst_stage_mask = .{ .early_fragment_tests = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{
.depth_stencil_attachment_write_bit = true,
.depth_stencil_attachment_write = true,
},
.dst_access_mask = .{
.depth_stencil_attachment_write_bit = true,
.depth_stencil_attachment_write = true,
},
.old_layout = .undefined,
.new_layout = .depth_stencil_attachment_optimal,
@@ -997,7 +997,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain.depth_texture.?.image,
.subresource_range = .{
.aspect_mask = .{ .depth_bit = true },
.aspect_mask = .{ .depth = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -1079,11 +1079,11 @@ fn render(self: *Game) !void {
command_buffer.endRendering();
command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .color_attachment_output_bit = true },
.dst_stage_mask = .{ .bottom_of_pipe_bit = true },
.src_stage_mask = .{ .color_attachment_output = true },
.dst_stage_mask = .{ .bottom_of_pipe = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{ .color_attachment_write_bit = true },
.src_access_mask = .{ .color_attachment_write = true },
.dst_access_mask = .{},
.old_layout = .color_attachment_optimal,
.new_layout = .present_src_khr,
@@ -1091,7 +1091,7 @@ fn render(self: *Game) !void {
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = swapchain_image.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -1108,7 +1108,7 @@ fn render(self: *Game) !void {
.wait_semaphores = &.{
.{
.semaphore = self.global_uniforms_transfer_semaphores[swapchain.image_index.?],
.stage_flags = .{ .vertex_shader_bit = true },
.stage_flags = .{ .vertex_shader = true },
},
},
}) 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.z_input.onKeyDown(key);
const key_code = @intFromEnum(key);
if (key_code >= @intFromEnum(glfw.Key.one) and key_code <= @intFromEnum(glfw.Key.nine)) {
self.block_index = @intCast(key_code - @intFromEnum(glfw.Key.one));
const key_code = @backingInt(key);
if (key_code >= @backingInt(glfw.Key.one) and key_code <= @backingInt(glfw.Key.nine)) {
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)}, .{
.position_sspx = .init(margin, margin + font_size),
.font_id = @enumFromInt(0),
.font_id = game.font,
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Y {s}", .{formatHexCoord(self.position_sv.y, &number_buf)}, .{
.position_sspx = .init(margin, 2 * (margin + font_size)),
.font_id = @enumFromInt(0),
.font_id = game.font,
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Z {s}", .{formatHexCoord(self.position_sv.z, &number_buf)}, .{
.position_sspx = .init(margin, 3 * (margin + font_size)),
.font_id = @enumFromInt(0),
.font_id = game.font,
.cap_height_px = font_size,
.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 });
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 = &materials.array.items[@intFromEnum(material_id)];
const material = &materials.array.items[@backingInt(material_id)];
if (i == self.block_index) {
gui.pushBox(.{
@@ -527,9 +527,10 @@ fn formatHexCoord(coord: i32, buf: *[9]u8) []const u8 {
}
fn resetAllButtons(self: *Player) void {
inline for (@typeInfo(Player).@"struct".fields) |field| {
if (field.type == Button) {
@field(self, field.name).reset();
const type_info = @typeInfo(Player).@"struct";
inline for (type_info.field_types, type_info.field_names) |field_type, field_name| {
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.
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
/// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id {
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
/// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_blocks) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index)));
return @fromBackingInt(@intCast(index));
}
/// Cast an ID into an integer.
pub fn toInt(self: Id) u16 {
return @intFromEnum(self);
return @backingInt(self);
}
};
@@ -265,10 +266,10 @@ fn loadBlock(filename: []const u8) !Definition {
break :blk .{
.walls = walls: {
var ret: Definition.Walls = undefined;
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| {
@field(ret, field.name) = .{
.material = try materials.getOrLoad(@field(walls, field.name).material),
.transform = @field(walls, field.name).transform,
inline for (@typeInfo(voxels.Orientation).@"enum".field_names) |field_name| {
@field(ret, field_name) = .{
.material = try materials.getOrLoad(@field(walls, field_name).material),
.transform = @field(walls, field_name).transform,
};
}
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.
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
/// asserts that the index is not greater than the max atom value.
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
/// error if the index is greater than the max atom value.
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
@@ -52,7 +52,7 @@ pub const Atom = enum(u16) {
const atom = Atom.fromIndexSafe(atoms.array.items.len) catch |err| switch (err) {
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.array.appendAssumeCapacity(owned_string);
@@ -76,7 +76,7 @@ pub const Atom = enum(u16) {
/// Cast an atom into an integer.
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.

View File

@@ -168,7 +168,7 @@ pub const VertexBufferBinding = struct {
pub fn beginCommandBuffer(self: CommandBuffer) !void {
try self.proxy.beginCommandBuffer(&.{
.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,
random: std.Random,
const debug = @import("builtin").mode == .Debug;
const debug = @import("builtin").mode == .debug;
const vk_version: vk.Version = vk.makeApiVersion(
0,
c.app_version.major,
@@ -96,15 +96,15 @@ const vk_version: vk.Version = vk.makeApiVersion(
);
const vk_debug_utils_messenger_create_info: vk.DebugUtilsMessengerCreateInfoEXT = .{
.message_severity = .{
.verbose_bit_ext = false,
.info_bit_ext = false,
.warning_bit_ext = true,
.error_bit_ext = true,
.verbose_ext = false,
.info_ext = false,
.warning_ext = true,
.error_ext = true,
},
.message_type = .{
.general_bit_ext = true,
.validation_bit_ext = true,
.performance_bit_ext = true,
.general_ext = true,
.validation_ext = true,
.performance_ext = true,
},
.pfn_user_callback = &debugUtilsMessengerCallback,
.p_user_data = null,
@@ -230,7 +230,7 @@ pub fn init() !*Engine {
const transfer_queue_index = queue_allocator.allocateQueueIndex(transfer_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| {
if (count == 0) continue;
@@ -315,19 +315,19 @@ pub fn init() !*Engine {
// --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------
const graphics_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.flags = .{ .transient = true },
.queue_family_index = queue_allocations.graphics_queue.family,
}, ctx.vk_allocator.capture());
errdefer device.destroyCommandPool(graphics_command_pool, ctx.vk_allocator.capture());
const compute_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.flags = .{ .transient = true },
.queue_family_index = queue_allocations.compute_queue.family,
}, ctx.vk_allocator.capture());
errdefer device.destroyCommandPool(compute_command_pool, ctx.vk_allocator.capture());
const transfer_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.flags = .{ .transient = true },
.queue_family_index = queue_allocations.transfer_queue.family,
}, 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"),
};
const handle_value: u64 = @intFromEnum(handle);
const handle_value: u64 = @backingInt(handle);
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) });
return;
};
@@ -592,18 +592,18 @@ fn debugUtilsMessengerCallback(
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 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 args = .{ type_name, message };
if (severity.error_bit_ext) {
if (severity.error_ext) {
log.err(format, args);
} else if (severity.warning_bit_ext) {
} else if (severity.warning_ext) {
log.warn(format, args);
} else if (severity.info_bit_ext) {
} else if (severity.info_ext) {
log.info(format, args);
} else if (severity.verbose_bit_ext) {
} else if (severity.verbose_ext) {
log.debug(format, args);
}
@@ -611,10 +611,10 @@ fn debugUtilsMessengerCallback(
}
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| {
const graphics_bit = queue_family_properties.queue_flags.graphics_bit;
const graphics_bit = queue_family_properties.queue_flags.graphics;
if (graphics_bit) {
return @intCast(i);
}
@@ -624,21 +624,21 @@ fn findGraphicsQueueFamily(queue_families_properties: []const vk.QueueFamilyProp
}
fn findComputeQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 {
// Look for the first family that has the `compute_bit` set, but not
// `graphics_bit`.
// Look for the first family that has the `compute` bit set, but not
// `graphics` bit.
for (queue_families_properties, 0..) |queue_family_properties, i| {
const compute_bit = queue_family_properties.queue_flags.compute_bit;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit;
const compute_bit = queue_family_properties.queue_flags.compute;
const graphics_bit = queue_family_properties.queue_flags.graphics;
if (compute_bit and !graphics_bit) {
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| {
const compute_bit = queue_family_properties.queue_flags.compute_bit;
const compute_bit = queue_family_properties.queue_flags.compute;
if (compute_bit) {
return @intCast(i);
}
@@ -648,28 +648,28 @@ fn findComputeQueueFamily(queue_families_properties: []const vk.QueueFamilyPrope
}
fn findTransferQueueFamily(queue_families_properties: []const vk.QueueFamilyProperties) ?u32 {
// Look for the first family that has the `transfer_bit` set, but neither
// `graphics_bit` or `compute_bit`.
// Look for the first family that has the `transfer` bit set, but neither
// `graphics` bit or `compute` bit.
for (queue_families_properties, 0..) |queue_family_properties, i| {
const transfer_bit = queue_family_properties.queue_flags.transfer_bit;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit;
const compute_bit = queue_family_properties.queue_flags.compute_bit;
const transfer_bit = queue_family_properties.queue_flags.transfer;
const graphics_bit = queue_family_properties.queue_flags.graphics;
const compute_bit = queue_family_properties.queue_flags.compute;
if (transfer_bit and !graphics_bit and !compute_bit) {
return @intCast(i);
}
}
// Look for the first family that has either `transfer_bit`, `graphics_bit`
// or `compute_bit` set.
// Look for the first family that has either `transfer_` bit, `graphics` bit
// 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.
for (queue_families_properties, 0..) |queue_family_properties, i| {
const transfer_bit = queue_family_properties.queue_flags.transfer_bit;
const graphics_bit = queue_family_properties.queue_flags.graphics_bit;
const compute_bit = queue_family_properties.queue_flags.compute_bit;
const transfer_bit = queue_family_properties.queue_flags.transfer;
const graphics_bit = queue_family_properties.queue_flags.graphics;
const compute_bit = queue_family_properties.queue_flags.compute;
if (transfer_bit or graphics_bit or compute_bit) {
return @intCast(i);
}

View File

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

View File

@@ -154,13 +154,13 @@ pub fn init() !*Gui {
.binding = 0,
.descriptor_type = .uniform_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 1,
.descriptor_type = .storage_buffer,
.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(.{
.stages = &.{
.{
.stage = .{ .vertex_bit = true },
.stage = .{ .vertex = true },
.module = box_shader,
.name = "vertexMain",
},
.{
.stage = .{ .fragment_bit = true },
.stage = .{ .fragment = true },
.module = box_shader,
.name = "fragmentMain",
},
@@ -214,7 +214,7 @@ pub fn init() !*Gui {
.line_width = 1,
},
.multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true },
.rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false,
.min_sample_shading = 1,
.alpha_to_coverage_enable = .false,
@@ -260,10 +260,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add,
.color_write_mask = .{
.r_bit = true,
.g_bit = true,
.b_bit = true,
.a_bit = true,
.r = true,
.g = true,
.b = true,
.a = true,
},
},
},
@@ -287,31 +287,31 @@ pub fn init() !*Gui {
.binding = 0,
.descriptor_type = .uniform_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 1,
.descriptor_type = .storage_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 2,
.descriptor_type = .storage_buffer,
.descriptor_count = Fonts.max_fonts,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 3,
.descriptor_type = .storage_buffer,
.descriptor_count = Fonts.max_fonts,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 4,
.descriptor_type = .storage_buffer,
.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(.{
.stages = &.{
.{
.stage = .{ .vertex_bit = true },
.stage = .{ .vertex = true },
.module = text_shader,
.name = "vertexMain",
},
.{
.stage = .{ .fragment_bit = true },
.stage = .{ .fragment = true },
.module = text_shader,
.name = "fragmentMain",
},
@@ -365,7 +365,7 @@ pub fn init() !*Gui {
.line_width = 1,
},
.multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true },
.rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false,
.min_sample_shading = 1,
.alpha_to_coverage_enable = .false,
@@ -411,10 +411,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add,
.color_write_mask = .{
.r_bit = true,
.g_bit = true,
.b_bit = true,
.a_bit = true,
.r = true,
.g = true,
.b = true,
.a = true,
},
},
},
@@ -438,26 +438,26 @@ pub fn init() !*Gui {
.binding = 0,
.descriptor_type = .uniform_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 1,
.descriptor_type = .storage_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
},
.{
.binding = 2,
.descriptor_type = .sampler,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.stage_flags = .{ .vertex = true, .fragment = true },
.immutable_samplers = &.{sampler},
},
.{
.binding = 3,
.descriptor_type = .sampled_image,
.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(.{
.stages = &.{
.{
.stage = .{ .vertex_bit = true },
.stage = .{ .vertex = true },
.module = image_shader,
.name = "vertexMain",
},
.{
.stage = .{ .fragment_bit = true },
.stage = .{ .fragment = true },
.module = image_shader,
.name = "fragmentMain",
},
@@ -511,7 +511,7 @@ pub fn init() !*Gui {
.line_width = 1,
},
.multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true },
.rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false,
.min_sample_shading = 1,
.alpha_to_coverage_enable = .false,
@@ -557,10 +557,10 @@ pub fn init() !*Gui {
.dst_alpha_blend_factor = .one_minus_src_alpha,
.alpha_blend_op = .add,
.color_write_mask = .{
.r_bit = true,
.g_bit = true,
.b_bit = true,
.a_bit = true,
.r = true,
.g = true,
.b = true,
.a = true,
},
},
},
@@ -770,7 +770,7 @@ pub fn printLine(self: *Gui, comptime fmt: []const u8, fmt_args: anytype, print_
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 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.
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
/// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id {
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
/// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_materials) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index)));
return @fromBackingInt(@intCast(index));
}
/// Cast an ID into an integer.
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);
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;
}

View File

@@ -96,11 +96,11 @@ pub fn load(
},
.mip_levels = 1,
.array_layers = 1,
.samples = .{ .@"1_bit" = true },
.samples = .{ .@"1" = true },
.tiling = .optimal,
.usage = .{
.transfer_dst_bit = true,
.sampled_bit = true,
.transfer_dst = true,
.sampled = true,
},
.queue_family_indices = &.{
engine.compute_queue.allocation.family,
@@ -111,7 +111,7 @@ pub fn load(
defer engine.destroyImage(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);
try engine.bindImageMemory(equirect_image, equirect_device_memory, 0);
@@ -121,7 +121,7 @@ pub fn load(
.view_type = .@"2d",
.format = .r16g16b16a16_sfloat,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -137,19 +137,19 @@ pub fn load(
try transfer_command_buffer.beginCommandBuffer();
transfer_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true },
.dst_stage_mask = .{ .transfer_bit = true },
.src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .transfer = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{},
.dst_access_mask = .{ .transfer_write_bit = true },
.dst_access_mask = .{ .transfer_write = true },
.old_layout = .undefined,
.new_layout = .transfer_dst_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = equirect_image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -168,7 +168,7 @@ pub fn load(
.buffer_row_length = img.width,
.buffer_image_height = img.height,
.image_subresource = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.mip_level = 0,
.base_array_layer = 0,
.layer_count = 1,
@@ -191,19 +191,19 @@ pub fn load(
try transition1_command_buffer.beginCommandBuffer();
transition1_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .transfer_bit = true },
.dst_stage_mask = .{ .compute_shader_bit = true },
.src_stage_mask = .{ .transfer = true },
.dst_stage_mask = .{ .compute_shader = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{ .transfer_write_bit = true },
.dst_access_mask = .{ .shader_read_bit = true },
.src_access_mask = .{ .transfer_write = true },
.dst_access_mask = .{ .shader_read = true },
.old_layout = .transfer_dst_optimal,
.new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = equirect_image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -222,7 +222,7 @@ pub fn load(
// --- CREATE CUBEMAP IMAGE ------------------------------------------------
const cubemap_image = try engine.createImage(.{
.flags = .{ .cube_compatible_bit = true },
.flags = .{ .cube_compatible = true },
.image_type = .@"2d",
.format = .r16g16b16a16_sfloat,
.extent = .{
@@ -232,11 +232,11 @@ pub fn load(
},
.mip_levels = 1,
.array_layers = 6,
.samples = .{ .@"1_bit" = true },
.samples = .{ .@"1" = true },
.tiling = .optimal,
.usage = .{
.sampled_bit = true,
.storage_bit = true,
.sampled = true,
.storage = true,
},
.queue_family_indices = &.{
engine.graphics_queue.allocation.family,
@@ -247,7 +247,7 @@ pub fn load(
errdefer engine.destroyImage(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);
try engine.bindImageMemory(cubemap_image, cubemap_device_memory, 0);
@@ -257,7 +257,7 @@ pub fn load(
.view_type = .cube,
.format = .r16g16b16a16_sfloat,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -277,7 +277,7 @@ pub fn load(
.view_type = .@"2d_array",
.format = .r16g16b16a16_sfloat,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -313,20 +313,20 @@ pub fn load(
.binding = 0,
.descriptor_type = .sampler,
.descriptor_count = 1,
.stage_flags = .{ .compute_bit = true },
.stage_flags = .{ .compute = true },
.immutable_samplers = &.{sampler},
},
.{
.binding = 1,
.descriptor_type = .sampled_image,
.descriptor_count = 1,
.stage_flags = .{ .compute_bit = true },
.stage_flags = .{ .compute = true },
},
.{
.binding = 2,
.descriptor_type = .storage_image,
.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, &.{
.{
.stage = .{
.stage = .{ .compute_bit = true },
.stage = .{ .compute = true },
.module = compute_shader,
.p_name = "main",
},
@@ -423,19 +423,19 @@ pub fn load(
try compute_command_buffer.beginCommandBuffer();
compute_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true },
.dst_stage_mask = .{ .compute_shader_bit = true },
.src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .compute_shader = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{},
.dst_access_mask = .{ .shader_write_bit = true },
.dst_access_mask = .{ .shader_write = true },
.old_layout = .undefined,
.new_layout = .general,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = cubemap_image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -453,7 +453,7 @@ pub fn load(
.wait_semaphores = &.{
.{
.semaphore = semaphore_transition_compute,
.stage_flags = .{ .compute_shader_bit = true },
.stage_flags = .{ .compute_shader = true },
},
},
.signal_semaphores = &.{semaphore_compute_transition},
@@ -466,19 +466,19 @@ pub fn load(
try transition2_command_buffer.beginCommandBuffer();
transition2_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .compute_shader_bit = true },
.dst_stage_mask = .{ .fragment_shader_bit = true },
.src_stage_mask = .{ .compute_shader = true },
.dst_stage_mask = .{ .fragment_shader = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{ .shader_write_bit = true },
.dst_access_mask = .{ .shader_read_bit = true },
.src_access_mask = .{ .shader_write = true },
.dst_access_mask = .{ .shader_read = true },
.old_layout = .general,
.new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = cubemap_image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -560,20 +560,20 @@ pub fn load(
.binding = 0,
.descriptor_type = .uniform_buffer,
.descriptor_count = 1,
.stage_flags = .{ .vertex_bit = true },
.stage_flags = .{ .vertex = true },
},
.{
.binding = 1,
.descriptor_type = .sampler,
.descriptor_count = 1,
.stage_flags = .{ .fragment_bit = true },
.stage_flags = .{ .fragment = true },
.immutable_samplers = &.{sampler},
},
.{
.binding = 2,
.descriptor_type = .sampled_image,
.descriptor_count = 1,
.stage_flags = .{ .fragment_bit = true },
.stage_flags = .{ .fragment = true },
},
},
});
@@ -649,12 +649,12 @@ pub fn load(
const pipeline = try engine.createGraphicsPipeline(.{
.stages = &.{
.{
.stage = .{ .vertex_bit = true },
.stage = .{ .vertex = true },
.module = shader,
.name = "vertexMain",
},
.{
.stage = .{ .fragment_bit = true },
.stage = .{ .fragment = true },
.module = shader,
.name = "fragmentMain",
},
@@ -688,7 +688,7 @@ pub fn load(
.depth_clamp_enable = .false,
.rasterizer_discard_enable = .false,
.polygon_mode = .fill,
.cull_mode = .{ .back_bit = true },
.cull_mode = .{ .back = true },
.front_face = .counter_clockwise,
.depth_bias_enable = .false,
.depth_bias_constant_factor = 0,
@@ -697,7 +697,7 @@ pub fn load(
.line_width = 1,
},
.multisample_state = .{
.rasterization_samples = .{ .@"1_bit" = true },
.rasterization_samples = .{ .@"1" = true },
.sample_shading_enable = .false,
.min_sample_shading = 1,
.alpha_to_coverage_enable = .false,
@@ -743,10 +743,10 @@ pub fn load(
.dst_alpha_blend_factor = .zero,
.alpha_blend_op = .add,
.color_write_mask = .{
.r_bit = true,
.g_bit = true,
.b_bit = true,
.a_bit = true,
.r = true,
.g = true,
.b = 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_extent = extent,
.image_array_layers = 1,
.image_usage = .{ .color_attachment_bit = true },
.image_usage = .{ .color_attachment = true },
.queue_family_indices = &.{
engine.graphics_queue.allocation.family,
engine.presentation_queue.allocation.family,
},
.pre_transform = surface_capabilities.current_transform,
.composite_alpha = .{ .opaque_bit_khr = true },
.composite_alpha = .{ .opaque_khr = true },
.present_mode = .fifo_khr,
.clipped = .true,
.old_swapchain = old_swapchain,
@@ -189,7 +189,7 @@ pub fn recreate(self: *Swapchain) !void {
engine.setObjectName(semaphore_image_acquired, "S Acquired[E]", .{});
const fence = try engine.createFence(.{
.flags = .{ .signaled_bit = true },
.flags = .{ .signaled = true },
});
errdefer engine.destroyFence(fence);
engine.setObjectName(fence, "F", .{});
@@ -239,7 +239,7 @@ pub fn present(self: *Swapchain, present_info: PresentInfo) !void {
wait_semaphores.appendAssumeCapacity(.{
.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);
@@ -349,7 +349,7 @@ const SwapchainImage = struct {
.view_type = .@"2d",
.format = props.format,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,

View File

@@ -103,12 +103,12 @@ pub fn init(init_info: InitInfo) !Texture {
},
.mip_levels = 1,
.array_layers = 1,
.samples = .{ .@"1_bit" = true },
.samples = .{ .@"1" = true },
.tiling = .optimal,
.usage = .{
.depth_stencil_attachment_bit = init_info.usage == .depth,
.transfer_dst_bit = init_info.usage != .depth,
.sampled_bit = init_info.usage != .depth,
.depth_stencil_attachment = init_info.usage == .depth,
.transfer_dst = init_info.usage != .depth,
.sampled = init_info.usage != .depth,
},
.queue_family_indices = &.{ target_queue_family, transfer_queue_family },
.initial_layout = .undefined,
@@ -125,7 +125,7 @@ pub fn init(init_info: InitInfo) !Texture {
try device_allocation.bindImage(image);
} else {
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| {
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(),
.subresource_range = .{
.aspect_mask = .{
.color_bit = init_info.usage != .depth,
.depth_bit = init_info.usage == .depth,
.color = init_info.usage != .depth,
.depth = init_info.usage == .depth,
},
.base_mip_level = 0,
.level_count = 1,
@@ -231,19 +231,19 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
try transfer_command_buffer.beginCommandBuffer();
transfer_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .top_of_pipe_bit = true },
.dst_stage_mask = .{ .transfer_bit = true },
.src_stage_mask = .{ .top_of_pipe = true },
.dst_stage_mask = .{ .transfer = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{},
.dst_access_mask = .{ .transfer_write_bit = true },
.dst_access_mask = .{ .transfer_write = true },
.old_layout = .undefined,
.new_layout = .transfer_dst_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = self.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.base_array_layer = 0,
@@ -263,7 +263,7 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
.buffer_row_length = self.width,
.buffer_image_height = self.height,
.image_subresource = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.mip_level = 0,
.base_array_layer = 0,
.layer_count = 1,
@@ -291,19 +291,19 @@ pub fn writeRaw(self: Texture, data: []const u8) !void {
try graphics_command_buffer.beginCommandBuffer();
graphics_command_buffer.pipelineBarrier(.{
.src_stage_mask = .{ .transfer_bit = true },
.dst_stage_mask = .{ .fragment_shader_bit = true },
.src_stage_mask = .{ .transfer = true },
.dst_stage_mask = .{ .fragment_shader = true },
.image_memory_barriers = &.{
.{
.src_access_mask = .{ .transfer_write_bit = true },
.dst_access_mask = .{ .shader_read_bit = true },
.src_access_mask = .{ .transfer_write = true },
.dst_access_mask = .{ .shader_read = true },
.old_layout = .transfer_dst_optimal,
.new_layout = .shader_read_only_optimal,
.src_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.dst_queue_family_index = vk.QUEUE_FAMILY_IGNORED,
.image = self.image,
.subresource_range = .{
.aspect_mask = .{ .color_bit = true },
.aspect_mask = .{ .color = true },
.base_mip_level = 0,
.level_count = 1,
.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.
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
/// asserts that the index is not greater than the max ID value.
pub fn fromIndex(index: usize) Id {
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
/// error if the index is greater than the max ID value.
pub fn fromIndexSafe(index: usize) error{Overflow}!Id {
if (index >= max_textures) return error.Overflow;
return @enumFromInt(@as(u16, @intCast(index)));
return @fromBackingInt(@intCast(index));
}
/// Cast an ID into an integer.
pub fn toInt(self: Id) u16 {
return @intFromEnum(self);
return @backingInt(self);
}
};
@@ -102,11 +103,11 @@ pub fn init() !*Textures {
},
.mip_levels = 1,
.array_layers = 1,
.samples = .{ .@"1_bit" = true },
.samples = .{ .@"1" = true },
.tiling = .optimal,
.usage = .{
.transfer_dst_bit = true,
.sampled_bit = true,
.transfer_dst = true,
.sampled = true,
},
.queue_family_indices = &.{
engine.graphics_queue.allocation.family,
@@ -114,9 +115,9 @@ pub fn init() !*Textures {
},
.initial_layout = .undefined,
},
.{ .color_bit = true },
.{ .color = true },
max_memory,
.{ .device_local_bit = true },
.{ .device_local = true },
);
// 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
// with the same, relatively big alignment and hope for the best.
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 log = std.log.scoped(.vk_allocator);

View File

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