Skip to content

Commit 06fc6f7

Browse files
feat(wgsl): recognize enable primitive-index; (#8237)
1 parent d0bcb7e commit 06fc6f7

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ By @cwfitzgerald in [#8162](https://github.com/gfx-rs/wgpu/pull/8162).
166166

167167
- Added support for external textures based on WebGPU's [`GPUExternalTexture`](https://www.w3.org/TR/webgpu/#gpuexternaltexture). These allow shaders to transparently operate on potentially multiplanar source texture data in either RGB or YCbCr formats via WGSL's `texture_external` type. This is gated behind the `Features::EXTERNAL_TEXTURE` feature, which is currently only supported on DX12. By @jamienicol in [#4386](https://github.com/gfx-rs/wgpu/issues/4386).
168168

169+
#### naga
170+
171+
- Expose `naga::front::wgsl::UnimplementedEnableExtension`. By @ErichDonGubler in [#8237](https://github.com/gfx-rs/wgpu/pull/8237).
172+
169173
### Changes
170174

171175
#### General

naga/src/front/wgsl/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ mod parse;
1111
#[cfg(test)]
1212
mod tests;
1313

14-
pub use parse::directive::enable_extension::{EnableExtension, ImplementedEnableExtension};
14+
pub use parse::directive::enable_extension::{
15+
EnableExtension, ImplementedEnableExtension, UnimplementedEnableExtension,
16+
};
1517

1618
pub use crate::front::wgsl::error::ParseError;
1719
pub use crate::front::wgsl::parse::directive::language_extension::{

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl EnableExtension {
7171
const CLIP_DISTANCES: &'static str = "clip_distances";
7272
const DUAL_SOURCE_BLENDING: &'static str = "dual_source_blending";
7373
const SUBGROUPS: &'static str = "subgroups";
74+
const PRIMITIVE_INDEX: &'static str = "primitive_index";
7475

7576
/// Convert from a sentinel word in WGSL into its associated [`EnableExtension`], if possible.
7677
pub(crate) fn from_ident(word: &str, span: Span) -> Result<'_, Self> {
@@ -81,6 +82,9 @@ impl EnableExtension {
8182
Self::Implemented(ImplementedEnableExtension::DualSourceBlending)
8283
}
8384
Self::SUBGROUPS => Self::Unimplemented(UnimplementedEnableExtension::Subgroups),
85+
Self::PRIMITIVE_INDEX => {
86+
Self::Unimplemented(UnimplementedEnableExtension::PrimitiveIndex)
87+
}
8488
_ => return Err(Box::new(Error::UnknownEnableExtension(span, word))),
8589
})
8690
}
@@ -95,6 +99,7 @@ impl EnableExtension {
9599
},
96100
Self::Unimplemented(kind) => match kind {
97101
UnimplementedEnableExtension::Subgroups => Self::SUBGROUPS,
102+
UnimplementedEnableExtension::PrimitiveIndex => Self::PRIMITIVE_INDEX,
98103
},
99104
}
100105
}
@@ -132,12 +137,19 @@ pub enum UnimplementedEnableExtension {
132137
///
133138
/// [`enable subgroups;`]: https://www.w3.org/TR/WGSL/#extension-subgroups
134139
Subgroups,
140+
/// Enables the `@builtin(primitive_index)` attribute in WGSL.
141+
///
142+
/// In the WGSL standard, this corresponds to [`enable primitive-index;`].
143+
///
144+
/// [`enable primitive-index;`]: https://www.w3.org/TR/WGSL/#extension-primitive_index
145+
PrimitiveIndex,
135146
}
136147

137148
impl UnimplementedEnableExtension {
138149
pub(crate) const fn tracking_issue_num(self) -> u16 {
139150
match self {
140151
Self::Subgroups => 5555,
152+
Self::PrimitiveIndex => 8236,
141153
}
142154
}
143155
}

naga/tests/naga/wgsl_errors.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,6 +4098,46 @@ fn invalid_clip_distances() {
40984098
}
40994099
}
41004100

4101+
#[test]
4102+
fn recognized_but_unimplemented_enable_extension() {
4103+
for extension in [
4104+
naga::front::wgsl::UnimplementedEnableExtension::Subgroups,
4105+
naga::front::wgsl::UnimplementedEnableExtension::PrimitiveIndex,
4106+
] {
4107+
// NOTE: We match exhaustively here to help maintainers add or remove variants to the above
4108+
// array.
4109+
let snapshot = match extension {
4110+
naga::front::wgsl::UnimplementedEnableExtension::Subgroups => "\
4111+
error: the `subgroups` enable-extension is not yet supported
4112+
┌─ wgsl:1:8
4113+
4114+
1 │ enable subgroups;
4115+
│ ^^^^^^^^^ this enable-extension specifies standard functionality which is not yet implemented in Naga
4116+
4117+
= note: Let Naga maintainers know that you ran into this at <https://github.com/gfx-rs/wgpu/issues/5555>, so they can prioritize it!
4118+
4119+
",
4120+
naga::front::wgsl::UnimplementedEnableExtension::PrimitiveIndex => "\
4121+
error: the `primitive_index` enable-extension is not yet supported
4122+
┌─ wgsl:1:8
4123+
4124+
1 │ enable primitive_index;
4125+
│ ^^^^^^^^^^^^^^^ this enable-extension specifies standard functionality which is not yet implemented in Naga
4126+
4127+
= note: Let Naga maintainers know that you ran into this at <https://github.com/gfx-rs/wgpu/issues/8236>, so they can prioritize it!
4128+
4129+
",
4130+
};
4131+
4132+
let shader = {
4133+
let extension = naga::front::wgsl::EnableExtension::Unimplemented(extension);
4134+
format!("enable {};", extension.to_ident())
4135+
};
4136+
4137+
check(&shader, snapshot);
4138+
}
4139+
}
4140+
41014141
#[test]
41024142
fn max_type_size_large_array() {
41034143
// The total size of an array is not resolved until validation. Type aliases

0 commit comments

Comments
 (0)