Skip to content

Commit

Permalink
Easier Rendy initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakarum committed Nov 3, 2019
1 parent 8b56900 commit bebb733
Show file tree
Hide file tree
Showing 27 changed files with 1,170 additions and 842 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"descriptor",
"factory",
"frame",
"init",
"memory",
"mesh",
"rendy",
Expand Down
6 changes: 3 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pipeline {
steps {
withCredentials([string(credentialsId: 'codecov_token', variable: 'CODECOV_TOKEN')]) {
echo 'Building to calculate coverage'
sh 'cd rendy && cargo test --all --features "full vulkan"'
sh 'cd rendy && cargo test --all --all-features'
echo 'Calculating code coverage...'
sh 'for file in target/debug/rendy*[^\\.d]; do mkdir -p \"target/cov/$(basename $file)\"; kcov --exclude-pattern=/.cargo,/usr/lib --verify \"target/cov/$(basename $file)\" \"$file\" || true; done'
echo "Uploading coverage..."
Expand All @@ -59,7 +59,7 @@ pipeline {
echo 'Beginning tests...'
// TODO: Once we support DX12, we should switch to it from vulkan for windows
// FIXME: Can't test "full" because of problems with shaderc compilation on windows box
bat 'cd rendy && C:\\Users\\root\\.cargo\\bin\\cargo test --all --no-default-features --features "base mesh-obj texture-image texture-palette spirv-reflection serde-1 vulkan"'
bat 'cd rendy && C:\\Users\\root\\.cargo\\bin\\cargo test --all --no-default-features --features "base mesh-obj texture-image texture-palette spirv-reflection serde-1 dx12 gl vulkan"'
echo 'Tests done!'
}
}
Expand All @@ -73,7 +73,7 @@ pipeline {
}
steps {
echo 'Beginning tests...'
sh 'cd rendy && /Users/jenkins/.cargo/bin/cargo test --all --features "full metal"'
sh 'cd rendy && /Users/jenkins/.cargo/bin/cargo test --all --all-features'
echo 'Tests done!'
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ifeq ($(OS),Windows_NT)
else
UNAME_S:=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
RENDY_BACKEND=vulkan-x11
RENDY_BACKEND=vulkan
endif
ifeq ($(UNAME_S),Darwin)
RENDY_BACKEND=metal
Expand Down
5 changes: 2 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ dx12 = ["gfx-backend-dx12"]
metal = ["gfx-backend-metal"]
gl = ["gfx-backend-gl"]
vulkan = ["gfx-backend-vulkan"]
vulkan-x11 = ["gfx-backend-vulkan/x11"]
no-slow-safety-checks = []

[dependencies]
gfx-hal = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b" }
gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", optional = true }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", optional = true }
gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", features = ["glutin"], optional = true }
derivative = "1.0"
lazy_static = "1.0"
log = "0.4"
Expand All @@ -45,4 +44,4 @@ gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e82
gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", optional = true }

[target.'cfg(all(any(target_os = "windows", all(unix, not(any(target_os = "macos", target_os = "ios")))), not(target_arch = "wasm32")))'.dependencies]
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", optional = true }
gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "46386475f7e823e807ec984c372ffe04dcc0a22b", features = ["x11"], optional = true }
174 changes: 80 additions & 94 deletions core/src/backend.rs

Large diffs are not rendered by default.

49 changes: 8 additions & 41 deletions core/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,56 @@ macro_rules! rendy_without_dx12_backend {

/// Resolve into input AST if empty backend is enabled.
#[macro_export]
#[cfg(feature = "gfx-backend-empty")]
#[cfg(feature = "empty")]
macro_rules! rendy_with_empty_backend {
($($tt:tt)*) => { $($tt)* };
}

/// Resolve into input AST if empty backend is enabled.
#[macro_export]
#[cfg(not(feature = "gfx-backend-empty"))]
#[cfg(not(feature = "empty"))]
macro_rules! rendy_with_empty_backend {
($($tt:tt)*) => {};
}

/// Resolve into input AST if empty backend is disabled.
#[macro_export]
#[cfg(not(feature = "gfx-backend-empty"))]
#[cfg(not(feature = "empty"))]
macro_rules! rendy_without_empty_backend {
($($tt:tt)*) => { $($tt)* };
}

/// Resolve into input AST if empty backend is disabled.
#[macro_export]
#[cfg(feature = "gfx-backend-empty")]
#[cfg(feature = "empty")]
macro_rules! rendy_without_empty_backend {
($($tt:tt)*) => {};
}

/// Resolve into input AST if gl backend is enabled.
#[macro_export]
#[cfg(feature = "gfx-backend-gl")]
#[cfg(feature = "gl")]
macro_rules! rendy_with_gl_backend {
($($tt:tt)*) => { $($tt)* };
}

/// Resolve into input AST if gl backend is enabled.
#[macro_export]
#[cfg(not(feature = "gfx-backend-gl"))]
#[cfg(not(feature = "gl"))]
macro_rules! rendy_with_gl_backend {
($($tt:tt)*) => {};
}

/// Resolve into input AST if gl backend is disabled.
#[macro_export]
#[cfg(not(feature = "gfx-backend-gl"))]
#[cfg(not(feature = "gl"))]
macro_rules! rendy_without_gl_backend {
($($tt:tt)*) => { $($tt)* };
}

/// Resolve into input AST if gl backend is disabled.
#[macro_export]
#[cfg(feature = "gfx-backend-gl")]
#[cfg(feature = "gl")]
macro_rules! rendy_without_gl_backend {
($($tt:tt)*) => {};
}
Expand Down Expand Up @@ -265,36 +265,3 @@ macro_rules! rendy_with_slow_safety_checks {
macro_rules! rendy_with_slow_safety_checks {
($($tt:tt)*) => {};
}

/// Execute arm with matching backend.
/// If particular backend is disabled
/// then its arm is stripped from compilation altogether.
#[macro_export]
macro_rules! rendy_backend_match {
($target:path {
$(empty => $empty_code:block)?
$(dx12 => $dx12_code:block)?
$(metal => $metal_code:block)?
$(vulkan => $vulkan_code:block)?
}) => {{
$($crate::rendy_with_empty_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::empty::Backend>() { return $empty_code; }))?;
$($crate::rendy_with_dx12_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::dx12::Backend>() { return $dx12_code; }))?;
$($crate::rendy_with_metal_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::metal::Backend>() { return $metal_code; }))?;
$($crate::rendy_with_vulkan_backend!(if std::any::TypeId::of::<$target>() == std::any::TypeId::of::<$crate::vulkan::Backend>() { return $vulkan_code; }))?;

panic!("
Undefined backend requested.
Make sure feature for required backend is enabled.
Try to add `--features=vulkan` or if on macos `--features=metal`.
")
}};

($target:path as $back:ident => $code:block) => {{
$crate::rendy_backend_match!($target {
empty => { use $crate::empty as $back; $code }
dx12 => { use $crate::dx12 as $back; $code }
metal => { use $crate::metal as $back; $code }
vulkan => { use $crate::vulkan as $back; $code }
});
}};
}
5 changes: 1 addition & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ pub use gfx_hal as hal;
#[doc(inline)]
pub use gfx_backend_dx12 as dx12;

#[cfg(all(
feature = "gl",
all(target_os = "windows", not(target_arch = "wasm32"))
))]
#[cfg(feature = "gl")]
#[doc(inline)]
pub use gfx_backend_gl as gl;

