-
Notifications
You must be signed in to change notification settings - Fork 938
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e28ac60
commit 499bddd
Showing
4 changed files
with
244 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
naga/src/front/wgsl/parse/directive/language_extension.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#[cfg(test)] | ||
use strum::IntoEnumIterator; | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
pub(crate) enum LanguageExtension { | ||
#[allow(unused)] | ||
Implemented(ImplementedLanguageExtension), | ||
Unimplemented(UnimplementedLanguageExtension), | ||
} | ||
|
||
impl LanguageExtension { | ||
#[cfg(test)] | ||
const NAGA_REPLACE_ME_WITH_A_REAL_EXTENSION_PLZ: &'static str = | ||
"naga_replace_me_with_a_real_extension_plz"; | ||
const READONLY_AND_READWRITE_STORAGE_TEXTURES: &'static str = | ||
"readonly_and_readwrite_storage_textures"; | ||
const PACKED4X8_INTEGER_DOT_PRODUCT: &'static str = "packed_4x8_integer_dot_product"; | ||
const UNRESTRICTED_POINTER_PARAMETERS: &'static str = "unrestricted_pointer_parameters"; | ||
const POINTER_COMPOSITE_ACCESS: &'static str = "pointer_composite_access"; | ||
|
||
pub fn from_ident(s: &str) -> Option<Self> { | ||
Some(match s { | ||
#[cfg(test)] | ||
Self::NAGA_REPLACE_ME_WITH_A_REAL_EXTENSION_PLZ => { | ||
Self::Implemented(ImplementedLanguageExtension::NagaReplaceMeWithARealExtensionPlz) | ||
} | ||
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES => Self::Unimplemented( | ||
UnimplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures, | ||
), | ||
Self::PACKED4X8_INTEGER_DOT_PRODUCT => { | ||
Self::Unimplemented(UnimplementedLanguageExtension::Packed4x8IntegerDotProduct) | ||
} | ||
Self::UNRESTRICTED_POINTER_PARAMETERS => { | ||
Self::Unimplemented(UnimplementedLanguageExtension::UnrestrictedPointerParameters) | ||
} | ||
Self::POINTER_COMPOSITE_ACCESS => { | ||
Self::Unimplemented(UnimplementedLanguageExtension::PointerCompositeAccess) | ||
} | ||
_ => return None, | ||
}) | ||
} | ||
|
||
pub fn to_ident(self) -> &'static str { | ||
match self { | ||
Self::Implemented(kind) => match kind { | ||
#[cfg(test)] | ||
ImplementedLanguageExtension::NagaReplaceMeWithARealExtensionPlz => { | ||
Self::NAGA_REPLACE_ME_WITH_A_REAL_EXTENSION_PLZ | ||
} | ||
}, | ||
Self::Unimplemented(kind) => match kind { | ||
UnimplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures => { | ||
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES | ||
} | ||
UnimplementedLanguageExtension::Packed4x8IntegerDotProduct => { | ||
Self::PACKED4X8_INTEGER_DOT_PRODUCT | ||
} | ||
UnimplementedLanguageExtension::UnrestrictedPointerParameters => { | ||
Self::UNRESTRICTED_POINTER_PARAMETERS | ||
} | ||
UnimplementedLanguageExtension::PointerCompositeAccess => { | ||
Self::POINTER_COMPOSITE_ACCESS | ||
} | ||
}, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
fn iter() -> impl Iterator<Item = Self> { | ||
let implemented = ImplementedLanguageExtension::iter().map(Self::Implemented); | ||
let unimplemented = UnimplementedLanguageExtension::iter().map(Self::Unimplemented); | ||
implemented.chain(unimplemented) | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
#[cfg_attr(test, derive(strum::EnumIter))] | ||
pub(crate) enum ImplementedLanguageExtension { | ||
#[cfg(test)] | ||
NagaReplaceMeWithARealExtensionPlz, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] | ||
#[cfg_attr(test, derive(strum::EnumIter))] | ||
pub(crate) enum UnimplementedLanguageExtension { | ||
ReadOnlyAndReadWriteStorageTextures, | ||
Packed4x8IntegerDotProduct, | ||
UnrestrictedPointerParameters, | ||
PointerCompositeAccess, | ||
} | ||
|
||
impl UnimplementedLanguageExtension { | ||
pub(crate) fn tracking_issue_num(self) -> u16 { | ||
match self { | ||
Self::ReadOnlyAndReadWriteStorageTextures => todo!(), | ||
Self::Packed4x8IntegerDotProduct => todo!(), | ||
Self::UnrestrictedPointerParameters => todo!(), | ||
Self::PointerCompositeAccess => todo!(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use itertools::Itertools; | ||
use strum::IntoEnumIterator; | ||
|
||
use crate::front::wgsl::assert_parse_err; | ||
|
||
use super::{ImplementedLanguageExtension, LanguageExtension}; | ||
|
||
#[test] | ||
fn implemented() { | ||
#[derive(Clone, Debug, strum::EnumIter)] | ||
enum Count { | ||
ByItself, | ||
WithOther, | ||
} | ||
|
||
#[derive(Clone, Debug, strum::EnumIter)] | ||
enum Separation { | ||
SameLineNoSpace, | ||
SameLine, | ||
MultiLine, | ||
} | ||
|
||
#[derive(Clone, Debug, strum::EnumIter)] | ||
enum TrailingComma { | ||
Yes, | ||
No, | ||
} | ||
|
||
#[track_caller] | ||
fn test_requires(before: &str, idents: &[&str], ident_sep: &str, after: &str) { | ||
let ident_list = idents.join(ident_sep); | ||
let shader = format!("requires{before}{ident_list}{after};"); | ||
let expected_msg = "".to_string(); | ||
assert_parse_err(&shader, &expected_msg); | ||
} | ||
|
||
let implemented_extensions = | ||
ImplementedLanguageExtension::iter().map(LanguageExtension::Implemented); | ||
|
||
let iter = implemented_extensions | ||
.clone() | ||
.cartesian_product(Count::iter()) | ||
.cartesian_product(Separation::iter()) | ||
.cartesian_product(TrailingComma::iter()); | ||
for (((extension, count), separation), trailing_comma) in iter { | ||
let before; | ||
let ident_sep; | ||
match separation { | ||
Separation::SameLine => { | ||
before = " "; | ||
ident_sep = ", "; | ||
} | ||
Separation::SameLineNoSpace => { | ||
before = " "; | ||
ident_sep = ","; | ||
} | ||
Separation::MultiLine => { | ||
before = "\n "; | ||
ident_sep = ",\n "; | ||
} | ||
} | ||
let after = match trailing_comma { | ||
TrailingComma::Yes => ident_sep, | ||
TrailingComma::No => before, | ||
}; | ||
match count { | ||
Count::ByItself => test_requires(before, &[extension.to_ident()], ident_sep, after), | ||
Count::WithOther => { | ||
for other_extension in implemented_extensions.clone() { | ||
for list in [[extension, other_extension], [other_extension, extension]] { | ||
let list = list.map(|e| e.to_ident()); | ||
test_requires(before, &list, ident_sep, after); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn unimplemented() {} | ||
|
||
#[test] | ||
fn unknown() {} | ||
|
||
#[test] | ||
fn malformed() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters