kotlin-graphics / Vkk

Licence: apache-2.0
VK², Kotlin Wrapper for Vulkan: code expressiveness and safety meet graphic power

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to Vkk

Soul Engine
Physically based renderer and simulation engine for real-time applications.
Stars: ✭ 37 (-48.61%)
Mutual labels:  vulkan
Vulkan Tutorial
This is a series of tutorials on Vulkan, include all example projects which step by step.
Stars: ✭ 56 (-22.22%)
Mutual labels:  vulkan
Vulkanmemoryallocator
Easy to integrate Vulkan memory allocation library
Stars: ✭ 1,136 (+1477.78%)
Mutual labels:  vulkan
Mongoose
Minimalistic Vulkan engine for fast propotyping.
Stars: ✭ 41 (-43.06%)
Mutual labels:  vulkan
Spear
SPEAR is a integrated domain specific language translating C++17 to SPIR-V at host runtime
Stars: ✭ 45 (-37.5%)
Mutual labels:  vulkan
Vulkan2drenderer
Easy to use 2D rendering engine using Vulkan API as backend.
Stars: ✭ 60 (-16.67%)
Mutual labels:  vulkan
Glfw
A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
Stars: ✭ 8,416 (+11588.89%)
Mutual labels:  vulkan
Tristeon3d
A 3D Engine built by two Game Engineering students.
Stars: ✭ 68 (-5.56%)
Mutual labels:  vulkan
Ncnn Android Styletransfer
The style transfer android example
Stars: ✭ 54 (-25%)
Mutual labels:  vulkan
Gl vs vk
Comparison of OpenGL and Vulkan API in terms of performance.
Stars: ✭ 65 (-9.72%)
Mutual labels:  vulkan
Llgl
Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
Stars: ✭ 1,011 (+1304.17%)
Mutual labels:  vulkan
Shaderc
A collection of tools, libraries, and tests for Vulkan shader compilation.
Stars: ✭ 1,016 (+1311.11%)
Mutual labels:  vulkan
Nebula Trifid
Nebula Trifid
Stars: ✭ 62 (-13.89%)
Mutual labels:  vulkan
Vk denoise
Denoising a Vulkan ray traced image using OptiX denoiser
Stars: ✭ 41 (-43.06%)
Mutual labels:  vulkan
Shaderconductor
ShaderConductor is a tool designed for cross-compiling HLSL to other shading languages
Stars: ✭ 1,146 (+1491.67%)
Mutual labels:  vulkan
Intrinsic
Intrinsic is a Vulkan based cross-platform game and rendering engine. The project is currently in an early stage of development.
Stars: ✭ 984 (+1266.67%)
Mutual labels:  vulkan
Dain Vulkan Gui
AI-Powered video interpolater (eg. 30fps -> 60fps) for Vulkan devices. Based on dain-ncnn-vulkan and ffmpeg
Stars: ✭ 58 (-19.44%)
Mutual labels:  vulkan
Gears Vk
Powerful low-level C++20 rendering framework for Vulkan 1.2, including Real-Time Ray Tracing (RTX) support, built atop Auto-Vk.
Stars: ✭ 71 (-1.39%)
Mutual labels:  vulkan
3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+16147.22%)
Mutual labels:  vulkan
Vulkust
An engine for Vulkan in Rust, tries to implement modern graphic features. (suspended for now)
Stars: ✭ 64 (-11.11%)
Mutual labels:  vulkan

VK², Kotlin Wrapper for Vulkan

Build Status license Release Size Github All Releases

The goal of the VK² is to provide a library for the Vulkan C API to improve the developers Vulkan experience without introducing any considerable CPU runtime cost. It adds features like type safety for enums and bitfields, collection support, exceptions and simple enumerations.

Strongly inspired by Vulkan hpp, it's shaped on the Sasha examples port. It's the Vulkan counterpart of the OpenGL gln.

See it in action here!

Getting Started

VK² can be obtained by adding the following lines in your build.gradle:

  • Step 1. Add the JitPack repository to your build file at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
  • Step 2. Add the dependency:

    dependencies {
        implementation 'com.github.kotlin-graphics:vkk:-SNAPSHOT'
    }
    

Usage

vk object

