EmbarkStudios / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://shader.rs
Apache License 2.0
7.31k stars 246 forks source link

Panic when compiling `bevy-pbr-rust` with `--spirt-passes=reduce` #1004

Open Shfty opened 1 year ago

Shfty commented 1 year ago

Expected Behaviour

Successful compilation of bevy-pbr-rust with --spirt-passes=reduce enabled via RUSTGPU_CODEGEN_ARGS.

This was done using the v0.5.0 tag as a preliminary test before upgrading to v0.6.0, under advisement of @eddyb.

Example & Steps To Reproduce

Compile via spirv-builder, rustc panics with the attached backtrace.

The following minimal reproduction case illustrates the issue:

#![no_std]

use spirv_std::{
    glam::{Mat3, Mat4, Vec4},
    spirv,
};

#[spirv(vertex)]
pub fn vertex(foo: Vec4) {
    // No panic if the add is removed
    let bar = Mat4::IDENTITY + Mat4::IDENTITY;

    // No panic if using Mat3::from_mat4
    let _baz = Mat3 {
        x_axis: bar.x_axis.truncate(),
        y_axis: bar.y_axis.truncate(),
        z_axis: bar.z_axis.truncate(),
    }
    // No panic if removing this mul
    * foo.truncate();
}

System Info

Backtrace

Backtrace

