Skip to content

Commit 9ebd79c

Browse files
committed
Move LanguageExtensions and EnableExtensions to directive module.
This commit is just code motion and module path adjustments; there are no significant changes to the code.
1 parent 301f373 commit 9ebd79c

10 files changed

Lines changed: 155 additions & 156 deletions

File tree

naga/src/front/wgsl/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use crate::error::replace_control_chars;
66
use crate::proc::{Alignment, ConstantEvaluatorError, ResolveError};
77
use crate::{Scalar, SourceLocation, Span};
88

9-
use super::parse::directive::enable_extension::EnableExtensions;
10-
use super::parse::directive::language_extension::LanguageExtensions;
9+
use super::parse::directive::{EnableExtensions, LanguageExtensions};
1110
use super::parse::lexer::Token;
1211

1312
use codespan_reporting::diagnostic::{Diagnostic, Label};

naga/src/front/wgsl/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ mod parse;
1111
#[cfg(test)]
1212
mod tests;
1313

14-
pub use parse::directive::enable_extension::EnableExtensions;
15-
pub use parse::directive::language_extension::LanguageExtensions;
14+
pub use parse::directive::{EnableExtensions, LanguageExtensions};
1615

1716
pub use crate::front::wgsl::error::ParseError;
1817
pub use crate::front::wgsl::parse::Options;

naga/src/front/wgsl/parse/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::vec::Vec;
22
use core::hash::Hash;
33

44
use crate::diagnostic_filter::DiagnosticFilterNode;
5-
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
5+
use crate::front::wgsl::parse::directive::EnableExtensions;
66
use crate::front::wgsl::parse::number::Number;
77
use crate::front::wgsl::Scalar;
88
use crate::{Arena, FastIndexSet, Handle, Span};

naga/src/front/wgsl/parse/conv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
1+
use crate::front::wgsl::parse::directive::EnableExtensions;
22
use crate::front::wgsl::{Error, Result, Scalar};
33
use crate::Span;
44

naga/src/front/wgsl/parse/directive.rs

