Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay configuration flag for the graphics context #91

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 4 additions & 0 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
19 changes: 6 additions & 13 deletions blade-graphics/src/vulkan/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -240,13 +238,16 @@ impl super::Context {
.collect::<Vec<_>>();

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);
Expand All @@ -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
};

Expand Down
3 changes: 2 additions & 1 deletion examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ impl Example {
gpu::Context::init_windowed(
window,
gpu::ContextDesc {
validation: cfg!(debug_assertions),
validation: false,
capture: false,
overlay: true,
},
)
.unwrap()
Expand Down
8 changes: 1 addition & 7 deletions examples/init/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(irrefutable_let_patterns)]

use std::{env, path::Path, ptr, sync::Arc};

Check warning on line 3 in examples/init/main.rs

View workflow job for this annotation

GitHub Actions / build (MacOS, macos-latest, x86_64-apple-darwin)

unused import: `ptr`

use blade_graphics as gpu;

Expand Down Expand Up @@ -132,13 +132,7 @@
let mut rd = renderdoc::RenderDoc::<renderdoc::V120>::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 {
Expand Down
8 changes: 1 addition & 7 deletions examples/mini/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Globals as gpu::ShaderData>::layout();
let shader_source = std::fs::read_to_string("examples/mini/shader.wgsl").unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/particle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl Example {
gpu::ContextDesc {
validation: cfg!(debug_assertions),
capture: false,
overlay: false,
},
)
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions examples/ray-query/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Example {
gpu::ContextDesc {
validation: cfg!(debug_assertions),
capture: false,
overlay: false,
},
)
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ impl Example {
gpu::ContextDesc {
validation: cfg!(debug_assertions),
capture: false,
overlay: false,
},
)
.unwrap()
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ impl Engine {
gpu::ContextDesc {
validation: cfg!(debug_assertions),
capture: false,
overlay: false,
},
)
.unwrap()
Expand Down
Loading