working on vtable

This commit is contained in:
2025-10-29 17:39:28 +01:00
parent 610f377fac
commit 0c0bc75959
2 changed files with 19 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
const std = @import("std");
const vk = @import("vulkan"); const vk = @import("vulkan");
const PhysicalDevice = @import("PhysicalDevice").PhysicalDevice;
const Object = @import("object.zig").Object; const Object = @import("object.zig").Object;
pub const Instance = extern struct { pub const Instance = extern struct {
@@ -6,4 +8,6 @@ pub const Instance = extern struct {
const ObjectType: vk.ObjectType = .instance; const ObjectType: vk.ObjectType = .instance;
object: Object, object: Object,
physical_devices: std.ArrayList(*PhysicalDevice),
alloc_callbacks: vk.AllocationCallbacks,
}; };

View File

@@ -23,15 +23,14 @@ pub const Object = extern struct {
}; };
pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T { pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T {
if (handle == .null_handle) { comptime {
return error.NullHandle; 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")) { if (handle == .null_handle) {
return error.NotAnObject; return error.NullHandle;
}
if (!@hasDecl(T, "ObjectType") || @TypeOf(T.ObjectType) != vk.ObjectType) {
@panic("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
} }
const dispatchable: *T = @ptrFromInt(@intFromEnum(handle)); 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; 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);
}