Skip to content

Commit 8396e6f

Browse files
committed
Documentation pass
1 parent 30acf45 commit 8396e6f

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

src/main.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use spirv_builder::{
1919

2020
use tracing::{error, info};
2121

22+
/// Instantiate an async watcher and return it alongside a channel to receive events on.
2223
fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Result<Event>>)> {
2324
let (mut tx, rx) = channel(1);
2425

@@ -36,9 +37,10 @@ fn async_watcher() -> notify::Result<(RecommendedWatcher, Receiver<notify::Resul
3637
Ok((watcher, rx))
3738
}
3839

40+
/// Watch a file or directory, sending relevant events through the provided channel.
3941
async fn async_watch<P: AsRef<Path>>(
4042
path: P,
41-
mut change_tx: UnboundedSender<()>,
43+
mut event_tx: UnboundedSender<()>,
4244
) -> Result<(), Box<dyn Error>> {
4345
let path = path.as_ref();
4446
let path = std::fs::canonicalize(path)
@@ -53,12 +55,18 @@ async fn async_watch<P: AsRef<Path>>(
5355
while let Some(res) = rx.next().await {
5456
match res {
5557
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();
6270
}
6371
}
6472
Err(e) => error!("Watch error: {:?}", e),
@@ -68,6 +76,7 @@ async fn async_watch<P: AsRef<Path>>(
6876
Ok(())
6977
}
7078

79+
/// Clap value parser for [`SpirvMetadata`].
7180
fn spirv_metadata(s: &str) -> Result<SpirvMetadata, clap::Error> {
7281
match s {
7382
"none" => Ok(SpirvMetadata::None),
@@ -77,34 +86,53 @@ fn spirv_metadata(s: &str) -> Result<SpirvMetadata, clap::Error> {
7786
}
7887
}
7988

89+
/// Clap application struct.
8090
#[derive(Debug, Clone, Parser)]
8191
#[command(author, version, about, long_about = None)]
8292
struct ShaderBuilder {
83-
/// Shader crate to compile
93+
/// Shader crate to compile.
8494
path_to_crate: PathBuf,
85-
/// rust-gpu compile target
95+
/// rust-gpu compile target.
8696
#[arg(short, long, default_value = "spirv-unknown-spv1.5")]
8797
target: String,
98+
/// Treat warnings as errors during compilation.
8899
#[arg(long, default_value = "false")]
89100
deny_warnings: bool,
101+
/// Compile shaders in release mode.
90102
#[arg(long, default_value = "true")]
91103
release: bool,
104+
/// Compile one .spv file per entry point.
92105
#[arg(long, default_value = "false")]
93106
multimodule: bool,
107+
/// Set the level of metadata included in the SPIR-V binary.
94108
#[arg(long, value_parser=spirv_metadata, default_value = "none")]
95109
spirv_metadata: SpirvMetadata,
110+
/// Allow store from one struct type to a different type with compatible layout and members.
96111
#[arg(long, default_value = "false")]
97112
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.
98115
#[arg(long, default_value = "false")]
99116
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.
100120
#[arg(long, default_value = "false")]
101121
relax_block_layout: bool,
122+
/// Enable VK_KHR_uniform_buffer_standard_layout when checking standard uniform buffer layouts.
102123
#[arg(long, default_value = "false")]
103124
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.
104129
#[arg(long, default_value = "false")]
105130
scalar_block_layout: bool,
131+
/// Skip checking standard uniform / storage buffer layout. Overrides any --relax-block-layout
132+
/// or --scalar-block-layout option.
106133
#[arg(long, default_value = "false")]
107134
skip_block_layout: bool,
135+
/// Preserve unused descriptor bindings. Useful for reflection.
108136
#[arg(long, default_value = "false")]
109137
preserve_bindings: bool,
110138
/// If set, will watch the provided directory and recompile on change.
@@ -115,6 +143,7 @@ struct ShaderBuilder {
115143
}
116144

117145
impl ShaderBuilder {
146+
/// Builds a shader with the provided set of options.
118147
pub fn build_shader(&self) -> Result<CompileResult, SpirvBuilderError> {
119148
SpirvBuilder::new(&self.path_to_crate, &self.target)
120149
.deny_warnings(self.deny_warnings)

0 commit comments

Comments
 (0)