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
#[cfg(feature = "rafx-metal")]
use crate::metal::RafxBufferMetal;
#[cfg(feature = "rafx-vulkan")]
use crate::vulkan::RafxBufferVulkan;
use crate::{RafxBufferDef, RafxResult};
#[derive(Debug)]
pub enum RafxBuffer {
#[cfg(feature = "rafx-vulkan")]
Vk(RafxBufferVulkan),
#[cfg(feature = "rafx-metal")]
Metal(RafxBufferMetal),
}
impl RafxBuffer {
pub fn copy_to_host_visible_buffer<T: Copy>(
&self,
data: &[T],
) -> RafxResult<()> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => inner.copy_to_host_visible_buffer(data),
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => unimplemented!(),
}
}
pub fn copy_to_host_visible_buffer_with_offset<T: Copy>(
&self,
data: &[T],
buffer_byte_offset: u64,
) -> RafxResult<()> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => {
inner.copy_to_host_visible_buffer_with_offset(data, buffer_byte_offset)
}
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => unimplemented!(),
}
}
pub fn buffer_def(&self) -> &RafxBufferDef {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => inner.buffer_def(),
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => unimplemented!(),
}
}
pub fn map_buffer(&self) -> RafxResult<*mut u8> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => inner.map_buffer(),
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => unimplemented!(),
}
}
pub fn unmap_buffer(&self) -> RafxResult<()> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => inner.unmap_buffer(),
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => unimplemented!(),
}
}
#[cfg(feature = "rafx-vulkan")]
pub fn vk_buffer(&self) -> Option<&RafxBufferVulkan> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(inner) => Some(inner),
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(_inner) => None,
}
}
#[cfg(feature = "rafx-metal")]
pub fn metal_buffer(&self) -> Option<&RafxBufferMetal> {
match self {
#[cfg(feature = "rafx-vulkan")]
RafxBuffer::Vk(_inner) => None,
#[cfg(feature = "rafx-metal")]
RafxBuffer::Metal(inner) => Some(inner),
}
}
}