Skip to content

Commit ae00abb

Browse files
committed
Add --capability arg for specifying SPIR-V capabilities
1 parent c8d6f40 commit ae00abb

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/main.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
error::Error,
33
path::{Path, PathBuf},
4+
str::FromStr,
45
};
56

67
use clap::{error::ErrorKind, Parser};
@@ -14,7 +15,7 @@ use futures::{
1415
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher};
1516

1617
use spirv_builder::{
17-
CompileResult, MetadataPrintout, SpirvBuilder, SpirvBuilderError, SpirvMetadata,
18+
Capability, CompileResult, MetadataPrintout, SpirvBuilder, SpirvBuilderError, SpirvMetadata,
1819
};
1920

2021
use tracing::{error, info};
@@ -87,6 +88,13 @@ fn spirv_metadata(s: &str) -> Result<SpirvMetadata, clap::Error> {
8788
}
8889
}
8990

91+
fn spirv_capability(s: &str) -> Result<Capability, clap::Error> {
92+
match Capability::from_str(s) {
93+
Ok(capability) => Ok(capability),
94+
Err(_) => Err(clap::Error::new(ErrorKind::InvalidValue)),
95+
}
96+
}
97+
9098
/// Clap application struct.
9199
#[derive(Debug, Clone, Parser)]
92100
#[command(author, version, about, long_about = None)]
@@ -102,6 +110,9 @@ struct ShaderBuilder {
102110
/// Compile shaders in release mode.
103111
#[arg(long, default_value = "true")]
104112
release: bool,
113+
/// Enables the provided SPIR-V capability.
114+
#[arg(long, value_parser=spirv_capability)]
115+
capability: Vec<Capability>,
105116
/// Compile one .spv file per entry point.
106117
#[arg(long, default_value = "false")]
107118
multimodule: bool,
@@ -146,7 +157,7 @@ struct ShaderBuilder {
146157
impl ShaderBuilder {
147158
/// Builds a shader with the provided set of options.
148159
pub fn build_shader(&self) -> Result<CompileResult, SpirvBuilderError> {
149-
SpirvBuilder::new(&self.path_to_crate, &self.target)
160+
let mut builder = SpirvBuilder::new(&self.path_to_crate, &self.target)
150161
.deny_warnings(self.deny_warnings)
151162
.release(self.release)
152163
.multimodule(self.multimodule)
@@ -158,8 +169,13 @@ impl ShaderBuilder {
158169
.scalar_block_layout(self.scalar_block_layout)
159170
.skip_block_layout(self.skip_block_layout)
160171
.preserve_bindings(self.preserve_bindings)
161-
.print_metadata(MetadataPrintout::None)
162-
.build()
172+
.print_metadata(MetadataPrintout::None);
173+
174+
for capability in &self.capability {
175+
builder = builder.capability(*capability);
176+
}
177+
178+
builder.build()
163179
}
164180
}
165181

0 commit comments

Comments
 (0)