| 1 |
//! `requires …;` extensions in WGSL. |
| 2 |
//! |
| 3 |
//! The focal point of this module is the [`LanguageExtension`] API. |
| 4 |
|
| 5 |
use strum::VariantArray; |
| 6 |
|
| 7 |
/// A language extension recognized by Naga, but not guaranteed to be present in all environments. |
| 8 |
/// |
| 9 |
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec> |
| 10 |
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] |
| 11 |
pub enum LanguageExtension { |
| 12 |
#[allow(unused)] |
| 13 |
Implemented(ImplementedLanguageExtension), |
| 14 |
Unimplemented(UnimplementedLanguageExtension), |
| 15 |
} |
| 16 |
|
| 17 |
impl LanguageExtension { |
| 18 |
const READONLY_AND_READWRITE_STORAGE_TEXTURES: &'static str = |
| 19 |
"readonly_and_readwrite_storage_textures"; |
| 20 |
const PACKED4X8_INTEGER_DOT_PRODUCT: &'static str = "packed_4x8_integer_dot_product"; |
| 21 |
const UNRESTRICTED_POINTER_PARAMETERS: &'static str = "unrestricted_pointer_parameters"; |
| 22 |
const POINTER_COMPOSITE_ACCESS: &'static str = "pointer_composite_access"; |
| 23 |
|
| 24 |
/// Convert from a sentinel word in WGSL into its associated [`LanguageExtension`], if possible. |
| 25 |
pub fn from_ident(s: &str) -> Option<Self> { |
| 26 |
Some(match s { |
| 27 |
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES => { |
| 28 |
Self::Implemented(ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures) |
| 29 |
} |
| 30 |
Self::PACKED4X8_INTEGER_DOT_PRODUCT => { |
| 31 |
Self::Implemented(ImplementedLanguageExtension::Packed4x8IntegerDotProduct) |
| 32 |
} |
| 33 |
Self::UNRESTRICTED_POINTER_PARAMETERS => { |
| 34 |
Self::Unimplemented(UnimplementedLanguageExtension::UnrestrictedPointerParameters) |
| 35 |
} |
| 36 |
Self::POINTER_COMPOSITE_ACCESS => { |
| 37 |
Self::Implemented(ImplementedLanguageExtension::PointerCompositeAccess) |
| 38 |
} |
| 39 |
_ => return None, |
| 40 |
}) |
| 41 |
} |
| 42 |
|
| 43 |
/// Maps this [`LanguageExtension`] into the sentinel word associated with it in WGSL. |
| 44 |
pub const fn to_ident(self) -> &'static str { |
| 45 |
match self { |
| 46 |
Self::Implemented(kind) => kind.to_ident(), |
| 47 |
Self::Unimplemented(kind) => match kind { |
| 48 |
UnimplementedLanguageExtension::UnrestrictedPointerParameters => { |
| 49 |
Self::UNRESTRICTED_POINTER_PARAMETERS |
| 50 |
} |
| 51 |
}, |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/// A variant of [`LanguageExtension::Implemented`]. |
| 57 |
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, VariantArray)] |
| 58 |
pub enum ImplementedLanguageExtension { |
| 59 |
ReadOnlyAndReadWriteStorageTextures, |
| 60 |
Packed4x8IntegerDotProduct, |
| 61 |
PointerCompositeAccess, |
| 62 |
} |
| 63 |
|
| 64 |
impl ImplementedLanguageExtension { |
| 65 |
/// Returns slice of all variants of [`ImplementedLanguageExtension`]. |
| 66 |
pub const fn all() -> &'static [Self] { |
| 67 |
Self::VARIANTS |
| 68 |
} |
| 69 |
|
| 70 |
/// Maps this [`ImplementedLanguageExtension`] into the sentinel word associated with it in WGSL. |
| 71 |
pub const fn to_ident(self) -> &'static str { |
| 72 |
match self { |
| 73 |
ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures => { |
| 74 |
LanguageExtension::READONLY_AND_READWRITE_STORAGE_TEXTURES |
| 75 |
} |
| 76 |
ImplementedLanguageExtension::Packed4x8IntegerDotProduct => { |
| 77 |
LanguageExtension::PACKED4X8_INTEGER_DOT_PRODUCT |
| 78 |
} |
| 79 |
ImplementedLanguageExtension::PointerCompositeAccess => { |
| 80 |
LanguageExtension::POINTER_COMPOSITE_ACCESS |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
/// A variant of [`LanguageExtension::Unimplemented`]. |
| 87 |
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] |
| 88 |
pub enum UnimplementedLanguageExtension { |
| 89 |
UnrestrictedPointerParameters, |
| 90 |
} |
| 91 |
|
| 92 |
impl UnimplementedLanguageExtension { |
| 93 |
pub(crate) const fn tracking_issue_num(self) -> u16 { |
| 94 |
match self { |
| 95 |
Self::UnrestrictedPointerParameters => 5158, |
| 96 |
} |
| 97 |
} |
| 98 |
} |