You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1086 Old labels: t: bug Originally creatd by schell on 2023-07-28T01:00:19Z
While debugging an issue with nested loops I simplified my shader to one loop as a sanity check and then hit this compiler panic. It seems to be caused by looping indefinitely (in my shader I forgot to increment a value used in the break condition).
Expected Behaviour
Compiler should error instead of panic.
Actual Behavior
Compiler panics with:
thread 'rustc' panicked at 'assertion failed: list_eq_key(children) ==\n list_eq_key(self.func_def_body.at(unstructured_region).def().children)',
/Users/schell/.cargo/registry/src/index.crates.io-6f17d22bba15001f/spirt-0.2.0/src/cfg.rs:1214:13
Example & Steps To Reproduce
Compile this shader:
use glam::{Vec3,Vec4,Vec4Swizzles,Vec3Swizzles};use spirv_std::{image::Cubemap,Sampler, spirv};#[cfg(target_arch = "spirv")]use spirv_std::num_traits::Float;#[spirv(fragment)]pubfnfragment_convolve_diffuse_irradiance(environment_texture:&Cubemap,sampler:&Sampler,local_pos:Vec3,frag_color:&mutVec4,){let pi:f32 = 3.1415927;let normal = local_pos.normalize_or_zero();letmut irradiance = Vec3::new(0.0,0.0,0.0);let right = Vec3::new(0.0,1.0,0.0).cross(normal).normalize_or_zero();let up = normal.cross(right).normalize_or_zero();let nr_samples = 0.0;
irradiance += environment_texture.sample(*sampler, up).xyz();loop{if nr_samples > 2.0{break;}
irradiance += environment_texture.sample(*sampler, up).xyz();}let color = irradiance *(pi / nr_samples);*frag_color = color.xyz().extend(1.0);}
System Info
note: rustc 1.70.0-nightly (84dd17b56 2023-04-14) running on aarch64-apple-darwin
Comment from eddyb (CONTRIBUTOR) on 2023-07-28T04:31:27Z
I've edited the description and title to explicitly mention the message.
This is a "known" panic I have yet to investigate because so far I've only hit it with RUSTGPU_CODEGEN_ARGS=--no-early-report-zombies, which can let some malformed SPIR-V rustc_codegen_spirv generates through, so I just assumed that was the cause here.
If it can happen without RUSTGPU_CODEGEN_ARGS, then this deserves a lot more scrutiny. I'll attempt to minimize the testcase provided (is it complete though? there's no #[spirv(...)], so that's just dead code?EDIT: was just a missing #[spirv(fragment)], added that to the issue description, can confirm it repros).
Comment from eddyb (CONTRIBUTOR) on 2023-07-28T05:28:55Z
This reduces somewhat bizarrely:
use spirv_std::spirv;#[inline(never)]fnbug(cond:bool){if(if cond {true}else{false}){}loop{}}#[spirv(fragment)]pubfnmain(){bug(false);}
I'll have to move --dump-spirt-passes into a helper type that implements Drop so panics don't stop it from showing useful information (in general it seems sensible to do that sort of thing, just because removing 100% of possible panics is hard, esp. before we have a SPIR-T validator).
// Structured return, the function is fully structurized.//// FIXME(eddyb) also support structured return when the whole body// is divergent, by generating undef constants (needs access to the// whole `FuncDecl`, not just `FuncDefBody`, to get the right types).
I forgot about this since, because it apparently never(?) caused any issues in practice, but e.g. "always reach an infinite loop" Rust-GPU shaders wouldn't end up 100% structured - my best guess for why spirv-val doesn't complain is that the actual body is structured, there's just a single unstructured branch at the very start, which SPIR-V doesn't care about ("structured SPIR-V" only puts requirements on merging selects/loops).
Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1086
Old labels: t: bug
Originally creatd by schell on 2023-07-28T01:00:19Z
While debugging an issue with nested loops I simplified my shader to one loop as a sanity check and then hit this compiler panic. It seems to be caused by looping indefinitely (in my shader I forgot to increment a value used in the break condition).
Expected Behaviour
Compiler should error instead of panic.
Actual Behavior
Compiler panics with:
Example & Steps To Reproduce
Compile this shader:
System Info
note: rustc 1.70.0-nightly (84dd17b56 2023-04-14) running on aarch64-apple-darwin
note: compiler flags: --crate-type dylib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -Z unstable-options -Z codegen-backend=/Users/schell/code/renderling/shaders/target/release/librustc_codegen_spirv.dylib -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=--module-output=multiple
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
note:
rust-gpu
version 0.8.0Backtrace
Backtrace
The text was updated successfully, but these errors were encountered: