Skip to content

Minimum-Viable-Web/wgpuc

Repository files navigation

Build Releases

WGPUC — WebGPU in C99

⚠️ EXPERIMENTAL – This project is under active development and APIs may change without notice. Use at your own risk.


WGPUC is a pure C99 implementation of the WebGPU standard, providing a cross-platform graphics and compute API with multiple backend support.


Looking for a tiny web development ecosystem? See: Minimum Viable Web


Supported Backends

Backend Platform Status
Vulkan Windows, Linux, Android In Progress
Metal macOS, iOS Stubbed
D3D12 Windows 10+ In Progress
D3D11 Windows 7+ In Progress
OpenGL / GLES Cross-platform In Progress

Features

  • Pure C99 — No language dependencies in the core library
  • WebGPU Standard Compliant — Follows the W3C WebGPU specification
  • Multi-Backend — Single API surface across Vulkan, Metal, D3D12, D3D11, and OpenGL
  • Embeddable — Designed for integration into games, engines, and applications

Layout

  • CMakeLists.txt — Top-level build entrypoint with validation toggles
  • include/ — Public headers (wgpu.h, wgpu_platform.h, wgpu_limits.h)
  • src/ — Implementation:
    • api/ — API entrypoints
    • core/, val/ — Resource/state management and validation logic
    • hal/ — Hardware abstraction layer interface
    • shader/ — Shader compilation and reflection
    • backends/ — Platform-specific backends (Vulkan, Metal, D3D12, D3D11, GL)

Build

Basic Build

cmake -S . -B build -DWGPU_ENABLE_VALIDATION=ON
cmake --build build

Build with WGSL Translation (Metal Backend)

To enable WGSL-to-MSL translation for the Metal backend, you need Rust/Cargo installed:

# Install Rust if not already installed
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build with WGSL translation enabled
cmake -S . -B build -DWGPU_ENABLE_WGSL_TRANSLATION=ON
cmake --build build

The WGSL translator uses naga (from wgpu-native) to translate WGSL shaders to Metal Shading Language (MSL) at runtime.

Test

cmake -S . -B build -DWGPU_BUILD_TESTS=ON
cmake --build build
ctest --test-dir build --output-on-failure

Key Resources

Backend Feature Matrix

This is a per-backend feature tracker for the implementation. The authoritative status board is TRACKING.md (with enforcement), and intentional gaps/stubs are tracked in STUB_REGISTRY.md.

Legend: ✅ Implemented | ⚠️ Partial | ❌ Not Implemented

Core Object Model

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Adapter enumeration All backends enumerate hardware
Device creation Queue created with device
Limits negotiation ⚠️ ⚠️ Vulkan/Metal query actual limits; others use defaults

Surfaces & Present

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Surface creation Platform-specific (HWND, CAMetalLayer, etc.)
Swapchain configure DXGI/Vulkan swapchain, GL FBOs
Acquire texture Returns current backbuffer view
Present SwapBuffers/Present/drawable present

Buffers

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Create buffer All usage flags supported
Map/Unmap Persistent mapping where available
Queue write buffer Staging + copy or direct write
Buffer destroy Resource cleanup

Textures

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Create texture 2D textures; 3D/array partial
Texture views ⚠️ GL emulates views (no GL 4.3 texture_view)
Depth/stencil formats ⚠️ GL limited format support
Color formats ⚠️ GL subset of formats

Samplers

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Create sampler Filter/wrap/LOD/compare
Comparison samplers Shadow sampling

Bind Groups & Layouts

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Bind group layout Descriptor set layouts / root signature
Bind group creation Resource binding
Buffer bindings Uniform/storage buffers
Texture bindings Sampled textures
Sampler bindings Separate samplers
Storage texture bindings ⚠️ ⚠️ ⚠️ UAV/imageStore support varies

Shader Modules

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
WGSL ingestion ⚠️ ⚠️ Vulkan via SPIR-V, Metal via naga→MSL, GL via WGSL→GLSL
SPIR-V ingestion Native Vulkan only
HLSL ingestion D3D backends native
Shader reflection ⚠️ ⚠️ Binding/layout derivation

Pipelines

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Render pipeline Vertex + fragment stages
Compute pipeline ⚠️ GL requires 4.3+
Pipeline layout Derived or explicit
Vertex input state ⚠️ D3D11 input layout partial
Depth/stencil state ⚠️ ⚠️ D3D partial

Render Passes

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Begin/end render pass Framebuffer setup
Color attachments Multiple render targets
Depth/stencil attachment ⚠️ ⚠️ D3D partial
Load/store ops Clear/load/store
Set pipeline Bind render pipeline
Set bind group Bind descriptor sets
Set vertex buffer ⚠️ ⚠️ D3D vertex buffer binding partial
Set index buffer ⚠️ ⚠️ D3D index buffer binding partial
Draw Non-indexed draw
Draw indexed ⚠️ ⚠️ D3D indexed draw partial
Draw instanced Instance drawing

Compute Passes

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Begin/end compute pass ⚠️ GL requires 4.3+
Set pipeline ⚠️ GL requires 4.3+
Set bind group ⚠️ GL requires 4.3+
Dispatch ⚠️ GL requires 4.3+

Command Encoding

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Copy buffer to buffer ⚠️ D3D11 via mapped memory
Copy buffer to texture ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Partial across all backends
Copy texture to buffer ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Partial across all backends
Queue submit Command buffer execution

Synchronization

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Queue submit fence Wait for completion
Resource barriers ⚠️ Vulkan/D3D12 explicit barriers

Validation & Testing

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Validation layer ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Basic validation in src/val/*
Backend tests ⚠️ ⚠️ ⚠️ See tests/backend/*

Roadmap

  • Harden Vulkan sync/validation (barriers, timelines, present paths)
  • Flesh out shader module ingestion (WGSL/SPIR-V) and richer pipeline state
  • Extend backend HAL shims for Metal/D3D12 and fill remaining stubs
  • Advance GL backend: add WGSL→GLSL path, pipeline/bind group binding, draw/compute support
  • Add validation layer
  • Expand conformance tests and sample programs

License

WGPUC is MIT licensed. See LICENSE.MIT.

Releases

No releases published

Contributors

Languages