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

51
src/vulkan/NonDispatchable.zig git.filemode.normal_file
View 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;
}
};
}