From 117d729ff8defd404945c021fc62cf4c8d4862d7 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 25 Apr 2021 18:20:04 -0400 Subject: [PATCH] [spv-in] allow non-strict check for capabilities --- bin/naga.rs | 1 + src/front/glsl/parser.rs | 7 ++++++- src/front/spv/mod.rs | 14 ++++++++++++-- tests/snapshots.rs | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/naga.rs b/bin/naga.rs index bd8100bf57..a0ab7b6754 100644 --- a/bin/naga.rs +++ b/bin/naga.rs @@ -105,6 +105,7 @@ fn main() { "spv" => { let options = naga::front::spv::Options { adjust_coordinate_space: params.spv_adjust_coordinate_space, + strict_capabilities: false, flow_graph_dump_prefix: params.spv_flow_dump_prefix.map(std::path::PathBuf::from), }; let input = fs::read(input_path).unwrap(); diff --git a/src/front/glsl/parser.rs b/src/front/glsl/parser.rs index 1b260ea72c..3f26863abc 100644 --- a/src/front/glsl/parser.rs +++ b/src/front/glsl/parser.rs @@ -1,4 +1,9 @@ -#![allow(clippy::panic, clippy::needless_lifetimes, clippy::upper_case_acronyms)] +#![allow( + unused_braces, + clippy::panic, + clippy::needless_lifetimes, + clippy::upper_case_acronyms +)] use pomelo::pomelo; pomelo! { //%verbose; diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index 90f397c4df..b33db13603 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -68,7 +68,10 @@ pub const SUPPORTED_CAPABILITIES: &[spirv::Capability] = &[ spirv::Capability::UniformBufferArrayDynamicIndexing, spirv::Capability::StorageBufferArrayDynamicIndexing, ]; -pub const SUPPORTED_EXTENSIONS: &[&str] = &["SPV_KHR_vulkan_memory_model"]; +pub const SUPPORTED_EXTENSIONS: &[&str] = &[ + "SPV_KHR_storage_buffer_storage_class", + "SPV_KHR_vulkan_memory_model", +]; pub const SUPPORTED_EXT_SETS: &[&str] = &["GLSL.std.450"]; #[derive(Copy, Clone)] @@ -347,6 +350,8 @@ pub struct Options { /// so by default we flip the Y coordinate of the `BuiltIn::Position`. /// This flag can be used to avoid this. pub adjust_coordinate_space: bool, + /// Only allow shaders with the known set of capabilities. + pub strict_capabilities: bool, pub flow_graph_dump_prefix: Option, } @@ -354,6 +359,7 @@ impl Default for Options { fn default() -> Self { Options { adjust_coordinate_space: true, + strict_capabilities: false, flow_graph_dump_prefix: None, } } @@ -2208,7 +2214,11 @@ impl> Parser { let cap = spirv::Capability::from_u32(capability).ok_or(Error::UnknownCapability(capability))?; if !SUPPORTED_CAPABILITIES.contains(&cap) { - return Err(Error::UnsupportedCapability(cap)); + if self.options.strict_capabilities { + return Err(Error::UnsupportedCapability(cap)); + } else { + log::warn!("Unknown capability {:?}", cap); + } } Ok(()) } diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 1363d3ef62..ed46091c0b 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -263,6 +263,7 @@ fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { &fs::read(format!("{}/{}/{}.spv", root, DIR_IN, name)).expect("Couldn't find spv file"), &naga::front::spv::Options { adjust_coordinate_space, + strict_capabilities: false, flow_graph_dump_prefix: None, }, )