``` Compiling shader v0.1.0 (/mnt/projects/personal/rust/Projects/bevy-rust-gpu-project/example-workspace/rust-gpu/crates/shader) thread 'rustc' panicked at 'no entry found for key', /home/user/.cargo/git/checkouts/spirt-9c237dd53f05c2cc/0fed5a9/src/spv/lift.rs:1185:44 stack backtrace: 0: 0x7f45a4c0785a - std::backtrace_rs::backtrace::libunwind::trace::h51cb40f2f8f23f31 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f45a4c0785a - std::backtrace_rs::backtrace::trace_unsynchronized::hebc3338ffed58a56 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f45a4c0785a - std::sys_common::backtrace::_print_fmt::h136f982a4680ac7f at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f45a4c0785a - ::fmt::hd1514baae6e42eb6 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f45a4c6a36e - core::fmt::write::hfbed4b54a5eebfee at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/core/src/fmt/mod.rs:1208:17 5: 0x7f45a4bf7bd5 - std::io::Write::write_fmt::h9f6098b6a54a9a94 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/io/mod.rs:1682:15 6: 0x7f45a4c07625 - std::sys_common::backtrace::_print::h6e7a2bc7da6ecf73 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f45a4c07625 - std::sys_common::backtrace::print::h631b25ef82a0eea1 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f45a4c0a36f - std::panicking::default_hook::{{closure}}::h41299fc951b157c9 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/panicking.rs:267:22 9: 0x7f45a4c0a0ab - std::panicking::default_hook::hd317023abfdceaed at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/panicking.rs:286:9 10: 0x7f4597521b95 - rustc_codegen_spirv::__rustc_codegen_backend::{{closure}}::ha48d52bd426b74ce 11: 0x7f45a4c0abad - as core::ops::function::Fn>::call::h813f31c5cc72640d at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/alloc/src/boxed.rs:2032:9 12: 0x7f45a4c0abad - std::panicking::rust_panic_with_hook::h2e61684db9120e8e at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/panicking.rs:692:13 13: 0x7f45a4c0a929 - std::panicking::begin_panic_handler::{{closure}}::h63d39cc19c97d34a at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/panicking.rs:579:13 14: 0x7f45a4c07d0c - std::sys_common::backtrace::__rust_end_short_backtrace::h8da6b271e1c3c543 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys_common/backtrace.rs:137:18 15: 0x7f45a4c0a632 - rust_begin_unwind at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/panicking.rs:575:5 16: 0x7f45a4c66d53 - core::panicking::panic_fmt::h89c37196e57a859c at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/core/src/panicking.rs:64:14 17: 0x7f45a4c66ea1 - core::panicking::panic_display::h9291dff40a4a809f at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/core/src/panicking.rs:135:5 18: 0x7f45a4c66e4b - core::panicking::panic_str::h647e8fee22e5d4a5 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/core/src/panicking.rs:119:5 19: 0x7f45a4c66ad6 - core::option::expect_failed::hfb5fae7076a47926 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/core/src/option.rs:1923:5 20: 0x7f459766c9b4 - spirt::spv::lift::LazyInst::to_inst_and_attrs::{{closure}}::hf6e1b5db38327d33 21: 0x7f45977698db - as core::iter::traits::collect::Extend<::Item>>::extend::h1736bb6dadb49a30 22: 0x7f459766be5c - spirt::spv::lift::LazyInst::to_inst_and_attrs::hdb8c034edb0fa0a0 23: 0x7f45976f91dd - spirt::spv::lift::::lift_to_spv_module_emitter::hed2e99131c8ead1c 24: 0x7f4597519a9c - rustc_codegen_spirv::linker::link::h376c672ae7aaefe3 25: 0x7f45973c9be5 - rustc_codegen_spirv::link::link::h21377f283e4c1a0a 26: 0x7f459751f52d - ::link::hf332f3cf7f1aa6b0 27: 0x7f45a2cd9c1a - ::link 28: 0x7f45a2cbc98b - rustc_span[fd000e025c1fef5b]::with_source_map::, rustc_interface[58e4822cc60d2a6c]::interface::run_compiler, rustc_driver[8fc339cf4408bec4]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 29: 0x7f45a2cbc3a5 - >::set::, rustc_driver[8fc339cf4408bec4]::run_compiler::{closure#1}>::{closure#0}, core[486592e7c49a8aa]::result::Result<(), rustc_errors[5442e185e098f882]::ErrorGuaranteed>> 30: 0x7f45a2cbb992 - std[14b7645e29e8dad4]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[8fc339cf4408bec4]::run_compiler::{closure#1}>::{closure#0}, core[486592e7c49a8aa]::result::Result<(), rustc_errors[5442e185e098f882]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[486592e7c49a8aa]::result::Result<(), rustc_errors[5442e185e098f882]::ErrorGuaranteed>> 31: 0x7f45a32f2c1a - <::spawn_unchecked_, rustc_driver[8fc339cf4408bec4]::run_compiler::{closure#1}>::{closure#0}, core[486592e7c49a8aa]::result::Result<(), rustc_errors[5442e185e098f882]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[486592e7c49a8aa]::result::Result<(), rustc_errors[5442e185e098f882]::ErrorGuaranteed>>::{closure#1} as core[486592e7c49a8aa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 32: 0x7f45a4c14983 - as core::ops::function::FnOnce>::call_once::hdbff13d45d6b3b01 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/alloc/src/boxed.rs:2000:9 33: 0x7f45a4c14983 - as core::ops::function::FnOnce>::call_once::h1e5384a2b7a0037a at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/alloc/src/boxed.rs:2000:9 34: 0x7f45a4c14983 - std::sys::unix::thread::Thread::new::thread_start::h4b8540c4f94d9763 at /rustc/0468a00ae3fd6ef1a6a0f9eaf637d7aa9e604acc/library/std/src/sys/unix/thread.rs:108:17 35: 0x7f45a0697bb5 - 36: 0x7f45a0719d90 - 37: 0x0 - error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/EmbarkStudios/rust-gpu/issues/new note: rustc 1.68.0-nightly (0468a00ae 2022-12-17) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type dylib -C opt-level=3 -C embed-bitcode=no -Z unstable-options -Z codegen-backend=/mnt/projects/personal/rust/Projects/bevy-rust-gpu-project/example-workspace/rust-gpu/target/release/librustc_codegen_spirv.so -Z binary-dep-depinfo -C symbol-mangling-version=v0 -Z crate-attr=feature(register_tool) -Z crate-attr=register_tool(rust_gpu) -C llvm-args=--spirt --dump-spirt-passes=/mnt/projects/personal/rust/Projects/bevy-rust-gpu-project/example-workspace/rust-gpu/spirt-passes --spirt-passes=reduce,fuse_selects note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack note: `rust-gpu` version 0.5.0 error: could not compile `shader` ```

Shfty commented 1 year ago

This is also reproducible on v0.6.0; corresponding SPIR-T HTML output can be found here.

Shfty commented 1 year ago

And again with the SPIR-T qptr branch patched in for the sake of nicer pretty-printing.

eddyb commented 1 year ago

Can you test on 0.9.0? I think I had to include a fix for this in #1083 IIRC.