diff --git a/config/log.toml b/config/log.toml index 77f557f..893e4a0 100644 --- a/config/log.toml +++ b/config/log.toml @@ -1 +1,2 @@ -input = false \ No newline at end of file +input = false +vulkan_validation_layers = true \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 5fd7f6f..a1e03b8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,7 +4,8 @@ use std::fs; #[derive(Debug, Serialize, Deserialize)] pub struct LogConfig { - pub input: bool + pub input: bool, + pub vulkan_validation_layers: bool, } impl LogConfig { diff --git a/src/main.rs b/src/main.rs index a803a82..f8ccbf2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,6 +99,10 @@ impl Game for TestGame { _ => {} } } + + fn validation_layers_enabled(self: &Self) -> bool { + self.log_config.vulkan_validation_layers + } } fn main() { diff --git a/src/vulkan.rs b/src/vulkan.rs index e04579a..6906f38 100644 --- a/src/vulkan.rs +++ b/src/vulkan.rs @@ -41,11 +41,6 @@ const VALIDATION_LAYERS: &[&str] = &[ "VK_LAYER_LUNARG_standard_validation" ]; -#[cfg(all(debug_assertions))] -const ENABLE_VALIDATION_LAYERS: bool = true; -#[cfg(not(debug_assertions))] -const ENABLE_VALIDATION_LAYERS: bool = false; - #[derive(Default, Debug, Clone)] pub struct Vertex { pub position: [f32; 3], @@ -61,6 +56,8 @@ pub struct LinePoint { vulkano::impl_vertex!(LinePoint, position); pub trait Game { + fn validation_layers_enabled(self: &Self) -> bool; + fn update(self: &mut Self, game_data: &mut GameData); /// Returns true if event should be ignored by the vulkan handler @@ -98,7 +95,7 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) dimensions: [0, 0] }; - if ENABLE_VALIDATION_LAYERS { + if game.validation_layers_enabled() { println!("Enabling validation layers..."); } @@ -115,7 +112,7 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) engine_version: Some(Version { major: 0, minor: 1, patch: 0 }) }; - if ENABLE_VALIDATION_LAYERS { + if game.validation_layers_enabled() { let available_layers = vulkano::instance::layers_list().unwrap().map(|layer| String::from(layer.name())).collect::>(); VALIDATION_LAYERS.iter().for_each(|wanted_layer_name| { @@ -132,7 +129,7 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) // lifetime of this is important, even tho it isn't used! let mut _debug_callback = None; - if ENABLE_VALIDATION_LAYERS { + if game.validation_layers_enabled() { let msg_types = MessageTypes { error: true, warning: true,