#Vulkan bindings

1 messages · Page 1 of 1 (latest)

burnt barn
fiery folio
#

Great Vulkan bindings! Got my seal of approval!

full gust
#

I am currently using these and they are pretty lit

midnight wyvern
# burnt barn https://github.com/Snektron/vulkan-zig
self.vkb = vk.BaseWrapper.load(c.SDL_Vulkan_GetVkGetInstanceProcAddr);

Error when building:

.zig-cache/o/d55ae902be81ed03dcf52b64a96575e6/vk.zig:27022:33: error: expected 0 argument(s), found 2
                const cmd_ptr = loader(Instance.null_handle, field.name.ptr) orelse undefined;
                                ^~~~~~
/home/leeb/Projects/Nashi/.zig-cache/o/ffe70c69b6b234637678234c67df6247/cimport.zig:7476:12: note: function declared here
pub extern fn SDL_Vulkan_GetVkGetInstanceProcAddr() SDL_FunctionPointer;

Is there a fix for this?

burnt barn
#

Yeah you need to call the SDL function i think

burnt barn
#
self.vkb = vk.BaseWrapper.load(@as(vk.PfnGetInstanceProcAddr, @ptrCast(c.SDL_Vulkan_GetVkGetInstanceProcAddr)));
midnight wyvern
#
self.vkb = vk.BaseWrapper.load(@as(vk.PfnGetInstanceProcAddr, @ptrCast(c.SDL_Vulkan_GetVkGetInstanceProcAddr())));

->

thread 26701 panic: cast causes pointer to be null
/home/leeb/Projects/Nashi/src/renderer_vk.zig:28:66: 0x122c48c in prepare_vulkan (zig_sdl3_cross_template)
        vkb = vk.BaseWrapper.load(@as(vk.PfnGetInstanceProcAddr, @ptrCast(c.SDL_Vulkan_GetVkGetInstanceProcAddr())));
#

oh, nvm brain fart. It was just this:

self.vkb = vk.BaseWrapper.load(@as(vk.PfnGetInstanceProcAddr, @ptrCast(&c.SDL_Vulkan_GetVkGetInstanceProcAddr)));
#

Thx

midnight wyvern
# burnt barn Yeah you need to call the SDL function i think

But, still there's one issue when compiling to android:

.zig-cache/o/d55ae902be81ed03dcf52b64a96575e6/vk.zig:11:55: error: no field or member function named 'isARM' in 'Target.Cpu.Arch'
else if (builtin.abi == .android and (builtin.cpu.arch.isARM() or builtin.cpu.arch.isThumb()) and std.Target.arm.featureSetHas(builtin.cpu.features, .has_v7) and builtin.cpu.arch.ptrBitWidth() == 32)
midnight wyvern
burnt barn
#

Oh that seems like a bug

#

Can you submit an issue? I can't fix that rn

#

Or maybe a pr

midnight wyvern
#

alr

burnt barn
#

That function needs to be replaced with whatever the current one is

midnight wyvern
#

it's isArm();

burnt barn
#

Seems like a simple enough fix

midnight wyvern
#

ye

burnt barn
#

I can press the merge button from my phone but i can't edit

burnt barn
#

I see it

#

I think you made the pr from the master branch

midnight wyvern
#

nope

#

right?

burnt barn
#

I mean the commits in your branch are from master

#

So you should cherry pick your commit onto the 0.14 branch

#

But first you should retarget your pr to the master branch because the fix is needed there too

#

If that makes sense

midnight wyvern
#

Yeah, to be honest I'm quite new to a lot of git stuff. Just so you know. But I'll try

burnt barn
#

No problem, I'll help you through it

#

So first you should edit your pull request to target master instead of 0.14-compat

midnight wyvern
#

What I'm confused about is why only the main branch in my fork is showingSKULL

burnt barn
#

Hmm you may need explicitly check it out

#

Try git checkout zig-0.14-compat

midnight wyvern
#

That didnt work, it literally doesn't show up on github.

burnt barn
#

You may have checked some button to only clone master, i think there is one

#

In that case use git remote add upstream https://github.com/Snektron/vulkan-zig

#

Followed by git fetch --all

midnight wyvern
#

yeah, that did it

midnight wyvern
burnt barn
#

Excellent, thanks!

midnight wyvern
#

