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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
#[macro_export]
macro_rules! vk_bitflags_wrapped {
($ name : ident , $ flag_type : ty) => {
impl Default for $name {
fn default() -> Self {
Self(0)
}
}
impl $name {
#[inline]
pub const fn empty() -> Self {
Self(0)
}
#[inline]
pub const fn from_raw(x: $flag_type) -> Self {
Self(x)
}
#[inline]
pub const fn as_raw(self) -> $flag_type {
self.0
}
#[inline]
pub const fn is_empty(self) -> bool {
self.0 == Self::empty().0
}
#[inline]
pub const fn intersects(self, other: Self) -> bool {
!Self(self.0 & other.0).is_empty()
}
#[doc = r" Returns whether `other` is a subset of `self`"]
#[inline]
pub const fn contains(self, other: Self) -> bool {
self.0 & other.0 == other.0
}
}
impl ::std::ops::BitOr for $name {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
impl ::std::ops::BitOrAssign for $name {
#[inline]
fn bitor_assign(&mut self, rhs: Self) {
*self = *self | rhs
}
}
impl ::std::ops::BitAnd for $name {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self {
Self(self.0 & rhs.0)
}
}
impl ::std::ops::BitAndAssign for $name {
#[inline]
fn bitand_assign(&mut self, rhs: Self) {
*self = *self & rhs
}
}
impl ::std::ops::BitXor for $name {
type Output = Self;
#[inline]
fn bitxor(self, rhs: Self) -> Self {
Self(self.0 ^ rhs.0)
}
}
impl ::std::ops::BitXorAssign for $name {
#[inline]
fn bitxor_assign(&mut self, rhs: Self) {
*self = *self ^ rhs
}
}
impl ::std::ops::Not for $name {
type Output = Self;
#[inline]
fn not(self) -> Self {
Self(!self.0)
}
}
};
}
#[macro_export]
macro_rules! handle_nondispatchable {
($ name : ident , $ ty : ident) => {
handle_nondispatchable!($name, $ty, doc = "");
};
($ name : ident , $ ty : ident , $ doc_link : meta) => {
#[repr(transparent)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default)]
#[$doc_link]
pub struct $name(u64);
impl Handle for $name {
const TYPE: ObjectType = ObjectType::$ty;
fn as_raw(self) -> u64 {
self.0
}
fn from_raw(x: u64) -> Self {
Self(x)
}
}
impl $name {
pub const fn null() -> Self {
Self(0)
}
}
impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:x}", self.0)
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "0x{:x}", self.0)
}
}
};
}
#[macro_export]
macro_rules! define_handle {
($ name : ident , $ ty : ident) => {
define_handle!($name, $ty, doc = "");
};
($ name : ident , $ ty : ident , $ doc_link : meta) => {
#[repr(transparent)]
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash)]
#[$doc_link]
pub struct $name(*mut u8);
impl Default for $name {
fn default() -> Self {
Self::null()
}
}
impl Handle for $name {
const TYPE: ObjectType = ObjectType::$ty;
fn as_raw(self) -> u64 {
self.0 as u64
}
fn from_raw(x: u64) -> Self {
Self(x as _)
}
}
unsafe impl Send for $name {}
unsafe impl Sync for $name {}
impl $name {
pub const fn null() -> Self {
Self(::std::ptr::null_mut())
}
}
impl fmt::Pointer for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Pointer::fmt(&self.0, f)
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}
};
}
|