From 915c60e9c3adbc46023f190ee9c0f4bcc7c6b914 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Wed, 11 Oct 2023 10:53:35 +0200 Subject: [PATCH] Allow overriding validation and debug flags via an env var --- wgpu-core/src/instance.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 90126f15ee3..690cd0868c8 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -71,8 +71,24 @@ pub struct Instance { impl Instance { pub fn new(name: &str, instance_desc: wgt::InstanceDescriptor) -> Self { + fn env(key: &str) -> Option { + std::env::var(key).ok().map(|s| { + match s.as_str() { + "0" => false, + _ => true, + } + }) + } fn init(_: A, instance_desc: &wgt::InstanceDescriptor) -> Option { 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,