libstd/vulkan

Bindings to Vulkan and helpers for the first steps of a Vulkan program: instance, physical and logical device, graphics queue, window surface and swapchain. It links libvulkan.so on Linux and vulkan-1.dll on Windows (installed with the GPU driver); the instance enables the surface extension of the system it runs on. Vulkan structs are declared as classes with explicit padding; handles are long.

#include <libstd/vulkan>

Includes libstd/stdio, libstd/dict. Links the shared library vulkan-1.dll, libvulkan.so (FFI).

Example

#include <libstd/vulkan>

app = create_vulkan_instance("Hello World")
instance = vk_create_instance(app)
gpu = vk_get_first_physical_device(instance)
if gpu == (0 as long):
    print("no Vulkan device\n")
    exit(1)
family = vk_find_graphics_queue_family(gpu)
device = vk_create_logical_device(gpu, family)
queue = 0 as long
vkGetDeviceQueue(device, family, 0, &queue)
vkDestroyDevice(device, 0 as long)
vk_destroy_instance(instance)

Constants

NameValueMeaning
VK_STRUCTURE_TYPE_APPLICATION_INFO0
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO1
VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO2
VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO3
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR1000004000
VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR1000009000
VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR1000001000
VK_QUEUE_GRAPHICS_BIT1
VK_FORMAT_B8G8R8A8_UNORM44
VK_COLOR_SPACE_SRGB_NONLINEAR_KHR0
VK_PRESENT_MODE_FIFO_KHR2
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT16
VK_IMAGE_USAGE_TRANSFER_DST_BIT2
VK_SHARING_MODE_EXCLUSIVE0
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR1
VK_PHYSICAL_DEVICE_PROPERTIES_SIZE824
VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO39
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO40
VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO42
VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER45
VK_STRUCTURE_TYPE_FENCE_CREATE_INFO8
VK_STRUCTURE_TYPE_SUBMIT_INFO4
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR1000001001
VK_IMAGE_ASPECT_COLOR_BIT1
VK_IMAGE_LAYOUT_UNDEFINED0
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL7
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR1000001002
VK_ACCESS_TRANSFER_WRITE_BIT4096
VK_ACCESS_MEMORY_READ_BIT32768
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT1
VK_PIPELINE_STAGE_TRANSFER_BIT4096
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT8192
VK_QUEUE_FAMILY_IGNORED-1
VK_COMMAND_BUFFER_LEVEL_PRIMARY0

Classes

class
VkApplicationInfo
    sType int
    _pad0 int
    pNext long
    pApplicationName str
    applicationVersion int
    _pad1 int
    pEngineName str
    engineVersion int
    apiVersion int
class
VkInstanceCreateInfo
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
    pApplicationInfo long
    enabledLayerCount int
    _pad2 int
    ppEnabledLayerNames long
    enabledExtensionCount int
    _pad3 int
    ppEnabledExtensionNames long
class
VkAllocationCallbacks
    pUserData long
    pfnAllocation long
    pfnReallocation long
    pfnFree long
    pfnInternalAllocation long
    pfnInternalFree long
class
VkQueueFamilyProperties
    queueFlags int
    queueCount int
    timestampValidBits int
    minImageTransferGranularityWidth int
    minImageTransferGranularityHeight int
    minImageTransferGranularityDepth int
class
VkDeviceQueueCreateInfo
    sType int
    _pad0 int
    pNext long
    flags int
    queueFamilyIndex int
    queueCount int
    _pad1 int
    pQueuePriorities long
class
VkDeviceCreateInfo
    sType int
    _pad0 int
    pNext long
    flags int
    queueCreateInfoCount int
    pQueueCreateInfos long
    enabledLayerCount int
    _pad1 int
    ppEnabledLayerNames long
    enabledExtensionCount int
    _pad2 int
    ppEnabledExtensionNames long
    pEnabledFeatures long
class
VkXlibSurfaceCreateInfoKHR
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
    dpy long
    window long
class
VkWin32SurfaceCreateInfoKHR
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
    hinstance long
    hwnd long
class
VkSurfaceCapabilitiesKHR
    minImageCount int
    maxImageCount int
    currentExtentWidth int
    currentExtentHeight int
    minImageExtentWidth int
    minImageExtentHeight int
    maxImageExtentWidth int
    maxImageExtentHeight int
    maxImageArrayLayers int
    supportedTransforms int
    currentTransform int
    supportedCompositeAlpha int
    supportedUsageFlags int
class
VkSurfaceFormatKHR
    format int
    colorSpace int
