Skip to content

Commit

Permalink
Fix Spirv Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Feb 5, 2025
1 parent 60def99 commit c13c5ab
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions naga/src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,10 @@ impl Writer {
..
}
| crate::TypeInner::Scalar(crate::Scalar::F16) => {
self.require_any("16 bit floating-point", &[spirv::Capability::Float16])?;
self.require_any(
"16 bit floating-point",
&[spirv::Capability::Float16, spirv::Capability::Float16Buffer],
"16 bit floating-point in buffers",
&[spirv::Capability::Float16Buffer],
)?;
self.use_extension("SPV_KHR_16bit_storage");
}
Expand Down
1 change: 1 addition & 0 deletions naga/tests/out/spv/f16.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
; Bound: 159
OpCapability Shader
OpCapability Float16
OpCapability Float16Buffer
OpCapability StorageBuffer16BitAccess
OpCapability UniformAndStorageBuffer16BitAccess
OpCapability StorageInputOutput16
Expand Down
8 changes: 8 additions & 0 deletions naga/tests/spirv_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,11 @@ fn int64() {
"#,
);
}

#[test]
fn float16() {
require(
&[Ca::Float16, Ca::Float16Buffer],
"enable f16; fn f(x: f16) { }",
);
}
3 changes: 2 additions & 1 deletion naga/tests/wgsl_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,8 @@ fn float16_in_push_constant() {
"enable f16; var<push_constant> input: f16;",
"enable f16; var<push_constant> input: vec2<f16>;",
"enable f16; var<push_constant> input: mat4x4<f16>;",
"enable f16; struct S { a: f16 }; var<push_constant> input: S;":
"enable f16; struct S { a: f16 }; var<push_constant> input: S;",
"enable f16; struct S1 { a: f16 }; struct S2 { a : S1 } var<push_constant> input: S2;":
Err(naga::valid::ValidationError::GlobalVariable {
source: naga::valid::GlobalVariableError::InvalidPushConstantType(
naga::valid::PushConstantError::InvalidScalar(
Expand Down

0 comments on commit c13c5ab

Please sign in to comment.