naga/front/wgsl/parse/directive/
enable_extension.rs1use crate::front::wgsl::{Error, Result};
6use crate::Span;
7
8use alloc::boxed::Box;
9
10#[derive(Clone, Debug, Eq, PartialEq)]
12pub struct EnableExtensions {
13 dual_source_blending: bool,
14 f16: bool,
16}
17
18impl EnableExtensions {
19 pub(crate) const fn empty() -> Self {
20 Self {
21 f16: false,
22 dual_source_blending: false,
23 }
24 }
25
26 pub(crate) fn add(&mut self, ext: ImplementedEnableExtension) {
28 let field = match ext {
29 ImplementedEnableExtension::DualSourceBlending => &mut self.dual_source_blending,
30 ImplementedEnableExtension::F16 => &mut self.f16,
31 };
32 *field = true;
33 }
34
35 pub(crate) const fn contains(&self, ext: ImplementedEnableExtension) -> bool {
37 match ext {
38 ImplementedEnableExtension::DualSourceBlending => self.dual_source_blending,
39 ImplementedEnableExtension::F16 => self.f16,
40 }
41 }
42}
43
44impl Default for EnableExtensions {
45 fn default() -> Self {
46 Self::empty()
47 }
48}
49
50#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
54pub enum EnableExtension {
55 Implemented(ImplementedEnableExtension),
56 Unimplemented(UnimplementedEnableExtension),
57}
58
59impl From<ImplementedEnableExtension> for EnableExtension {
60 fn from(value: ImplementedEnableExtension) -> Self {
61 Self::Implemented(value)
62 }
63}
64
65impl EnableExtension {
66 const F16: &'static str = "f16";
67 const CLIP_DISTANCES: &'static str = "clip_distances";
68 const DUAL_SOURCE_BLENDING: &'static str = "dual_source_blending";
69 const SUBGROUPS: &'static str = "subgroups";
70
71 pub(crate) fn from_ident(word: &str, span: Span) -> Result<Self> {
73 Ok(match word {
74 Self::F16 => Self::Implemented(ImplementedEnableExtension::F16),
75 Self::CLIP_DISTANCES => {
76 Self::Unimplemented(UnimplementedEnableExtension::ClipDistances)
77 }
78 Self::DUAL_SOURCE_BLENDING => {
79 Self::Implemented(ImplementedEnableExtension::DualSourceBlending)
80 }
81 Self::SUBGROUPS => Self::Unimplemented(UnimplementedEnableExtension::Subgroups),
82 _ => return Err(Box::new(Error::UnknownEnableExtension(span, word))),
83 })
84 }
85
86 pub const fn to_ident(self) -> &'static str {
88 match self {
89 Self::Implemented(kind) => match kind {
90 ImplementedEnableExtension::DualSourceBlending => Self::DUAL_SOURCE_BLENDING,
91 ImplementedEnableExtension::F16 => Self::F16,
92 },
93 Self::Unimplemented(kind) => match kind {
94 UnimplementedEnableExtension::ClipDistances => Self::CLIP_DISTANCES,
95 UnimplementedEnableExtension::Subgroups => Self::SUBGROUPS,
96 },
97 }
98 }
99}
100
101#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
103pub enum ImplementedEnableExtension {
104 F16,
110 DualSourceBlending,
116}
117
118#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
120pub enum UnimplementedEnableExtension {
121 ClipDistances,
127 Subgroups,
133}
134
135impl UnimplementedEnableExtension {
136 pub(crate) const fn tracking_issue_num(self) -> u16 {
137 match self {
138 Self::ClipDistances => 6236,
139 Self::Subgroups => 5555,
140 }
141 }
142}