Use a demangled symbol name for OpName. (#266)

* Use a demangled symbol name for OpName.

* Rename my_smoothstep back to smoothstep.

* Update SPIR-V tests to look for the absolute fn
path.
This commit is contained in:
Eduard-Mihai Burtescu 2020-11-20 15:54:26 +02:00 committed by GitHub
parent 3eebcd789f
commit 0581f8580e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 9 deletions

7
Cargo.lock generated
View File

@ -1963,6 +1963,12 @@ dependencies = [
"spirv_headers 1.5.0 (git+https://github.com/gfx-rs/rspirv.git?rev=01ca0d2e5b667a0e4ff1bc1804511e38f9a08759)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
name = "rustc_codegen_spirv"
version = "0.1.0"
@ -1971,6 +1977,7 @@ dependencies = [
"pipe",
"pretty_assertions",
"rspirv",
"rustc-demangle",
"spirv-tools",
"tar",
"tempfile",

View File

@ -29,6 +29,7 @@ use-compiled-tools = ["spirv-tools/use-compiled-tools"]
[dependencies]
bimap = "0.5"
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "01ca0d2e5b667a0e4ff1bc1804511e38f9a08759" }
rustc-demangle = "0.1.18"
spirv-tools = { version = "0.1.0", default-features = false }
tar = "0.4.30"
topological-sort = "0.1"

View File

@ -91,11 +91,20 @@ impl<'tcx> CodegenCx<'tcx> {
}
emit.end_function().unwrap();
let human_name = format!("{}", instance);
emit.name(fn_id, &human_name);
// HACK(eddyb) this is a bit roundabout, but the easiest way to get a
// fully absolute path that contains at least as much information as
// `instance.to_string()` (at least with `-Z symbol-mangling-version=v0`).
// While we could use the mangled symbol insyead, like we do for linkage,
// `OpName` is more of a debugging aid, so not having to separately
// demangle the SPIR-V can help. However, if some tools assume `OpName`
// is always a valid identifier, we may have to offer the mangled name
// (as some sort of opt-in, or toggled based on the platform, etc.).
let symbol_name = self.tcx.symbol_name(instance).name;
let demangled_symbol_name = format!("{:#}", rustc_demangle::demangle(symbol_name));
emit.name(fn_id, &demangled_symbol_name);
drop(emit); // set_linkage uses emit
if let Some(linkage) = linkage {
let symbol_name = self.tcx.symbol_name(instance).name;
self.set_linkage(fn_id, symbol_name.to_owned(), linkage);
}
@ -104,7 +113,8 @@ impl<'tcx> CodegenCx<'tcx> {
for attr in parse_attrs(self, self.tcx.get_attrs(instance.def_id())) {
match attr {
SpirvAttribute::Entry(entry) => {
self.entry_stub(&instance, &fn_abi, declared, human_name.clone(), entry)
let crate_relative_name = instance.to_string();
self.entry_stub(&instance, &fn_abi, declared, crate_relative_name, entry)
}
SpirvAttribute::ReallyUnsafeIgnoreBitcasts => {
self.really_unsafe_ignore_bitcasts

View File

@ -143,7 +143,7 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
format!(" -C target-feature={}", target_features.join(","))
};
let rustflags = format!(
"-Z codegen-backend={}{}",
"-Z codegen-backend={} -Z symbol-mangling-version=v0{}",
rustc_codegen_spirv.display(),
feature_flag,
);

View File

@ -113,12 +113,13 @@ fn assert_str_eq(expected: &str, result: &str) {
fn dis_fn(src: &str, func: &str, expect: &str) {
let _lock = global_lock();
let module = read_module(&build(src)).unwrap();
let abs_func_path = format!("test_project::{}", func);
let id = module
.debugs
.iter()
.find(|inst| {
inst.class.opcode == rspirv::spirv::Op::Name
&& inst.operands[1].unwrap_literal_string() == func
&& inst.operands[1].unwrap_literal_string() == abs_func_path
})
.expect("No function with that name found")
.operands[0]

View File

@ -39,8 +39,7 @@ pub fn acos_approx(v: f32) -> f32 {
}
}
/// renamed because of cross-compilation issues with spirv-cross/ moltenvk
pub fn my_smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
pub fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
// Scale, bias and saturate x to 0..1 range
let x = ((x - edge0) / (edge1 - edge0)).saturate();
// Evaluate polynomial

View File

@ -97,7 +97,7 @@ fn sky(dir: Vec3, sun_position: Vec3) -> Vec3 {
// Composition + solar disc
let sun_angular_diameter_cos = SUN_ANGULAR_DIAMETER_DEGREES.cos();
let sundisk = my_smoothstep(
let sundisk = smoothstep(
sun_angular_diameter_cos,
sun_angular_diameter_cos + 0.00002,
cos_theta,