Skip to content

Commit

Permalink
Merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sectopod committed Aug 10, 2016
1 parent d6e01b4 commit 9e21c41
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 50 deletions.
4 changes: 0 additions & 4 deletions examples/performance/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ impl GFX {
}
}

fn duration_to_f64(dur: Duration) -> f64 {
dur.as_secs() as f64 + dur.subsec_nanos() as f64 / 1000_000_000.0
}

impl Renderer for GFX {
fn render(&mut self, proj_view: &Matrix4<f32>) {
let start = Instant::now();
Expand Down
2 changes: 1 addition & 1 deletion src/backend/vulkan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ vk = "0.0"
vk-sys = { path = "../../../../vulkano/vk-sys" }
shared_library = "0.1"
winit = "0.5"
gfx_core = { path = "../../core", version = "0.3" }
gfx_core = { path = "../../core", version = "0.4" }
125 changes: 84 additions & 41 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ extern crate gfx_device_dx11;
#[cfg(target_os = "windows")]
extern crate gfx_window_dxgi;

#[cfg(feature = "vulkan")]
extern crate gfx_device_vulkan;
#[cfg(feature = "vulkan")]
extern crate gfx_window_vulkan;

#[cfg(target_os = "macos")]
extern crate gfx_device_metal;
#[cfg(target_os = "macos")]
extern crate gfx_window_metal;

#[cfg(feature = "vulkan")]
extern crate gfx_device_vulkan;
#[cfg(feature = "vulkan")]
extern crate gfx_window_vulkan;

pub mod shade;


Expand Down Expand Up @@ -175,17 +175,6 @@ pub trait ApplicationGL {
fn launch(&str, Config);
}

#[cfg(target_os = "macos")]
pub trait ApplicationMetal {
fn launch(&str, Config);
}

#[cfg(target_os = "windows")]
pub trait ApplicationD3D11 {
fn launch(&str, Config);
}


impl Factory<gfx_device_gl::Resources> for gfx_device_gl::Factory {
type CommandBuffer = gfx_device_gl::CommandBuffer;
fn create_encoder(&mut self) -> gfx::Encoder<gfx_device_gl::Resources, Self::CommandBuffer> {
Expand All @@ -210,10 +199,9 @@ impl<A> ApplicationGL for A where
.with_dimensions(config.size.0 as u32, config.size.1 as u32)
.with_gl(gl_version)
.with_vsync();
let (window, mut device, mut factory, main_color, main_depth) =
let (window, mut device, factory, main_color, main_depth) =
gfx_window_glutin::init::<ColorFormat, DepthFormat>(builder);
let (width, height) = window.get_inner_size().unwrap();
let combuf = factory.create_command_buffer();
let shade_lang = device.get_info().shading_language;

let mut app = Self::new(factory, Init {
Expand Down Expand Up @@ -246,6 +234,58 @@ impl<A> ApplicationGL for A where
}
}


#[cfg(target_os = "windows")]
pub trait ApplicationD3D11 {
fn launch(&str, Config);
}

#[cfg(target_os = "windows")]
impl Factory<gfx_device_dx11::Resources> for gfx_device_dx11::Factory {
type CommandBuffer = D3D11CommandBuffer;
fn create_encoder(&mut self) -> gfx::Encoder<gfx_device_dx11::Resources, Self::CommandBuffer> {
self.create_command_buffer_native().into()
}
}

#[cfg(target_os = "windows")]
impl<
A: ApplicationBase<gfx_device_dx11::Resources, D3D11CommandBuffer>
> ApplicationD3D11 for A {
fn launch(title: &str, config: Config) {
use gfx::traits::{Device, Factory};

env_logger::init().unwrap();
let (window, device, factory, main_color) =
gfx_window_dxgi::init::<ColorFormat>(title, config.size.0, config.size.1)
.unwrap();
let main_depth = factory.create_depth_stencil_view_only(
window.size.0, window.size.1).unwrap();

let mut app = Self::new(factory, Init {
backend: shade::Backend::Hlsl(device.get_shader_model()),
color: main_color,
depth: main_depth,
aspect_ratio: window.size.0 as f32 / window.size.1 as f32,
});
let mut device: gfx_device_dx11::Deferred = device.into();

let mut harness = Harness::new();
while window.dispatch() {
app.render(&mut device);
window.swap_buffers(1);
device.cleanup();
harness.bump();
}
}
}


#[cfg(target_os = "macos")]
pub trait ApplicationMetal {
fn launch(&str, Config);
}

#[cfg(target_os = "macos")]
impl Factory<gfx_device_metal::Resources> for gfx_device_metal::Factory {
type CommandBuffer = gfx_device_meta::CommandBuffer;
Expand Down Expand Up @@ -297,42 +337,45 @@ impl<
}
}

#[cfg(target_os = "windows")]
impl Factory<gfx_device_dx11::Resources> for gfx_device_dx11::Factory {
type CommandBuffer = D3D11CommandBuffer;
fn create_encoder(&mut self) -> gfx::Encoder<gfx_device_dx11::Resources, Self::CommandBuffer> {
self.create_command_buffer_native().into()

#[cfg(feature = "vulkan")]
pub trait ApplicationVulkan {
fn launch(&str, Config);
}

#[cfg(feature = "vulkan")]
impl Factory<gfx_device_vulkan::Resources> for gfx_device_vulkan::Factory {
type CommandBuffer = gfx_device_vulkan::CommandBuffer;
fn create_encoder(&mut self) -> gfx::Encoder<gfx_device_vulkan::Resources, Self::CommandBuffer> {
self.create_command_buffer().into()
}
}

#[cfg(target_os = "windows")]
#[cfg(feature = "vulkan")]
impl<
A: ApplicationBase<gfx_device_dx11::Resources, D3D11CommandBuffer>
> ApplicationD3D11 for A {
A: ApplicationBase<gfx_device_vulkan::Resources, gfx_device_vulkan::CommandBuffer>
> ApplicationVulkan for A {
fn launch(title: &str, config: Config) {
use gfx::traits::{Device, Factory};

env_logger::init().unwrap();
let (window, device, factory, main_color) =
gfx_window_dxgi::init::<ColorFormat>(title, config.size.0, config.size.1)
.unwrap();
let main_depth = factory.create_depth_stencil_view_only(
window.size.0, window.size.1).unwrap();
let (mut win, mut factory) = gfx_window_vulkan::init_xcb::<ColorFormat>(title, config.size.0 as u32, config.size.1 as u32);
let main_depth = factory.create_depth_stencil::<DepthFormat>(config.size.0, config.size.1).unwrap();

let mut app = Self::new(factory, Init {
backend: shade::Backend::Hlsl(device.get_shader_model()),
color: main_color,
depth: main_depth,
aspect_ratio: window.size.0 as f32 / window.size.1 as f32,
backend: shade::Backend::Vulkan,
color: win.get_any_target(),
depth: main_depth.2,
aspect_ratio: config.size.0 as f32 / config.size.1 as f32, //TODO
});
let mut device: gfx_device_dx11::Deferred = device.into();

let mut harness = Harness::new();
while window.dispatch() {
app.render(&mut device);
window.swap_buffers(1);
device.cleanup();
harness.bump();
while let Ok(frame_opt) = win.wait_draw() {
if let Some(mut frame) = frame_opt {
app.render(frame.get_queue());
frame.get_queue().cleanup();
harness.bump();
}
}
}
}
3 changes: 2 additions & 1 deletion src/render/src/macros/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ macro_rules! gfx_impl_struct {

impl $crate::pso::buffer::Structure<$runtime_format> for $root {
fn query(name: &str) -> Option<$crate::pso::buffer::Element<$runtime_format>> {
use std::mem::size_of;
use $crate::pso::buffer::{Element, ElemOffset};
let tmp: &$root = unsafe{ ::std::mem::uninitialized() };
let base = tmp as *const _ as usize;
Expand All @@ -42,7 +43,7 @@ macro_rules! gfx_impl_struct {
Some(s) if s.starts_with('.') => &s[1..],
_ => name,
};
(sub_name, array_id * (stride as ElemOffset))
(sub_name, array_id * (size_of::<$root>() as ElemOffset))
},
None => (name, 0),
}
Expand Down
4 changes: 2 additions & 2 deletions src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'a> Source<'a> {
Source { glsl_es_100: s, .. } if s != EMPTY && v >= 100 => s,
Source { glsl_es_200: s, .. } if s != EMPTY && v >= 200 => s,
Source { glsl_es_300: s, .. } if s != EMPTY && v >= 300 => s,
_ => return Err(())
_ => return Err(SelectError(backend))
}
},
#[cfg(target_os = "windows")]
Expand All @@ -115,7 +115,7 @@ impl<'a> Source<'a> {
Backend::Msl(revision) => match *self {
Source { msl_11: s, .. } if s != EMPTY && revision >= 11 => s,
Source { msl_10: s, .. } if s != EMPTY && revision >= 10 => s,
_ => return Err(())
_ => return Err(SelectError(backend))
},
#[cfg(feature = "vulkan")]
Backend::Vulkan => match *self {
Expand Down
2 changes: 1 addition & 1 deletion src/window/vulkan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ name = "gfx_window_vulkan"
winit = "0.5"
xcb = "0.7"
vk-sys = { path = "../../../../vulkano/vk-sys" }
gfx_core = { path = "../../core", version = "0.3" }
gfx_core = { path = "../../core", version = "0.4" }
gfx_device_vulkan = { path = "../../backend/vulkan", version = "0.1" }

0 comments on commit 9e21c41

Please sign in to comment.