adding device memory base
This commit is contained in:
51
src/vulkan/NonDispatchable.zig
git.filemode.normal_file
51
src/vulkan/NonDispatchable.zig
git.filemode.normal_file
@@ -0,0 +1,51 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
pub fn NonDispatchable(comptime T: type) type {
|
||||
return struct {
|
||||
const Self = @This();
|
||||
|
||||
object_type: vk.ObjectType,
|
||||
object: *T,
|
||||
|
||||
pub fn wrap(allocator: std.mem.Allocator, object: *T) VkError!*Self {
|
||||
const self = allocator.create(Self) catch return VkError.OutOfHostMemory;
|
||||
self.* = .{
|
||||
.object_type = T.ObjectType,
|
||||
.object = object,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
|
||||
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub inline fn toHandle(self: *Self) usize {
|
||||
return @intFromPtr(self);
|
||||
}
|
||||
|
||||
pub inline fn toVkHandle(self: *Self, comptime VkT: type) VkT {
|
||||
return @enumFromInt(@intFromPtr(self));
|
||||
}
|
||||
|
||||
pub inline fn fromHandle(vk_handle: anytype) VkError!*Self {
|
||||
const handle = @intFromEnum(vk_handle);
|
||||
if (handle == 0) {
|
||||
return VkError.Unknown;
|
||||
}
|
||||
const nondispatchable: *Self = @ptrFromInt(handle);
|
||||
if (nondispatchable.object_type != T.ObjectType) {
|
||||
return VkError.Unknown;
|
||||
}
|
||||
return nondispatchable;
|
||||
}
|
||||
|
||||
pub inline fn fromHandleObject(handle: anytype) VkError!*T {
|
||||
const nondispatchable_handle = try Self.fromHandle(handle);
|
||||
return nondispatchable_handle.object;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user