Building Error using Emscripten with WebGPU
Hi, I am building DiligentEngine using Emscripten on Windows with WebGPU, and I used dawn as the native implementation of WebGPU, there are a lot of type name errors, such as :
DiligentCore/Graphics/GraphicsEngineWebGPU/src/WebGPUResourceBase.cpp:78:13: error: use of undeclared identifier 'wgpuBufferGetMapState' if (wgpuBufferGetMapState(BufferInfo.wgpuBuffer) == WGPUBufferMapState_Unmapped)
/DiligentCore/Graphics/GraphicsEngineWebGPU/include\WebGPUTypeConversions.hpp:58:1: error: unknown type name 'WGPUMipmapFilterMode'; did you mean 'WGPUFilterMode'? WGPUMipmapFilterMode FilterTypeToWGPUMipMapMode(FILTER_TYPE FilterType);
and there seems no document about how to build DiligentEngine to run on the browser with WebGPU.
On Windows, did you build it by setting DILIGENT_NO_WEBGPU=OFF CMake variable?
When building for the Web, WebGPU backend is enabled by default. To use it, you initialize it like any other backend. Here is an example. The only caveat is that the device needs to be preinitialized in java script.
after setting DILIGENT_NO_WEBGPU OFF there is no conflict while some errors about JSON parsing, the errors just like:
In file included from E:/DilligentEngine/webgpu/DiligentTools/RenderStateNotation/src/RenderStateNotationParserImpl.cpp:27: In file included from E:/DilligentEngine/webgpu/DiligentTools/RenderStateNotation/include\pch.h:36: E:/DilligentEngine/webgpu/build/Emscripten/DiligentTools/RenderStateNotation/parser_headers\generated/CommonParser.hpp:83:10: error: no matching member function for call to 'get_to' 83 | Json.get_to(pObject); | ~~~~~^~~~~~ E:/DilligentEngine/webgpu/DiligentTools/RenderStateNotation/src/RenderStateNotationParserImpl.cpp:70:9: note: in instantiation of function template specialization 'Diligent::ParseRSN<Diligent::PipelineStateDesc, true>' requested here 70 | ParseRSN(Json["PSODesc"], Type.PSODesc, Allocator); | ^ E:/DilligentEngine/webgpu/DiligentTools/ThirdParty/json/single_include/nlohmann\json.hpp:21100:17: note: candidate template ignored: requirement 'detail::has_from_json<nlohmann::basic_json<std::map, std::vector, std::string, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>, void>, Diligent::PipelineStateDesc, void>::value' was not satisfied [with ValueType = Diligent::PipelineStateDesc] 21100 | ValueType & get_to(ValueType& v) const noexcept(noexcept(
What is your build setup?
Environment:Windows & Emscripten SDK 3.1.65 & Ninja 1.10.2 generation command:emcmake cmake -S . -B ./build/Emscripten -G "Ninja" -DDILIGENT_NO_WEBGPU=OFF build command:cmake --build ./build/Emscripten
I am now confused what you trying to do.
- When you are building for the Web using Emscripten (on any platform, Windows, Mac or Linux), Dawn or any other native implementation is not needed, WebGPU headers are provided by Emscripten. Also,
DILIGENT_NO_WEBGPU=OFFis set by default and does not need to be set explicitly. WebGPU is enabled automatically. - You need Dawn if you want to use WebGPU backend when running native application (e.g., on Windows, you will be able to select WebGPU backend when running Windows application).
Did you follow the Emscripten build instructions?
Yes,I followed the instuctions, and the reason why I used -DDILIGENT_NO_WEBGPU=OFF is that I had set the WebGPU ON and used dawn to build native application, I used the option to force it to be off.
If you are building for the Web, please follow these instructions that detail how to build and run the samples in the browser.
If you are building native application and want to enable WebGPU, use -DDILIGENT_NO_WEBGPU=OFF. You should not need anything besides that.
Yes, I followed the instructions for build_and_run_emscripten, the errors are same.
Honestly, I don't know what the problem is. Here is the last CI build that uses same setup and works without issues
There may be some errors in my compile environment since cmake log shows can‘t find the ASM compiler, however I can't fix it currently.
Hi, after a year, I noticed that the webgpu build instructions have been changed, and I followed them to have a try, while still getting errors, this time they are webgpu/webgpu.h file not found. I am using Windows with vs2022
Are you building for Web or Windows? Which emscripten version do you use?
Are you building for Web or Windows? Which emscripten version do you use?
I am building for Web, emsdk is the latest 4.0.22
I am building for Web, emsdk is the latest 4.0.22
Emscripten version 4.0.10 breaks compatibility with WebGPU. Please try this branch to run with version 4.0.22 https://github.com/MikhailGorobets/DiligentCore/tree/upgrade_dawn
Ok, this will not work as Emscripten completely changed how they support WebGPU, and Diligent has not yet been updated. Try 4.0.0
thanks, 4.0.0 works!