A C11 library that implements a Vulkan-to-WebGPU translation layer, enabling Vulkan API code to run in browsers via WebAssembly.
WebVulkan acts as a shim between the Vulkan API and WebGPU, translating Vulkan calls to their WebGPU equivalents at runtime. This allows existing Vulkan codebases to target the web with minimal modifications.
┌─────────────────┐
│ Application │
│ (Vulkan API) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ WebVulkan │ ← Translation Layer
│ (this library) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ WebGPU │
│ (Browser/GPU) │
└─────────────────┘
- Vulkan API Compatibility: Implements core Vulkan 1.0 API subset
- SPIR-V to WGSL Transpilation: Converts Vulkan shaders to WebGPU-compatible WGSL
- WebAssembly Support: Builds with Emscripten for browser deployment
- Zero Dependencies: Only requires Vulkan headers (fetched automatically)
- Reference Counting: Proper object lifecycle management
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildRequires Emscripten SDK.
# Setup Emscripten
source /path/to/emsdk/emsdk_env.sh
# Configure and build
emcmake cmake -B build-wasm \
-DCMAKE_BUILD_TYPE=Release \
-DWEBVULKAN_WASM=ON \
-DWEBVULKAN_BUILD_TESTS=OFF \
-DWEBVULKAN_BUILD_SAMPLES=ON
cmake --build build-wasm| Option | Default | Description |
|---|---|---|
WEBVULKAN_BUILD_SAMPLES |
ON | Build sample applications |
WEBVULKAN_BUILD_TESTS |
ON | Build unit tests |
WEBVULKAN_WASM |
OFF | Build for WebAssembly |
#include <vulkan/vulkan.h>
VkApplicationInfo app_info = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = "MyApp",
.apiVersion = VK_API_VERSION_1_0,
};
VkInstanceCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pApplicationInfo = &app_info,
};
VkInstance instance;
VkResult result = vkCreateInstance(&create_info, NULL, &instance);WebVulkan supports direct WGSL shader input by passing the WGSL source as the shader code:
const char* vertex_wgsl =
"@vertex\n"
"fn main(@location(0) pos: vec2<f32>) -> @builtin(position) vec4<f32> {\n"
" return vec4<f32>(pos, 0.0, 1.0);\n"
"}\n";
VkShaderModuleCreateInfo shader_info = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.codeSize = strlen(vertex_wgsl),
.pCode = (const uint32_t*)vertex_wgsl,
};
VkShaderModule module;
vkCreateShaderModule(device, &shader_info, NULL, &module);After building for WebAssembly, serve the sample files:
cd build-wasm/samples
python3 -m http.server 8080Then open http://localhost:8080/triangle/ in a WebGPU-compatible browser.
| Object | Status | Notes |
|---|---|---|
| VkInstance | ✅ | Full support |
| VkPhysicalDevice | ✅ | Single device |
| VkDevice | ✅ | Full support |
| VkQueue | ✅ | Full support |
| VkCommandBuffer | ✅ | Basic recording |
| Object | Status | Notes |
|---|---|---|
| VkBuffer | ✅ | Full support |
| VkImage | ✅ | 2D textures |
| VkImageView | ✅ | Full support |
| VkDeviceMemory | ✅ | Host-visible memory |
| VkSampler | ✅ | Basic sampling |
| Object | Status | Notes |
|---|---|---|
| VkShaderModule | ✅ | WGSL input |
| VkPipelineLayout | ✅ | Full support |
| VkPipeline | ✅ | Graphics pipelines |
| VkDescriptorSet | ✅ | Uniform buffers |
| VkDescriptorSetLayout | ✅ | Full support |
| Object | Status | Notes |
|---|---|---|
| VkSemaphore | ✅ | Binary semaphores |
| VkFence | ✅ | Full support |
| VkEvent | ✅ | Full support |
See docs/ARCHITECTURE.md for detailed architecture documentation.
src/
├── core/ # Instance, Device, PhysicalDevice, Queue
├── objects/ # Vulkan object implementations
├── commands/ # Command buffer recording
├── shaders/ # SPIR-V parser and WGSL generator
├── sync/ # Synchronization primitives
├── memory/ # Memory management
└── util/ # Utilities (list, hash table)
WebVulkan requires WebGPU support. Tested browsers:
- Chrome 113+ (stable)
- Chrome Canary (latest)
- Edge 113+
- Firefox Nightly (behind flag)
- Single physical device only
- No tessellation or geometry shaders
- Limited SPIR-V transpilation (direct WGSL recommended)
- No ray tracing support
- Fork the repository
- Create a feature branch
- Ensure code passes
clang-formatandclang-tidy - Add tests for new functionality
- Submit a pull request
MIT License - see LICENSE file for details.
- Khronos Group for Vulkan and WebGPU specifications
- Emscripten for WebAssembly toolchain
- Google Naga for SPIR-V/WGSL translation reference