mirror of
https://github.com/storytold/wgpu.git
synced 2026-12-01 02:24:35 +01:00
[spv-out] allow capabilities to be derived
This commit is contained in:
1 parent
f77abdb156
commit
3049e3a4ac
3 files changed
+26
-14
No files matched your search
+3
-5
@@ -57,8 +57,8 @@ pub struct Options {
|
||||
pub lang_version: (u8, u8),
|
||||
/// Configuration flags for the writer.
|
||||
pub flags: WriterFlags,
|
||||
/// Set of SPIR-V capabilities.
|
||||
pub capabilities: crate::FastHashSet<Capability>,
|
||||
/// Set of SPIR-V allowed capabilities, if provided.
|
||||
pub capabilities: Option<crate::FastHashSet<Capability>>,
|
||||
}
|
||||
|
||||
impl Default for Options {
|
||||
@@ -67,12 +67,10 @@ impl Default for Options {
|
||||
if cfg!(debug_assertions) {
|
||||
flags |= WriterFlags::DEBUG;
|
||||
}
|
||||
let mut capabilities = crate::FastHashSet::default();
|
||||
capabilities.insert(Capability::Shader);
|
||||
Options {
|
||||
lang_version: (1, 0),
|
||||
flags,
|
||||
capabilities,
|
||||
capabilities: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-8
@@ -284,6 +284,7 @@ pub struct Writer {
|
||||
logical_layout: LogicalLayout,
|
||||
id_gen: IdGenerator,
|
||||
capabilities: crate::FastHashSet<spirv::Capability>,
|
||||
strict_capabilities: bool,
|
||||
debugs: Vec<Instruction>,
|
||||
annotations: Vec<Instruction>,
|
||||
flags: WriterFlags,
|
||||
@@ -317,7 +318,15 @@ impl Writer {
|
||||
physical_layout: PhysicalLayout::new(raw_version),
|
||||
logical_layout: LogicalLayout::default(),
|
||||
id_gen,
|
||||
capabilities: options.capabilities.clone(),
|
||||
capabilities: match options.capabilities {
|
||||
Some(ref caps) => caps.clone(),
|
||||
None => {
|
||||
let mut caps = crate::FastHashSet::default();
|
||||
caps.insert(spirv::Capability::Shader);
|
||||
caps
|
||||
}
|
||||
},
|
||||
strict_capabilities: options.capabilities.is_some(),
|
||||
debugs: vec![],
|
||||
annotations: vec![],
|
||||
flags: options.flags,
|
||||
@@ -336,14 +345,19 @@ impl Writer {
|
||||
}
|
||||
|
||||
fn check(&mut self, capabilities: &[spirv::Capability]) -> Result<(), Error> {
|
||||
if capabilities.is_empty()
|
||||
|| capabilities
|
||||
.iter()
|
||||
.any(|cap| self.capabilities.contains(cap))
|
||||
{
|
||||
Ok(())
|
||||
if self.strict_capabilities {
|
||||
if capabilities.is_empty()
|
||||
|| capabilities
|
||||
.iter()
|
||||
.any(|cap| self.capabilities.contains(cap))
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::MissingCapabilities(capabilities.to_vec()))
|
||||
}
|
||||
} else {
|
||||
Err(Error::MissingCapabilities(capabilities.to_vec()))
|
||||
self.capabilities.extend(capabilities);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ fn check_output_spv(
|
||||
let options = spv::Options {
|
||||
lang_version: params.spv_version,
|
||||
flags,
|
||||
capabilities: params.spv_capabilities.clone(),
|
||||
capabilities: Some(params.spv_capabilities.clone()),
|
||||
};
|
||||
|
||||
let spv = spv::write_vec(module, info, &options).unwrap();
|
||||
|
||||
Reference in new issue
Block a user