1 #[macro_use] 2 extern crate bitflags; 3 4 use std::ffi::CStr; 5 use winapi::{ 6 shared::dxgiformat, 7 um::{d3d12, d3dcommon}, 8 }; 9 10 mod com; 11 mod command_allocator; 12 mod command_list; 13 mod debug; 14 mod descriptor; 15 mod device; 16 mod dxgi; 17 mod heap; 18 mod pso; 19 mod query; 20 mod queue; 21 mod resource; 22 mod sync; 23 24 pub use crate::com::*; 25 pub use crate::command_allocator::*; 26 pub use crate::command_list::*; 27 pub use crate::debug::*; 28 pub use crate::descriptor::*; 29 pub use crate::device::*; 30 pub use crate::dxgi::*; 31 pub use crate::heap::*; 32 pub use crate::pso::*; 33 pub use crate::query::*; 34 pub use crate::queue::*; 35 pub use crate::resource::*; 36 pub use crate::sync::*; 37 38 pub use winapi::shared::winerror::HRESULT; 39 40 pub type D3DResult<T> = (T, HRESULT); 41 pub type GpuAddress = d3d12::D3D12_GPU_VIRTUAL_ADDRESS; 42 pub type Format = dxgiformat::DXGI_FORMAT; 43 pub type Rect = d3d12::D3D12_RECT; 44 pub type NodeMask = u32; 45 46 /// Index into the root signature. 47 pub type RootIndex = u32; 48 /// Draw vertex count. 49 pub type VertexCount = u32; 50 /// Draw vertex base offset. 51 pub type VertexOffset = i32; 52 /// Draw number of indices. 53 pub type IndexCount = u32; 54 /// Draw number of instances. 55 pub type InstanceCount = u32; 56 /// Number of work groups. 57 pub type WorkGroupCount = [u32; 3]; 58 59 pub type TextureAddressMode = [d3d12::D3D12_TEXTURE_ADDRESS_MODE; 3]; 60 61 pub struct SampleDesc { 62 pub count: u32, 63 pub quality: u32, 64 } 65 66 #[repr(u32)] 67 pub enum FeatureLevel { 68 L9_1 = d3dcommon::D3D_FEATURE_LEVEL_9_1, 69 L9_2 = d3dcommon::D3D_FEATURE_LEVEL_9_2, 70 L9_3 = d3dcommon::D3D_FEATURE_LEVEL_9_3, 71 L10_0 = d3dcommon::D3D_FEATURE_LEVEL_10_0, 72 L10_1 = d3dcommon::D3D_FEATURE_LEVEL_10_1, 73 L11_0 = d3dcommon::D3D_FEATURE_LEVEL_11_0, 74 L11_1 = d3dcommon::D3D_FEATURE_LEVEL_11_1, 75 L12_0 = d3dcommon::D3D_FEATURE_LEVEL_12_0, 76 L12_1 = d3dcommon::D3D_FEATURE_LEVEL_12_1, 77 } 78 79 pub type Blob = WeakPtr<d3dcommon::ID3DBlob>; 80 81 pub type Error = WeakPtr<d3dcommon::ID3DBlob>; 82 impl Error { as_c_str(&self) -> &CStr83 pub unsafe fn as_c_str(&self) -> &CStr { 84 debug_assert!(!self.is_null()); 85 let data = self.GetBufferPointer(); 86 CStr::from_ptr(data as *const _ as *const _) 87 } 88 } 89 90 #[cfg(feature = "libloading")] 91 #[derive(Debug)] 92 pub struct D3D12Lib { 93 lib: libloading::Library, 94 } 95 96 #[cfg(feature = "libloading")] 97 impl D3D12Lib { new() -> Result<Self, libloading::Error>98 pub fn new() -> Result<Self, libloading::Error> { 99 unsafe { libloading::Library::new("d3d12.dll").map(|lib| D3D12Lib { lib }) } 100 } 101 } 102