Skip to content

Commit a15afa0

Browse files
WumpfErichDonGubler
authored andcommitted
add parse (!) error for enable feature flag
1 parent 42e630c commit a15afa0

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ impl EnableExtensions {
2525
}
2626

2727
/// Query whether an enable-extension tracked here has been requested.
28-
#[allow(unused)]
2928
pub(crate) const fn contains(&self, ext: ImplementedEnableExtension) -> bool {
3029
match ext {
3130
ImplementedEnableExtension::DualSourceBlending => self.dual_source_blending,
@@ -49,6 +48,12 @@ pub enum EnableExtension {
4948
Unimplemented(UnimplementedEnableExtension),
5049
}
5150

51+
impl From<ImplementedEnableExtension> for EnableExtension {
52+
fn from(value: ImplementedEnableExtension) -> Self {
53+
Self::Implemented(value)
54+
}
55+
}
56+
5257
impl EnableExtension {
5358
const F16: &'static str = "f16";
5459
const CLIP_DISTANCES: &'static str = "clip_distances";

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ pub(in crate::front::wgsl) struct Lexer<'a> {
218218
/// statements.
219219
last_end_offset: usize,
220220

221-
#[allow(dead_code)]
222221
pub(in crate::front::wgsl) enable_extensions: EnableExtensions,
223222
}
224223

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use directive::enable_extension::ImplementedEnableExtension;
2+
13
use crate::diagnostic_filter::{
24
self, DiagnosticFilter, DiagnosticFilterMap, DiagnosticFilterNode, FilterableTriggeringRule,
35
ShouldConflictOnFullDuplicate, StandardFilterableTriggeringRule,
@@ -221,6 +223,16 @@ impl<'a> BindingParser<'a> {
221223
self.invariant.set(true, name_span)?;
222224
}
223225
"blend_src" => {
226+
if !lexer
227+
.enable_extensions
228+
.contains(ImplementedEnableExtension::DualSourceBlending)
229+
{
230+
return Err(Error::EnableExtensionNotEnabled {
231+
span: name_span,
232+
kind: ImplementedEnableExtension::DualSourceBlending.into(),
233+
});
234+
}
235+
224236
lexer.expect(Token::Paren('('))?;
225237
self.blend_src
226238
.set(parser.general_expression(lexer, ctx)?, name_span)?;

naga/src/valid/interface.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ impl VaryingContext<'_> {
319319
if let Some(blend_src) = blend_src {
320320
// `blend_src` is only valid if dual source blending was explicitly enabled,
321321
// see https://www.w3.org/TR/WGSL/#extension-dual_source_blending
322-
// TODO: check that dual source blending feature was enabled in the shader.
323322
if !self
324323
.capabilities
325324
.contains(Capabilities::DUAL_SOURCE_BLENDING)

naga/tests/wgsl_errors.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,19 +1345,23 @@ fn invalid_blend_src() {
13451345
}
13461346

13471347
// Missing enable directive.
1348-
// TODO:
1349-
// check_validation! {
1350-
// "
1351-
// struct FragmentOutput {
1352-
// @location(0) @blend_src(0) output0: vec4<f32>,
1353-
// @location(0) @blend_src(1) output1: vec4<f32>,
1354-
// }
1355-
// @fragment
1356-
// fn main(@builtin(position) position: vec4<f32>) -> FragmentOutput { return FragmentOutput(vec4(0.0), vec4(0.0)); }
1357-
// ":
1358-
// Err(???),
1359-
// Capabilities::DUAL_SOURCE_BLENDING
1360-
// }
1348+
// Note that this is a parsing error, not a validation error.
1349+
check("
1350+
struct FragmentOutput {
1351+
@location(0) @blend_src(0) output0: vec4<f32>,
1352+
@location(0) @blend_src(1) output1: vec4<f32>,
1353+
}
1354+
@fragment
1355+
fn main(@builtin(position) position: vec4<f32>) -> FragmentOutput { return FragmentOutput(vec4(0.0), vec4(0.0)); }
1356+
",
1357+
r###"error: `dual_source_blending` enable-extension is not enabled
1358+
┌─ wgsl:3:27
1359+
1360+
3 │ @location(0) @blend_src(0) output0: vec4<f32>,
1361+
│ ^^^^^^^^^ the `dual_source_blending` enable-extension is needed for this functionality, but it is not currently enabled
1362+
1363+
"###,
1364+
);
13611365

13621366
// Using blend_src on an input.
13631367
check_validation! {

0 commit comments

Comments
 (0)