Skip to content

Commit e77ed1c

Browse files
committed
abi layout: glam::BVec support
1 parent 8bec6c0 commit e77ed1c

File tree

7 files changed

+9
-81
lines changed

7 files changed

+9
-81
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ fn trans_intrinsic_type<'tcx>(
984984
let (element, count) =
985985
trans_glam_like_struct(cx, span, ty, args, "`#[spirv(vector)]`")?;
986986
match cx.lookup_type(element) {
987+
SpirvType::Bool => (),
987988
SpirvType::Float { .. } => (),
988989
SpirvType::Integer { .. } => (),
989990
ty => {
@@ -992,7 +993,7 @@ fn trans_intrinsic_type<'tcx>(
992993
.dcx()
993994
.struct_span_err(
994995
span,
995-
"`#[spirv(vector)]` type fields must all be floats or integers",
996+
"`#[spirv(vector)]` type fields must all be floats, integers or bools",
996997
)
997998
.with_note(format!("field type is {}", ty.debug(element, cx)))
998999
.emit());

crates/spirv-std/src/vector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl_vector! {
4949
f64: glam::DVec2 => 2, glam::DVec3 => 3, glam::DVec4 => 4;
5050
u32: glam::UVec2 => 2, glam::UVec3 => 3, glam::UVec4 => 4;
5151
i32: glam::IVec2 => 2, glam::IVec3 => 3, glam::IVec4 => 4;
52+
bool: glam::BVec2 => 2, glam::BVec3 => 3, glam::BVec4 => 4;
5253
}
5354

5455
/// Trait that implements slicing of a vector into a scalar or vector of lower dimensions, by

tests/compiletests/ui/arch/all.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
11
// build-pass
22

3-
#![feature(repr_simd)]
4-
53
use core::num::NonZeroUsize;
64
use spirv_std::spirv;
75
use spirv_std::{scalar::Scalar, vector::Vector, vector::VectorOrScalar};
86

9-
/// HACK(shesp). Rust doesn't allow us to declare regular (tuple-)structs containing `bool` members
10-
/// as `#[repl(simd)]`. But we need this for `spirv_std::arch::any()` and `spirv_std::arch::all()`
11-
/// to work.
12-
/// Fortunately, this requirement isn't checked on generic structs, so we have a way to work around
13-
/// it (for now at least)
14-
#[repr(simd)]
15-
#[derive(Copy, Clone, Debug)]
16-
struct Vec2<T>(T, T);
17-
unsafe impl<T: Scalar> VectorOrScalar for Vec2<T> {
18-
type Scalar = T;
19-
const DIM: NonZeroUsize = match NonZeroUsize::new(2) {
20-
None => panic!(),
21-
Some(n) => n,
22-
};
23-
}
24-
unsafe impl<T: Scalar> Vector<T, 2> for Vec2<T> {}
25-
26-
impl<T: Scalar> Default for Vec2<T> {
27-
fn default() -> Vec2<T> {
28-
Vec2(T::default(), T::default())
29-
}
30-
}
31-
327
#[spirv(fragment)]
338
pub fn main() {
34-
let vector = Vec2(true, true);
9+
let vector = glam::BVec2::new(true, true);
3510
assert!(spirv_std::arch::all(vector));
3611
}

tests/compiletests/ui/arch/all.stderr

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/compiletests/ui/arch/any.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
11
// build-pass
22

3-
#![feature(repr_simd)]
4-
53
use core::num::NonZeroUsize;
64
use spirv_std::spirv;
75
use spirv_std::{scalar::Scalar, vector::Vector, vector::VectorOrScalar};
86

9-
/// HACK(shesp). Rust doesn't allow us to declare regular (tuple-)structs containing `bool` members
10-
/// as `#[repl(simd)]`. But we need this for `spirv_std::arch::any()` and `spirv_std::arch::all()`
11-
/// to work.
12-
/// Fortunately, this requirement isn't checked on generic structs, so we have a way to work around
13-
/// it (for now at least)
14-
#[repr(simd)]
15-
#[derive(Copy, Clone, Debug)]
16-
struct Vec2<T>(T, T);
17-
unsafe impl<T: Scalar> VectorOrScalar for Vec2<T> {
18-
type Scalar = T;
19-
const DIM: NonZeroUsize = match NonZeroUsize::new(2) {
20-
None => panic!(),
21-
Some(n) => n,
22-
};
23-
}
24-
unsafe impl<T: Scalar> Vector<T, 2> for Vec2<T> {}
25-
26-
impl<T: Scalar> Default for Vec2<T> {
27-
fn default() -> Vec2<T> {
28-
Vec2(T::default(), T::default())
29-
}
30-
}
31-
327
#[spirv(fragment)]
338
pub fn main() {
34-
let vector = Vec2(false, true);
9+
let vector = glam::BVec2::new(false, true);
3510
assert!(spirv_std::arch::any(vector));
3611
}

tests/compiletests/ui/arch/any.stderr

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/compiletests/ui/arch/debug_printf_type_checking.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ error[E0277]: the trait bound `{float}: Vector<f32, 2>` is not satisfied
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Vector<f32, 2>` is not implemented for `{float}`
122122
|
123123
= help: the following other types implement trait `Vector<T, N>`:
124+
`BVec2` implements `Vector<bool, 2>`
125+
`BVec3` implements `Vector<bool, 3>`
126+
`BVec4` implements `Vector<bool, 4>`
124127
`DVec2` implements `Vector<f64, 2>`
125128
`DVec3` implements `Vector<f64, 3>`
126129
`DVec4` implements `Vector<f64, 4>`
127130
`IVec2` implements `Vector<i32, 2>`
128131
`IVec3` implements `Vector<i32, 3>`
129-
`IVec4` implements `Vector<i32, 4>`
130-
`UVec2` implements `Vector<u32, 2>`
131-
`UVec3` implements `Vector<u32, 3>`
132-
and 5 others
132+
and 8 others
133133
note: required by a bound in `debug_printf_assert_is_vector`
134134
--> $SPIRV_STD_SRC/lib.rs:140:8
135135
|

0 commit comments

Comments
 (0)