9 Commits

Author SHA1 Message Date
d1902bddd6 readFileAlloc compatibility 2025-10-08 19:54:14 -04:00
Katie Hall
8961518db2 Update Zig version to latest stable (Hopefully that's good enough.) 2025-10-04 18:10:23 -07:00
Katie Hall
7acf3a1163 Fix src/main.zig using both incorrect argument order and using a nonexistant enum value (.unlimited replaced with std.math.maxInt(usize) for the closest to intended effect) 2025-10-03 09:17:37 -07:00
Robin Voetter
4b7b9a8b94 Merge pull request #205 from DialecticalMaterialist/update-zig
Update zig
2025-09-04 14:40:25 +02:00
DialecticalMaterialist
4066c2c526 Update zig 2025-09-04 14:15:52 +02:00
Robin Voetter
c9c4dae703 Merge pull request #204 from zacoons/debugMessages
Debug messages
2025-08-31 22:41:24 +02:00
zac
ecf97034c4 add debug messenger to graphics context 2025-08-30 18:27:22 +10:00
zac
3c7d4021e9 change extension_names to use vk.extensions over hardcoded string 2025-08-30 18:24:00 +10:00
Robin Voetter
f879074293 Merge pull request #203 from Snektron/vkbool32-enum
replace vk.Bool32 with enum
2025-08-26 23:07:48 +02:00
4 changed files with 39 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
.name = .vulkan,
.fingerprint = 0xbe155a03c72db6af,
.version = "0.0.0",
.minimum_zig_version = "0.15.0-dev.1518+749f10af4",
.minimum_zig_version = "0.15.1",
.paths = .{
"build.zig",
"LICENSE",

View File

@@ -35,6 +35,7 @@ pub const GraphicsContext = struct {
vkb: BaseWrapper,
instance: Instance,
debug_messenger: vk.DebugUtilsMessengerEXT,
surface: vk.SurfaceKHR,
pdev: vk.PhysicalDevice,
props: vk.PhysicalDeviceProperties,
@@ -51,10 +52,11 @@ pub const GraphicsContext = struct {
var extension_names: std.ArrayList([*:0]const u8) = .empty;
defer extension_names.deinit(allocator);
// these extensions are to support vulkan in mac os
try extension_names.append(allocator, vk.extensions.ext_debug_utils.name);
// the following extensions are to support vulkan in mac os
// see https://github.com/glfw/glfw/issues/2335
try extension_names.append(allocator, "VK_KHR_portability_enumeration");
try extension_names.append(allocator, "VK_KHR_get_physical_device_properties2");
try extension_names.append(allocator, vk.extensions.khr_portability_enumeration.name);
try extension_names.append(allocator, vk.extensions.khr_get_physical_device_properties_2.name);
var glfw_exts_count: u32 = 0;
const glfw_exts = c.glfwGetRequiredInstanceExtensions(&glfw_exts_count);
@@ -81,6 +83,22 @@ pub const GraphicsContext = struct {
self.instance = Instance.init(instance, vki);
errdefer self.instance.destroyInstance(null);
self.debug_messenger = try self.instance.createDebugUtilsMessengerEXT(&.{
.message_severity = .{
//.verbose_bit_ext = true,
//.info_bit_ext = true,
.warning_bit_ext = true,
.error_bit_ext = true,
},
.message_type = .{
.general_bit_ext = true,
.validation_bit_ext = true,
.performance_bit_ext = true,
},
.pfn_user_callback = &debugUtilsMessengerCallback,
.p_user_data = null,
}, null);
self.surface = try createSurface(self.instance, window);
errdefer self.instance.destroySurfaceKHR(self.surface, null);
@@ -107,6 +125,7 @@ pub const GraphicsContext = struct {
pub fn deinit(self: GraphicsContext) void {
self.dev.destroyDevice(null);
self.instance.destroySurfaceKHR(self.surface, null);
self.instance.destroyDebugUtilsMessengerEXT(self.debug_messenger, null);
self.instance.destroyInstance(null);
// Don't forget to free the tables to prevent a memory leak.
@@ -196,6 +215,17 @@ const QueueAllocation = struct {
present_family: u32,
};
fn debugUtilsMessengerCallback(severity: vk.DebugUtilsMessageSeverityFlagsEXT, msg_type: vk.DebugUtilsMessageTypeFlagsEXT, callback_data: ?*const vk.DebugUtilsMessengerCallbackDataEXT, _: ?*anyopaque) callconv(.c) vk.Bool32 {
const severity_str = if (severity.verbose_bit_ext) "verbose" else if (severity.info_bit_ext) "info" else if (severity.warning_bit_ext) "warning" else if (severity.error_bit_ext) "error" else "unknown";
const type_str = if (msg_type.general_bit_ext) "general" else if (msg_type.validation_bit_ext) "validation" else if (msg_type.performance_bit_ext) "performance" else if (msg_type.device_address_binding_bit_ext) "device addr" else "unknown";
const message: [*c]const u8 = if (callback_data) |cb_data| cb_data.p_message else "NO MESSAGE!";
std.debug.print("[{s}][{s}]. Message:\n {s}\n", .{ severity_str, type_str, message });
return .false;
}
fn pickPhysicalDevice(
instance: Instance,
allocator: Allocator,

View File

@@ -52,7 +52,7 @@ pub fn isZigPrimitiveType(name: []const u8) bool {
return false;
}
pub fn writeIdentifier(w: *std.io.Writer, id: []const u8) !void {
pub fn writeIdentifier(w: *std.Io.Writer, id: []const u8) !void {
try w.print("{f}", .{std.zig.fmtId(id)});
}
@@ -121,7 +121,7 @@ pub const SegmentIterator = struct {
pub const IdRenderer = struct {
tags: []const []const u8,
text_cache: std.io.Writer.Allocating,
text_cache: std.Io.Writer.Allocating,
pub fn init(allocator: Allocator, tags: []const []const u8) IdRenderer {
return .{

View File

@@ -102,18 +102,18 @@ pub fn main() !void {
};
const cwd = std.fs.cwd();
const xml_src = cwd.readFileAlloc(allocator, xml_path, std.math.maxInt(usize)) catch |err| {
const xml_src = cwd.readFileAlloc(xml_path, allocator, .unlimited) catch |err| {
std.process.fatal("failed to open input file '{s}' ({s})", .{ xml_path, @errorName(err) });
};
const maybe_video_xml_src = if (maybe_video_xml_path) |video_xml_path|
cwd.readFileAlloc(allocator, video_xml_path, std.math.maxInt(usize)) catch |err| {
cwd.readFileAlloc(video_xml_path, allocator, .unlimited) catch |err| {
std.process.fatal("failed to open input file '{s}' ({s})", .{ video_xml_path, @errorName(err) });
}
else
null;
var aw: std.io.Writer.Allocating = .init(allocator);
var aw: std.Io.Writer.Allocating = .init(allocator);
generator.generate(allocator, api, xml_src, maybe_video_xml_src, &aw.writer) catch |err| {
if (debug) {
return err;