From 4f67353ac2c0f87b871b60b4550c19afe0c7ddd0 Mon Sep 17 00:00:00 2001 From: khyperia Date: Wed, 18 Aug 2021 09:23:07 +0200 Subject: [PATCH 1/2] Various fixes and cleanup While working on other patches that ended up not being applicable, I've gathered these changes unrelated to the irrelevant patch. So, submitting them as a seperate change, since the bigger change isn't going in. --- crates/rustc_codegen_spirv/src/lib.rs | 23 ++++++++----- crates/rustc_codegen_spirv/src/linker/dce.rs | 35 +++++++++++--------- tests/ui/image/gather.rs | 1 + 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index ce23c88b36..e545f69e8b 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -621,15 +621,20 @@ fn get_env_dump_dir(env_var: &str) -> Option { /// This is the entrypoint for a hot plugged `rustc_codegen_spirv` #[no_mangle] pub fn __rustc_codegen_backend() -> Box { - // Override rustc's panic hook with our own to override the ICE error - // message, and direct people to `rust-gpu`. - std::panic::set_hook(Box::new(|panic_info| { - rustc_driver::report_ice( - panic_info, - "https://github.com/EmbarkStudios/rust-gpu/issues/new", - ); - eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION")); - })); + // Setting the hook nukes the backtrace, so give developers an escape hatch to see the crash, + // even if the message is wrong. + // TODO: Figure out a way to print both the backtrace and override the bug report URL. + if env::var_os("NO_PANIC_HOOK").is_none() { + // Override rustc's panic hook with our own to override the ICE error + // message, and direct people to `rust-gpu`. + std::panic::set_hook(Box::new(|panic_info| { + rustc_driver::report_ice( + panic_info, + "https://github.com/EmbarkStudios/rust-gpu/issues/new", + ); + eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION")); + })); + } Box::new(SpirvCodegenBackend) } diff --git a/crates/rustc_codegen_spirv/src/linker/dce.rs b/crates/rustc_codegen_spirv/src/linker/dce.rs index 04d7269955..f5289f97b2 100644 --- a/crates/rustc_codegen_spirv/src/linker/dce.rs +++ b/crates/rustc_codegen_spirv/src/linker/dce.rs @@ -25,6 +25,20 @@ pub fn collect_roots(module: &Module) -> FxHashSet { rooted } +// Exactly the same as Function::all_inst_iter, except return type is `impl DoubleEndedIterator` +// instead of `impl Iterator` +fn all_inst_iter(func: &Function) -> impl DoubleEndedIterator { + func.def + .iter() + .chain(func.parameters.iter()) + .chain( + func.blocks + .iter() + .flat_map(|b| b.label.iter().chain(b.instructions.iter())), + ) + .chain(func.end.iter()) +} + fn spread_roots(module: &Module, rooted: &mut FxHashSet) -> bool { let mut any = false; for inst in module.global_inst_iter() { @@ -40,18 +54,7 @@ fn spread_roots(module: &Module, rooted: &mut FxHashSet) -> bool { // earlier insts, by reversing the iteration order, we're more likely to root the // entire relevant function at once. // See https://github.com/EmbarkStudios/rust-gpu/pull/691#discussion_r681477091 - for inst in func - .end - .iter() - .chain( - func.blocks - .iter() - .rev() - .flat_map(|b| b.instructions.iter().rev().chain(b.label.iter())), - ) - .chain(func.parameters.iter().rev()) - .chain(func.def.iter()) - { + for inst in all_inst_iter(func).rev() { if !instruction_is_pure(inst) { any |= root(inst, rooted); } else if let Some(id) = inst.result_id { @@ -111,13 +114,13 @@ fn kill_unrooted(module: &mut Module, rooted: &FxHashSet) { module .functions .retain(|f| is_rooted(f.def.as_ref().unwrap(), rooted)); - module.functions.iter_mut().for_each(|fun| { - fun.blocks.iter_mut().for_each(|block| { + for fun in &mut module.functions { + for block in &mut fun.blocks { block .instructions .retain(|inst| !instruction_is_pure(inst) || is_rooted(inst, rooted)); - }); - }); + } + } } pub fn dce_phi(func: &mut Function) { diff --git a/tests/ui/image/gather.rs b/tests/ui/image/gather.rs index 02a82446b8..0fd8df11b9 100644 --- a/tests/ui/image/gather.rs +++ b/tests/ui/image/gather.rs @@ -20,6 +20,7 @@ pub fn main( #[cfg(not(any( target_env = "vulkan1.0", target_env = "vulkan1.1", + target_env = "vulkan1.1spv1.4", target_env = "vulkan1.2" )))] #[spirv(fragment)] From 627156ba607b7dc0868a0a50a6ebcea82e4b0567 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khyperia@users.noreply.github.com> Date: Fri, 20 Aug 2021 10:41:20 +0200 Subject: [PATCH 2/2] Revert change superseded by #732 --- crates/rustc_codegen_spirv/src/lib.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/lib.rs b/crates/rustc_codegen_spirv/src/lib.rs index e545f69e8b..ce23c88b36 100644 --- a/crates/rustc_codegen_spirv/src/lib.rs +++ b/crates/rustc_codegen_spirv/src/lib.rs @@ -621,20 +621,15 @@ fn get_env_dump_dir(env_var: &str) -> Option { /// This is the entrypoint for a hot plugged `rustc_codegen_spirv` #[no_mangle] pub fn __rustc_codegen_backend() -> Box { - // Setting the hook nukes the backtrace, so give developers an escape hatch to see the crash, - // even if the message is wrong. - // TODO: Figure out a way to print both the backtrace and override the bug report URL. - if env::var_os("NO_PANIC_HOOK").is_none() { - // Override rustc's panic hook with our own to override the ICE error - // message, and direct people to `rust-gpu`. - std::panic::set_hook(Box::new(|panic_info| { - rustc_driver::report_ice( - panic_info, - "https://github.com/EmbarkStudios/rust-gpu/issues/new", - ); - eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION")); - })); - } + // Override rustc's panic hook with our own to override the ICE error + // message, and direct people to `rust-gpu`. + std::panic::set_hook(Box::new(|panic_info| { + rustc_driver::report_ice( + panic_info, + "https://github.com/EmbarkStudios/rust-gpu/issues/new", + ); + eprintln!("note: `rust-gpu` version {}\n", env!("CARGO_PKG_VERSION")); + })); Box::new(SpirvCodegenBackend) }