What's the state of the art in Zig ecosystem for Wayland+Vulkan without libc? 2

Yes, that is my understanding. And I was able to give it a test on a different computer with an Nvidia card and can confirm that that if fails at the DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE call.

I’d like to drill into this once I have things more stable on the AMD side. There must be some way to coerce the Nvidia driver into spitting out a syncobj.

Yeah, same error for me, nixos + niri(patched) + nvidia.

On nvidia you don’t make the syncobj yourself though. The driver creates one inside the WSI.

for nvidia I think you can only use implicit-sync or wait for the 2473 to be implemented.

so really depends on if you want to support nvidia right now or just make progress on amd

1 Like

It works!!

4 Likes

With the efforts of @Daskie and @TibboddiT combined, I think we’re looking at something quite interesting indeed…

4 Likes

A data point from Asahi Linux (M1) - Linux mbpp 6.19.14-400.asahi.fc42.aarch64+16k

I switched the target to -Dtarget=aarch64-linux-gnu and it built first time :slight_smile: but running gave:

error(vk_general): loader_validate_layers: Layer 0 does not exist in the list of available layers

Looking at the code, it seems to use/request a validation layer, so I switched to --release=fast and then I got:

info(vulkan): Physical device name: "Apple M1 Pro (G13S C0)", type: integrated_gpu, API version: 1.4.328, driver version: 104869894 error: NoValidMemoryType

So I hacked the code a bit to match what I was seeing from my vulkaninfo output, and I ended up with this:

fn _initMemoryTypeIndices() !void {
    const properties = vki.getPhysicalDeviceMemoryProperties(physicalDevice);
    for (0..properties.memory_heap_count) |i| {
        const heapType = properties.memory_heaps[i];
        if (heapType.flags.device_local_bit) {
            deviceMemoryTypeIndex = @intCast(i);
            break;
        }
    } else {
        return error.NoValidMemoryType;
    }

    for (0..properties.memory_type_count) |i| {
        const memoryType = properties.memory_types[i];
        if (memoryType.property_flags.host_visible_bit and
            memoryType.property_flags.host_coherent_bit and
            !memoryType.property_flags.host_cached_bit and
            memoryType.property_flags.device_local_bit) {
            hostMemoryTypeIndex = @intCast(i);
            break;
        }
    } else {
        return error.NoValidMemoryType;
    }
}

And the great news is that it now works!!! 60fps butterly smooth resize, drag, and can get to fullscreen and back. Nice work all!! But oh poo! what have you done, I thought I’d given up on games development :slight_smile:

6 Likes

Not just game development.

The era for zig (no libc) graphics applications has begun.

Next step, linux kernel integration :face_savoring_food:

7 Likes

why doesn’t the Zig repo have a shell.nix? I saw you use it in a talk/conference


not even a single .nix file, not trying to make Zig have one, I’m just curious for why

I’m getting a panic when I try this (Version 29064d0c):

➜  presentation-example git:(main) ✗ zig-out/bin/test                   
WARNING: radv is not a conformant Vulkan implementation, testing use only.
info(vulkan): Physical device name: "AMD Radeon RX 9060 XT (RADV GFX1200)", type: discrete_gpu, API version: 1.4.348, driver version: 109056003
thread 869897 panic: 
/home/pauls/Research/zig/presentation-example/window/window.zig:152:21: 0x121c417 in init (window.zig)
                    @panic("");
                    ^
