Code Monkey home page Code Monkey logo

vkbind's Introduction

A single file Vulkan header and API loader.

discord mastodon

vkbind is a Vulkan API loader and includes a full implementation of the Vulkan headers (auto-generated from the Vulkan spec) so there's no need for the offical headers or SDK. Unlike the official headers, the platform-specific sections are all contained within the same file.

Usage

For platforms that statically expose all Vulkan APIs you can use vkbind like so:

#define VKBIND_IMPLEMENTATION
#include "vkbind.h"

int main()
{
    VkResult result = vkbInit(NULL);
    if (result != VK_SUCCESS) {
        printf("Failed to initialize vkbind.");
        return -1;
    }

    // Do stuff here.

    vkbUninit();
    return 0;
}

For those platforms that do not statically expose all Vulkan APIs, you should do something like this:

#define VKBIND_IMPLEMENTATION
#include "vkbind.h"

int main()
{
    VkbAPI api;
    VkResult result = vkbInit(&api);
    if (result != VK_SUCCESS) {
        printf("Failed to initialize vkbind.");
        return -1;
    }
    
    // ... Create your Vulkan instance here (vkCreateInstance) ...

    result = vkbInitInstanceAPI(instance, &api);
    if (result != VK_SUCCESS) {
        printf("Failed to initialize instance API.");
        return -2;
    }

    result = vkbBindAPI(&api);  // <-- Optional. Can call APIs directly like api.vkDestroyInstance().
    if (result != VK_SUCCESS) {
        printf("Failed to bind instance API.");
        return -3;
    }

    // Do stuff here.

    vkbUninit();
    return 0;
}

The code above uses the VkbAPI structure which contains function pointers to all Vulkan APIs. The idea is that you first initialize with vkbInit(), then call vkbInitInstanceAPI() after you've created your Vulkan instance. The VkbAPI object will be filled with usable function pointers at this point (so long as they're supported by the platform). In this example, the instance APIs are bound to global scope using vkbBindAPI(), however if you have multiple instances running at the same time, you should instead invoke the functions directly from the VkbAPI object.

You can also initialize the VkbAPI object from a Vulkan device. This is optional, and is intended as an optimization to avoid the cost of internal dispatching. To use this, you first initialize your VkbAPI object with vkbInitializeInstanceAPI(), then call vkbInitializeDeviceAPI(), passing in the same VkbAPI object.

VkbAPI api;
vkbInitInstanceAPI(instance, &api);
vkbInitDeviceAPI(device, &api);
vkbBindAPI(&api);

Examples

You can find some general Vulkan examples in the "examples" folder. The first example, 01_Fundamentals, is completely flat and self contained in a single code file. This is unlike most of the other popular example projects out there which are full of abstractions which make things too hard to follow. It covers most (all?) of the fundamentals any real Vulkan program is going to need, and tries to explain how things like vertex layouts and descriptor sets interact with shaders which I think is something other examples seem to overlook.

For practicality, future examples will not be entirely flat, but should still be significantly better than other popular examples out there in terms of readability.

Note that shaders are pre-compiled with glslangValidator (GLSL to SPIR-V compiler) and embedded into a source file for each example. This is just to avoid the need to worry about file IO for shaders and to focus on Vulkan itself.

License

Public domain or MIT-0 (No Attribution). Choose whichever you prefer.

vkbind's People

Contributors

mackron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vkbind's Issues

Wrong enums

Hi,
I saw there are some enums that have wrong values:

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES = 999999000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES = 999999000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES = 999999000,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES = 999999000,

Should be:

VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES = 49,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES = 50,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES = 51,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES = 52,

Same for VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE and other enums

custom path for vkbLoadVulkanSO

While testing the library on macos I discovered that vkbind only looks for libMoltenVK.dylib in its working folder.
Would be neat to pass a path or have a define where I can set a path where it looks first for the dynamic library.

Empty enums trigger compiler error.

I'm replacing the Windows SDK with vkbind for my helper library, but I've hit upon this possible bug:

inc/vkbind.h(1594,1): error: use of empty enum
} VkShaderModuleCreateFlagBits;
^
inc/vkbind.h(6365,1): error: use of empty enum
} VkAcquireProfilingLockFlagBitsKHR;
^
inc/vkbind.h(7788,1): error: use of empty enum
} VkPipelineCompilerControlFlagBitsAMD;
^
inc/vkbind.h(8382,1): error: use of empty enum
} VkShaderCorePropertiesFlagBitsAMD;
^
inc/vkbind.h(9333,1): error: use of empty enum
} VkPrivateDataSlotCreateFlagBitsEXT;
^

A cursory look at vkbind.h shows these enums are indeed empty. I've never given it serious thought, but this SO question seems to indicate they are ill-formed statements (at least in the c++ standard.) Thoughts?

P.S. For context, I'm on a recent Windows 10 build using a recent clang compiler (clang-cl.exe). My codebase is all plain C.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.