Vulkan.c3
Vulkan bindings for C3 language
Install / Use
/learn @tonis2/Vulkan.c3README
Vulkan.c3
Vulkan bindings for C3, auto-generated from the official Vulkan XML specification. Covers Vulkan 1.0 through 1.4 with all platform-compatible extensions included.
- Idiomatic C3 error handling — Vulkan error codes map to C3 faults
- Builder pattern — auto-generated
.set*()and.build()methods for Vulkan structs - Cross-platform — Windows, Linux (X11/Wayland), and macOS
Project structure
vk/ # Generated + hand-written bindings (this is the library)
vk.c3 # Types, enums, structs, unions
commands.c3 # Function declarations and extension loading
builders.c3 # Auto-generated builder/setter methods
extra.c3 # Hand-written type aliases (platform types, function pointers)
helpers.c3 # Convenience wrappers (swapchain, device queries, etc.)
buffer.c3 # Memory allocator and buffer helpers
parser/ # Bindings generator (reads vk.xml, writes vk/*.c3)
build.c3 # Main generator logic
types.c3 # XML parsing types
examples/
cube/ # 3D rotating cube with camera controls
Quick start
Prerequisites
- C3 compiler (latest version)
- Vulkan drivers installed for your GPU
Running the cube example
Linux:
c3c run cube
Windows:
c3c run cube-win
macOS (needs Vulkan SDK rpath):
c3c run cube -z -rpath -z /path/to/VulkanSDK/macOS/lib
Platform setup
Linux — install Vulkan packages for your distro:
# Ubuntu/Debian
sudo apt install libvulkan-dev vulkan-tools vulkan-validationlayers-dev spirv-tools
# Fedora
sudo dnf install vulkan-loader-devel vulkan-tools vulkan-validation-layers-devel spirv-tools
# Arch
sudo pacman -S vulkan-icd-loader vulkan-tools vulkan-validation-layers spirv-tools
Windows — download and install the Vulkan SDK. Make sure VULKAN_SDK is set. The cube-win target includes Windows SDK configuration for cross-compilation from Linux.
macOS — download the Vulkan SDK for macOS and pass the library path when building (see above).
Using the library in your project
Option 1: Download the pre-built library
Download vulkan.c3l from releases, place it in your project (e.g. ./libs/), and add it to your project.json:
{
"dependency-search-paths": ["./libs"],
"dependencies": ["vulkan"],
"linked-libraries": ["vulkan"]
}
Option 2: Build from source
c3c build zip --trust=full
This creates vulkan.c3l in the project root.
Example usage
import vk;
fn void! main() {
ApplicationInfo info = {
.pApplicationName = "My App",
.pEngineName = "My Engine",
.applicationVersion = vk::@makeApiVersion(0, 1, 0, 0),
.engineVersion = vk::@makeApiVersion(0, 1, 0, 0),
.apiVersion = vk::@makeApiVersion(0, 1, 3, 0)
};
InstanceCreateInfo instanceInfo = vk::instanceCreateInfo()
.setApplicationInfo(&info)
.setEnabledExtensionNames(extensions.array_view());
vk::Instance instance;
vk::createInstance(&instanceInfo, null, &instance)!;
}
The builder pattern lets you chain .set*() calls, then call .build() on create-info structs:
vk::Pipeline pipeline = vk::graphicsPipelineCreateInfo()
.setStages(shader_stages)
.setLayout(pipeline_layout)
.setRenderPass(render_pass)
.build(device)!;
Regenerating bindings
To regenerate the bindings from the latest Vulkan XML specification:
sh build.sh
This downloads vk.xml from the Khronos repository and runs the parser. All extensions compatible with supported platforms (Win32, X11, XCB, Wayland, macOS/Metal, iOS) are included. Extensions referencing undefined types are automatically skipped.
Resources
- Window library (c3w) — windowing dependency used by the examples
- Example game — a larger project using these bindings
- C3 documentation
- Vulkan Tutorial
- Vulkan Specification
License
See LICENSE.
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