/home/pauls/Research/zig/presentation-example/test/test.zig:15:16: 0x11f0e0d in main (test.zig)
    window.init(.{
               ^
/home/pauls/.cache/zig/p/N-V-__8AAFFSVRWqblwBIcA-Yqv-u7sbjsJoww8K0mWaHbmJ/lib/std/start.zig:699:88: 0x11f17a8 in callMain (std.zig)
    if (fn_info.params[0].type.? == std.process.Init.Minimal) return wrapMain(root.main(.{
                                                                                       ^
???:?:?: 0x7f678da27740 in ??? (/usr/lib/libc.so.6)
???:?:?: 0x7f678da27878 in ??? (/usr/lib/libc.so.6)
/home/pauls/.cache/zig/p/N-V-__8AAFFSVRWqblwBIcA-Yqv-u7sbjsJoww8K0mWaHbmJ/lib/libc/glibc/sysdeps/x86_64/start-2.33.S:120: 0x12657e9 in ??? (/home/pauls/.cache/zig/p/N-V-__8AAFFSVRWqblwBIcA-Yqv-u7sbjsJoww8K0mWaHbmJ/lib/libc/glibc/sysdeps/x86_64/start-2.33.S)
	call *__libc_start_main@GOTPCREL(%rip)

[2]    869897 abort (core dumped)  zig-out/bin/test

window.zig
----------
    // Check that all globals are found
        for (std.enums.values(_WlGlobal)) |global| {
            if (_wlGlobalNames.get(global) == 0) {
                // Allow XDG Decoration Manager to be optional (thanks Gnome)
                if (global == .zxdg_decoration_manager_v1) {
                    _haveXdgDecoration = false;
                } else {
                    @panic(""); // PANIC HERE
                }
            }
        }
    }

Adding a debug print just before the panic tells me that the value of global of wp_linux_drm_syncobj_manager_v1.

Are you on niri?

How’d you guess :wink: Looks like there’s an open ticket for this.

1 Like

I’m on niri as well :wink: I patched mine with the commit from the MR.
But I have nvidia, so it’s moot as long as nvidia doesn’t implement sync stuff

I think it’s in poor taste when a project comes with a shell.nix checked into the source repository.

Zig has no dependency on Nix, nor does it favor NixOS above other distributions, nor does it even favor Linux above other operating systems.

We also don’t list apt-get commands that you would use on Debian to install LLVM, and we don’t have screenshots of how to set up LLVM on Windows. We don’t have vim editor configuration or vscode editor configuration files in the repo. That documentation belongs outside ziglang/zig source repository.

We also don’t put .DS_Store, *.swp or other editor-specific files in .gitignore. That belongs in the user’s global .gitignore. We also don’t ever assume the user will use git, for example in zig init we do not initialize a .gitignore file.

Hopefully this helps paint the picture. There are an infinite number of third party projects that zig can live with or interact with, from the past, present, and future, and picking favorites is completely outside the scope of the project.

33 Likes

thank you Andrew for taking the time to respond to us users, we might be a bother sometimes (you could just say “we would then need to provide builds for other systems” and be done, but rather you took time to explain and I wanted to thank you for that)

anyways, ok, we shall keep that in mind anytime we want to “favor” any distro or build system. no favoring

2 Likes

Users are not a bother. They are the entire point!

16 Likes

I forked the presentation example and swapped out the dynamic library loader:

https://codeberg.org/andrewrk/presentation-example/

Produces a fully static 392 KB executable!

8 Likes

Compiling and running this gives me this:

error(vk_general): loader_validate_layers: Layer 0 does not exist in the list of available layers
error: LayerNotPresent
/run/host/var/home/kilian/presentation-example/.zig-cache/o/a6562ab8c63eb637b1eb6af7f73249a4/vk.zig:24306:51: 0x130fcce in createInstance (vk.zig)
                Result.error_layer_not_present => return error.LayerNotPresent,
                                                  ^
/run/host/var/home/kilian/presentation-example/example/vulkan-stuff.zig:76:22: 0x12997a7 in _initInstance (main.zig)
    const instance = try baseWrapper.createInstance(&vk.InstanceCreateInfo{ .p_next = &debugUtilsMessengerCreateInfo, .p_application_info = &vk.ApplicationInfo{ .p_application_name = "Wayland Test", .application_version = 0, .p_engine_name = "waylandtest", .engine_version = 0, .api_version = @bitCast(vk.makeApiVersion(0, 1, 2, 0)) }, .enabled_layer_count = neededLayers.len, .pp_enabled_layer_names = neededLayers.ptr, .enabled_extension_count = neededExtensions.len, .pp_enabled_extension_names = neededExtensions.ptr }, null);
                     ^
/run/host/var/home/kilian/presentation-example/example/vulkan-stuff.zig:30:5: 0x129b149 in init (main.zig)
    try _initInstance(vkGetInstanceProcAddr);
    ^
/run/host/var/home/kilian/presentation-example/example/main.zig:27:5: 0x129b738 in main (main.zig)
    try vulkan.init();
    ^

(PS: KDE with AMD Mesa driver)

It looks like that means you don’t have validation layers available. You could install those, or you could remove the code that asks for them, which is nearby your stack trace.

Ok, now I get a panic from window/window.zig:1052 that it can’t find format+modifier matching preference:

/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:1052:5: 0x12c156d in pickFormatModifier (window.zig)
    @panic("");
    ^
/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:1009:54: 0x12beb64 in updateFormatModifier (window.zig)
    const format, const modifier = pickFormatModifier();
                                                     ^
/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:918:37: 0x12bae7b in handleWaylandEvent (window.zig)
                updateFormatModifier();
                                    ^
/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:569:27: 0x12b7b91 in readWaylandEvents (window.zig)
        handleWaylandEvent(header, data);
                          ^
/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:541:30: 0x12b6e24 in poll (window.zig)
            readWaylandEvents();
                             ^
/run/host/var/home/kilian/presentation-example-andrewrk/window/window.zig:293:21: 0x12b5f50 in waitUntilNextFrameReady (window.zig)
            _ = poll(true);
                    ^
/run/host/var/home/kilian/presentation-example-andrewrk/example/main.zig:46:56: 0x129b884 in main (main.zig)
        const swapInfo = window.waitUntilNextFrameReady();
                                                       ^
/var/home/kilian/toolbox-local/zig/.zi/0.17.0-dev.1257+67b05e521/zig-x86_64-linux-0.17.0-dev.1257+67b05e521/lib/std/start.zig:790:30: 0x129c80d in callMain (std.zig)
    return wrapMain(root.main(.{
                             ^
/var/home/kilian/toolbox-local/zig/.zi/0.17.0-dev.1257+67b05e521/zig-x86_64-linux-0.17.0-dev.1257+67b05e521/lib/std/start.zig:217:5: 0x1251ff1 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^
Abgebrochen                (Speicherabzug geschrieben) /run/host/var/home/kilian/presentation-example-andrewrk/zig-out/bin/example

I got the same error on Arch/Hyprland (NVIDIA discrete, AMD integrated GPU). I assumed it was just something misconfigured in my environment (maybe still is?). I installed vulkan-validation-layers package, but now I get the panic that @WeeBull posted about.

When I explicitly tell it to use the AMD drivers, it does work on the integrated card, so progress?

VK_DRIVER_FILES=/usr/share/vulkan/icd.d/radeon_icd.json zig-out/bin/test

There are already third party repositories one can use. I’ve used GitHub - mitchellh/zig-overlay: Nix flake for the Zig compiler. · GitHub, with a patch to use LLVM 22

2 Likes