diff --git a/README.md b/README.md index f3ac44aac..4a5cf7688 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Testing, examples, and `::from_env()` methods use a standardized set of environm See the [documentation](https://docs.rs/wgpu/latest/wgpu/index.html?search=env) for more environment variables. -When running the CTS, use the variables `DENO_WEBGPU_ADAPTER_NAME`, `DENO_WEBGPU_BACKEND`, `DENO_WEBGPU_POWER_PREFERENCE`. +When running the CTS, use the variables `DENO_WEBGPU_ADAPTER_NAME`, `DENO_WEBGPU_BACKEND`, `DENO_WEBGPU_POWER_PREFERENCE`, and `DENO_WEBGPU_DX12_COMPILER`. ## Repo Overview diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 87ec2d708..a841792a6 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -289,7 +289,7 @@ webgpu:api,validation,texture,destroy:twice:* webgpu:api,validation,texture,float32_filterable:create_bind_group:* webgpu:api,validation,texture,rg11b10ufloat_renderable:* -webgpu:shader,execution,expression,call,builtin,atan2:f16:* +fails-if(dx12) webgpu:shader,execution,expression,call,builtin,atan2:f16:* webgpu:shader,execution,expression,call,builtin,atan2:f32:* webgpu:shader,execution,expression,call,builtin,dot:abstract_int_vec2:* webgpu:shader,execution,expression,call,builtin,dot:abstract_int_vec3:* diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 958247f07..ad14c1335 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -171,6 +171,9 @@ impl GPU { ) -> Option { let mut state = state.borrow_mut(); + let dx12_compiler = std::env::var("DENO_WEBGPU_DX12_COMPILER") + .ok() + .and_then(|s| s.parse().ok()); let backends = std::env::var("DENO_WEBGPU_BACKEND").map_or_else( |_| wgpu_types::Backends::all(), |s| wgpu_types::Backends::from_comma_list(&s), @@ -189,7 +192,8 @@ impl GPU { }, backend_options: wgpu_types::BackendOptions { dx12: wgpu_types::Dx12BackendOptions { - shader_compiler: wgpu_types::Dx12Compiler::Fxc, + shader_compiler: dx12_compiler + .unwrap_or(wgpu_types::Dx12Compiler::Fxc), ..Default::default() }, gl: wgpu_types::GlBackendOptions::default(), diff --git a/wgpu-types/src/backend.rs b/wgpu-types/src/backend.rs index b1487b720..91d192549 100644 --- a/wgpu-types/src/backend.rs +++ b/wgpu-types/src/backend.rs @@ -1,7 +1,7 @@ //! [`Backend`], [`Backends`], and backend-specific options. use alloc::string::String; -use core::hash::Hash; +use core::{hash::Hash, str::FromStr}; #[cfg(any(feature = "serde", test))] use serde::{Deserialize, Serialize}; @@ -632,16 +632,13 @@ impl Dx12Compiler { /// - `StaticDxc` #[must_use] pub fn from_env() -> Option { - let value = crate::env::var("WGPU_DX12_COMPILER") - .as_deref()? - .to_lowercase(); - match value.as_str() { - "dxc" | "dynamicdxc" => Some(Self::default_dynamic_dxc()), - "staticdxc" => Some(Self::StaticDxc), - "fxc" => Some(Self::Fxc), - "auto" => Some(Self::Auto), - _ => None, - } + let env = crate::env::var("WGPU_DX12_COMPILER")?; + env.parse().map_err(|expected_msg| { + log::warn!( + "Unknown value `{env:?}` for `WGPU_DX12_COMPILER` environment variable. {expected_msg}" + ) + }) + .ok() } /// Takes the given compiler, modifies it based on the `WGPU_DX12_COMPILER` environment variable, and returns the result. @@ -657,6 +654,20 @@ impl Dx12Compiler { } } +impl FromStr for Dx12Compiler { + type Err = &'static str; + + fn from_str(value: &str) -> Result { + Ok(match value.to_lowercase().as_str() { + "dxc" | "dynamicdxc" => Self::default_dynamic_dxc(), + "staticdxc" => Self::StaticDxc, + "fxc" => Self::Fxc, + "auto" => Self::Auto, + _ => return Err("Expected `dynamicdxc` (alias `dxc`), `staticdxc`, `fxc`, or `auto`."), + }) + } +} + /// Whether and how to use a waitable handle obtained from `GetFrameLatencyWaitableObject`. #[derive(Clone, Debug, Default)] pub enum Dx12UseFrameLatencyWaitableObject {