class
VkSwapchainCreateInfoKHR
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
    surface long
    minImageCount int
    imageFormat int
    imageColorSpace int
    imageExtentWidth int
    imageExtentHeight int
    imageArrayLayers int
    imageUsage int
    imageSharingMode int
    queueFamilyIndexCount int
    _pad2 int
    pQueueFamilyIndices long
    preTransform int
    compositeAlpha int
    presentMode int
    clipped int
    oldSwapchain long
class
VkCommandPoolCreateInfo
    sType int
    _pad0 int
    pNext long
    flags int
    queueFamilyIndex int
class
VkCommandBufferAllocateInfo
    sType int
    _pad0 int
    pNext long
    commandPool long
    level int
    commandBufferCount int
class
VkCommandBufferBeginInfo
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
    pInheritanceInfo long
class
VkImageSubresourceRange
    aspectMask int
    baseMipLevel int
    levelCount int
    baseArrayLayer int
    layerCount int
class
VkImageMemoryBarrier
    sType int
    _pad0 int
    pNext long
    srcAccessMask int
    dstAccessMask int
    oldLayout int
    newLayout int
    srcQueueFamilyIndex int
    dstQueueFamilyIndex int
    image long
    subresourceAspectMask int
    subresourceBaseMipLevel int
    subresourceLevelCount int
    subresourceBaseArrayLayer int
    subresourceLayerCount int
    _pad2 int
class
VkFenceCreateInfo
    sType int
    _pad0 int
    pNext long
    flags int
    _pad1 int
class
VkSubmitInfo
    sType int
    _pad0 int
    pNext long
    waitSemaphoreCount int
    _pad1 int
    pWaitSemaphores long
    pWaitDstStageMask long
    commandBufferCount int
    _pad2 int
    pCommandBuffers long
    signalSemaphoreCount int
    _pad3 int
    pSignalSemaphores long
class
VkPresentInfoKHR
    sType int
    _pad0 int
    pNext long
    waitSemaphoreCount int
    _pad1 int
    pWaitSemaphores long
    swapchainCount int
    _pad2 int
    pSwapchains long
    pImageIndices long
    pResults long

Functions

