Introduce depth buffer finally
This commit is contained in:
@@ -12,6 +12,7 @@ pub const Usage = enum {
|
||||
normal,
|
||||
occlusion_roughness_metallic,
|
||||
emissive,
|
||||
depth,
|
||||
|
||||
pub fn vkFormat(self: Usage) vk.Format {
|
||||
return switch (self) {
|
||||
@@ -19,6 +20,7 @@ pub const Usage = enum {
|
||||
.normal => .r8g8b8a8_snorm,
|
||||
.occlusion_roughness_metallic => .r8g8b8a8_unorm,
|
||||
.emissive => .r16g16b16a16_sfloat,
|
||||
.depth => .d32_sfloat,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -28,6 +30,7 @@ pub const Usage = enum {
|
||||
.normal => 4,
|
||||
.occlusion_roughness_metallic => 4,
|
||||
.emissive => 4,
|
||||
.depth => 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,6 +40,7 @@ pub const Usage = enum {
|
||||
.normal => i8,
|
||||
.occlusion_roughness_metallic => u8,
|
||||
.emissive => f16,
|
||||
.depth => f32,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -80,6 +84,11 @@ pub fn init(engine: *Engine, init_info: InitInfo) !Texture {
|
||||
};
|
||||
const transfer_queue_family = engine.transfer_queue.allocation.family;
|
||||
|
||||
const queue_family_indices: []const u32 = if (init_info.usage == .depth)
|
||||
&.{target_queue_family}
|
||||
else
|
||||
&.{ target_queue_family, transfer_queue_family };
|
||||
|
||||
const image = try engine.createImage(.{
|
||||
.image_type = .@"2d",
|
||||
.format = init_info.usage.vkFormat(),
|
||||
@@ -93,10 +102,11 @@ pub fn init(engine: *Engine, init_info: InitInfo) !Texture {
|
||||
.samples = .{ .@"1_bit" = true },
|
||||
.tiling = .optimal,
|
||||
.usage = .{
|
||||
.transfer_dst_bit = true,
|
||||
.sampled_bit = true,
|
||||
.depth_stencil_attachment_bit = init_info.usage == .depth,
|
||||
.transfer_dst_bit = init_info.usage != .depth,
|
||||
.sampled_bit = init_info.usage != .depth,
|
||||
},
|
||||
.queue_family_indices = &.{ target_queue_family, transfer_queue_family },
|
||||
.queue_family_indices = queue_family_indices,
|
||||
.initial_layout = .undefined,
|
||||
});
|
||||
errdefer engine.destroyImage(image);
|
||||
@@ -112,7 +122,10 @@ pub fn init(engine: *Engine, init_info: InitInfo) !Texture {
|
||||
.view_type = .@"2d",
|
||||
.format = init_info.usage.vkFormat(),
|
||||
.subresource_range = .{
|
||||
.aspect_mask = .{ .color_bit = true },
|
||||
.aspect_mask = .{
|
||||
.color_bit = init_info.usage != .depth,
|
||||
.depth_bit = init_info.usage == .depth,
|
||||
},
|
||||
.base_mip_level = 0,
|
||||
.level_count = 1,
|
||||
.base_array_layer = 0,
|
||||
@@ -167,6 +180,7 @@ pub fn writeRaw(self: Texture, engine: *Engine, data: []const u8) !void {
|
||||
const texel_count = try std.math.mul(u32, self.width, self.height);
|
||||
const byte_length = try std.math.mul(u32, texel_count, self.usage.bytesPerTexel());
|
||||
std.debug.assert(data.len == byte_length);
|
||||
std.debug.assert(self.usage != .depth);
|
||||
|
||||
var staging_buffer = try StagingBuffer.init(engine, .{
|
||||
.capacity = @intCast(byte_length),
|
||||
|
||||
Reference in New Issue
Block a user