Skip to content

Commit

Permalink
Allow overriding validation and debug flags via an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
nical committed Oct 11, 2023
1 parent 29562ee commit 915c60e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,24 @@ pub struct Instance {

impl Instance {
pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self {
fn env(key: &str) -> Option<bool> {
std::env::var(key).ok().map(|s| {
match s.as_str() {
"0" => false,
_ => true,
}
})
}
fn init<A: HalApi>(_: A, instance_desc: &wgt::InstanceDescriptor) -> Option<A::Instance> {
if instance_desc.backends.contains(A::VARIANT.into()) {
let mut flags = instance_desc.flags;
if let Some(bit) = env("WGPU_VALIDATION") {
flags.set(wgt::InstanceFlags::VALIDATION, bit);
}
if let Some(bit) = env("WGPU_DEBUG") {
flags.set(wgt::InstanceFlags::DEBUG, bit);
}

let hal_desc = hal::InstanceDescriptor {
name: "wgpu",
flags: instance_desc.flags,
Expand Down

0 comments on commit 915c60e

Please sign in to comment.