Skip to content

Commit a48588b

Browse files
committed
Update spirt for better OpExtInst support (EmbarkStudios/spirt#45).
1 parent 4c7c97f commit a48588b

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646
(see its documentation for more details about each available panic handling strategy)
4747

4848
### Changed 🛠
49+
- [PR#1083](https://github.com/EmbarkStudios/rust-gpu/pull/1083) updated SPIR-T to get pretty-printer
50+
improvements (especially for `OpExtInst`, including Rust-GPU's custom ones), and started more
51+
aggressively deduplicating custom debuginfo instructions (to make SPIR-T dumps more readable)
4952
- [PR#1079](https://github.com/EmbarkStudios/rust-gpu/pull/1079) revised `spirv-builder`'s `README.md`,
5053
and added a way for `docs.rs` to be able to build it (via `cargo +stable doc --no-default-features`)
5154
- [PR#1070](https://github.com/EmbarkStudios/rust-gpu/pull/1070) made panics (via the `abort` intrinsic)

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustc_codegen_spirv/src/custom_insts.rs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ use smallvec::SmallVec;
1515
/// See `CUSTOM_EXT_INST_SET`'s docs for further constraints on the full name.
1616
pub const CUSTOM_EXT_INST_SET_PREFIX: &str = concat!("Rust.", env!("CARGO_PKG_NAME"), ".");
1717

18+
macro_rules! join_cargo_pkg_version_major_minor_patch {
19+
($sep:literal) => {
20+
concat!(
21+
env!("CARGO_PKG_VERSION_MAJOR"),
22+
$sep,
23+
env!("CARGO_PKG_VERSION_MINOR"),
24+
$sep,
25+
env!("CARGO_PKG_VERSION_PATCH"),
26+
)
27+
};
28+
}
29+
1830
lazy_static! {
1931
/// `OpExtInstImport` "instruction set" name for all Rust-GPU instructions.
2032
///
@@ -30,10 +42,6 @@ lazy_static! {
3042
/// if the definitions of the custom instructions have changed - this is
3143
/// achieved by hashing the `SCHEMA` constant from `def_custom_insts!` below
3244
pub static ref CUSTOM_EXT_INST_SET: String = {
33-
const VER_MAJOR: &str = env!("CARGO_PKG_VERSION_MAJOR");
34-
const VER_MINOR: &str = env!("CARGO_PKG_VERSION_MINOR");
35-
const VER_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
36-
3745
let schema_hash = {
3846
use rustc_data_structures::stable_hasher::StableHasher;
3947
use std::hash::Hash;
@@ -43,11 +51,47 @@ lazy_static! {
4351
let (lo, hi) = hasher.finalize();
4452
(lo as u128) | ((hi as u128) << 64)
4553
};
46-
47-
format!("{CUSTOM_EXT_INST_SET_PREFIX}{VER_MAJOR}_{VER_MINOR}_{VER_PATCH}.{schema_hash:x}")
54+
let version = join_cargo_pkg_version_major_minor_patch!("_");
55+
format!("{CUSTOM_EXT_INST_SET_PREFIX}{version}.{schema_hash:x}")
4856
};
4957
}
5058

59+
pub fn register_to_spirt_context(cx: &spirt::Context) {
60+
use spirt::spv::spec::{ExtInstSetDesc, ExtInstSetInstructionDesc};
61+
cx.register_custom_ext_inst_set(
62+
&CUSTOM_EXT_INST_SET,
63+
ExtInstSetDesc {
64+
// HACK(eddyb) this is the most compact form I've found, that isn't
65+
// outright lossy by omitting "Rust vs Rust-GPU" or the version.
66+
short_alias: Some(
67+
concat!("Rust-GPU ", join_cargo_pkg_version_major_minor_patch!(".")).into(),
68+
),
69+
instructions: SCHEMA
70+
.iter()
71+
.map(|&(i, name, operand_names)| {
72+
(
73+
i,
74+
ExtInstSetInstructionDesc {
75+
name: name.into(),
76+
operand_names: operand_names
77+
.iter()
78+
.map(|name| {
79+
name.strip_prefix("..")
80+
.unwrap_or(name)
81+
.replace('_', " ")
82+
.into()
83+
})
84+
.collect(),
85+
is_debuginfo: name.contains("Debug")
86+
|| name.contains("InlinedCallFrame"),
87+
},
88+
)
89+
})
90+
.collect(),
91+
},
92+
);
93+
}
94+
5195
macro_rules! def_custom_insts {
5296
($($num:literal => $name:ident $({ $($field:ident),+ $(, ..$variadic_field:ident)? $(,)? })?),+ $(,)?) => {
5397
const SCHEMA: &[(u32, &str, &[&str])] = &[

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ pub fn link(
409409
spirv_tools::binary::from_binary(&spv_words).to_vec()
410410
};
411411
let cx = std::rc::Rc::new(spirt::Context::new());
412+
crate::custom_insts::register_to_spirt_context(&cx);
412413
let mut module = {
413414
let _timer = sess.timer("spirt::Module::lower_from_spv_file");
414415
match spirt::Module::lower_from_spv_bytes(cx.clone(), spv_bytes) {

0 commit comments

Comments
 (0)