fixing module export
This commit is contained in:
@@ -9,7 +9,7 @@ const ImplementationDesc = struct {
|
|||||||
const implementations = [_]ImplementationDesc{
|
const implementations = [_]ImplementationDesc{
|
||||||
.{
|
.{
|
||||||
.name = "soft",
|
.name = "soft",
|
||||||
.root_source_file = "src/soft/libvulkan.zig",
|
.root_source_file = "src/soft/lib.zig",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
7
src/soft/lib.zig
git.filemode.normal_file
7
src/soft/lib.zig
git.filemode.normal_file
@@ -0,0 +1,7 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const vk = @import("vulkan");
|
||||||
|
const common = @import("common");
|
||||||
|
|
||||||
|
export fn libVulkanExport() void {
|
||||||
|
_ = common;
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const vk = @import("vulkan");
|
|
||||||
const common = @import("common");
|
|
||||||
|
|
||||||
pub export fn vk_icdGetInstanceProcAddr(instance: vk.Instance, pName: ?[*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction {
|
|
||||||
if (pName == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const name = std.mem.span(pName.?);
|
|
||||||
return common.icd.getInstanceProcAddr(instance, name);
|
|
||||||
}
|
|
||||||
@@ -6,19 +6,19 @@ const Object = @import("object.zig").Object;
|
|||||||
pub const Instance = extern struct {
|
pub const Instance = extern struct {
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
pub const ObjectType: vk.ObjectType = .instance;
|
pub const ObjectType: vk.ObjectType = .instance;
|
||||||
pub const vtable: *const VTable = .{};
|
pub const vtable: VTable = .{};
|
||||||
|
|
||||||
object: Object,
|
object: Object,
|
||||||
//physical_devices: std.ArrayList(*PhysicalDevice),
|
//physical_devices: std.ArrayList(*PhysicalDevice),
|
||||||
alloc_callbacks: vk.AllocationCallbacks,
|
alloc_callbacks: vk.AllocationCallbacks,
|
||||||
|
|
||||||
pub const VTable = struct {
|
pub const VTable = struct {
|
||||||
createInstance: ?vk.PfnCreateInstance,
|
createInstance: ?vk.PfnCreateInstance = null,
|
||||||
destroyInstance: ?vk.PfnDestroyInstance,
|
destroyInstance: ?vk.PfnDestroyInstance = null,
|
||||||
enumeratePhysicalDevices: ?vk.PfnEnumeratePhysicalDevices,
|
enumeratePhysicalDevices: ?vk.PfnEnumeratePhysicalDevices = null,
|
||||||
getInstanceProcAddr: ?vk.PfnGetInstanceProcAddr,
|
getInstanceProcAddr: ?vk.PfnGetInstanceProcAddr = null,
|
||||||
enumerateInstanceVersion: ?vk.PfnEnumerateInstanceVersion,
|
enumerateInstanceVersion: ?vk.PfnEnumerateInstanceVersion = null,
|
||||||
//enumerateInstanceLayerProperties: vk.PfnEnumerateInstanceProperties,
|
//enumerateInstanceLayerProperties: vk.PfnEnumerateInstanceProperties = null,
|
||||||
enumerateInstanceExtensionProperties: ?vk.PfnEnumerateInstanceExtensionProperties,
|
enumerateInstanceExtensionProperties: ?vk.PfnEnumerateInstanceExtensionProperties = null,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,18 +7,15 @@ const c = @cImport({
|
|||||||
const Instance = @import("Instance.zig").Instance;
|
const Instance = @import("Instance.zig").Instance;
|
||||||
const fromHandle = @import("object.zig").fromHandle;
|
const fromHandle = @import("object.zig").fromHandle;
|
||||||
|
|
||||||
pub fn getInstanceProcAddr(vk_instance: vk.Instance, name: []const u8) vk.PfnVoidFunction {
|
const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||||
_ = fromHandle(Instance, vk.Instance, vk_instance) catch .{};
|
.{ "vkGetInstanceProcAddr", @as(vk.PfnVoidFunction, @ptrCast(&getInstanceProcAddr)) },
|
||||||
|
.{ "vkCreateInstance", @as(vk.PfnVoidFunction, @ptrCast(&Instance.vtable.createInstance)) },
|
||||||
|
});
|
||||||
|
|
||||||
inline for (.{
|
pub fn getInstanceProcAddr(instance: vk.Instance, name: []const u8) vk.PfnVoidFunction {
|
||||||
"vkCreateInstance",
|
if (global_pfn_map.get(name)) |pfn| {
|
||||||
"vkDestroyInstance",
|
return pfn;
|
||||||
"vkGetInstanceProcAddr",
|
|
||||||
}) |sym| {
|
|
||||||
if (std.mem.eql(u8, name, sym)) {
|
|
||||||
//const f = @field(Instance.vtable, sym);
|
|
||||||
return @ptrFromInt(12);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (instance != .null_handle) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const vk = @import("vulkan");
|
||||||
|
|
||||||
pub const icd = @import("icd.zig");
|
pub const icd = @import("icd.zig");
|
||||||
|
|
||||||
pub const Instance = @import("Instance.zig");
|
pub const Instance = @import("Instance.zig");
|
||||||
pub const PhysicalDevice = @import("PhysicalDevice.zig");
|
pub const PhysicalDevice = @import("PhysicalDevice.zig");
|
||||||
|
|
||||||
|
pub export fn vkGetInstanceProcAddr(instance: vk.Instance, pName: ?[*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction {
|
||||||
|
if (pName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const name = std.mem.span(pName.?);
|
||||||
|
return icd.getInstanceProcAddr(instance, name);
|
||||||
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
std.testing.refAllDeclsRecursive(@This());
|
std.testing.refAllDeclsRecursive(@This());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ int main(void)
|
|||||||
printf("openning ./zig-out/lib/lib" LIBVK ".so\n");
|
printf("openning ./zig-out/lib/lib" LIBVK ".so\n");
|
||||||
void* lib = dlopen("./zig-out/lib/lib" LIBVK ".so", RTLD_NOW | RTLD_LOCAL);
|
void* lib = dlopen("./zig-out/lib/lib" LIBVK ".so", RTLD_NOW | RTLD_LOCAL);
|
||||||
|
|
||||||
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dlsym(lib, "vk_icdGetInstanceProcAddr");
|
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = dlsym(lib, "vkGetInstanceProcAddr");
|
||||||
|
|
||||||
|
printf("test %p\n", vkGetInstanceProcAddr);
|
||||||
printf("test %p\n", vkGetInstanceProcAddr(NULL, "vkCreateInstance"));
|
printf("test %p\n", vkGetInstanceProcAddr(NULL, "vkCreateInstance"));
|
||||||
|
|
||||||
dlclose(lib);
|
dlclose(lib);
|
||||||
|
|||||||
Reference in New Issue
Block a user