Expand Down
1 change: 0 additions & 1 deletion core/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//!
//! Types shared across rendy
//!
#[doc(inline)]
pub mod vertex;

/// Set layout
Expand Down
20 changes: 15 additions & 5 deletions core/src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ where
instance,
}
}
}

impl<B> Instance<B>
where
B: Backend,
{
/// Wrap instance value.
pub unsafe fn from_raw(instance: B::Instance, id: InstanceId) -> Self {
Instance { id, instance }
}

/// Get instance id.
pub fn id(&self) -> InstanceId {
self.id
Expand All @@ -104,6 +104,11 @@ where
pub fn raw_mut(&mut self) -> &mut B::Instance {
&mut self.instance
}

/// Get inner raw instance
pub fn into_raw(self) -> B::Instance {
self.instance
}
}

impl<B> Deref for Instance<B>
Expand Down Expand Up @@ -191,6 +196,11 @@ where
pub fn raw_mut(&mut self) -> &mut B::Device {
&mut self.device
}

/// Get inner raw device
pub fn into_raw(self) -> B::Device {
self.device
}
}

impl<B> Deref for Device<B>
Expand Down
1 change: 0 additions & 1 deletion factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ empty = ["rendy-core/empty"]
dx12 = ["rendy-core/dx12"]
gl = ["rendy-core/gl"]
metal = ["rendy-core/metal"]
vulkan = ["rendy-core/vulkan"]
no-slow-safety-checks = ["rendy-core/no-slow-safety-checks"]
profiler = ["thread_profiler/thread_profiler"]

