Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a wgpu backend #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add a wgpu backend #63

wants to merge 9 commits into from

Conversation

expenses
Copy link
Contributor

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 #62 (comment).

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

src/render_wgpu.rs Outdated Show resolved Hide resolved
@expenses
Copy link
Contributor Author

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.

@repi
Copy link
Owner

repi commented Apr 27, 2021

Cool will try it out

@repi
Copy link
Owner

repi commented Apr 27, 2021

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

@expenses
Copy link
Contributor Author

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
Copy link
Contributor Author

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 expenses marked this pull request as ready for review April 30, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants