mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
`D3D12_HEAP_TYPE, D3D12_CPU_PAGE_PROPERTY, D3D12_MEMORY_POOL, D3D12_HEAP_FLAGS, D3D12_HEAP_PROPERTIES, and D3D12_HEAP_DESC ID3D12Heap Wrap ID3D12Device::CreateHeap Made a tricky enum because DX12 doesn't follow Rust's rules bump version to 0.2.0 Use bitflags for heap::Flags Fix typo Another typo fix
88 lines
2.9 KiB
Rust
88 lines
2.9 KiB
Rust
use com::WeakPtr;
|
|
use winapi::um::d3d12;
|
|
|
|
pub type Heap = WeakPtr<d3d12::ID3D12Heap>;
|
|
|
|
#[repr(u32)]
|
|
#[derive(Clone, Copy)]
|
|
pub enum Type {
|
|
Default = d3d12::D3D12_HEAP_TYPE_DEFAULT,
|
|
Upload = d3d12::D3D12_HEAP_TYPE_UPLOAD,
|
|
Readback = d3d12::D3D12_HEAP_TYPE_READBACK,
|
|
Custom = d3d12::D3D12_HEAP_TYPE_CUSTOM,
|
|
}
|
|
|
|
#[repr(u32)]
|
|
#[derive(Clone, Copy)]
|
|
pub enum CpuPageProperty {
|
|
Unknown = d3d12::D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
|
|
NotAvailable = d3d12::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE,
|
|
WriteCombine = d3d12::D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE,
|
|
WriteBack= d3d12::D3D12_CPU_PAGE_PROPERTY_WRITE_BACK,
|
|
}
|
|
|
|
#[repr(u32)]
|
|
#[derive(Clone, Copy)]
|
|
pub enum MemoryPool {
|
|
Unknown = d3d12::D3D12_CPU_PAGE_PROPERTY_UNKNOWN,
|
|
L0 = d3d12::D3D12_MEMORY_POOL_L0,
|
|
L1 = d3d12::D3D12_MEMORY_POOL_L1,
|
|
}
|
|
|
|
bitflags! {
|
|
pub struct Flags: u32 {
|
|
const NONE = d3d12::D3D12_HEAP_FLAG_NONE;
|
|
const SHARED = d3d12::D3D12_HEAP_FLAG_SHARED;
|
|
const DENY_BUFFERS = d3d12::D3D12_HEAP_FLAG_DENY_BUFFERS;
|
|
const ALLOW_DISPLAY = d3d12::D3D12_HEAP_FLAG_ALLOW_DISPLAY;
|
|
const SHARED_CROSS_ADAPTER = d3d12::D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER;
|
|
const DENT_RT_DS_TEXTURES = d3d12::D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES;
|
|
const DENY_NON_RT_DS_TEXTURES = d3d12::D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES;
|
|
const HARDWARE_PROTECTED = d3d12::D3D12_HEAP_FLAG_HARDWARE_PROTECTED;
|
|
const ALLOW_WRITE_WATCH = d3d12::D3D12_HEAP_FLAG_ALLOW_WRITE_WATCH;
|
|
const ALLOW_ALL_BUFFERS_AND_TEXTURES = d3d12::D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES;
|
|
const ALLOW_ONLY_BUFFERS = d3d12::D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS;
|
|
const ALLOW_ONLY_NON_RT_DS_TEXTURES = d3d12::D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES;
|
|
const ALLOW_ONLY_RT_DS_TEXTURES = d3d12::D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES;
|
|
}
|
|
}
|
|
|
|
#[repr(transparent)]
|
|
pub struct Properties(pub d3d12::D3D12_HEAP_PROPERTIES);
|
|
impl Properties {
|
|
pub fn new(
|
|
heap_type: Type,
|
|
cpu_page_property: CpuPageProperty,
|
|
memory_pool_preference: MemoryPool,
|
|
creation_node_mask: u32,
|
|
visible_node_mask: u32,
|
|
) -> Self {
|
|
Properties(d3d12::D3D12_HEAP_PROPERTIES {
|
|
Type: heap_type as _,
|
|
CPUPageProperty: cpu_page_property as _,
|
|
MemoryPoolPreference: memory_pool_preference as _,
|
|
CreationNodeMask: creation_node_mask,
|
|
VisibleNodeMask: visible_node_mask,
|
|
})
|
|
}
|
|
}
|
|
|
|
#[repr(transparent)]
|
|
pub struct Desc(d3d12::D3D12_HEAP_DESC);
|
|
impl Desc{
|
|
pub fn new(
|
|
size_in_bytes: u64,
|
|
properties: Properties,
|
|
alignment: u64,
|
|
flags: Flags,
|
|
) -> Self {
|
|
Desc(d3d12::D3D12_HEAP_DESC{
|
|
SizeInBytes: size_in_bytes,
|
|
Properties: properties.0,
|
|
Alignment: alignment,
|
|
Flags: flags.bits(),
|
|
})
|
|
}
|
|
}
|
|
|