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 Notes
Vulkan Windows, Linux, Android ~95% (production-ready) Primary backend. Default blend state, no async submit
D3D12 Windows 10+ ~90% Blocked end-to-end on WGSL→HLSL wiring
D3D11 Windows 7+ ~90% Same WGSL→HLSL blocker
OpenGL / GLES Currently Windows-only ~50% Pipeline/compute incomplete; cross-platform context modules pending
Metal macOS, iOS Scaffolding (~0% end-to-end) Pure-C Objective-C runtime bridge exists; no shader path to MSL yet

See TRACKING.md for the authoritative per-backend board and per-backend review docs under docs/.

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

Shader Translation

WGPUC has two WGSL translation paths:

  • Built-in pure-C99 translator (src/shader/wgslc/): unconditionally compiled, emits GLSL/MSL/HLSL. No external toolchain. Currently not yet wired into the D3D/Metal/GL pipeline-creation paths — see the roadmap below.
  • Optional naga path (WGPU_ENABLE_WGSL_TRANSLATION=ON): uses naga via a Rust crate for higher-fidelity translation. Requires Rust/Cargo installed.
# (Optional) install Rust if you want the naga path
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

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

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 ⚠️ ⚠️ ⚠️ ⚠️ In-tree wgslc translator exists but not yet wired to Metal/D3D/GL pipeline creation
SPIR-V ingestion Native Vulkan only
Shader reflection ⚠️ ⚠️ ⚠️ ⚠️ SPIR-V reflection is primary

Pipelines

Feature Vulkan Metal D3D12 D3D11 GL/GLES Notes
Render pipeline ⚠️ Metal pipeline exists but has no shader source
Compute pipeline ⚠️ ⚠️ GL requires 4.3+; Metal shader-path blocker
Pipeline layout Derived or explicit
Vertex input state ⚠️ D3D11 input layout partial
Depth/stencil / primitive / blend / multisample state ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Descriptor fields partially exposed; blend state and full primitive/stencil state pending

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+; Metal shader-path blocker
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 ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Minimal; descriptor/usage/limits validation pending
Backend tests ⚠️ ⚠️ ⚠️ Happy-path only; see tests/backend/*

Not yet on any backend

Query sets (occlusion, timestamp), render bundles, indirect draw/dispatch, debug markers, dynamic state (viewport/scissor/blend constant/stencil ref), texture-to-texture copy, ClearBuffer, async APIs (mapAsync, requestAdapter/Device callbacks, onSubmittedWorkDone), error scopes, uncaptured-error and device-lost callbacks, real feature negotiation, getCompilationInfo(). Tracked in TRACKING.md and .cursor/plans/.

Roadmap

Near-term focus: wire the in-tree wgslc translator into Metal/D3D12/D3D11/GL pipeline creation, fill the missing command-encoding and dynamic-state APIs, add an async/error model, and build out the validation layer.

Detailed per-area plans live in .cursor/plans/; authoritative status in TRACKING.md.

License

WGPUC is MIT licensed. See LICENSE.MIT.

Releases

No releases published

Contributors

Languages