shadertoy-browser icon indicating copy to clipboard operation
shadertoy-browser copied to clipboard

Add a `wgpu` backend

Open expenses opened this issue 4 years ago • 7 comments

This wgpu backend creates all the pipelines in about 30 seconds on linux, which imo is good enough and doesn't mean we require a pipeline cache as suggested in https://github.com/repi/shadertoy-browser/pull/62#issuecomment-824176822.

It works flawlessly on linux via vulkan, but I'm still trying it out on macos so better to wait to see how that goes before merging.

expenses avatar Apr 22 '21 16:04 expenses

on wgpu 0.7.1, spirv_cross is used to compile shader to metal, and SIGABRTs when it fails to compile something:

there was a compiler error: Cannot resolve expression type.
fish: Job 1, 'cargo run --release' terminated by signal SIGABRT (Abort)

So we can either A) not the wgpu backend on macos or B) use the git version of wgpu, which uses naga instead and let's you catch the errors.

expenses avatar Apr 22 '21 17:04 expenses

Yikes, I got the git version of wgpu to work on macOS but it hangs the GPU 😟. Perhaps because naga creates less optimised metal shaders than spirv-opt does at present? I've got a branch here: https://github.com/expenses/shadertoy-browser/pull/new/wgpu-git-backend if you want to try it and see if you have more luck.

expenses avatar Apr 22 '21 18:04 expenses

Yikes, I got the git version of wgpu to work on macOS but it hangs the GPU 😟. Perhaps because naga creates less optimised metal shaders than spirv-opt does at present? I've got a branch here: https://github.com/expenses/shadertoy-browser/pull/new/wgpu-git-backend if you want to try it and see if you have more luck.

It works pretty well on my eGPU actually, so I think that using the git version is the way to go for now. Some shaders stall (which causes the whole grid to stall when that's enabled) and some feel a bit unoptimised but in general it works well.

expenses avatar Apr 27 '21 18:04 expenses

Cool will try it out

repi avatar Apr 27 '21 18:04 repi

Oh on Windows getting a bunch of linking errors with shaderc from spirv-cross, dll vs static linking issue:

 = note: libspirv_cross-0fc766aebb3b8d0a.rlib(wrapper.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_cross.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_cross_util.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_glsl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_hlsl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_msl.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_cfg.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_cross_parsed_ir.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          libspirv_cross-0fc766aebb3b8d0a.rlib(spirv_parser.o) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in libshaderc_sys-74ac287a3a40a409.rlib(shaderc.obj)
          LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
          libshaderc-b97a02d3fb476473.rlib(shaderc-b97a02d3fb476473.shaderc.1on52s2i-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol shaderc_compile_options_set_target_spirv referenced 
in function _ZN7shaderc14CompileOptions16set_target_spirv17h04af859c75cbe1bbE
          libshaderc-b97a02d3fb476473.rlib(shaderc-b97a02d3fb476473.shaderc.1on52s2i-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol shaderc_compile_options_set_invert_y referenced in function _ZN7shaderc14CompileOptions12set_invert_y17h7ea8b52b62d1889eE
          libshaderc-b97a02d3fb476473.rlib(shaderc-b97a02d3fb476473.shaderc.1on52s2i-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol shaderc_compile_options_set_nan_clamp referenced in 
function _ZN7shaderc14CompileOptions13set_nan_clamp17haebce51401d88381E
          C:\git\private\shadertoy-browser\target\release\deps\shadertoy_browser.exe : fatal error LNK1120: 3 unresolved externals

repi avatar Apr 27 '21 22:04 repi

Hmm, I don't use Windows that often so I can't really help you there. One of the env variables from https://github.com/google/shaderc-rs#setup might help.

expenses avatar Apr 28 '21 21:04 expenses

Now that wgpu 0.8 is out, we can use that instead. I didn't encounter the same shaderc problem as you, probably because I had the vulkan sdk installed. We could set the build-from-source feature for shaderc and that would also fix the problem.

expenses avatar Apr 30 '21 15:04 expenses