Skip to content

Commit 848a198

Browse files
committed
show-targets
comments
1 parent 2180d73 commit 848a198

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

crates/cargo-gpu/src/show.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Display various information about `cargo gpu`, eg its cache directory.
22
3+
use std::process::{Command, Stdio};
4+
35
use crate::cache_dir;
46

57
/// Show the computed source of the spirv-std dependency.
@@ -21,6 +23,9 @@ pub enum Info {
2123
Commitsh,
2224
/// All the available SPIR-V capabilities that can be set with `--capabilities`
2325
Capabilities,
26+
27+
/// All available SPIR-V targets
28+
Targets,
2429
}
2530

2631
/// `cargo gpu show`
@@ -63,6 +68,10 @@ impl Show {
6368
println!(" {capability:?}");
6469
}
6570
}
71+
Info::Targets => {
72+
let target_info = get_spirv_targets()?.join("\n");
73+
println!("{}", target_info);
74+
}
6675
}
6776

6877
Ok(())
@@ -77,3 +86,42 @@ impl Show {
7786
(0..=last_capability).filter_map(spirv_builder::Capability::from_u32)
7887
}
7988
}
89+
90+
/// Gets available SPIR-V targets by calling the `spirv-tools`' validator:
91+
/// ```sh
92+
/// $ spirv-val --version
93+
/// SPIRV-Tools v2022.2-dev unknown hash, 2022-02-16T16:37:15
94+
/// Targets:
95+
/// SPIR-V 1.0
96+
/// SPIR-V 1.1
97+
/// SPIR-V 1.2
98+
/// ... snip for brevity
99+
/// SPIR-V 1.6 (under Vulkan 1.3 semantics)
100+
/// ```
101+
fn get_spirv_targets() -> anyhow::Result<Vec<String>> {
102+
// Defaults that have been tested, 1.2 is the existing default in the shader-crate-template.toml
103+
let mut targets = vec![
104+
"spirv-unknown-vulkan1.0",
105+
"spirv-unknown-vulkan1.1",
106+
"spirv-unknown-vulkan1.2",
107+
];
108+
109+
let output = Command::new("spirv-val")
110+
.arg("--version")
111+
.stdout(Stdio::piped())
112+
.stderr(Stdio::piped())
113+
.output();
114+
115+
if let Ok(output) = output {
116+
let version_info = String::from_utf8_lossy(&output.stdout);
117+
if version_info.contains("SPIR-V 1.3") {
118+
targets.push("spirv-unknown-vulkan1.3");
119+
}
120+
if version_info.contains("SPIR-V 1.4") {
121+
targets.push("spirv-unknown-vulkan1.4");
122+
}
123+
// Exhaustively, manually put in all possible versions? or regex them out?
124+
}
125+
126+
Ok(targets.into_iter().map(String::from).collect())
127+
}

0 commit comments

Comments
 (0)