bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.04k stars 3.44k forks source link

weird binary problem #130

Closed coolit closed 2 years ago

coolit commented 4 years ago

Yesterday I built a binary on win10 in release mode and copied it to a new folder named "xxx". The cmd I used was: cargo run --target-dir "D:/rust_build/all" --release --example button Today I deleted all content under D:/rust_build/all and changed the cmd to the following and rebuilt it: cargo run --target-dir "D:/rust_build/" --release --example button

Then of course no error occurred to the new binary. But the following error occurred when I ran the old binary under folder "xxx":

thread '<unnamed>' panicked at 'Failed to execute glslangValidator: Os { code: 2, kind: NotFound, message: "系统找不到指定的文件。" }', C:\Users\Administrator\.cargo\registry\src\mirrors.sjtug.sjtu.edu.cn-4f7dbcce21e258a2\bevy-glsl-to-spirv-0.1.7\src\lib.rs:59:18
"系统找不到指定的文件" means "The system cannot find the specified file"
cart commented 4 years ago

hmm very interesting. looks like its failing to find the glslLangValidator binary (which makes sense given its a standalone executable). https://github.com/cart/glsl-to-spirv/blob/7c4b23dc3c2386e85dad4f0492353b54e61c2fb8/src/lib.rs#L59

This is absolutely a problem that needs solving.

I can think of three fixes:

  1. Copy the glslLangValidator binary so it is a sibling of the bevy output
  2. Once naga is ready, we can compile the shader compiler into the bevy game binary itself.
  3. Do ahead-of-time shader compilation to Spir-V, so the final binary doesn't need glslLangValidator (or naga)
cart commented 4 years ago

The issue is we do "on demand shader compilation" based on run time state. Shaderc (or naga) is really the perfect fit for this kind of thing.

We don't use the shaderc rust bindings because they complicate the builds, especially on windows, but that would also be a fix.

StarArawn commented 4 years ago

It might be nice to have a bevy_shaderc plugin/optional feature? Naga is still a ways out from being usable even though a lot of progress has been made.

eliaspekkala commented 4 years ago

The error 'Failed to execute glslangValidator' also occurs if you move the bevy folder.

To reproduce:

  1. git clone https://github.com/bevyengine/bevy.git && cd bevy
  2. cargo run --example 3d_scene (works)
  3. cd .. && mkdir otherfolder
  4. mv bevy otherfolder && cd otherfolder/bevy
  5. cargo run --example 3d_scene (fails)
~/.../otherfolder/bevy >>> cargo run --example 3d_scene
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s
     Running `target/debug/examples/3d_scene`
thread '<unnamed>' panicked at 'Failed to execute glslangValidator: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/elias/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy-glsl-to-spirv-0.1.7/src/lib.rs:59:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To fix:

  1. cargo clean
  2. cargo run --example 3d_scene (works)

To fix (if you use sccache)

  1. rm -rf ~/.cache/sccache (note: this will delete everything sccache has cached!)
  2. cargo clean
  3. cargo run --example 3d_scene (works)

These fixes work for now. Let's work towards using naga :)

szunami commented 4 years ago

Hey all, I hit this today too. I'm new to this ecosystem and not sure what the pros / cons of naga vs shaderc are; I note that docs say that shaderc should be used in place of bevy-glsl-to-spirv.

@cart could you elaborate on the build issues with shaderc? Are they discussed somewhere? Would you be willing to accept a PR adding shaderc to solve this problem?

cart commented 4 years ago

There's already a PR out for it. I explain my rationale there: https://github.com/bevyengine/bevy/pull/324

szunami commented 4 years ago

I managed to work around this by forking glsl-to-spirv (https://github.com/szunami/glsl-to-spirv/blob/master/src/lib.rs#L31)

Obviously this is a bit jank, but I should be ok for now. Thanks all!

PrototypeNM1 commented 4 years ago

@cart I'm tackling this as part of moving glsl-to-spirv to using glslang as a library. Could you assign the issue to me?

cart commented 4 years ago

Sure, but lets sync up on what your plan is first. I would like to retain the "works without additional setup" properties of the current approach if we can, which would mean providing precompiled binaries.

We have a few "solutions" to the problem in general:

  1. adapt glsl-to-spirv to use precompiled libs instead of precompiled exes
  2. add the option to use our existing shaderc support on desktop platforms (currently only enabled for ios). this has the downside of complicating builds, so i would prefer to not do this by default.
  3. somehow make naga work (already a pr out for this)
alice-i-cecile commented 2 years ago

Closed as we now use naga.