adding device memory base
This commit is contained in:
@@ -60,7 +60,7 @@ pub fn build(b: *std.Build) void {
|
||||
.root_module = lib_mod,
|
||||
.linkage = .dynamic,
|
||||
});
|
||||
b.installArtifact(lib);
|
||||
const lib_install_step = b.addInstallArtifact(lib, .{});
|
||||
|
||||
const lib_tests = b.addTest(.{ .root_module = lib_mod });
|
||||
|
||||
@@ -90,8 +90,9 @@ pub fn build(b: *std.Build) void {
|
||||
b.installArtifact(c_test_exe);
|
||||
|
||||
const run_c_test = b.addRunArtifact(c_test_exe);
|
||||
run_c_test.step.dependOn(&lib_install_step.step);
|
||||
|
||||
const test_c_step = b.step(b.fmt("test-c-{s}", .{impl.name}), b.fmt("Run lib{s} C test", .{impl.name}));
|
||||
test_c_step.dependOn(b.getInstallStep());
|
||||
test_c_step.dependOn(&run_c_test.step);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
.{
|
||||
.name = .VulkanDriver,
|
||||
.version = "0.0.0",
|
||||
.version = "0.0.1",
|
||||
.fingerprint = 0x52cb73649f1107de,
|
||||
.minimum_zig_version = "0.15.1",
|
||||
.minimum_zig_version = "0.15.2",
|
||||
|
||||
.dependencies = .{
|
||||
.vulkan_headers = .{
|
||||
@@ -13,11 +13,6 @@
|
||||
.url = "git+https://github.com/catmeow72/vulkan-zig/#8961518db28f88d2cf09ea68e146923de2cfa7f0",
|
||||
.hash = "vulkan-0.0.0-r7Ytx6hBAwD8X_TN32qlkzul4riK6vFvjtK9fZfRvALg",
|
||||
},
|
||||
.cpuinfo = .{
|
||||
.url = "git+https://github.com/Kbz-8/cpuinfo-zig#77f82a1248194e7fb706967343c66021f8522766",
|
||||
.hash = "cpuinfo-0.1.0-V7dMLcghAADJuG7dkd3MnwDPZ232pBK_8uGjxY43eP5u",
|
||||
.lazy = true,
|
||||
},
|
||||
.zdt = .{
|
||||
.url = "git+https://github.com/FObersteiner/zdt/?ref=v0.8.1#8b551a0a3e5ae64a32b5bad0e6a93119787b43af",
|
||||
.hash = "zdt-0.8.1-xr0_vAxUDwCJRDh9pcAS_mdZBIsvcGTtN-K8JJSWY4I6",
|
||||
@@ -27,6 +22,11 @@
|
||||
.hash = "N-V-__8AAPn9BwCBHnaxOC_rffCpFI7QRfi5qBCLvov9EYK3",
|
||||
.lazy = true,
|
||||
},
|
||||
.cpuinfo = .{
|
||||
.url = "git+https://github.com/Kbz-8/cpuinfo-zig#77f82a1248194e7fb706967343c66021f8522766",
|
||||
.hash = "cpuinfo-0.1.0-V7dMLcghAADJuG7dkd3MnwDPZ232pBK_8uGjxY43eP5u",
|
||||
.lazy = true,
|
||||
},
|
||||
},
|
||||
|
||||
.paths = .{
|
||||
|
||||
@@ -37,8 +37,10 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
|
||||
interface.mem_props.memory_types[0] = .{
|
||||
.heap_index = 0,
|
||||
.property_flags = .{
|
||||
.device_local_bit = true,
|
||||
.host_visible_bit = true,
|
||||
.host_coherent_bit = true,
|
||||
.host_cached_bit = true,
|
||||
},
|
||||
};
|
||||
interface.mem_props.memory_heap_count = 1;
|
||||
|
||||
13
src/vulkan/Buffer.zig
git.filemode.normal_file
13
src/vulkan/Buffer.zig
git.filemode.normal_file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
const Device = @import("Device.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .buffer;
|
||||
|
||||
owner: *const Device,
|
||||
size: vk.DeviceSize,
|
||||
offset: vk.DeviceSize,
|
||||
usage: vk.BufferUsageFlags,
|
||||
37
src/vulkan/DeviceMemory.zig
git.filemode.normal_file
37
src/vulkan/DeviceMemory.zig
git.filemode.normal_file
@@ -0,0 +1,37 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
const VkError = @import("error_set.zig").VkError;
|
||||
const Device = @import("Device.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .device_memory;
|
||||
|
||||
owner: *const Device,
|
||||
size: vk.DeviceSize,
|
||||
memory_type_index: u32,
|
||||
is_mapped: bool,
|
||||
|
||||
vtable: *const VTable,
|
||||
|
||||
pub const VTable = struct {
|
||||
map: *const fn (*Self, vk.DeviceSize, vk.DeviceSize) VkError!?*anyopaque,
|
||||
unmap: *const fn (*Self) void,
|
||||
};
|
||||
|
||||
pub fn init(device: *const Device, size: vk.DeviceSize, memory_type_index: u32) VkError!Self {
|
||||
return .{
|
||||
.owner = device,
|
||||
.size = size,
|
||||
.memory_type_index = memory_type_index,
|
||||
.is_mapped = false,
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn map(self: *Self, offset: vk.DeviceSize, size: vk.DeviceSize) VkError!?*anyopaque {
|
||||
return self.vtable.map(self, offset, size);
|
||||
}
|
||||
|
||||
pub inline fn unmap(self: *Self) void {
|
||||
return self.vtable.unmap(self);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub const lib_vulkan = @import("lib_vulkan.zig");
|
||||
pub const logger = @import("logger.zig");
|
||||
|
||||
pub const Dispatchable = @import("Dispatchable.zig").Dispatchable;
|
||||
pub const NonDispatchable = @import("NonDispatchable.zig").NonDispatchable;
|
||||
pub const VkError = @import("error_set.zig").VkError;
|
||||
|
||||
pub const Instance = @import("Instance.zig");
|
||||
|
||||
Reference in New Issue
Block a user