-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getInstanceProcAddress can't be used with zig-vulkan #49
Comments
This works: mach-glfw: pub fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*c]const u8) callconv(.C) ?VKProc {
const proc_address = c.glfwGetInstanceProcAddress(if (vk_instance) |v| @ptrCast(c.VkInstance, v) else null, proc_name);
getError() catch {}; // ignore errors for now
if (proc_address) |addr| return addr;
return null;
} user code: // load base dispatch wrapper
const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
self.vkb = try dispatch.Base.load(vk_proc); |
Thanks for flagging this, I knew the Vulkan procs had a different calling convention but didn't realize I had made them inline - habit from working on this code I suppose :) I think we can preserve the ABI as you suggest even without returning a different implementation, by simply panicking on error and indicating that we do so in the docstring. That's not perfect, but preserving ABI seems far more important for this function. This also generally matches the C usage of the function: mach/glfw/upstream/glfw/include/GLFW/glfw3.h Lines 5754 to 5755 in 3d38f56
mach/glfw/upstream/glfw/include/GLFW/glfw3.h Lines 5757 to 5758 in 3d38f56
For ours, it will just be a requirement that the caller has ensured GLFW is initialized and that |
One thing related to glfw init checks: in zig it is trivial to move such a check do compile time! Of course it would be a lot of work simply because of the scale of the API |
I don't think it's possible if your initialization requires heap allocation (which is true in the case of Unless I've misunderstood something and you have a trick there for enforcing at comptime that a runtime function is to be called. |
It's possible. The example i sent shows code that does it. You can run custom checks on compile time in your functions to verify on compile time whether the user has called glfw.init at any point in the code base. It might however not be something that we would want in the library 😅 |
Very interesting, will read more into this later and come back with more
informed thoughts :)
|
One thing I should note: The actual calling convention of this is not the same as the Vulkan calling convention you had posted in the issue description. The GLFW definition is:
And
So, it's the C calling convention (since And actually if we look closely at the generate Zig code you had posted, we can also see it doesn't specify a calling convention either. Now, having the C calling convention specified here is still a good idea (someone may want to pass this into a C library) - just thought I'd note this. |
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes #49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes #49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes #49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes #49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Should be fixed, will sync to the mach-glfw repo later today. Also created follow-up issues for doing the same for OpenGL proc addr functions, and for investigating the comptime init idea: |
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes hexops/mach#49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Having `glfw.getInstanceProcAddress` conform to the GLFW C ABI is important as it is often likely to be passed into libraries which expect exactly that ABI, e.g. zig-vulkan. Fixes hexops/mach#49 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
glfwGetInstanceProcAddress is used in zig-vulkan to gather all function addresses required for the requested vkInstance. Here is a generated code example:
In the definition of glfw.getInstanceProcAddress there are two major issues.
vulkan_call_conv
which is defined as:I'm unsure how this should be resolved, but two suggestions are:
ABI = enum { Preserved, NotPreserved }
where based on input enum it returns either current implementation or a true to ABI functionThe text was updated successfully, but these errors were encountered: