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
|
//! GPU Resource
use crate::{com::ComPtr, D3DResult, Rect};
use std::{ops::Range, ptr};
use winapi::um::d3d12;
pub type Subresource = u32;
pub struct DiscardRegion<'a> {
pub rects: &'a [Rect],
pub subregions: Range<Subresource>,
}
pub type Resource = ComPtr<d3d12::ID3D12Resource>;
impl Resource {
///
pub fn map(
&self,
subresource: Subresource,
read_range: Option<Range<usize>>,
) -> D3DResult<*mut ()> {
let mut ptr = ptr::null_mut();
let read_range = read_range.map(|r| d3d12::D3D12_RANGE {
Begin: r.start,
End: r.end,
});
let read = match read_range {
Some(ref r) => r as *const _,
None => ptr::null(),
};
let hr = unsafe { self.Map(subresource, read, &mut ptr) };
(ptr as _, hr)
}
pub fn unmap(&self, subresource: Subresource, write_range: Option<Range<usize>>) {
let write_range = write_range.map(|r| d3d12::D3D12_RANGE {
Begin: r.start,
End: r.end,
});
let write = match write_range {
Some(ref r) => r as *const _,
None => ptr::null(),
};
unsafe { self.Unmap(subresource, write) };
}
pub fn gpu_virtual_address(&self) -> u64 {
unsafe { self.GetGPUVirtualAddress() }
}
}
|