DiligentEngine icon indicating copy to clipboard operation
DiligentEngine copied to clipboard

Building Error using Emscripten with WebGPU

Open mingweiLIU opened this issue 1 year ago • 11 comments

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.

mingweiLIU avatar Oct 10 '24 09:10 mingweiLIU

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.

TheMostDiligent avatar Oct 10 '24 15:10 TheMostDiligent

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(

mingweiLIU avatar Oct 12 '24 10:10 mingweiLIU

What is your build setup?

TheMostDiligent avatar Oct 12 '24 16:10 TheMostDiligent

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

mingweiLIU avatar Oct 14 '24 01:10 mingweiLIU

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=OFF is 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).

TheMostDiligent avatar Oct 14 '24 05:10 TheMostDiligent

Did you follow the Emscripten build instructions?

TheMostDiligent avatar Oct 14 '24 05:10 TheMostDiligent

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.

mingweiLIU avatar Oct 18 '24 11:10 mingweiLIU

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.

TheMostDiligent avatar Oct 18 '24 21:10 TheMostDiligent

Yes, I followed the instructions for build_and_run_emscripten, the errors are same.

mingweiLIU avatar Oct 21 '24 06:10 mingweiLIU

Honestly, I don't know what the problem is. Here is the last CI build that uses same setup and works without issues

TheMostDiligent avatar Oct 22 '24 04:10 TheMostDiligent

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.

mingweiLIU avatar Oct 28 '24 02:10 mingweiLIU

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

mingweiLIU avatar Dec 23 '25 01:12 mingweiLIU

Are you building for Web or Windows? Which emscripten version do you use?

TheMostDiligent avatar Dec 23 '25 02:12 TheMostDiligent

Are you building for Web or Windows? Which emscripten version do you use?

TheMostDiligent avatar Dec 23 '25 02:12 TheMostDiligent

I am building for Web, emsdk is the latest 4.0.22

mingweiLIU avatar Dec 23 '25 02:12 mingweiLIU

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

MikhailGorobets avatar Dec 23 '25 02:12 MikhailGorobets

Ok, this will not work as Emscripten completely changed how they support WebGPU, and Diligent has not yet been updated. Try 4.0.0

TheMostDiligent avatar Dec 23 '25 02:12 TheMostDiligent

thanks, 4.0.0 works!

mingweiLIU avatar Dec 23 '25 03:12 mingweiLIU