To avoid name collisions with the lwjgl Vulkan bindings, the VK² wrapper resides mostly under the object vk. The following rules apply to the new naming

  • All functions, extension functions, and structs have the Vk prefix removed. In addition to this the first letter of functions is lower case.
    • VkCreateImage can be accessed as vk.createImage
    • VkImageTiling can be accessed as vk.ImageTiling
    • VkImageCreateInfo can be accessed as vk.ImageCreateInfo
  • Enums are mapped to scoped enums to provide compile time type safety. The names have been changed to have the Enum Base in CamelCase with the VK_ prefix and the enum name in Capital letters (corresponding to the original counterpart). Enums starting with a number requires to be surrounded by backticks the underscore prefix _, this because Idea handles backticks this very poorly.

Some examples:

  • VK_COLOR_SPACE_SRGB_NONLINEAR_KHR is now VkColorSpace.SRGB_NONLINEAR_KHR
  • VK_IMAGETYPE_2D is now VkImageType._2D
  • Flag bits are handled like scoped enums with the addition that the _BIT suffix has also been removed.

Extension functions

This is one case where Kotlin really shines: VK² declares a class for all handles to ensure full type safety and to add support for member functions on handles. A member function has been added to a handle class for each function which accepts the corresponding handle as first parameter. Instead of vkBindBufferMemory(device, ...) one can write device.bindBufferMemory(...).

Mask Flags

All flags masks have been typealiased accordingly. For example a field of type VkBufferUsageFlags means that it represents a mask from the VkBufferUsage. enum. The postfix Flag has been eliminated from the enum name for conciseness matter. However, it has been kept for some special cases, such as VkQueueFlag, to avoid clashes with existing other structures, in this case the VkQueue class for example.

CreateInfo structs and appBuffer

When constructing a handle in Vulkan one usually has to create some CreateInfo struct which describes the new handle. Moreover, allocation has to be handled manually and everywhere C code uses pointers, we have to use buffers on the JVM. This can result in quite lengthy code as can be seen in the following Vulkan example:

val info = VkImageCreateInfo.calloc()
    .sType(VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO)
    .pNext(null)
    .flags(...some flags...)
    .imageType(VK_IMAGE_TYPE_2D)
    .format(VK_FORMAT_R8G8B8A8_UNORM)
    .extent().apply {
        .width(size.x)
        .height(size.y)
        .depth(1)
    }
    .mipLevels(1)
    .arrayLayers(1)
    .samples(VK_SAMPLE_COUNT_1_BIT)
    .tiling(VK_IMAGE_TILING_OPTIMAL)
    .usage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
    .sharingMode(VK_SHARING_MODE_EXCLUSIVE)
    .pQueueFamilyIndices(null)
    .initialLayout(VK_IMAGE_LAYOUT_UNDEFINED)
val pImage = MemoryUtil.memAllocLong(1)
vkCreateImage(device, info, allocator, pImage)
image = pImage.get(0)
info.free()
memFree(pImage)

One typical issue Vulkan developers encounter when filling out a CreateInfo struct field by field is that sType is incorrect.

VK² provides constructors for all CreateInfo objects (and others) where sType is automatically filled with the correct value and pNext set to a nullptr by default. All other field are also initialized to zero. There are exceptions though.

Moreover, all the allocations takes place in the thread local memory, using the lwjgl MemoryStack class.

VK² provides also special method accepting glm classes, like extent accepting a (Vec3i) or (Vec2i, Int). Here's how the same code looks with a constructor:

val info = vk.ImageCreateInfo {
    flags = ...some flags...
    imageType = VkImageType.`2D`
    format = VkFormat.R8G8B8A8_UNORM
    extent(size, 1)
    mipLevels = 1
    arrayLayers = 1
    samples = VkSampleCount.`1_BIT`
    tiling = VkImageTiling.OPTIMAL
    usage = VkImageUsage.COLOR_ATTACHMENT_BIT.i
    sharingMode = VkSharingMode.EXCLUSIVE
}
image = device createImage info

Errors will be checked automatically in debug mode, but you can set DEBUG explicitely as you wish. In case VULKAN_NO_EXCEPTIONS is true, errors will be reported in the System.err stream, otherwise the exception to the corresponding error will be thrown.

TODO

Build-logic and platform dependencies

The build logic has been extracted in dedicated plugins, as well as the versioning in specific platform plugins.

In order to import vkk you need then to add the repository where these plugins are getting published for the time being.

In Gradle KTS you can do that by adding the following to your settings.gradle.kts:

pluginManagement {
    repositories {
        gradlePluginPortal()
        maven("https://repo.repsy.io/mvn/elect/kx")
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].