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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use std::mem;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[repr(u8)]
pub enum Usage {
Data,
Dynamic,
Upload,
Download,
}
bitflags!(
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub flags Access: u8 {
const READ = 0x1,
const WRITE = 0x2,
const RW = 0x3,
}
);
bitflags!(
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
pub flags Bind: u8 {
const RENDER_TARGET = 0x1,
const DEPTH_STENCIL = 0x2,
const SHADER_RESOURCE = 0x4,
const UNORDERED_ACCESS = 0x8,
const TRANSFER_SRC = 0x10,
const TRANSFER_DST = 0x20,
}
);
impl Bind {
pub fn is_mutable(&self) -> bool {
let mutable = TRANSFER_DST | UNORDERED_ACCESS | RENDER_TARGET | DEPTH_STENCIL;
self.intersects(mutable)
}
}
#[doc(hidden)]
pub trait Typed: Sized {
type Raw;
fn new(raw: Self::Raw) -> Self;
fn raw(&self) -> &Self::Raw;
}
pub unsafe trait Pod {}
macro_rules! impl_pod {
( ty = $($ty:ty)* ) => { $( unsafe impl Pod for $ty {} )* };
( ar = $($tt:expr)* ) => { $( unsafe impl<T: Pod> Pod for [T; $tt] {} )* };
}
impl_pod! { ty = isize usize i8 u8 i16 u16 i32 u32 i64 u64 f32 f64 }
impl_pod! { ar =
0 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
}
unsafe impl<T: Pod, U: Pod> Pod for (T, U) {}
pub fn cast_slice<A: Pod, B: Pod>(slice: &[A]) -> &[B] {
use std::slice;
let raw_len = mem::size_of::<A>().wrapping_mul(slice.len());
let len = raw_len / mem::size_of::<B>();
assert_eq!(raw_len, mem::size_of::<B>().wrapping_mul(len));
unsafe {
slice::from_raw_parts(slice.as_ptr() as *const B, len)
}
}