fix(naga wgsl-in): Add checks for wgpu_cooperative_matrix extension

This commit is contained in:
Andy Leiserson authored and Teodor Tanasoaia committed 2026-01-19 10:38:47 +01:00
1 parent b1bdabda53
commit b40c01a018
4 files changed
+106 -20

No files matched your search

+44 -20
View File
@@ -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)
+1
View File
@@ -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,
}
}
@@ -1,3 +1,5 @@
enable wgpu_cooperative_matrix;
// type declarations with different roles
var<private> a: coop_mat8x8<f32, A>;
var<private> b: coop_mat8x8<f32, B>;
+59
View File
@@ -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}<f32, A>;
}}
"#
),
&format!(
r#"error: the `wgpu_cooperative_matrix` enable extension is not enabled
┌─ wgsl:2:12
│
2 │ var a: {ty}<f32, A>;
│ {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}<f32, A>();
}}
"#,
),
&format!(
r#"error: the `wgpu_cooperative_matrix` enable extension is not enabled
┌─ wgsl:2:13
│
2 │ let a = {ty}<f32, A>();
│ {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),
..
})
);
}
}