extern def vkCreateInstance(pCreateInfo: VkInstanceCreateInfo, pAllocator: long, pIsnstance: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroyInstance(instance: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkEnumerateInstanceVersion(pApiVersion: &int) -> int

C library function, called as declared in the library's own documentation.

extern def vkEnumeratePhysicalDevices(instance: long, pPhysicalDeviceCount: &int, pPhysicalDevices: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice: long, pQueueFamilyPropertyCount: &int, pQueueFamilyProperties: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkGetPhysicalDeviceProperties(physicalDevice: long, pProperties: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkCreateDevice(physicalDevice: long, pCreateInfo: VkDeviceCreateInfo, pAllocator: long, pDevice: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroyDevice(device: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkGetDeviceQueue(device: long, queueFamilyIndex: int, queueIndex: int, pQueue: &long) -> None

C library function, called as declared in the library's own documentation.

extern def vkCreateXlibSurfaceKHR(instance: long, pCreateInfo: VkXlibSurfaceCreateInfoKHR, pAllocator: long, pSurface: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkCreateWin32SurfaceKHR(instance: long, pCreateInfo: VkWin32SurfaceCreateInfoKHR, pAllocator: long, pSurface: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroySurfaceKHR(instance: long, surface: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice: long, queueFamilyIndex: int, surface: long, pSupported: &int) -> int

C library function, called as declared in the library's own documentation.

extern def vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice: long, surface: long, pSurfaceCapabilities: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice: long, surface: long, pSurfaceFormatCount: &int, pSurfaceFormats: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkCreateSwapchainKHR(device: long, pCreateInfo: VkSwapchainCreateInfoKHR, pAllocator: long, pSwapchain: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroySwapchainKHR(device: long, swapchain: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkGetSwapchainImagesKHR(device: long, swapchain: long, pSwapchainImageCount: &int, pSwapchainImages: long) -> int

C library function, called as declared in the library's own documentation.

def vkMakeVersion(major: int, minor: int, patch: int) -> int

Packs major/minor/patch into a Vulkan version number.

def vk_alloc_device_props() -> long

Allocates a VkPhysicalDeviceProperties buffer (824 bytes, raw_alloc); free with raw_free.

def vk_device_props_device_type(props: long) -> int

The device type field of a properties buffer.

def vk_device_props_device_name(props: long) -> str

The device name of a properties buffer.

def vk_get_first_physical_device(instance: long) -> long

The first physical device of an instance, 0 if none.

def vk_find_graphics_queue_family(physicalDevice: long) -> int

Index of the first queue family with VK_QUEUE_GRAPHICS_BIT, -1 if none.

def vk_create_logical_device(physicalDevice: long, queueFamilyIndex: int) -> long

Creates a logical device with one queue of the given family.

def vk_create_xlib_surface(instance: long, display: long, window: long) -> long

Linux: creates a VkSurfaceKHR for an X11 window.

def vk_create_win32_surface(instance: long, hinstance: long, hwnd: long) -> long

Windows: creates a VkSurfaceKHR for a window of user32 (vkCreateWin32SurfaceKHR, from its HINSTANCE and HWND).

def vk_create_window_surface(instance: long, display: long, window: long) -> long

Creates the VkSurfaceKHR for a window of libstd/window, from the display, window that window_open returned: an X11 surface on Linux, a Win32 one on Windows. The portable choice.

def vk_get_surface_capabilities(physicalDevice: long, surface: long) -> VkSurfaceCapabilitiesKHR

Surface capabilities (extent, image counts, transforms).

def vk_pick_surface_format(physicalDevice: long, surface: long) -> (int, int)

Picks a (format, colorSpace) pair supported by the surface.

def vk_create_swapchain(device: long, surface: long, format: int, colorSpace: int, width: int, height: int, minImageCount: int, preTransform: int) -> long

Creates a swapchain with the given format, size and image count.

def vk_get_swapchain_images(device: long, swapchain: long) -> (long, int)

The swapchain images as (pointer to handles, count).

def create_vulkan_instance(app_name: str) -> VkApplicationInfo

Fills a VkApplicationInfo for vk_create_instance.

def vk_create_instance(pCreateInfo: VkApplicationInfo) -> long

Creates the instance (with the Xlib surface extensions enabled).

def vk_destroy_instance(instance: long) -> None

Destroys the instance.

extern def vkCreateCommandPool(device: long, pCreateInfo: VkCommandPoolCreateInfo, pAllocator: long, pCommandPool: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroyCommandPool(device: long, commandPool: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkAllocateCommandBuffers(device: long, pAllocateInfo: VkCommandBufferAllocateInfo, pCommandBuffers: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkFreeCommandBuffers(device: long, commandPool: long, commandBufferCount: int, pCommandBuffers: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkBeginCommandBuffer(commandBuffer: long, pBeginInfo: VkCommandBufferBeginInfo) -> int

C library function, called as declared in the library's own documentation.

extern def vkEndCommandBuffer(commandBuffer: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkCmdPipelineBarrier(commandBuffer: long, srcStageMask: int, dstStageMask: int, dependencyFlags: int, memoryBarrierCount: int, pMemoryBarriers: long, bufferMemoryBarrierCount: int, pBufferMemoryBarriers: long, imageMemoryBarrierCount: int, pImageMemoryBarriers: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkCmdClearColorImage(commandBuffer: long, image: long, imageLayout: int, pColor: long, rangeCount: int, pRanges: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkCreateFence(device: long, pCreateInfo: VkFenceCreateInfo, pAllocator: long, pFence: &long) -> int

C library function, called as declared in the library's own documentation.

extern def vkDestroyFence(device: long, fence: long, pAllocator: long) -> None

C library function, called as declared in the library's own documentation.

extern def vkWaitForFences(device: long, fenceCount: int, pFences: long, waitAll: int, timeout: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkResetFences(device: long, fenceCount: int, pFences: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkAcquireNextImageKHR(device: long, swapchain: long, timeout: long, semaphore: long, fence: long, pImageIndex: &int) -> int

C library function, called as declared in the library's own documentation.

extern def vkQueueSubmit(queue: long, submitCount: int, pSubmits: long, fence: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkQueueWaitIdle(queue: long) -> int

C library function, called as declared in the library's own documentation.

extern def vkQueuePresentKHR(queue: long, pPresentInfo: VkPresentInfoKHR) -> int

C library function, called as declared in the library's own documentation.

def vk_create_command_pool(device: long, queueFamilyIndex: int) -> long

A command pool for a queue family.

def vk_allocate_command_buffers(device: long, pool: long, count: int) -> long

Allocates count primary command buffers; returns a pointer to their handles.

def vk_make_clear_color_buf() -> long

A VkClearColorValue buffer.

def vk_make_color_subresource_range() -> VkImageSubresourceRange

A colour subresource range covering one mip level and layer.

def vk_record_clear_cmdbuf(cmdbuf: long, image: long, clearColor: long, range: long) -> None

Records a clear of a swapchain image into a command buffer.

def vk_create_fence(device: long, signaled: int) -> long

Creates a fence, optionally signalled.

def vk_present_frame(device: long, swapchain: long, queue: long, cmdbufs: long, fence: long) -> None

Acquires the next image, submits the matching command buffer, presents, waits for the fence.