Lines changed: 148 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,50 @@
22
//!
33
//! See also <https://www.w3.org/TR/WGSL/#directives>.
44
5+
use alloc::boxed::Box;
6+
7+
/// A parsed sentinel word indicating the type of directive to be parsed next.
8+
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
9+
#[cfg_attr(test, derive(strum::EnumIter))]
10+
pub(crate) enum DirectiveKind {
11+
/// A [`crate::diagnostic_filter`].
12+
Diagnostic,
13+
/// An [`enable_extension`].
14+
Enable,
15+
/// A [`language_extension`].
16+
Requires,
17+
}
18+
19+
impl DirectiveKind {
20+
const DIAGNOSTIC: &'static str = "diagnostic";
21+
const ENABLE: &'static str = "enable";
22+
const REQUIRES: &'static str = "requires";
23+
24+
/// Convert from a sentinel word in WGSL into its associated [`DirectiveKind`], if possible.
25+
pub fn from_ident(s: &str) -> Option<Self> {
26+
Some(match s {
27+
Self::DIAGNOSTIC => Self::Diagnostic,
28+
Self::ENABLE => Self::Enable,
29+
Self::REQUIRES => Self::Requires,
30+
_ => return None,
31+
})
32+
}
33+
}
34+
35+
impl crate::diagnostic_filter::Severity {
36+
#[cfg(feature = "wgsl-in")]
37+
pub(crate) fn report_wgsl_parse_diag<'a>(
38+
self,
39+
err: Box<crate::front::wgsl::error::Error<'a>>,
40+
source: &str,
41+
) -> crate::front::wgsl::Result<'a, ()> {
42+
self.report_diag(err, |e, level| {
43+
let e = e.as_parse_error(source);
44+
log::log!(level, "{}", e.emit_to_string(source));
45+
})
46+
}
47+
}
48+
549
/// Define a bitflags type representing a set of extensions, with their source names.
650
///
751
/// This is used to define bitflags types for language and enable
@@ -58,47 +102,117 @@ macro_rules! define_extensions {
58102
pub mod enable_extension;
59103
pub(crate) mod language_extension;
60104

61-
use alloc::boxed::Box;
105+
define_extensions! {
106+
/// All enable extensions known to Naga.
107+
///
108+
/// This includes extensions that Naga does not implement; the [`IMPLEMENTED`]
109+
/// associated constant indicates which ones we do support.
110+
///
111+
/// [`IMPLEMENTED`]: EnableExtensions::IMPLEMENTED
112+
#[derive(Default)]
113+
pub struct EnableExtensions: u32 {
114+
/// Enables `f16`/`half` primitive support in all shader languages.
115+
///
116+
/// In the WGSL standard, this corresponds to [`enable f16;`].
117+
///
118+
/// [`enable f16;`]: https://www.w3.org/TR/WGSL/#extension-f16
119+
const F16, "f16" = 0x1;
62120

63-
/// A parsed sentinel word indicating the type of directive to be parsed next.
64-
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
65-
#[cfg_attr(test, derive(strum::EnumIter))]
66-
pub(crate) enum DirectiveKind {
67-
/// A [`crate::diagnostic_filter`].
68-
Diagnostic,
69-
/// An [`enable_extension`].
70-
Enable,
71-
/// A [`language_extension`].
72-
Requires,
121+
/// Enables the `clip_distances` variable in WGSL.
122+
///
123+
/// In the WGSL standard, this corresponds to [`enable clip_distances;`].
124+
///
125+
/// [`enable clip_distances;`]: https://www.w3.org/TR/WGSL/#extension-clip_distances
126+
const CLIP_DISTANCES, "clip_distances" = 0x2;
127+
128+
/// Enables the `blend_src` attribute in WGSL.
129+
///
130+
/// In the WGSL standard, this corresponds to [`enable dual_source_blending;`].
131+
///
132+
/// [`enable dual_source_blending;`]: https://www.w3.org/TR/WGSL/#extension-dual_source_blending
133+
const DUAL_SOURCE_BLENDING, "dual_source_blending" = 0x4;
134+
135+
/// Enables subgroup built-ins in all languages.
136+
///
137+
/// In the WGSL standard, this corresponds to [`enable subgroups;`].
138+
///
139+
/// [`enable subgroups;`]: https://www.w3.org/TR/WGSL/#extension-subgroups
140+
const SUBGROUPS, "subgroups" = 0x8;
141+
142+
/// Enables the `@builtin(primitive_index)` attribute in WGSL.
143+
///
144+
/// In the WGSL standard, this corresponds to [`enable primitive-index;`].
145+
///
146+
/// [`enable primitive-index;`]: https://www.w3.org/TR/WGSL/#extension-primitive_index
147+
const PRIMITIVE_INDEX, "primitive_index" = 0x10;
148+
149+
// wgpu extensions
150+
151+
/// Enables the `wgpu_mesh_shader` extension, native only
152+
const WGPU_MESH_SHADER, "wgpu_mesh_shader" = 0x100;
153+
154+
/// Enables the `wgpu_ray_query` extension, native only.
155+
const WGPU_RAY_QUERY, "wgpu_ray_query" = 0x200;
156+
157+
/// Enables the `wgpu_ray_query_vertex_return` extension, native only.
158+
const WGPU_RAY_QUERY_VERTEX_RETURN, "wgpu_ray_query_vertex_return" = 0x400;
159+
}
73160
}
74161

75-
impl DirectiveKind {
76-
const DIAGNOSTIC: &'static str = "diagnostic";
77-
const ENABLE: &'static str = "enable";
78-
const REQUIRES: &'static str = "requires";
162+
impl EnableExtensions {
163+
pub const IMPLEMENTED: Self =
164+
Self::empty()
165+
.union(Self::WGPU_MESH_SHADER)
166+
.union(Self::WGPU_RAY_QUERY)
167+
.union(Self::WGPU_RAY_QUERY_VERTEX_RETURN)
168+
.union(Self::DUAL_SOURCE_BLENDING)
169+
.union(Self::F16)
170+
.union(Self::CLIP_DISTANCES);
79171

80-
/// Convert from a sentinel word in WGSL into its associated [`DirectiveKind`], if possible.
81-
pub fn from_ident(s: &str) -> Option<Self> {
82-
Some(match s {
83-
Self::DIAGNOSTIC => Self::Diagnostic,
84-
Self::ENABLE => Self::Enable,
85-
Self::REQUIRES => Self::Requires,
86-
_ => return None,
87-
})
172+
pub const UNIMPLEMENTED: Self = Self::IMPLEMENTED.complement();
173+
174+
pub fn tracking_issue_num(self) -> Option<u16> {
175+
match self {
176+
Self::SUBGROUPS => Some(5555),
177+
Self::PRIMITIVE_INDEX => Some(8236),
178+
other => {
179+
assert!(Self::IMPLEMENTED.contains(other));
180+
None
181+
}
182+
}
88183
}
89184
}
90185

91-
impl crate::diagnostic_filter::Severity {
92-
#[cfg(feature = "wgsl-in")]
93-
pub(crate) fn report_wgsl_parse_diag<'a>(
94-
self,
95-
err: Box<crate::front::wgsl::error::Error<'a>>,
96-
source: &str,
97-
) -> crate::front::wgsl::Result<'a, ()> {
98-
self.report_diag(err, |e, level| {
99-
let e = e.as_parse_error(source);
100-
log::log!(level, "{}", e.emit_to_string(source));
101-
})
186+
define_extensions! {
187+
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
188+
///
189+
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
190+
#[derive(Default)]
191+
pub struct LanguageExtensions: u32 {
192+
const READONLY_AND_READWRITE_STORAGE_TEXTURES, "readonly_and_readwrite_storage_textures" = 0x1;
193+
const PACKED4X8_INTEGER_DOT_PRODUCT, "packed_4x8_integer_dot_product" = 0x2;
194+
const UNRESTRICTED_POINTER_PARAMETERS, "unrestricted_pointer_parameters" = 0x4;
195+
const POINTER_COMPOSITE_ACCESS, "pointer_composite_access" = 0x8;
196+
}
197+
}
198+
199+
impl LanguageExtensions {
200+
pub const IMPLEMENTED: Self =
201+
Self::empty()
202+
.union(Self::READONLY_AND_READWRITE_STORAGE_TEXTURES)
203+
.union(Self::PACKED4X8_INTEGER_DOT_PRODUCT)
204+
.union(Self::POINTER_COMPOSITE_ACCESS);
205+
206+
pub const UNIMPLEMENTED: Self = Self::IMPLEMENTED.complement();
207+
208+
pub(crate) const fn tracking_issue_num(self) -> Option<u16> {
209+
match self {
210+
Self::UNRESTRICTED_POINTER_PARAMETERS => Some(5158),
211+
other => {
212+
assert!(Self::IMPLEMENTED.contains(other));
213+
None
214+
}
215+
}
102216
}
103217
}
104218

naga/src/front/wgsl/parse/directive/enable_extension.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,3 @@
22
//!
33
//! The focal point of this module is the [`EnableExtensions`] bitflags type.
44
5-
define_extensions! {
6-
/// All enable extensions known to Naga.
7-
///
8-
/// This includes extensions that Naga does not implement; the [`IMPLEMENTED`]
9-
/// associated constant indicates which ones we do support.
10-
///
11-
/// [`IMPLEMENTED`]: EnableExtensions::IMPLEMENTED
12-
#[derive(Default)]
13-
pub struct EnableExtensions: u32 {
14-
/// Enables `f16`/`half` primitive support in all shader languages.
15-
///
16-
/// In the WGSL standard, this corresponds to [`enable f16;`].
17-
///
18-
/// [`enable f16;`]: https://www.w3.org/TR/WGSL/#extension-f16
19-
const F16, "f16" = 0x1;
20-
21-
/// Enables the `clip_distances` variable in WGSL.
22-
///
23-
/// In the WGSL standard, this corresponds to [`enable clip_distances;`].
24-
///
25-
/// [`enable clip_distances;`]: https://www.w3.org/TR/WGSL/#extension-clip_distances
26-
const CLIP_DISTANCES, "clip_distances" = 0x2;
27-
28-
/// Enables the `blend_src` attribute in WGSL.
29-
///
30-
/// In the WGSL standard, this corresponds to [`enable dual_source_blending;`].
31-
///
32-
/// [`enable dual_source_blending;`]: https://www.w3.org/TR/WGSL/#extension-dual_source_blending
33-
const DUAL_SOURCE_BLENDING, "dual_source_blending" = 0x4;
34-
35-
/// Enables subgroup built-ins in all languages.
36-
///
37-
/// In the WGSL standard, this corresponds to [`enable subgroups;`].
38-
///
39-
/// [`enable subgroups;`]: https://www.w3.org/TR/WGSL/#extension-subgroups
40-
const SUBGROUPS, "subgroups" = 0x8;
41-
42-
/// Enables the `@builtin(primitive_index)` attribute in WGSL.
43-
///
44-
/// In the WGSL standard, this corresponds to [`enable primitive-index;`].
45-
///
46-
/// [`enable primitive-index;`]: https://www.w3.org/TR/WGSL/#extension-primitive_index
47-
const PRIMITIVE_INDEX, "primitive_index" = 0x10;
48-
49-
// wgpu extensions
50-
51-
/// Enables the `wgpu_mesh_shader` extension, native only
52-
const WGPU_MESH_SHADER, "wgpu_mesh_shader" = 0x100;
53-
54-
/// Enables the `wgpu_ray_query` extension, native only.
55-
const WGPU_RAY_QUERY, "wgpu_ray_query" = 0x200;
56-
57-
/// Enables the `wgpu_ray_query_vertex_return` extension, native only.
58-
const WGPU_RAY_QUERY_VERTEX_RETURN, "wgpu_ray_query_vertex_return" = 0x400;
59-
}
60-
}
61-
62-
impl EnableExtensions {
63-
pub const IMPLEMENTED: Self =
64-
Self::empty()
65-
.union(Self::WGPU_MESH_SHADER)
66-
.union(Self::WGPU_RAY_QUERY)
67-
.union(Self::WGPU_RAY_QUERY_VERTEX_RETURN)
68-
.union(Self::DUAL_SOURCE_BLENDING)
69-
.union(Self::F16)
70-
.union(Self::CLIP_DISTANCES);
71-
72-
pub const UNIMPLEMENTED: Self = Self::IMPLEMENTED.complement();
73-
74-
pub fn tracking_issue_num(self) -> Option<u16> {
75-
match self {
76-
Self::SUBGROUPS => Some(5555),
77-
Self::PRIMITIVE_INDEX => Some(8236),
78-
other => {
79-
assert!(Self::IMPLEMENTED.contains(other));
80-
None
81-
}
82-
}
83-
}
84-
}

naga/src/front/wgsl/parse/directive/language_extension.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,3 @@
22
//!
33
//! The focal point of this module is the [`LanguageExtension`] API.
44
5-
define_extensions! {
6-
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
7-
///
8-
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
9-
#[derive(Default)]
10-
pub struct LanguageExtensions: u32 {
11-
const READONLY_AND_READWRITE_STORAGE_TEXTURES, "readonly_and_readwrite_storage_textures" = 0x1;
12-
const PACKED4X8_INTEGER_DOT_PRODUCT, "packed_4x8_integer_dot_product" = 0x2;
13-
const UNRESTRICTED_POINTER_PARAMETERS, "unrestricted_pointer_parameters" = 0x4;
14-
const POINTER_COMPOSITE_ACCESS, "pointer_composite_access" = 0x8;
15-
}
16-
}
17-
18-
impl LanguageExtensions {
19-
pub const IMPLEMENTED: Self =
20-
Self::empty()
21-
.union(Self::READONLY_AND_READWRITE_STORAGE_TEXTURES)
22-
.union(Self::PACKED4X8_INTEGER_DOT_PRODUCT)
23-
.union(Self::POINTER_COMPOSITE_ACCESS);
24-
25-
pub const UNIMPLEMENTED: Self = Self::IMPLEMENTED.complement();
26-
27-
pub(crate) const fn tracking_issue_num(self) -> Option<u16> {
28-
match self {
29-
Self::UNRESTRICTED_POINTER_PARAMETERS => Some(5158),
30-
other => {
31-
assert!(Self::IMPLEMENTED.contains(other));
32-
None
33-
}
34-
}
35-
}
36-
}

naga/src/front/wgsl/parse/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{number::consume_number, Error, ExpectedToken, Result};
22
use crate::front::wgsl::error::NumberError;
3-
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
3+
use crate::front::wgsl::parse::directive::EnableExtensions;
44
use crate::front::wgsl::parse::{conv, Number};
55
use crate::front::wgsl::Scalar;
66
use crate::Span;

naga/src/front/wgsl/parse/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use alloc::{boxed::Box, vec::Vec};
2-
use directive::language_extension::LanguageExtensions;
2+
use directive::{EnableExtensions, LanguageExtensions};
33

44
use crate::diagnostic_filter::{
55
self, DiagnosticFilter, DiagnosticFilterMap, DiagnosticFilterNode, FilterableTriggeringRule,
66
ShouldConflictOnFullDuplicate, StandardFilterableTriggeringRule,
77
};
88
use crate::front::wgsl::error::{DiagnosticAttributeNotSupportedPosition, Error, ExpectedToken};
9-
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
109
use crate::front::wgsl::parse::directive::DirectiveKind;
1110
use crate::front::wgsl::parse::lexer::{Lexer, Token};
1211
use crate::front::wgsl::parse::number::Number;

naga/src/front/wgsl/parse/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::format;
22

33
use crate::front::wgsl::error::NumberError;
4-
use crate::front::wgsl::parse::directive::enable_extension::EnableExtensions;
4+
use crate::front::wgsl::parse::directive::EnableExtensions;
55
use crate::front::wgsl::parse::lexer::Token;
66
use half::f16;
77

0 commit comments

Comments
 (0)