forked from vv/efemra
1
0
Fork 0
efemra/src/rendering/vulkan/Extensions.zig

74 lines
2.2 KiB
Zig

const std = @import("std");
const vk = @import("vulkan");
const settings = @import("settings.zig");
pub const Device = struct {
khr_swapchain: bool,
ext_memory_budget: bool,
ext_hdr_metadata: bool,
khr_shader_float_16_int_8: bool,
khr_1_6bit_storage: bool,
khr_push_descriptor: bool,
ext_memory_priority: bool,
khr_bind_memory_2: bool,
khr_shader_float_controls: bool,
khr_spirv_1_4: bool,
ext_conditional_rendering: bool,
khr_draw_indirect_count: bool,
khr_acceleration_structure: if (settings.rt_on) bool else void,
khr_ray_tracing_pipeline: if (settings.rt_on) bool else void,
khr_ray_query: if (settings.rt_on) bool else void,
khr_deferred_host_operations: if (settings.rt_on) bool else void,
pub fn get(props: []vk.ExtensionProperties) @This() {
return getExtensions(@This(), props);
}
pub fn toArray(allocator: std.mem.Allocator) [][*:0]const u8 {
return extToArray(@This(), allocator);
}
};
pub const Instance = struct {
khr_get_physical_device_properties_2: bool,
ext_swapchain_colorspace: bool,
ext_debug_utils: if (settings.messenger_on) bool else void,
pub fn get(props: []vk.ExtensionProperties) @This() {
return getExtensions(@This(), props);
}
pub fn toArray(allocator: std.mem.Allocator) [][*:0]const u8 {
return extToArray(@This(), allocator);
}
};
fn getExtensions(comptime T: type, props: []vk.ExtensionProperties) T {
var ext: T = undefined;
inline for (@typeInfo(T).Struct.fields) |field| {
if (field.field_type == void) {
continue;
}
for (props) |prop| {
const ext_name = std.mem.sliceTo(&prop.extension_name, 0);
if (std.ascii.eqlIgnoreCase(ext_name, "vk_" ++ field.name)) {
@field(ext, field.name) = true;
}
}
}
return ext;
}
pub fn extToArray(comptime T: type, allocator: std.mem.Allocator) [][*:0]const u8 {
const arr = allocator.alloc([*:0]const u8, @typeInfo(T).Struct.fields.len) catch unreachable;
comptime for (@typeInfo(T).Struct.fields) |field, i| {
const name_info = @field(vk.extension_info, field.name);
arr[i] = name_info.name;
};
return arr;
}