cwoffenden / hello-webgpu

Cross-platform C++ example for WebGPU and Dawn
272 stars 36 forks source link

Some questions about hello-webgpu #17

Closed FuXiii closed 1 year ago

FuXiii commented 1 year ago

When I research hello-webgpu use Emscripten, I had met some questions:

  1. Using Emscripten to compile main.cpp (./src/main.cpp) will include webgpu.h(./inc/webgpu.h), and webgpu.h(./inc/webgpu.h) will also include webgpu/webgpu.h. Where is this webgpu/webgpu.h?
  2. Where can I found the documents for the various flags set in CMAKE_CXX_FLAGS? I can't found the description about -Wno-nonportable-include-path in gcc doc
  3. Where can I find documents such as -s WASM=1,-s USE_WEBGPU=1 in CMAKE_EXE_LINKER_FLAGS
  4. Why would there be a shell.html file? For what purpose? Where can I find the document?
  5. What is glue.h/glue.cpp used for? Where can I find the document?
  6. Where are documents such as WGPUDevice? In https://www.w3.org/TR/webgpu/ the WGPUDevice was not found in the official documentation of WebGPU, but GPUDevice could be found, but such as WGPUSurfaceDescriptorFromCanvasHTMLSelector or GPUSurfaceDescriptorFromCanvasHTMLSelector could not be found.
  7. Where is the WebGPU document for Emscripten?

Thanks~(●'◡'●)ノ♥

cwoffenden commented 1 year ago

Hi! Some answers:

  1. webgpu/webgpu.h is part of Emscripten, in the system folder (see here).
  2. The nonportable-include-path warning is from Clang, and I read about it years ago.
  3. All the Emscripten flags are documented here. Anything missing can be found in the settings sources.
  4. The shell file is to have a cut-down HTML page that does the loading, display, etc., of the Wasm content. You can build without it, but then you get all of the Emscripten console and other widgets on your page (details, little as they are, are found on the flags docs above, search for --shell-file).
  5. glue.h and glue.cpp are my code, used to hold other parts of the code together. Since this is written for Windows, Mac and the browser, it smooths out some of the features. Compare with the Mac and Windows sources.
  6. I wrote this years ago to experiment with Dawn and WebGPU. Not many docs existed at the time and I worked things out from whatever I could, some from the spec docs, some from the Dawn examples.
  7. It's all very incomplete, and you'll need to look at Dawn and the JavaScript APIs to make sense of it.

Hope that helps!

FuXiii commented 1 year ago

Thank you for your answer! o(〃'▽'〃)o In the third item the documented here link url is https://github.com/cwoffenden/hello-webgpu/issues/nonportable-include-path it look like a invalid link. (`・ω・′)ゞ

cwoffenden commented 1 year ago

Link fixed!

FuXiii commented 1 year ago

Thanks~(●'◡'●)ノ♥

FuXiii commented 1 year ago

Some question about compile hello-webgpu base emscripten:

ヾ(๑╹◡╹)ノ" Thanks~

cwoffenden commented 1 year ago

The KEEP_IN_MODULE macro is used because I want to call _glue_main_() from JavaScript (once the WebGPU context has been asynchronously created). Without this, and depending on other compiler flags, it risks being either name mangled or removed from the exports.

And yes, in JS an extra _ is inserted.

FuXiii commented 1 year ago

Ok, Thanks~ ٩(๑❛ᴗ❛๑)۶

If I run hello-webgpu in python -m http.server server, it will work well. but if I copy hello-webgpu.html , hello-webgpu.js and hello-webgpu.wasm into real http server and open the page in same browser it will show nothing and output No support for WebGPU error message.

image

The page URL is this

cwoffenden commented 1 year ago

It fails because WebGPU use needs serving from a secure context (HTTPS). This link works, for example:

https://wip.numfum.com/cw/2023-05-12/index.html

FuXiii commented 1 year ago

Thank you very much!!! ~(●'◡'●)ノ♥