Comments (10)
Good point, I hadn't thought about that, and it just happened to work so my brain decided that "welp, our work here is done".
from mach.
pub fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*:0]const u8) callconv(.C) ?VKProc {
const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
There is a calling convention mismatch here, getInstanceProcAddress
is defined as having the C calling convention, while it's cast to a function pointer with unspecified calling convention. Note that the load
function for Wrappers does not require any specific calling convention, specifically to allow you to load using functions that do not necessarily follow the Vulkan calling convention. This means that
- pub fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*:0]const u8) callconv(.C) ?VKProc {
+ pub fn getInstanceProcAddress(vk_instance: ?*opaque {}, proc_name: [*:0]const u8) ?VKProc {
and
const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
self.vkb = try BaseDispatch.load(vk_proc);
should also resolve the problem.
from mach.
It's definitely a weird issue; your fix does stop the panic from happening, but removing the 'getError' call and catch also stops it. As well, when I run it with gdb, without the fix, it seems to panic before even calling root.main
, instead panicking in 'start.zig', while measuring the c_envp
parameter of start.main
. On Windows 10 at least.
from mach.
Indeed, then we know the issue is cross platform as i tested on ubuntu 20.04.
I'm am having issues other places in my code on release, so I am starting to suspect there might be some weird miss compilations in zig master.
from mach.
After flipping a bunch of knobs on and off, I've discovered what I believe to be the culprit: in 'graphics_context.zig', inside the function GraphicsContext.init
, the line of code:
const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
It would seem that the issue here is to do with calling convention. By changing the line of code to:
const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) callconv(vk.vulkan_call_conv) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
The panic no longer occurs, so it is very probable that the issue here is how the compiler is deciding to call the function that is calling all the weirdness.
Edit: in fact, this is probably even better:
const vk_proc = @ptrCast(vk.PfnGetInstanceProcAddr, glfw.getInstanceProcAddress);
from mach.
Tested and works. Good job! I'll close this issue, but keep the issue on the vulkan project.
from mach.
Thanks for reporting this and debugging! You are definitely right about the pointer cast missing a calling convention being the culprit here.
However, I want to call out that using vk.vulkan_call_conv
is not right in this case. You should use callconv(.C)
I believe as this is a GLFW C proc, not a Vulkan proc, as I described previously in #49 (comment)
Unfortunately, vulkan-zig does not declare vk.PfnGetInstanceProcAddr
with the correct calling convention either, I have filed an issue: Snektron/vulkan-zig#30
The most correct change I see, aside from fixing that issue in zig-vulkan, is the following:
-const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
+const vk_proc = @ptrCast(fn(instance: vk.Instance, procname: [*:0]const u8) callconv(.C) vk.PfnVoidFunction, glfw.getInstanceProcAddress);
from mach.
Since the mach wrapper does not really add any direct improvements, I vote for it to simply forward export of the function instead of having its own wrapper implementation. The only issue is that getError() will pollute other functions. A wrapper implementation could be introduced if this shows to be a problem
from mach.
Which error(s) does it panic with? Is it 'ApiUnavailable'?
from mach.
Which error(s) does it panic with? Is it 'ApiUnavailable'?
Included in the original issue: thread 1030138 panic: reached unreachable code
from mach.
Related Issues (20)
- {core,engine}: sysgpu disabled in v0.3 due to lack of optional Zig dependencies; spirv-cross/spirv-tools are indirect and take a while to build
- core: autodoc segfaults the build if enabled, after Zig 2024.1.0-mach update HOT 1
- core: custom entrypoint build API design broken after Zig 2024.1.0-mach update
- all: nominate Zig 2024.03 HOT 2
- sysgpu: SPIR-V code gen fails on else ifs
- 100% banish usingnamespace from all of our codebases
- all: Mach 0.3 release checklist
- all: eliminate `sdkPath` HOT 3
- sysaudio: runtime alignment error when converting samples on Windows HOT 1
- core: window size not restored on leaving .fullscreen to .windowed.
- all: change addPaths(step) -> addPaths(mod); fix linux -> macOS cross-compilation
- docs: should be more clear about required Zig version in getting-started guides
- docs: suggest using zig fetch --save
- all: use snake_case for package names and build CLI flags
- sysgpu: provide clear default values instead of WebGPU 'undefined' default values HOT 3
- sysaudio: opus play.zig example crashes after a few seconds of playing HOT 1
- docs: provide guidance/tooling for app distribution (packaging, code signing, notarization, installers, etc.)
- glfw may not build on Arch Linux, why? HOT 1
- all: use Wayland by default once it is stable/reliable/good enough consistently HOT 3
- sysgpu: metal: pbr-basic codegen failure HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mach.