DiligentGraphics / DiligentEngine

A modern cross-platform low-level graphics library and rendering framework
http://diligentgraphics.com/diligent-engine/
Apache License 2.0
3.62k stars 330 forks source link

Building Error using Emscripten with WebGPU #317

Open mingweiLIU opened 1 month ago

mingweiLIU commented 1 month ago

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.

TheMostDiligent commented 1 month ago

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.

mingweiLIU commented 1 month ago

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(

TheMostDiligent commented 1 month ago

What is your build setup?

mingweiLIU commented 1 month ago

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

TheMostDiligent commented 1 month ago

I am now confused what you trying to do.

TheMostDiligent commented 1 month ago

Did you follow the Emscripten build instructions?

mingweiLIU commented 4 weeks ago

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.

TheMostDiligent commented 4 weeks ago

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.

mingweiLIU commented 3 weeks ago

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

TheMostDiligent commented 3 weeks ago

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

mingweiLIU commented 2 weeks ago

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.