-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wgsl-in): create skeleton for
enable
directives
Co-Authored-By: FL33TW00D <chris@fleetwood.dev>
- Loading branch information
1 parent
b3f665b
commit 685e73c
Showing
7 changed files
with
202 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
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
112 changes: 112 additions & 0 deletions
112
naga/src/front/wgsl/parse/directive/enable_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,112 @@ | ||
//! `enable …;` extensions in WGSL. | ||
//! | ||
//! The focal point of this module is the [`EnableExtension`] API. | ||
use crate::{front::wgsl::error::Error, Span}; | ||
|
||
/// Tracks the status of every enable extension known to Naga. | ||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct EnableExtensions {} | ||
|
||
impl EnableExtensions { | ||
pub(crate) const fn empty() -> Self { | ||
Self {} | ||
} | ||
|
||
/// Add an enable extension to the set requested by a module. | ||
#[allow(unreachable_code)] | ||
pub(crate) fn add(&mut self, ext: ImplementedEnableExtension) { | ||
let _field: &mut bool = match ext {}; | ||
*_field = true; | ||
} | ||
|
||
/// Query whether an enable extension tracked here has been requested. | ||
#[allow(unused)] | ||
pub(crate) const fn contains(&self, ext: ImplementedEnableExtension) -> bool { | ||
match ext {} | ||
} | ||
} | ||
|
||
impl Default for EnableExtensions { | ||
fn default() -> Self { | ||
Self::empty() | ||
} | ||
} | ||
|
||
/// A shader language extension not guaranteed to be present in all environments. | ||
/// | ||
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#enable-extensions-sec> | ||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] | ||
pub enum EnableExtension { | ||
#[allow(unused)] | ||
Implemented(ImplementedEnableExtension), | ||
Unimplemented(UnimplementedEnableExtension), | ||
} | ||
|
||
impl EnableExtension { | ||
const F16: &'static str = "f16"; | ||
const CLIP_DISTANCES: &'static str = "clip_distances"; | ||
const DUAL_SOURCE_BLENDING: &'static str = "dual_source_blending"; | ||
|
||
/// Convert from a sentinel word in WGSL into its associated [`EnableExtension`], if possible. | ||
pub(crate) fn from_ident(word: &str, span: Span) -> Result<Self, Error<'_>> { | ||
Ok(match word { | ||
Self::F16 => Self::Unimplemented(UnimplementedEnableExtension::F16), | ||
Self::CLIP_DISTANCES => { | ||
Self::Unimplemented(UnimplementedEnableExtension::ClipDistances) | ||
} | ||
Self::DUAL_SOURCE_BLENDING => { | ||
Self::Unimplemented(UnimplementedEnableExtension::DualSourceBlending) | ||
} | ||
_ => return Err(Error::UnknownEnableExtension(span, word)), | ||
}) | ||
} | ||
|
||
/// Maps this [`EnableExtension`] into the sentinel word associated with it in WGSL. | ||
pub fn to_ident(self) -> &'static str { | ||
match self { | ||
Self::Implemented(kind) => match kind {}, | ||
Self::Unimplemented(kind) => match kind { | ||
UnimplementedEnableExtension::F16 => Self::F16, | ||
UnimplementedEnableExtension::ClipDistances => todo!(), | ||
UnimplementedEnableExtension::DualSourceBlending => todo!(), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
/// A variant of [`EnableExtension::Implemented`]. | ||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] | ||
pub enum ImplementedEnableExtension {} | ||
|
||
/// A variant of [`EnableExtension::Unimplemented`]. | ||
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)] | ||
pub enum UnimplementedEnableExtension { | ||
/// Enables `f16`/`half` primitive support in all shader languages. | ||
/// | ||
/// In the WGSL standard, this corresponds to [`enable f16;`]. | ||
/// | ||
/// [`enable f16;`]: https://www.w3.org/TR/WGSL/#extension-f16 | ||
F16, | ||
/// Enables the `clip_distances` variable in WGSL. | ||
/// | ||
/// In the WGSL standard, this corresponds to [`enable clip_distances;`]. | ||
/// | ||
/// [`enable clip_distances;`]: https://www.w3.org/TR/WGSL/#extension-f16 | ||
ClipDistances, | ||
/// Enables the `blend_src` attribute in WGSL. | ||
/// | ||
/// In the WGSL standard, this corresponds to [`enable dual_source_blending;`]. | ||
/// | ||
/// [`enable dual_source_blending;`]: https://www.w3.org/TR/WGSL/#extension-f16 | ||
DualSourceBlending, | ||
} | ||
|
||
impl UnimplementedEnableExtension { | ||
pub(crate) const fn tracking_issue_num(self) -> u16 { | ||
match self { | ||
Self::F16 => 4384, | ||
Self::ClipDistances => 6236, | ||
Self::DualSourceBlending => 6402, | ||
} | ||
} | ||
} |
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