mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 06:21:13 +01:00
Move language_extension into naga-types
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
1 parent
0acb823f54
commit
a072eea89d
6 files changed
+130
-123
No files matched your search
Generated
+1
@@ -2495,6 +2495,7 @@ dependencies = [
|
||||
"indexmap",
|
||||
"rustc-hash 1.1.0",
|
||||
"serde",
|
||||
"strum 0.28.0",
|
||||
"thiserror 2.0.20",
|
||||
]
|
||||
|
||||
|
||||
@@ -27,3 +27,6 @@ indexmap.workspace = true
|
||||
rustc-hash.workspace = true
|
||||
serde = { workspace = true, features = ["alloc", "derive"], optional = true }
|
||||
thiserror.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
strum.workspace = true
|
||||
@@ -8,6 +8,7 @@ pub mod glsl;
|
||||
pub mod hlsl;
|
||||
pub mod msl;
|
||||
pub mod spv;
|
||||
pub mod wgsl;
|
||||
|
||||
/// Create a Markdown link definition referring to the `wgpu` crate.
|
||||
///
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/// `requires …;` extensions in WGSL.
|
||||
///
|
||||
/// The focal point of this module is the [`LanguageExtension`](language_extension::LanguageExtension) API.
|
||||
pub mod language_extension {
|
||||
|
||||
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
|
||||
///
|
||||
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum LanguageExtension {
|
||||
Implemented(ImplementedLanguageExtension),
|
||||
Unimplemented(UnimplementedLanguageExtension),
|
||||
}
|
||||
|
||||
impl LanguageExtension {
|
||||
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";
|
||||
const IMMEDIATE_ADDRESS_SPACE: &'static str = "immediate_address_space";
|
||||
|
||||
/// Convert from a sentinel word in WGSL into its associated [`LanguageExtension`], if possible.
|
||||
pub fn from_ident(s: &str) -> Option<Self> {
|
||||
Some(match s {
|
||||
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES => Self::Implemented(
|
||||
ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures,
|
||||
),
|
||||
Self::PACKED4X8_INTEGER_DOT_PRODUCT => {
|
||||
Self::Implemented(ImplementedLanguageExtension::Packed4x8IntegerDotProduct)
|
||||
}
|
||||
Self::UNRESTRICTED_POINTER_PARAMETERS => Self::Unimplemented(
|
||||
UnimplementedLanguageExtension::UnrestrictedPointerParameters,
|
||||
),
|
||||
Self::POINTER_COMPOSITE_ACCESS => {
|
||||
Self::Implemented(ImplementedLanguageExtension::PointerCompositeAccess)
|
||||
}
|
||||
Self::IMMEDIATE_ADDRESS_SPACE => {
|
||||
Self::Implemented(ImplementedLanguageExtension::ImmediateAddressSpace)
|
||||
}
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Maps this [`LanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {
|
||||
Self::Implemented(kind) => kind.to_ident(),
|
||||
Self::Unimplemented(kind) => match kind {
|
||||
UnimplementedLanguageExtension::UnrestrictedPointerParameters => {
|
||||
Self::UNRESTRICTED_POINTER_PARAMETERS
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Implemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[cfg_attr(test, derive(strum::VariantArray))]
|
||||
pub enum ImplementedLanguageExtension {
|
||||
ReadOnlyAndReadWriteStorageTextures,
|
||||
Packed4x8IntegerDotProduct,
|
||||
PointerCompositeAccess,
|
||||
ImmediateAddressSpace,
|
||||
}
|
||||
|
||||
impl ImplementedLanguageExtension {
|
||||
/// A slice of all variants of [`ImplementedLanguageExtension`].
|
||||
pub const VARIANTS: &'static [Self] = &[
|
||||
Self::ReadOnlyAndReadWriteStorageTextures,
|
||||
Self::Packed4x8IntegerDotProduct,
|
||||
Self::PointerCompositeAccess,
|
||||
Self::ImmediateAddressSpace,
|
||||
];
|
||||
|
||||
/// Returns slice of all variants of [`ImplementedLanguageExtension`].
|
||||
pub const fn all() -> &'static [Self] {
|
||||
Self::VARIANTS
|
||||
}
|
||||
|
||||
/// Maps this [`ImplementedLanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {
|
||||
ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures => {
|
||||
LanguageExtension::READONLY_AND_READWRITE_STORAGE_TEXTURES
|
||||
}
|
||||
ImplementedLanguageExtension::Packed4x8IntegerDotProduct => {
|
||||
LanguageExtension::PACKED4X8_INTEGER_DOT_PRODUCT
|
||||
}
|
||||
ImplementedLanguageExtension::PointerCompositeAccess => {
|
||||
LanguageExtension::POINTER_COMPOSITE_ACCESS
|
||||
}
|
||||
ImplementedLanguageExtension::ImmediateAddressSpace => {
|
||||
LanguageExtension::IMMEDIATE_ADDRESS_SPACE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Asserts that the manual implementation of VARIANTS is the same as the derived strum version would be
|
||||
/// while still allowing strum to be a dev-only dependency
|
||||
fn test_manual_variants_array_is_correct() {
|
||||
assert_eq!(
|
||||
<ImplementedLanguageExtension as strum::VariantArray>::VARIANTS,
|
||||
ImplementedLanguageExtension::VARIANTS
|
||||
);
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Unimplemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum UnimplementedLanguageExtension {
|
||||
UnrestrictedPointerParameters,
|
||||
}
|
||||
|
||||
impl UnimplementedLanguageExtension {
|
||||
pub const fn tracking_issue_num(self) -> u16 {
|
||||
match self {
|
||||
Self::UnrestrictedPointerParameters => 5158,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
//! See also <https://www.w3.org/TR/WGSL/#directives>.
|
||||
|
||||
pub mod enable_extension;
|
||||
pub(crate) mod language_extension;
|
||||
pub(crate) use naga_types::wgsl::language_extension;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
//! `requires …;` extensions in WGSL.
|
||||
//!
|
||||
//! The focal point of this module is the [`LanguageExtension`] API.
|
||||
|
||||
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
|
||||
///
|
||||
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum LanguageExtension {
|
||||
Implemented(ImplementedLanguageExtension),
|
||||
Unimplemented(UnimplementedLanguageExtension),
|
||||
}
|
||||
|
||||
impl LanguageExtension {
|
||||
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";
|
||||
const IMMEDIATE_ADDRESS_SPACE: &'static str = "immediate_address_space";
|
||||
|
||||
/// Convert from a sentinel word in WGSL into its associated [`LanguageExtension`], if possible.
|
||||
pub fn from_ident(s: &str) -> Option<Self> {
|
||||
Some(match s {
|
||||
Self::READONLY_AND_READWRITE_STORAGE_TEXTURES => {
|
||||
Self::Implemented(ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures)
|
||||
}
|
||||
Self::PACKED4X8_INTEGER_DOT_PRODUCT => {
|
||||
Self::Implemented(ImplementedLanguageExtension::Packed4x8IntegerDotProduct)
|
||||
}
|
||||
Self::UNRESTRICTED_POINTER_PARAMETERS => {
|
||||
Self::Unimplemented(UnimplementedLanguageExtension::UnrestrictedPointerParameters)
|
||||
}
|
||||
Self::POINTER_COMPOSITE_ACCESS => {
|
||||
Self::Implemented(ImplementedLanguageExtension::PointerCompositeAccess)
|
||||
}
|
||||
Self::IMMEDIATE_ADDRESS_SPACE => {
|
||||
Self::Implemented(ImplementedLanguageExtension::ImmediateAddressSpace)
|
||||
}
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Maps this [`LanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {
|
||||
Self::Implemented(kind) => kind.to_ident(),
|
||||
Self::Unimplemented(kind) => match kind {
|
||||
UnimplementedLanguageExtension::UnrestrictedPointerParameters => {
|
||||
Self::UNRESTRICTED_POINTER_PARAMETERS
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Implemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[cfg_attr(test, derive(strum::VariantArray))]
|
||||
pub enum ImplementedLanguageExtension {
|
||||
ReadOnlyAndReadWriteStorageTextures,
|
||||
Packed4x8IntegerDotProduct,
|
||||
PointerCompositeAccess,
|
||||
ImmediateAddressSpace,
|
||||
}
|
||||
|
||||
impl ImplementedLanguageExtension {
|
||||
/// A slice of all variants of [`ImplementedLanguageExtension`].
|
||||
pub const VARIANTS: &'static [Self] = &[
|
||||
Self::ReadOnlyAndReadWriteStorageTextures,
|
||||
Self::Packed4x8IntegerDotProduct,
|
||||
Self::PointerCompositeAccess,
|
||||
Self::ImmediateAddressSpace,
|
||||
];
|
||||
|
||||
/// Returns slice of all variants of [`ImplementedLanguageExtension`].
|
||||
pub const fn all() -> &'static [Self] {
|
||||
Self::VARIANTS
|
||||
}
|
||||
|
||||
/// Maps this [`ImplementedLanguageExtension`] into the sentinel word associated with it in WGSL.
|
||||
pub const fn to_ident(self) -> &'static str {
|
||||
match self {
|
||||
ImplementedLanguageExtension::ReadOnlyAndReadWriteStorageTextures => {
|
||||
LanguageExtension::READONLY_AND_READWRITE_STORAGE_TEXTURES
|
||||
}
|
||||
ImplementedLanguageExtension::Packed4x8IntegerDotProduct => {
|
||||
LanguageExtension::PACKED4X8_INTEGER_DOT_PRODUCT
|
||||
}
|
||||
ImplementedLanguageExtension::PointerCompositeAccess => {
|
||||
LanguageExtension::POINTER_COMPOSITE_ACCESS
|
||||
}
|
||||
ImplementedLanguageExtension::ImmediateAddressSpace => {
|
||||
LanguageExtension::IMMEDIATE_ADDRESS_SPACE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
/// Asserts that the manual implementation of VARIANTS is the same as the derived strum version would be
|
||||
/// while still allowing strum to be a dev-only dependency
|
||||
fn test_manual_variants_array_is_correct() {
|
||||
assert_eq!(
|
||||
<ImplementedLanguageExtension as strum::VariantArray>::VARIANTS,
|
||||
ImplementedLanguageExtension::VARIANTS
|
||||
);
|
||||
}
|
||||
|
||||
/// A variant of [`LanguageExtension::Unimplemented`].
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum UnimplementedLanguageExtension {
|
||||
UnrestrictedPointerParameters,
|
||||
}
|
||||
|
||||
impl UnimplementedLanguageExtension {
|
||||
pub(crate) const fn tracking_issue_num(self) -> u16 {
|
||||
match self {
|
||||
Self::UnrestrictedPointerParameters => 5158,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user