No problem (and thanks for your incredible patience!

#

And that fixed the error, thanks!

midnight wyvern
# burnt barn Excellent, thanks!

Now I'm having an issue with android again:

fn create_instance(self: *renderer) !void {
    const allocator = std.heap.c_allocator;

    const app_info: vk.ApplicationInfo = .{
        .p_application_name = "Nashi",
        .application_version = @bitCast(vk.makeApiVersion(1, 0, 0, 0)),
        .p_engine_name = "Nashi",
        .engine_version = @bitCast(vk.makeApiVersion(0, 0, 1, 0)),
        .api_version = @bitCast(vk.API_VERSION_1_2),
    };    

    var extension_names = std.ArrayList([*:0]const u8).init(allocator);
    defer extension_names.deinit();

    try extension_names.append("VK_KHR_portability_enumeration");

    var sdl_exts_count: u32 = 0;
    const sdl_exts = c.SDL_Vulkan_GetInstanceExtensions(&sdl_exts_count);

    try extension_names.appendSlice(@ptrCast(sdl_exts[0..sdl_exts_count]));

    for (extension_names.items) |e| {
        std.log.info("Extension: {s}", .{ e });
    }

    const validation_layer_name = "VK_LAYER_KHRONOS_validation"; // Null-terminated C string
    const validation_layers = [_][*:0]const u8{
        validation_layer_name,
    };


    const create_info: vk.InstanceCreateInfo = .{
        .p_application_info = &app_info,
        .enabled_extension_count = @intCast(extension_names.items.len),
        .pp_enabled_extension_names = extension_names.items.ptr,
        .enabled_layer_count = @intCast(validation_layers.len),
        .pp_enabled_layer_names = validation_layers[0..],
        .flags = .{ .enumerate_portability_bit_khr = true },
    }; 

    const instance = try self.vkb.createInstance(&create_info, null);

    const vki = try allocator.create(vk.InstanceWrapper);
    errdefer allocator.destroy(vki);
    vki.* = vk.InstanceWrapper.load(instance, self.vkb.dispatch.vkGetInstanceProcAddr.?);
    self.vk_instance = vk.InstanceProxy.init(instance, vki);
    errdefer self.vk_instance.destroyInstance(null);
}

This is what I'm doing and it's crashing after 1 second or so...

#

It's working just fine for Dekstop

burnt barn
#

Can you try removing the validation layer?

#

If youre testing as cli program then that won't work

#

But i don't recall if that makes it crash

#

Otherwise i don't know

midnight wyvern
# burnt barn Can you try removing the validation layer?

that didn't work, what I do for android in build.zig:

const vulkan = b.dependency("vulkan", .{
    .registry = b.dependency("vulkan_headers", .{}).path("registry/vk.xml"),
});
exe.root_module.addImport("vulkan", vulkan.module("vulkan-zig"));

burnt barn
#

I can't help you rn sorry

midnight wyvern
midnight wyvern
burnt barn
#

When i get home maybe

midnight wyvern
#

u on vacation?

burnt barn
#

Ye but going home today

midnight wyvern
#

Yo, have fun, dude!

burnt barn
#

I get the feeling that it's probably related to your own logic than to the library, though

midnight wyvern
#

maybe

burnt barn
#

I think it depends a bit on your phone, some android vendors are lacking a bit

#

i recommend installing the vulkan caps viewer app so that you can double check

#

if that's not the problem, then perhaps you can share the entire project with me so that i can build it from scratch

midnight wyvern
#

It's both not working on the emulator and my actual physical phone

burnt barn
#

you got a repo?

midnight wyvern
midnight wyvern
#

zig build -Dandroid

#

you need zig 0.15 (nightly) though

burnt barn
#

that shouldnt be a problem

burnt barn
#

the android sdk on the other hand...

burnt barn
#

@midnight wyvern

error: ld.lld: /nix/store/28hvz5qsipq2n92qbrr8d0xlacs312fh-libglvnd-1.7.0/lib/libGLESv1_CM.so is incompatible with armelf_linux_eabi
error: ld.lld: /nix/store/28hvz5qsipq2n92qbrr8d0xlacs312fh-libglvnd-1.7.0/lib/libGLESv2.so is incompatible with armelf_linux_eabi
#

hmm looks like an issue in your SDL bindings, for some reason it prefers my system gles rather than the sdk one... I removed the system one and now it builds

burnt barn
#
  • you didnt create sdl with the right flag (SDL_INIT_VIDEO)
  • you didnt call SDL_Vulkan_LoadLibrary
  • you should check if portability is available before adding it (my phone doesnt have it)
#

i recommend starting with vulkan on desktop before moving onto android because its significantly easier to debug

midnight wyvern
#

alright, thank you!

nimble cobalt
#

Hey there, I'm trying out the vulkan-zig bindings in an embedded project, so we don't have X/wayland in there. vkcube runs fine on it and basically uses direct display rendering. Due to this, we're basically not using any SDL/GLFW bindings and need to load vkGetInstanceProcAddr ourselves. We seem to be having some issues with it, here's current simplified code:

const std = @import("std");
const vk = @import("vulkan");

pub fn main() !void {
    var lib = try std.DynLib.openZ("libvulkan.so.1");
    defer lib.close();

    const vkGetInstanceLookup = lib.lookup(vk.PfnGetInstanceProcAddr, "vkGetInstanceProcAddr")
        orelse return error.SymbolNotFound;

    const vkb = vk.BaseWrapper.load(vkGetInstanceLookup);
    ...
}

This segfaults on const vkb = vk.BaseWrapper.load(vkGetInstanceLookup);:

/usr/bin/zig build run
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)```

Any recommendations on what would you use to load this or what the issue might be? Thanks!
#

Zig version 0.14.1, vulkan-zig branch zig-0.14-compat, Vulkan-Headers v1.4.317

nimble cobalt
#

Solved, in case anyone finds this in the future: exe.linkLibC(); kek

hollow jasper
bronze plover
#

Hmm wanted to do a quick test before going to bed but none of the hunks I suspected we're the culprit grief

burnt barn
#

yeah sorry about that

#

i need to get on that

#

its been broken for a while

burnt barn
#

ah they finally made the <proto> definitions a bit better

dusty oriole
#

Hi, I am trying to use push descriptors and distinct immutable samplers and images. Any idea why ⁨⁨cmd.pushDescriptorSet⁩⁩ segfaults?
⁨⁨```
fn pushDescriptorSets (
self: *UiRenderer, cmd: vk.CommandBufferProxy
) void {
const sampler_write = vk.WriteDescriptorSet {
.descriptor_type = .sampler,

    .dst_binding = 0,
    .descriptor_count = 1,
    .dst_array_element = 0,

    .p_buffer_info = undefined,
    .p_image_info = undefined,
    .p_texel_buffer_view = undefined,
    .dst_set = .null_handle
};

const txr_atlas_info = vk.DescriptorImageInfo {
    .image_view = self.txr_atlas.img_view,
    .image_layout = .shader_read_only_optimal,
    .sampler = .null_handle,
};

const txr_atlas_write = vk.WriteDescriptorSet {
    .descriptor_type = .sampled_image,

    .dst_binding = 1,
    .descriptor_count = 1,
    .dst_array_element = 0,

    .p_image_info = @ptrCast (&txr_atlas_info),

    .p_buffer_info = undefined,
    .p_texel_buffer_view = undefined,
    .dst_set = .null_handle
};

const write_array = [_] vk.WriteDescriptorSet {
    sampler_write, txr_atlas_write
};

cmd.pushDescriptorSet (
    .graphics, self.ppl_layout, 0, @intCast (write_array.len), &write_array
);

}

