From 84f64479a95c21c3c96bda8fc19e4e98bd43044d Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 2 Mar 2024 21:00:05 -0800 Subject: [PATCH] Overlay configuration flag for the graphics context --- blade-graphics/src/lib.rs | 7 ++++++- blade-graphics/src/metal/mod.rs | 4 ++++ blade-graphics/src/vulkan/init.rs | 19 ++++++------------- examples/bunnymark/main.rs | 3 ++- examples/init/main.rs | 8 +------- examples/mini/main.rs | 8 +------- examples/particle/main.rs | 1 + examples/ray-query/main.rs | 1 + examples/scene/main.rs | 1 + src/lib.rs | 1 + 10 files changed, 24 insertions(+), 29 deletions(-) diff --git a/blade-graphics/src/lib.rs b/blade-graphics/src/lib.rs index 39f620eb..865aec36 100644 --- a/blade-graphics/src/lib.rs +++ b/blade-graphics/src/lib.rs @@ -74,10 +74,15 @@ pub use hal::*; use std::{fmt, num::NonZeroU32}; -#[derive(Debug)] +#[derive(Clone, Debug, Default)] pub struct ContextDesc { + /// Enable validation of the GAPI, shaders, + /// and insert crash markers into command buffers. pub validation: bool, + /// Enable capture support with GAPI tools. pub capture: bool, + /// Enable GAPI overlay. + pub overlay: bool, } #[derive(Debug)] diff --git a/blade-graphics/src/metal/mod.rs b/blade-graphics/src/metal/mod.rs index 282be051..d53c8d7b 100644 --- a/blade-graphics/src/metal/mod.rs +++ b/blade-graphics/src/metal/mod.rs @@ -346,6 +346,10 @@ impl Context { if desc.validation { std::env::set_var("METAL_DEVICE_WRAPPER_TYPE", "1"); } + if desc.overlay { + std::env::set_var("MTL_HUD_ENABLED", "1"); + } + let device = metal::Device::system_default().ok_or(super::NotSupportedError)?; let queue = device.new_command_queue(); diff --git a/blade-graphics/src/vulkan/init.rs b/blade-graphics/src/vulkan/init.rs index 9481cb0d..352fbf67 100644 --- a/blade-graphics/src/vulkan/init.rs +++ b/blade-graphics/src/vulkan/init.rs @@ -5,8 +5,6 @@ use ash::{ use naga::back::spv; use std::{ffi, mem, sync::Mutex}; -const OPTIONAL_LAYERS: &[&[u8]] = &[]; - const REQUIRED_DEVICE_EXTENSIONS: &[&ffi::CStr] = &[ vk::ExtInlineUniformBlockFn::name(), vk::KhrTimelineSemaphoreFn::name(), @@ -240,13 +238,16 @@ impl super::Context { .collect::>(); let mut layers: Vec<&'static ffi::CStr> = Vec::new(); - let mut required_layers = Vec::new(); + let mut requested_layers = Vec::<&[u8]>::new(); if desc.validation { - required_layers.push(b"VK_LAYER_KHRONOS_validation\0"); + requested_layers.push(b"VK_LAYER_KHRONOS_validation\0"); + } + if desc.overlay { + requested_layers.push(b"VK_LAYER_MESA_overlay\0"); } - for required in required_layers { + for required in requested_layers { let name = ffi::CStr::from_bytes_with_nul(required).unwrap(); if supported_layer_names.contains(&name) { layers.push(name); @@ -255,14 +256,6 @@ impl super::Context { } } - for &optional in OPTIONAL_LAYERS { - let name = ffi::CStr::from_bytes_with_nul(optional).unwrap(); - if supported_layer_names.contains(&name) { - log::info!("Enabling optional layer: {:?}", name); - layers.push(name); - } - } - layers }; diff --git a/examples/bunnymark/main.rs b/examples/bunnymark/main.rs index ac203f79..4f9e77a0 100644 --- a/examples/bunnymark/main.rs +++ b/examples/bunnymark/main.rs @@ -57,8 +57,9 @@ impl Example { gpu::Context::init_windowed( window, gpu::ContextDesc { - validation: cfg!(debug_assertions), + validation: false, capture: false, + overlay: true, }, ) .unwrap() diff --git a/examples/init/main.rs b/examples/init/main.rs index 200a8d25..9aa151b6 100644 --- a/examples/init/main.rs +++ b/examples/init/main.rs @@ -132,13 +132,7 @@ fn main() { let mut rd = renderdoc::RenderDoc::::new(); println!("Initializing"); - let context = Arc::new(unsafe { - gpu::Context::init(gpu::ContextDesc { - validation: cfg!(debug_assertions), - capture: true, - }) - .unwrap() - }); + let context = Arc::new(unsafe { gpu::Context::init(gpu::ContextDesc::default()).unwrap() }); #[cfg(any(target_os = "windows", target_os = "linux"))] if let Ok(ref mut rd) = rd { diff --git a/examples/mini/main.rs b/examples/mini/main.rs index 8a8f3c07..047a5c0a 100644 --- a/examples/mini/main.rs +++ b/examples/mini/main.rs @@ -31,13 +31,7 @@ impl gpu::ShaderData for Globals { fn main() { env_logger::init(); - let context = unsafe { - gpu::Context::init(gpu::ContextDesc { - validation: true, - capture: true, - }) - .unwrap() - }; + let context = unsafe { gpu::Context::init(gpu::ContextDesc::default()).unwrap() }; let global_layout = ::layout(); let shader_source = std::fs::read_to_string("examples/mini/shader.wgsl").unwrap(); diff --git a/examples/particle/main.rs b/examples/particle/main.rs index b59cd05b..242a2ae3 100644 --- a/examples/particle/main.rs +++ b/examples/particle/main.rs @@ -21,6 +21,7 @@ impl Example { gpu::ContextDesc { validation: cfg!(debug_assertions), capture: false, + overlay: false, }, ) .unwrap() diff --git a/examples/ray-query/main.rs b/examples/ray-query/main.rs index 9fc09de4..4e7eabef 100644 --- a/examples/ray-query/main.rs +++ b/examples/ray-query/main.rs @@ -52,6 +52,7 @@ impl Example { gpu::ContextDesc { validation: cfg!(debug_assertions), capture: false, + overlay: false, }, ) .unwrap() diff --git a/examples/scene/main.rs b/examples/scene/main.rs index e7fee6a5..734a0dc1 100644 --- a/examples/scene/main.rs +++ b/examples/scene/main.rs @@ -176,6 +176,7 @@ impl Example { gpu::ContextDesc { validation: cfg!(debug_assertions), capture: false, + overlay: false, }, ) .unwrap() diff --git a/src/lib.rs b/src/lib.rs index acb2ecbc..e9217e08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -252,6 +252,7 @@ impl Engine { gpu::ContextDesc { validation: cfg!(debug_assertions), capture: false, + overlay: false, }, ) .unwrap()