Compare commits

...

2 Commits

Author SHA1 Message Date
a18fcb44ac Signed coord display in HUD 2026-09-22 02:24:59 +02:00
609321af2a Don't use variable descriptor count 2026-09-22 02:22:23 +02:00
3 changed files with 24 additions and 27 deletions

View File

@@ -50,7 +50,6 @@ skybox: Skybox,
player: Player,
font: Fonts.Id,
const max_textures = 1024;
const max_point_lights = 1024;
const max_directional_lights = 4;
const chunk_descriptor_pool = 1024;
@@ -138,9 +137,8 @@ pub fn init() !Game {
.{
.binding = 5,
.descriptor_type = .sampled_image,
.descriptor_count = max_textures,
.descriptor_count = Textures.max_textures,
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
.flags = .{ .variable_descriptor_count_bit = true }, // TODO Get rid of this AND somehow integrate with Textures module?
},
},
});
@@ -418,7 +416,7 @@ pub fn init() !Game {
},
.{
.type = .sampled_image,
.descriptor_count = max_textures,
.descriptor_count = Textures.max_textures,
},
.{
.type = .uniform_buffer,
@@ -436,7 +434,6 @@ pub fn init() !Game {
const global_descriptor_set = try engine.allocateDescriptorSet(.{
.descriptor_pool = descriptor_pool,
.set_layout = global_descriptor_set_layout,
.variable_descriptor_count = @intCast(textures.array.items.len),
});
engine.setObjectName(global_descriptor_set, "DS Global", .{});

View File

@@ -421,30 +421,35 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
const margin: f16 = 8;
const font_size: f32 = 16;
// NOTE We have to do the number formatting semi-manually, because zig's
// std fmt is weird with signed numbers
var number_buf: [9]u8 = undefined; // sign ('-' or ' ') and 8 hex digits
gui.pushBox(.{
.background_color = .init(0, 0, 0, 0.75),
.border_color = .init(0, 0, 0, 1),
.position_sspx = .init(0, 0),
.size_px = .init(157, 4 * margin + 3 * font_size),
.size_px = .init(164, 4 * margin + 3 * font_size),
.border_width_px = 0,
.border_radius_px = 0,
});
gui.printLine("X {X:0>8}", .{@as(u32, @bitCast(self.position_sv.x))}, .{
gui.printLine("X {s}", .{formatHexCoord(self.position_sv.x, &number_buf)}, .{
.position_sspx = .init(margin, margin + font_size),
.font_id = @enumFromInt(0),
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Y {X:0>8}", .{@as(u32, @bitCast(self.position_sv.y))}, .{
gui.printLine("Y {s}", .{formatHexCoord(self.position_sv.y, &number_buf)}, .{
.position_sspx = .init(margin, 2 * (margin + font_size)),
.font_id = @enumFromInt(0),
.cap_height_px = font_size,
.color = .init(1, 1, 1, 1),
});
gui.printLine("Z {X:0>8}", .{@as(u32, @bitCast(self.position_sv.z))}, .{
gui.printLine("Z {s}", .{formatHexCoord(self.position_sv.z, &number_buf)}, .{
.position_sspx = .init(margin, 3 * (margin + font_size)),
.font_id = @enumFromInt(0),
.cap_height_px = font_size,
@@ -508,6 +513,19 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
}
}
fn formatHexCoord(coord: i32, buf: *[9]u8) []const u8 {
buf[0] = ' ';
const coord_abs = @abs(coord);
_ = std.fmt.bufPrint(buf[1..9], "{X:>8}", .{coord_abs}) catch unreachable;
if (coord < 0) {
const i = std.mem.findScalarLast(u8, buf, ' ') orelse unreachable;
buf[i] = '-';
}
return buf[0..];
}
fn resetAllButtons(self: *Player) void {
inline for (@typeInfo(Player).@"struct".fields) |field| {
if (field.type == Button) {

View File

@@ -275,7 +275,6 @@ pub fn init() !*Engine {
.shader_float_16 = .true,
.descriptor_indexing = .true,
.descriptor_binding_partially_bound = .true,
.descriptor_binding_variable_descriptor_count = .true,
.runtime_descriptor_array = .true,
.scalar_block_layout = .true,
.imageless_framebuffer = .true,
@@ -745,13 +744,11 @@ pub const DescriptorPoolCreateInfo = struct {
pub const DescriptorSetAllocateInfo = struct {
descriptor_pool: vk.DescriptorPool,
set_layout: vk.DescriptorSetLayout,
variable_descriptor_count: ?u32 = null,
};
pub const DescriptorSetsAllocateInfo = struct {
descriptor_pool: vk.DescriptorPool,
set_layouts: []const vk.DescriptorSetLayout,
variable_descriptor_counts: []const u32 = &.{},
};
pub const DescriptorSetLayoutBinding = struct {
@@ -969,28 +966,13 @@ pub fn allocateDescriptorSet(self: *Engine, allocate_info: DescriptorSetAllocate
try self.allocateDescriptorSets(.{
.descriptor_pool = allocate_info.descriptor_pool,
.set_layouts = &.{allocate_info.set_layout},
.variable_descriptor_counts = if (allocate_info.variable_descriptor_count) |x| &.{x} else &.{},
}, &descriptor_sets);
return descriptor_sets[0];
}
pub fn allocateDescriptorSets(self: *Engine, allocate_info: DescriptorSetsAllocateInfo, descriptor_sets: []vk.DescriptorSet) !void {
std.debug.assert(descriptor_sets.len >= allocate_info.set_layouts.len);
const has_variable_descriptor_counts = allocate_info.variable_descriptor_counts.len > 0;
var p_next: ?*const anyopaque = null;
if (has_variable_descriptor_counts) {
p_next = &vk.DescriptorSetVariableDescriptorCountAllocateInfo{
.p_next = p_next,
.descriptor_set_count = @intCast(allocate_info.variable_descriptor_counts.len),
.p_descriptor_counts = allocate_info.variable_descriptor_counts.ptr,
};
}
try self.device.allocateDescriptorSets(&.{
.p_next = p_next,
.descriptor_pool = allocate_info.descriptor_pool,
.descriptor_set_count = @intCast(allocate_info.set_layouts.len),
.p_set_layouts = allocate_info.set_layouts.ptr,