adding entry point to soft driver, adding C test

This commit is contained in:
2025-10-29 21:55:28 +01:00
parent 0c0bc75959
commit 6d559d719a
8 changed files with 97 additions and 13 deletions

View File

@@ -1,13 +1,24 @@
const std = @import("std");
const vk = @import("vulkan");
const PhysicalDevice = @import("PhysicalDevice").PhysicalDevice;
const PhysicalDevice = @import("PhysicalDevice.zig").PhysicalDevice;
const Object = @import("object.zig").Object;
pub const Instance = extern struct {
const Self = @This();
const ObjectType: vk.ObjectType = .instance;
pub const ObjectType: vk.ObjectType = .instance;
pub const vtable: *const VTable = .{};
object: Object,
physical_devices: std.ArrayList(*PhysicalDevice),
//physical_devices: std.ArrayList(*PhysicalDevice),
alloc_callbacks: vk.AllocationCallbacks,
pub const VTable = struct {
createInstance: ?vk.PfnCreateInstance,
destroyInstance: ?vk.PfnDestroyInstance,
enumeratePhysicalDevices: ?vk.PfnEnumeratePhysicalDevices,
getInstanceProcAddr: ?vk.PfnGetInstanceProcAddr,
enumerateInstanceVersion: ?vk.PfnEnumerateInstanceVersion,
//enumerateInstanceLayerProperties: vk.PfnEnumerateInstanceProperties,
enumerateInstanceExtensionProperties: ?vk.PfnEnumerateInstanceExtensionProperties,
};
};

24
src/vulkan/icd.zig git.filemode.normal_file
View File

@@ -0,0 +1,24 @@
const std = @import("std");
const vk = @import("vulkan");
const c = @cImport({
@cInclude("vulkan/vk_icd.h");
});
const Instance = @import("Instance.zig").Instance;
const fromHandle = @import("object.zig").fromHandle;
pub fn getInstanceProcAddr(vk_instance: vk.Instance, name: []const u8) vk.PfnVoidFunction {
_ = fromHandle(Instance, vk.Instance, vk_instance) catch .{};
inline for (.{
"vkCreateInstance",
"vkDestroyInstance",
"vkGetInstanceProcAddr",
}) |sym| {
if (std.mem.eql(u8, name, sym)) {
//const f = @field(Instance.vtable, sym);
return @ptrFromInt(12);
}
}
return null;
}

View File

@@ -1,5 +1,7 @@
const std = @import("std");
pub const icd = @import("icd.zig");
pub const Instance = @import("Instance.zig");
pub const PhysicalDevice = @import("PhysicalDevice.zig");

View File

@@ -10,7 +10,7 @@ pub const Object = extern struct {
kind: vk.ObjectType,
owner: ?*anyopaque,
// VK_EXT_debug_utils
name: ?[]const u8,
name: ?[*]const u8,
pub fn init(owner: ?*anyopaque, kind: vk.ObjectType) Self {
return .{
@@ -24,7 +24,7 @@ pub const Object = extern struct {
pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T {
comptime {
if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
if (!@hasField(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
@compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
}
}