Skip to content

Commit 97b56dd

Browse files
committed
TARGET_SPECS has them all at comp time
1 parent 5570a22 commit 97b56dd

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed

crates/cargo-gpu/src/show.rs

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

75
/// Show the computed source of the spirv-std dependency.
@@ -69,8 +67,9 @@ impl Show {
6967
}
7068
}
7169
Info::Targets => {
72-
let target_info = get_spirv_targets()?.join("\n");
73-
println!("{}", target_info);
70+
for target in Self::available_spirv_targets_iter() {
71+
println!("{target}");
72+
}
7473
}
7574
}
7675

@@ -85,43 +84,12 @@ impl Show {
8584
let last_capability = spirv_builder::Capability::CacheControlsINTEL as u32;
8685
(0..=last_capability).filter_map(spirv_builder::Capability::from_u32)
8786
}
88-
}
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-
];
10887

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?
88+
/// All supported spirv targets at the time cargo-gpu was compiled.
89+
fn available_spirv_targets_iter() -> impl Iterator<Item = String> {
90+
legacy_target_specs::TARGET_SPECS
91+
.iter()
92+
.filter(|(spec, _src)| spec.contains("vulkan"))
93+
.map(|(spec, _src)| spec.replace(".json", ""))
12494
}
125-
126-
Ok(targets.into_iter().map(String::from).collect())
12795
}

0 commit comments

Comments
 (0)