Expand Down
2 changes: 1 addition & 1 deletion factory/src/barriers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
command::Encoder,
resource::{Handle, Image},
},
rendy_core::hal::{self, buffer, image, memory::Barrier, pso, Backend},
rendy_core::hal::{buffer, image, memory::Barrier, pso, Backend},
std::ops::Range,
};

Expand Down
18 changes: 9 additions & 9 deletions factory/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub unsafe trait QueuesConfigure {

/// Configure.
fn configure(
self,
&self,
device: DeviceId,
families: &[impl rendy_core::hal::queue::QueueFamily],
) -> Self::Families;
Expand All @@ -73,7 +73,7 @@ unsafe impl QueuesConfigure for OneGraphicsQueue {
type Priorities = [f32; 1];
type Families = Option<(FamilyId, [f32; 1])>;
fn configure(
self,
&self,
device: DeviceId,
families: &[impl rendy_core::hal::queue::QueueFamily],
) -> Option<(FamilyId, [f32; 1])> {
Expand Down Expand Up @@ -103,14 +103,14 @@ unsafe impl QueuesConfigure for SavedQueueConfig {
type Priorities = Vec<f32>;
type Families = Vec<(FamilyId, Vec<f32>)>;
fn configure(
self,
&self,
device: DeviceId,
_: &[impl rendy_core::hal::queue::QueueFamily],
) -> Vec<(FamilyId, Vec<f32>)> {
// TODO: FamilyId should be stored directly once it become serializable.
self.0
.into_iter()
.map(|(id, vec)| (FamilyId { device, index: id }, vec))
.iter()
.map(|(id, vec)| (FamilyId { device, index: *id }, vec.clone()))
.collect()
}
}
Expand All @@ -131,7 +131,7 @@ pub unsafe trait HeapsConfigure {

/// Configure.
fn configure(
self,
&self,
properties: &rendy_core::hal::adapter::MemoryProperties,
) -> (Self::Types, Self::Heaps);
}
Expand All @@ -153,7 +153,7 @@ unsafe impl HeapsConfigure for BasicHeapsConfigure {
type Heaps = Vec<u64>;

fn configure(
self,
&self,
properties: &rendy_core::hal::adapter::MemoryProperties,
) -> (Self::Types, Self::Heaps) {
let _1mb = 1024 * 1024;
Expand Down Expand Up @@ -213,10 +213,10 @@ unsafe impl HeapsConfigure for SavedHeapsConfig {
type Heaps = Vec<u64>;

fn configure(
self,
&self,
_properties: &rendy_core::hal::adapter::MemoryProperties,
) -> (Self::Types, Self::Heaps) {
(self.types, self.heaps)
(self.types.clone(), self.heaps.clone())
}
}

Expand Down
Loading

0 comments on commit bebb733

Please sign in to comment.