Skip to content

Commit 7e02135

Browse files
Firestar99eddyb
authored andcommitted
abi layout: limit vectors to at most 4 components, as spec states
1 parent 94c26ff commit 7e02135

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -973,15 +973,18 @@ fn trans_intrinsic_type<'tcx>(
973973
}
974974
IntrinsicType::Matrix => {
975975
let span = span_for_spirv_type_adt(cx, ty).unwrap();
976-
let (element, count) =
977-
trans_glam_like_struct(cx, span, ty, args, "`#[spirv(matrix)]`")?;
976+
let err_attr_name = "`#[spirv(matrix)]`";
977+
let (element, count) = trans_glam_like_struct(cx, span, ty, args, err_attr_name)?;
978978
match cx.lookup_type(element) {
979979
SpirvType::Vector { .. } => (),
980980
ty => {
981981
return Err(cx
982982
.tcx
983983
.dcx()
984-
.struct_span_err(span, "`#[spirv(matrix)]` type fields must all be vectors")
984+
.struct_span_err(
985+
span,
986+
format!("{err_attr_name} type fields must all be vectors"),
987+
)
985988
.with_note(format!("field type is {}", ty.debug(element, cx)))
986989
.emit());
987990
}
@@ -990,8 +993,8 @@ fn trans_intrinsic_type<'tcx>(
990993
}
991994
IntrinsicType::Vector => {
992995
let span = span_for_spirv_type_adt(cx, ty).unwrap();
993-
let (element, count) =
994-
trans_glam_like_struct(cx, span, ty, args, "`#[spirv(vector)]`")?;
996+
let err_attr_name = "`#[spirv(vector)]`";
997+
let (element, count) = trans_glam_like_struct(cx, span, ty, args, err_attr_name)?;
995998
match cx.lookup_type(element) {
996999
SpirvType::Bool | SpirvType::Float { .. } | SpirvType::Integer { .. } => (),
9971000
ty => {
@@ -1000,7 +1003,9 @@ fn trans_intrinsic_type<'tcx>(
10001003
.dcx()
10011004
.struct_span_err(
10021005
span,
1003-
"`#[spirv(vector)]` type fields must all be floats, integers or bools",
1006+
format!(
1007+
"{err_attr_name} type fields must all be floats, integers or bools"
1008+
),
10041009
)
10051010
.with_note(format!("field type is {}", ty.debug(element, cx)))
10061011
.emit());
@@ -1048,18 +1053,16 @@ fn trans_glam_like_struct<'tcx>(
10481053
let element_word = element.spirv_type(span, cx);
10491054
let count = u32::try_from(count)
10501055
.ok()
1051-
.filter(|count| *count >= 2)
1056+
.filter(|count| 2 <= *count && *count <= 4)
10521057
.ok_or_else(|| {
1053-
tcx.dcx().span_err(
1054-
span,
1055-
format!("{err_attr_name} must have at least 2 members"),
1056-
)
1058+
tcx.dcx()
1059+
.span_err(span, format!("{err_attr_name} must have 2, 3 or 4 members"))
10571060
})?;
10581061

10591062
Ok((element_word, count))
10601063
} else {
10611064
Err(tcx
10621065
.dcx()
1063-
.span_err(span, "#[spirv(vector)] type must be a struct"))
1066+
.span_err(span, format!("{err_attr_name} type must be a struct")))
10641067
}
10651068
}

tests/compiletests/ui/spirv-attr/invalid-matrix-type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `#[spirv(matrix)]` must have at least 2 members
1+
error: `#[spirv(matrix)]` must have 2, 3 or 4 members
22
--> $DIR/invalid-matrix-type.rs:7:1
33
|
44
7 | pub struct _FewerFields {

0 commit comments

Comments
 (0)