-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathall.rs
More file actions
36 lines (31 loc) · 1.02 KB
/
all.rs
File metadata and controls
36 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// build-pass
#![feature(repr_simd)]
use core::num::NonZeroUsize;
use spirv_std::spirv;
use spirv_std::{scalar::Scalar, vector::Vector, vector::VectorOrScalar};
/// HACK(shesp). Rust doesn't allow us to declare regular (tuple-)structs containing `bool` members
/// as `#[repl(simd)]`. But we need this for `spirv_std::arch::any()` and `spirv_std::arch::all()`
/// to work.
/// Fortunately, this requirement isn't checked on generic structs, so we have a way to work around
/// it (for now at least)
#[repr(simd)]
#[derive(Copy, Clone, Debug)]
struct Vec2<T>(T, T);
unsafe impl<T: Scalar> VectorOrScalar for Vec2<T> {
type Scalar = T;
const DIM: NonZeroUsize = match NonZeroUsize::new(2) {
None => panic!(),
Some(n) => n,
};
}
unsafe impl<T: Scalar> Vector<T, 2> for Vec2<T> {}
impl<T: Scalar> Default for Vec2<T> {
fn default() -> Vec2<T> {
Vec2(T::default(), T::default())
}
}
#[spirv(fragment)]
pub fn main() {
let vector = Vec2(true, true);
assert!(spirv_std::arch::all(vector));
}