Skip to content

C++ Wrapper #596

Open
Open

Description

@MendyBerger

I'd like to propose adding a C++ wrapper to this repository.

Dawn ships webgpu_cpp.h, which has become the de facto standard C++ bindings for WebGPU. That works well if you want to use Dawn's implementation, but if you want to use C++ with a different backend — wasi:webgpu in our case — the only option is to bind directly to the C header. That defeats the purpose of having a standard, implementation-agnostic header, at least for C++ use cases

Emscripten also implements webgpu_cpp.h, so it's already in use across multiple projects and backends, not just Dawn.

Would it make sense to move (or adopt an equivalent of) webgpu_cpp.h into webgpu-headers, so it becomes a standard C++ wrapper that any implementation (Dawn, wgpu-native, wasi:webgpu, etc.) can provide, rather than something tied to a specific implementation?

Activity

  1. kainino0x commented on Jul 14, 2026

    @kainino0x
    Collaborator

    I think C++ bindings should live in a separate project, here's my rationale:

    • This repo defines a stable API and ABI, a C++ binding project would only need to provide a stable API and wouldn't really ever need to be fully stable
    • There is a lot of room for different designs, and C++ bindings are usability-focused (rather than FFI-focused like C), so naturally there will be competing C++ bindings.
      There's at least one other: https://github.com/eliemichel/WebGPU-Cpp
    • The C bindings are minimal, only defining the stable subset and intending for separate headers to define extensions (though Dawn currently still doesn't do this, it dumps everything in one header).
      In C++, it's impossible to add methods to a previously-defined class, so C++ bindings would more naturally be maximal, defining bindings to any and all implementations and all their (possibly unstable) extensions and having multiple versions (like both Dawn and eliemichel's bindings do) or use #if to enable different parts.
      Related: Making language bindings portable over different versions of webgpu.h #202
  2. added
    non-breakingDoes not require a breaking change (that would block V1.0)
    on Jul 14, 2026
  3. MendyBerger commented on Jul 15, 2026

    @MendyBerger
    ContributorAuthor

    A separate repo under this org would be fine, the point is official standing, not this repo specifically.

    Some context on why I opened this: big projects like llama.cpp and onnx-runtime write their WebGPU backends against Dawn's webgpu_cpp.h, so they're stuck on one implementation. I'd like to get them onto backend-agnostic code so they also work on wgpu-native, wasi:webgpu, etc.

    https://github.com/eliemichel/WebGPU-Cpp shows this is doable, but a project that size isn't going to depend on a single-maintainer repo, however good it is. Dawn's header became the standard because Google ships it. If there were an official wrapper somewhere under webgpu-native, "use the standard bindings instead of Dawn's" becomes a PR I can actually send them. Right now it isn't.

  4. kainino0x commented on Jul 15, 2026

    @kainino0x
    Collaborator

    Makes sense. Unfortunately the amount of maintainer power behind this org is not really any bigger, it has some participation from wgpu and Dawn but no dedicated time from anyone (wgpu-native hasn't even seen much progress in updating to the stabilized webgpu.h). And since Dawn has its own bindings we wouldn't really be contributing to it. Though I definitely want to see there be portable C++ bindings.

    Maybe @eliemichel would be interested in making WebGPU-Cpp more official?

  5. MendyBerger commented on Jul 17, 2026

    @MendyBerger
    ContributorAuthor

    Not sure how realistic this is, but would Dawn be open to donating webgpu_cpp.h to the org?

    It seems like the path of least resistance: the header already has maintainers (Dawn's team, who keep it current with webgpu.h) and a large existing user base through both Dawn and Emscripten. The maintenance wouldn't change, just where it lives — Dawn consumes it from here like any other implementation would. That sidesteps the maintainer-power problem, since the org isn't taking on work nobody has time for.

    Compared to other options, this one also has the smallest migration cost for the ecosystem. Projects like llama.cpp and onnx-runtime are already written against webgpu_cpp.h, so if it lived here they'd get backend-agnostic bindings essentially for free — whereas any new or adopted wrapper asks all of those projects to port.

    That said, making WebGPU-Cpp more official would be a great outcome too — just wanted to put this on the table as well.

  6. Kangz commented on Jul 21, 2026

    @Kangz
    Collaborator

    Dawn should be able to produce a C++ header for the subset of dawn.json that matches the headers in this repo, but Dawn cannot consume C++ headers from this repo because it adds a lot of Dawn-specific extensions. We also cannot make stability guarantees for the C++ headers as we keep tweaking them to make them more ergonomic or safe to use. I also don't know what the mechanisms would be to generate the headers because the code generators live in Dawn and use a JSON file instead of YAML.

    If it were to happen, I believe we'd need to generate the C++ headers using upstream Dawn's code generator by producing an alternative JSON file for it.

  7. MendyBerger commented on Aug 19, 2026

    @MendyBerger
    ContributorAuthor

    Maybe an easier ask would be to add a webgpu.h or wasi to the dawn generator
    This should not take a lot of work since it would be more restrictive than all the other options in there.
    Something like this

    If the dawn maintainers would be open to this, I'm happy to open a PR if outside contributions are allowed.

  8. Kangz commented on Aug 19, 2026

    @Kangz
    Collaborator

    Dawn can take something like this and put it as part of the generation of the "webgpu_headers" that match the headers here.

    Contributing is certainly welcome! https://dawn.googlesource.com/dawn/+/refs/heads/main/CONTRIBUTING.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    non-breakingDoes not require a breaking change (that would block V1.0)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions