Add debug interface, factory creation and adapter enumeration

This commit is contained in:
msiglreith 2018-09-02 14:11:18 +02:00
parent 4097a10997
commit 2aacc3b11b
4 changed files with 61 additions and 2 deletions

View File

@ -1,8 +1,8 @@
[package]
name = "d3d12-rs"
name = "d3d12"
version = "0.1.0"
authors = ["msiglreith <m.siglreith@gmail.com>"]
[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"] }

21
src/debug.rs Normal file
View File

@ -0,0 +1,21 @@
use com::WeakPtr;
use winapi::um::{d3d12, d3d12sdklayers};
use winapi::Interface;
use D3DResult;
pub type Debug = WeakPtr<d3d12sdklayers::ID3D12Debug>;
impl Debug {
pub fn get_debug_interface() -> D3DResult<Self> {
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() }
}
}

35
src/dxgi.rs Normal file
View File

@ -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<dxgi::IDXGIAdapter1>;
pub type Factory4 = WeakPtr<dxgi1_4::IDXGIFactory4>;
impl Factory4 {
pub fn create(flags: FactoryCreationFlags) -> D3DResult<Self> {
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<Adapter1> {
let mut adapter = Adapter1::null();
let hr = unsafe { self.EnumAdapters1(id, adapter.mut_void() as *mut *mut _) };
(adapter, hr)
}
}

View File

@ -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};