Some questions about hello-webgpu
FuXiii opened this issue · comments
When I research hello-webgpu
use Emscripten
, I had met some questions:
- Using
Emscripten
to compilemain.cpp
(./src/main.cpp
) will includewebgpu.h
(./inc/webgpu.h
), andwebgpu.h
(./inc/webgpu.h
) will also includewebgpu/webgpu.h
. Where is thiswebgpu/webgpu.h
? - 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 - Where can I find documents such as
-s WASM=1,-s USE_WEBGPU=1
inCMAKE_EXE_LINKER_FLAGS
- Why would there be a
shell.html
file? For what purpose? Where can I find the document? - What is
glue.h/glue.cpp
used for? Where can I find the document? - Where are documents such as
WGPUDevice
? Inhttps://www.w3.org/TR/webgpu/
theWGPUDevice
was not found in the official documentation ofWebGPU
, butGPUDevice
could be found, but such asWGPUSurfaceDescriptorFromCanvasHTMLSelector
orGPUSurfaceDescriptorFromCanvasHTMLSelector
could not be found. - Where is the WebGPU document for
Emscripten
?
Thanks~(●'◡'●)ノ♥
Hi! Some answers:
webgpu/webgpu.h
is part of Emscripten, in thesystem
folder (see here).- The
nonportable-include-path
warning is from Clang, and I read about it years ago. - All the Emscripten flags are documented here. Anything missing can be found in the settings sources.
- 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
). glue.h
andglue.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.- 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.
- 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!
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. (`・ω・′)ゞ
Link fixed!
Thanks~(●'◡'●)ノ♥
Some question about compile hello-webgpu
base emscripten
:
-
Why must use
#define KEEP_IN_MODULE extern "C" __attribute__((used, visibility("default")))
before_glue_main_()
?
Where I can find the documents about it?#ifndef KEEP_IN_MODULE #define KEEP_IN_MODULE extern "C" __attribute__((used, visibility("default"))) #endif KEEP_IN_MODULE void _glue_main_() { __main__(0, nullptr); }
-
In
glue.cpp
the_glue_main_()
will call__main__(int argc, char* argv[])
which defined inmain.cpp
,but inJavaScript
codevoid glue_preint()
which defined inEM_JS
it will call thevar entry
which is__glue_main_
.Whyentry
equal to__glue_main_
instead of_glue_main_
(one less underline) ?KEEP_IN_MODULE void _glue_main_() { __main__(0, nullptr); } EM_JS(void, glue_preint, (), { var entry = __glue_main_; // Why can't be: var entry = _glue_main_;
I try to find the
JavaScript
code in browser, I found:... var __glue_main_, _main, _malloc, _free, stackSave, stackRestore, stackAlloc, dynCall_jiji; WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { asm = output.instance.exports; __glue_main_ = asm["_glue_main_"]; ... }
Is that means all exposed
C/C++
function intoWebAssembly
will add a underline in front of it?
ヾ(๑╹◡╹)ノ" Thanks~
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.
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.
The page URL is this
It fails because WebGPU use needs serving from a secure context (HTTPS). This link works, for example:
Thank you very much!!! ~(●'◡'●)ノ♥