Skip to content

Added WGVK webgpu backend#9246

Open
r-lyeh wants to merge 3 commits intoocornut:masterfrom
r-lyeh:wgvk
Open

Added WGVK webgpu backend#9246
r-lyeh wants to merge 3 commits intoocornut:masterfrom
r-lyeh:wgvk

Conversation

@r-lyeh
Copy link

@r-lyeh r-lyeh commented Feb 15, 2026

Hello Omar,

  • Here is a preliminary PR that adds a new webgpu backend (WGVK) targetting Vulkan.
  • By default, WGVK can only consume SPIRV shaders: WGSL and GLSL shaders can be enabled by linking against extra libs. The fastest way to have WGSL shaders enabled is to link against Simple_WGSL and add their -DSUPPORT_WGSL directive to the build commands.
  • In order to simplify adoption and minimize build problems I have decided to support both modes: vanilla WGVK(SPIRV) and WGVK+WGSL support.
    • If the end-user decides to link only against the vanilla wgvk.c file, then the webgpu backend will load some new embedded WGSL->SPIRV shaders which can be found now in the implementation.
    • If the end-user decides to link against wgvk.c AND Simple_WGSL AND add the -DSUPPORT_WGSL directive, then the backend will consume the existing WGSL shaders and the current backend is probably on parity with Dawn and WGPU.
    • To simplify the process in the future, it would be probably good to try loading WGSL first, and switching to SPIRV as a fallback if shader compilation fails, I guess.
  • While integrating the new backend some problems in the GLFW3/SDL2/SDL3 examples were found, mostly about setting up the device and some UB logic regarding the async/futures setup. Why this was not crashing for WGPU/Dawn is not known to me, but apparently passing a adapterCallbackInfo.mode = 0 to the spec is invalid (the enumeration starts from 1).
  • The backend has been tested against latest WGVK (with and without Simple_WGSL) and SDL2/SDL3/GLFW3 backends.
  • No hurries to merge this PR at the moment, but it is probably a good time to start discussing the proposed changes.

@procedural
Copy link

rip r-lyeh, let Omar's wrath be merciful

@ocornut
Copy link
Owner

ocornut commented Feb 16, 2026

Before I have a chance to look at this, I have an immediate problem which is that I noticed today that latest Emscripten the WGPU backend doesn't compile anymore:
https://github.com/ocornut/imgui/actions/runs/22069146278/job/63768805098

Which version of Emcripten did you build with?

The new version is 5.0.1 but even if I replace to use the defines html5_webgpu.h is missing.
It works with 5.0.0 (!) but not 5.0.1.
It works with 4.0.23.
And here I thought 4.0 was the end of our problems, nope 😭 cc @BrutPitt

I cannot find where proper Emscripten/WGPU changelog are published.
Many major open-source projects don't seem to care about exposing reliable changelogs apparently (neither Emscripten neither SDL3 do).

@ocornut
Copy link
Owner

ocornut commented Feb 16, 2026

  • Can you confirm Emscripten (and potentially WGVK) version used?
  • Did you test building and/or running changes with WGPU and DAWN? (preferably yes, but if you didn't I'd appreciate to know)
  • If that's easy for you could you squash everything into 1 commit, so we don't have to carry a bunch of unrelated stuff in history?
  • I don't know where the shader sources are?
  • Could the same shaders sources in backends/vulkan/* and stored binary in backends/imgui_impl_vulkan.cpp be used for some of the path?
  • Best to not make ImGui_ImplWGPU_CreateShaderModule() a template and simply use e.g. void*
  • If SUPPORT_WGSL is not a standard define then the name should presumably use a IMGUI_IMPL_WEBGPU_XXX prefix? But it seems like this could be a runtime flag rather than a compile-time one? Would a ImGui_ImplWGPU_SetShaderSourceType(WGPUSType shader_source_type) be more adequate?

While integrating the new backend some problems in the GLFW3/SDL2/SDL3 examples were found, mostly about setting up the device and some UB logic regarding the async/futures setup

  • Could this be isolated in a dedicated commit? So we can make and tests with other backends.

ocornut added a commit that referenced this pull request Feb 16, 2026
…mples currently don't build with 5.0.1).

Getting 'warning: unused function 'CreateWGPUSurface' [-Wunused-function]' in some build paths.
cc #9246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants