adding device memory base

This commit is contained in:
2025-11-08 01:00:30 +01:00
parent 7fdc02c260
commit 4b23abe795
8 changed files with 115 additions and 37 deletions

View File

@@ -13,30 +13,6 @@ pub fn Dispatchable(comptime T: type) type {
loader_data: c.VK_LOADER_DATA,
object_type: vk.ObjectType,
object: *T,
is_owner: bool = false,
pub fn create(allocator: std.mem.Allocator, args: anytype) VkError!*Self {
comptime {
const ti = @typeInfo(@TypeOf(args));
if (ti != .@"struct" or !ti.@"struct".is_tuple) {
@compileError("pass a tuple literal like .{...}");
}
if (!std.meta.hasMethod(T, "init")) {
@compileError("Dispatchable types are expected to have 'init' and 'deinit' methods.");
}
const init_params = @typeInfo(@TypeOf(T.init)).@"fn".params;
if (init_params.len < 1 or init_params[0].type != std.mem.Allocator) {
@compileError("Dispatchable types 'init' method should take a 'std.mem.Allocator' as its first parameter.");
}
}
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
const object = allocator.create(T) catch return VkError.OutOfHostMemory;
object.* = try @call(.auto, T.init, .{allocator} ++ args);
self.is_owner = true;
return self.wrap(object);
}
pub fn wrap(allocator: std.mem.Allocator, object: *T) VkError!*Self {
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
@@ -48,10 +24,7 @@ pub fn Dispatchable(comptime T: type) type {
return self;
}
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
if (self.is_owner) {
allocator.destroy(self.object);
}
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
allocator.destroy(self);
}