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

use naga instead of spirv-reflect for shader reflection #2130

Closed
wants to merge 11 commits into from

Conversation

jakobhellermann
Copy link
Contributor

@jakobhellermann jakobhellermann commented May 7, 2021

Replaces spirv-reflect with naga only for shader reflection. The glsl to spirv compilation ist still done using beyv-glsl-to-spirv.

For some reason the spirv-reflect dependency can't be removed though, because I then get a ton of linker errors (fixed in cart/glsl-to-spirv#13):

Errors
 ld.lld: error: undefined symbol: operator new[](unsigned long)
          >>> referenced by /home/travis/build/KhronosGroup/glslang/glslang/CInterface/glslang_c_interface.cpp
          >>>               glslang_c_interface.cpp.o:(DirStackFileIncluder::newIncludeResult(std::string const&, std::basic_ifstream<char, std::char_traits<char> >&, int) const) in archive /home/jakob/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.2.1/build/linux/libglslang.glsltospirv.a
          >>> referenced by /home/travis/build/KhronosGroup/glslang/glslang/MachineIndependent/ShaderLang.cpp
          >>>               ShaderLang.cpp.o:((anonymous namespace)::CompileDeferred(TCompiler*, char const* const*, int, int const*, char const* const*, char const*, EShOptimizationLevel, TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, glslang::TIntermediate&, glslang::TShader::Includer&, std::string, glslang::TEnvironment*)) in archive /home/jakob/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.2.1/build/linux/libglslang.glsltospirv.a
          >>> referenced by /home/travis/build/KhronosGroup/glslang/glslang/MachineIndependent/ShaderLang.cpp
          >>>               ShaderLang.cpp.o:((anonymous namespace)::CompileDeferred(TCompiler*, char const* const*, int, int const*, char const* const*, char const*, EShOptimizationLevel, TBuiltInResource const*, int, EProfile, bool, bool, EShMessages, glslang::TIntermediate&, glslang::TShader::Includer&, std::string, glslang::TEnvironment*)) in archive /home/jakob/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.2.1/build/linux/libglslang.glsltospirv.a
          >>> referenced 17 more times
...

This could allow shader reflection to work on wasm, however I'm not sure if that is useful, as spirv isn't used in wasm contexts IIRC.
It should also fix a bug with spirv-reflect @mtsr was experiencing which lead to CubeArray images being incorrectly reflected as Cube.

fixes #2122

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen labels May 7, 2021
@bjorn3
Copy link
Contributor

bjorn3 commented May 8, 2021

For some reason the spirv-reflect dependency can't be removed though, because I then get a ton of linker errors:

I presume that beyv-glsl-to-spirv is missing some linker args then that spirv-reflect does declare. Probably -lstdc++ on Linux or -lc++ on macOS.

@cart
Copy link
Member

cart commented May 14, 2021

Sounds like we have this tested on linux already. If we can verify the other glsl-to-spirv platforms (windows, macos) I think we're good to go!

I'd like to verify android too, but its currently broken for other reasons, which will make that job hard.

@cart
Copy link
Member

cart commented May 14, 2021

To clarify: "If we can verify the other glsl-to-spirv platforms using the just-merged glsl-to-spirv version then we're good to go".

We will need to sort out the following issue before we can publish a new glsl-to-spirv version: cart/glsl-to-spirv#12. I'll ping the crates.io team to request a size increase for the new crate.

(which I consider a prerequisite to merging this pr)

@NiklasEi
Copy link
Member

Sounds like we have this tested on linux already. If we can verify the other glsl-to-spirv platforms (windows, macos) I think we're good to go!

What exactly do I need to do to test this?

@mockersf
Copy link
Member

mockersf commented May 14, 2021

on macOS, after using this pr and changing bevy-glsl-to-spirv dependency to

bevy-glsl-to-spirv = { git = "https://github.com/cart/glsl-to-spirv", rev = "fe95427b7935d205885c7d2976c407f92e231205"}
    Updating git repository `https://github.com/cart/glsl-to-spirv`
    Updating git submodule `https://github.com/KhronosGroup/glslang.git`
error: failed to get `bevy-glsl-to-spirv` as a dependency of package `bevy_render v0.5.0 (bevy/crates/bevy_render)`

Caused by:
  failed to load source for dependency `bevy-glsl-to-spirv`

Caused by:
  Unable to update https://github.com/cart/glsl-to-spirv?rev=fe95427b7935d205885c7d2976c407f92e231205

Caused by:
  failed to update submodule `glsl-to-spirv-builder/glslang`

Caused by:
  object not found - no match for id (e22e71ed4b53713311dc24bcc54a44b95767cb92); class=Odb (9); code=NotFound (-3)

@cart
Copy link
Member

cart commented May 14, 2021

Checkout this pr, checkout the glsl-to-spirv pr with the fix, edit bevy_render's cargo.toml to point to the local glsl-to-spirv checkout containing the PR changes, run a 3d example.

@mtsr
Copy link
Contributor

mtsr commented May 15, 2021

I just:

  • Checked out out the above branch of glsl-to-spirv;
  • Changed bevy_render to use bevy-glsl-to-spirv = { path = "../../../glsl-to-spirv" }
  • Did a cargo update;
  • Tested the 2d, 3d and shader examples.

No problems.

@bevyengine bevyengine deleted a comment May 16, 2021
@jakobhellermann
Copy link
Contributor Author

@mockersf it seems like cargo can't handle bevy-glsl-to-spirv's submodule configuration. Can you try cloning the repo and adding the dependency using path = ...?

@mockersf
Copy link
Member

works fine by pointing to a local clone 👍

@superdump
Copy link
Contributor

superdump commented Jun 6, 2021

Just a note that this fixes #2122 for me on macOS. I have tested 3d_scene, shader_custom_material, array_texture, and shader_defs examples and all work fine. Can this be merged? What are we waiting on?

@cart
Copy link
Member

cart commented Jun 7, 2021

At this point we're just blocked on a bevy-glsl-to-spirv release (see the comments about it above). I reached out to the crates.io team awhile back and they're cool with bumping the limit on the new crate, so I just need to publish an empty version of the crate, have them bump the limit on the crate, then publish the real version of the crate.

@cart
Copy link
Member

cart commented Jun 7, 2021

Just published the empty crate and asked the crates.io team to bump the size limit.

@mockersf
Copy link
Member

mockersf commented Jun 8, 2021

Unrelated to the switch to naga, but I just remembered that when updating bevy-glsl-to-spirv we should also change how it's selected (from #1819) to match the new platform supported

@cart cart added the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 23, 2021
@mockersf mockersf removed the S-Pre-Relicense This PR was made before Bevy added the Apache license. Cannot be merged or used for other work label Jul 24, 2021
@alice-i-cecile
Copy link
Member

Is this still relevant with the pipelined-rendering work?

@cart
Copy link
Member

cart commented Sep 23, 2021

It might inform future reflection work, but the types have all changed a lot and so far we've been favoring a more explicit model. Auto-reflection on the level of the current bevy_render is too opinionated in a number of areas. I do think that we eventually might want something a bit more automatic, but I think we'll need to revisit the interfaces to ensure we aren't restricting things too much. I'll close this for now.

@cart cart closed this Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example shader/array_texture crash with wgpu error
9 participants