diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 932c49abd..159a79141 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -663,14 +663,26 @@ impl Parser { ty_span: Span::UNDEFINED, })) } - "coop_mat8x8" => ast::ConstructorType::PartialCooperativeMatrix { - columns: crate::CooperativeSize::Eight, - rows: crate::CooperativeSize::Eight, - }, - "coop_mat16x16" => ast::ConstructorType::PartialCooperativeMatrix { - columns: crate::CooperativeSize::Sixteen, - rows: crate::CooperativeSize::Sixteen, - }, + "coop_mat8x8" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuCooperativeMatrix, + span, + )?; + ast::ConstructorType::PartialCooperativeMatrix { + columns: crate::CooperativeSize::Eight, + rows: crate::CooperativeSize::Eight, + } + } + "coop_mat16x16" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuCooperativeMatrix, + span, + )?; + ast::ConstructorType::PartialCooperativeMatrix { + columns: crate::CooperativeSize::Sixteen, + rows: crate::CooperativeSize::Sixteen, + } + } "array" => ast::ConstructorType::PartialArray, "atomic" | "binding_array" @@ -1744,18 +1756,30 @@ impl Parser { ty: ctx.new_scalar(Scalar::F16), ty_span: Span::UNDEFINED, }, - "coop_mat8x8" => self.cooperative_matrix_with_type( - lexer, - ctx, - crate::CooperativeSize::Eight, - crate::CooperativeSize::Eight, - )?, - "coop_mat16x16" => self.cooperative_matrix_with_type( - lexer, - ctx, - crate::CooperativeSize::Sixteen, - crate::CooperativeSize::Sixteen, - )?, + "coop_mat8x8" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuCooperativeMatrix, + span, + )?; + self.cooperative_matrix_with_type( + lexer, + ctx, + crate::CooperativeSize::Eight, + crate::CooperativeSize::Eight, + )? + } + "coop_mat16x16" => { + lexer.require_enable_extension( + ImplementedEnableExtension::WgpuCooperativeMatrix, + span, + )?; + self.cooperative_matrix_with_type( + lexer, + ctx, + crate::CooperativeSize::Sixteen, + crate::CooperativeSize::Sixteen, + )? + } "atomic" => { let scalar = lexer.next_scalar_generic()?; ast::Type::Atomic(scalar) diff --git a/naga/src/valid/mod.rs b/naga/src/valid/mod.rs index 348d4c2d2..229dff45a 100644 --- a/naga/src/valid/mod.rs +++ b/naga/src/valid/mod.rs @@ -224,6 +224,7 @@ impl Capabilities { Self::MESH_SHADER => Some(Ext::WgpuMeshShader), Self::RAY_QUERY => Some(Ext::WgpuRayQuery), Self::RAY_HIT_VERTEX_POSITION => Some(Ext::WgpuRayQueryVertexReturn), + Self::COOPERATIVE_MATRIX => Some(Ext::WgpuCooperativeMatrix), _ => None, } } diff --git a/naga/tests/in/wgsl/cooperative-matrix.wgsl b/naga/tests/in/wgsl/cooperative-matrix.wgsl index 7352b7acd..ed5bfecdd 100644 --- a/naga/tests/in/wgsl/cooperative-matrix.wgsl +++ b/naga/tests/in/wgsl/cooperative-matrix.wgsl @@ -1,3 +1,5 @@ +enable wgpu_cooperative_matrix; + // type declarations with different roles var a: coop_mat8x8; var b: coop_mat8x8; diff --git a/naga/tests/naga/wgsl_errors.rs b/naga/tests/naga/wgsl_errors.rs index 96c4da2cd..9e3e8819f 100644 --- a/naga/tests/naga/wgsl_errors.rs +++ b/naga/tests/naga/wgsl_errors.rs @@ -4535,3 +4535,62 @@ fn binding_array_requires_capability() { Capabilities::all() } } + +#[test] +fn cooperative_matrix_enable_extension() { + for ty in ["coop_mat8x8", "coop_mat16x16"] { + let carets = "^".repeat(ty.len()); + + check_extension_validation!( + // Used in type declaration + Capabilities::COOPERATIVE_MATRIX, + &format!( + r#"fn foo() {{ + var a: {ty}; +}} +"# + ), + &format!( + r#"error: the `wgpu_cooperative_matrix` enable extension is not enabled + ┌─ wgsl:2:12 + │ +2 │ var a: {ty}; + │ {carets} the `wgpu_cooperative_matrix` "Enable Extension" is needed for this functionality, but it is not currently enabled. + │ + = note: You can enable this extension by adding `enable wgpu_cooperative_matrix;` at the top of the shader, before any other items. + +"#, + ), + Err(naga::valid::ValidationError::Type { + source: naga::valid::TypeError::MissingCapability(Capabilities::COOPERATIVE_MATRIX), + .. + }) + ); + + // Used as constructor + check_extension_validation!( + Capabilities::COOPERATIVE_MATRIX, + &format!( + r#"fn foo() {{ + let a = {ty}(); +}} +"#, + ), + &format!( + r#"error: the `wgpu_cooperative_matrix` enable extension is not enabled + ┌─ wgsl:2:13 + │ +2 │ let a = {ty}(); + │ {carets} the `wgpu_cooperative_matrix` "Enable Extension" is needed for this functionality, but it is not currently enabled. + │ + = note: You can enable this extension by adding `enable wgpu_cooperative_matrix;` at the top of the shader, before any other items. + +"#, + ), + Err(naga::valid::ValidationError::Type { + source: naga::valid::TypeError::MissingCapability(Capabilities::COOPERATIVE_MATRIX), + .. + }) + ); + } +}