-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make WebGPU backend portable to emscripten, Dawn, and wgpu-native #6188
Make WebGPU backend portable to emscripten, Dawn, and wgpu-native #6188
Conversation
Hello, Thanks for the PR. There are too many changes here. Each individual change would need to be carefully explained and discussed in its own commit. Your changelog mention "Adapter for LearnWebGPU tutorial series" which seems different from what is stated here and in the change. I believe the WEBGPU_NONSTD_RELEASE mess may be beneficial to change to a single Why was the a wgpuBufferRelease() call removed? |
b349a02
to
4dd88e8
Compare
Thx for the feedback:
Tested with emscripten, wgpu-native + Windows, Dawn + Windows, and got feedback that it works on wgpu-native + macOS but could not test myself. |
Hello, The only change that I can potentially merging without further explanation is the one with the defines (for WEBGPU_BACKEND_WGPU). For each change I would otherwise needs an explanation as to why you are making the change. e.g.
Thank you. |
Hello, I understand, here are some details: Switch to WGSL. Hard to track down were the official discussion is about this right now because it is not a consensual choice, but last time I checked the possibility to use SPIR-V shaders in WebGPU was only transitional:
From @Kangz (source) (BTW hi Corentin if you'd have some heads up this'd help :) ) Using SPIR-V would remain possible when building Desktop applications (using wgpu-native or Dawn) but not when cross-compiling for the web (emscripten). (On a side note, I believe that binary blobs in source code are not convenient to maintain but as I'm not the maintainer here this isn't really a point.) Alignment. I first added it because the WebGPU device was raising a runtime error complaining about it. Then when squashing it seemed to no longer be a problem, then I got the error again... I'm still investigating but at this stage it might be hardware and/or backend dependent. According to the alignment and size rules, the Release vs Drop. The different names in wgpu-native vs Dawn correspond to slightly different semantics in their role. The issue lasts from the very beginning of the project and is still open and both Drop and Release have been proposed but remain unmerged. I believe it does not affect the way it is used here but I mention it FYI. Gamma correction. Dawn only allow |
This is still the case in browsers. WGSL has become a decent language now and all WebGPU implementation (in native or Web) will support it. So IMHO imgui should just use that for the small amount of shaders it needs. Alignment Vertex buffers and index buffers only need an alignment of 4. I'm not sure what the 16 alignment is for Release v Drop: we really need to settle this between Dawn and wgpu :/ Gamma correction: on the Web the GPUCanvasContext can be configured with |
backends/imgui_impl_wgpu.cpp
Outdated
@group(1) @binding(0) var t: texture_2d<f32>; | ||
|
||
@fragment | ||
fn main(in: VertexOutput) -> @location(0) vec4<f32> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: in the future when wgpu supports them, you could use shorthand types like vec4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep I'm looking fwd to it :)
Thanks a lot for your review :) (about alignment, I wrote 16 instead of 4 for vertex buffer, but in the code it's aligned to 4 bytes as expected) |
Needs confirmation but it seems that the globals (around line 80) don't do well with multiple ImGui contexts. But this deserves a whole new PR I think. |
582e4d7
to
fd944ec
Compare
Amend from original pr to use a macro.
fd944ec
to
c8d770b
Compare
Thanks both for your kind explanation.
That's correct, I've pushed those changes in cbdac1e + rebased this PR over this. For alignment, I used a macro instead For the remaining:
|
…d Gamma uniform. (#6188) Add gamma correction uniform Group uniforms in a single binding The second binding was not satisfying the minimum BufferBindingType::Uniform alignment (256) and since this alignment is large it is more idiomatic to group uniforms tegether. Also ensures that the size of the uniform buffer is aligned to 16 bytes.
Fix include for wgpu-native
c8d770b
to
11d34d5
Compare
Amend: I made a mistake merging the WGSL change before the Gamma one as they depended on each others. |
It feels to me that "wgpu" tends to refer to Firefox' implementation of WebGPU so
I believe it would be good to settle on macros at the scale of the whole ecosystem. The choice of |
I strongly believe that Dawn and wgpu should be targeting the same header eventually. There is basically a single issue to resolve, and some tech debt. So the |
This is now fully merged, there is no more backend discrepencies requiring some |
Hello Elie, |
For what is used in this backend, yes they do. So what you progressively merged for Dawn/emscripten just works with wgpu-native as well (no more need for the custom preprocessor macros). I stopped using my branch and switched my projects to the official ImGui v1.89.8; it works in all 3 build cases! |
Note that as of 1ac162f we have added define to facilitate supporting both Dawn and WGPU. |
The wgpu backend was only compatible with emscripten's flavor of WebGPU, which does not exactly match the officiel webgpu native headers.
This PR adds support for the two main (and only?) implementations of WebGPU that one can use when building native binary applications instead of wasm:
The header assumes that the following macros are defined:
WEBGPU_BACKEND_WGPU
iff wgpu-native backend is usedWEBGPU_BACKEND_DAWN
iff Dawn backend is usedWEBGPU_BACKEND_EMSCRIPTEN
is assumedNB These macros are automatically defined in the WebGPU-binaries distributions (
main
branch uses wgpu-native,dawn
branch uses Dawn) which are used in my LearnWebGPU for native C++ tutorial series. This gives the context in which I adapted this wgpu backend.Notable changes