Add support for dx12

This commit is contained in:
msiglreith 2017-12-26 19:45:31 +01:00
parent d15b5fa59f
commit 458568cad2
4 changed files with 58 additions and 25 deletions

View file

@ -6,6 +6,11 @@ authors = ["Dzmitry Malyshau <kvark@mozilla.com>"]
[lib]
name = "portability_gfx"
[features]
default = []
dx12 = ["gfx-backend-dx12"]
vulkan = ["gfx-backend-vulkan"]
[dependencies]
lazy_static = "1.0"
@ -17,3 +22,9 @@ branch = "portable"
git = "https://github.com/gfx-rs/gfx"
branch = "portable"
features = ["portable"]
optional = true
[target.'cfg(windows)'.dependencies.gfx-backend-dx12]
git = "https://github.com/gfx-rs/gfx"
branch = "portable"
optional = true

View file

@ -156,7 +156,7 @@ pub extern fn gfxCreateDevice(
(family, vec![1.0; info.queueCount as usize])
}).collect::<Vec<_>>();
let gpu = adapter.physical_device.clone().open(request_infos);
let gpu = adapter.physical_device.open(request_infos);
unsafe { *pDevice = Handle::new(gpu) };
VkResult::VK_SUCCESS
@ -1348,3 +1348,40 @@ extern "C" {
discardRectangleCount: u32,
pDiscardRectangles: *const VkRect2D);
}
pub fn gfxCreateWin32SurfaceKHR(
instance: VkInstance,
pCreateInfos: *const VkWin32SurfaceCreateInfoKHR,
pAllocator: *const VkAllocationCallbacks,
pSurface: *mut VkSurfaceKHR,
) -> VkResult {
#[cfg(all(feature = "vulkan", target_os = "windows"))]
{
unsafe {
assert_eq!((*pCreateInfos).flags, 0);
assert!(pAllocator.is_null());
*pSurface = Handle::new(
instance.create_surface_from_hwnd(
(*pCreateInfos).hinstance,
(*pCreateInfos).hwnd,
)
);
VkResult::VK_SUCCESS
}
}
#[cfg(feature = "dx12")]
{
unsafe {
assert_eq!((*pCreateInfos).flags, 0);
assert!(pAllocator.is_null());
*pSurface = Handle::new(
instance.create_surface_from_hwnd(
(*pCreateInfos).hwnd,
)
);
VkResult::VK_SUCCESS
}
}
#[cfg(not(target_os = "windows"))]
unreachable!()
}

View file

@ -4,7 +4,11 @@
#![allow(improper_ctypes)] //TEMP: buggy Rustc FFI analysis
extern crate gfx_hal as hal;
#[cfg(feature = "dx12")]
extern crate gfx_backend_dx12 as back;
#[cfg(feature = "vulkan")]
extern crate gfx_backend_vulkan as back;
#[macro_use]
extern crate lazy_static;
@ -4806,30 +4810,6 @@ pub struct VkWin32SurfaceCreateInfoKHR {
impl Clone for VkWin32SurfaceCreateInfoKHR {
fn clone(&self) -> Self { *self }
}
pub fn gfxCreateWin32SurfaceKHR(
instance: VkInstance,
pCreateInfos: *const VkWin32SurfaceCreateInfoKHR,
pAllocator: *const VkAllocationCallbacks,
pSurface: *mut VkSurfaceKHR,
) -> VkResult {
#[cfg(target_os = "windows")]
{
unsafe {
assert_eq!((*pCreateInfos).flags, 0);
assert!(pAllocator.is_null());
// TODO: handle HINSTANCE
*pSurface = Handle::new(
instance.create_surface_from_hwnd(
(*pCreateInfos).hinstance,
(*pCreateInfos).hwnd,
)
);
VkResult::VK_SUCCESS
}
}
#[cfg(not(target_os = "windows"))]
unreachable!()
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct VkPhysicalDeviceFeatures2KHR {

View file

@ -7,5 +7,10 @@ authors = ["Dzmitry Malyshau <kvark@mozilla.com>"]
name = "portability"
crate-type = ["staticlib"]
[features]
default = []
dx12 = ["portability-gfx/dx12"]
vulkan = ["portability-gfx/vulkan"]
[dependencies]
portability-gfx = { path = "../libportability-gfx" }