From 0c0bc759593a823d039f9099c360d024bc7b8df5 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 29 Oct 2025 17:39:28 +0100 Subject: [PATCH] working on vtable --- src/vulkan/Instance.zig | 4 ++++ src/vulkan/object.zig | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/vulkan/Instance.zig b/src/vulkan/Instance.zig index 6677dbc..b0d9b95 100644 --- a/src/vulkan/Instance.zig +++ b/src/vulkan/Instance.zig @@ -1,4 +1,6 @@ +const std = @import("std"); const vk = @import("vulkan"); +const PhysicalDevice = @import("PhysicalDevice").PhysicalDevice; const Object = @import("object.zig").Object; pub const Instance = extern struct { @@ -6,4 +8,6 @@ pub const Instance = extern struct { const ObjectType: vk.ObjectType = .instance; object: Object, + physical_devices: std.ArrayList(*PhysicalDevice), + alloc_callbacks: vk.AllocationCallbacks, }; diff --git a/src/vulkan/object.zig b/src/vulkan/object.zig index b12cb48..e964c30 100644 --- a/src/vulkan/object.zig +++ b/src/vulkan/object.zig @@ -23,15 +23,14 @@ pub const Object = extern struct { }; pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T { - if (handle == .null_handle) { - return error.NullHandle; + comptime { + if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) { + @compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed."); + } } - if (!@hasDecl(T, "object")) { - return error.NotAnObject; - } - if (!@hasDecl(T, "ObjectType") || @TypeOf(T.ObjectType) != vk.ObjectType) { - @panic("Object type \"" ++ @typeName(T) ++ "\" is malformed."); + if (handle == .null_handle) { + return error.NullHandle; } const dispatchable: *T = @ptrFromInt(@intFromEnum(handle)); @@ -40,3 +39,12 @@ pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T } return dispatchable; } + +pub inline fn toHandle(comptime T: type, handle: *T) usize { + comptime { + if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) { + @compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed."); + } + } + return @intFromPtr(handle); +}