fixing module export
This commit is contained in:
@@ -9,7 +9,7 @@ const ImplementationDesc = struct {
|
||||
const implementations = [_]ImplementationDesc{
|
||||
.{
|
||||
.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 {
|
||||
const Self = @This();
|
||||
pub const ObjectType: vk.ObjectType = .instance;
|
||||
pub const vtable: *const VTable = .{};
|
||||
pub const vtable: VTable = .{};
|
||||
|
||||
object: Object,
|
||||
//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,
|
||||
createInstance: ?vk.PfnCreateInstance = null,
|
||||
destroyInstance: ?vk.PfnDestroyInstance = null,
|
||||
enumeratePhysicalDevices: ?vk.PfnEnumeratePhysicalDevices = null,
|
||||
getInstanceProcAddr: ?vk.PfnGetInstanceProcAddr = null,
|
||||
enumerateInstanceVersion: ?vk.PfnEnumerateInstanceVersion = null,
|
||||
//enumerateInstanceLayerProperties: vk.PfnEnumerateInstanceProperties = null,
|
||||
enumerateInstanceExtensionProperties: ?vk.PfnEnumerateInstanceExtensionProperties = null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -7,18 +7,15 @@ const c = @cImport({
|
||||
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 .{};
|
||||
const global_pfn_map = std.StaticStringMap(vk.PfnVoidFunction).initComptime(.{
|
||||
.{ "vkGetInstanceProcAddr", @as(vk.PfnVoidFunction, @ptrCast(&getInstanceProcAddr)) },
|
||||
.{ "vkCreateInstance", @as(vk.PfnVoidFunction, @ptrCast(&Instance.vtable.createInstance)) },
|
||||
});
|
||||
|
||||
inline for (.{
|
||||
"vkCreateInstance",
|
||||
"vkDestroyInstance",
|
||||
"vkGetInstanceProcAddr",
|
||||
}) |sym| {
|
||||
if (std.mem.eql(u8, name, sym)) {
|
||||
//const f = @field(Instance.vtable, sym);
|
||||
return @ptrFromInt(12);
|
||||
}
|
||||
pub fn getInstanceProcAddr(instance: vk.Instance, name: []const u8) vk.PfnVoidFunction {
|
||||
if (global_pfn_map.get(name)) |pfn| {
|
||||
return pfn;
|
||||
}
|
||||
if (instance != .null_handle) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
|
||||
pub const icd = @import("icd.zig");
|
||||
|
||||
pub const Instance = @import("Instance.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 {
|
||||
std.testing.refAllDeclsRecursive(@This());
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ int main(void)
|
||||
printf("openning ./zig-out/lib/lib" LIBVK ".so\n");
|
||||
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"));
|
||||
|
||||
dlclose(lib);
|
||||
|
||||
Reference in New Issue
Block a user