diff --git a/Cargo.toml b/Cargo.toml index 5e6b53e92..9e054e3be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "d3d12-rs" +name = "d3d12" version = "0.1.0" authors = ["msiglreith "] [dependencies] bitflags = "1" -winapi = { version = "0.3", features = ["d3d12","d3dcommon","d3dcompiler","dxgiformat","winerror"] } +winapi = { version = "0.3", features = ["dxgi1_3","dxgi1_4","d3d12","d3d12sdklayers","d3dcommon","d3dcompiler","dxgiformat","winerror"] } diff --git a/src/debug.rs b/src/debug.rs new file mode 100644 index 000000000..450beeac7 --- /dev/null +++ b/src/debug.rs @@ -0,0 +1,21 @@ +use com::WeakPtr; +use winapi::um::{d3d12, d3d12sdklayers}; +use winapi::Interface; +use D3DResult; + +pub type Debug = WeakPtr; + +impl Debug { + pub fn get_debug_interface() -> D3DResult { + let mut debug = Debug::null(); + let hr = unsafe { + d3d12::D3D12GetDebugInterface(&d3d12sdklayers::ID3D12Debug::uuidof(), debug.mut_void()) + }; + + (debug, hr) + } + + pub fn enable_debug_layer(&self) { + unsafe { self.EnableDebugLayer() } + } +} diff --git a/src/dxgi.rs b/src/dxgi.rs new file mode 100644 index 000000000..22d0d7352 --- /dev/null +++ b/src/dxgi.rs @@ -0,0 +1,35 @@ +use com::WeakPtr; +use winapi::shared::{dxgi, dxgi1_3, dxgi1_4}; +use winapi::Interface; +use D3DResult; + +bitflags! { + pub struct FactoryCreationFlags: u32 { + const DEBUG = dxgi1_3::DXGI_CREATE_FACTORY_DEBUG; + } +} + +pub type Adapter1 = WeakPtr; +pub type Factory4 = WeakPtr; + +impl Factory4 { + pub fn create(flags: FactoryCreationFlags) -> D3DResult { + let mut factory = Factory4::null(); + let hr = unsafe { + dxgi1_3::CreateDXGIFactory2( + flags.bits(), + &dxgi1_4::IDXGIFactory4::uuidof(), + factory.mut_void(), + ) + }; + + (factory, hr) + } + + pub fn enumerate_adapters(&self, id: u32) -> D3DResult { + let mut adapter = Adapter1::null(); + let hr = unsafe { self.EnumAdapters1(id, adapter.mut_void() as *mut *mut _) }; + + (adapter, hr) + } +} diff --git a/src/lib.rs b/src/lib.rs index 036ff059e..5434912ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,10 @@ use winapi::um::{d3d12, d3dcommon}; mod com; pub mod command_allocator; pub mod command_list; +pub mod debug; pub mod descriptor; pub mod device; +pub mod dxgi; pub mod pso; pub mod query; pub mod queue; @@ -20,6 +22,7 @@ pub mod sync; pub use self::com::WeakPtr; pub use self::command_allocator::CommandAllocator; pub use self::command_list::{CommandSignature, GraphicsCommandList}; +pub use self::debug::Debug; pub use self::descriptor::{CpuDescriptor, DescriptorHeap, GpuDescriptor, RootSignature}; pub use self::device::Device; pub use self::pso::{CachedPSO, PipelineState, Shader};