j
jaipkg.dev
packages / library / jai-vulkan-generator

jai-vulkan-generator

249649flibrary

A Vulkan generator (and generated modules) for the JAI programming language.

Zlib · updated 10 months ago

JAI Vulkan binding generator

This is a generator and replacement for Vulkan bindings in JAI.

Caution

This is very experimental and hack-y code.

It was put together in a few hours and it is not well tested at all.

Also note that currently only linux has been tested.

windows and android support is best effort and macosx and iOS support is not yet implemented.

If you run into issues (which you probably will), please open an issue or a pull request.

Why a replacement?

The Vulkan module that ships with the compiler, at the time of writing, is out of date.

It doesn't include some of the 1.2 and 1.3 features, nor does it have surface extensions.

Generated modules

The generator can create bindings with or without the vk suffix.

Both versions can be found in the modules directory.

The easiest way to include this binding in your project is to save one of the modules to your own modules folder and use it directly.

  • If you are using the version with the vk suffix, you can use it like this:
#import "vulkan_with_prefix.jai"; // Or better, rename the file to simply be vulkan

main :: () {
    vulkan_load_library();
    vulkan_load_global_functions();
    ci := VkInstanceCreateInfo.{ /* ... */ };
    instance: VkInstance;
    vkCreateInstance(ci, null, instance);
}
  • If you are using the version without the vk suffix, you can use it like this:
vk :: #import "vulkan.jai"; // Or better, rename the file to simply be vulkan

main :: () {
    vk.load_library();
    vk.load_global_functions();
    ci := vk.InstanceCreateInfo.{ /* ... */ };
    instance: vk.Instance;
    vk.CreateInstance(ci, null, instance);
}

How to use it?

The generated module offers a few functions that aren't part of the vulkan API.

Those are:

[[vulkan_]]load_library :: () -> bool;
[[vulkan_]]load_global_functions :: (get_instance_proc_addr: PFN_GetInstanceProcAddr = null);
[[vulkan_]]load_instance_functions :: (instance: Instance, get_instance_proc_addr: PFN_GetInstanceProcAddr = null);
[[vulkan_]]load_device_functions :: (device: Device, get_device_proc_addr: PFN_GetDeviceProcAddr = null);

Those functions must be used to load the vulkan library (optional) and to load all function addresses.

Currently the module doesn't provide a way to access the loader functions for performance reasons.

It is preferable to use the load_*_functions function above.

Important

Multi-device device procedures are currently not supported.

If you need to support multiple devices and need a function pointer tables, you'll need to modify this generator.

This is unlikely to change in the near future as it isn't a feature that is used often.

See example.jai for a simple example of how to use the module.

License

Both the generator and the generated code are licensed, where applicable, under the ZLib license.

All the Vulkan code is licensed under the Apache License 2.0. See the Khronos website for more information.

The choice of license was such as to allow use of the code without attribution in binary form.