adding object base
This commit is contained in:
9
src/vulkan/Instance.zig
git.filemode.normal_file
9
src/vulkan/Instance.zig
git.filemode.normal_file
@@ -0,0 +1,9 @@
|
||||
const vk = @import("vulkan");
|
||||
const Object = @import("object.zig").Object;
|
||||
|
||||
pub const Instance = extern struct {
|
||||
const Self = @This();
|
||||
const ObjectType: vk.ObjectType = .instance;
|
||||
|
||||
object: Object,
|
||||
};
|
||||
14
src/vulkan/PhysicalDevice.zig
git.filemode.normal_file
14
src/vulkan/PhysicalDevice.zig
git.filemode.normal_file
@@ -0,0 +1,14 @@
|
||||
const vk = @import("vulkan");
|
||||
const Instance = @import("Instance.zig").Instance;
|
||||
const Object = @import("object.zig").Object;
|
||||
|
||||
pub const PhysicalDevice = extern struct {
|
||||
const Self = @This();
|
||||
const ObjectType: vk.ObjectType = .physical_device;
|
||||
|
||||
object: Object,
|
||||
|
||||
instance: *Instance,
|
||||
props: vk.PhysicalDeviceProperties,
|
||||
queue_families: [3]vk.QueueFamilyProperties,
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const Instance = @import("Instance.zig");
|
||||
pub const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||
|
||||
test {
|
||||
std.testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
42
src/vulkan/object.zig
git.filemode.normal_file
42
src/vulkan/object.zig
git.filemode.normal_file
@@ -0,0 +1,42 @@
|
||||
const vk = @import("vulkan");
|
||||
const c = @cImport({
|
||||
@cInclude("vulkan/vk_icd.h");
|
||||
});
|
||||
|
||||
pub const Object = extern struct {
|
||||
const Self = @This();
|
||||
|
||||
loader_data: c.VK_LOADER_DATA,
|
||||
kind: vk.ObjectType,
|
||||
owner: ?*anyopaque,
|
||||
// VK_EXT_debug_utils
|
||||
name: ?[]const u8,
|
||||
|
||||
pub fn init(owner: ?*anyopaque, kind: vk.ObjectType) Self {
|
||||
return .{
|
||||
.loader_data = c.ICD_LOADER_MAGIC,
|
||||
.kind = kind,
|
||||
.owner = owner,
|
||||
.name = null,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T {
|
||||
if (handle == .null_handle) {
|
||||
return error.NullHandle;
|
||||
}
|
||||
|
||||
if (!@hasDecl(T, "object")) {
|
||||
return error.NotAnObject;
|
||||
}
|
||||
if (!@hasDecl(T, "ObjectType") || @TypeOf(T.ObjectType) != vk.ObjectType) {
|
||||
@panic("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
|
||||
}
|
||||
|
||||
const dispatchable: *T = @ptrFromInt(@intFromEnum(handle));
|
||||
if (dispatchable.object.kind != T.ObjectType) {
|
||||
return error.InvalidObjectType;
|
||||
}
|
||||
return dispatchable;
|
||||
}
|
||||
Reference in New Issue
Block a user