mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-22 06:45:13 +00:00
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:
parent
3eebcd789f
commit
0581f8580e
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -1963,6 +1963,12 @@ dependencies = [
|
|||||||
"spirv_headers 1.5.0 (git+https://github.com/gfx-rs/rspirv.git?rev=01ca0d2e5b667a0e4ff1bc1804511e38f9a08759)",
|
"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]]
|
[[package]]
|
||||||
name = "rustc_codegen_spirv"
|
name = "rustc_codegen_spirv"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -1971,6 +1977,7 @@ dependencies = [
|
|||||||
"pipe",
|
"pipe",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
"rspirv",
|
"rspirv",
|
||||||
|
"rustc-demangle",
|
||||||
"spirv-tools",
|
"spirv-tools",
|
||||||
"tar",
|
"tar",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
@ -29,6 +29,7 @@ use-compiled-tools = ["spirv-tools/use-compiled-tools"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
bimap = "0.5"
|
bimap = "0.5"
|
||||||
rspirv = { git = "https://github.com/gfx-rs/rspirv.git", rev = "01ca0d2e5b667a0e4ff1bc1804511e38f9a08759" }
|
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 }
|
spirv-tools = { version = "0.1.0", default-features = false }
|
||||||
tar = "0.4.30"
|
tar = "0.4.30"
|
||||||
topological-sort = "0.1"
|
topological-sort = "0.1"
|
||||||
|
@ -91,11 +91,20 @@ impl<'tcx> CodegenCx<'tcx> {
|
|||||||
}
|
}
|
||||||
emit.end_function().unwrap();
|
emit.end_function().unwrap();
|
||||||
|
|
||||||
let human_name = format!("{}", instance);
|
// HACK(eddyb) this is a bit roundabout, but the easiest way to get a
|
||||||
emit.name(fn_id, &human_name);
|
// 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
|
drop(emit); // set_linkage uses emit
|
||||||
if let Some(linkage) = linkage {
|
if let Some(linkage) = linkage {
|
||||||
let symbol_name = self.tcx.symbol_name(instance).name;
|
|
||||||
self.set_linkage(fn_id, symbol_name.to_owned(), linkage);
|
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())) {
|
for attr in parse_attrs(self, self.tcx.get_attrs(instance.def_id())) {
|
||||||
match attr {
|
match attr {
|
||||||
SpirvAttribute::Entry(entry) => {
|
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 => {
|
SpirvAttribute::ReallyUnsafeIgnoreBitcasts => {
|
||||||
self.really_unsafe_ignore_bitcasts
|
self.really_unsafe_ignore_bitcasts
|
||||||
|
@ -143,7 +143,7 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
|
|||||||
format!(" -C target-feature={}", target_features.join(","))
|
format!(" -C target-feature={}", target_features.join(","))
|
||||||
};
|
};
|
||||||
let rustflags = format!(
|
let rustflags = format!(
|
||||||
"-Z codegen-backend={}{}",
|
"-Z codegen-backend={} -Z symbol-mangling-version=v0{}",
|
||||||
rustc_codegen_spirv.display(),
|
rustc_codegen_spirv.display(),
|
||||||
feature_flag,
|
feature_flag,
|
||||||
);
|
);
|
||||||
|
@ -113,12 +113,13 @@ fn assert_str_eq(expected: &str, result: &str) {
|
|||||||
fn dis_fn(src: &str, func: &str, expect: &str) {
|
fn dis_fn(src: &str, func: &str, expect: &str) {
|
||||||
let _lock = global_lock();
|
let _lock = global_lock();
|
||||||
let module = read_module(&build(src)).unwrap();
|
let module = read_module(&build(src)).unwrap();
|
||||||
|
let abs_func_path = format!("test_project::{}", func);
|
||||||
let id = module
|
let id = module
|
||||||
.debugs
|
.debugs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|inst| {
|
.find(|inst| {
|
||||||
inst.class.opcode == rspirv::spirv::Op::Name
|
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")
|
.expect("No function with that name found")
|
||||||
.operands[0]
|
.operands[0]
|
||||||
|
@ -39,8 +39,7 @@ pub fn acos_approx(v: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// renamed because of cross-compilation issues with spirv-cross/ moltenvk
|
pub fn smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
|
||||||
pub fn my_smoothstep(edge0: f32, edge1: f32, x: f32) -> f32 {
|
|
||||||
// Scale, bias and saturate x to 0..1 range
|
// Scale, bias and saturate x to 0..1 range
|
||||||
let x = ((x - edge0) / (edge1 - edge0)).saturate();
|
let x = ((x - edge0) / (edge1 - edge0)).saturate();
|
||||||
// Evaluate polynomial
|
// Evaluate polynomial
|
||||||
|
@ -97,7 +97,7 @@ fn sky(dir: Vec3, sun_position: Vec3) -> Vec3 {
|
|||||||
|
|
||||||
// Composition + solar disc
|
// Composition + solar disc
|
||||||
let sun_angular_diameter_cos = SUN_ANGULAR_DIAMETER_DEGREES.cos();
|
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,
|
||||||
sun_angular_diameter_cos + 0.00002,
|
sun_angular_diameter_cos + 0.00002,
|
||||||
cos_theta,
|
cos_theta,
|
||||||
|
Loading…
Reference in New Issue
Block a user