@@ -19,6 +19,7 @@ use spirv_builder::{
19
19
20
20
use tracing:: { error, info} ;
21
21
22
+ /// Instantiate an async watcher and return it alongside a channel to receive events on.
22
23
fn async_watcher ( ) -> notify:: Result < ( RecommendedWatcher , Receiver < notify:: Result < Event > > ) > {
23
24
let ( mut tx, rx) = channel ( 1 ) ;
24
25
@@ -36,9 +37,10 @@ fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Resul
36
37
Ok ( ( watcher, rx) )
37
38
}
38
39
40
+ /// Watch a file or directory, sending relevant events through the provided channel.
39
41
async fn async_watch < P : AsRef < Path > > (
40
42
path : P ,
41
- mut change_tx : UnboundedSender < ( ) > ,
43
+ mut event_tx : UnboundedSender < ( ) > ,
42
44
) -> Result < ( ) , Box < dyn Error > > {
43
45
let path = path. as_ref ( ) ;
44
46
let path = std:: fs:: canonicalize ( path)
@@ -53,12 +55,18 @@ async fn async_watch<P: AsRef<Path>>(
53
55
while let Some ( res) = rx. next ( ) . await {
54
56
match res {
55
57
Ok ( event) => {
56
- if path. is_dir ( ) || event. paths . iter ( ) . find ( |candidate| {
57
- std:: fs:: canonicalize ( candidate)
58
- . unwrap_or_else ( |e| panic ! ( "Failed to canonicalize path {path:?}: {e:}" ) )
59
- == path
60
- } ) . is_some ( ) {
61
- change_tx. send ( ( ) ) . await . unwrap ( ) ;
58
+ if path. is_dir ( )
59
+ || event
60
+ . paths
61
+ . iter ( )
62
+ . find ( |candidate| {
63
+ std:: fs:: canonicalize ( candidate) . unwrap_or_else ( |e| {
64
+ panic ! ( "Failed to canonicalize path {path:?}: {e:}" )
65
+ } ) == path
66
+ } )
67
+ . is_some ( )
68
+ {
69
+ event_tx. send ( ( ) ) . await . unwrap ( ) ;
62
70
}
63
71
}
64
72
Err ( e) => error ! ( "Watch error: {:?}" , e) ,
@@ -68,6 +76,7 @@ async fn async_watch<P: AsRef<Path>>(
68
76
Ok ( ( ) )
69
77
}
70
78
79
+ /// Clap value parser for [`SpirvMetadata`].
71
80
fn spirv_metadata ( s : & str ) -> Result < SpirvMetadata , clap:: Error > {
72
81
match s {
73
82
"none" => Ok ( SpirvMetadata :: None ) ,
@@ -77,34 +86,53 @@ fn spirv_metadata(s: &str) -> Result<SpirvMetadata, clap::Error> {
77
86
}
78
87
}
79
88
89
+ /// Clap application struct.
80
90
#[ derive( Debug , Clone , Parser ) ]
81
91
#[ command( author, version, about, long_about = None ) ]
82
92
struct ShaderBuilder {
83
- /// Shader crate to compile
93
+ /// Shader crate to compile.
84
94
path_to_crate : PathBuf ,
85
- /// rust-gpu compile target
95
+ /// rust-gpu compile target.
86
96
#[ arg( short, long, default_value = "spirv-unknown-spv1.5" ) ]
87
97
target : String ,
98
+ /// Treat warnings as errors during compilation.
88
99
#[ arg( long, default_value = "false" ) ]
89
100
deny_warnings : bool ,
101
+ /// Compile shaders in release mode.
90
102
#[ arg( long, default_value = "true" ) ]
91
103
release : bool ,
104
+ /// Compile one .spv file per entry point.
92
105
#[ arg( long, default_value = "false" ) ]
93
106
multimodule : bool ,
107
+ /// Set the level of metadata included in the SPIR-V binary.
94
108
#[ arg( long, value_parser=spirv_metadata, default_value = "none" ) ]
95
109
spirv_metadata : SpirvMetadata ,
110
+ /// Allow store from one struct type to a different type with compatible layout and members.
96
111
#[ arg( long, default_value = "false" ) ]
97
112
relax_struct_store : bool ,
113
+ /// Allow allocating an object of a pointer type and returning a pointer value from a function
114
+ /// in logical addressing mode.
98
115
#[ arg( long, default_value = "false" ) ]
99
116
relax_logical_pointer : bool ,
117
+ /// Enable VK_KHR_relaxed_block_layout when checking standard uniform,
118
+ /// storage buffer, and push constant layouts.
119
+ /// This is the default when targeting Vulkan 1.1 or later.
100
120
#[ arg( long, default_value = "false" ) ]
101
121
relax_block_layout : bool ,
122
+ /// Enable VK_KHR_uniform_buffer_standard_layout when checking standard uniform buffer layouts.
102
123
#[ arg( long, default_value = "false" ) ]
103
124
uniform_buffer_standard_layout : bool ,
125
+ /// Enable VK_EXT_scalar_block_layout when checking standard uniform, storage buffer, and push
126
+ /// constant layouts.
127
+ /// Scalar layout rules are more permissive than relaxed block layout so in effect this will
128
+ /// override the --relax-block-layout option.
104
129
#[ arg( long, default_value = "false" ) ]
105
130
scalar_block_layout : bool ,
131
+ /// Skip checking standard uniform / storage buffer layout. Overrides any --relax-block-layout
132
+ /// or --scalar-block-layout option.
106
133
#[ arg( long, default_value = "false" ) ]
107
134
skip_block_layout : bool ,
135
+ /// Preserve unused descriptor bindings. Useful for reflection.
108
136
#[ arg( long, default_value = "false" ) ]
109
137
preserve_bindings : bool ,
110
138
/// If set, will watch the provided directory and recompile on change.
@@ -115,6 +143,7 @@ struct ShaderBuilder {
115
143
}
116
144
117
145
impl ShaderBuilder {
146
+ /// Builds a shader with the provided set of options.
118
147
pub fn build_shader ( & self ) -> Result < CompileResult , SpirvBuilderError > {
119
148
SpirvBuilder :: new ( & self . path_to_crate , & self . target )
120
149
. deny_warnings ( self . deny_warnings )
0 commit comments