1
1
//! Display various information about `cargo gpu`, eg its cache directory.
2
2
3
+ use std:: process:: { Command , Stdio } ;
4
+
3
5
use crate :: cache_dir;
4
6
5
7
/// Show the computed source of the spirv-std dependency.
@@ -21,6 +23,9 @@ pub enum Info {
21
23
Commitsh ,
22
24
/// All the available SPIR-V capabilities that can be set with `--capabilities`
23
25
Capabilities ,
26
+
27
+ /// All available SPIR-V targets
28
+ Targets ,
24
29
}
25
30
26
31
/// `cargo gpu show`
@@ -63,6 +68,10 @@ impl Show {
63
68
println ! ( " {capability:?}" ) ;
64
69
}
65
70
}
71
+ Info :: Targets => {
72
+ let target_info = get_spirv_targets ( ) ?. join ( "\n " ) ;
73
+ println ! ( "{}" , target_info) ;
74
+ }
66
75
}
67
76
68
77
Ok ( ( ) )
@@ -77,3 +86,42 @@ impl Show {
77
86
( 0 ..=last_capability) . filter_map ( spirv_builder:: Capability :: from_u32)
78
87
}
79
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
+ ] ;
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