adding device memory base
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user