#

Here's the create function too:
⁨```
fn createDescriptorSetLayout (self: *UiRenderer, gpu: Gpu) !void {
const sampler_bdg = vk.DescriptorSetLayoutBinding {
.binding = 0,
.descriptor_count = 1,
.descriptor_type = .sampler,
.p_immutable_samplers = @ptrCast (&self.sampler),
.stage_flags = .{.fragment_bit = true}
};

const txr_atlas_bdg = vk.DescriptorSetLayoutBinding {
    .binding = 1,
    .descriptor_count = 1,
    .descriptor_type = .sampled_image,
    .stage_flags = .{.fragment_bit = true}
};

const bindings = [_] vk.DescriptorSetLayoutBinding {sampler_bdg, txr_atlas_bdg};

const info = vk.DescriptorSetLayoutCreateInfo {
    .flags = .{.push_descriptor_bit = true},

    .binding_count = @intCast (bindings.len),
    .p_bindings = &bindings
};

self.desc_layout = try gpu.dev.createDescriptorSetLayout (&info, null);

}

quiet vector
dusty oriole
#

Do I need it if I enabled the feature and the vulkan 1.4 api?

quiet vector
#

Oh then you shouldn't

#

Have you tried running under validation layers? Also a debugger

#

Oh maybe make a zig-help thread

dusty oriole
#

It actually segfaults in the layer

#

Maybe I'll try without when I get home. I wonder if it expects null for those values instead of undefined...

dusty oriole
#

Supplying a value dummy value for p_image_info fixed it like this:

const sampler_info = vk.DescriptorImageInfo {
    .image_layout = .undefined,
    .image_view = .null_handle,
    .sampler = .null_handle
    };

I think this might be a bug though. The docs say that this value should be ignored:

To push an immutable sampler, use a VkWriteDescriptorSet with dstBinding and dstArrayElement selecting the immutable sampler’s binding. If the descriptor type is VK_DESCRIPTOR_TYPE_SAMPLER, the pImageInfo parameter is ignored and the immutable sampler is taken from the push descriptor set layout in the pipeline layout. If the descriptor type is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, the sampler member of the pImageInfo parameter is ignored and the immutable sampler is taken from the push descriptor set layout in the pipeline layout.

tulip cloud
#

i have been using these bindings for months now, works great, thanks!

#

Now to wait until zig has full support for shader land and it's going to be even better.

tulip cloud
#

Hello.

#

don't have a github account, but i think i found a bug with the library.

#

wrapper.dispatch.vkGetDeviceFaultReportsKHR is null even when enabling the device fault extension and feature.

burnt barn
#

Does your driver have that available?